Ejemplo n.º 1
0
        /// <summary>
        /// 保存csv;
        /// </summary>
        private static void Save()
        {
            if (string.IsNullOrEmpty(_targetPath))
            {
                LogHelper.PrintWarning("#未指定配表路径#path:" + _targetPath);
                return;
            }
            int count = _infoDict.Count;

            string[] info = new string[count];
            for (int i = 0; i < count; i++)
            {
                string        target = string.Empty;
                List <string> list   = _infoDict[i + 1];
                for (int j = 0; j < list.Count; j++)
                {
                    if (j != 0)
                    {
                        target = target + ",";
                    }
                    target = target + list[j];
                }
                info[i] = target;
            }
            File.WriteAllLines(_targetPath, info, Encoding.UTF8);
            EditorUtility.DisplayDialog("提示", "配置表已刷新并保存!", "确认");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加事件;
        /// </summary>
        /// <param name="receiver">接收者</param>
        /// <param name="type">事件类型</param>
        /// <param name="callBack">事件回调</param>
        public void AddEvent(ObjectEx receiver, EventType type, EventHandler callBack)
        {
            if (null == receiver)
            {
                LogHelper.PrintError("[EventMgr]AddEvent error,the receiver is null.");
                return;
            }
            Dictionary <EventType, List <EventHandler> > dict;
            List <EventHandler> list;

            if (!EventDict.TryGetValue(receiver, out dict))
            {
                EventDict[receiver] = new Dictionary <EventType, List <EventHandler> >();
            }
            dict = EventDict[receiver];
            if (!dict.TryGetValue(type, out list))
            {
                list       = new List <EventHandler>();
                dict[type] = list;
            }
            list = dict[type];
            if (list.Contains(callBack))
            {
                LogHelper.PrintWarning(string.Format("[EventMgr]AddEvent repeat,receiver:{0},eventType:{1}.",
                                                     receiver.ID, type.ToString()));
            }
            else
            {
                list.Add(callBack);
            }
        }
Ejemplo n.º 3
0
        public static void ExportByte(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            _infoDict.Clear();
            _tableTypeDict.Clear();
            _infoDict = TableReader.ReadCsvFile(path);

            List <byte> allBytes = new List <byte>();

            if (_infoDict.ContainsKey(2))
            {
                _fileName = Path.GetFileNameWithoutExtension(path);
                string        filePath = _targetPath + _fileName + ".byte";
                List <string> line     = _infoDict[2];
                for (int i = 0; i < line.Count; i++)
                {
                    string   target = line[i];
                    string[] temp   = target.Split(":".ToArray());
                    string   type   = TableFiledType.STRING.ToString();
                    if (temp.Length < 2)
                    {
                        LogHelper.PrintWarning(string.Format("#配表未指定类型{0}行,{1}列#path:" + path, 2.ToString(), i.ToString()));
                        return;
                    }
                    else
                    {
                        type = temp[1];
                    }
                    _tableTypeDict[i] = TableReader.GetTableFiledType(type);
                }
                int    col       = line.Count;
                byte[] dataCount = ConvertHelper.GetBytes(_infoDict.Count - 2);
                allBytes.AddRange(dataCount);
                int index = 3;
                while (_infoDict.ContainsKey(index))
                {
                    List <string> info = _infoDict[index];
                    if (info.Count != col)
                    {
                        LogHelper.PrintWarning(string.Format("#配表未指定类型{0}行错误#path:" + path, index));
                        return;
                    }
                    for (int i = 0; i < info.Count; i++)
                    {
                        byte[] tempByte = Export2Bytes(info[i], _tableTypeDict[i]);
                        allBytes.AddRange(tempByte);
                    }
                    index++;
                }
                FileHelper.Write2Bytes(filePath, allBytes.ToArray());
                EditorUtility.DisplayDialog("提示", "byte 导出成功!", "确认");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据AssetBundle Name打包全部AssetBundle;
        /// </summary>
        /// <param name="buildPath">目标路径</param>
        private static void GenerateAssetBundle(string buildPath)
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            BuildPipeline.BuildAssetBundles(buildPath, AssetBuildDefine.options, AssetBuildDefine.buildTarget);
            watch.Stop();
            LogHelper.PrintWarning(string.Format("GenerateAllAssetBundle Spend Time:{0}s", watch.Elapsed.TotalSeconds));
            AssetDatabase.Refresh();
            EditorUtility.UnloadUnusedAssetsImmediate();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 构造函数;
 /// </summary>
 protected MonoSingleton()
 {
     if (null != _instance)
     {
         LogHelper.PrintWarning((typeof(T)).ToString() + " singleton Instance is not null.");
     }
     else
     {
         LogHelper.Print((typeof(T)).ToString() + " singleton Instance created.");
     }
 }
 private void OnDestroy()
 {
     if (_isRelease)
     {
         return;
     }
     if (AtlasMgr.ApplicationIsPlaying)
     {
         LogHelper.PrintWarning($"[AtlasRecycleBehaviour]auto recycle atlas at:{name}");
         OnRelease();
     }
 }
Ejemplo n.º 7
0
        public static void ExportCs(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            _infoDict.Clear();
            _fileName = string.Empty;
            _code     = string.Empty;

            _infoDict = TableReader.ReadCsvFile(path);
            _code     = template;
            if (_infoDict.ContainsKey(2))
            {
                _fileName = Path.GetFileNameWithoutExtension(path);
                string filePath = _targetPath + _fileName + ".cs";
                _code = _code.Replace("#fileName#", _fileName);

                string fields  = string.Empty;
                string mainKey = string.Empty;
                string funcs   = string.Empty;

                List <string> line = _infoDict[2];
                for (int i = 0; i < line.Count; i++)
                {
                    string         target = line[i];
                    string[]       temp   = target.Split(":".ToArray());
                    TableFiledType type   = TableFiledType.STRING;
                    if (temp.Length < 2)
                    {
                        LogHelper.PrintWarning(string.Format("#配表未指定类型{0}行,{1}列,请先初始化#path:" + path, 2.ToString(), i.ToString()));
                        return;
                    }
                    else
                    {
                        type = TableReader.GetTableFiledType(temp[1]);
                    }
                    fields = fields + "\r\n " + "    public " + _tableTypeDict[type].ToString() + " " + temp[0] + ";";
                    if (i == 0)
                    {
                        mainKey = temp[0];
                    }
                    funcs = funcs + "\r\n " + string.Format(_tableReadDict[type], temp[0]);
                }
                _code = _code.Replace("#fields#", fields);
                _code = _code.Replace("#mainKey#", mainKey);
                _code = _code.Replace("#function#", funcs);
                File.WriteAllText(filePath, _code);
                AssetDatabase.Refresh();
                EditorUtility.DisplayDialog("提示", "cs 导出成功,等待编译通过!", "确认");
            }
        }
Ejemplo n.º 8
0
        public static void InitTable()
        {
            _colDict.Clear();
            _infoDict.Clear();
            _targetPath = string.Empty;

            bool autoSave = false;
            var  window   = GetWindow(typeof(TableInitCsv), false, "初始化配置表");

            window.Show();
            string path = string.Empty;

            try
            {
                path = EditorUtility.OpenFilePanel("选择配置表", TableConfig.TablePath, "csv");
            }
            catch (Exception e)
            {
                LogHelper.PrintWarning(e.ToString());
            }
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            _infoDict = TableReader.ReadCsvFile(path);
            if (_infoDict.ContainsKey(2))
            {
                _targetPath = path;
                List <string> line = _infoDict[2];
                for (int i = 0; i < line.Count; i++)
                {
                    string   target = line[i];
                    string[] temp   = target.Split(":".ToArray());
                    string   type   = TableFiledType.STRING.ToString();
                    if (temp.Length < 2)
                    {
                        LogHelper.PrintWarning(string.Format("#配表未指定类型{0}行,{1}列#path:" + path, 2.ToString(), i.ToString()));
                        autoSave        = true;
                        _infoDict[2][i] = temp[0] + ":" + type;
                    }
                    else
                    {
                        type = temp[1];
                    }
                    _colDict[i] = new KeyValuePair <string, TableFiledType>(temp[0], TableReader.GetTableFiledType(type));
                }
                if (autoSave)
                {
                    Save();
                }
            }
        }
        private static void GenerateAssetBundle(string buildPath, List <AssetBundleBuild> list)
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            if (!Directory.Exists(buildPath))
            {
                Directory.CreateDirectory(buildPath);
            }
            BuildPipeline.BuildAssetBundles(buildPath, list.ToArray(), AssetBuildDefine.options, AssetBuildDefine.buildTarget);
            watch.Stop();
            LogHelper.PrintWarning(string.Format("GenerateAllAssetBundle Spend Time:{0}s", watch.Elapsed.TotalSeconds));
            AssetDatabase.Refresh();
            EditorUtility.UnloadUnusedAssetsImmediate();
        }
Ejemplo n.º 10
0
 public void RemoveBehaviorTree(AbsEntity entity)
 {
     if (entity == null)
     {
         LogHelper.PrintError("[BehaviorTreeMgr]Remove BehaviorTree error,entity is null!");
         return;
     }
     if (!_treeDict.ContainsKey(entity))
     {
         LogHelper.PrintWarning(string.Format("[BehaviorTreeMgr]can not find a BehaviorTree at EntityName: {0}.", entity.EntityName));
     }
     else
     {
         _treeDict.Remove(entity);
     }
 }
Ejemplo n.º 11
0
        public void CreateBehaviorTree(AbsEntity entity, string path, bool enable = false)
        {
            BehaviorTree tree = BehaviorTreeFactory.CreateBehaviorTree(entity, path);

            if (entity == null)
            {
                LogHelper.PrintError("[BehaviorTreeMgr]Create BehaviorTree error,entity is null!");
                return;
            }
            if (_treeDict.ContainsKey(entity))
            {
                LogHelper.PrintWarning(string.Format("[BehaviorTreeMgr]repeat add BehaviorTree at EntityName: {0}.", entity.EntityName));
            }
            tree.Enable       = enable;
            _treeDict[entity] = tree;
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 添加事件;
 /// </summary>
 /// <param name="type">事件类型</param>
 /// <param name="callBack">事件回调</param>
 public void AddGlobalEvent(EventType type, EventHandler callBack)
 {
     if (!GlobalEventDict.TryGetValue(type, out var list))
     {
         GlobalEventDict[type] = new List <EventHandler>();
     }
     list = GlobalEventDict[type];
     if (list.Contains(callBack))
     {
         LogHelper.PrintWarning($"[EventMgr]AddGlobalEvent repeat,EventType:{type.ToString()}.");
     }
     else
     {
         list.Add(callBack);
     }
 }
Ejemplo n.º 13
0
        public static byte[] ReadFromFile(string path)
        {
            var ms = new MemoryStream
            {
                Position = 0
            };

            ms.SetLength(0);
            try
            {
                using (var fsRead = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    if (fsRead.CanRead)
                    {
                        var leftLength = fsRead.Length;       //还没有读取的文件内容长度;
                        var maxLength  = _bufferBytes.Length; //每次读取的最大字节数;
                        var num        = 0;                   //每次实际返回的字节数长度;
                        var fileStart  = 0;                   //文件开始读取的位置;
                        while (leftLength > 0)
                        {
                            fsRead.Position = fileStart;     //设置文件流的读取位置;
                            if (leftLength < maxLength)
                            {
                                num = fsRead.Read(_bufferBytes, 0, Convert.ToInt32(leftLength));
                            }
                            else
                            {
                                num = fsRead.Read(_bufferBytes, 0, maxLength);
                            }
                            if (num == 0)
                            {
                                break;
                            }
                            fileStart  += num;
                            leftLength -= num;
                            ms.Write(_bufferBytes, 0, num);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LogHelper.PrintWarning(e.ToString());
            }
            return(ms.GetBuffer());
        }
Ejemplo n.º 14
0
        public static void ExportSelectCsharp()
        {
            string path = string.Empty;

            try
            {
                path = EditorUtility.OpenFilePanel("选择配置表", TableConfig.TablePath, "csv");
            }
            catch (Exception e)
            {
                LogHelper.PrintWarning(e.ToString());
            }
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            TableExportCs.ExportCs(path);
        }
Ejemplo n.º 15
0
 protected override void UpdateEx(float interval)
 {
     LogHelper.PrintWarning(string.Format("BTLevel's level:{0}", _level));
     Reslut = BehaviorState.Finish;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 同步服务器的时间到客户端;
 /// </summary>
 /// <param name="time">服务器时间</param>
 public void SyncServerTime(DateTime time)
 {
     serverTime      = time;
     clientStartTime = Time.realtimeSinceStartup;
     LogHelper.PrintWarning($"[Sync Server Time] ServerTime = {serverTime}");
 }
        /// <summary>
        /// 分析全部资源依赖关系;
        /// </summary>
        /// <returns></returns>
        public List <AssetBundleBuild> AnalysisAllAsset()
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            string[] allPath = Directory.GetFiles(FilePathHelper.resPath, "*.*", SearchOption.AllDirectories);

            //剔除.meta文件;
            List <string> allAssetPath = new List <string>();

            foreach (string tempPath in allPath)
            {
                string path = tempPath.Replace("\\", "/");
                if (Path.GetExtension(path) == ".meta")
                {
                    continue;
                }
                allAssetPath.Add(path);
            }

            //开始分析资源依赖关系;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                if (!CheckAssetNode(allAssetPath[i]))
                {
                    continue;
                }

                //还未遍历到该资源;
                if (!allAsset.ContainsKey(allAssetPath[i]))
                {
                    allAsset[allAssetPath[i]] = CreateNewAssetNode(allAssetPath[i]);
                }

                //获取依赖关系;
                string[] allDirectDependencies = AssetDatabase.GetDependencies(allAssetPath[i], false);

                foreach (string tempPath in allDirectDependencies)
                {
                    if (!CheckAssetNode(tempPath))
                    {
                        continue;
                    }

                    //添加依赖的资源信息;
                    allAsset[allAssetPath[i]].sonDependentAssets.Add(tempPath);
                    //添加被依赖的资源信息;
                    if (!allAsset.ContainsKey(tempPath))
                    {
                        allAsset[tempPath] = CreateNewAssetNode(tempPath);
                    }
                    allAsset[tempPath].parentDependentAssets.Add(allAssetPath[i]);
                }
            }

            foreach (var tempAsset in allAsset)
            {
                if (tempAsset.Value.parentDependentAssets.Count == 0 || //没有被依赖的资源;
                    tempAsset.Value.parentDependentAssets.Count > 1 ||  //被超过一个资源依赖的资源;
                    tempAsset.Key.Contains(FilePathHelper.resPath))     //Bundles资源目录下的资源,允许加载所以单独打包;
                {
                    independenceAsset[tempAsset.Key] = tempAsset.Value;
                }
            }

            //TODO:AssetBundleBuild修改为可以包含多个资源.
            List <AssetBundleBuild> builderList = new List <AssetBundleBuild>();

            foreach (var asset in independenceAsset)
            {
                var node = asset.Value;
                AssetBundleBuild build = new AssetBundleBuild
                {
                    assetBundleName = FilePathHelper.GetAssetBundleFileName(node.assetPath)
                };
                List <string> assetLis = new List <string>
                {
                    node.assetPath
                };
                foreach (var tempAsset in node.sonDependentAssets)
                {
                    if (!independenceAsset.ContainsKey(tempAsset))
                    {
                        assetLis.Add(tempAsset);
                    }
                }
                build.assetNames = assetLis.ToArray();
                builderList.Add(build);
            }

            AssetBundleBuild shaderBuild = new AssetBundleBuild
            {
                assetBundleName = FilePathHelper.GetAssetBundleFileName(FilePathHelper.shaderAssetBundleName)
            };
            List <string> shaderList = new List <string>();

            foreach (var shader in allShaderAsset)
            {
                shaderList.Add(shader);
            }
            shaderBuild.assetNames = shaderList.ToArray();
            builderList.Add(shaderBuild);

            AssetBundleBuild luaBuild = new AssetBundleBuild
            {
                assetBundleName = FilePathHelper.GetAssetBundleFileName(FilePathHelper.luaAssetBundleName)
            };
            List <string> luaList = new List <string>();

            foreach (var lua in allLuaAsset)
            {
                luaList.Add(lua);
            }
            luaBuild.assetNames = luaList.ToArray();
            builderList.Add(luaBuild);

            watch.Stop();

            LogHelper.PrintWarning($"[AssetDependenciesAnalysis]Asset Dependencies Analysis Spend Time:{watch.Elapsed.TotalSeconds}s");

            SaveBuildInfo(builderList);

            return(builderList);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 分析全部资源依赖关系;
        /// </summary>
        public void AnalysisAllAsset()
        {
            Stopwatch watch = Stopwatch.StartNew();//开启计时;

            string[] allPath = Directory.GetFiles(FilePathHelper.resPath, "*.*", SearchOption.AllDirectories);

            //剔除.meta文件;
            List <string> allAssetPath = new List <string>();

            foreach (string tempPath in allPath)
            {
                string path = tempPath.Replace("\\", "/");
                if (Path.GetExtension(path) == ".meta")
                {
                    continue;
                }
                allAssetPath.Add(path);
            }

            //开始分析资源依赖关系;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "获取需要打包的资源", ((float)i / (float)allAssetPath.Count));

                //还未遍历到该资源;
                if (!allAsset.ContainsKey(allAssetPath[i]))
                {
                    allAsset[allAssetPath[i]] = CreateNewAssetNode(allAssetPath[i]);
                }
                //获取依赖关系;
                string[] allDirectDependencies = AssetDatabase.GetDependencies(allAssetPath[i], false);
                foreach (string tempPath in allDirectDependencies)
                {
                    //依赖脚本直接添加到脚本队列;
                    if (AssetBundleDefine.GetAssetType(tempPath) == AssetType.Scripts)
                    {
                        continue;
                    }
                    //依赖Shader直接添加到Shader队列;
                    if (AssetBundleDefine.GetAssetType(tempPath) == AssetType.Shader)
                    {
                        allShaderAsset.Add(tempPath);
                        continue;
                    }
                    if (tempPath.Contains(FilePathHelper.resPath))
                    {
                        //添加依赖的资源信息;
                        allAsset[allAssetPath[i]].sonDependentAssets.Add(tempPath);
                        //添加被依赖的资源信息;
                        if (!allAsset.ContainsKey(tempPath))
                        {
                            allAsset[tempPath] = CreateNewAssetNode(tempPath);
                        }
                        allAsset[tempPath].parentDependentAssets.Add(allAssetPath[i]);
                    }
                    else
                    {
                        //需要打包AssetBundle的资源目录下的资源,引用非该目录下的资源;
                        LogHelper.Print("[Asset Dependencies Analysis] path:" + allAssetPath[i] + "--->>>reference--->>>: " + tempPath);
                    }
                }
            }
            EditorUtility.ClearProgressBar();

            //找出需要打包的资源;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "分析需要打包的资源", ((float)i / (float)allAssetPath.Count));

                //图集特殊处理;

                /*
                 * if (allAssetPath[i].Contains("Atlas") && Path.GetExtension(allAssetPath[i]) == ".prefab")//ngui
                 * {
                 *  independenceAsset[allAssetPath[i]] = allAsset[allAssetPath[i]];
                 *  continue;
                 * }
                 */
                if (allAssetPath[i].Contains(FilePathHelper.resPath + "Shaders") && Path.GetExtension(allAssetPath[i]) == ".shader")
                {
                    allShaderAsset.Add(allAssetPath[i]);
                    continue;
                }
                if (allAsset[allAssetPath[i]].parentDependentAssets.Count == 0 || //没有被依赖的资源;
                    allAsset[allAssetPath[i]].parentDependentAssets.Count > 1 ||  //被超过一个资源依赖的资源;
                    allAssetPath[i].Contains(FilePathHelper.singleResPath))       //指定要求单独打包的资源;
                {
                    independenceAsset[allAssetPath[i]] = allAsset[allAssetPath[i]];
                }
            }
            EditorUtility.ClearProgressBar();

            //设置资源AssetBundle Name;
            for (int i = 0; i < allAssetPath.Count; i++)
            {
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "设置AssetBundle Name", ((float)i / (float)allAssetPath.Count));

                AssetImporter importer = AssetImporter.GetAtPath(allAssetPath[i]);
                if (importer != null)
                {
                    if (independenceAsset.ContainsKey(allAssetPath[i]))
                    {
                        importer.assetBundleName = FilePathHelper.GetAssetBundleFileName(independenceAsset[allAssetPath[i]].type, independenceAsset[allAssetPath[i]].assetName);
                    }
                    else
                    {
                        importer.assetBundleName = null;
                    }
                    AssetDatabase.ImportAsset(allAssetPath[i]);
                }
            }
            EditorUtility.ClearProgressBar();

            int index = 0;

            //设置Shader AssetBundle Name;
            foreach (string tempPath in allShaderAsset)
            {
                index++;
                EditorUtility.DisplayProgressBar("AssetBundle打包提示", "设置Shader AssetBundle Name", ((float)index / (float)allShaderAsset.Count));
                AssetImporter importer = AssetImporter.GetAtPath(tempPath);
                if (importer != null)
                {
                    importer.assetBundleName = FilePathHelper.GetAssetBundleFileName(AssetType.Shader, "Shaders");
                    AssetDatabase.ImportAsset(tempPath);
                }
            }

            SetLuaAssetName();
            //SetAtlasName();

            EditorUtility.ClearProgressBar();

            watch.Stop();
            LogHelper.PrintWarning(string.Format("[AssetDependenciesAnalysis]Asset Dependencies Analysis Spend Time:{0}s", watch.Elapsed.TotalSeconds));

            AssetDatabase.Refresh();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// 同步服务器的时间到客户端;
 /// </summary>
 /// <param name="time">服务器时间</param>
 public void SyncServerTime(DateTime time)
 {
     serverTime      = time;
     clientStartTime = Time.realtimeSinceStartup;
     LogHelper.PrintWarning(string.Format("[Sync Server Time] ServerTime = {0}", serverTime));
 }
Ejemplo n.º 20
0
 protected override void UpdateEx(float interval)
 {
     LogHelper.PrintWarning($"BTLevel's level:{_level}");
     Reslut = BehaviorState.Finish;
 }