Ejemplo n.º 1
0
        public void DrawDetails(Rect position, SerializedProperty property)
        {
            var cache = SPGUI.DisableIfPlaying();

            //draw basic details
            var yMin = position.yMin;

            for (int i = 0; i < _detailProps.Length; i++)
            {
                //var r = new Rect(position.xMin, yMin + i * EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight);
                switch (_detailProps[i])
                {
                case SPAnimClip.PROP_WRAPMODE:
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    var wrapModeProp = property.FindPropertyRelative(SPAnimClip.PROP_WRAPMODE);
                    wrapModeProp.SetEnumValue(SPEditorGUI.WrapModeField(r, wrapModeProp.displayName, wrapModeProp.GetEnumValue <WrapMode>(), true));
                }
                break;

                case "ScaledDuration":
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    var label = EditorHelper.TempContent("Scaled Duration", "The duration of the clip with the speed applied. Modifying this alters the 'speed' property.");
                    var clip  = property.FindPropertyRelative(PROP_CLIP).objectReferenceValue as AnimationClip;
                    if (clip == null)
                    {
                        EditorGUI.FloatField(r, label, 0f);
                        continue;
                    }

                    var   speedProp = property.FindPropertyRelative(SPAnimClip.PROP_SPEED);
                    float dur       = (speedProp.floatValue == 0f) ? float.PositiveInfinity : Mathf.Abs(clip.length / speedProp.floatValue);
                    EditorGUI.BeginChangeCheck();

                    dur = EditorGUI.FloatField(r, label, dur);

                    if (EditorGUI.EndChangeCheck())
                    {
                        speedProp.floatValue = (dur <= 0f) ? 0f : clip.length / dur;
                    }
                }
                break;

                default:
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    EditorGUI.PropertyField(r, property.FindPropertyRelative(_detailProps[i]));
                }
                break;
                }
            }

            cache.Reset();
        }