/// <summary>
 /// Dels all entity.
 /// </summary>
 /// <param name="config">Config.</param>
 static public void DelAllEntity(ZEntityPoolTree config)
 {
     foreach (var en in config.GetAllEntities())
     {
         DelEntityFile(en.Name);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Syncs the layout.
        /// </summary>
        /// <returns><c>true</c>, if layout was synced, <c>false</c> otherwise.</returns>
        /// <param name="pool">Pool.</param>
        public bool SyncLayout(ZEntityPoolTree pool)
        {
            List <ZEntityNode> newItems = pool.GetAllEntities();

            if (items == null || items.Count == 0)
            {
                //newItems = pool.GetAllEntities();
            }
            else
            {
                var delItems = items.Where((a) => newItems.Find((b) => b.ID == a.wndID) != null).ToList();

                items    = delItems;
                newItems = newItems.Where((a) => items.Find((b) => b.wndID == a.ID) == null).ToList();
            }


            foreach (var n in newItems)
            {
                EditorWindowLayoutItem item = new EditorWindowLayoutItem();
                item.wndID = n.ID;
                item.title = n.Name;
                item.rect  = GetRandomRect();
                items.Add(item);
            }

            return(newItems.Count > 0);
            ///pool.Entities.Join(items, (a)=> a
        }
        /// <summary>
        /// Loads the entity pool config data.
        /// </summary>
        /// <returns>The entity pool config data.</returns>
        /// <param name="name">Name.</param>
        static public ZEntityPoolTree LoadEntityPoolConfigData(string name)
        {
            string strFileName = name + "_pool.json";
            string path        = Application.dataPath + localPoolPath + strFileName;

            //System.IO.FileInfo file = new System.IO.FileInfo (path);

            string          sl         = "";
            string          ret        = "";
            ZEntityPoolTree data       = new ZEntityPoolTree();
            string          entityPath = Application.dataPath + localPoolPath + name + "/Entities/";

            if (!System.IO.Directory.Exists(entityPath))
            {
                System.IO.Directory.CreateDirectory(entityPath);
            }

            if (!System.IO.File.Exists(path))
            {
                return(data);
            }



            try
            {
                StreamReader sr = new StreamReader(path, Encoding.Default);

                while (sl != null)
                {
                    sl = sr.ReadLine();
                    if (sl != "")
                    {
                        ret += sl;
                    }
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


            object boxedStruct = data;

            EditorJsonUtility.FromJsonOverwrite(ret, boxedStruct);              //editor.curPool.Json.text

            return((ZEntityPoolTree)boxedStruct);
        }
        /// <summary>
        /// Saves the entity pool config data.
        /// </summary>
        /// <param name="config">Config.</param>
        static public void SaveEntityPoolConfigData(ZEntityPoolTree config)
        {
            string strFileName = config.Name + "_pool.json";
            string path        = Application.dataPath + localPoolPath + strFileName;

            string strData = EditorJsonUtility.ToJson(config, true);

            System.IO.FileInfo file = new System.IO.FileInfo(path);
            StreamWriter       sw   = file.CreateText();

            sw.WriteLine(strData);
            sw.Close();
            sw.Dispose();
        }
        /// <summary>
        /// Loads the pool.
        /// </summary>
        /// <returns>The pool.</returns>
        /// <param name="name">Name.</param>
        static public void LoadPool(UnityEngine.Object target)
        {
            ZEntityPoolTree config = EntityPoolEditorBuildUtils.LoadEntityPoolConfigData(target.name);

            var poolConfig = (EntityPoolConfig)target;

            poolConfig.Reset();

            poolConfig.InitEntityPoolConfigData(config);


            foreach (var e in config.GetAllEntities())
            {
                ZEntity en = EntityPoolEditorBuildUtils.LoadEntity(e.Name, e.ID);

                poolConfig.EntityFileMgr.AddAsset(LoadEntityFileAsset(e.Name));

                poolConfig.AddEntityTemplate(en);
            }
        }