Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 private static extern void Internal_create0(AnimationClip managedInstance, AnimationCurves curves, bool isAdditive, uint sampleRate, RootMotion rootMotion);
Exemplo n.º 3
0
 private static extern void Internal_setCurves(IntPtr thisPtr, AnimationCurves curves);
Exemplo n.º 4
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:
                    if (internalType == typeof(Vector4))
                    {
                        setter = f =>
                        {
                            Vector4 value = property.GetValue <Vector4>();
                            value[elementIdx] = f;
                            property.SetValue(value);
                        };
                    }
                    else if (internalType == typeof(Quaternion))
                    {
                        setter = f =>
                        {
                            Quaternion value = property.GetValue <Quaternion>();
                            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();
        }
Exemplo n.º 5
0
 private static extern void Internal_AnimationCurves(AnimationCurves managedInstance);
Exemplo n.º 6
0
        /// <summary>
        /// Finds any curves that affect a transform of a specific scene object, and ensures that animation properly updates
        /// those transforms. This does not include curves referencing bones.
        /// </summary>
        private void UpdateSceneObjectMapping()
        {
            List <SceneObjectMappingInfo> newMappingInfos = new List <SceneObjectMappingInfo>();

            foreach (var entry in mappingInfo)
            {
                if (entry.isMappedToBone)
                {
                    newMappingInfos.Add(entry);
                }
                else
                {
                    _native.UnmapSceneObject(entry.sceneObject);
                }
            }

            if (primaryClip != null)
            {
                SceneObject root = SceneObject;

                Action <NamedVector3Curve[]> findMappings = x =>
                {
                    foreach (var curve in x)
                    {
                        if (curve.Flags.HasFlag(AnimationCurveFlags.ImportedCurve))
                        {
                            continue;
                        }

                        SceneObject currentSO = FindSceneObject(root, curve.Name);

                        bool found = false;
                        for (int i = 0; i < newMappingInfos.Count; i++)
                        {
                            if (newMappingInfos[i].sceneObject == currentSO)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            SceneObjectMappingInfo newMappingInfo = new SceneObjectMappingInfo();
                            newMappingInfo.isMappedToBone = false;
                            newMappingInfo.sceneObject    = currentSO;

                            newMappingInfos.Add(newMappingInfo);

                            _native.MapCurveToSceneObject(curve.Name, currentSO);
                        }
                    }
                };

                AnimationCurves curves = primaryClip.Curves;
                findMappings(curves.PositionCurves);
                findMappings(curves.RotationCurves);
                findMappings(curves.ScaleCurves);
            }

            mappingInfo = newMappingInfos;
        }