yyl
2025-06-09 b9751b2f076ee050fe5b685e91ae4fc4469b1015
Main/Component/UI/Decorate/PingPong/PingPongRotation.cs
@@ -1,47 +1,46 @@
using UnityEngine;
using System.Collections;
namespace vnxbqy.UI {
    public class PingPongRotation:MonoBehaviour {
        public Transform reference;
        public Vector3 amplitue;
        public float speed;
public class PingPongRotation:MonoBehaviour {
        Vector3 referenceEuler = Vector3.zero;
    public Transform reference;
    public Vector3 amplitue;
    public float speed;
        void OnEnable() {
            referenceEuler = reference == null ? this.transform.localEulerAngles : reference.localEulerAngles;
        }
    Vector3 referenceEuler = Vector3.zero;
        float x = 0f;
        float y = 0f;
        float z = 0f;
        void LateUpdate() {
            if(Mathf.Abs(amplitue.x) > 0.001f) {
                x = referenceEuler.x - amplitue.x * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.x);
            }
            else {
                x = referenceEuler.x;
            }
            if(Mathf.Abs(amplitue.y) > 0.001f) {
                y = referenceEuler.y - amplitue.y * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.y);
            }
            else {
                y = referenceEuler.y;
            }
            if(Mathf.Abs(amplitue.z) > 0.001f) {
                z = referenceEuler.z - amplitue.z * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.z);
            }
            else {
                z = referenceEuler.z;
            }
            this.transform.localEulerAngles = new Vector3(x,y,z);
        }
    void OnEnable() {
        referenceEuler = reference == null ? this.transform.localEulerAngles : reference.localEulerAngles;
    }
    float x = 0f;
    float y = 0f;
    float z = 0f;
    void LateUpdate() {
        if(Mathf.Abs(amplitue.x) > 0.001f) {
            x = referenceEuler.x - amplitue.x * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.x);
        }
        else {
            x = referenceEuler.x;
        }
        if(Mathf.Abs(amplitue.y) > 0.001f) {
            y = referenceEuler.y - amplitue.y * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.y);
        }
        else {
            y = referenceEuler.y;
        }
        if(Mathf.Abs(amplitue.z) > 0.001f) {
            z = referenceEuler.z - amplitue.z * 0.5f + Mathf.PingPong(Time.time * speed,amplitue.z);
        }
        else {
            z = referenceEuler.z;
        }
        this.transform.localEulerAngles = new Vector3(x,y,z);
    }
}