Netcode Bootstrap
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Unity.Assertions;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Rukhanka.Samples
|
||||
{
|
||||
class ScriptedAnimatorSampleConf: MonoBehaviour
|
||||
{
|
||||
public Slider animationTimeSlider;
|
||||
public Slider weight;
|
||||
public float animationTime;
|
||||
public bool manualTimeControl;
|
||||
public int2 animationIndices;
|
||||
public bool doBlending;
|
||||
|
||||
public static ScriptedAnimatorSampleConf Instance { get; private set; }
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Assert.IsNull(Instance);
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (manualTimeControl)
|
||||
{
|
||||
animationTime = animationTimeSlider.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
animationTime += Time.deltaTime;
|
||||
animationTimeSlider.value = math.frac(animationTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b6e9e7626b46ee438f1084ca0d610a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 298480
|
||||
packageName: Rukhanka Animation System 2
|
||||
packageVersion: 2.9.0
|
||||
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/21. Scripted Controller/Scripts/ScriptedAnimatorSampleConf.cs
|
||||
uploadId: 897522
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
using Unity.Burst;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using Unity.Entities.Content;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using Hash128 = Unity.Entities.Hash128;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Rukhanka.Samples
|
||||
{
|
||||
[WorldSystemFilter(WorldSystemFilterFlags.LocalSimulation | WorldSystemFilterFlags.ClientSimulation)]
|
||||
[UpdateInGroup(typeof(RukhankaAnimationSystemGroup))]
|
||||
[UpdateBefore(typeof(AnimationProcessSystem))]
|
||||
public partial class ScriptedAnimatorSampleSystem: SystemBase
|
||||
{
|
||||
[BurstCompile]
|
||||
partial struct ScriptedAnimatorSampleJob: IJobEntity
|
||||
{
|
||||
[ReadOnly]
|
||||
public NativeHashMap<Hash128, BlobAssetReference<AnimationClipBlob>> animDB;
|
||||
public float weight;
|
||||
public float animTime;
|
||||
public int2 animationIndices;
|
||||
public bool blending;
|
||||
|
||||
void Execute(ref DynamicBuffer<AnimationToProcessComponent> atps, ScriptedAnimatorSampleUsedAnimationsComponent c)
|
||||
{
|
||||
ScriptedAnimator.ResetAnimationState(ref atps);
|
||||
animDB.TryGetValue(c.clips[animationIndices.x], out var clip0Blob);
|
||||
animDB.TryGetValue(c.clips[animationIndices.y], out var clip1Blob);
|
||||
if (blending)
|
||||
ScriptedAnimator.BlendTwoAnimations(ref atps, clip0Blob, clip1Blob, animTime, weight);
|
||||
else
|
||||
ScriptedAnimator.PlayAnimation(ref atps, clip0Blob, animTime, weight);
|
||||
}
|
||||
}
|
||||
|
||||
//=================================================================================================================//
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
var cfg = ScriptedAnimatorSampleConf.Instance;
|
||||
if (cfg == null)
|
||||
return;
|
||||
|
||||
if (!SystemAPI.TryGetSingleton<BlobDatabaseSingleton>(out var blobDB))
|
||||
return;
|
||||
|
||||
var job = new ScriptedAnimatorSampleJob()
|
||||
{
|
||||
animDB = blobDB.animations,
|
||||
weight = cfg.weight.value,
|
||||
animTime = cfg.animationTime,
|
||||
blending = cfg.doBlending,
|
||||
animationIndices = cfg.animationIndices
|
||||
};
|
||||
|
||||
job.ScheduleParallel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 865d2e1d0bb5c5b44858b64cb8a2229a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 298480
|
||||
packageName: Rukhanka Animation System 2
|
||||
packageVersion: 2.9.0
|
||||
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/21. Scripted Controller/Scripts/ScriptedAnimatorSampleSystem.cs
|
||||
uploadId: 897522
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
|
||||
using Rukhanka.Hybrid;
|
||||
using Unity.Collections;
|
||||
using Unity.Entities;
|
||||
using UnityEngine;
|
||||
using Hash128 = Unity.Entities.Hash128;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace Rukhanka.Samples
|
||||
{
|
||||
public class ScriptedAnimatorSampleUsedAnimationsAuthoring: MonoBehaviour { }
|
||||
|
||||
//=================================================================================================================//
|
||||
|
||||
struct ScriptedAnimatorSampleUsedAnimationsComponent: IComponentData
|
||||
{
|
||||
public FixedList512Bytes<Hash128> clips;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if UNITY_EDITOR
|
||||
class ScriptedAnimatorSampleUsedAnimationsBaker: Baker<ScriptedAnimatorSampleUsedAnimationsAuthoring>
|
||||
{
|
||||
public override void Bake(ScriptedAnimatorSampleUsedAnimationsAuthoring a)
|
||||
{
|
||||
var rigDef = a.GetComponent<RigDefinitionAuthoring>();
|
||||
var avatar = rigDef.GetAvatar();
|
||||
var e = GetEntity(a, TransformUsageFlags.None);
|
||||
var anms = a.GetComponent<AnimationAssetSetAuthoring>();
|
||||
var c = new ScriptedAnimatorSampleUsedAnimationsComponent();
|
||||
for (var i = 0; i < anms.animationClips.Length; ++i)
|
||||
{
|
||||
c.clips.Add(BakingUtils.ComputeAnimationHash(anms.animationClips[i], avatar));
|
||||
}
|
||||
AddComponent(e, c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6026ebc68b6fcbf439739f8d850a0d2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 298480
|
||||
packageName: Rukhanka Animation System 2
|
||||
packageVersion: 2.9.0
|
||||
assetPath: Packages/com.rukhanka.animation/Samples~/Samples/Scenes/21. Scripted Controller/Scripts/ScriptedAnimatorSampleUsedAnimationsAuthoring.cs
|
||||
uploadId: 897522
|
||||
Reference in New Issue
Block a user