Exemple #1
0
    public static void Open()
    {
        StateEditorWindow window = GetWindow <StateEditorWindow>("State Editor");

        window.my = (StateDataBase)AssetDatabase.LoadAssetAtPath("Assets/DataBase/Data_States.asset", typeof(StateDataBase));
        window.SetStyle();
    }
Exemple #2
0
        public static bool GetStateClickPoint(State state, out Quaternion quaternion)
        {
            quaternion = default;
            if (Event.current.type != EventType.MouseDown || Event.current.button != 0)
            {
                return(false);
            }
            GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
            Event.current.Use();

            SphereCollider collider = state.GetComponent <SphereCollider>();
            Ray            ray      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            ray.origin -= ray.direction * collider.radius * 4;

            if (collider.Raycast(ray, out RaycastHit hit, 100.0f))
            {
                var toCenterDirection = state.transform.position - hit.point;
                var rightDirection    = Vector3.Cross(toCenterDirection, ray.direction);
                var normal            = Vector3.Cross(rightDirection, ray.direction);
                var hitPosition       = state.transform.position + StateEditorWindow.ReflectDirection(toCenterDirection, normal);

                Undo.RecordObject(state, "Undo orientation change");

                quaternion = Quaternion.FromToRotation(Vector3.forward,
                                                       hitPosition - state.transform.position);
                return(true);
            }
            return(false);
        }
Exemple #3
0
    public static void Open(StateDataBase Content)
    {
        StateEditorWindow window = GetWindow <StateEditorWindow>("State Editor");

        window.my = Content;
        window.SetStyle();
    }
Exemple #4
0
 public override void OnInspectorGUI()
 {
     //base.OnInspectorGUI();
     if (GUILayout.Button("Open Editor"))
     {
         StateEditorWindow.Open((StateDataBase)target);
     }
 }
 public static void Open()
 {
     ItemEditorWindow.Open();
     StateEditorWindow.Open();
     TraitEditorWindow.Open();
     RaceEditorWindow.Open();
     ClassEditorWindow.Open();
     ShopEditorWindow.Open();
 }
Exemple #6
0
    void Initialize()
    {
        //TODO if anything
        entityInfoEditor = CreateWindow <EntityEditedInfoWindow>(GetType());
        stateInfoEditor  = CreateWindow <StateEditorWindow>(GetType(), entityInfoEditor.GetType());

        entityInfoEditor.Initialize(this, stateInfoEditor);
        stateInfoEditor.Initialize(this, entityInfoEditor);

        entityInfoEditor.OnEditedEntityChanged -= OnEntityEditedChanged;
        entityInfoEditor.OnEditedEntityChanged += OnEntityEditedChanged;

        entityInfoEditor.OnEntityReloaded -= OnEntityEditedChanged;
        entityInfoEditor.OnEntityReloaded += OnEntityEditedChanged;

        changed = false;

        Nodes       = new List <EditorStateNode>();
        Transitions = new List <EditorTransition>();
    }
Exemple #7
0
    private static void SceneGui(SceneView sceneView)
    {
        if (!EditableItem || !EditableState)
        {
            return;
        }

        Handles.color = CubeColor;
        Handles.DrawWireCube(
            EditableState.transform.position + EditableItem.orientation * Vector3.forward,
            Vector3.one * 0.2f
            );

        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
            GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive);
            Event.current.Use();

            SphereCollider collider = EditableState.GetComponent <SphereCollider>();
            Ray            ray      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            //if ((state.transform.position - ray.origin).magnitude <= collider.radius * collider.radius)
            ray.origin -= ray.direction * collider.radius * 4;

            if (collider.Raycast(ray, out RaycastHit hit, 100.0f))
            {
                var toCenterDirection = EditableState.transform.position - hit.point;
                var rightDirection    = Vector3.Cross(toCenterDirection, ray.direction);
                var normal            = Vector3.Cross(rightDirection, ray.direction);
                var hitPosition       = EditableState.transform.position + StateEditorWindow.ReflectDirection(toCenterDirection, normal);

                Undo.RecordObject(EditableItem, "Undo orientation change");

                EditableItem.orientation = Quaternion.FromToRotation(Vector3.forward,
                                                                     hitPosition - EditableState.transform.position);
            }
        }
    }
Exemple #8
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--;
        }
    }
 public void Initialize(MovementStateMachineEditor stateMachineEditor, StateEditorWindow stateEditor)
 {
     this.stateMachineEditor = stateMachineEditor;
     this.stateEditor        = stateEditor;
 }