|
|
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class RotationController : MonoBehaviour
- {
-
- #region Read-Only Fields
- public float RotationPeriod => m_RotationPeriod;
- public Vector3 Position => transform.position;
- public Vector3 RotationAxis => m_RotationAxis;
- public float CorrelusStrength => m_correlusStrength;
- #endregion Read-Only Fields
-
- [SerializeField]
- private float m_RotationPeriod;
-
- [SerializeField]
- private Vector3 m_RotationAxis = Vector3.forward;
-
- [SerializeField]
- private float m_correlusStrength = 100;
-
- [SerializeField]
- private Material m_Skybox;
-
- [SerializeField]
- private float m_SkyboxRotationMultiplier = 1;
-
-
- public Vector3 getDownDirection(Vector3 objectPosition, bool normalized = true)
- {
- if (normalized)
- return Vector3.ProjectOnPlane((objectPosition - transform.position), m_RotationAxis).normalized;
- else
- return Vector3.ProjectOnPlane((objectPosition - transform.position), m_RotationAxis);
-
- }
-
- public Vector3 getPerpendicularDirection(Vector3 objectPosition)
- {
- return Vector3.Cross(RotationAxis, getDownDirection(objectPosition)).normalized;
- }
-
- public Quaternion getUpRotation(Vector3 objectPosition)
- {
- return Quaternion.FromToRotation(Vector3.up, -getDownDirection(objectPosition));
- }
-
-
- private void Start()
- {
- if (m_Skybox == null)
- m_Skybox = RenderSettings.skybox;
- }
-
- private void Update()
- {
- if (m_Skybox != null)
- {
- m_Skybox.SetVector("_RotationAxis", m_RotationAxis);
- m_Skybox.SetFloat("_Rotation", (Time.time * m_SkyboxRotationMultiplier * m_RotationPeriod) % 360);
- }
- }
-
-
- }
|