private void OnClickAddNode(Vector2 mousePosition, LZFighter fighter)
    {
        /*string path = AssetDatabase.GetAssetPath(fighter);
         * string filename = Path.GetFileNameWithoutExtension(path);
         * string directory = Path.GetDirectoryName(path);
         * if (!AssetDatabase.IsValidFolder(directory + "/" + filename)) {
         *  AssetDatabase.CreateFolder(directory, filename);
         * }*/
        StateMachineNode newState = new StateMachineNode();

        newState.nodeRect.position = mousePosition;
        int id = machine.states.Add(newState);

        if (treePath.Count > 0)
        {
            StateMachineNode parent = machine.states[treePath[treePath.Count - 1]];
            newState.parent = treePath[treePath.Count - 1];
            parent.containedNodes.Add(id);
            if (parent.containedNodes.Count == 1)
            {
                parent.startState = id;
            }
        }

        /*AssetDatabase.CreateAsset(newState, directory + "/" + filename + "/" + fighter.states.Count + ".asset");
         * Debug.Log(Path.GetDirectoryName(path));*/
    }
 public void SetFighter(LZFighter fighter)
 {
     this.fighter = fighter;
     if (OnFighterSet != null)
     {
         OnFighterSet.Invoke();
     }
 }
    private void ProcessContextMenu(Vector2 mousePosition, LZFighter fighter)
    {
        GenericMenu genericMenu = new GenericMenu();

        genericMenu.AddItem(new GUIContent("Add node"), false, () => OnClickAddNode(mousePosition, fighter));
        foreach (var state in machine.states.GetIDs())
        {
            string path = "Shortcut/";
            path += machine.GetStatePath(state);
            genericMenu.AddItem(new GUIContent(path), false, () => OnClickAddShortcut(mousePosition, state));
        }
        genericMenu.ShowAsContext();
    }
示例#4
0
 public static void ScriptListField(List <MiniScript> scripts, LZFighter fighter)
 {
     ListField(scripts, (i) => {
         EditorGUILayout.BeginVertical(NodeStyle);
         scripts[i] = (MiniScript)EditorGUILayout.ObjectField(scripts[i], typeof(MiniScript), false);
         if (scripts[i] != null)
         {
             scripts[i].Initialize(fighter);
             Editor scriptEditor = Editor.CreateEditor(scripts[i]);
             scriptEditor.OnInspectorGUI();
         }
         EditorGUILayout.EndVertical();
     });
 }
示例#5
0
 public void Initialize()
 {
     fighter = Instantiate(fighterObject);
     fighter.Initialize(controller, gameObject);
     components = GetComponents <LZFighterComponent>();
     foreach (var c in components)
     {
         c.SetFighter(fighter);
     }
     if (onInitialize != null)
     {
         onInitialize.Invoke();
     }
 }
示例#6
0
    public void DrawState(StateMachineNode state)
    {
        if (state.IsShortcut)
        {
            DrawShortcut(state);
            return;
        }
        LabelTitle(state.name);
        state.data = (LZFighterStateData)EditorGUILayout.ObjectField(state.data, typeof(LZFighterStateData), false);
        if (state.data != null && state.name == "")
        {
            state.name = state.data.name;
        }
        // Edit instance
        if (GUILayout.Button("Edit"))
        {
            if (state.data == null)
            {
                LZFighter fighter   = LZFighterEditor.Instance.fighter;
                string    path      = AssetDatabase.GetAssetPath(fighter);
                string    filename  = Path.GetFileNameWithoutExtension(path);
                string    directory = Path.GetDirectoryName(path);
                if (!AssetDatabase.IsValidFolder(directory + "/" + filename))
                {
                    AssetDatabase.CreateFolder(directory, filename);
                }
                LZFighterStateData newData = ScriptableObject.CreateInstance <LZFighterStateData>();
                AssetDatabase.CreateAsset(newData, directory + "/" + filename + "/" + state.name + ".asset");
                Debug.Log(Path.GetDirectoryName(path));
                state.data = newData;
            }
            LZFighterStateEditor.Open(state.data);
        }
        string currentName = state.name;
        string newName     = EditorGUILayout.TextField("Name:", currentName);

        /*if (currentName != newName && state.data != null) {
         *  AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(state.data), newName);
         * }*/
        state.name     = newName;
        state.velocity = EditorGUILayout.Vector2Field("StateVelocity: ", state.velocity);
        if (state.data != null)
        {
            state.data.velocity = EditorGUILayout.Vector2Field("DataVelocity:", state.data.velocity);
        }
        state.invert = EditorGUILayout.Toggle("Invert", state.invert);
        state.loop   = EditorGUILayout.Toggle("Loop", state.loop);

        GUITools.ScriptListField(state.scripts, fighter);
    }
 public StateMachineEditor(StateMachine machine, LZFighter fighter)
 {
     this.machine = machine;
     this.fighter = fighter;
 }