Esempio n. 1
0
        public static void SetSyntaxStateGUIColor(SequenceSyntaxState syntaxState)
        {
            switch (syntaxState)
            {
            case SequenceSyntaxState.Valid:
                GUI.color = Color.green;
                break;

            case SequenceSyntaxState.Error:
                GUI.color = Color.red;
                break;
            }
        }
Esempio n. 2
0
        public static string DrawLayout(GUIContent guiContent, string sequence, ref Rect rect, ref SequenceSyntaxState syntaxState)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(guiContent);
            EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(sequence));
            if (GUILayout.Button(new GUIContent("Check", "Check sequence for errors."), EditorStyles.miniButton, GUILayout.Width(52)))
            {
                syntaxState = CheckSyntax(sequence);
            }
            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginChangeCheck();

            if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(26)))
            {
                DrawContextMenu(sequence);
            }
            EditorGUILayout.EndHorizontal();
            if (menuResult != MenuResult.Unselected)
            {
                sequence   = ApplyMenuResult(menuResult, sequence);
                menuResult = MenuResult.Unselected;
            }

            //EditorWindowTools.StartIndentedSection(); // Removed indent; looks better without.

            SetSyntaxStateGUIColor(syntaxState);

            var newSequence = EditorGUILayout.TextArea(sequence);

            ClearSyntaxStateGUIColor();
            if (!string.Equals(newSequence, sequence))
            {
                sequence    = newSequence;
                GUI.changed = true;
            }

            switch (Event.current.type)
            {
            case EventType.Repaint:
                rect = GUILayoutUtility.GetLastRect();
                break;

            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (rect.Contains(Event.current.mousePosition))
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    if (Event.current.type == EventType.DragPerform)
                    {
                        DragAndDrop.AcceptDrag();
                        foreach (var obj in DragAndDrop.objectReferences)
                        {
                            if (obj is AudioClip)
                            {
                                // Drop audio clip according to selected audio command:
                                var clip = obj as AudioClip;
                                var path = AssetDatabase.GetAssetPath(clip);
                                if (path.Contains("Resources"))
                                {
                                    sequence    = AddCommandToSequence(sequence, GetCurrentAudioCommand() + "(" + GetResourceName(path) + ")");
                                    GUI.changed = true;
                                }
                                else if (GetCurrentAudioCommand() == "LipSync")
                                {
                                    sequence    = AddCommandToSequence(sequence, GetCurrentAudioCommand() + "(" + System.IO.Path.GetFileNameWithoutExtension(path) + ")");
                                    GUI.changed = true;
                                }
                                else
                                {
                                    EditorUtility.DisplayDialog("Not in Resources Folder", "To use drag-n-drop, audio clips must be located in the hierarchy of a Resources folder.", "OK");
                                }
                            }
                            else if (obj is GameObject)
                            {
                                // Drop GameObject.
                                var go = obj as GameObject;
                                if (sequence.EndsWith("("))
                                {
                                    // If sequence ends in open paren, add GameObject and close:
                                    sequence += go.name + ")";
                                }
                                else
                                {
                                    // Drop GameObject according to selected GameObject command:
                                    var command = Event.current.alt ? alternateGameObjectDragDropCommand : gameObjectDragDropCommand;
                                    sequence = AddCommandToSequence(sequence, GetCurrentGameObjectCommand(command, go.name));
                                }
                                GUI.changed = true;
                            }
                            else if (obj is Component)
                            {
                                // Drop component.
                                var component = obj as Component;
                                var go        = component.gameObject;
                                if (sequence.EndsWith("("))
                                {
                                    // If sequence ends in open paren, add component and close:
                                    sequence += component.GetType().Name + ")";
                                }
                                else
                                {
                                    // Drop component according to selected component command:
                                    var command = Event.current.alt ? alternateComponentDragDropCommand : componentDragDropCommand;
                                    sequence = AddCommandToSequence(sequence, GetCurrentComponentCommand(command, component.GetType().Name, go.name));
                                }
                                GUI.changed = true;
                            }
                        }
                    }
                }
                break;
            }

            // If content changed, reset syntax check state:
            if (EditorGUI.EndChangeCheck())
            {
                syntaxState = SequenceSyntaxState.Unchecked;
            }

            //EditorWindowTools.EndIndentedSection();

            return(sequence);
        }