unity简易lua文件迁移工具

一. 了解商业游戏的Lua热更新开发方式

市面上的3种结合Lua热更新的开发方式
1.纯Lua开发(所有的游戏主要逻辑都用Lua实现)
好处:机动性强;坏处:代码效率略差

2.半C#,半Lua开发(核心逻辑C#开发,业务逻辑Lua开发)
好处:性能略好;坏处:机动性略差

3.xLua热补丁(纯C#开发,后期加口入xLua热补丁,不建议)
好处:解燃眉之急;坏处:破坏项目稳定性整体性

二. VS插件

Chinese
c#
c# XML Documentation Comments
Debugger for Unity
Unity Tools
UnitySnippets
Auto_Using for C#

三. Lua迁移工具代码

using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class LuaCopyEditor : Editor
{
    [MenuItem("XLua/自动生成txt后缀的Lua")]
   public static void CopyLuaToTxt()
   {
        //首先要找到 我们的所有Lua文件
        string path = Application.dataPath + "/Lua/";
        //判断路径是否存在
        if( !Directory.Exists(path) )
            return;
        //得到每一个lua文件的路径 才能进行迁移拷贝
        string[] strs = Directory.GetFiles(path, "*.lua");

       //然后把Lua文件拷贝到一个新的文件夹中
       //首先定一个新路径
       string newPath = Application.dataPath + "/LuaTxt/";

        //为了避免一些被删除的lua文件 不再使用 我们应该先清空目标路径

        //判断新路径文件夹 是否存在
        if( !Directory.Exists(newPath) )
            Directory.CreateDirectory(newPath);
        else
        {
            //得到该路径中 所有后缀.txt的文件 把他们全部删除了
            string[] oldFileStrs = Directory.GetFiles(newPath, "*.txt");
            for (int i = 0; i < oldFileStrs.Length; i++)
            {
                File.Delete(oldFileStrs[i]);
            }
        }

        List<string> newFileNames = new List<string>();
        string fileName;
       for(int i = 0; i < strs.Length; ++i)
       {
            //得到新的文件路径 用于拷贝
            fileName = newPath + strs[i].Substring(strs[i].LastIndexOf("/")+1) + ".txt";
            newFileNames.Add(fileName);
            File.Copy(strs[i], fileName);
       }

       AssetDatabase.Refresh();

        //刷新过后再来改制定包 因为 如果不刷新 第一次改变 会没用
        for (int i = 0; i < newFileNames.Count; i++)
        {
            //Unity API
            //改API传入的路径 必须是 相对Assets文件夹的 Assets/..../....
            AssetImporter importer = AssetImporter.GetAtPath( newFileNames[i].Substring(newFileNames[i].IndexOf("Assets")));
            if(importer != null)
                importer.assetBundleName = "lua";
        }
   }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值