protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World, AnimSource.ShowLifetime, "Init KnockBack entity:{0} state entity:{1}", entity, animSource.animStateEntity); var state = SystemState.Default; state.MixerNode = AnimationGraphHelper.CreateNode <LayerMixerNode>(animationGraphSystem, "MixerNode"); state.ClipNode = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "ClipNode"); state.OffsetNode = AnimationGraphHelper.CreateNode <OffsetTransformNode>(animationGraphSystem, "OffsetNode"); state.SubtractClipNode = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "SubtractClipNode"); state.DeltaNode = AnimationGraphHelper.CreateNode <DeltaNode>(animationGraphSystem, "DeltaNode"); nodeSet.Connect(state.ClipNode, ClipNode.KernelPorts.Output, state.DeltaNode, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.SubtractClipNode, ClipNode.KernelPorts.Output, state.DeltaNode, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.DeltaNode, DeltaNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input1); nodeSet.Connect(state.MixerNode, LayerMixerNode.KernelPorts.Output, state.OffsetNode, OffsetTransformNode.KernelPorts.Input); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput0, BlendingMode.Override); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput1, 1f); // Expose input and outputs animSource.inputNode = state.MixerNode; animSource.inputPortID = (InputPortID)LayerMixerNode.KernelPorts.Input0; animSource.outputNode = state.OffsetNode; animSource.outputPortID = (OutputPortID)OffsetTransformNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; // Handle create AnimSource Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, DynamicBuffer <AnimSourceEntities> childAnimSourceEntities, ref AnimSource.Data animSource) => { var state = SystemState.Default; state.MixerNode = AnimationGraphHelper.CreateNode <MixerNode>(animationGraphSystem, "MixerNode"); state.AnimSourceEntityA = childAnimSourceEntities[0].Value; state.AnimSourceEntityB = childAnimSourceEntities[1].Value; state.AnimSourceA = EntityManager.GetComponentData <AnimSource.Data>(state.AnimSourceEntityA); state.AnimSourceB = EntityManager.GetComponentData <AnimSource.Data>(state.AnimSourceEntityB); animSource.outputNode = state.MixerNode; animSource.outputPortID = (OutputPortID)MixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); // Handle destroyed entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <AnimSource.Data>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World, AnimSource.ShowLifetime, "Init AnimSourceSingleClip entity:{0}", entity); var state = SystemState.Default; state.ClipNode = AnimationGraphHelper.CreateNode <ClipPlayerNode>(animationGraphSystem, "SingleClipNode"); // Expose input and outputs animSource.outputNode = state.ClipNode; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); // Handled deleted entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var animGraphSystem = m_AnimationGraphSystem; var commands = new EntityCommandBuffer(Allocator.TempJob); // Handle create AnimSources Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .WithAll <AnimSourceEntities>() .ForEach((Entity entity, ref AnimSource.Data animSource) => { var systemState = SystemState.Default; systemState.inputNode = AnimationGraphHelper.CreateNode <BoundaryNode>(animGraphSystem, "inputNode"); systemState.outputNode = AnimationGraphHelper.CreateNode <BoundaryNode>(animGraphSystem, "outputNode"); animSource.inputNode = systemState.inputNode; animSource.inputPortID = (InputPortID)BoundaryNode.KernelPorts.Input; animSource.outputNode = systemState.outputNode; animSource.outputPortID = (OutputPortID)BoundaryNode.KernelPorts.Output; commands.AddComponent(entity, systemState); }).Run(); // Handle destroyed AnimSources Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <AnimSourceEntities>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(commands, entity, animGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone<SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World,AnimSource.ShowLifetime,"Init Run8Dir entity:{0} state entity:{1}", entity, animSource.animStateEntity); var state = SystemState.Default; settings.RunBlendSpace2D = BlendTreeEntityStoreHelper.CreateBlendTree2DFromComponents(EntityManager, entity); state.BlendTreeNode = AnimationGraphHelper.CreateNode<BlendTree2DNode>(animationGraphSystem, "BlendTreeNode"); state.AimVertical = AnimationGraphHelper.CreateNode<ClipNode>(animationGraphSystem, "AimVertical"); state.AimHorizontal = AnimationGraphHelper.CreateNode<ClipNode>(animationGraphSystem, "AimHorizontal"); state.AdditiveRefPoseA = AnimationGraphHelper.CreateNode<ClipNode>(animationGraphSystem,"AdditiveRefPoseA"); state.AdditiveRefPoseB = AnimationGraphHelper.CreateNode<ClipNode>(animationGraphSystem, "AdditiveRefPoseB"); state.AimVerticalDelta = AnimationGraphHelper.CreateNode<DeltaNode>(animationGraphSystem, "AimVerticalDelta"); state.AimHorizontalDelta = AnimationGraphHelper.CreateNode<DeltaNode>(animationGraphSystem, "AimHorizontalDelta"); state.Mixer = AnimationGraphHelper.CreateNode<LayerMixerNode>(animationGraphSystem, "Mixer"); nodeSet.SendMessage(state.Mixer, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.Mixer, LayerMixerNode.SimulationPorts.WeightInput1, 1f); nodeSet.SendMessage(state.Mixer, LayerMixerNode.SimulationPorts.WeightInput2, 0f); nodeSet.SendMessage(state.Mixer, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.Mixer, LayerMixerNode.SimulationPorts.BlendModeInput2, BlendingMode.Additive); nodeSet.Connect(state.BlendTreeNode, BlendTree2DNode.KernelPorts.Output, state.Mixer, LayerMixerNode.KernelPorts.Input0); nodeSet.Connect(state.AdditiveRefPoseA, ClipNode.KernelPorts.Output, state.AimVerticalDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AdditiveRefPoseB, ClipNode.KernelPorts.Output, state.AimHorizontalDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AimVertical, ClipNode.KernelPorts.Output, state.AimVerticalDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimHorizontal, ClipNode.KernelPorts.Output, state.AimHorizontalDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimVerticalDelta, DeltaNode.KernelPorts.Output, state.Mixer, LayerMixerNode.KernelPorts.Input1); nodeSet.Connect(state.AimHorizontalDelta, DeltaNode.KernelPorts.Output, state.Mixer, LayerMixerNode.KernelPorts.Input2); // Load clips and store clip info state.AimVerticalDuration = settings.RunAimClipRef.Value.Duration; state.AimHorizontalDuration = settings.RunAimClipRef.Value.Duration; // All clips are the same length so we can use a static clip duration state.RunClipDuration = settings.RunBlendSpace2D.Value.Motions[0].Clip.Value.Duration; // Expose input and outputs animSource.outputNode = state.Mixer; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); // Handled deleted entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone<Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return default; }
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var ownedAbilityBufferFromEntity = GetBufferFromEntity <AbilityOwner.OwnedAbility>(true); // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { // GameDebug.Log("Init Run"); var state = SystemState.Default; var abilityMovementEntity = Ability.FindAbility(ownedAbilityBufferFromEntity, animSource.animStateEntity, AbilityMovement.Tag); if (abilityMovementEntity == Entity.Null) { return; } var abilityMovementSettings = EntityManager.GetComponentData <AbilityMovement.Settings>(abilityMovementEntity); state.JumpNode = AnimationGraphHelper.CreateNode <ClipPlayerNode>(m_AnimationGraphSystem, "JumpNode"); state.DeltaTimeNode = AnimationGraphHelper.CreateNode <DeltaTimeNode>(m_AnimationGraphSystem, "DeltaTimeNode"); state.AimVerticalNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AimVerticalNode"); state.AimHorizontalNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AimHorizontalNode"); state.AdditiveRefPoseA = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AdditiveRefPoseA"); state.AdditiveRefPoseB = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AdditiveRefPoseB"); state.AimVerticalDelta = AnimationGraphHelper.CreateNode <DeltaNode>(m_AnimationGraphSystem, "AimVerticalDelta"); state.AimHorizontalDelta = AnimationGraphHelper.CreateNode <DeltaNode>(m_AnimationGraphSystem, "AimHorizontalDelta"); state.MixerNode = AnimationGraphHelper.CreateNode <LayerMixerNode>(m_AnimationGraphSystem, "MixerNode"); nodeSet.SendMessage(state.JumpNode, ClipPlayerNode.SimulationPorts.Speed, 1.0f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput1, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput2, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput2, BlendingMode.Additive); nodeSet.Connect(state.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, state.JumpNode, ClipPlayerNode.KernelPorts.DeltaTime); nodeSet.Connect(state.JumpNode, ClipPlayerNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input0); nodeSet.Connect(state.AdditiveRefPoseA, ClipNode.KernelPorts.Output, state.AimVerticalDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AdditiveRefPoseB, ClipNode.KernelPorts.Output, state.AimHorizontalDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AimVerticalNode, ClipNode.KernelPorts.Output, state.AimVerticalDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimHorizontalNode, ClipNode.KernelPorts.Output, state.AimHorizontalDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimVerticalDelta, DeltaNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input1); nodeSet.Connect(state.AimHorizontalDelta, DeltaNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input2); // Store clip info state.AimVerticalDuration = settings.JumpAimVerticalClip.Value.Duration; state.AimHorizontalDuration = settings.JumpAimHorizontalClip.Value.Duration; state.JumpDuration = settings.JumpClip.Value.Duration; // Adjust play speed so vertical velocity in animation is matched with character velocity (so feet doesnt penetrate ground) var animJumpVel = settings.jumpHeight / settings.JumpClip.Value.Duration; var characterJumpVel = abilityMovementSettings.jumpAscentHeight / abilityMovementSettings.jumpAscentDuration; if (characterJumpVel > 0f && animJumpVel > 0f) { state.PlaySpeed = characterJumpVel / animJumpVel; } else { GameDebug.LogWarning("Cannot set jump anim speed, values need to be more than 0"); } // Expose input and outputs animSource.outputNode = state.MixerNode; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); // Handled deleted entities var animationGraphSystem = m_AnimationGraphSystem; Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World, AnimSource.ShowLifetime, "Init AnimSourceInAir entity:{0}", entity); var state = SystemState.Default; state.MainMixer = AnimationGraphHelper.CreateNode <MixerNode>(m_AnimationGraphSystem, "MainMixer"); state.InAirClipNode = AnimationGraphHelper.CreateNode <ClipPlayerNode>(m_AnimationGraphSystem, "InAirClipNode"); nodeSet.Connect(state.InAirClipNode, ClipPlayerNode.KernelPorts.Output, state.MainMixer, MixerNode.KernelPorts.Input0); state.LandAnticClipNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "LandAnticClipNode"); state.AdditiveRefPose = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AdditiveRefPose"); state.AimDelta = AnimationGraphHelper.CreateNode <DeltaNode>(m_AnimationGraphSystem, "AimDelta"); nodeSet.Connect(state.LandAnticClipNode, ClipNode.KernelPorts.Output, state.MainMixer, MixerNode.KernelPorts.Input1); state.AimMixer = AnimationGraphHelper.CreateNode <LayerMixerNode>(m_AnimationGraphSystem, "AimMixer"); nodeSet.Connect(state.MainMixer, MixerNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input0); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.BlendModeInput0, BlendingMode.Override); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.WeightInput0, 1f); state.AimUpDownClipNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AimUpDownClipNode"); nodeSet.Connect(state.AdditiveRefPose, ClipNode.KernelPorts.Output, state.AimDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AimUpDownClipNode, ClipNode.KernelPorts.Output, state.AimDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimDelta, DeltaNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input1); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.WeightInput1, 1f); // Store clip info state.AimVerticalDuration = settings.animAimDownToUp.Value.Duration; // Expose input and outputs animSource.outputNode = state.AimMixer; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); // Handled deleted entities var animationGraphSystem = m_AnimationGraphSystem; Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>().ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { var nodeSet = m_AnimationGraphSystem.Set; var PostUpdateCommands = new EntityCommandBuffer(Allocator.TempJob); Entities .WithNone <SystemState>() .WithAll <ActionDefinitions>() .WithNativeDisableContainerSafetyRestriction(PostUpdateCommands) .WithoutBurst() // nodeSet.SendMessage() .ForEach((Entity entity, ref AnimSource.Data animSource) => { var state = SystemState.Default; var actionDefinitions = EntityManager.GetBuffer <ActionDefinitions>(entity).AsNativeArray(); var numDefinitions = actionDefinitions.Length; if (numDefinitions == 0) { return; } var actionAnimations = EntityManager.GetBuffer <ActionAnimations>(entity); for (var i = 0; i < (int)Ability.AbilityAction.Action.NumActions; i++) { var entry = new ActionAnimations { Value = ActionAnimation.Default }; actionAnimations.Add(entry); } for (var i = 0; i < numDefinitions; i++) { var def = actionDefinitions[i].Value; if (!def.animation.IsCreated) { continue; } var actionAnim = ActionAnimation.Default; actionAnim.Action = def.action; actionAnim.Clip = def.animation; actionAnim.ClipDuration = actionAnim.Clip.Value.Duration; actionAnim.RestartTimeOffset = def.restartTimeOffset; if (def.action == Ability.AbilityAction.Action.Reloading) { state.ReloadActionAnim = actionAnim; } var animEntry = new ActionAnimations { Value = actionAnim }; actionAnimations[(int)def.action] = animEntry; } state.MixerNode = AnimationGraphHelper.CreateNode <LayerMixerNode>(m_AnimationGraphSystem, "MixerNode"); state.ActionClipNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "ActionClipNode"); state.BasePoseClipNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "BasePoseClipNode"); state.ActionDeltaNode = AnimationGraphHelper.CreateNode <DeltaNode>(m_AnimationGraphSystem, "ActionDeltaNode"); nodeSet.Connect(state.ActionClipNode, ClipNode.KernelPorts.Output, state.ActionDeltaNode, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.BasePoseClipNode, ClipNode.KernelPorts.Output, state.ActionDeltaNode, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.ActionDeltaNode, DeltaNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input1); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput0, BlendingMode.Override); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput1, 1f); // Expose input and outputs animSource.inputNode = state.MixerNode; animSource.inputPortID = (InputPortID)LayerMixerNode.KernelPorts.Input0; animSource.outputNode = state.MixerNode; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; PostUpdateCommands.AddComponent(entity, state); }).Run(); Entities .WithNone <ActionDefinitions>() .WithoutBurst() .WithNativeDisableContainerSafetyRestriction(PostUpdateCommands) .ForEach((Entity entity, ref SystemState state) => { Deinitialize(PostUpdateCommands, entity, m_AnimationGraphSystem, state); }).Run(); PostUpdateCommands.Playback(EntityManager); PostUpdateCommands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>().ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World, AnimSource.ShowLifetime, "Init AnimSourceDamage entity:{0}", entity); var state = SystemState.Default; settings.BlendTree = BlendTreeEntityStoreHelper.CreateBlendTree1DFromComponents(EntityManager, entity);; // Create nodes state.BlendTreeNode = AnimationGraphHelper.CreateNode <BlendTree1DNode>(m_AnimationGraphSystem, "BlendTreeNode"); state.MixerNode = AnimationGraphHelper.CreateNode <LayerMixerNode>(m_AnimationGraphSystem, "MixerNode"); state.AdditiveRefPoseNode = AnimationGraphHelper.CreateNode <ClipNode>(m_AnimationGraphSystem, "AdditiveRefPoseNode"); state.AdditiveDeltaNode = AnimationGraphHelper.CreateNode <DeltaNode>(m_AnimationGraphSystem, "AdditiveDeltaNode"); state.DeltaTimeNode = AnimationGraphHelper.CreateNode <DeltaTimeNode>(m_AnimationGraphSystem, "DeltaTimeNode"); state.TimeCounterNode = AnimationGraphHelper.CreateNode <TimeCounterNode>(m_AnimationGraphSystem, "TimeCounterNode"); state.TimeLoopNode = AnimationGraphHelper.CreateNode <TimeLoopNode>(m_AnimationGraphSystem, "TimeLoopNode"); state.FloatRcpSimNode = AnimationGraphHelper.CreateNode <FloatRcpSimNode>(m_AnimationGraphSystem, "FloatRcpSimNode"); nodeSet.Connect(state.AdditiveRefPoseNode, ClipNode.KernelPorts.Output, state.AdditiveDeltaNode, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.BlendTreeNode, BlendTree1DNode.KernelPorts.Output, state.AdditiveDeltaNode, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AdditiveDeltaNode, DeltaNode.KernelPorts.Output, state.MixerNode, LayerMixerNode.KernelPorts.Input1); nodeSet.Connect(state.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, state.TimeCounterNode, TimeCounterNode.KernelPorts.DeltaTime); nodeSet.Connect(state.TimeCounterNode, TimeCounterNode.KernelPorts.Time, state.TimeLoopNode, TimeLoopNode.KernelPorts.InputTime); nodeSet.Connect(state.TimeLoopNode, TimeLoopNode.KernelPorts.OutputTime, state.BlendTreeNode, BlendTree1DNode.KernelPorts.NormalizedTime); nodeSet.Connect(state.FloatRcpSimNode, FloatRcpSimNode.SimulationPorts.Output, state.TimeCounterNode, TimeCounterNode.SimulationPorts.Speed); nodeSet.Connect(state.BlendTreeNode, BlendTree1DNode.SimulationPorts.Duration, state.FloatRcpSimNode, FloatRcpSimNode.SimulationPorts.Input); nodeSet.SendMessage(state.TimeLoopNode, TimeLoopNode.SimulationPorts.Duration, 1.0F); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.WeightInput1, 0f); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput0, BlendingMode.Override); nodeSet.SendMessage(state.MixerNode, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); // Load clips and store clip info var blendSpaceClip = settings.BlendTree.Value.Motions[0].Clip; state.ReactionAnimDuration = blendSpaceClip.Value.Duration; // Declare anim source inputs and outputs animSource.inputNode = state.MixerNode; animSource.inputPortID = (InputPortID)LayerMixerNode.KernelPorts.Input0; animSource.outputNode = state.MixerNode; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; // Add state commands.AddComponent(entity, state); }).Run(); // Handled deleted entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>().ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, m_AnimationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { var state = SystemState.Default; state.StandIkNode = AnimationGraphHelper.CreateNode <StandIkNode>(animationGraphSystem, "StandIkNode"); nodeSet.SetData(state.StandIkNode, StandIkNode.KernelPorts.Weight, 1f); // TODO: Hardcode values for now. Next step, generate from events (when they arrive) or evaluate curves? state.LeftTurnFootFalls = new FootFalls { leftFootUp = 0.3015f, leftFootDown = 0.4659f, rightFootUp = 0.0925f, rightFootDown = 0.2957f }; state.RightTurnFootFalls = new FootFalls { leftFootUp = 0.1202f, leftFootDown = 0.2635f, rightFootUp = 0.2706f, rightFootDown = 0.4499f }; // Set collision mask var defaultLayer = LayerMask.NameToLayer("Default"); var playerLayer = LayerMask.NameToLayer("collision_player"); var platformLayer = LayerMask.NameToLayer("Platform"); state.Mask = 1 << defaultLayer | 1 << playerLayer | 1 << platformLayer; // Expose input and outputs animSource.inputNode = state.StandIkNode; animSource.inputPortID = (InputPortID)StandIkNode.KernelPorts.Input; animSource.outputNode = state.StandIkNode; animSource.outputPortID = (OutputPortID)StandIkNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);
protected override JobHandle OnUpdate(JobHandle inputDeps) { inputDeps.Complete(); var nodeSet = m_AnimationGraphSystem.Set; var commands = new EntityCommandBuffer(Allocator.TempJob); var animationGraphSystem = m_AnimationGraphSystem; // Handle created entities Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <SystemState>() .ForEach((Entity entity, ref AnimSource.Data animSource, ref Settings settings) => { GameDebug.Log(World, AnimSource.ShowLifetime, "Init Stand entity:{0} state entity:{1}", entity, animSource.animStateEntity); var state = SystemState.Default; state.Idle = AnimationGraphHelper.CreateNode <UberClipNode>(animationGraphSystem, "Idle"); state.DeltaTimeNode = AnimationGraphHelper.CreateNode <DeltaTimeNode>(animationGraphSystem, "DeltaTimeNode"); state.TimeCounterNode = AnimationGraphHelper.CreateNode <TimeCounterNode>(animationGraphSystem, "TimeCounterNode"); state.TurnL = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "TurnL"); state.TurnR = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "TurnR"); state.AimLeft = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "AimLeft"); state.AimMid = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "AimMid"); state.AimRight = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "AimRight"); state.AdditiveRefPose = AnimationGraphHelper.CreateNode <ClipNode>(animationGraphSystem, "AdditiveRefPose"); state.AimLeftDelta = AnimationGraphHelper.CreateNode <DeltaNode>(animationGraphSystem, "AimLeftDelta"); state.AimMidDelta = AnimationGraphHelper.CreateNode <DeltaNode>(animationGraphSystem, "AimMidDelta"); state.AimRightDelta = AnimationGraphHelper.CreateNode <DeltaNode>(animationGraphSystem, "AimRightDelta"); state.MixerLeft = AnimationGraphHelper.CreateNode <MixerNode>(animationGraphSystem, "MixerLeft"); state.MixerRight = AnimationGraphHelper.CreateNode <MixerNode>(animationGraphSystem, "MixerRight"); state.AimMixer = AnimationGraphHelper.CreateNode <LayerMixerNode>(animationGraphSystem, "AimMixer"); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.WeightInput0, 1f); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.BlendModeInput1, BlendingMode.Additive); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.BlendModeInput2, BlendingMode.Additive); nodeSet.SendMessage(state.AimMixer, LayerMixerNode.SimulationPorts.BlendModeInput3, BlendingMode.Additive); nodeSet.SendMessage(state.Idle, UberClipNode.SimulationPorts.Configuration, new ClipConfiguration { Mask = (int)ClipConfigurationMask.LoopTime }); // TODO: Convert to using cascade mixer or blend space? nodeSet.Connect(state.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, state.TimeCounterNode, TimeCounterNode.KernelPorts.DeltaTime); nodeSet.Connect(state.TimeCounterNode, TimeCounterNode.KernelPorts.Time, state.Idle, UberClipNode.KernelPorts.Time); nodeSet.Connect(state.TurnL, ClipNode.KernelPorts.Output, state.MixerLeft, MixerNode.KernelPorts.Input0); nodeSet.Connect(state.Idle, UberClipNode.KernelPorts.Output, state.MixerLeft, MixerNode.KernelPorts.Input1); nodeSet.Connect(state.MixerLeft, MixerNode.KernelPorts.Output, state.MixerRight, MixerNode.KernelPorts.Input0); nodeSet.Connect(state.TurnR, ClipNode.KernelPorts.Output, state.MixerRight, MixerNode.KernelPorts.Input1); nodeSet.Connect(state.MixerRight, MixerNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input0); nodeSet.Connect(state.AimLeft, ClipNode.KernelPorts.Output, state.AimLeftDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimMid, ClipNode.KernelPorts.Output, state.AimMidDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AimRight, ClipNode.KernelPorts.Output, state.AimRightDelta, DeltaNode.KernelPorts.Input); nodeSet.Connect(state.AdditiveRefPose, ClipNode.KernelPorts.Output, state.AimLeftDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AdditiveRefPose, ClipNode.KernelPorts.Output, state.AimMidDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AdditiveRefPose, ClipNode.KernelPorts.Output, state.AimRightDelta, DeltaNode.KernelPorts.Subtract); nodeSet.Connect(state.AimLeftDelta, DeltaNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input1); nodeSet.Connect(state.AimMidDelta, DeltaNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input2); nodeSet.Connect(state.AimRightDelta, DeltaNode.KernelPorts.Output, state.AimMixer, LayerMixerNode.KernelPorts.Input3); // TODO: Use pr. clip values (turn direction)? state.TurnDuration = settings.TurnLeftClip.Value.Duration; state.AimDuration = settings.StandAimLeftClip.Value.Duration; // Setup transition data var numMixerPorts = 3; for (var i = 0; i < numMixerPorts; i++) { var transitionWeights = EntityManager.GetBuffer <SimpleTransition.PortWeights>(entity); transitionWeights.Add(new SimpleTransition.PortWeights { Value = 1f }); } // Expose input and outputs animSource.outputNode = state.AimMixer; animSource.outputPortID = (OutputPortID)LayerMixerNode.KernelPorts.Output; commands.AddComponent(entity, state); }).Run(); Entities .WithoutBurst() // Can be removed once NodeSets are Burst-friendly .WithNone <Settings>() .ForEach((Entity entity, ref SystemState state) => { Deinitialize(World, commands, entity, animationGraphSystem, state); }).Run(); commands.Playback(EntityManager); commands.Dispose(); return(default);