BITFALL/Assets/BITKit/Unity/Scripts/Location/LocationAdditiveElement.cs

57 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class LocationAdditiveElement : MonoBehaviour
{
[SerializeField] private bool useLateUpdate;
[SerializeField] private LocationAdditive locationAdditive;
[SerializeField] private Vector3 positionWeight = Vector3.one;
[SerializeField] private Vector3 eulerWeight = Vector3.one;
private Transform Transform;
private void Start()
{
Transform = transform;
}
private void Update()
{
if (useLateUpdate) return;
Tick();
}
private void LateUpdate()
{
if (!useLateUpdate) return;
Tick();
}
private void Tick()
{
var localPosition = Transform.localPosition;
var localEulerAngles = Transform.localEulerAngles;
//locationAdditive.AddPosition(transform.localPosition);
//locationAdditive.AddEuler(transform.localEulerAngles);
locationAdditive.AddPosition(
new Vector3
{
x = localPosition.x * positionWeight.x,
y = localPosition.y * positionWeight.y,
z = localPosition.z * positionWeight.z
});
locationAdditive.AddEuler(
new Vector3
{
x = localEulerAngles.x * eulerWeight.x,
y = localEulerAngles.y * eulerWeight.y,
z = localEulerAngles.z * eulerWeight.z
});
}
}
}