Пример #1
0
        void OnEnable()
        {
            curEditor  = this;
            poolConfig = (EntityPoolConfig)target;
            EntityPoolEditorBuildUtils.SwitchPool(target);
            LoadPoolFromConfig(target.name);


            if (!Application.isPlaying)
            {
                AssetDatabase.Refresh();
            }
        }
Пример #2
0
        static public void ShowEditor()
        {
            if (Selection.activeGameObject != null)
            {
                var poolConfig = Selection.activeGameObject.GetComponent <EntityPoolConfig> ();

                ZEditorWindow editor = EditorWindow.GetWindow <ZEditorWindow>("Pool Config");
                editor.curPoolConfig = poolConfig;


                if (editor.curPoolConfig != null)
                {
                    editor.WndName = editor.curPoolConfig.gameObject.name;
                    editor.loadLayout();
                }

                editor.OnSelWindow += (wndID) => {
                    //Debug.Log("OnSelWindow" + wndID);

                    if (wndID >= 0)
                    {
                        editor.curPoolConfig.SelAEntity(wndID);

                        editor.strTempEditEntityName = editor.curPoolConfig.CurEntity.Name;

                        EditorApplication.RepaintHierarchyWindow();

                        if (EntityPoolInspectorEditor.curEditor != null)
                        {
                            EntityPoolInspectorEditor.curEditor.Repaint();
                        }
                    }
                    else
                    {
                        editor.strTempEditEntityName = "No Selected";
                    }
                };

                Selection.selectionChanged += () => editor.RefreshAndRepaint();

                editor.OnLinkNode += (parentID, subID) => {
                    //Debug.Log("OnLinkNode " + parentID + " sub " + subID);
                    editor.curPoolConfig.PoolNodeRoot.SetRelation(parentID, subID);
                    EntityPoolEditorBuildUtils.SaveEntityPoolConfigData(editor.curPoolConfig.PoolNodeRoot);
                    editor.Refresh();
                };
            }
        }
Пример #3
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);
            }
        }
Пример #4
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();
        }
Пример #5
0
 /// <summary>
 /// Reload this instance.
 /// </summary>
 private void Reload()
 {
     EntityPoolEditorBuildUtils.BuildLocalPathBase();
     EntityPoolEditorBuildUtils.LoadPool(target);
     Repaint();
 }
Пример #6
0
        /// <summary>
        /// Draws the entity.
        /// </summary>
        void DrawEntity()
        {
            EditorGUI.BeginChangeCheck();

            var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f);

            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            List <IZComponent> coms = curEntity.GetComponents <IZComponent> ();


            //draw current selected entity
            EditorGUILayout.BeginVertical(entityStyle);

            //show the entity name
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Entity Name: " + curEntity.Name);
            //curEntity.Name = EditorGUILayout.TextField (curEntity.Name);
            EditorGUILayout.EndHorizontal();

            //show component info
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("Component x " + coms.Count, GUILayout.MaxWidth(100));
            GUILayout.FlexibleSpace();

            //show the component menu
            IZComponent c = curEntity.EType == EntityType.Entity ?
                            ComponentsPool <IZComponent> .DrawAddComponentMenu() :
                            ComponentsPool <IZComponent> .DrawAddSystemMenu();

            if (c != null)
            {
                var com = ComponentsPool <IZComponent> .CreateComponent(c.GetType());

                curEntity.AddComponent(com);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();


            //Draw Component
            componentColor   = Color.HSVToRGB(0.9f, 0.1f, 0.9f);
            componentColor.a = 0.15f;
            entityStyle      = new GUIStyle(GUI.skin.box);

            entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor);

            ///EditorGUILayout.Space();

            foreach (IZComponent com in coms)
            {
                DrawComponent(com);
            }


            if (EditorGUI.EndChangeCheck())
            {
                // Code to execute if GUI.changed
                // was set to true inside the block of code above.

                if (poolConfig != null && poolConfig.CurPool != null)
                {
                    //Debug.Log("EndChangeCheck");
                    EntityPoolEditorBuildUtils.SaveEntity(curEntity);

                    serializedObject.SetIsDifferentCacheDirty();
                    EditorApplication.DirtyHierarchyWindowSorting();
                    EditorApplication.RepaintProjectWindow();
                    //AssetDatabase.Refresh ();
                    //EditorApplication.
                }
            }
        }