本文整理汇总了C#中StateMachine.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# StateMachine.GetComponent方法的具体用法?C# StateMachine.GetComponent怎么用?C# StateMachine.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StateMachine
的用法示例。
在下文中一共展示了StateMachine.GetComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
}
示例2: 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();
}
}
}
}