Exemplo n.º 1
0
        void Awake()
        {
            UIObject3D      = this.GetComponent <UIObject3D>();
            initialRotation = UIObject3DUtilities.NormalizeRotation(UIObject3D.TargetRotation);

            SetupEvents();
        }
Exemplo n.º 2
0
        IEnumerator SnapBack(float time)
        {
            var timeStarted = Time.time;

            float   percentageComplete = 0f;
            Vector3 snapStartRotation  = UIObject3DUtilities.NormalizeRotation(UIObject3D.TargetRotation);


            // This sort of works, but perhaps it would be best to simply go back the way we came?
            float desiredX = (Mathf.Abs(snapStartRotation.x - initialRotation.x) >= 180f) ? (initialRotation.x - 180f) : initialRotation.x;
            float desiredY = (Mathf.Abs(snapStartRotation.y - initialRotation.y) >= 180f) ? (initialRotation.y - 180f) : initialRotation.y;
            float desiredZ = (Mathf.Abs(snapStartRotation.z - initialRotation.z) >= 180f) ? (initialRotation.z - 180f) : initialRotation.z;

            while (percentageComplete < 1f)
            {
                //UIObject3D.TargetRotation = Vector3.Lerp(snapStartRotation, initialRotation, percentageComplete);
                UIObject3D.TargetRotation = new Vector3(
                    (RotateX ? Mathf.Lerp(snapStartRotation.x, desiredX, percentageComplete) : desiredX),
                    (RotateY ? Mathf.Lerp(snapStartRotation.y, desiredY, percentageComplete) : desiredY),
                    (RotateZ ? Mathf.Lerp(snapStartRotation.z, desiredZ, percentageComplete) : desiredZ)
                    );

                percentageComplete = (Time.time - timeStarted) / time;

                yield return(null);
            }

            UIObject3D.TargetRotation = initialRotation;
        }