Пример #1
0
        /// <summary>
        /// Draws the node window.
        /// </summary>
        /// <param name="id">Identifier.</param>
        protected override void DrawNodeWindow(int id)
        {
            int iconSize = (int)EditorGUIUtility.singleLineHeight;

            ZEntity en = curPoolConfig.CurPool.FindEntityTemplateByID(id);

            if (en.EType == EntityType.System)
            {
                GUI.DrawTexture(new Rect(5, 20, iconSize, iconSize), IconHelper.SystemsHierarchyIcon);
            }
            else
            {
                GUI.DrawTexture(new Rect(5, 20, iconSize, iconSize), IconHelper.EntityHierarchyIcon);
            }



            if (en != null)
            {
                int count = en.GetComponentCount();
                GUILayout.Label("      x " + count.ToString());
            }

            //draw delete button

            base.DrawNodeWindow(id);
        }
Пример #2
0
        /// <summary>
        /// Changes the name of the entity.
        /// </summary>
        /// <param name="en">En.</param>
        /// <param name="name">Name.</param>
        static public void ChangeEntityName(ZEntity en, string name)
        {
            DelEntityFile(en);
            en.Name = name;

            SaveEntity(en);
        }
Пример #3
0
        /// <summary>
        /// Loads the entity.
        /// </summary>
        /// <returns>The entity.</returns>
        /// <param name="name">Name.</param>
        static public ZEntity LoadEntity(string name, int ID = -1)
        {
            string strFileName = name + ".json";

            string sl = "";

            //create the entity
            ZEntity newEntity = new ZEntity();

            newEntity.Name = name;
            newEntity.ID   = ID;

            string entityPath = Application.dataPath + GetCurPoolEntityPath();

            if (!System.IO.File.Exists(entityPath + strFileName))
            {
                return(newEntity);
            }

            try
            {
                StreamReader sr = new StreamReader(entityPath + strFileName, Encoding.Default);

                if (sr == null)
                {
                    return(newEntity);
                }

                //get entity ID
                sl = sr.ReadLine();
                //newEntity.ID = Convert.ToInt32(sl);
                //read type
                sl = sr.ReadLine();
                newEntity.EType = (EntityType)Enum.Parse(typeof(EntityType), sl);
                //Debug.Log("EType is " + newEntity.EType);

                while (sl != null)
                {
                    sl = sr.ReadLine();
                    if (sl != null && sl.CompareTo(ComponentPrefix) == 0)
                    {
                        var c = LoadAComponent(sr);
                        if (c != null)
                        {
                            newEntity.AddComponent(c);
                        }
                    }
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new Exception("Load Entity Error " + name + e.Message);
                //return null;
            }

            return(newEntity);
        }
Пример #4
0
    // Use this for initialization
    void Start()
    {
        pool = EntityPoolBuilder.FindByName("TestPool");

        ZEntity en = pool.CreateEntity(1);

        Debug.Log(" en data is " + en.GetComponent <TestComponent4> ().data4.ToString());

        //test singleton
        TestSingleton test = SingletonEntity <TestSingleton> .Instance;

        if (test != null)
        {
            Debug.Log(" SingletonEntity data is " + test.data2.ToString());
        }
    }
Пример #5
0
        //在这里方法中就可以绘制面板。
        public override void OnInspectorGUI()
        {
            curEntity = poolConfig.CurEntity;

            serializedObject.Update();
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Edit"))
            {
                ZEditorWindow.ShowEditor();
            }

            var oldColor = GUI.color;

            GUI.color = Color.yellow;
            EditorGUILayout.LabelField("Entity x " + poolConfig.CurPool.TemplateCount);

            GUILayout.FlexibleSpace();

            GUI.color = oldColor;


            if (GUILayout.Button("Reload"))
            {
                Reload();
            }

            EditorGUILayout.EndHorizontal();

            if (curEntity != null)
            {
                DrawEntity();
            }
            else
            {
                EditorGUILayout.LabelField("please select a entity");
            }

            //serializedObject.Update();
            serializedObject.SetIsDifferentCacheDirty();
            EditorApplication.DirtyHierarchyWindowSorting();
            serializedObject.ApplyModifiedProperties();
        }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        /// <summary>
        /// Pres the draw node window.
        /// </summary>
        /// <param name="item">Item.</param>
        protected override void PreDrawNodeWindow(EditorWindowLayoutItem item)
        {
            ZEntity en = curPoolConfig.CurPool.FindEntityTemplateByID(item.wndID);

            GUI.color = Color.yellow;

            if (en != null)
            {
                ColorAttribute ca = en.GetSupportAttribute <ColorAttribute> ();
                if (ca != null)
                {
                    //Debug.Log ("NodeColor is " + ca.NodeColor);
                    GUI.color = ca.ToUnityColor();
                }
            }

            if (en.EType == EntityType.System)
            {
                GUI.color = Color.gray;
            }
        }
Пример #8
0
        /// <summary>
        /// Saves the entity.
        /// </summary>
        /// <param name="en">En.</param>
        static public void SaveEntity(ZEntity en)
        {
            //save entity data
            List <IZComponent> coms    = en.GetComponents <IZComponent>();
            string             strData = en.ID.ToString() + "\n" + en.EType.ToString() + "\n";

            foreach (var c in coms)
            {
                strData += SaveComponentData(c);
            }

            string strFileName = en.Name + ".json";

            string entityPath = Application.dataPath + GetCurPoolEntityPath();

            System.IO.FileInfo file = new System.IO.FileInfo(entityPath + strFileName);
            StreamWriter       sw   = file.CreateText();

            sw.WriteLine(strData);
            sw.Close();
            sw.Dispose();
        }
Пример #9
0
 /// <summary>
 /// Dels the entity file.
 /// </summary>
 /// <param name="en">En.</param>
 static public void DelEntityFile(ZEntity en)
 {
     DelEntityFile(en.Name);
 }
Пример #10
0
        /// <summary>
        /// Draws the control bar.
        /// </summary>
        void DrawControlBar()
        {
            var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f);

            componentColor.a = 0.15f;
            var style = new GUIStyle(GUI.skin.label);

            style.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);
//
            EditorGUILayout.BeginHorizontal(style);


            //EditorGUILayout.LabelField ("");

            if (GUILayout.Button("Add Entity", GUILayout.MaxWidth(100)))
            {
                var node = curPoolConfig.PoolNodeRoot.FindNode(CurSelWndID);

                //curPoolConfig.CreateEntity ();
                curPoolConfig.CreateEntityAt(node);
                EntityPoolEditorBuildUtils.SaveEntity(curPoolConfig.CurEntity);

                EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);
                Refresh();
            }

            if (GUILayout.Button("Delete Entity", GUILayout.MaxWidth(100)))
            {
                ZEntity en = curPoolConfig.DeleteCurEntity();
                EntityPoolEditorBuildUtils.DelEntityFile(en);

                EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);

                Refresh();
            }

            if (GUILayout.Button("Add System", GUILayout.MaxWidth(100)))
            {
                curPoolConfig.CreateSystem();
                EntityPoolEditorBuildUtils.SaveEntity(curPoolConfig.CurEntity);

                EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);
                Refresh();
            }

            if (GUILayout.Button("Reset", GUILayout.MaxWidth(100)))
            {
                EntityPoolEditorBuildUtils.DelAllEntity(curPoolConfig.PoolNodeRoot);

                curPoolConfig.DeleteAllEntity();

                EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);

                Refresh();
            }

            if (GUILayout.Button("Isolate", GUILayout.MaxWidth(100)))
            {
                if (curPoolConfig.CurEntity != null)
                {
                    curPoolConfig.PoolNodeRoot.IsolateRelation(curPoolConfig.CurEntity.ID);
                    EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);
                    Refresh();
                }
            }

            strTempEditEntityName = GUILayout.TextArea(strTempEditEntityName, GUILayout.MaxWidth(200));


            if (GUILayout.Button("Rename", GUILayout.MaxWidth(100)))
            {
                if (curPoolConfig.CurEntity != null && CurSelWndID >= 0)
                {
                    //curPoolConfig.CurEntity.Name = strTempEditEntityName;
                    curPoolConfig.PoolNodeRoot.Rename(curPoolConfig.CurEntity.ID, strTempEditEntityName);
                    root.RenameTitle(curPoolConfig.CurEntity.ID, strTempEditEntityName);
                    SaveLayout();
                    EntityPoolEditorBuildUtils.ChangeEntityName(curPoolConfig.CurEntity, strTempEditEntityName);
                    EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(curPoolConfig.PoolNodeRoot);
                    Refresh();
                }
            }

            //curEntity.Name = EditorGUILayout.TextField (curEntity.Name);
            EditorGUILayout.EndHorizontal();
        }