Пример #1
0
        /// <summary>Handle developer relative postiion adjustment</summary>
        /// <param name="preset"></param>
        /// <returns></returns>
        internal static bool OnSceneHandlePosition(Preset preset)
        {
            bool changed = false;

            // Visualize handler's
            if (Tools.current == Tool.Move)
            {
                Tools.hidden = true;
                Quaternion handlerQuat = (Tools.pivotRotation == PivotRotation.Global) ? Quaternion.identity : preset.transform.rotation;

                // Camera position handler
                float
                    radius = preset.m_VirtualPosition.m_Camera.m_Coordinates.radius;
                Transform
                    tran = preset.Instance.m_ChaseTargetOffsetHandler.transform;
                Vector3
                    org  = tran.position.PointOnDistance((preset.Instance.m_PitchHandler.transform.forward * radius), radius),
                    edit = Handles.PositionHandle(org, handlerQuat),
                    ld1  = tran.InverseTransformPoint(org),
                    ld2  = tran.InverseTransformPoint(edit);

                if (!edit.Equals(org))
                {
                    Undo.RecordObject(preset, "Change Camera coordinates" + preset.GetInstanceID());
                    SphericalCoordinates
                        sc1 = SphericalCoordinates.RelativeToTarget(ld1, Vector3.zero),
                        sc2 = SphericalCoordinates.RelativeToTarget(ld2, Vector3.zero);
                    preset.Instance.YawDegree     = preset.m_VirtualPosition.m_Camera.m_Coordinates.Yaw += sc1.Yaw - sc2.Yaw;
                    preset.Instance.PitchDegree   = preset.m_VirtualPosition.m_Camera.m_Coordinates.Pitch += sc1.Pitch - sc2.Pitch;
                    preset.Instance.OrbitDistance = preset.m_VirtualPosition.m_Camera.m_Coordinates.radius = sc2.radius;
                    preset.m_Editing = true;
                    changed          = true;
                }

                // ExtendLookAt handler
                if (preset.m_VirtualPosition.m_EnableLookTarget)
                {
                    radius = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.radius;
                    tran   = preset.Instance.m_PitchLookAtHandler.transform;
                    org    = tran.position.PointOnDistance((tran.forward * radius), radius);
                    edit   = Handles.PositionHandle(org, handlerQuat);
                    ld1    = tran.InverseTransformPoint(org);
                    ld2    = tran.InverseTransformPoint(edit);
                    if (!edit.Equals(org))
                    {
                        Undo.RecordObject(preset, "Change lookAt coordinates" + preset.GetInstanceID());
                        SphericalCoordinates
                            sc1 = SphericalCoordinates.RelativeToTarget(ld1, Vector3.zero),
                            sc2 = SphericalCoordinates.RelativeToTarget(ld2, Vector3.zero);
                        preset.Instance.YawLookAtDegree     = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.Yaw += sc1.Yaw - sc2.Yaw;
                        preset.Instance.PitchLookAtDegree   = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.Pitch += sc1.Pitch - sc2.Pitch;
                        preset.Instance.OrbitLookAtDistance = preset.m_VirtualPosition.m_LookTarget.m_Coordinates.radius = sc2.radius;
                        preset.m_Editing = true;
                        changed          = true;
                    }
                }
            }
            return(changed);
        }