Ejemplo n.º 1
0
 public void CreateRotationCurves()
 {
     TimelineEditorTools.CreateEmptyCurves(
         clip: TimelineEditor.selectedClip,
         type: this.GetType(),
         propertyNames: new List <string>(new string[] { "Rotation.x", "Rotation.y", "Rotation.z" })
         );
 }
Ejemplo n.º 2
0
 public void CreateFlippedCurves()
 {
     TimelineEditorTools.CreateEmptyCurves(
         clip: TimelineEditor.selectedClip,
         type: this.GetType(),
         propertyNames: new List <string>(new string[] { "Flipped" }),
         defaultValues: new List <float>(new float[] { 1f })
         );
 }
Ejemplo n.º 3
0
        public void CreatePositionKeysFromTransform(Transform transform)
        {
            List <string> properties = new List <string>(new string[] { "Position.x", "Position.y", "Position.z" });

            float[] values = new float[] { transform.position.x, transform.position.y, transform.position.z };
            EditorCurveBinding[] propBindings = new EditorCurveBinding[3];
            TimelineClip         clip         = TimelineEditor.selectedClip;

            if (clip.curves != null)
            {
                foreach (EditorCurveBinding binding in AnimationUtility.GetCurveBindings(clip.curves))
                {
                    if (properties.Contains(binding.propertyName))
                    {
                        propBindings[properties.IndexOf(binding.propertyName)] = binding;
                    }
                }


                for (int i = 0; i < propBindings.Length; i++)
                {
                    if (string.IsNullOrEmpty(propBindings[i].propertyName))
                    {
                        propBindings[i] = TimelineEditorTools.CreateEmptyCurve(clip, this.GetType(), properties[i]);
                        Debug.Log("binding created!");
                    }

                    AnimationCurve curve = AnimationUtility.GetEditorCurve(clip.curves, propBindings[i]);

                    float time = (float)(TimelineEditor.masterDirector.time - clip.start);
                    if (curve.AddKey(time, values[i]) == -1)
                    {
                        for (int j = 0; j < curve.keys.Length; j++)
                        {
                            if (curve.keys[j].time == time)
                            {
                                curve.RemoveKey(j);
                                break;
                            }
                        }

                        curve.AddKey(time, values[i]);
                    }

                    clip.curves.SetCurve("", this.GetType(), properties[i], curve);
                }

                TimelineEditor.masterDirector.RebuildGraph();
                TimelineEditor.inspectedDirector.RebuildGraph();
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
                UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
            }
        }
        /// <summary>
        /// Given a list of properties, create an empty curve for each property with
        /// a default keyframe at time 0.
        /// </summary>
        /// <param name="clip">The timeline clip to create curves on.</param>
        /// <param name="type">The type used for the curve (used by AnimationCurve.SetCurve)</param>
        /// <param name="missing">A list of the missing properties.</param>
        /// <param name="propertyNames">The full list of desired properties for the clip</param>
        /// <param name="defaultValues">The list of default keyframe values for the desired properties</param>
        private static void CreateMissingProperties(TimelineClip clip, Type type, IList <string> missing, IList <string> propertyNames, IList <float> defaultValues = null)
        {
            bool useDefaults = defaultValues != null;

            // Create a curve with a keyframe at time 0 for each missing property.
            foreach (string prop in missing)
            {
                if (useDefaults)
                {
                    TimelineEditorTools.CreateEmptyCurve(clip, type, prop, defaultValues[propertyNames.IndexOf(prop)]);
                }
                else
                {
                    TimelineEditorTools.CreateEmptyCurve(clip, type, prop);
                }
            }
        }
Ejemplo n.º 5
0
        public void CreateAllCurves()
        {
            string[] properties = { "Position.x", "Position.y", "Position.z",
                                    "Rotation.x", "Rotation.y", "Rotation.z",
                                    "Scale.x",    "Scale.y",    "Scale.z",
                                    "Active",     "Flipped" };
            float[]  values = { 0, 0, 0,
                                0,  0, 0,
                                1,  1, 1,
                                1, 0 };

            TimelineEditorTools.CreateEmptyCurves(
                clip: TimelineEditor.selectedClip,
                type: this.GetType(),
                propertyNames: new List <string>(properties),
                defaultValues: new List <float>(values)
                );
        }