protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
#warning TODO: values acording to read version (current 2017.3.0f3)
            YAMLMappingNode node = base.ExportYAMLRoot(container);
            node.AddSerializedVersion(GetSerializedVersion(container.Version));
            node.Add("m_Legacy", GetIsLegacy(container.Version));
            node.Add("m_Compressed", Compressed);
            node.Add("m_UseHighQualityCurve", UseHightQualityCurve);

            AnimationCurves curves = GetAnimationCurves(container.Version, container.Platform);
            node.Add("m_RotationCurves", curves.RotationCurves.ExportYAML(container));
            node.Add("m_CompressedRotationCurves", curves.RotationCurves.ExportYAML(container));
            node.Add("m_EulerCurves", curves.EulerCurves.ExportYAML(container));
            node.Add("m_PositionCurves", curves.PositionCurves.ExportYAML(container));
            node.Add("m_ScaleCurves", curves.ScaleCurves.ExportYAML(container));
            node.Add("m_FloatCurves", curves.FloatCurves.ExportYAML(container));
            node.Add("m_PPtrCurves", curves.PPtrCurves.ExportYAML(container));

            node.Add("m_SampleRate", SampleRate);
            node.Add("m_WrapMode", (int)WrapMode);
            node.Add("m_Bounds", Bounds.ExportYAML(container));
            node.Add("m_ClipBindingConstant", ClipBindingConstant.ExportYAML(container));
            node.Add("m_AnimationClipSettings", MuscleClip.ExportYAML(container));
            node.Add("m_EditorCurves", YAMLSequenceNode.Empty);
            node.Add("m_EulerEditorCurves", YAMLSequenceNode.Empty);
            node.Add("m_HasGenericRootTransform", false);
            node.Add("m_HasMotionFloatCurves", false);
            node.Add("m_GenerateMotionCurves", false);
            node.Add("m_Events", IsReadEvents(container.Version) ? m_events.ExportYAML(container) : YAMLSequenceNode.Empty);

            return(node);
        }
Beispiel #2
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.AddSerializedVersion(GetSerializedVersion(container.ExportVersion));
            node.Add(LegacyName, GetLegacy(container.Version));
            node.Add(CompressedName, Compressed);
            node.Add(UseHighQualityCurveName, UseHightQualityCurve);

            AnimationCurves curves = GetAnimationCurves(container.Version, container.Flags);

            node.Add(RotationCurvesName, curves.RotationCurves.ExportYAML(container));
            node.Add(CompressedRotationCurvesName, curves.CompressedRotationCurves.ExportYAML(container));
            node.Add(EulerCurvesName, curves.EulerCurves.ExportYAML(container));
            node.Add(PositionCurvesName, curves.PositionCurves.ExportYAML(container));
            node.Add(ScaleCurvesName, curves.ScaleCurves.ExportYAML(container));
            node.Add(FloatCurvesName, curves.FloatCurves.ExportYAML(container));
            node.Add(PPtrCurvesName, curves.PPtrCurves.ExportYAML(container));

            node.Add(SampleRateName, SampleRate);
            node.Add(WrapModeName, (int)WrapMode);
            node.Add(BoundsName, Bounds.ExportYAML(container));
            node.Add(ClipBindingConstantName, GetClipBindingConstant(container.Version).ExportYAML(container));
            node.Add(AnimationClipSettingsName, GetAnimationClipSettings(container.Version, container.Flags).ExportYAML(container));
            node.Add(EditorCurvesName, GetEditorCurves(container.Version, container.Flags).ExportYAML(container));
            node.Add(EulerEditorCurvesName, GetEulerEditorCurves(container.Version, container.Flags).ExportYAML(container));
            node.Add(HasGenericRootTransformName, HasGenericRootTransform);
            node.Add(HasMotionFloatCurvesName, HasMotionFloatCurves);
            node.Add(GenerateMotionCurvesName, GetGenerateMotionCurves(container.Version, container.Flags));
            node.Add(EventsName, GetEvents(container.Version).ExportYAML(container));

            return(node);
        }
        public void DrawScene(SpriteBatch spriteBatch)
        {
            float t  = (float)(totalTime.TotalMilliseconds / (2 * TransitionTime.TotalMilliseconds));
            float tt = AnimationCurves.Fade(t);

            levelRenderer.Render(levelCollection.CurrentLevel, spriteBatch, tt);
        }
Beispiel #4
0
        public void Advance(Level level, TimeSpan elapsedTime)
        {
            this.elapsedAnimation += elapsedTime;
            if (elapsedAnimation > AnimationDuration)
            {
                elapsedAnimation = AnimationDuration;
            }

            float t  = (float)(elapsedAnimation.TotalMilliseconds / AnimationDuration.TotalMilliseconds);
            float tt = AnimationCurves.Movement(t);

            level.Crates.Remove(intermediatePoint);
            intermediatePoint = (1 - tt) * initialPoint + tt * destinationPoint;
            level.Crates.Add(intermediatePoint);
        }
Beispiel #5
0
        public void Advance(Level level, TimeSpan elapsedTime)
        {
            this.elapsedAnimation += elapsedTime;
            if (elapsedAnimation > AnimationDuration)
            {
                elapsedAnimation = AnimationDuration;
            }

            float t = (float)(elapsedAnimation.TotalMilliseconds / AnimationDuration.TotalMilliseconds);

            level.PlayerFrameCycle = (int)(t * 3) % 2;
            level.PlayerDirection  = finalDirection;
            float tt = AnimationCurves.Movement(t);

            level.PlayerPosition = (1 - tt) * initialPoint + tt * destinationPoint;
        }
        /// <summary>
        /// Loads curve and event information from the provided clip, and creates a new instance of this object containing
        /// the required data for editing the source clip in the animation editor.
        /// </summary>
        /// <param name="clip">Clip to load.</param>
        /// <returns>Editor specific editable information about an animation clip.</returns>
        public static EditorAnimClipInfo Create(AnimationClip clip)
        {
            EditorAnimClipInfo clipInfo = new EditorAnimClipInfo();

            clipInfo.clip       = clip;
            clipInfo.isImported = IsClipImported(clip);
            clipInfo.sampleRate = (int)clip.SampleRate;

            AnimationCurves        clipCurves      = clip.Curves;
            EditorAnimClipTangents editorCurveData = null;

            string resourcePath = ProjectLibrary.GetPath(clip);

            if (!string.IsNullOrEmpty(resourcePath))
            {
                LibraryEntry entry    = ProjectLibrary.GetEntry(resourcePath);
                string       clipName = PathEx.GetTail(resourcePath);

                if (entry != null && entry.Type == LibraryEntryType.File)
                {
                    FileEntry      fileEntry = (FileEntry)entry;
                    ResourceMeta[] metas     = fileEntry.ResourceMetas;

                    if (clipInfo.isImported)
                    {
                        for (int i = 0; i < metas.Length; i++)
                        {
                            if (clipName == metas[i].SubresourceName)
                            {
                                editorCurveData = metas[i].EditorData as EditorAnimClipTangents;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (metas.Length > 0)
                        {
                            editorCurveData = metas[0].EditorData as EditorAnimClipTangents;
                        }
                    }
                }
            }

            if (editorCurveData == null)
            {
                editorCurveData = new EditorAnimClipTangents();
            }

            int globalCurveIdx = 0;
            Action <NamedVector3Curve[], EditorVector3CurveTangents[], string> loadVector3Curve =
                (curves, tangents, subPath) =>
            {
                foreach (var curveEntry in curves)
                {
                    TangentMode[] tangentsX = null;
                    TangentMode[] tangentsY = null;
                    TangentMode[] tangentsZ = null;

                    if (tangents != null)
                    {
                        foreach (var tangentEntry in tangents)
                        {
                            if (tangentEntry.name == curveEntry.name)
                            {
                                tangentsX = tangentEntry.tangentsX;
                                tangentsY = tangentEntry.tangentsY;
                                tangentsZ = tangentEntry.tangentsZ;
                                break;
                            }
                        }
                    }

                    // Convert compound curve to three per-component curves
                    AnimationCurve[] componentCurves = AnimationUtility.SplitCurve(curveEntry.curve);

                    FieldAnimCurves fieldCurves = new FieldAnimCurves();
                    fieldCurves.type            = SerializableProperty.FieldType.Vector3;
                    fieldCurves.curveInfos      = new CurveDrawInfo[3];
                    fieldCurves.isPropertyCurve = !clipInfo.isImported;

                    fieldCurves.curveInfos[0]       = new CurveDrawInfo();
                    fieldCurves.curveInfos[0].curve = new EdAnimationCurve(componentCurves[0], tangentsX);
                    fieldCurves.curveInfos[0].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);

                    fieldCurves.curveInfos[1]       = new CurveDrawInfo();
                    fieldCurves.curveInfos[1].curve = new EdAnimationCurve(componentCurves[1], tangentsY);
                    fieldCurves.curveInfos[1].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);

                    fieldCurves.curveInfos[2]       = new CurveDrawInfo();
                    fieldCurves.curveInfos[2].curve = new EdAnimationCurve(componentCurves[2], tangentsZ);
                    fieldCurves.curveInfos[2].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);

                    string curvePath = curveEntry.name.TrimEnd('/') + subPath;
                    clipInfo.curves[curvePath] = fieldCurves;
                }
            };

            // Convert rotation from quaternion to euler
            NamedQuaternionCurve[] rotationCurves      = clipCurves.Rotation;
            NamedVector3Curve[]    eulerRotationCurves = new NamedVector3Curve[rotationCurves.Length];
            for (int i = 0; i < rotationCurves.Length; i++)
            {
                eulerRotationCurves[i]       = new NamedVector3Curve();
                eulerRotationCurves[i].name  = rotationCurves[i].name;
                eulerRotationCurves[i].flags = rotationCurves[i].flags;
                eulerRotationCurves[i].curve = AnimationUtility.QuaternionToEulerCurve(rotationCurves[i].curve);
            }

            loadVector3Curve(clipCurves.Position, editorCurveData.positionCurves, "/Position");
            loadVector3Curve(eulerRotationCurves, editorCurveData.rotationCurves, "/Rotation");
            loadVector3Curve(clipCurves.Scale, editorCurveData.scaleCurves, "/Scale");

            // Find which individual float curves belong to the same field
            Dictionary <string, Tuple <int, int, bool>[]> floatCurveMapping = new Dictionary <string, Tuple <int, int, bool>[]>();

            {
                int curveIdx = 0;
                foreach (var curveEntry in clipCurves.Generic)
                {
                    string path         = curveEntry.name;
                    string pathNoSuffix = null;

                    string pathSuffix;
                    if (path.Length >= 2)
                    {
                        pathSuffix   = path.Substring(path.Length - 2, 2);
                        pathNoSuffix = path.Substring(0, path.Length - 2);
                    }
                    else
                    {
                        pathSuffix = "";
                    }

                    int tangentIdx        = -1;
                    int currentTangentIdx = 0;
                    foreach (var tangentEntry in editorCurveData.floatCurves)
                    {
                        if (tangentEntry.name == curveEntry.name)
                        {
                            tangentIdx = currentTangentIdx;
                            break;
                        }

                        currentTangentIdx++;
                    }

                    Animation.PropertySuffixInfo suffixInfo;
                    if (Animation.PropertySuffixInfos.TryGetValue(pathSuffix, out suffixInfo))
                    {
                        Tuple <int, int, bool>[] curveInfo;
                        if (!floatCurveMapping.TryGetValue(pathNoSuffix, out curveInfo))
                        {
                            curveInfo = new Tuple <int, int, bool> [4];
                        }

                        curveInfo[suffixInfo.elementIdx] = Tuple.Create(curveIdx, tangentIdx, suffixInfo.isVector);
                        floatCurveMapping[pathNoSuffix]  = curveInfo;
                    }
                    else
                    {
                        Tuple <int, int, bool>[] curveInfo = new Tuple <int, int, bool> [4];
                        curveInfo[0] = Tuple.Create(curveIdx, tangentIdx, suffixInfo.isVector);

                        floatCurveMapping[path] = curveInfo;
                    }

                    curveIdx++;
                }
            }

            foreach (var KVP in floatCurveMapping)
            {
                int numCurves = 0;
                for (int i = 0; i < 4; i++)
                {
                    if (KVP.Value[i] == null)
                    {
                        continue;
                    }

                    numCurves++;
                }

                if (numCurves == 0)
                {
                    continue; // Invalid curve
                }
                FieldAnimCurves fieldCurves = new FieldAnimCurves();

                // Deduce type (note that all single value types are assumed to be float even if their source type is int or bool)
                if (numCurves == 1)
                {
                    fieldCurves.type = SerializableProperty.FieldType.Float;
                }
                else if (numCurves == 2)
                {
                    fieldCurves.type = SerializableProperty.FieldType.Vector2;
                }
                else if (numCurves == 3)
                {
                    fieldCurves.type = SerializableProperty.FieldType.Vector3;
                }
                else // 4 curves
                {
                    bool isVector = KVP.Value[0].Item3;
                    if (isVector)
                    {
                        fieldCurves.type = SerializableProperty.FieldType.Vector4;
                    }
                    else
                    {
                        fieldCurves.type = SerializableProperty.FieldType.Color;
                    }
                }

                bool   isMorphCurve = false;
                string curvePath    = KVP.Key;

                fieldCurves.curveInfos = new CurveDrawInfo[numCurves];
                for (int i = 0; i < numCurves; i++)
                {
                    int curveIdx   = KVP.Value[i].Item1;
                    int tangentIdx = KVP.Value[i].Item2;

                    TangentMode[] tangents = null;
                    if (tangentIdx != -1)
                    {
                        tangents = editorCurveData.floatCurves[tangentIdx].tangents;
                    }

                    fieldCurves.curveInfos[i]       = new CurveDrawInfo();
                    fieldCurves.curveInfos[i].curve = new EdAnimationCurve(clipCurves.Generic[curveIdx].curve, tangents);
                    fieldCurves.curveInfos[i].color = GUICurveDrawing.GetUniqueColor(globalCurveIdx++);

                    if (clipCurves.Generic[curveIdx].flags.HasFlag(AnimationCurveFlags.MorphFrame))
                    {
                        curvePath    = "MorphShapes/Frames/" + KVP.Key;
                        isMorphCurve = true;
                    }
                    else if (clipCurves.Generic[curveIdx].flags.HasFlag(AnimationCurveFlags.MorphWeight))
                    {
                        curvePath    = "MorphShapes/Weight/" + KVP.Key;
                        isMorphCurve = true;
                    }
                }

                fieldCurves.isPropertyCurve = !clipInfo.isImported && !isMorphCurve;

                clipInfo.curves[curvePath] = fieldCurves;
            }

            // Add events
            clipInfo.events = clip.Events;
            return(clipInfo);
        }
        /// <summary>
        /// Applies any changes made to the animation curves or events to the actual animation clip. Only works for
        /// non-imported animation clips.
        /// </summary>
        /// <param name="tangents">Tangent modes for all the saved animation curves.</param>
        public void Apply(out EditorAnimClipTangents tangents)
        {
            if (isImported || clip == null)
            {
                tangents = null;
                return;
            }

            List <NamedVector3Curve>    positionCurves = new List <NamedVector3Curve>();
            List <NamedQuaternionCurve> rotationCurves = new List <NamedQuaternionCurve>();
            List <NamedVector3Curve>    scaleCurves    = new List <NamedVector3Curve>();
            List <NamedFloatCurve>      floatCurves    = new List <NamedFloatCurve>();

            List <EditorVector3CurveTangents> positionTangents = new List <EditorVector3CurveTangents>();
            List <EditorVector3CurveTangents> rotationTangents = new List <EditorVector3CurveTangents>();
            List <EditorVector3CurveTangents> scaleTangents    = new List <EditorVector3CurveTangents>();
            List <EditorFloatCurveTangents>   floatTangents    = new List <EditorFloatCurveTangents>();

            foreach (var kvp in curves)
            {
                string[] pathEntries = kvp.Key.Split('/');
                if (pathEntries.Length == 0)
                {
                    continue;
                }

                string lastEntry = pathEntries[pathEntries.Length - 1];

                if (lastEntry == "Position" || lastEntry == "Rotation" || lastEntry == "Scale")
                {
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < pathEntries.Length - 2; i++)
                    {
                        sb.Append(pathEntries[i] + "/");
                    }

                    if (pathEntries.Length > 1)
                    {
                        sb.Append(pathEntries[pathEntries.Length - 2]);
                    }

                    string curvePath = sb.ToString();

                    NamedVector3Curve curve = new NamedVector3Curve();
                    curve.name  = curvePath;
                    curve.curve = AnimationUtility.CombineCurve(new[]
                    {
                        new AnimationCurve(kvp.Value.curveInfos[0].curve.KeyFrames),
                        new AnimationCurve(kvp.Value.curveInfos[1].curve.KeyFrames),
                        new AnimationCurve(kvp.Value.curveInfos[1].curve.KeyFrames)
                    });

                    EditorVector3CurveTangents curveTangents = new EditorVector3CurveTangents();
                    curveTangents.name      = curvePath;
                    curveTangents.tangentsX = kvp.Value.curveInfos[0].curve.TangentModes;
                    curveTangents.tangentsY = kvp.Value.curveInfos[1].curve.TangentModes;
                    curveTangents.tangentsZ = kvp.Value.curveInfos[2].curve.TangentModes;

                    if (lastEntry == "Position")
                    {
                        positionCurves.Add(curve);
                        positionTangents.Add(curveTangents);
                    }
                    else if (lastEntry == "Rotation")
                    {
                        NamedQuaternionCurve quatCurve = new NamedQuaternionCurve();
                        quatCurve.name  = curve.name;
                        quatCurve.curve = AnimationUtility.EulerToQuaternionCurve(curve.curve);

                        rotationCurves.Add(quatCurve);
                        rotationTangents.Add(curveTangents);
                    }
                    else if (lastEntry == "Scale")
                    {
                        scaleCurves.Add(curve);
                        scaleTangents.Add(curveTangents);
                    }
                }
                else
                {
                    Action <int, string, string, AnimationCurveFlags> addCurve = (idx, path, subPath, flags) =>
                    {
                        string fullPath = path + subPath;

                        NamedFloatCurve curve = new NamedFloatCurve(fullPath,
                                                                    new AnimationCurve(kvp.Value.curveInfos[idx].curve.KeyFrames));
                        curve.flags = flags;

                        EditorFloatCurveTangents curveTangents = new EditorFloatCurveTangents();
                        curveTangents.name     = fullPath;
                        curveTangents.tangents = kvp.Value.curveInfos[idx].curve.TangentModes;

                        floatCurves.Add(curve);
                        floatTangents.Add(curveTangents);
                    };

                    switch (kvp.Value.type)
                    {
                    case SerializableProperty.FieldType.Vector2:
                        addCurve(0, kvp.Key, ".x", 0);
                        addCurve(1, kvp.Key, ".y", 0);
                        break;

                    case SerializableProperty.FieldType.Vector3:
                        addCurve(0, kvp.Key, ".x", 0);
                        addCurve(1, kvp.Key, ".y", 0);
                        addCurve(2, kvp.Key, ".z", 0);
                        break;

                    case SerializableProperty.FieldType.Vector4:
                        addCurve(0, kvp.Key, ".x", 0);
                        addCurve(1, kvp.Key, ".y", 0);
                        addCurve(2, kvp.Key, ".z", 0);
                        addCurve(3, kvp.Key, ".w", 0);
                        break;

                    case SerializableProperty.FieldType.Color:
                        addCurve(0, kvp.Key, ".r", 0);
                        addCurve(1, kvp.Key, ".g", 0);
                        addCurve(2, kvp.Key, ".b", 0);
                        addCurve(3, kvp.Key, ".a", 0);
                        break;

                    case SerializableProperty.FieldType.Bool:
                    case SerializableProperty.FieldType.Int:
                    case SerializableProperty.FieldType.Float:
                    {
                        AnimationCurveFlags flags = 0;
                        string path = kvp.Key;

                        if (IsMorphShapeCurve(kvp.Key))
                        {
                            string   trimmedPath = path.Trim('/');
                            string[] entries     = trimmedPath.Split('/');

                            bool isWeight = entries[entries.Length - 2] == "Weight";

                            if (isWeight)
                            {
                                flags = AnimationCurveFlags.MorphWeight;
                            }
                            else
                            {
                                flags = AnimationCurveFlags.MorphFrame;
                            }

                            path = entries[entries.Length - 1];
                        }

                        addCurve(0, path, "", flags);
                    }
                    break;
                    }
                }
            }

            AnimationCurves newClipCurves = new AnimationCurves();

            newClipCurves.Position = positionCurves.ToArray();
            newClipCurves.Rotation = rotationCurves.ToArray();
            newClipCurves.Scale    = scaleCurves.ToArray();
            newClipCurves.Generic  = floatCurves.ToArray();

            clip.Curves     = newClipCurves;
            clip.Events     = events;
            clip.SampleRate = (uint)sampleRate;

            tangents = new EditorAnimClipTangents();
            tangents.positionCurves = positionTangents.ToArray();
            tangents.rotationCurves = rotationTangents.ToArray();
            tangents.scaleCurves    = scaleTangents.ToArray();
            tangents.floatCurves    = floatTangents.ToArray();
        }
Beispiel #8
0
        /// <summary>
        /// Saves the animation curves and events stored in this object, into the associated animation clip resource.
        /// Relevant animation clip resource must already be created and exist in the project library.
        /// </summary>
        public void SaveToClip()
        {
            if (!isImported)
            {
                List <NamedVector3Curve> positionCurves = new List <NamedVector3Curve>();
                List <NamedVector3Curve> rotationCurves = new List <NamedVector3Curve>();
                List <NamedVector3Curve> scaleCurves    = new List <NamedVector3Curve>();
                List <NamedFloatCurve>   floatCurves    = new List <NamedFloatCurve>();

                List <EditorVector3CurveTangents> positionTangents = new List <EditorVector3CurveTangents>();
                List <EditorVector3CurveTangents> rotationTangents = new List <EditorVector3CurveTangents>();
                List <EditorVector3CurveTangents> scaleTangents    = new List <EditorVector3CurveTangents>();
                List <EditorFloatCurveTangents>   floatTangents    = new List <EditorFloatCurveTangents>();

                foreach (var kvp in curves)
                {
                    string[] pathEntries = kvp.Key.Split('/');
                    if (pathEntries.Length == 0)
                    {
                        continue;
                    }

                    string lastEntry = pathEntries[pathEntries.Length - 1];

                    if (lastEntry == "Position" || lastEntry == "Rotation" || lastEntry == "Scale")
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < pathEntries.Length - 2; i++)
                        {
                            sb.Append(pathEntries[i] + "/");
                        }

                        if (pathEntries.Length > 1)
                        {
                            sb.Append(pathEntries[pathEntries.Length - 2]);
                        }

                        string curvePath = sb.ToString();

                        NamedVector3Curve curve = new NamedVector3Curve(curvePath,
                                                                        new AnimationCurve(kvp.Value.curveInfos[0].curve.KeyFrames),
                                                                        new AnimationCurve(kvp.Value.curveInfos[1].curve.KeyFrames),
                                                                        new AnimationCurve(kvp.Value.curveInfos[2].curve.KeyFrames));

                        EditorVector3CurveTangents tangents = new EditorVector3CurveTangents();
                        tangents.name      = curvePath;
                        tangents.tangentsX = kvp.Value.curveInfos[0].curve.TangentModes;
                        tangents.tangentsY = kvp.Value.curveInfos[1].curve.TangentModes;
                        tangents.tangentsZ = kvp.Value.curveInfos[2].curve.TangentModes;

                        if (lastEntry == "Position")
                        {
                            positionCurves.Add(curve);
                            positionTangents.Add(tangents);
                        }
                        else if (lastEntry == "Rotation")
                        {
                            rotationCurves.Add(curve);
                            rotationTangents.Add(tangents);
                        }
                        else if (lastEntry == "Scale")
                        {
                            scaleCurves.Add(curve);
                            scaleTangents.Add(tangents);
                        }
                    }
                    else
                    {
                        Action <int, string> addCurve = (idx, subPath) =>
                        {
                            string path = kvp.Key + subPath;

                            NamedFloatCurve curve = new NamedFloatCurve(path,
                                                                        new AnimationCurve(kvp.Value.curveInfos[idx].curve.KeyFrames));

                            EditorFloatCurveTangents tangents = new EditorFloatCurveTangents();
                            tangents.name     = path;
                            tangents.tangents = kvp.Value.curveInfos[idx].curve.TangentModes;

                            floatCurves.Add(curve);
                            floatTangents.Add(tangents);
                        };

                        switch (kvp.Value.type)
                        {
                        case SerializableProperty.FieldType.Vector2:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            break;

                        case SerializableProperty.FieldType.Vector3:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            addCurve(2, ".z");
                            break;

                        case SerializableProperty.FieldType.Vector4:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            addCurve(2, ".z");
                            addCurve(3, ".w");
                            break;

                        case SerializableProperty.FieldType.Color:
                            addCurve(0, ".r");
                            addCurve(1, ".g");
                            addCurve(2, ".b");
                            addCurve(3, ".a");
                            break;

                        case SerializableProperty.FieldType.Bool:
                        case SerializableProperty.FieldType.Int:
                        case SerializableProperty.FieldType.Float:
                            addCurve(0, "");
                            break;
                        }
                    }
                }

                AnimationCurves newClipCurves = new AnimationCurves();
                newClipCurves.PositionCurves = positionCurves.ToArray();
                newClipCurves.RotationCurves = rotationCurves.ToArray();
                newClipCurves.ScaleCurves    = scaleCurves.ToArray();
                newClipCurves.FloatCurves    = floatCurves.ToArray();

                clip.Curves     = newClipCurves;
                clip.Events     = events;
                clip.SampleRate = sampleRate;

                string resourcePath = ProjectLibrary.GetPath(clip);
                ProjectLibrary.Save(clip);

                // Save tangents for editor only use
                EditorAnimClipTangents newCurveData = new EditorAnimClipTangents();
                newCurveData.positionCurves = positionTangents.ToArray();
                newCurveData.rotationCurves = rotationTangents.ToArray();
                newCurveData.scaleCurves    = scaleTangents.ToArray();
                newCurveData.floatCurves    = floatTangents.ToArray();

                ProjectLibrary.SetEditorData(resourcePath, newCurveData);
            }
            else
            {
                string       resourcePath = ProjectLibrary.GetPath(clip);
                LibraryEntry entry        = ProjectLibrary.GetEntry(resourcePath);

                if (entry != null && entry.Type == LibraryEntryType.File)
                {
                    FileEntry         fileEntry         = (FileEntry)entry;
                    MeshImportOptions meshImportOptions = (MeshImportOptions)fileEntry.Options;

                    string clipName = PathEx.GetTail(resourcePath);

                    List <ImportedAnimationEvents> newEvents = new List <ImportedAnimationEvents>();
                    newEvents.AddRange(meshImportOptions.AnimationEvents);

                    bool isExisting = false;
                    for (int i = 0; i < newEvents.Count; i++)
                    {
                        if (newEvents[i].name == clipName)
                        {
                            newEvents[i].events = events;
                            isExisting          = true;
                            break;
                        }
                    }

                    if (!isExisting)
                    {
                        ImportedAnimationEvents newEntry = new ImportedAnimationEvents();
                        newEntry.name   = clipName;
                        newEntry.events = events;

                        newEvents.Add(newEntry);
                    }

                    meshImportOptions.AnimationEvents = newEvents.ToArray();

                    ProjectLibrary.Reimport(resourcePath, meshImportOptions, true);
                }
            }
        }
Beispiel #9
0
 /// <summary>Creates an animation clip with specified curves.</summary>
 /// <param name="curves">Curves to initialize the animation with.</param>
 /// <param name="isAdditive">
 /// Determines does the clip contain additive curve data. This will change the behaviour how is the clip blended with
 /// other animations.
 /// </param>
 /// <param name="sampleRate">
 /// If animation uses evenly spaced keyframes, number of samples per second. Not relevant if keyframes are unevenly
 /// spaced.
 /// </param>
 /// <param name="rootMotion">
 /// Optional set of curves that can be used for animating the root bone. Not used by the animation system directly but is
 /// instead provided to the user for manual evaluation.
 /// </param>
 public AnimationClip(AnimationCurves curves, bool isAdditive = false, uint sampleRate = 1, RootMotion rootMotion = null)
 {
     Internal_create0(this, curves, isAdditive, sampleRate, rootMotion);
 }
Beispiel #10
0
 private static extern void Internal_create0(AnimationClip managedInstance, AnimationCurves curves, bool isAdditive, uint sampleRate, RootMotion rootMotion);
Beispiel #11
0
 private static extern void Internal_setCurves(IntPtr thisPtr, AnimationCurves curves);
 private static extern void Internal_SetAnimationCurves(IntPtr thisPtr, AnimationCurves curves);
Beispiel #13
0
        /// <summary>
        /// Builds a list of properties that will be animated using float animation curves.
        /// </summary>
        /// <param name="clip">Clip to retrieve the float animation curves from.</param>
        partial void RebuildFloatProperties(RRef <AnimationClip> clip)
        {
            if (clip == null)
            {
                floatProperties = null;
                return;
            }

            AnimationCurves curves = clip.Value.Curves;

            List <FloatCurvePropertyInfo> newFloatProperties = new List <FloatCurvePropertyInfo>();

            for (int i = 0; i < curves.Generic.Length; i++)
            {
                bool isMorphCurve = curves.Generic[i].flags.HasFlag(AnimationCurveFlags.MorphWeight) ||
                                    curves.Generic[i].flags.HasFlag(AnimationCurveFlags.MorphFrame);

                if (isMorphCurve)
                {
                    continue;
                }

                string suffix;
                SerializableProperty property = FindProperty(SceneObject, curves.Generic[i].name, out suffix);
                if (property == null)
                {
                    continue;
                }

                int elementIdx = 0;
                if (!string.IsNullOrEmpty(suffix))
                {
                    PropertySuffixInfo suffixInfo;
                    if (PropertySuffixInfos.TryGetValue(suffix, out suffixInfo))
                    {
                        elementIdx = suffixInfo.elementIdx;
                    }
                }

                Action <float> setter = null;

                Type internalType = property.InternalType;
                switch (property.Type)
                {
                case SerializableProperty.FieldType.Vector2:
                    if (internalType == typeof(Vector2))
                    {
                        setter = f =>
                        {
                            Vector2 value = property.GetValue <Vector2>();
                            value[elementIdx] = f;
                            property.SetValue(value);
                        };
                    }

                    break;

                case SerializableProperty.FieldType.Vector3:
                    if (internalType == typeof(Vector3))
                    {
                        setter = f =>
                        {
                            Vector3 value = property.GetValue <Vector3>();
                            value[elementIdx] = f;
                            property.SetValue(value);
                        };
                    }
                    break;

                case SerializableProperty.FieldType.Vector4:
                    setter = f =>
                    {
                        Vector4 value = property.GetValue <Vector4>();
                        value[elementIdx] = f;
                        property.SetValue(value);
                    };
                    break;

                case SerializableProperty.FieldType.Color:
                    if (internalType == typeof(Color))
                    {
                        setter = f =>
                        {
                            Color value = property.GetValue <Color>();
                            value[elementIdx] = f;
                            property.SetValue(value);
                        };
                    }
                    break;

                case SerializableProperty.FieldType.Bool:
                    setter = f =>
                    {
                        bool value = f > 0.0f;
                        property.SetValue(value);
                    };
                    break;

                case SerializableProperty.FieldType.Int:
                    setter = f =>
                    {
                        int value = (int)f;
                        property.SetValue(value);
                    };
                    break;

                case SerializableProperty.FieldType.Float:
                    setter = f =>
                    {
                        property.SetValue(f);
                    };
                    break;
                }

                if (setter == null)
                {
                    continue;
                }

                FloatCurvePropertyInfo propertyInfo = new FloatCurvePropertyInfo();
                propertyInfo.curveIdx = i;
                propertyInfo.setter   = setter;

                newFloatProperties.Add(propertyInfo);
            }

            floatProperties = newFloatProperties.ToArray();
        }
 private static extern void Internal_AnimationCurves(AnimationCurves managedInstance);