示例#1
0
        // Refresh the asset database and load in the texture resources required for the editor.
        // Close the window however if the main Blockout window is not open
        void OnEnable()
        {
            AssetDatabase.Refresh();

            var icon = Resources.Load(
                EditorGUIUtility.isProSkin ? "Blockout/UI_Icons/Blockout_Icon_Light" : "Blockout/UI_Icons/Blockout_Icon_Dark",
                typeof(Texture2D)) as Texture2D;

            titleContent = new GUIContent("Block Helper", icon);

            suggestedAsstesTex =
                Resources.Load(
                    EditorGUIUtility.isProSkin ? "Blockout/UI_Icons/Blockout_Suggested_Assets_Light" : "Blockout/UI_Icons/Blockout_Suggested_Assets",
                    typeof(Texture2D)) as Texture2D;

            sceneFavouritesTex =
                Resources.Load(
                    EditorGUIUtility.isProSkin ? "Blockout/UI_Icons/Blockout_Scene_Favourites_Light" : "Blockout/UI_Icons/Blockout_Scene_Favourites",
                    typeof(Texture2D)) as Texture2D;

            logoSkin = (GUISkin)Resources.Load(EditorGUIUtility.isProSkin ? "Blockout/UI_Icons/BlockoutEditorSkinLight" : "Blockout/UI_Icons/BlockoutEditorSkin", typeof(GUISkin));

            SceneView.onSceneGUIDelegate += OnScene;
            bottomBarRect      = position;
            bottomBarRect.yMin = bottomBarRect.yMax - bottomBarHieght;

            parentWindow = BlockoutEditorWindow.Instance;
            windowCount++;

            if (!parentWindow)
            {
                Debug.LogError("Blockout Window Required To Be Active!");
                this.Close();
            }

            if (windowCount > 1)
            {
                Close();
            }
        }
示例#2
0
 public static void Awake(BlockoutEditorWindow targetWindow_)
 {
     targetWindow = targetWindow_;
     SceneView.onSceneGUIDelegate += OnScene;
 }
示例#3
0
 public static void Awake()
 {
     targetWindow = BlockoutEditorWindow.Instance;
     SceneView.onSceneGUIDelegate += OnScene;
 }
示例#4
0
        static EditorHotkeysTracker()
        {
            SceneView.onSceneGUIDelegate += view =>
            {
                var e = Event.current;
                if (e != null && e.keyCode != KeyCode.None)
                {
                    if (e.control && e.alt && e.keyCode == KeyCode.B && e.type == EventType.KeyDown)
                    {
                        if (!BlockoutEditorWindow.isVisible)
                        {
                            BlockoutEditorWindow.Init();
                        }
                        else
                        {
                            EditorWindow.GetWindow <BlockoutEditorWindow>().Close();
                            SceneView.currentDrawingSceneView.Focus();
                        }
                    }

                    if (e.alt && e.keyCode == KeyCode.S && e.type == EventType.KeyDown)
                    {
                        if (BlockoutEditorWindow.isVisible)
                        {
                            var window = BlockoutEditorWindow.Instance;
                            window.Focus();
                            window.doSnapPosition = !window.doSnapPosition;
                            SceneView.currentDrawingSceneView.Focus();
                        }
                    }

                    if (e.alt && e.control && e.keyCode == KeyCode.Z && e.type == EventType.KeyDown)
                    {
                        if (BlockoutEditorWindow.isVisible)
                        {
                            var window = BlockoutEditorWindow.Instance;
                            window.Focus();
                            window.DecreaseSnapValue();
                            SceneView.currentDrawingSceneView.Focus();
                        }
                    }
                    if (e.alt && e.control && e.keyCode == KeyCode.X && e.type == EventType.KeyDown)
                    {
                        if (BlockoutEditorWindow.isVisible)
                        {
                            var window = BlockoutEditorWindow.Instance;
                            window.Focus();
                            window.IncreaseSnapValue();
                            SceneView.currentDrawingSceneView.Focus();
                        }
                    }

                    if (e.keyCode == KeyCode.End && e.type == EventType.KeyDown)
                    {
                        var window     = BlockoutEditorWindow.Instance;
                        var tempDoSnap = window.doSnapPosition;
                        if (tempDoSnap)
                        {
                            window.doSnapPosition = !window.doSnapPosition;
                        }
                        window.Snap(Vector3.down, BlockoutAxis.Y, true);
                        if (tempDoSnap)
                        {
                            window.doSnapPosition = !window.doSnapPosition;
                        }
                    }

                    if (e.alt && e.keyCode == KeyCode.C && e.type == EventType.KeyDown)
                    {
                        var window = BlockoutEditorWindow.Instance;
                        window.showCommentsBox = !window.showCommentsBox;
                        SceneView.currentDrawingSceneView.Focus();
                    }

                    if (e.keyCode == KeyCode.G && e.type == EventType.KeyDown)
                    {
                        BlockoutEditorWindow.SelectAsset();
                    }
                }
            };
        }
示例#5
0
 public static void Init(BlockoutEditorWindow targetEditor_)
 {
     targetEditor = targetEditor_;
     SceneView.onSceneGUIDelegate += OnScene;
 }
示例#6
0
        private static void OnScene(SceneView view)
        {
            var e = Event.current;

            if (!targetEditor)
            {
                targetEditor = EditorWindow.GetWindow <BlockoutEditorWindow>();
            }

            if (e.control && e.alt && e.keyCode == KeyCode.B && e.type == EventType.KeyDown)
            {
                if (!BlockoutEditorWindow.isVisible)
                {
                    BlockoutEditorWindow.Init();
                    e.Use();
                }
                else
                {
                    targetEditor.Close();
                    SceneView.currentDrawingSceneView.Focus();
                    e.Use();
                }
            }

            if (!targetEditor)
            {
                return;
            }


            if (e != null && e.delta != Vector2.zero && e.type == EventType.ScrollWheel && scrollPicker)
            {
                SceneView.lastActiveSceneView.size = size;
                amount += e.delta.y;
                if (amount >= 5.0f && targetEditor.suggestedSection.shownItems.Count > 0)
                {
                    int first = targetEditor.suggestedSection.shownItems[0];
                    targetEditor.suggestedSection.shownItems.RemoveAt(0);
                    targetEditor.suggestedSection.shownItems.Add(first);
                    amount -= 5f;
                }
                else if (amount <= -5f && targetEditor.suggestedSection.shownItems.Count > 0)
                {
                    int last =
                        targetEditor.suggestedSection
                        .shownItems[targetEditor.suggestedSection.shownItems.Count - 1];
                    targetEditor.suggestedSection.shownItems
                    .RemoveAt(targetEditor.suggestedSection.shownItems.Count - 1);
                    targetEditor.suggestedSection.shownItems.Insert(0, last);
                    amount += 5f;
                }
                e.Use();
                SceneView.lastActiveSceneView.Repaint();
            }

            else if (e != null && e.keyCode != KeyCode.None)
            {
                // Snapping Toggle
                if (e.alt && e.keyCode == KeyCode.S && e.type == EventType.KeyDown)
                {
                    if (BlockoutEditorWindow.isVisible)
                    {
                        BlockoutEditorSettings.AutoSnap = !BlockoutEditorSettings.AutoSnap;
                        targetEditor.Repaint();
                        SceneView.currentDrawingSceneView.Focus();
                        e.Use();
                    }
                }
                // Increase snap value
                else if (e.alt && e.control && e.keyCode == KeyCode.Z && e.type == EventType.KeyDown)
                {
                    if (BlockoutEditorWindow.isVisible)
                    {
                        var window = targetEditor;
                        window.gridSnapping.IncreaseSnapValue();
                        targetEditor.Repaint();
                        SceneView.currentDrawingSceneView.Focus();
                        e.Use();
                    }
                }
                // Decrease Snap Value
                else if (e.alt && e.control && e.keyCode == KeyCode.X && e.type == EventType.KeyDown)
                {
                    if (BlockoutEditorWindow.isVisible)
                    {
                        var window = targetEditor;
                        window.gridSnapping.DecreaseSnapValue();
                        targetEditor.Repaint();
                        SceneView.currentDrawingSceneView.Focus();
                        e.Use();
                    }
                }
                // Snap To Floor
                else if (e.keyCode == KeyCode.End && e.type == EventType.KeyDown)
                {
                    var tempDoSnap = BlockoutEditorSettings.AutoSnap;
                    if (tempDoSnap)
                    {
                        BlockoutEditorSettings.AutoSnap = !BlockoutEditorSettings.AutoSnap;
                    }
                    BlockoutStaticFunctions.Snap(Vector3.down, BlockoutAxis.Y, true);
                    if (tempDoSnap)
                    {
                        BlockoutEditorSettings.AutoSnap = !BlockoutEditorSettings.AutoSnap;
                    }
                    e.Use();
                }
                // Toggle Comments
                else if (e.alt && e.keyCode == KeyCode.C && e.type == EventType.KeyDown)
                {
                    if (BlockoutEditorWindow.isVisible)
                    {
                        var window = targetEditor;
                        window.commentsSection.showSection = !window.commentsSection.showSection;
                        if (window.commentsSection.showSection)
                        {
                            window.commentsSection.showSceneInformation = true;
                        }
                        SceneView.currentDrawingSceneView.Focus();
                        e.Use();
                    }
                }
                // Initialise Quick Picker
                else if (e.keyCode == KeyCode.C && e.type == EventType.KeyDown && !scrollPicker)
                {
                    if (Selection.activeGameObject)
                    {
                        scrollPicker = true;
                        size         = SceneView.lastActiveSceneView.size;
                        Selection.activeGameObject.GetComponent <Collider>().enabled = false;
                        targetEditor.suggestedSection.InitialiseScrollPicker();
                    }
                    e.Use();
                }
                else if (e.keyCode == KeyCode.Space && e.type == EventType.KeyDown)
                {
                    if (!quickPicker && !scrollPicker)
                    {
                        quickPicker = true;
                        targetEditor.suggestedSection.InitialiseQuickPicker();
                        e.Use();
                    }
                    else if (scrollPicker)
                    {
                        scrollPicker = false;
                        targetEditor.suggestedSection.ConfirmSpawn();
                        e.Use();
                    }
                }
                else if (e.keyCode == KeyCode.Escape && e.type == EventType.KeyDown && quickPicker)
                {
                    quickPicker = false;
                    targetEditor.suggestedSection.CancelQickpicker();
                    e.Use();
                }
                else if (e.keyCode == KeyCode.C && e.type == EventType.KeyUp && scrollPicker)
                {
                    scrollPicker = false;
                    targetEditor.suggestedSection.ConfirmSwap();
                    e.Use();
                }
                else if (e.keyCode == KeyCode.Space && e.type == EventType.KeyUp && scrollPicker && !quickPicker)
                {
                    scrollPicker = false;
                    targetEditor.suggestedSection.ConfirmSwap();
                    e.Use();
                }
                else if (e.alt && e.keyCode == KeyCode.Space && e.type == EventType.KeyUp && scrollPicker)
                {
                    scrollPicker = false;
                    targetEditor.suggestedSection.ConfirmSpawn();
                    e.Use();
                }
                // Select asset
                else if (e.keyCode == KeyCode.G && e.type == EventType.KeyDown)
                {
                    BlockoutStaticFunctions.SelectAsset();
                    e.Use();
                }
                // Lock selected
                else if (e.keyCode == KeyCode.L && e.type == EventType.KeyDown)
                {
                    Selection.gameObjects.Where(x => x.GetComponent <BlockoutHelper>())
                    .Select(x => x.GetComponent <BlockoutHelper>()).ToList()
                    .ForEach(x => x.SetLock(!x.Locked));
                    e.Use();
                }



                if (quickPicker)
                {
                    if (e.keyCode == KeyCode.LeftArrow && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.selected--;
                        targetEditor.suggestedSection.scroll.y =
                            (float)targetEditor.suggestedSection.selected / (float)targetEditor.suggestedSection.SuggestedItemCount;
                        e.Use();
                    }
                    else if (e.keyCode == KeyCode.RightArrow && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.selected++;
                        targetEditor.suggestedSection.scroll.y =
                            (float)targetEditor.suggestedSection.selected / (float)targetEditor.suggestedSection.SuggestedItemCount;
                        e.Use();
                    }
                    else if (e.keyCode == KeyCode.UpArrow && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.selected -= targetEditor.suggestedSection.maxPerRow;
                        targetEditor.suggestedSection.scroll.y  =
                            (float)targetEditor.suggestedSection.selected / (float)targetEditor.suggestedSection.SuggestedItemCount;
                        e.Use();
                    }
                    else if (e.keyCode == KeyCode.DownArrow && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.selected += targetEditor.suggestedSection.maxPerRow;
                        targetEditor.suggestedSection.scroll.y  =
                            (float)targetEditor.suggestedSection.selected / (float)targetEditor.suggestedSection.SuggestedItemCount;
                        e.Use();
                    }

                    else if ((e.keyCode == KeyCode.Space || e.keyCode == KeyCode.Return) && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.SpawnSelected(targetEditor.suggestedSection.selected);
                        targetEditor.suggestedSection.scroll.y =
                            (float)targetEditor.suggestedSection.selected / (float)targetEditor.suggestedSection.SuggestedItemCount;
                        e.Use();
                    }
                    else if (e.keyCode == KeyCode.Escape && e.type == EventType.KeyDown)
                    {
                        targetEditor.suggestedSection.CancelQickpicker();
                        e.Use();
                    }
                }
            }
        }