Пример #1
0
        //Hotkey Check
        void HotKeyCheck()
        {
            Event hotkey_e = Event.current;

            switch (hotkey_e.type)
            {
            case EventType.KeyDown:
                if (hotkey_e.shift)
                {
                    switch (hotkey_e.keyCode)
                    {
                    case KeyCode.P:
                        grid.selected = Grid.DRAWOPTION.paint;
                        Repaint();
                        break;

                    case KeyCode.E:
                        grid.selected = Grid.DRAWOPTION.erase;
                        Repaint();
                        break;

                    case KeyCode.S:
                        grid.selected = Grid.DRAWOPTION.select;
                        Repaint();
                        break;

                    case KeyCode.F:
                        grid.gridEnabled = !grid.gridEnabled;
                        Repaint();
                        break;

                    case KeyCode.G:
                        grid.showGrid = !grid.showGrid;
                        Repaint();
                        break;

                    case KeyCode.T:
                        SpriteSheetPicker.ShowWindow();
                        break;

                    case KeyCode.H:
                        HideLayerHelper(!grid.hideOtherLayer);
                        Repaint();
                        break;

                    case KeyCode.L:
                        SwitchLayer(false);
                        Repaint();
                        break;

                    case KeyCode.K:
                        SwitchLayer(true);
                        Repaint();
                        break;
                    }
                }
                break;
            }
        }
Пример #2
0
        void OnGUI()
        {
            Init();

            if (grid)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Layer: " + grid.currentLayer.ToString(), GUILayout.Width(80));

                if (GUILayout.Button(new GUIContent(LeftIcon, "Switch between layers")))
                {
                    SwitchLayer(true);
                }

                if (GUILayout.Button(new GUIContent(RightIcon, "Switch between layers")))
                {
                    SwitchLayer(false);
                }

                if (GUILayout.Button(new GUIContent(AdIconB, "Add a new layer")))
                {
                    AddLayer();
                }

                if (GUILayout.Button(new GUIContent(BinIcon, "Delete current layer")))
                {
                    DeleteLayer();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (grid.gridEnabled)
                {
                    if (GUILayout.Button((new GUIContent(PauseIcon, "Disable edit mode"))))
                    {
                        HideLayerHelper(false);
                        grid.gridEnabled = false;
                    }
                }
                else
                {
                    if (GUILayout.Button((new GUIContent(ForwardIcon, "Enable edit mode"))))
                    {
                        grid.gridEnabled = true;
                    }
                }

                switch (grid.selected)
                {
                case Grid.DRAWOPTION.paint:

                    if (GUILayout.Button(new GUIContent(BrushIcon, "Draw Mode")))
                    {
                        grid.selected = Grid.DRAWOPTION.select;
                    }

                    break;

                case Grid.DRAWOPTION.select:

                    if (GUILayout.Button(new GUIContent(PointerIcon, "Select Mode")))
                    {
                        grid.selected = Grid.DRAWOPTION.paint;
                    }
                    break;

                default:
                    if (GUILayout.Button(new GUIContent(CrossIcon, "Currently in delete mode")))
                    {
                        grid.selected = Grid.DRAWOPTION.paint;
                    }
                    break;
                }

                if (grid.selected != Grid.DRAWOPTION.erase)
                {
                    if (GUILayout.Button(new GUIContent(EraserIcon, "Delete Mode")))
                    {
                        grid.selected = Grid.DRAWOPTION.erase;
                    }
                }
                else
                {
                    if (GUILayout.Button(new GUIContent(EraserIcon, "Delete Mode")))
                    {
                        grid.selected = Grid.DRAWOPTION.paint;
                    }
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                if (!grid.hideOtherLayer)
                {
                    if (GUILayout.Button("Hide other Layers"))
                    {
                        HideLayerHelper(true);
                    }
                }
                else
                {
                    if (GUILayout.Button("Show other Layers"))
                    {
                        HideLayerHelper(false);
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                if (grid.showGrid)
                {
                    if (GUILayout.Button("Hide Grid"))
                    {
                        grid.showGrid = false;
                    }
                }
                else
                {
                    if (GUILayout.Button("Show Grid"))
                    {
                        grid.showGrid = true;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (grid.snapToGrid)
                {
                    if (GUILayout.Button("Snap to Grid"))
                    {
                        grid.snapToGrid = false;
                    }
                }
                else
                {
                    if (GUILayout.Button("Free Hand"))
                    {
                        grid.snapToGrid = true;
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Optimize Colliders"))
                {
                    ColliderBuilder.OptimizeAll();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Restore Colliders"))
                {
                    ColliderBuilder.RestoreAllCollider();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Sprite Sheet Picker"))
                {
                    SpriteSheetPicker.ShowWindow();
                    return;
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (grid.complexView)
                {
                    if (GUILayout.Button("Complex View"))
                    {
                        grid.complexView = false;
                    }
                }
                else
                {
                    if (GUILayout.Button("Simple View"))
                    {
                        grid.complexView = true;
                    }
                }
                EditorGUILayout.EndHorizontal();

                int prefCounter = 0;

                EditorGUILayout.BeginHorizontal();
                scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandWidth(true));

                if (grid.complexView)
                {
                    foreach (Object obj in grid.prefabs)
                    {
                        if (obj)
                        {
                            bool isGo = false;
                            if (obj is GameObject)
                            {
                                isGo = true;
                            }


                            Texture2D prefabIcon = null;

                            if (isGo)
                            {
                                prefabIcon = AssetPreview.GetAssetPreview(obj);
                            }
                            else
                            {
                                Sprite t = (Sprite)obj;
                                prefabIcon = t.texture;
                            }

                            EditorGUILayout.BeginHorizontal();

                            EditorGUILayout.BeginVertical();
                            EditorGUILayout.LabelField(obj.name, GUILayout.Width(130));

                            EditorGUILayout.BeginHorizontal();


                            if (grid.selectedObj == obj)
                            {
                                if (GUILayout.Button(new GUIContent(FlagIcon, "Select Prefab"), GUILayout.Width(64)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                    }
                                }
                            }
                            else
                            {
                                if (GUILayout.Button(new GUIContent(CheckIcon, "Select Prefab"), GUILayout.Width(64)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                    }
                                }
                            }

                            if (GUILayout.Button(new GUIContent(BinIcon, "Delete Prefab from list"), GUILayout.Width(64)))
                            {
                                if (isGo)
                                {
                                    Delete((GameObject)obj);
                                }
                                else
                                {
                                    Delete((Sprite)obj);
                                }
                                break;
                            }
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndVertical();



                            if (prefabIcon == null)
                            {
                                if (GUILayout.Button(new GUIContent(EmptyIcon, obj.name), GUILayout.Height(50), GUILayout.Width(50)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                        grid.tileMap = false;
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                        grid.tileMap = false;
                                    }
                                }
                            }
                            else
                            {
                                if (GUILayout.Button(new GUIContent(prefabIcon, obj.name), GUILayout.Height(50), GUILayout.Width(50)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                        grid.tileMap = false;
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                        grid.tileMap = false;
                                    }
                                }
                            }

                            EditorGUILayout.BeginVertical();
                            if (GUILayout.Button(new GUIContent(UpIcon, "Move item up"), GUILayout.Width(25), GUILayout.Height(25)))
                            {
                                MovePrefab(true, prefCounter);
                                break;
                            }
                            if (GUILayout.Button(new GUIContent(DownIcon, "Move item down"), GUILayout.Width(25), GUILayout.Height(25)))
                            {
                                MovePrefab(false, prefCounter);
                                break;
                            }
                            EditorGUILayout.EndVertical();
                            EditorGUILayout.EndHorizontal();
                            prefCounter++;
                        }
                    }
                }

                else
                {
                    int ticker = 0;
                    foreach (Object obj in grid.prefabs)
                    {
                        if (obj)
                        {
                            bool isGo = false;
                            if (obj is GameObject)
                            {
                                isGo = true;
                            }

                            if (ticker == 0)
                            {
                                EditorGUILayout.BeginHorizontal();
                            }

                            Texture2D prefabIcon = null;

                            if (isGo)
                            {
                                prefabIcon = AssetPreview.GetAssetPreview(obj);
                            }
                            else
                            {
                                Sprite t = (Sprite)obj;
                                prefabIcon = t.texture;
                            }


                            if (prefabIcon == null)
                            {
                                if (GUILayout.Button(new GUIContent(EmptyIcon, obj.name), GUILayout.Height(50), GUILayout.Width(50)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                        grid.tileMap = false;
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                        grid.tileMap = false;
                                    }
                                }
                            }
                            else
                            {
                                if (GUILayout.Button(new GUIContent(prefabIcon, obj.name), GUILayout.Height(50), GUILayout.Width(50)))
                                {
                                    if (isGo)
                                    {
                                        Select((GameObject)obj);
                                        grid.tileMap = false;
                                    }
                                    else
                                    {
                                        Select((Sprite)obj);
                                        grid.tileMap = false;
                                    }
                                }
                            }

                            if (ticker == 3)
                            {
                                EditorGUILayout.EndHorizontal();
                                ticker = 0;
                            }
                            else
                            {
                                ticker++;
                            }

                            prefCounter++;
                        }
                    }

                    if (ticker != 0)
                    {
                        EditorGUILayout.EndHorizontal();
                    }
                }

                EditorGUILayout.EndScrollView();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent(LeftIcon, "Switch between prefab lists")))
                {
                    SwitchGroup(true);
                }

                if (GUILayout.Button(new GUIContent(RightIcon, "Switch between prefab lists")))
                {
                    SwitchGroup(false);
                }

                EditorGUILayout.EndHorizontal();


                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent(AdIcon, "Select the prefabs in the project view and then hit the button.")))
                {
                    CreateNewPrefab();
                }

                if (GUILayout.Button(new GUIContent(BinIconB, "Delete current prefab list")))
                {
                    RemovePrefabs();
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("");
                EditorGUILayout.EndHorizontal();

                EditorUtility.SetDirty(grid);
            }
            else
            {
                if (GUILayout.Button("Create Grit"))
                {
                    GameObject obj = (GameObject)PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath("Assets/GridEditor2D/Prefabs/Grid.prefab", typeof(GameObject)));
                    obj.transform.position = new Vector3(0, 0, 0);
                }
            }
        }
Пример #3
0
 public static void ShowWindow()
 {
     SpriteSheetPicker window = (SpriteSheetPicker)EditorWindow.GetWindow(typeof(SpriteSheetPicker), false, "SpriteSheetPicker");
     window.minSize = new Vector2(100, 100);
 }