public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty UProp = property.FindPropertyRelative(nameof(UVMatrix.U));
            SerializedProperty VProp = property.FindPropertyRelative(nameof(UVMatrix.V));

            int translationID = GUIUtility.GetControlID(FocusType.Keyboard);
            int scaleID       = GUIUtility.GetControlID(FocusType.Keyboard);
            int rotationID    = GUIUtility.GetControlID(FocusType.Keyboard);

            var uvMatrix = new UVMatrix(UProp.vector4Value, VProp.vector4Value);
            var state    = (UVMatrixState)EditorGUIUtility.GetStateObject(typeof(UVMatrixState), translationID);

            if (!state.initialized || state.uvMatrix.U != uvMatrix.U || state.uvMatrix.V != uvMatrix.V)
            {
                uvMatrix.Decompose(out state.translation, out state.rotation, out state.scale);
                state.uvMatrix    = uvMatrix;
                state.initialized = true;
            }

            var hasLabel = ChiselGUIUtility.LabelHasContent(label);

            var prevIndenLevel = EditorGUI.indentLevel;

            EditorGUI.BeginProperty(position, label, property);
            {
                EditorGUI.BeginChangeCheck();

                var prevMixedValues = EditorGUI.showMixedValue;
                EditorGUI.showMixedValue = property.hasMultipleDifferentValues;

                var translationContent = (label == null) ? GUIContent.none : kTranslationContent;
                var scaleContent       = (label == null) ? GUIContent.none : kScaleContent;
                var rotationContent    = (label == null) ? GUIContent.none : kRotationContent;

                position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, GUIContent.none);
                var fieldRect = EditorGUI.PrefixLabel(position, translationID, !hasLabel ? GUIContent.none : translationContent);
                EditorGUI.indentLevel = 0;
                state.translation     = EditorGUI.Vector2Field(fieldRect, GUIContent.none, state.translation);
                EditorGUI.indentLevel = prevIndenLevel;
                position.y           += position.height + kSpacing;

                position.height       = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, GUIContent.none);
                fieldRect             = EditorGUI.PrefixLabel(position, scaleID, !hasLabel ? GUIContent.none : scaleContent);
                EditorGUI.indentLevel = 0;
                state.scale           = EditorGUI.Vector2Field(fieldRect, GUIContent.none, state.scale);

                EditorGUI.indentLevel = prevIndenLevel;
                position.y           += position.height + kSpacing;

                position.height       = EditorGUI.GetPropertyHeight(SerializedPropertyType.Float, GUIContent.none);
                fieldRect             = EditorGUI.PrefixLabel(position, rotationID, !hasLabel ? GUIContent.none : rotationContent);
                EditorGUI.indentLevel = 0;
                state.rotation        = EditorGUI.FloatField(fieldRect, GUIContent.none, state.rotation);
                EditorGUI.indentLevel = prevIndenLevel;
                position.y           += position.height + kSpacing;

                EditorGUI.showMixedValue = prevMixedValues;

                if (EditorGUI.EndChangeCheck())
                {
                    state.scale.x = (float)Math.Max(Math.Abs(state.scale.x), UVMatrix.kMinScale) * Math.Sign(state.scale.x);
                    state.scale.y = (float)Math.Max(Math.Abs(state.scale.y), UVMatrix.kMinScale) * Math.Sign(state.scale.y);

                    uvMatrix           = UVMatrix.TRS(state.translation, state.rotation, state.scale);
                    UProp.vector4Value = uvMatrix.U;
                    VProp.vector4Value = uvMatrix.V;
                    state.uvMatrix     = uvMatrix;
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
            EditorGUI.EndProperty();

            /*
             *
             * SerializedProperty UxProp   = property.FindPropertyRelative($"{nameof(UVMatrix.U)}.{nameof(UVMatrix.U.x)}");
             * SerializedProperty VxProp   = property.FindPropertyRelative($"{nameof(UVMatrix.V)}.{nameof(UVMatrix.V.x)}");
             *
             * EditorGUI.BeginProperty(position, label, property);
             * {
             *  position.height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector4, GUIContent.none);
             *  position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Keyboard), label);
             *
             *  EditorGUI.MultiPropertyField(position, xyzw, UxProp);
             *  position.y += position.height + kSpace;
             *
             *  EditorGUI.MultiPropertyField(position, xyzw, VxProp);
             * }
             * EditorGUI.EndProperty();
             */
        }
예제 #2
0
    private void OnGUI()
    {
        CheckDialogue();

        if (!dialogue)
        {
            GUILayout.Label("This object has no Dialogues component");
            return;
        }

        CheckConnections();

        if (BackgroundTexture == null)
        {
            MakeTextures();
        }

        if (dialogue.TreeCount == 0)
        {
            GUIStyle Style = GUI.skin.GetStyle("Label");
            Style.alignment = TextAnchor.MiddleCenter;

            GUILayout.Label("\n\nThere are no existing Dialogue Trees\nClick the 'New' button to add a tab", Style);
        }
        else
        {
            //Creates large scroll view for the work area
            ScrollPosition = GUI.BeginScrollView(new Rect(0, 0, position.width, position.height),
                                                 ScrollPosition, new Rect(Vector2.zero, WorkSize), GUIStyle.none, GUIStyle.none);
            //Makes the background a dark gray
            GUI.DrawTexture(new Rect(0, 0, WorkSize.x, WorkSize.y), BackgroundTexture, ScaleMode.StretchToFill);
            Handles.BeginGUI();

            //Draws the small, light squares all over the work area
            int Count = 0;
            while ((Count * 10) < WorkSize.x)
            {
                EditorGUI.DrawRect(new Rect(Count * 10, 0, 2, WorkSize.y), SmallLines);
                Count++;
            }
            Count = 0;
            while ((Count * 10) < WorkSize.y)
            {
                EditorGUI.DrawRect(new Rect(0, Count * 10, WorkSize.x, 2), SmallLines);
                Count++;
            }

            //Draws the larger, thicker lines on the work area
            for (int i = 0; i < WorkSize.x / 100; i++)
            {
                EditorGUI.DrawRect(new Rect(i * 100, 0, 2, WorkSize.y), BigLines);
            }
            for (int i = 0; i < WorkSize.y / 100; i++)
            {
                EditorGUI.DrawRect(new Rect(0, i * 100, WorkSize.x, 2), BigLines);
            }

            DrawConnections(Color.white);

            Handles.EndGUI();

            BeginWindows();
            ClearIds();

            BuildWindows();

            if (isNewWindowShow)
            {
                NewTree = GUI.Window(99999, NewTree, AddNewTree, "Add New Dialogue Tree");
            }

            EndWindows();

            GUI.EndScrollView();
            GUILayout.BeginArea(new Rect(0, 20, Screen.width, 20));
            dialogue.TreeIndex = GUILayout.Toolbar(dialogue.TreeIndex, dialogue.TabsNames);
            GUILayout.EndArea();

            if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition))
            {
                if (Event.current.button == 1)
                {
                    GenericMenu Menu = new GenericMenu();

                    BuildMenus(Menu);
                    if (CheckDialogueExists())
                    {
                        Menu.AddItem(new GUIContent("Save Changes"), false, SaveChanges);
                        Menu.AddItem(new GUIContent(""), false, () => { });
                        Menu.AddItem(new GUIContent("Clear All"), false, Clear);
                    }
                    Menu.ShowAsContext();
                }
            }

            if (new Rect(0, 0, position.width, position.height).Contains(Event.current.mousePosition))
            {
                if (Event.current.button == 2 && Event.current.type == EventType.MouseDrag)
                {
                    Vector2 CurrentPos = Event.current.mousePosition;

                    if (Vector2.Distance(CurrentPos, PreviousPosition) < 50)
                    {
                        float x = PreviousPosition.x - CurrentPos.x;
                        float y = PreviousPosition.y - CurrentPos.y;

                        ScrollPosition.x += x;
                        ScrollPosition.y += y;
                        Event.current.Use();
                    }
                    PreviousPosition = CurrentPos;
                }
            }
        }

        //Extra layouts
        GUILayout.BeginArea(new Rect(0, 0, Screen.width, 50));
        GUILayout.BeginHorizontal("GUIEditor.BreadcrumbLeft");
        if (GUILayout.Button("New Dialogue Tree", new GUIStyle("TE toolbarbutton"), GUILayout.Width(150), GUILayout.Height(18)))
        {
            NewTree         = new Rect(50 + ScrollPosition.x, 50 + ScrollPosition.y, 400, 150);
            NewTreeName     = "";
            NewTreeInfo     = "";
            isNewWindowShow = true;
        }

        if (GUILayout.Button("Remove Tree", new GUIStyle("TE toolbarbutton"), GUILayout.Width(100), GUILayout.Height(18)))
        {
            if (dialogue.TreeCount > 0)
            {
                dialogue.RemoveCurrentTree();
            }
        }

        GUILayout.EndHorizontal();
        GUILayout.EndArea();


        if (isNewWindowShow && dialogue.TreeCount == 0)
        {
            BeginWindows();
            NewTree = GUI.Window(99999, NewTree, AddNewTree, "Add New Dialogue Tree");
            EndWindows();
        }

        //Found this easy cut/copy/paste solution from http://answers.unity3d.com/questions/181333/how-can-i-add-copy-and-paste-support-for-my-editor.html
        TextEditor textEditor = EditorGUIUtility.GetStateObject(typeof(TextEditor), EditorGUIUtility.keyboardControl) as TextEditor;

        if (textEditor != null)
        {
            if (focusedWindow == this)
            {
                if (Event.current.control)
                {
                    switch (Event.current.keyCode)
                    {
                    case KeyCode.X:
                        textEditor.Cut();
                        break;

                    case KeyCode.C:
                        textEditor.Copy();
                        break;

                    case KeyCode.V:
                        textEditor.Paste();
                        break;
                    }
                }
            }
        }
    }