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


C# StateMachine.GetOrAddComponent方法代码示例

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

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

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

示例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();
                }
            }
        }
开发者ID:Magicolo,项目名称:No-Love-No-Gain,代码行数:65,代码来源:StateMachineUtility.cs


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