1
This commit is contained in:
@@ -15,20 +15,20 @@ namespace BITFALL.Rig{
|
||||
public class TickOverrideTranformService : MonoBehaviour
|
||||
{
|
||||
//[BurstCompile]
|
||||
public struct CopyTransformJob : IJobParallelForTransform
|
||||
{
|
||||
[Unity.Collections.ReadOnly]
|
||||
public NativeArray<float3> positions;
|
||||
[Unity.Collections.ReadOnly]
|
||||
public NativeArray<quaternion> rotations;
|
||||
|
||||
|
||||
// The code actually running on the job
|
||||
public void Execute(int index, TransformAccess transform)
|
||||
{
|
||||
transform.SetPositionAndRotation(positions[index],rotations[index]);
|
||||
}
|
||||
}
|
||||
// public struct CopyTransformJob : IJobParallelForTransform
|
||||
// {
|
||||
// [Unity.Collections.ReadOnly]
|
||||
// public NativeArray<float3> positions;
|
||||
// [Unity.Collections.ReadOnly]
|
||||
// public NativeArray<quaternion> rotations;
|
||||
//
|
||||
//
|
||||
// // The code actually running on the job
|
||||
// public void Execute(int index, TransformAccess transform)
|
||||
// {
|
||||
// transform.SetPositionAndRotation(positions[index],rotations[index]);
|
||||
// }
|
||||
// }
|
||||
public static void Register(int id,TickOverrideTransform tickOverrideTransform)
|
||||
{
|
||||
Dictionary.Add(id,tickOverrideTransform);
|
||||
@@ -47,11 +47,11 @@ namespace BITFALL.Rig{
|
||||
|
||||
[SerializeReference, SubclassSelector] private ITicker ticker;
|
||||
|
||||
private TransformAccessArray m_AccessArray;
|
||||
private NativeArray<quaternion> _rotations;
|
||||
private NativeArray<float3> _positions;
|
||||
private JobHandle _jobHandle;
|
||||
private InitializationState _initializationState;
|
||||
// private TransformAccessArray m_AccessArray;
|
||||
// private NativeArray<quaternion> _rotations;
|
||||
// private NativeArray<float3> _positions;
|
||||
// private JobHandle _jobHandle;
|
||||
// private InitializationState _initializationState;
|
||||
private void OnEnable()
|
||||
{
|
||||
ticker.Add(Tick);
|
||||
@@ -60,27 +60,40 @@ namespace BITFALL.Rig{
|
||||
{
|
||||
ticker.Remove(Tick);
|
||||
}
|
||||
|
||||
// private void OnDestroy()
|
||||
// {
|
||||
// if (_initializationState is not InitializationState.Initializing) return;
|
||||
// _jobHandle.Complete();
|
||||
// _rotations.Dispose();
|
||||
// _positions.Dispose();
|
||||
// }
|
||||
|
||||
private void Tick(float obj)
|
||||
{
|
||||
switch (_initializationState)
|
||||
{
|
||||
case InitializationState.Initializing when _jobHandle.IsCompleted:
|
||||
_jobHandle.Complete();
|
||||
_rotations.Dispose();
|
||||
_positions.Dispose();
|
||||
_initializationState = InitializationState.Initialized;
|
||||
break;
|
||||
case InitializationState.None:
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
// switch (_initializationState)
|
||||
// {
|
||||
// case InitializationState.Initializing when _jobHandle.IsCompleted:
|
||||
// _jobHandle.Complete();
|
||||
// _rotations.Dispose();
|
||||
// _positions.Dispose();
|
||||
// _initializationState = InitializationState.Initialized;
|
||||
// break;
|
||||
// case InitializationState.None:
|
||||
// break;
|
||||
// default:
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (IsDirty)
|
||||
{
|
||||
var newLength = Dictionary.Count;
|
||||
Sources = new Transform[newLength];
|
||||
Targets = new Transform[newLength];
|
||||
|
||||
//_positions = new NativeArray<float3>(newLength, Allocator.Persistent);
|
||||
//_rotations = new NativeArray<quaternion>(newLength, Allocator.Persistent);
|
||||
|
||||
var index = 0;
|
||||
foreach (var x in Dictionary.Values)
|
||||
{
|
||||
@@ -94,27 +107,34 @@ namespace BITFALL.Rig{
|
||||
|
||||
if(length is 0) return;
|
||||
|
||||
m_AccessArray = new TransformAccessArray(length);
|
||||
m_AccessArray.SetTransforms(Sources);
|
||||
// m_AccessArray = new TransformAccessArray(length);
|
||||
// m_AccessArray.SetTransforms(Sources);
|
||||
|
||||
_positions = new NativeArray<float3>(length, Allocator.Persistent);
|
||||
_rotations = new NativeArray<quaternion>(length, Allocator.Persistent);
|
||||
|
||||
var i = 0;
|
||||
foreach (var x in Targets)
|
||||
for (var j = 0; j < length; j++)
|
||||
{
|
||||
_positions[i] = x.position;
|
||||
_rotations[i] = x.rotation;
|
||||
i++;
|
||||
Sources[j].SetPositionAndRotation(Targets[j].position,Targets[j].rotation);
|
||||
}
|
||||
var _job = new CopyTransformJob()
|
||||
{
|
||||
positions = _positions,
|
||||
rotations = _rotations
|
||||
};
|
||||
_jobHandle = _job.Schedule(m_AccessArray);
|
||||
|
||||
_initializationState = InitializationState.Initializing;
|
||||
// foreach (var x in Targets)
|
||||
// {
|
||||
// _positions[i] = x.position;
|
||||
// _rotations[i] = x.rotation;
|
||||
// i++;
|
||||
// }
|
||||
//
|
||||
// foreach (var x in Sources)
|
||||
// {
|
||||
// x.position = _positions[i];
|
||||
// x.rotation = _rotations[i];
|
||||
// }
|
||||
// var _job = new CopyTransformJob()
|
||||
// {
|
||||
// positions = _positions,
|
||||
// rotations = _rotations
|
||||
// };
|
||||
// _jobHandle = _job.Schedule(m_AccessArray);
|
||||
//
|
||||
// _initializationState = InitializationState.Initializing;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user