Example #1
0
    //selecting element
        #if UNITY_EDITOR
    public void OnGUI()
    {
        if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
        {
            InstantGuiElement selectedElement = null;
            if (UnityEditor.Selection.activeGameObject != null)
            {
                selectedElement = UnityEditor.Selection.activeGameObject.GetComponent <InstantGuiElement>();
            }

            if (Event.current.isMouse && Event.current.button == 0)
            {
                if (!selectedElement)                 //selecting element only when no element selected. Otherwise it is done from Frame
                {
                    GetComponent <InstantGuiElement>().Point(true);
                    if (pointed != null && pointed.gameObject != null)
                    {
                        UnityEditor.Selection.activeGameObject = pointed.gameObject;
                    }
                    selectedElement = pointed;
                }
            }

            //editing and drawing frame
            if (selectedElement != null)
            {
                if (Event.current.isMouse || Event.current.isKey || Event.current.type == EventType.ValidateCommand)
                {
                    InstantGuiFrame.EditFrame(selectedElement);
                }
                if (InstantGuiFrame.drawFrames && Event.current.type == EventType.Repaint)
                {
                    InstantGuiFrame.DrawFrame(selectedElement);
                }

                //removing element on delete
                if (Event.current.keyCode == KeyCode.Delete)
                {
                    StartCoroutine(selectedElement.YieldAndDestroy());
                }
            }

            //making gui repaint
            if (Event.current.type == EventType.Repaint)
            {
                UnityEditor.EditorUtility.SetDirty(this);
            }
        }
    }