コード例 #1
0
ファイル: AnimGraph_Emote.cs プロジェクト: TashaSkyUp/Staging
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Emote settings)
        {
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;
            m_settings       = settings;

            m_mixer = AnimationMixerPlayable.Create(graph, settings.emoteData.Length + 1);

            var ports = new int[m_settings.emoteData.Length + 1];

            for (var i = 0; i < ports.Length; i++)
            {
                ports[i] = i;
            }

            m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_mixer, ports);

            for (int i = 0; i < settings.emoteData.Length; i++)
            {
                var clip         = settings.emoteData[i].clip;
                var clipPlayable = AnimationClipPlayable.Create(graph, clip);
                clipPlayable.SetDuration(clip.length);
                clipPlayable.Pause();

                var port = i + 1;
                m_mixer.ConnectInput(port, clipPlayable, 0);
                m_mixer.SetInputWeight(port, 0.0f);
            }
        }
コード例 #2
0
ファイル: AnimGraph_Stand.cs プロジェクト: zy199711/FPSSample
        public CharacterAnimGraph_3PStand(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Stand template)
        {
            if (s_Instances == null)
            {
                s_Instances = new List <CharacterAnimGraph_3PStand>(16);
            }

            s_Instances.Add(this);


            m_template       = template;
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;

            GameDebug.Assert(entityManager.HasComponent <Animator>(owner), "Owner has no Animator component");
            var animator = entityManager.GetComponentObject <Animator>(owner);

            GameDebug.Assert(entityManager.HasComponent <Skeleton>(owner), "Owner has no Skeleton component");
            var skeleton = entityManager.GetComponentObject <Skeleton>(owner);

            GameDebug.Assert(entityManager.HasComponent <CharPredictedStateData>(m_AnimStateOwner), "Owner has no CharPredictedState component");

            var leftToes  = skeleton.bones[skeleton.GetBoneIndex(template.leftToeBone.GetHashCode())];
            var rightToes = skeleton.bones[skeleton.GetBoneIndex(template.rightToeBone.GetHashCode())];

            // Locomotion mixer and loco animation
            m_locomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

            // Idle
            m_animIdle = AnimationClipPlayable.Create(graph, template.animIdle);
            m_animIdle.SetApplyFootIK(true);
            graph.Connect(m_animIdle, 0, m_locomotionMixer, (int)LocoMixerPort.Idle);
            m_locomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

            // Turns and trasitions
            m_animTurnL = CreateTurnAnim(graph, template.animTurnL, LocoMixerPort.TurnL);
            m_animTurnR = CreateTurnAnim(graph, template.animTurnR, LocoMixerPort.TurnR);

            var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

            m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_locomotionMixer, ports);

            // Foot IK
            if (m_template.animTurnL.events.Length != 0)
            {
                m_LeftTurnFootFalls  = ExtractFootFalls(m_template.animTurnL);
                m_RightTurnFootFalls = ExtractFootFalls(m_template.animTurnR);
            }

            var ikJob = new FootIkJob
            {
                settings = m_template.footIK,
                leftToe  = animator.BindStreamTransform(leftToes),
                rightToe = animator.BindStreamTransform(rightToes)
            };

            m_footIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
            graph.Connect(m_locomotionMixer, 0, m_footIk, 0);
            m_footIk.SetInputWeight(0, 1f);

            m_defaultLayer  = LayerMask.NameToLayer("Default");
            m_playerLayer   = LayerMask.NameToLayer("collision_player");
            m_platformLayer = LayerMask.NameToLayer("Platform");

            m_mask = 1 << m_defaultLayer | 1 << m_playerLayer | 1 << m_platformLayer;

            // Aim and Aim mixer
            m_aimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

            m_animAimLeft  = CreateAimAnim(graph, template.animAimLeft, AimMixerPort.AimLeft);
            m_animAimMid   = CreateAimAnim(graph, template.animAimMid, AimMixerPort.AimMid);
            m_animAimRight = CreateAimAnim(graph, template.animAimRight, AimMixerPort.AimRight);

            // Setup other additive mixer
            m_additiveMixer = AnimationLayerMixerPlayable.Create(graph);

            var locoMixerPort = m_additiveMixer.AddInput(m_footIk, 0);

            m_additiveMixer.SetInputWeight(locoMixerPort, 1);

            var aimMixerPort = m_additiveMixer.AddInput(m_aimMixer, 0);

            m_additiveMixer.SetInputWeight(aimMixerPort, 1);
            m_additiveMixer.SetLayerAdditive((uint)aimMixerPort, true);

            // Actions
            m_actionAnimationHandler = new ActionAnimationHandler(m_additiveMixer, template.actionAnimations);

            m_ReloadActionAnimation = m_actionAnimationHandler.GetActionAnimation(CharPredictedStateData.Action.Reloading);

            // Shoot pose
            m_animShootPose = AnimationClipPlayable.Create(graph, template.animShootPose);
            m_animShootPose.SetApplyFootIK(false);
            m_animShootPose.SetDuration(template.animShootPose.length);
            m_animShootPose.Pause();
            m_ShootPosePort = m_additiveMixer.AddInput(m_animShootPose, 0);
            m_additiveMixer.SetInputWeight(m_ShootPosePort, 0.0f);
            m_additiveMixer.SetLayerAdditive((uint)m_ShootPosePort, true);
        }
コード例 #3
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());
        }