本文整理汇总了C#中StateMachine.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.GetComponents方法的具体用法?C# StateMachine.GetComponents怎么用?C# StateMachine.GetComponents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.GetComponents方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnEnable
public override void OnEnable()
{
base.OnEnable();
stateMachine = (StateMachine)target;
stateMachineObject = stateMachine.gameObject;
HideMachineComponents();
if (stateMachine.GetComponents<StateMachine>().Length > 1) {
Logger.LogError("There can be only one state machine (StateMachine) per game object (GameObject). Use layers (StateLayer) instead.");
stateMachine.Remove();
}
}
示例2: OnEnable
public override void OnEnable()
{
base.OnEnable();
machine = (StateMachine)target;
machineObject = machine.gameObject;
HideMachineComponents();
if (machine.GetComponents<StateMachine>().Length > 1) {
Logger.LogError("There can be only one StateMachine per GameObject.");
machine.Remove();
}
}
示例3: UpdateLayerStates
public static void UpdateLayerStates(StateMachine machine)
{
var layers = machine.GetComponents<StateLayer>();
for (int i = 0; i < layers.Length; i++)
UpdateLayerStates(machine, layers[i]);
}
示例4: UpdateCallbacks
public static void UpdateCallbacks(StateMachine machine)
{
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
int callerMask = 0;
var layers = machine.GetComponents<StateLayer>();
var states = machine.GetComponents<State>();
for (int i = 0; i < layers.Length; i++)
{
var layer = layers[i];
var layerType = layer.GetType();
while (layerType != typeof(StateLayer) || !typeof(StateLayer).IsAssignableFrom(layerType))
{
var methods = layerType.GetMethods(flags);
for (int j = 0; j < methods.Length; j++)
{
var method = methods[j];
if (CallbackNames.Contains(method.Name))
callerMask |= 1 << (Array.IndexOf(CallbackNames, method.Name) + 2);
}
layerType = layerType.BaseType;
}
}
for (int i = 0; i < states.Length; i++)
{
var state = states[i];
var stateType = state.GetType();
while (stateType != typeof(State) || !typeof(State).IsAssignableFrom(stateType))
{
var methods = stateType.GetMethods(flags);
for (int j = 0; j < methods.Length; j++)
{
var method = methods[j];
if (CallbackNames.Contains(method.Name))
callerMask |= 1 << (Array.IndexOf(CallbackNames, method.Name) + 2);
}
stateType = stateType.BaseType;
}
}
for (int i = 0; i < CallbackTypes.Length; i++)
{
if ((callerMask & 1 << i + 2) != 0)
{
var caller = machine.gameObject.GetOrAddComponent(CallbackTypes[i]) as StateMachineCaller;
caller.hideFlags = HideFlags.HideInInspector;
caller.machine = machine;
}
else
{
var caller = machine.GetComponent(CallbackTypes[i]) as StateMachineCaller;
if (caller != null)
caller.Destroy();
}
}
}
示例5: AddState
public static State AddState(StateMachine machine, StateLayer layer, Type stateType)
{
State state = null;
#if UNITY_EDITOR
state = Array.Find(machine.GetComponents(stateType), component => component.GetType() == stateType) as State;
state = state == null ? machine.gameObject.AddComponent(stateType) as State : state;
state = AddState(machine, layer, state);
#endif
return state;
}
示例6: AddLayer
public static StateLayer AddLayer(StateMachine machine, Type layerType, UnityEngine.Object parent)
{
StateLayer layer = null;
#if UNITY_EDITOR
layer = Array.Find(machine.GetComponents(layerType), component => component.GetType() == layerType) as StateLayer;
layer = layer == null ? machine.gameObject.AddComponent(layerType) as StateLayer : layer;
layer = AddLayer(machine, layer, parent);
#endif
return layer;
}
示例7: UpdateLayerStates
public static void UpdateLayerStates(StateMachine machine)
{
foreach (StateLayer layer in machine.GetComponents<StateLayer>()) {
UpdateLayerStates(machine, layer);
}
}
示例8: UpdateCallbacks
public static void UpdateCallbacks(StateMachine machine)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
int callerMask = 0;
foreach (StateLayer layer in machine.GetComponents<StateLayer>()) {
foreach (MethodInfo method in layer.GetType().GetMethods(flags)) {
if (method.DeclaringType != typeof(StateLayer) && CallbackNames.Contains(method.Name)) {
callerMask |= 1 << (Array.IndexOf(CallbackNames, method.Name) + 2);
}
}
}
foreach (State state in machine.GetComponents<State>()) {
foreach (MethodInfo method in state.GetType().GetMethods(flags)) {
if (method.DeclaringType != typeof(State) && CallbackNames.Contains(method.Name)) {
callerMask |= 1 << (Array.IndexOf(CallbackNames, method.Name) + 2);
}
}
}
for (int i = 0; i < CallbackTypes.Length; i++) {
if ((callerMask & 1 << i + 2) != 0) {
StateMachineCaller caller = machine.GetOrAddComponent(CallbackTypes[i]) as StateMachineCaller;
caller.machine = machine;
}
else {
StateMachineCaller caller = machine.GetComponent(CallbackTypes[i]) as StateMachineCaller;
if (caller != null) {
caller.Remove();
}
}
}
}