浏览代码

Added StateMachine creation functionality

/main
Thomas ICHÉ 5 年前
当前提交
be32a307
共有 3 个文件被更改,包括 80 次插入3 次删除
  1. 4
      CHANGELOG.md
  2. 58
      Editor/HiearchyItems.cs
  3. 21
      Runtime/Ingredients/StateMachine/StateMachine.cs

4
CHANGELOG.md


## 2019.3.2
#### Added
- Added Create State button to StateMachines
- Added State Machine templates in the GameObject Creation Menu
#### Changed
- **Delayed Logic** now has a mode that allows you to have a random delay within a range.

58
Editor/HiearchyItems.cs


using UnityEngine;
using UnityEditor;
using System.Linq;
#region STATE MACHINES
[MenuItem("GameObject/Gameplay Ingredients/State Machines/State Machine (Empty)", false, 10)]
static void CreateEmptyStateMachine()
{
var go = new GameObject("New StateMachine");
var sm = go.AddComponent<StateMachines.StateMachine>();
if (Selection.activeGameObject != null)
go.transform.parent = Selection.activeGameObject.transform;
}
[MenuItem("GameObject/Gameplay Ingredients/State Machines/State Machine (On\\Off)", false, 10)]
static void CreateTwoStateStateMachine()
{
var go = new GameObject("New StateMachine");
var sm = go.AddComponent<StateMachines.StateMachine>();
AddState(sm, "On");
AddState(sm, "Off");
sm.DefaultState = "On";
if (Selection.activeGameObject != null)
go.transform.parent = Selection.activeGameObject.transform;
}
[MenuItem("GameObject/Gameplay Ingredients/State Machines/State Machine (On\\Off\\Disabled)", false, 10)]
static void CreateThreeStateStateMachine()
{
var go = new GameObject("New StateMachine");
var sm = go.AddComponent<StateMachines.StateMachine>();
AddState(sm, "Disabled");
AddState(sm, "On");
AddState(sm, "Off");
sm.DefaultState = "Disabled";
if (Selection.activeGameObject != null)
go.transform.parent = Selection.activeGameObject.transform;
}
static StateMachines.State AddState(StateMachines.StateMachine sm, string name)
{
var goState = new GameObject(name);
var state = goState.AddComponent<StateMachines.State>();
goState.transform.parent = sm.gameObject.transform;
goState.transform.localPosition = Vector3.zero;
goState.transform.localRotation = Quaternion.identity;
goState.transform.localScale = Vector3.one;
sm.States = sm.States.Concat(new StateMachines.State[] { state }).ToArray();
return state;
}
#endregion
#region TRIGGERS
[MenuItem("GameObject/Gameplay Ingredients/Events/Trigger (Box)", false, 10)]

21
Runtime/Ingredients/StateMachine/StateMachine.cs


public string DefaultState;
[ReorderableList, NonNullCheck]
public State[] States;
public State[] States = new State[0];
[ContextMenu("Reset State Objects")]
[Button("Create New State")]
private void AddNewState()
{
var newState = new GameObject($"State {States.Length}");
var state = newState.AddComponent<State>();
newState.transform.parent = transform;
newState.transform.localPosition = Vector3.zero;
newState.transform.localRotation = Quaternion.identity;
newState.transform.localScale = Vector3.one;
States = States.Concat(new State[] { state }).ToArray();
if (m_CurrentState == null)
m_CurrentState = state;
}
[Button("Reset State Objects")]
private void UpdateFromState()
{
foreach(var state in States)

正在加载...
取消
保存