1
This commit is contained in:
51
Src/Unity/Scripts/Components/ResetTransform.cs
Normal file
51
Src/Unity/Scripts/Components/ResetTransform.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class ResetTransform : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private bool resetPosition;
|
||||
[SerializeField] private bool resetRotation;
|
||||
[SerializeField] private bool resetScale;
|
||||
[SerializeField] private bool resetOnDisable;
|
||||
[SerializeField] private bool resetOnEnable;
|
||||
|
||||
private Vector3 _initialPosition;
|
||||
private Vector3 _initialScale;
|
||||
private Quaternion _initialRotation;
|
||||
private Transform Transform;
|
||||
private void Start()
|
||||
{
|
||||
Transform = transform;
|
||||
_initialPosition = Transform.localPosition;
|
||||
_initialRotation = Transform.localRotation;
|
||||
_initialScale = Transform.localScale;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if(resetOnDisable)
|
||||
Execute();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if(resetOnEnable)
|
||||
Execute();
|
||||
}
|
||||
|
||||
private void Execute()
|
||||
{
|
||||
if(resetPosition)
|
||||
Transform.localPosition = _initialPosition;
|
||||
if(resetRotation)
|
||||
Transform.localRotation = _initialRotation;
|
||||
if(resetScale)
|
||||
Transform.localScale = _initialScale;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user