private static void RenderPositionVertexes(State state, FieldItem fieldItem)
 {
     EditorGUILayout.BeginHorizontal();
     GUILayout.Space(EditorGUI.indentLevel * 15);
     for (int i = 0; i < fieldItem.vertices.Length; i++)
     {
         var vertex      = fieldItem.vertices[i];
         var buttonStyle = Styles.ToggleButtonStyleNormal;
         if (StateItemPlaceEditor.EditableItem == (object)vertex)
         {
             buttonStyle = Styles.ToggleButtonStyleToggled;
         }
         if (GUILayout.Button(vertex.index.ToString(), buttonStyle))
         {
             if (StateItemPlaceEditor.EditableItem == (object)vertex)
             {
                 StateItemPlaceEditor.CleadEditing();
             }
             else
             {
                 StateItemPlaceEditor.EnableEditing(state, vertex, Color.green);
             }
         }
     }
     EditorGUILayout.EndHorizontal();
 }
Exemplo n.º 2
0
    public void Draw(State state)
    {
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add"))
        {
            Undo.AddComponent <ContentItem>(state.gameObject);
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        foreach (var item in state.GetComponents <ContentItem>())
        {
            var titleName = GetTitleStringOf(item.name);
            if (item.isOpened = EditorGUILayout.Foldout(item.isOpened, titleName, true))
            {
                Undo.RecordObject(item, "Edit state item name");
                item.name = EditorGUILayout.TextField("Name", item.name);

                var buttonStyle = Styles.ToggleButtonStyleNormal;
                if (StateItemPlaceEditor.EditableItem == item)
                {
                    buttonStyle = Styles.ToggleButtonStyleToggled;
                }

                if (GUILayout.Button("edit", buttonStyle))
                {
                    if (StateItemPlaceEditor.EditableItem == item)
                    {
                        StateItemPlaceEditor.CleadEditing();
                    }
                    else
                    {
                        StateItemPlaceEditor.EnableEditing(state, item, Color.green);
                    }
                }

                if (GUILayout.Button("delete", Styles.DeleteButtonStyle))
                {
                    Undo.DestroyObjectImmediate(item);
                }
            }
            EditorGUILayout.Space();
        }
    }
Exemplo n.º 3
0
    public void Draw(State state)
    {
        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");
            groupConnection.title = EditorGUILayout.TextField("Title:", groupConnection.title);

            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]);
                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);
                }

                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();
            }
            EditorGUI.indentLevel--;
            EditorGUI.indentLevel--;
        }
    }
Exemplo n.º 4
0
    private void DrawStateEditPageGUI()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }

        var state = _selectedStates[0];

        if (_connectionsEditMode)
        {
            TourEditor.StateGraphRenderer.targetState = state;
        }

        // Draw title edit field
        GUILayout.Label("State title: ", EditorStyles.boldLabel);
        state.title = EditorGUILayout.TextField(state.title);
        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);
        }



        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);
        }

        fieldItemsOpened = EditorGUILayout.Foldout(fieldItemsOpened, "Field items", true);
        if (fieldItemsOpened)
        {
            fieldItemEditor.Draw(state);
        }
        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();
    }
    private void DrawStateEditPageGUI()
    {
        if (EditorApplication.isPlaying)
        {
            return;
        }

        var state = _selectedStates[0];

        if (_connectionsEditMode)
        {
            TourEditor.StateGraphRenderer.targetState = state;
        }

        // Draw title edit field
        GUILayout.Label("State title: ", EditorStyles.boldLabel);
        state.title = EditorGUILayout.TextField(state.title);
        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);
        }



        GUILayout.EndHorizontal();

        // Draw edit mode toggle
        GUIStyle editModeButtonStyle = _connectionsEditMode ? Styles.ToggleButtonStyleToggled : Styles.ToggleButtonStyleNormal;

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

            _connectionsEditMode = !_connectionsEditMode;
        }

        EditorGUILayout.Space();

        // Draw connections list
        connectionsOpened = EditorGUILayout.Foldout(connectionsOpened, "Connections: ", true);
        if (connectionsOpened)
        {
            itemsOpened = false;

            _connectionsListScroll = EditorGUILayout.BeginScrollView(_connectionsListScroll);

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

            foreach (var connection in connections)
            {
                if (connection.Destination == null)
                {
                    continue;
                }
                GUILayout.Label(connection.Destination.title, EditorStyles.boldLabel);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("move to"))
                {
                    FocusCamera(connection.Destination.gameObject);
                    SelectObject(connection.Destination.gameObject);
                }

                var buttonStyle = Styles.ToggleButtonStyleNormal;
                if (StateItemPlaceEditor.EditableItem == connection)
                {
                    buttonStyle = Styles.ToggleButtonStyleToggled;
                }

                if (GUILayout.Button("edit", buttonStyle))
                {
                    if (StateItemPlaceEditor.EditableItem == connection)
                    {
                        StateItemPlaceEditor.CleadEditing();
                    }
                    else
                    {
                        StateItemPlaceEditor.EnableEditing(state, connection, Color.green);
                    }
                }
                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());
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndScrollView();
        }

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

        // 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();
    }
        public void Draw(State state)
        {
            if (GUILayout.Button("Add"))
            {
                FieldItem item = Undo.AddComponent <FieldItem>(state.gameObject);
                item.Reset();
            }
            EditorGUILayout.Space();

            var fieldItems = state.GetComponents <FieldItem>();

            foreach (var fieldItem in fieldItems)
            {
                EditorGUILayout.BeginHorizontal();

                var fieldItemTitle = GetTitleStringOf(fieldItem.title);
                GUILayout.Label(fieldItemTitle, EditorStyles.boldLabel);

                if (GUILayout.Button("Reset"))
                {
                    fieldItem.Reset();
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel++;

                Undo.RecordObject(fieldItem, "Edit fieldItem title");

                fieldItem.title = EditorGUILayout.TextField("Title:", fieldItem.title);

                EditorGUILayout.LabelField("Corners:");
                EditorGUILayout.BeginHorizontal();

                for (int i = 0; i < fieldItem.vertices.Length; i++)
                {
                    var vertex      = fieldItem.vertices[i];
                    var buttonStyle = Styles.ToggleButtonStyleNormal;
                    if (StateItemPlaceEditor.EditableItem == (object)vertex)
                    {
                        buttonStyle = Styles.ToggleButtonStyleToggled;
                    }
                    if (GUILayout.Button(vertex.index.ToString(), buttonStyle))
                    {
                        if (StateItemPlaceEditor.EditableItem == (object)vertex)
                        {
                            StateItemPlaceEditor.CleadEditing();
                        }
                        else
                        {
                            StateItemPlaceEditor.EnableEditing(state, vertex, Color.green);
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();

                string[] content   = Enum.GetNames(typeof(FieldItem.ContentType));
                int      value_now = (int)fieldItem.contentType;
                fieldItem.contentType = (FieldItem.ContentType)EditorGUILayout.Popup(new GUIContent("Content:"), value_now, content);

                switch (fieldItem.contentType)
                {
                case FieldItem.ContentType.Photo:
                    var previewTexture = fieldItem.texture;
                    if (previewTexture == null)
                    {
                        previewTexture = EditorGUIUtility.whiteTexture;
                    }
                    fieldItem.texture = EditorGUI.ObjectField(EditorGUILayout.GetControlRect(false, 150.0f), fieldItem.texture, typeof(Texture2D), false) as Texture;
                    break;

                case FieldItem.ContentType.Video:
                    var previewVideoClip = fieldItem.videoClip;
                    if (previewVideoClip == null)
                    {
                        previewTexture = EditorGUIUtility.whiteTexture;
                    }
                    fieldItem.videoClip = EditorGUI.ObjectField(EditorGUILayout.GetControlRect(false, 150.0f), fieldItem.videoClip, typeof(VideoClip), false) as VideoClip;
                    break;
                }
            }
        }