1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
@@ -16,6 +17,10 @@ namespace BITKit
|
||||
[SerializeField] private bool disabledPosition;
|
||||
|
||||
[SerializeField] private Vector3 positionWeight=Vector3.one;
|
||||
|
||||
[SerializeField] private bool debug;
|
||||
|
||||
[SerializeField,ReadOnly(HideLabel = true)] private string debugInfo;
|
||||
|
||||
private Vector3 currentPosition;
|
||||
private Quaternion currentRotation=Quaternion.identity;
|
||||
@@ -25,6 +30,8 @@ namespace BITKit
|
||||
|
||||
private Transform _transform;
|
||||
|
||||
private readonly StringBuilder reportBuilder = new();
|
||||
|
||||
public Vector3 Position
|
||||
{
|
||||
get => _transform.localPosition;
|
||||
@@ -36,9 +43,13 @@ namespace BITKit
|
||||
set => _transform.localRotation = value;
|
||||
}
|
||||
|
||||
public void AddPosition(Vector3 value)
|
||||
public void AddPosition(Vector3 value,string info=null)
|
||||
{
|
||||
currentPosition += value;
|
||||
if (debug)
|
||||
{
|
||||
reportBuilder.AppendLine($"{info}:{value}");
|
||||
}
|
||||
}
|
||||
|
||||
// public void AddEuler(Vector3 value)
|
||||
@@ -46,11 +57,16 @@ namespace BITKit
|
||||
// //currentEuler += value;
|
||||
// currentRotation *= Quaternion.Euler(value);
|
||||
// }
|
||||
public void AddRotation(Quaternion value)
|
||||
public void AddRotation(Quaternion value, string info = null)
|
||||
{
|
||||
currentRotation *= value;
|
||||
if (debug)
|
||||
{
|
||||
reportBuilder.AppendLine($"{info}:{value}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetGlobalPosition(Vector3 value)
|
||||
{
|
||||
globalPosition = value;
|
||||
@@ -103,6 +119,12 @@ namespace BITKit
|
||||
currentRotation = Quaternion.identity;
|
||||
|
||||
currentPosition = Vector3.zero;
|
||||
|
||||
if (debug)
|
||||
{
|
||||
debugInfo = reportBuilder.ToString();
|
||||
reportBuilder.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,11 +16,14 @@ namespace BITKit
|
||||
[SerializeField] private Vector3 positionWeight = Vector3.one;
|
||||
|
||||
[SerializeReference,SubclassSelector] private IReference autoReference;
|
||||
[SerializeReference,SubclassSelector] private IReference nameReference;
|
||||
//[SerializeField] private Vector3 rotationAdditive = Vector3.one;
|
||||
private Transform Transform;
|
||||
|
||||
private string nameCache;
|
||||
private void Start()
|
||||
{
|
||||
nameCache = nameReference is not null?nameReference.Value:gameObject.name;
|
||||
Transform = transform;
|
||||
var components =
|
||||
GetComponentsInParent<LocationAdditive>(true)
|
||||
@@ -39,7 +42,6 @@ namespace BITKit
|
||||
reportBuilder.AppendLine(x.autoReference is not null ? $"{x.autoReference.Value}@{x.transform.name}" : x.name);
|
||||
}
|
||||
BIT4Log.Log<LocationAdditiveElement>($"找不到对应的LocationAdditive:{autoReference.Value} \n{reportBuilder}");
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,11 +60,12 @@ namespace BITKit
|
||||
|
||||
private void Tick()
|
||||
{
|
||||
if (!locationAdditive) return;
|
||||
var localPosition = Transform.localPosition;
|
||||
|
||||
locationAdditive.AddPosition(Vector3.Scale(localPosition, positionWeight));
|
||||
locationAdditive.AddPosition(Vector3.Scale(localPosition, positionWeight), nameReference?.Value);
|
||||
//locationAdditive.AddRotation(Transform.localRotation * Quaternion.Euler(rotationAdditive));
|
||||
locationAdditive.AddRotation(Transform.localRotation);
|
||||
locationAdditive.AddRotation(Transform.localRotation, nameCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user