コード例 #1
0
        public void OnEnable()
        {
            GameGrid t = target as GameGrid;

            if (t == null)
            {
                return;
            }

            database = (TileTemplateDatabase)AssetDatabase.LoadAssetAtPath("Assets/TileTempalteDatabase.asset", typeof(TileTemplateDatabase));

            SetLayerOpacity();


            if (EditorPrefs.HasKey("selectedX"))
            {
                Selected.x = EditorPrefs.GetInt("selectedX");
                Selected.y = EditorPrefs.GetInt("selectedY");
                Selected.z = EditorPrefs.GetInt("selectedZ");


                if (!t.isInBounds(new GridPosition(Selected.z, Selected.y, Selected.z)))
                {
                    Selected.x = 0;
                    Selected.y = 0;
                    Selected.z = 0;

                    EditorPrefs.SetInt("selectedX", Selected.x);
                    EditorPrefs.SetInt("selectedY", Selected.y);
                    EditorPrefs.SetInt("selectedZ", Selected.z);
                }
            }

            if (EditorPrefs.HasKey("selectedX"))
            {
                ShowAll = EditorPrefs.GetBool("ShowAll");
            }
        }
コード例 #2
0
 public TemplateCreatorPopUp(TileTemplateDatabase database, GameTile targetTile)
 {
     this.tile     = targetTile;
     this.database = database;
 }
コード例 #3
0
        public override void OnInspectorGUI()
        {
            if (skini == null)
            {
                skini = EditorGUIUtility.Load("Navigation.guiskin") as GUISkin;
            }
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("P", EditorStyles.miniButtonRight, GUILayout.Width(20)))
            {
                var asm = Assembly.GetAssembly(typeof(EditorWindow));
                var T   = asm.GetType("UnityEditor.PreferencesWindow");
                var M   = T.GetMethod("ShowPreferencesWindow", BindingFlags.NonPublic | BindingFlags.Static);
                M.Invoke(null, null);
            }
            EditorGUILayout.EndHorizontal();
            DrawDefaultInspector();

            // get the chosen game object
            GameGrid t = target as GameGrid;

            if (t == null)
            {
                return;
            }

            if (database == null)
            {
                database = (TileTemplateDatabase)AssetDatabase.LoadAssetAtPath("Assets/TileTempalteDatabase.asset", typeof(TileTemplateDatabase));
            }

            if (t.layers.Count == 0)
            {
                t.Initialize();
            }

            EditorGUI.BeginChangeCheck();
            currentTilestyle = EditorGUILayout.Popup("Templates", currentTilestyle, database.GetNames());
            if (EditorGUI.EndChangeCheck())
            {
                if (selectedTile)
                {
                    selectedTile.SetData(database.tiles[currentTilestyle]);
                }
            }
            if (GUILayout.Button("New Style") && selectedTile != null)
            {
                PopupWindow.Show(buttonRect, new TemplateCreatorPopUp(database, selectedTile));
            }
            if (Event.current.type == EventType.Repaint)
            {
                buttonRect = GUILayoutUtility.GetLastRect();
            }

            t.GridSortingWeights[0] = EditorGUILayout.IntField("Column", t.GridSortingWeights[0]);
            t.GridSortingWeights[1] = EditorGUILayout.IntField("Row", t.GridSortingWeights[1]);
            t.GridSortingWeights[2] = EditorGUILayout.IntField("Layer", t.GridSortingWeights[2]);


            EditorGUI.BeginChangeCheck();
            Navigation(t);

            if (selectedTile != t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x])
            {
                selectedTile = t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x];
                if (selectedTile != null)
                {
                    tileEditor = Editor.CreateEditor(selectedTile);
                    ((GameTileEditor)tileEditor).gridEditorMode = true;
                }
            }



            if (selectedTile != null)
            {
                if (tileEditor == null)
                {
                    tileEditor = Editor.CreateEditor(selectedTile);
                    ((GameTileEditor)tileEditor).gridEditorMode = true;
                }

                if (tileEditor != null && selectedTile != null)
                {
                    tileEditor.OnInspectorGUI();
                }
            }
            else
            {
                EditorGUILayout.BeginHorizontal(EditorStyles.helpBox);
                EditorGUILayout.LabelField("Sprite", GUILayout.Width(38));
                if (GUILayout.Button("+", GUILayout.Width(20)))
                {
                    t.CreateBlock(Selected.y, Selected.x, Selected.z);
                    if (LastSprite != null)
                    {
                        t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].Srenderer.sprite = LastSprite;
                    }
                    else
                    {
                        LastSprite = t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].Srenderer.sprite;
                    }

                    if (database.tiles.Count != 0)
                    {
                        t.layers[Selected.z].Rows[Selected.y].Tiles[Selected.x].SetData(database.tiles[currentTilestyle]);
                    }
                }

                EditorGUILayout.EndHorizontal();
            }


            EditorGUILayout.Space();
            if (GUILayout.Button("New Layer"))
            {
                t.CreateEmptyLayer(t.layers.Count);
                Selected.z = t.layers.Count - 1;
                SceneView.RepaintAll();
            }
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt("selectedX", Selected.x);
                EditorPrefs.SetInt("selectedY", Selected.y);
                EditorPrefs.SetInt("selectedZ", Selected.z);
            }
            if (GUILayout.Button("Fill"))
            {
                t.FillLayer(Selected.z);
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(t.gameObject.scene);
            }
            if (GUILayout.Button("Reset Grid"))
            {
                t.ResetGrid();
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(t.gameObject.scene);
            }
            if (GUI.changed && !Application.isPlaying)
            {
                EditorUtility.SetDirty(t.gameObject);
                Debug.Log("SAved");
            }
            WasdListener(t);
        }