浏览代码

State Machine Action + Generic Logic

/main
Thomas ICHÉ 6 年前
当前提交
a48e9d98
共有 6 个文件被更改,包括 77 次插入1 次删除
  1. 2
      Runtime/StateMachine/State.cs
  2. 15
      Runtime/StateMachine/StateMachine.cs
  3. 19
      Runtime/Logic/Logic.cs
  4. 11
      Runtime/Logic/Logic.cs.meta
  5. 20
      Runtime/StateMachine/SetStateAction.cs
  6. 11
      Runtime/StateMachine/SetStateAction.cs.meta

2
Runtime/StateMachine/State.cs


{
public class State : MonoBehaviour
{
public string StateName = "State";
public string StateName { get { return gameObject.name; } }
[ReorderableList]
public Callable[] OnStateEnter;

15
Runtime/StateMachine/StateMachine.cs


void Start()
{
foreach (var state in States)
state.gameObject.SetActive(false);
SetState(DefaultState.StateName);
}

{
// Call Exit Actions
// Then finally disable old state
m_CurrentState.gameObject.SetActive(false);
}
// Switch Active new state
newState.gameObject.SetActive(true);
// Then Set new current state
// Finally, call State enter
Callable.Call(m_CurrentState.OnStateEnter, gameObject);
}
}

19
Runtime/Logic/Logic.cs


using NaughtyAttributes;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
namespace GameplayIngredients.Logic
{
public class Logic : LogicBase
{
[ReorderableList]
public Callable[] Calls;
public override void Execute(GameObject instigator = null)
{
Callable.Call(Calls, instigator);
}
}
}

11
Runtime/Logic/Logic.cs.meta


fileFormatVersion: 2
guid: 188f26a3e283eda41a6522c93af8996a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 6d0a734cdedf48d478f3fcc7612af66f, type: 3}
userData:
assetBundleName:
assetBundleVariant:

20
Runtime/StateMachine/SetStateAction.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameplayIngredients.StateMachines;
namespace GameplayIngredients.Actions
{
public class SetStateAction : ActionBase
{
[NonNullCheck]
public StateMachine StateMachine;
public string State = "State";
public override void Execute(GameObject instigator = null)
{
if(StateMachine != null)
StateMachine.SetState(State);
}
}
}

11
Runtime/StateMachine/SetStateAction.cs.meta


fileFormatVersion: 2
guid: 313f9593d35b2c740928abbd82069aa0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存