1
This commit is contained in:
58
Assets/BITKit/Unity/Scripts/Transform/UnityTransform.cs
Normal file
58
Assets/BITKit/Unity/Scripts/Transform/UnityTransform.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user