public override void CopyFrom(object source)
    {
        AnimationCurveData src = source as AnimationCurveData;

        base.CopyFrom(src);
        _desc  = src._desc;
        _curve = src._curve;
    }
Example #2
0
 private AnimationCurve GetAnimationCurveX(string curveName)
 {
     for (int i = 0; i < curveDataArray.Count; i++)
     {
         AnimationCurveData data = curveDataArray[i];
         if (data.curveName == curveName)
         {
             return(data.curve);
         }
     }
     Debug.LogError("AnimationCurve is not exist: " + curveName);
     return(null);
 }
    private void SaveRange(MaterialProperty prop, Material material)
    {
        AnimationCurveData curveData = GetDataSubAsset(prop, AssetDatabase.GetAssetPath(material));

        if (curveData != null)
        {
            AssetDatabase.RemoveObjectFromAsset(curveData);

            curveData.animationCurveRange = curveRange;

            AssetDatabase.AddObjectToAsset(curveData, material);

            AssetDatabase.SaveAssets();
        }
    }
    private AnimationCurveData GetDataSubAsset(MaterialProperty prop, string materialPath)
    {
        AnimationCurveData curveData = null;

        UnityEngine.Object[] subAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath(materialPath);

        for (int i = 0; i < subAssets.Length; i++)
        {
            if (subAssets[i].name == prop.name + subAssetDataEnding)
            {
                curveData = subAssets[i] as AnimationCurveData;
            }
        }

        return(curveData);
    }
    private void LoadCurveData(MaterialProperty prop, Material material)
    {
        AnimationCurveData curveData = GetDataSubAsset(prop, AssetDatabase.GetAssetPath(material));

        if (curveData == null)
        {
            DefaultCurve();
        }
        else
        {
            curve = curveData.animationCurve;

            curveRange = curveData.animationCurveRange;

            textureResolution = curveData.resolution;
        }
    }
        /// <summary>
        /// Upgrades old animations (GR2 files with header version v6) to the new CurveData format
        /// </summary>
        public void UpgradeToGr7()
        {
            // Skip if we've already upgraded
            if (this.CurveData != null)
            {
                return;
            }

            if (this.Degree == 0)
            {
                // Degree 0 curves are identities in all cases
                var curve = new DaIdentity();
                curve.CurveDataHeader_DaIdentity        = new CurveDataHeader();
                curve.CurveDataHeader_DaIdentity.Format = (byte)CurveFormat.DaIdentity;
                curve.CurveDataHeader_DaIdentity.Degree = 0;
                this.CurveData = curve;
            }
            else if (this.Degree == 2)
            {
                if (this.Knots == null || this.Controls == null)
                {
                    throw new InvalidOperationException("Could not upgrade animation curve: knots/controls unavailable");
                }

                // Degree 2 curves are stored in K32fC32f (v6 didn't support multiple curve formats)
                var curve = new DaK32fC32f();
                curve.CurveDataHeader_DaK32fC32f        = new CurveDataHeader();
                curve.CurveDataHeader_DaK32fC32f.Format = (byte)CurveFormat.DaK32fC32f;
                curve.CurveDataHeader_DaK32fC32f.Degree = 2;
                curve.Controls = Controls;
                curve.Knots    = Knots;
                this.CurveData = curve;
            }
            else
            {
                throw new InvalidOperationException("Could not upgrade animation curve: Unsupported curve degree");
            }
        }
    private void SaveDataTexture(MaterialProperty prop, Material material)
    {
        string materialPath = AssetDatabase.GetAssetPath(material);

        ClearOldSubAssets(prop, materialPath);

        curveTexture.name = prop.name + subAssetTextureEnding;

        AssetDatabase.AddObjectToAsset(curveTexture, material);

        AnimationCurveData curveData = ScriptableObject.CreateInstance <AnimationCurveData>();

        curveData.name                = prop.name + subAssetDataEnding;
        curveData.animationCurve      = curve;
        curveData.animationCurveRange = curveRange;
        curveData.resolution          = textureResolution;

        AssetDatabase.AddObjectToAsset(curveData, material);

        AssetDatabase.SaveAssets();

        prop.textureValue = GetTextureSubAsset(prop, materialPath);
    }