您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
41 行
1.3 KiB
41 行
1.3 KiB
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace UOP1.StateMachine.ScriptableObjects
|
|
{
|
|
[CreateAssetMenu(fileName = "New State", menuName = "State Machines/State")]
|
|
public class StateSO : ScriptableObject
|
|
{
|
|
[SerializeField] private StateActionSO[] _actions = null;
|
|
|
|
/// <summary>
|
|
/// Will create a new state or return an existing one inside <paramref name="createdInstances"/>.
|
|
/// </summary>
|
|
internal State GetState(StateMachine stateMachine, Dictionary<ScriptableObject, object> createdInstances)
|
|
{
|
|
if (createdInstances.TryGetValue(this, out var obj))
|
|
return (State)obj;
|
|
|
|
var state = new State();
|
|
createdInstances.Add(this, state);
|
|
|
|
state._originSO = this;
|
|
state._stateMachine = stateMachine;
|
|
state._transitions = new StateTransition[0];
|
|
state._actions = GetActions(_actions, stateMachine, createdInstances);
|
|
|
|
return state;
|
|
}
|
|
|
|
private static StateAction[] GetActions(StateActionSO[] scriptableActions,
|
|
StateMachine stateMachine, Dictionary<ScriptableObject, object> createdInstances)
|
|
{
|
|
int count = scriptableActions.Length;
|
|
var actions = new StateAction[count];
|
|
for (int i = 0; i < count; i++)
|
|
actions[i] = scriptableActions[i].GetAction(stateMachine, createdInstances);
|
|
|
|
return actions;
|
|
}
|
|
}
|
|
}
|