Exemplo n.º 1
0
    void OnSelectionChange()
    {
        Initialize();
        Trigger selectedTrigger = null;

        Trigger[] selectedTriggers = Selection.activeGameObject.GetComponentsInParent <Trigger>(true);
        if (selectedTriggers.Length != 0)
        {
            selectedTrigger = selectedTriggers[0];
        }

        if (selectedTrigger && selectedTrigger != _eventEditorContext.SelectedTrigger)
        {
            _eventEditorContext.SelectTrigger(selectedTrigger);
        }
        Repaint();
    }
Exemplo n.º 2
0
    private void DrawTriggerNode()
    {
        Color defaultColor = GUI.skin.button.normal.textColor;

        GUI.skin.button.fontStyle        = GameObject.activeInHierarchy ? FontStyle.Normal : FontStyle.Italic;
        GUI.skin.button.normal.textColor = GameObject.activeInHierarchy ? defaultColor : new Color(0.55f, 0.55f, 0.55f, 1.0f);

        Trigger.Enabled = GUILayout.Toggle(Trigger.Enabled, "", GUILayout.ExpandWidth(false));
        if (this.GameObject == _overviewContext.CurrentlyRenaming)
        {
            GameObject.name = GUILayout.TextField(GameObject.name, GUILayout.ExpandWidth(false));
            if (Event.current.isKey && Event.current.keyCode == KeyCode.Return || Event.current.type == EventType.MouseDown)// && !GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
            {
                _overviewContext.CurrentlyRenaming = null;
                _context.Refresh();
                Event.current.Use();
            }
        }
        else
        {
            if (_context.SelectedTrigger == Trigger)
            {
                GUI.skin.button.normal.textColor = new Color(1.0f, 0.45f, 0.45f, 1.0f);
                GUI.SetNextControlName("FakeButton" + GameObject.GetInstanceID());
                GUILayout.Label(GameObject.name, GUI.skin.button, GUILayout.ExpandWidth(false));
            }
            else
            {
                GUI.skin.button.fontStyle        = FontStyle.Normal;
                GUI.skin.button.normal.textColor = defaultColor;
                GUI.SetNextControlName("FakeButton" + GameObject.GetInstanceID());
                GUILayout.Label(GameObject.name, GUI.skin.button, GUILayout.ExpandWidth(false));
            }
            bool useEvent  = false;
            Rect labelRect = GUILayoutUtility.GetLastRect();
            if (Event.current.type == EventType.MouseDrag && labelRect.Contains(Event.current.mousePosition))
            {
                if (_buttonDown)
                {
                    _buttonDown = false;
                    DragAndDrop.PrepareStartDrag();
                    DragAndDrop.StartDrag("Draggingwtf?");
                    DragAndDrop.objectReferences = new UnityEngine.Object[] { GameObject };
                    useEvent = true;
                }
            }
            if (Event.current.type == EventType.MouseDown && labelRect.Contains(Event.current.mousePosition))
            {
                _buttonDown = true;
                useEvent    = true;
                GUI.FocusControl("FakeButton" + +GameObject.GetInstanceID());
            }
            if (_buttonDown && Event.current.type == EventType.MouseUp && labelRect.Contains(Event.current.mousePosition))
            {
                _buttonDown    = false;
                _buttonPressed = true;
                useEvent       = true;
            }
            if (_buttonPressed && Event.current.type == EventType.MouseUp && labelRect.Contains(Event.current.mousePosition))
            {
                _buttonPressed = false;
                _context.SelectTrigger(Trigger);
                _context.Repaint = true;
                if (Event.current.button == 1)
                {
                    Vector2 mousePosition = Event.current.mousePosition;
                    EditorUtility.DisplayCustomMenu(new Rect(mousePosition.x, mousePosition.y - 300, 100, 300), _triggerContextOptions, -1, TriggerContextMenuFunction, this);
                }
                useEvent = true;
            }

            if (useEvent)
            {
                _context.Repaint = true;
                Event.current.Use();
            }
        }

        GUI.skin.button.normal.textColor = defaultColor;
        GUI.skin.button.fontStyle        = FontStyle.Normal;
    }