Exemplo n.º 1
0
        private AnimatorStateMachine(AssetInfo assetInfo, AnimatorController controller, int stateMachineIndex) :
            base(assetInfo, 1)
        {
            VirtualSerializedFile virtualFile = (VirtualSerializedFile)assetInfo.File;

            LayerConstant layer = controller.Controller.GetLayerByStateMachineIndex(stateMachineIndex);

            Name = controller.TOS[layer.Binding];

            StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance;

            int stateCount        = stateMachine.StateConstantArray.Count;
            int stateMachineCount = 0;
            int count             = stateCount + stateMachineCount;
            int side = (int)Math.Ceiling(Math.Sqrt(count));

            List <AnimatorState> states = new List <AnimatorState>();

            m_childStates = new ChildAnimatorState[stateCount];
            for (int y = 0, stateIndex = 0; y < side && stateIndex < stateCount; y++)
            {
                for (int x = 0; x < side && stateIndex < stateCount; x++, stateIndex++)
                {
                    Vector3f           position   = new Vector3f(x * StateOffset, y * StateOffset, 0.0f);
                    AnimatorState      state      = AnimatorState.CreateVirtualInstance(virtualFile, controller, stateMachineIndex, stateIndex, position);
                    ChildAnimatorState childState = new ChildAnimatorState(state, position);
                    m_childStates[stateIndex] = childState;
                    states.Add(state);
                }
            }
            m_childStateMachines = new ChildAnimatorStateMachine[stateMachineCount];

            // set destination state for transitions here because all states has become valid only now
            for (int i = 0; i < stateMachine.StateConstantArray.Count; i++)
            {
                AnimatorState state         = states[i];
                StateConstant stateConstant = stateMachine.StateConstantArray[i].Instance;
                for (int j = 0; j < stateConstant.TransitionConstantArray.Count; j++)
                {
                    long stateTransitionPath                   = state.Transitions[j].PathID;
                    AnimatorStateTransition transition         = (AnimatorStateTransition)virtualFile.GetAsset(stateTransitionPath);
                    TransitionConstant      transitionConstant = stateConstant.TransitionConstantArray[j].Instance;
                    if (!transitionConstant.IsExit)
                    {
                        AnimatorState destState = states[transitionConstant.DestinationState];
                        transition.DstState = destState.File.CreatePPtr(destState);
                    }
                }
            }

            m_anyStateTransitions = new PPtr <AnimatorStateTransition> [stateMachine.AnyStateTransitionConstantArray.Count];
            for (int i = 0; i < stateMachine.AnyStateTransitionConstantArray.Count; i++)
            {
                TransitionConstant      transitionConstant = stateMachine.AnyStateTransitionConstantArray[i].Instance;
                AnimatorStateTransition transition         = AnimatorStateTransition.CreateVirtualInstance(virtualFile, controller, transitionConstant, states);
                m_anyStateTransitions[i] = transition.File.CreatePPtr(transition);
            }

            m_entryTransitions       = stateMachine.GetEntryTransitions(virtualFile, controller, layer.Binding, states);
            m_stateMachineBehaviours = new PPtr <MonoBehaviour> [0];

            AnyStatePosition           = new Vector3f(0.0f, -StateOffset, 0.0f);
            EntryPosition              = new Vector3f(StateOffset, -StateOffset, 0.0f);
            ExitPosition               = new Vector3f(2.0f * StateOffset, -StateOffset, 0.0f);
            ParentStateMachinePosition = new Vector3f(0.0f, -2.0f * StateOffset, 0.0f);

            DefaultState = ChildStates.Count > 0 ? ChildStates[stateMachine.DefaultState].State : default;
        }
Exemplo n.º 2
0
        private AnimatorStateMachine(AssetInfo assetInfo, AnimatorController controller, int stateMachineIndex) :
            base(assetInfo, HideFlags.HideInHierarchy)
        {
            VirtualSerializedFile virtualFile = (VirtualSerializedFile)assetInfo.File;

            LayerConstant layer = controller.Controller.GetLayerByStateMachineIndex(stateMachineIndex);

            Name = controller.TOS[layer.Binding];

            StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance;

            int stateCount        = stateMachine.StateConstantArray.Count;
            int stateMachineCount = 0;
            int count             = stateCount + stateMachineCount;
            int side = (int)Math.Ceiling(Math.Sqrt(count));

            List <AnimatorState> states = new List <AnimatorState>();

            m_childStates = new ChildAnimatorState[stateCount];
            for (int y = 0, stateIndex = 0; y < side && stateIndex < stateCount; y++)
            {
                for (int x = 0; x < side && stateIndex < stateCount; x++, stateIndex++)
                {
                    Vector3f           position   = new Vector3f(x * StateOffset, y * StateOffset, 0.0f);
                    AnimatorState      state      = AnimatorState.CreateVirtualInstance(virtualFile, controller, stateMachineIndex, stateIndex, position);
                    ChildAnimatorState childState = new ChildAnimatorState(state, position);
                    m_childStates[stateIndex] = childState;
                    states.Add(state);
                }
            }
#warning TODO: child StateMachines
            m_childStateMachines = new ChildAnimatorStateMachine[stateMachineCount];

            // set destination state for transitions here because all states has become valid only now
            for (int i = 0; i < stateMachine.StateConstantArray.Count; i++)
            {
                AnimatorState state         = states[i];
                StateConstant stateConstant = stateMachine.StateConstantArray[i].Instance;
                PPtr <AnimatorStateTransition>[] transitions = new PPtr <AnimatorStateTransition> [stateConstant.TransitionConstantArray.Count];
                for (int j = 0; j < stateConstant.TransitionConstantArray.Count; j++)
                {
                    TransitionConstant transitionConstant         = stateConstant.TransitionConstantArray[j].Instance;
                    AnimatorStateTransition.Parameters parameters = new AnimatorStateTransition.Parameters
                    {
                        StateMachine = stateMachine,
                        States       = states,
                        TOS          = controller.TOS,
                        Transition   = transitionConstant,
                        Version      = controller.File.Version,
                    };
                    AnimatorStateTransition transition = AnimatorStateTransition.CreateVirtualInstance(virtualFile, parameters);
                    transitions[j] = transition.File.CreatePPtr(transition);
                }
                state.Transitions = transitions;
            }

            m_anyStateTransitions = new PPtr <AnimatorStateTransition> [stateMachine.AnyStateTransitionConstantArray.Count];
            for (int i = 0; i < stateMachine.AnyStateTransitionConstantArray.Count; i++)
            {
                TransitionConstant transitionConstant         = stateMachine.AnyStateTransitionConstantArray[i].Instance;
                AnimatorStateTransition.Parameters parameters = new AnimatorStateTransition.Parameters
                {
                    StateMachine = stateMachine,
                    States       = states,
                    TOS          = controller.TOS,
                    Transition   = transitionConstant,
                    Version      = controller.File.Version,
                };
                AnimatorStateTransition transition = AnimatorStateTransition.CreateVirtualInstance(virtualFile, parameters);
                m_anyStateTransitions[i] = transition.File.CreatePPtr(transition);
            }

            StateMachineConstant.Parameters stateParameters = new StateMachineConstant.Parameters
            {
                ID      = layer.Binding,
                States  = states,
                TOS     = controller.TOS,
                Version = controller.File.Version,
            };
            m_entryTransitions       = stateMachine.CreateEntryTransitions(virtualFile, stateParameters);
            m_stateMachineBehaviours = new PPtr <MonoBehaviour> [0];

            AnyStatePosition           = new Vector3f(0.0f, -StateOffset, 0.0f);
            EntryPosition              = new Vector3f(StateOffset, -StateOffset, 0.0f);
            ExitPosition               = new Vector3f(2.0f * StateOffset, -StateOffset, 0.0f);
            ParentStateMachinePosition = new Vector3f(0.0f, -2.0f * StateOffset, 0.0f);

            DefaultState = ChildStates.Count > 0 ? ChildStates[stateMachine.DefaultState].State : default;
        }