本文整理汇总了C#中StateMachine.GetOrAddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.GetOrAddComponent方法的具体用法?C# StateMachine.GetOrAddComponent怎么用?C# StateMachine.GetOrAddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.GetOrAddComponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
}
示例2: AddLayer
public static StateLayer AddLayer(StateMachine machine, Type layerType, UnityEngine.Object parent)
{
StateLayer layer = null;
#if UNITY_EDITOR
layer = AddLayer(machine, machine.GetOrAddComponent(layerType) as StateLayer, parent);
#endif
return layer;
}
示例3: AddState
public static State AddState(StateMachine machine, StateLayer layer, Type stateType)
{
State state = null;
#if UNITY_EDITOR
state = AddState(machine, layer, machine.GetOrAddComponent(stateType) as State);
#endif
return state;
}
示例4: UpdateCallbacks
public static void UpdateCallbacks(StateMachine machine)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly;
int callerMask = 0;
StateLayer[] layers = machine.GetComponents<StateLayer>();
State[] states = machine.GetComponents<State>();
for (int i = 0; i < layers.Length; i++)
{
StateLayer layer = layers[i];
Type layerType = layer.GetType();
while (layerType != typeof(StateLayer) || !typeof(StateLayer).IsAssignableFrom(layerType))
{
MethodInfo[] methods = layerType.GetMethods(flags);
for (int j = 0; j < methods.Length; j++)
{
MethodInfo 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++)
{
State state = states[i];
Type stateType = state.GetType();
while (stateType != typeof(State) || !typeof(State).IsAssignableFrom(stateType))
{
MethodInfo[] methods = stateType.GetMethods(flags);
for (int j = 0; j < methods.Length; j++)
{
MethodInfo 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)
{
StateMachineCaller caller = machine.GetOrAddComponent(CallbackTypes[i]) as StateMachineCaller;
caller.hideFlags = HideFlags.HideInInspector;
caller.machine = machine;
}
else
{
StateMachineCaller caller = machine.GetComponent(CallbackTypes[i]) as StateMachineCaller;
if (caller != null)
caller.Destroy();
}
}
}