Exemplo n.º 1
0
        private void DrawOption(Rect position, ref System.Type propType, SerializedProperty optionProp)
        {
            if (propType == typeof(Vector2) || propType == typeof(Vector3) || propType == typeof(Vector4) || propType == typeof(Color))
            {
                bool value = ConvertUtil.ToBool(optionProp.intValue);
                value = EditorGUI.Toggle(position, "Option (Use Slerp)", value);
                optionProp.intValue = value ? 1 : 0;
            }
            else if (propType == typeof(Quaternion))
            {
                QuaternionTweenOption value = QuaternionTweenOption.Spherical;
                if (System.Enum.IsDefined(typeof(QuaternionTweenOption), optionProp.intValue))
                {
                    value = (QuaternionTweenOption)optionProp.intValue;
                }

                value = (QuaternionTweenOption)EditorGUI.EnumPopup(position, "Option", value);
                optionProp.intValue = (int)value;
                if (value == QuaternionTweenOption.Long)
                {
                    propType = typeof(Vector3);
                }
            }
            else
            {
                EditorGUI.LabelField(position, "Option", "(no option available)");
            }
        }
 public QuaternionMemberCurve(string propName, Ease ease, float dur, Vector3 eulerStart, Vector3 eulerEnd, QuaternionTweenOption mode)
     : base(propName, ease, dur)
 {
     _option    = mode;
     _start     = Quaternion.Euler(eulerStart);
     _end       = Quaternion.Euler(eulerEnd);
     _startLong = eulerStart;
     _endLong   = eulerEnd;
 }
 public QuaternionMemberCurve(string propName, Ease ease, float dur, Quaternion start, Quaternion end, QuaternionTweenOption mode)
     : base(propName, ease, dur)
 {
     _start     = start;
     _end       = end;
     _startLong = start.eulerAngles;
     _endLong   = end.eulerAngles;
     _option    = mode == QuaternionTweenOption.Long ? QuaternionTweenOption.Spherical : mode;
 }
 public QuaternionMemberCurve(string propName, float dur, Quaternion start, Quaternion end)
     : base(propName, dur)
 {
     _start     = start;
     _end       = end;
     _startLong = start.eulerAngles;
     _endLong   = end.eulerAngles;
     _option    = QuaternionTweenOption.Spherical;
 }
        void ISupportRedirectToMemberCurve.ConfigureAsRedirectTo(System.Type memberType, float totalDur, object current, object start, object end, object option)
        {
            _option = ConvertUtil.ToEnum <QuaternionTweenOption>(option);
            if (_option == QuaternionTweenOption.Long)
            {
                var c = QuaternionUtil.MassageAsEuler(current);
                var s = QuaternionUtil.MassageAsEuler(start);
                var e = QuaternionUtil.MassageAsEuler(end);

                c.x = MathUtil.NormalizeAngleToRange(c.x, s.x, e.x, false);
                c.y = MathUtil.NormalizeAngleToRange(c.y, s.y, e.y, false);
                c.z = MathUtil.NormalizeAngleToRange(c.z, s.z, e.z, false);

                _startLong = c;
                _endLong   = e;
                _start     = Quaternion.Euler(_startLong);
                _end       = Quaternion.Euler(_endLong);

                c            -= s;
                e            -= s;
                this.Duration = totalDur * (VectorUtil.NearZeroVector(e) ? 0f : 1f - c.magnitude / e.magnitude);
            }
            else
            {
                //treat as quat
                var c = QuaternionUtil.MassageAsQuaternion(current);
                var s = QuaternionUtil.MassageAsQuaternion(start);
                var e = QuaternionUtil.MassageAsQuaternion(end);
                _start     = c;
                _end       = e;
                _startLong = _start.eulerAngles;
                _endLong   = _end.eulerAngles;

                var at = Quaternion.Angle(s, e);
                if ((System.Math.Abs(at) < MathUtil.EPSILON))
                {
                    this.Duration = 0f;
                }
                else
                {
                    var ap = Quaternion.Angle(s, c);
                    this.Duration = (1f - ap / at) * totalDur;
                }
            }
        }
 protected override void ReflectiveInit(System.Type memberType, object start, object end, object option)
 {
     _option = ConvertUtil.ToEnum <QuaternionTweenOption>(option);
     if (_option == QuaternionTweenOption.Long)
     {
         _startLong = QuaternionUtil.MassageAsEuler(start);
         _endLong   = QuaternionUtil.MassageAsEuler(end);
         _start     = Quaternion.Euler(_startLong);
         _end       = Quaternion.Euler(_endLong);
     }
     else
     {
         _start     = QuaternionUtil.MassageAsQuaternion(start);
         _end       = QuaternionUtil.MassageAsQuaternion(end);
         _startLong = _start.eulerAngles;
         _endLong   = _end.eulerAngles;
     }
 }