Exemplo n.º 1
0
    public void Draw(State state, Action repaintAction)
    {
        if (GUILayout.Button("Add"))
        {
            Undo.AddComponent <GroupConnection>(state.gameObject);
        }
        EditorGUILayout.Space();
        var groupConnections = state.GetComponents <GroupConnection>();

        foreach (var groupConnection in groupConnections)
        {
            var groupConnectionTitle = GetTitleStringOf(groupConnection.title);
            GUILayout.Label(groupConnectionTitle, EditorStyles.boldLabel);

            EditorGUI.indentLevel++;

            Undo.RecordObject(groupConnection, "Edit group connection title");
            EditorGUILayout.BeginHorizontal();
            groupConnection.title = SpellCheckHintsContent.DrawTextField(
                $"{groupConnection.GetInstanceID()}_{nameof(groupConnection.title)}",
                "Title",
                groupConnection.title,
                repaintAction,
                n => { groupConnection.title = n; });
            if (Buttons.Delete())
            {
                Undo.DestroyObjectImmediate(groupConnection);
                repaintAction();
                return;
            }
            EditorGUILayout.EndHorizontal();
            var buttonStyle = Styles.ToggleButtonStyleNormal;
            if (StateItemPlaceEditor.EditableItem == (object)groupConnection)
            {
                buttonStyle = Styles.ToggleButtonStyleToggled;
            }

            var isEditable = StateItemPlaceEditor.EditableItem == (object)groupConnection;

            if (GUI.Toggle(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), isEditable, "edit", "Button") != isEditable)
            {
                if (isEditable)
                {
                    StateItemPlaceEditor.CleadEditing();
                }
                else
                {
                    StateItemPlaceEditor.EnableEditing(state, groupConnection, Color.green);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();


            var connections = state.GetComponents <Connection>();

            if (connections.Length > 0)
            {
                if (GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), $"Add connection"))
                {
                    GenericMenu menu = new GenericMenu();

                    foreach (var connection in connections)
                    {
                        menu.AddItem(new GUIContent(connection.Destination.title), false, o =>
                        {
                            var selectedConnection = o as Connection;
                            Undo.RecordObject(groupConnection, "Add state reference");
                            groupConnection.states.Add(selectedConnection.Destination);

                            Undo.DestroyObjectImmediate(selectedConnection);
                        }, connection);
                    }
                    menu.ShowAsContext();
                }
            }
            else
            {
                GUILayout.Label("No available connections to add");
            }

            if (GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), $"Add info"))
            {
                Undo.RecordObject(groupConnection, "Add info reference");
                groupConnection.infos.Add("");
            }
            for (int i = 0; i < groupConnection.infos.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                //groupConnection.infos[i] = EditorGUILayout.TextField("Info title: ", groupConnection.infos[i]);

                groupConnection.infos[i] = SpellCheckHintsContent.DrawTextField(
                    $"{groupConnection.GetInstanceID()}_{nameof(groupConnection.infos)}_{i}",
                    "Info title:",
                    groupConnection.infos[i],
                    repaintAction,
                    n => { groupConnection.infos[i] = n; });

                if (GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(GUILayout.Width(80))), $"Delete", Styles.DeleteButtonStyle))
                {
                    groupConnection.infos.RemoveAt(i);
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("State references:");
            EditorGUI.indentLevel++;
            foreach (var stateReference in groupConnection.states)
            {
                var title = stateReference ? stateReference.title : "No destination";
                EditorGUILayout.LabelField(title);
                var line = EditorGUILayout.BeginHorizontal();

                GUILayout.Space(40);

                if (GUILayout.Button("Move to"))
                {
                    StateEditorWindow.FocusCamera(stateReference.gameObject);
                    Selection.objects = new UnityEngine.Object[] { stateReference.gameObject };
                }

                if (GUILayout.Button("To simple connection"))
                {
                    Undo.RecordObject(groupConnection, "Delete state reference");
                    groupConnection.states.Remove(stateReference);
                    var addedConnection = Undo.AddComponent <Connection>(state.gameObject);
                    addedConnection.Destination = stateReference;
                    break;
                }

                if (Buttons.Delete())
                {
                    Undo.RecordObject(groupConnection, "Delete state reference");
                    groupConnection.states.Remove(stateReference);
                    break;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.BeginHorizontal();
            groupConnection.minimizeScale = EditorGUILayout.Slider(
                "minimize scale",
                groupConnection.minimizeScale,
                1, 5);
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
        }
    }
        private void DrawFieldItem(State state, FieldItem fieldItem, Action repaintAction)
        {
            EditorGUI.indentLevel++;

            Undo.RecordObject(fieldItem, "Edit group connection title");
            EditorGUILayout.BeginHorizontal();

            fieldItem.title = SpellCheckHintsContent.DrawTextField(
                $"{fieldItem.GetInstanceID()}_{nameof(fieldItem.title)}",
                "Title",
                fieldItem.title,
                repaintAction,
                n => { fieldItem.title = n; });

            //fieldItem.title = EditorGUILayout.TextField("Title:", fieldItem.title);
            if (Buttons.Delete())
            {
                Undo.DestroyObjectImmediate(fieldItem);
            }
            EditorGUILayout.EndHorizontal();

            RenderPositionVertexes(state, fieldItem);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUI.indentLevel * 15);
            fieldItem.attachmentsTabIndex = GUILayout.Toolbar(fieldItem.attachmentsTabIndex, new string[] {
                "Images",
                "Video",
                "Text",
                "Audio"
            });
            EditorGUILayout.EndHorizontal();
            var serializedObject = new SerializedObject(fieldItem);

            switch (fieldItem.attachmentsTabIndex)
            {
            case 0:
                var imagesProperty = serializedObject.FindProperty(nameof(fieldItem.images));
                EditorGUILayout.PropertyField(imagesProperty);
                break;

            case 1:
                var videosProperty = serializedObject.FindProperty(nameof(fieldItem.videos));
                EditorGUILayout.PropertyField(videosProperty, new GUIContent("ONLY FIRST VIDEO WILL BE USED! (now)"));
                break;

            case 2:
                var textProperty = serializedObject.FindProperty(nameof(fieldItem.text));
                EditorGUILayout.PropertyField(textProperty);
                break;

            case 3:
                var audiosProperty = serializedObject.FindProperty(nameof(fieldItem.audios));
                EditorGUILayout.PropertyField(audiosProperty, new GUIContent("ONLY FIRST AUDIO WILL BE USED! (now)"));
                break;

            default:
                break;
            }
            serializedObject.ApplyModifiedProperties();
            EditorGUI.indentLevel--;
        }
Exemplo n.º 3
0
    private void DrawStateEditPageGUI()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }

        var state = _selectedStates[0];

        Undo.RecordObject(state, "Change state");
        if (_connectionsEditMode)
        {
            TourEditor.StateGraphRenderer.targetState = state;
        }

        // Draw title edit field
        GUILayout.Label("State title: ", EditorStyles.boldLabel);
        state.title = SpellCheckHintsContent.DrawTextField($"{state.GetInstanceID()}_{nameof(state.title)}", state.title, Repaint, newValue => { state.title = newValue; });

        EditorGUILayout.Space();

        // Draw panorama texture edit field
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Panorama: ", EditorStyles.boldLabel);

        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Change texture source"))
        {
            _textureSourceEditor.ShowContextMenu(state);
        }

        EditorGUILayout.EndHorizontal();

        _textureSourceEditor.Draw(state);

        EditorGUILayout.Space();

        // Draw panorama preview

        var previewTexture = state.GetComponent <TextureSource>().LoadedTexture;

        if (previewTexture == null)
        {
            previewTexture = EditorGUIUtility.whiteTexture;
        }
        EditorGUI.DrawPreviewTexture(EditorGUILayout.GetControlRect(false, 150.0f), previewTexture, null, ScaleMode.ScaleToFit);


        EditorGUILayout.Space();

        GUILayout.Label("Actions: ", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();



        if (GUILayout.Button("Focus camera", GUILayout.Height(50)))
        {
            FocusCamera(state.gameObject);
            SelectObject(state.gameObject);
        }

        if (GUILayout.Button("Open preview", GUILayout.Height(50)))
        {
            var window = EditorWindow.GetWindow <LivePreviewWindow>("Live preview", focus: false);
            window.OpenState(state);
        }


        GUILayout.EndHorizontal();



        if (GUILayout.Toggle(_connectionsEditMode, "Edit mode", "Button", GUILayout.Height(50)) != _connectionsEditMode)
        {
            if (_connectionsEditMode)
            {
                TourEditor.StateGraphRenderer.targetState = null;
            }
            else
            {
                TourEditor.StateGraphRenderer.targetState = state;
            }

            _connectionsEditMode = !_connectionsEditMode;
        }

        EditorGUILayout.Space();

        _itemsScroll = EditorGUILayout.BeginScrollView(_itemsScroll);
        // Draw connections list
        connectionsFromOpened = EditorGUILayout.Foldout(connectionsFromOpened, "Connections from that:", true);
        if (connectionsFromOpened)
        {
            var connections = state.GetComponents <Connection>();
            EditorGUI.indentLevel++;
            foreach (var connection in connections)
            {
                var destinationTitle = connection.GetDestenationTitle() ?? "No destenation";
                EditorGUILayout.LabelField(destinationTitle, EditorStyles.boldLabel);
                EditorGUI.indentLevel++;

                var serializedObject = new SerializedObject(connection);
                EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(connection.Destination)));
                serializedObject.ApplyModifiedProperties();

                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * 20);
                if (connection.Destination)
                {
                    if (GUILayout.Button("move to"))
                    {
                        FocusCamera(connection.Destination.gameObject);
                        SelectObject(connection.Destination.gameObject);
                    }
                    var toggled = StateItemPlaceEditor.EditableItem == (object)connection;
                    if (GUILayout.Toggle(toggled, "edit", "Button") != toggled)
                    {
                        if (StateItemPlaceEditor.EditableItem == (object)connection)
                        {
                            StateItemPlaceEditor.CleadEditing();
                        }
                        else
                        {
                            StateItemPlaceEditor.EnableEditing(state, connection, Color.green);
                        }
                    }
                }
                if (Buttons.Delete())
                {
                    Undo.DestroyObjectImmediate(connection);
                }
                EditorGUILayout.EndHorizontal();

                var schemes     = Tour.Instance.colorSchemes;
                var schemeNames = schemes.Select(s => s.name).ToArray();
                connection.colorScheme = EditorGUILayout.Popup(new GUIContent("Color scheme"), connection.colorScheme, schemeNames.Select(sn => new GUIContent(sn)).ToArray());
                EditorGUI.indentLevel--;
                EditorGUILayout.Space();
            }
            EditorGUI.indentLevel--;
        }

        connectionsToOpened = EditorGUILayout.Foldout(connectionsToOpened, "Connections to that:", true);
        if (connectionsToOpened)
        {
            connectionsToStateEditor.Draw(state);
        }

        groupConnectionsOpened = EditorGUILayout.Foldout(groupConnectionsOpened, "Group connections:", true);
        if (groupConnectionsOpened)
        {
            groupConnectionEditor.Draw(state, Repaint);
        }

        fieldItemsOpened = EditorGUILayout.Foldout(fieldItemsOpened, "Field items", true);
        if (fieldItemsOpened)
        {
            fieldItemEditor.Draw(state, Repaint);
        }
        EditorGUILayout.EndScrollView();

        // TODO Content draw
        //itemsOpened = EditorGUILayout.Foldout(itemsOpened, "Items: ", true);
        //if (itemsOpened)
        //{
        //    connectionsOpened = false;
        //    _connectionsEditMode = false;
        //    TourEditor.StateGraphRenderer.targetState = null;
        //    itemsEditor.Draw(state);
        //}

        EditorGUILayout.Space();

        GUILayout.FlexibleSpace();
    }