这是第一个 Unity 开放项目的repo,是 Unity 和社区合作创建的一个小型开源游戏演示,第一款游戏是一款名为 Chop Chop 的动作冒险游戏。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

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