breakpoint
before update unity version
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
@@ -8,30 +10,45 @@ namespace BITKit
|
||||
{
|
||||
public class LocationAdditive : MonoBehaviour
|
||||
{
|
||||
[SerializeReference,SubclassSelector] internal IReference autoReference;
|
||||
|
||||
[SerializeField] private bool disabledRotation;
|
||||
[SerializeField] private bool disabledPosition;
|
||||
|
||||
[SerializeField] private Vector3 positionWeight=Vector3.one;
|
||||
[SerializeField] private Vector3 rotationWeight=Vector3.one;
|
||||
|
||||
public Vector3 GlobalPosition { get; private set; }
|
||||
public Vector3 GlobalEuler { get; private set; }
|
||||
public Vector3 GlobalRotation { get; private set; }
|
||||
|
||||
|
||||
private Vector3 currentPosition;
|
||||
private Vector3 currentEuler;
|
||||
private Quaternion currentRotation=Quaternion.identity;
|
||||
|
||||
private Vector3 globalPosition;
|
||||
private Quaternion globalRotation;
|
||||
private readonly Optional<Quaternion> globalRotation = new(Quaternion.identity);
|
||||
|
||||
private Transform _transform;
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get => _transform.localPosition;
|
||||
set => _transform.localPosition = value;
|
||||
}
|
||||
public Quaternion Rotation
|
||||
{
|
||||
get => _transform.localRotation;
|
||||
set => _transform.localRotation = value;
|
||||
}
|
||||
|
||||
public void AddPosition(Vector3 value)
|
||||
{
|
||||
currentPosition += value;
|
||||
}
|
||||
|
||||
public void AddEuler(Vector3 value)
|
||||
// public void AddEuler(Vector3 value)
|
||||
// {
|
||||
// //currentEuler += value;
|
||||
// currentRotation *= Quaternion.Euler(value);
|
||||
// }
|
||||
public void AddRotation(Quaternion value)
|
||||
{
|
||||
currentEuler += value;
|
||||
currentRotation *= value;
|
||||
}
|
||||
|
||||
public void SetGlobalPosition(Vector3 value)
|
||||
@@ -41,32 +58,34 @@ namespace BITKit
|
||||
|
||||
public void SetGlobalRotation(Quaternion value)
|
||||
{
|
||||
globalRotation = value;
|
||||
globalRotation.SetValueThenAllow(value);
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
private void Start()
|
||||
{
|
||||
_transform = transform;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
currentEuler = Vector3.Scale(currentEuler, rotationWeight);
|
||||
currentPosition = Vector3.Scale(currentPosition, positionWeight);
|
||||
|
||||
currentEuler = Vector3.ClampMagnitude(currentEuler, 4096);
|
||||
currentPosition = Vector3.ClampMagnitude(currentPosition, 4096);
|
||||
|
||||
|
||||
if (disabledRotation is false)
|
||||
switch (currentEuler, globalRotation)
|
||||
{
|
||||
if (globalRotation.Allow)
|
||||
{
|
||||
case var (euler, rotation) when euler.IsDefault() is false && rotation.IsDefault():
|
||||
transform.localRotation = Quaternion.Euler(euler);
|
||||
break;
|
||||
case var (euler, rotation) when euler.IsDefault() && rotation.IsDefault() is false:
|
||||
transform.rotation = globalRotation = rotation;
|
||||
break;
|
||||
case var (euler, rotation) when euler.IsDefault() is false && rotation.IsDefault() is false:
|
||||
transform.rotation = globalRotation = rotation * Quaternion.Euler(euler);
|
||||
break;
|
||||
transform.rotation =globalRotation * currentRotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localRotation = currentRotation;
|
||||
}
|
||||
}
|
||||
|
||||
if (disabledPosition is false)
|
||||
{
|
||||
switch (currentPosition, globalPosition)
|
||||
{
|
||||
case var (position, global) when position.IsDefault() is false && global.IsDefault():
|
||||
@@ -79,8 +98,10 @@ namespace BITKit
|
||||
transform.position = globalPosition = global + position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
currentEuler = Vector3.zero;
|
||||
currentRotation = Quaternion.identity;
|
||||
|
||||
currentPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user