Example #1
0
        /// <summary>
        /// 创建一个实体
        /// </summary>
        /// <typeparam name="T">驱动脚本</typeparam>
        /// <param name="type">实体类型</param>
        /// <param name="assettype">资源类型</param>
        /// <param name="parent">父节点物体</param>
        /// <param name="name">实体名称</param>
        /// <returns>实体ID</returns>
        public long CreateNewEntity <T>(Define.EntityType type, Define.ModelType assettype, GameObject parent = null, string name = "") where T : Base.BaseMotor, new()
        {
            long id = -1;

            AssetMgr.GetInstance().LoadAsset(PathMgr.GetInstance().GetPath(assettype), true, true, () =>
            {
                if (AssetMgr.GetInstance().GetAsset() != null)
                {
                    GameObject go;
                    go            = GameObject.Instantiate(AssetMgr.GetInstance().GetAsset(), parent == null ? EntityRoot.transform : parent.transform) as GameObject;
                    id            = go.GetHashCode() >= 0 ? go.GetHashCode() * 10 : -go.GetHashCode() * 10 + 1;
                    string goname = name == "" ? (id + "_" + assettype.ToString()) : name;
                    go.name       = goname;
                    go.AddComponent(typeof(T));
                    go.GetComponent <T>().InitEntity(id, goname, type);
                    EntityList.Add(id, go.GetComponent <T>());
                }
                else
                {
                    Debug.LogError("Create Failed!");
                    return;
                }
            });
            return(id);
        }
Example #2
0
 public static PathMgr GetInstance()
 {
     if (_instance == null)
     {
         _instance = new PathMgr();
     }
     return(_instance);
 }
Example #3
0
        /// <summary>
        /// 读取配置信息
        /// </summary>
        /// <typeparam name="N">主键类型</typeparam>
        /// <typeparam name="T">配置表数据</typeparam>
        /// <param name="type">配置类型</param>
        /// <returns></returns>
        public Dictionary <N, T> GetConfigItems <N, T>(DataType type) where T : Base.BaseData, new()
        {
            Dictionary <N, T> list = new Dictionary <N, T>();

            string[] data = new string[0];
            AssetMgr.GetInstance().LoadAsset(PathMgr.GetInstance().GetPath(type), false, false, () =>
            {
                if (AssetMgr.GetInstance().GetAsset() == null)
                {
                    return;
                }
                data = AssetMgr.GetInstance().GetAsset().ToString().Split('\n');
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = data[i].Replace("\r", "");
                }
            });
            if (data.Length == 0)
            {
                return(null);
            }
            else if (data.Length == 1)
            {
                return(list);
            }
            else
            {
                for (int i = 1; i < data.Length; i++)
                {
                    if (string.IsNullOrEmpty(data[i]) || data[i].StartsWith("#"))
                    {
                        continue;
                    }
                    T temp = new T();
                    temp.ReadData(data[i]);
                    object key = null;
                    if (typeof(N) == typeof(int))
                    {
                        key = int.Parse(data[i].Split(',')[0]);
                    }
                    else if (typeof(N) == typeof(long))
                    {
                        key = long.Parse(data[i].Split(',')[0]);
                    }
                    else
                    {
                        key = data[i].Split(',')[0];
                    }
                    list.Add((N)key, temp);
                }
                return(list);
            }
        }
Example #4
0
 /// <summary>
 /// 打开界面
 /// </summary>
 /// <param name="type">界面类型</param>
 /// <param name="funtion">完成后回调</param>
 public void ShowWin(UIType type, Action funtion = null)
 {
     if (!HasWinOpen(type))
     {
         AssetMgr.GetInstance().LoadAsset(PathMgr.GetInstance().GetPath(type), true, true, () =>
         {
             var win = GameObject.Instantiate(AssetMgr.GetInstance().GetAsset(), UIRoot.transform);
             WinList.Add(type, ((GameObject)win).GetComponent <BaseWindow>());
             UpUI = type;
         });
     }
     else
     {
         WinList[type].gameObject.SetActive(true);
     }
     if (funtion != null)
     {
         funtion();
     }
 }
Example #5
0
        /// <summary>
        /// 保存日志到本地
        /// </summary>
        public void SaveToLocal()
        {
            bool   isSavelLog = false;
            string filePath   = LOGPATH;

            if (!PathMgr.GetInstance().CheckFile(filePath))
            {
                StreamWriter logStream = File.CreateText(filePath);
                if (logStream != null)
                {
                    isSavelLog = true;
                    logStream.Close();
                }
                else
                {
                    ShowLogToPanel("创建log文件失败");
                }
            }
            else
            {
                isSavelLog = true;
            }

            if (isSavelLog)
            {
                string[] arr = File.ReadAllLines(filePath);
                if (arr.Length > MAX_LOG_ROW_COUNT)
                {
                    File.WriteAllLines(filePath, m_lstLog.ToArray());
                }
                else
                {
                    List <string> lst = new List <string>(arr);
                    lst.AddRange(m_lstLog);
                    File.WriteAllLines(filePath, lst.ToArray());
                }
                m_lstLog.Clear();
            }
        }