当前位置: 首页>>代码示例>>C#>>正文


C# StateMachine.GetComponent方法代码示例

本文整理汇总了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();
                }
            }
        }
开发者ID:Magicolo,项目名称:PseudoFramework,代码行数:66,代码来源:StateMachineUtility.cs

示例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();
                    }
                }
            }
        }
开发者ID:Dracir,项目名称:Final-bablititi,代码行数:36,代码来源:StateMachineUtility.cs


注:本文中的StateMachine.GetComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。