protected override BlendTree1DData CreateGraph(Entity entity, ref Rig rig, ProcessDefaultAnimationGraph graphSystem, ref BlendTree1DSetup setup) { var set = graphSystem.Set; var blendTreeComponent = EntityManager.GetBuffer <BlendTree1DResource>(entity); var blendTreeAsset = BlendTreeBuilder.CreateBlendTree1DFromComponents(blendTreeComponent[setup.BlendTreeIndex], EntityManager, entity); var data = new BlendTree1DData(); data.BlendTreeNode = set.Create <BlendTree1DNode>(); data.BlendTreeAsset = blendTreeAsset; data.EntityNode = set.CreateComponentNode(entity); data.DeltaTimeNode = set.Create <ConvertDeltaTimeToFloatNode>(); data.TimeCounterNode = set.Create <TimeCounterNode>(); data.TimeLoopNode = set.Create <TimeLoopNode>(); data.FloatRcpNode = set.Create <FloatRcpNode>(); data.BlendTreeInputNode = set.Create <ExtractBlendTree1DParametersNode>(); set.Connect(data.EntityNode, data.DeltaTimeNode, ConvertDeltaTimeToFloatNode.KernelPorts.Input); set.Connect(data.DeltaTimeNode, ConvertDeltaTimeToFloatNode.KernelPorts.Output, data.TimeCounterNode, TimeCounterNode.KernelPorts.DeltaTime); set.Connect(data.TimeCounterNode, TimeCounterNode.KernelPorts.Time, data.TimeLoopNode, TimeLoopNode.KernelPorts.InputTime); set.Connect(data.TimeLoopNode, TimeLoopNode.KernelPorts.OutputTime, data.BlendTreeNode, BlendTree1DNode.KernelPorts.NormalizedTime); set.Connect(data.BlendTreeNode, BlendTree1DNode.KernelPorts.Duration, data.FloatRcpNode, FloatRcpNode.KernelPorts.Input); set.Connect(data.FloatRcpNode, FloatRcpNode.KernelPorts.Output, data.TimeCounterNode, TimeCounterNode.KernelPorts.Speed); set.Connect(data.BlendTreeNode, BlendTree1DNode.KernelPorts.Output, data.EntityNode, NodeSet.ConnectionType.Feedback); set.Connect(data.EntityNode, data.BlendTreeInputNode, ExtractBlendTree1DParametersNode.KernelPorts.Input, NodeSet.ConnectionType.Feedback); set.Connect(data.BlendTreeInputNode, ExtractBlendTree1DParametersNode.KernelPorts.Output, data.BlendTreeNode, BlendTree1DNode.KernelPorts.BlendParameter); set.SendMessage(data.TimeLoopNode, TimeLoopNode.SimulationPorts.Duration, 1.0F); set.SendMessage(data.BlendTreeNode, BlendTree1DNode.SimulationPorts.Rig, rig); set.SendMessage(data.BlendTreeNode, BlendTree1DNode.SimulationPorts.BlendTree, data.BlendTreeAsset); return(data); }
protected override void OneTimeSetUp() { base.OneTimeSetUp(); var motionData = new BlendTree1DMotionData[] { new BlendTree1DMotionData { MotionThreshold = 0.2f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.4f, MotionSpeed = 0.8f }, new BlendTree1DMotionData { MotionThreshold = 0.6f, MotionSpeed = 0.6f }, new BlendTree1DMotionData { MotionThreshold = 0.8f, MotionSpeed = 0.4f }, new BlendTree1DMotionData { MotionThreshold = 1.0f, MotionSpeed = 0.2f }, }; m_BlendTree = BlendTreeBuilder.CreateBlendTree(motionData); }
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) { if (blendTree == null) { return; } conversionSystem.DeclareAssetDependency(gameObject, blendTree); var rig = dstManager.GetComponentData <Rig>(entity); var clipConfiguration = new ClipConfiguration { Mask = ClipConfigurationMask.LoopValues }; var bakeOptions = new BakeOptions { ClipConfiguration = clipConfiguration, RigDefinition = rig.Value, SampleRate = 60.0f }; var blendTreeIndex = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions); var blendTree2DResources = dstManager.GetBuffer <BlendTree2DResource>(entity); var blendTreeAsset = BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTree2DResources[blendTreeIndex], dstManager, entity); conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blendTreeAsset); var blendTree2DData = new BlendTree2DRuntime { BlendTreeAsset = blendTreeAsset }; dstManager.AddComponentData(entity, blendTree2DData); var blendTree2DParam = new BlendTree2DParamRuntime { InputMapping = float2.zero, StepMapping = paramStep }; dstManager.AddComponentData(entity, blendTree2DParam); dstManager.AddComponent <DeltaTimeRuntime>(entity); dstManager.AddComponent <ProcessDefaultAnimationGraph.AnimatedRootMotion>(entity); }
public static BlobAssetReference <BlendTree1D> CreateBlendTree1DFromComponents(EntityManager entityManager, Entity entity) { var data = entityManager.GetComponentData <BlendTree1DData>(entity); var motionData = entityManager.GetBuffer <BlendTree1DMotionData>(entity); var targetMotionData = new Unity.Animation.BlendTree1DMotionData[motionData.Length]; for (int i = 0; i < motionData.Length; i++) { targetMotionData[i].MotionThreshold = motionData[i].MotionThreshold; targetMotionData[i].MotionSpeed = motionData[i].MotionSpeed; targetMotionData[i].Motion.Clip = motionData[i].Motion; targetMotionData[i].MotionType = motionData[i].MotionType; } return(BlendTreeBuilder.CreateBlendTree(targetMotionData, data.BlendParameter)); }
public static BlobAssetReference <BlendTree2DSimpleDirectionnal> CreateBlendTree2DFromComponents(EntityManager entityManager, Entity entity) { // Create blendspace var blendSpaceData = entityManager.GetComponentData <BlendTree2DData>(entity); var blendSpaceEntries = entityManager.GetBuffer <BlendTree2DMotionData>(entity); var blendTree2DMotionData = new Unity.Animation.BlendTree2DMotionData[blendSpaceEntries.Length]; for (int i = 0; i < blendSpaceEntries.Length; i++) { blendTree2DMotionData[i].MotionPosition = blendSpaceEntries[i].MotionPosition; blendTree2DMotionData[i].MotionSpeed = blendSpaceEntries[i].MotionSpeed; blendTree2DMotionData[i].Motion.Clip = blendSpaceEntries[i].Motion; blendTree2DMotionData[i].MotionType = blendSpaceEntries[i].MotionType; } return(BlendTreeBuilder.CreateBlendTree2DSimpleDirectionnal(blendTree2DMotionData, blendSpaceData.BlendParam, blendSpaceData.BlendParamY)); }
public void CreateBlendTree1DCanSortMotionData() { var motionData = new [] { new BlendTree1DMotionData { MotionThreshold = 1.0f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.8f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.1f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.9f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.5f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.6f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.7f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.3f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.2f, MotionSpeed = 1.0f }, new BlendTree1DMotionData { MotionThreshold = 0.0f, MotionSpeed = 1.0f }, }; var blendTree = BlendTreeBuilder.CreateBlendTree(motionData); for (int i = 1; i < blendTree.Value.MotionThresholds.Length; i++) { Assert.That(blendTree.Value.MotionThresholds[i], Is.GreaterThanOrEqualTo(blendTree.Value.MotionThresholds[i - 1])); } }
protected override BlendTree2DData CreateGraph(Entity entity, NodeSet set, ref BlendTree2DSetup setup) { if (!EntityManager.HasComponent <SharedRigDefinition>(entity)) { throw new System.NullReferenceException("Entity doesn't have required SharedRigDefinition"); } var rigDefinition = EntityManager.GetSharedComponentData <SharedRigDefinition>(entity); var blendTreeComponent = EntityManager.GetBuffer <BlendTree2DResource>(entity); var blendTreeAsset = BlendTreeBuilder.CreateBlendTree2DFromComponents(blendTreeComponent[setup.BlendTreeIndex], EntityManager, entity); var data = new BlendTree2DData(); var strongHandle = set.Create <BlendTree2DNode>(); data.paramX = rand.NextFloat(-1.0f, 1.0f); data.paramY = rand.NextFloat(-1.0f, 1.0f); data.BlendTree = strongHandle; data.BlendTreeAsset = blendTreeAsset; data.DeltaTimeNode = set.Create <DeltaTimeNode>(); data.TimeCounterNode = set.Create <TimeCounterNode>(); data.TimeLoopNode = set.Create <TimeLoopNode>(); data.FloatRcpSimNode = set.Create <FloatRcpSimNode>(); set.Connect(data.DeltaTimeNode, (OutputPortID)DeltaTimeNode.KernelPorts.DeltaTime, data.TimeCounterNode, (InputPortID)TimeCounterNode.KernelPorts.DeltaTime); set.Connect(data.TimeCounterNode, (OutputPortID)TimeCounterNode.KernelPorts.Time, data.TimeLoopNode, (InputPortID)TimeLoopNode.KernelPorts.InputTime); set.Connect(data.TimeLoopNode, (OutputPortID)TimeLoopNode.KernelPorts.OutputTime, data.BlendTree, (InputPortID)BlendTree2DNode.KernelPorts.NormalizedTime); set.Connect(data.BlendTree, (OutputPortID)BlendTree2DNode.SimulationPorts.Duration, data.FloatRcpSimNode, (InputPortID)FloatRcpSimNode.SimulationPorts.Input); set.Connect(data.FloatRcpSimNode, (OutputPortID)FloatRcpSimNode.SimulationPorts.Output, data.TimeCounterNode, (InputPortID)TimeCounterNode.SimulationPorts.Speed); set.SendMessage(data.TimeLoopNode, (InputPortID)TimeLoopNode.SimulationPorts.Duration, 1.0F); set.SendMessage(data.BlendTree, (InputPortID)BlendTree2DNode.SimulationPorts.RigDefinition, rigDefinition.Value); set.SendMessage(data.BlendTree, (InputPortID)BlendTree2DNode.SimulationPorts.BlendTree, data.BlendTreeAsset); data.Output.Buffer = set.CreateGraphValue(strongHandle, BlendTree2DNode.KernelPorts.Output); PostUpdateCommands.AddComponent(entity, data.Output); return(data); }
protected override void OneTimeSetUp() { base.OneTimeSetUp(); var motionData = new BlendTree2DMotionData[] { new BlendTree2DMotionData { MotionPosition = new float2(-2, 0), MotionSpeed = 0.8f, }, new BlendTree2DMotionData { MotionPosition = new float2(2, 0), MotionSpeed = 0.6f, }, new BlendTree2DMotionData { MotionPosition = new float2(0, 2), MotionSpeed = 0.4f, }, new BlendTree2DMotionData { MotionPosition = new float2(0, -2), MotionSpeed = 0.2f, }, }; m_BlendTree = BlendTreeBuilder.CreateBlendTree2DSimpleDirectional(motionData); }
public void Convert(Entity entity, EntityManager dstManager, [NotNull] GameObjectConversionSystem conversionSystem) { conversionSystem.DeclareAssetDependency(gameObject, blendTree); var rigComponent = dstManager.GetComponentData <Rig>(entity); var clipConfiguration = new ClipConfiguration { Mask = ClipConfigurationMask.LoopValues }; var bakeOptions = new BakeOptions { RigDefinition = rigComponent.Value, ClipConfiguration = clipConfiguration, SampleRate = 60.0f }; var blendTreeIndex = BlendTreeConversion.Convert(blendTree, entity, dstManager, bakeOptions); var blendTreeComponents = dstManager.GetBuffer <BlendTree1DResource>(entity); var blobBlendTreeRef = BlendTreeBuilder.CreateBlendTree1DFromComponents(blendTreeComponents[blendTreeIndex], dstManager, entity); conversionSystem.BlobAssetStore.AddUniqueBlobAsset(ref blobBlendTreeRef); var blendTreeRuntime = new BlendTree1DRuntime { BlendTree = blobBlendTreeRef }; dstManager.AddComponentData(entity, blendTreeRuntime); var blendTreeParamRuntime = new BlendTree1DParamRuntime { VelocityStep = velocityStep, VelocityX = 0.0f }; dstManager.AddComponentData(entity, blendTreeParamRuntime); dstManager.AddComponent <DeltaTimeRuntime>(entity); }
public void BlendTree1DCreatedWithoutMotionDataReturnNull() { var blendTree = BlendTreeBuilder.CreateBlendTree(null); Assert.That(blendTree, Is.EqualTo(BlobAssetReference <BlendTree1D> .Null)); }