UnityEditor.CurveEditorWindow.CopyAndScaleCurveKeys C# (CSharp) Method

CopyAndScaleCurveKeys() private static method

private static CopyAndScaleCurveKeys ( Keyframe orgKeys, Rect rect, bool realToNormalized ) : UnityEngine.Keyframe[]
orgKeys UnityEngine.Keyframe
rect UnityEngine.Rect
realToNormalized bool
return UnityEngine.Keyframe[]
        private static Keyframe[] CopyAndScaleCurveKeys(Keyframe[] orgKeys, Rect rect, bool realToNormalized)
        {
            if (((rect.width == 0f) || (rect.height == 0f)) || (float.IsInfinity(rect.width) || float.IsInfinity(rect.height)))
            {
                Debug.LogError("CopyAndScaleCurve: Invalid scale: " + rect);
                return orgKeys;
            }
            Keyframe[] keyframeArray2 = new Keyframe[orgKeys.Length];
            if (realToNormalized)
            {
                for (int j = 0; j < keyframeArray2.Length; j++)
                {
                    keyframeArray2[j].time = (orgKeys[j].time - rect.xMin) / rect.width;
                    keyframeArray2[j].value = (orgKeys[j].value - rect.yMin) / rect.height;
                }
                return keyframeArray2;
            }
            for (int i = 0; i < keyframeArray2.Length; i++)
            {
                keyframeArray2[i].time = (orgKeys[i].time * rect.width) + rect.xMin;
                keyframeArray2[i].value = (orgKeys[i].value * rect.height) + rect.yMin;
            }
            return keyframeArray2;
        }

Usage Example

示例#1
0
 private void PresetDropDown(Rect rect)
 {
     if (EditorGUI.ButtonMouseDown(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.inspectorTitlebarText))
     {
         if (this.m_Curve != null)
         {
             if (this.m_CurvePresets == null)
             {
                 Debug.LogError("Curve presets error");
             }
             else
             {
                 this.ValidateCurveLibraryTypeAndScale();
                 AnimationCurve animationCurve = new AnimationCurve();
                 Rect           rect2;
                 if (this.GetNormalizationRect(out rect2))
                 {
                     bool realToNormalized = true;
                     animationCurve.keys = CurveEditorWindow.CopyAndScaleCurveKeys(this.m_Curve.keys, rect2, realToNormalized);
                 }
                 else
                 {
                     animationCurve = new AnimationCurve(this.m_Curve.keys);
                 }
                 animationCurve.postWrapMode             = this.m_Curve.postWrapMode;
                 animationCurve.preWrapMode              = this.m_Curve.preWrapMode;
                 this.m_CurvePresets.curveToSaveAsPreset = animationCurve;
                 PopupWindow.Show(rect, this.m_CurvePresets);
             }
         }
     }
 }
All Usage Examples Of UnityEditor.CurveEditorWindow::CopyAndScaleCurveKeys