Пример #1
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_SprintBlend settings)
        {
            // TODO: Remove the members that are not needed
            m_Settings       = settings;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            m_RunController                  = new AnimationControllerEntry();
            m_RunController.controller       = settings.runTemplate.Instatiate(entityManager, owner, graph, animStateOwner);
            m_RunController.animStateUpdater = m_RunController.controller as IGraphState;
            m_RunController.port             = 0;

            m_SprintController                  = new AnimationControllerEntry();
            m_SprintController.controller       = settings.sprintTemplate.Instatiate(entityManager, owner, graph, animStateOwner);
            m_SprintController.animStateUpdater = m_SprintController.controller as IGraphState;
            m_SprintController.port             = 1;

            m_RootMixer = AnimationMixerPlayable.Create(graph, 2);

            // TODO: Put into function?
            var outputPlayable = Playable.Null;
            var outputPort     = 0;

            m_RunController.controller.GetPlayableOutput(m_RunController.port, ref outputPlayable, ref outputPort);
            graph.Connect(outputPlayable, outputPort, m_RootMixer, 0);

            m_SprintController.controller.GetPlayableOutput(m_SprintController.port, ref outputPlayable, ref outputPort);
            graph.Connect(outputPlayable, outputPort, m_RootMixer, 1);

            m_RootMixer.SetInputWeight(0, 1f);
        }
Пример #2
0
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_StateSelector settings)
        {
            m_settings      = settings;
            m_graph         = graph;
            m_EntityManager = entityManager;
            m_Owner         = owner;

            animStateMixer = AnimationMixerPlayable.Create(m_graph, 0, true);
            m_RootPlayable = animStateMixer;

            // Animation states
            animStates = new AnimationControllerEntry[(int)CharacterAnimationState.NumStates];

            // Instantiate controllers. We only create one of each type even though it might be used in multiple animation states
            var controllers          = new Dictionary <AnimGraphAsset, IAnimGraphInstance>();
            var controllerPorts      = new Dictionary <IAnimGraphInstance, int>();
            var stateTransitionPorts = new List <int>();
            var transitionTimes      = new Dictionary <IAnimGraphInstance, float[]>();

            foreach (var controllderDef in m_settings.controllers)
            {
                if (controllderDef.template == null)
                {
                    continue;
                }

                if (controllers.ContainsKey(controllderDef.template))
                {
                    continue;
                }

                var controller = controllderDef.template.Instatiate(entityManager, owner, m_graph);
                controllers.Add(controllderDef.template, controller);

                var outputPlayable = Playable.Null;
                var outputPort     = 0;
                controller.GetPlayableOutput(0, ref outputPlayable, ref outputPort);
                var port = animStateMixer.AddInput(outputPlayable, outputPort);

                controllerPorts.Add(controller, port);
                stateTransitionPorts.Add(port);

                var times = new float[(int)CharacterAnimationState.NumStates];
                for (var i = 0; i < (int)CharacterAnimationState.NumStates; i++)
                {
                    times[i] = controllderDef.transitionTime;
                }

                for (var i = 0; i < controllderDef.customTransitions.Length; i++)
                {
                    var sourceStateIndex = (int)controllderDef.customTransitions[i].sourceState;
                    var time             = controllderDef.customTransitions[i].transtionTime;
                    times[sourceStateIndex] = time;
                }

                transitionTimes.Add(controller, times);
            }

            // Setup states specifically defined
            foreach (var controllderDef in m_settings.controllers)
            {
                var animState = controllderDef.animationState;
                if (animStates[(int)animState].controller != null)
                {
                    GameDebug.LogWarning("Animation state already registered");
                    continue;
                }

                var controller = controllers[controllderDef.template];
                animStates[(int)animState].controller       = controller;
                animStates[(int)animState].animStateUpdater = controller as IGraphState;
                animStates[(int)animState].port             = controllerPorts[controller];
                animStates[(int)animState].transitionTimes  = transitionTimes[controller];
            }

            m_StateTranstion = new SimpleTranstion <AnimationMixerPlayable>(animStateMixer, stateTransitionPorts.ToArray());
        }