57 lines
1.2 KiB
C#
57 lines
1.2 KiB
C#
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit
|
|
{
|
|
public static class TransformExtensions
|
|
{
|
|
public static UnityTransform ToUnityTransform(this Transform transform)
|
|
{
|
|
return new UnityTransform(transform);
|
|
}
|
|
}
|
|
public readonly struct UnityTransform:ITransform
|
|
{
|
|
private readonly Transform _transform;
|
|
public UnityTransform(Transform transform)
|
|
{
|
|
_transform = transform;
|
|
}
|
|
public void Dispose()
|
|
{
|
|
if (_transform)
|
|
Object.Destroy(_transform.gameObject);
|
|
}
|
|
|
|
public float3 LocalPosition
|
|
{
|
|
get => _transform.localPosition;
|
|
set => _transform.localPosition = value;
|
|
}
|
|
public float3 Position
|
|
{
|
|
get => _transform.position;
|
|
set => _transform.position = value;
|
|
}
|
|
public quaternion LocalRotation
|
|
{
|
|
get => _transform.localRotation;
|
|
set => _transform.localRotation = value;
|
|
}
|
|
public quaternion Rotation
|
|
{
|
|
get => _transform.rotation;
|
|
set => _transform.rotation = value;
|
|
}
|
|
public float3 LocalScale
|
|
{
|
|
get => _transform.localScale;
|
|
set => _transform.localScale = value;
|
|
}
|
|
public float4x4 Matrix
|
|
{
|
|
get =>new float4x4(_transform);
|
|
set => _transform.SetPositionAndRotation(value.c3.xyz,quaternion.LookRotation(value.c2.xyz,value.c1.xyz));
|
|
}
|
|
}
|
|
} |