private IDictionary<ChangedValues, AnimationCurve> GetCurves (TimeLine timeLine, SpatialInfo defaultInfo, List<TimeLineKey> parentTimeline) {
			var rv = new Dictionary<ChangedValues, AnimationCurve> (); //This method checks every animatable property for changes
			foreach (var key in timeLine.keys) {		//And creates a curve for that property if changes are detected
				var info = key.info;
				if (!info.processed) {
					SpatialInfo parentInfo = null;
					if (parentTimeline != null) {
						var pKey = parentTimeline.Find (x => x.time == key.time);
						if (pKey == null) {
							var pKeys = parentTimeline.FindAll (x => x.time < key.time);
							pKeys.Sort ((x, y) => x.time.CompareTo (y.time) * -1);
							if (pKeys.Count > 0) pKey = pKeys [0];
							else {
								pKeys = parentTimeline.FindAll (x => x.time > key.time);
								pKeys.Sort ((x, y) => x.time.CompareTo (y.time));
								if (pKeys.Count > 0) pKey = pKeys [0];
							}
						}
						if (pKey != null) parentInfo = pKey.info;
					}
					info.Process (parentInfo);
				}
				if (!rv.ContainsKey (ChangedValues.PositionX) && (defaultInfo.x != info.x || defaultInfo.y != info.y)) {
					rv [ChangedValues.PositionX] = new AnimationCurve (); //There will be irregular behaviour if curves aren't added for all members  
					rv [ChangedValues.PositionY] = new AnimationCurve (); //in a group, so when one is set, the others have to be set as well
					rv [ChangedValues.PositionZ] = new AnimationCurve ();
				}
				if (!rv.ContainsKey (ChangedValues.RotationZ) && (defaultInfo.rotation.z != info.rotation.z || defaultInfo.rotation.w != info.rotation.w)) {
				    rv [ChangedValues.RotationZ] = new AnimationCurve ();//x and y not necessary since the default of 0 is fine
					rv [ChangedValues.RotationW] = new AnimationCurve ();
				}
				if (!rv.ContainsKey (ChangedValues.ScaleX) && (defaultInfo.scale_x != info.scale_x || defaultInfo.scale_y != info.scale_y)) {
					rv [ChangedValues.ScaleX] = new AnimationCurve ();
					rv [ChangedValues.ScaleY] = new AnimationCurve ();
					rv [ChangedValues.ScaleZ] = new AnimationCurve ();
				}
				if (!rv.ContainsKey (ChangedValues.Alpha) && defaultInfo.a != info.a)
					rv [ChangedValues.Alpha] = new AnimationCurve ();
				var scontrol = defaultInfo as SpriteInfo;
				if (scontrol != null && !rv.ContainsKey (ChangedValues.Sprite)) {
					var sinfo = (SpriteInfo)info;
					if (scontrol.file != sinfo.file || scontrol.folder != sinfo.folder)
						rv [ChangedValues.Sprite] = new AnimationCurve ();
				}
			}
			return rv;
		}
		private void SetCurves (Transform child, SpatialInfo defaultInfo, List<TimeLineKey> parentTimeline, TimeLine timeLine, AnimationClip clip, Animation animation, ref float defaultZ) {
			var childPath = GetPathToChild (child);
			foreach (var kvPair in GetCurves (timeLine, defaultInfo, parentTimeline)) { //Makes sure that curves are only added for properties 
				switch (kvPair.Key) {									//that actually mutate in the animation
				case ChangedValues.PositionX :
					SetKeys (kvPair.Value, timeLine, x => x.x, animation);
					clip.SetCurve (childPath, typeof(Transform), "localPosition.x", kvPair.Value);
					break;
				case ChangedValues.PositionY :
					SetKeys (kvPair.Value, timeLine, x => x.y, animation);
					clip.SetCurve (childPath, typeof(Transform), "localPosition.y", kvPair.Value);
					break;
				case ChangedValues.PositionZ :
					kvPair.Value.AddKey (0f, defaultZ);
					clip.SetCurve (childPath, typeof(Transform), "localPosition.z", kvPair.Value);
					defaultZ = inf; //Lets the next method know this value has been set
					break;
				case ChangedValues.RotationZ :
					SetKeys (kvPair.Value, timeLine, x => x.rotation.z, animation);
					clip.SetCurve (childPath, typeof(Transform), "localRotation.z", kvPair.Value);
					break;
				case ChangedValues.RotationW :
					SetKeys (kvPair.Value, timeLine, x => x.rotation.w, animation);
					clip.SetCurve (childPath, typeof(Transform), "localRotation.w", kvPair.Value);
					break;
				case ChangedValues.ScaleX :
					SetKeys (kvPair.Value, timeLine, x => x.scale_x, animation);
					clip.SetCurve (childPath, typeof(Transform), "localScale.x", kvPair.Value);
					break;
				case ChangedValues.ScaleY :
					SetKeys (kvPair.Value, timeLine, x => x.scale_y, animation);
					clip.SetCurve (childPath, typeof(Transform), "localScale.y", kvPair.Value);
					break;
				case ChangedValues.ScaleZ :
					kvPair.Value.AddKey (0f, 1f);
					clip.SetCurve (childPath, typeof(Transform), "localScale.z", kvPair.Value);
					break;
				case ChangedValues.Alpha :
					SetKeys (kvPair.Value, timeLine, x => x.a, animation);
					clip.SetCurve (childPath, typeof(SpriteRenderer), "m_Color.a", kvPair.Value);
					break;
				case ChangedValues.Sprite :
					var swapper = child.GetComponent<TextureController> ();
					if (swapper == null) { //Add a Texture Controller if one doesn't already exist
						swapper = child.gameObject.AddComponent<TextureController> ();
						var info = (SpriteInfo)defaultInfo;
						swapper.Sprites = new[] {Folders [info.folder] [info.file]};
					}
					SetKeys (kvPair.Value, timeLine, ref swapper.Sprites, animation);
					clip.SetCurve (childPath, typeof(TextureController), "DisplayedSprite", kvPair.Value);
					break;
				}
			}
			clip.EnsureQuaternionContinuity ();
		}
		private void SetCurves (Transform child, SpatialInfo defaultInfo, List<TimeLineKey> parentTimeline, TimeLine timeLine, AnimationClip clip, Animation animation) {
			var defZ = 0f;
			SetCurves (child, defaultInfo, parentTimeline, timeLine, clip, animation, ref defZ);
		}
Exemple #4
0
        private IDictionary <ChangedValues, AnimationCurve> GetCurves(TimeLine timeLine, SpatialInfo defaultInfo, List <TimeLineKey> parentTimeline)
        {
            var rv = new Dictionary <ChangedValues, AnimationCurve> (); //This method checks every animatable property for changes

            foreach (var key in timeLine.keys)                          //And creates a curve for that property if changes are detected
            {
                var info = key.info;
                if (!info.processed)
                {
                    SpatialInfo parentInfo = null;
                    if (parentTimeline != null)
                    {
                        var pKey = parentTimeline.Find(x => x.time == key.time);
                        if (pKey == null)
                        {
                            var pKeys = parentTimeline.FindAll(x => x.time < key.time);
                            pKeys.Sort((x, y) => x.time.CompareTo(y.time) * -1);
                            if (pKeys.Count > 0)
                            {
                                pKey = pKeys [0];
                            }
                            else
                            {
                                pKeys = parentTimeline.FindAll(x => x.time > key.time);
                                pKeys.Sort((x, y) => x.time.CompareTo(y.time));
                                if (pKeys.Count > 0)
                                {
                                    pKey = pKeys [0];
                                }
                            }
                        }
                        if (pKey != null)
                        {
                            parentInfo = pKey.info;
                        }
                    }
                    info.Process(parentInfo);
                }
                if (!rv.ContainsKey(ChangedValues.PositionX) && (defaultInfo.x != info.x || defaultInfo.y != info.y))
                {
                    rv [ChangedValues.PositionX] = new AnimationCurve();                      //There will be irregular behaviour if curves aren't added for all members
                    rv [ChangedValues.PositionY] = new AnimationCurve();                      //in a group, so when one is set, the others have to be set as well
                    rv [ChangedValues.PositionZ] = new AnimationCurve();
                }
                if (!rv.ContainsKey(ChangedValues.RotationZ) && (defaultInfo.rotation.z != info.rotation.z || defaultInfo.rotation.w != info.rotation.w))
                {
                    rv [ChangedValues.RotationZ] = new AnimationCurve();                 //x and y not necessary since the default of 0 is fine
                    rv [ChangedValues.RotationW] = new AnimationCurve();
                }
                if (!rv.ContainsKey(ChangedValues.ScaleX) && (defaultInfo.scale_x != info.scale_x || defaultInfo.scale_y != info.scale_y))
                {
                    rv [ChangedValues.ScaleX] = new AnimationCurve();
                    rv [ChangedValues.ScaleY] = new AnimationCurve();
                    rv [ChangedValues.ScaleZ] = new AnimationCurve();
                }
                if (!rv.ContainsKey(ChangedValues.Alpha) && defaultInfo.a != info.a)
                {
                    rv [ChangedValues.Alpha] = new AnimationCurve();
                }
                var scontrol = defaultInfo as SpriteInfo;
                if (scontrol != null && !rv.ContainsKey(ChangedValues.Sprite))
                {
                    var sinfo = (SpriteInfo)info;
                    if (scontrol.file != sinfo.file || scontrol.folder != sinfo.folder)
                    {
                        rv [ChangedValues.Sprite] = new AnimationCurve();
                    }
                }
            }
            return(rv);
        }
Exemple #5
0
        private void SetCurves(Transform child, SpatialInfo defaultInfo, List <TimeLineKey> parentTimeline, TimeLine timeLine, AnimationClip clip, Animation animation, ref float defaultZ)
        {
            var childPath = GetPathToChild(child);

            foreach (var kvPair in GetCurves(timeLine, defaultInfo, parentTimeline))                //Makes sure that curves are only added for properties
            {
                switch (kvPair.Key)                                                                 //that actually mutate in the animation
                {
                case ChangedValues.PositionX:
                    SetKeys(kvPair.Value, timeLine, x => x.x, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localPosition.x", kvPair.Value);
                    break;

                case ChangedValues.PositionY:
                    SetKeys(kvPair.Value, timeLine, x => x.y, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localPosition.y", kvPair.Value);
                    break;

                case ChangedValues.PositionZ:
                    kvPair.Value.AddKey(0f, defaultZ);
                    clip.SetCurve(childPath, typeof(Transform), "localPosition.z", kvPair.Value);
                    defaultZ = inf;                     //Lets the next method know this value has been set
                    break;

                case ChangedValues.RotationZ:
                    SetKeys(kvPair.Value, timeLine, x => x.rotation.z, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localRotation.z", kvPair.Value);
                    break;

                case ChangedValues.RotationW:
                    SetKeys(kvPair.Value, timeLine, x => x.rotation.w, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localRotation.w", kvPair.Value);
                    break;

                case ChangedValues.ScaleX:
                    SetKeys(kvPair.Value, timeLine, x => x.scale_x, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localScale.x", kvPair.Value);
                    break;

                case ChangedValues.ScaleY:
                    SetKeys(kvPair.Value, timeLine, x => x.scale_y, animation);
                    clip.SetCurve(childPath, typeof(Transform), "localScale.y", kvPair.Value);
                    break;

                case ChangedValues.ScaleZ:
                    kvPair.Value.AddKey(0f, 1f);
                    clip.SetCurve(childPath, typeof(Transform), "localScale.z", kvPair.Value);
                    break;

                case ChangedValues.Alpha:
                    SetKeys(kvPair.Value, timeLine, x => x.a, animation);
                    clip.SetCurve(childPath, typeof(SpriteRenderer), "m_Color.a", kvPair.Value);
                    break;

                case ChangedValues.Sprite:
                    var swapper = child.GetComponent <TextureController> ();
                    if (swapper == null)                       //Add a Texture Controller if one doesn't already exist
                    {
                        swapper = child.gameObject.AddComponent <TextureController> ();
                        var info = (SpriteInfo)defaultInfo;
                        swapper.Sprites = new[] { Folders [info.folder] [info.file] };
                    }
                    SetKeys(kvPair.Value, timeLine, ref swapper.Sprites, animation);
                    clip.SetCurve(childPath, typeof(TextureController), "DisplayedSprite", kvPair.Value);
                    break;
                }
            }
            clip.EnsureQuaternionContinuity();
        }
Exemple #6
0
        private void SetCurves(Transform child, SpatialInfo defaultInfo, List <TimeLineKey> parentTimeline, TimeLine timeLine, AnimationClip clip, Animation animation)
        {
            var defZ = 0f;

            SetCurves(child, defaultInfo, parentTimeline, timeLine, clip, animation, ref defZ);
        }