/// <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, int sampleRate = 1, RootMotion rootMotion = null)
 {
     Internal_create0(this, curves, isAdditive, sampleRate, rootMotion);
 }
 private static extern void Internal_create0(AnimationClip managedInstance, AnimationCurves curves, bool isAdditive, int sampleRate, RootMotion rootMotion);
Exemple #3
0
 private static extern void Internal_AnimationCurves(AnimationCurves managedInstance);
 private static extern void Internal_setCurves(IntPtr thisPtr, AnimationCurves curves);
Exemple #5
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 Callback_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();
        }