private GameObject MakeGameObject(Ref childRef, GameObject parent)
        {
            TimelineKey key = childRef.Referenced;
            GameObject go = new GameObject(key.Timeline.Name);
            if (parent != null)
            {
                go.transform.parent = parent.transform;
            }

            //Any objects that show up only after t=0 begin inactive
            if(key.Time_Ms > 0)
            {
                go.SetActive(false);
            }

            var spriteKey = key as SpriteTimelineKey;
            if (spriteKey != null)
            {
                //Set initial sprite information
                var sprite = go.AddComponent<SpriteRenderer>();
                sprite.sprite = charMap.GetSprite(spriteKey.File.Folder.Id, spriteKey.File.Id);
            }

            SetTransform(childRef, go.transform);

            return go;
        }
        private GameObject MakeGameObject(Ref childRef, GameObject parent, string spriteFolder)
        {
            TimelineKey key = childRef.Referenced;
            GameObject go = new GameObject(key.Timeline.Name);
            if (parent != null)
            {
                go.transform.parent = parent.transform;
            }

            //Any objects that show up only after t=0 begin inactive
            if(key.Time_Ms > 0)
            {
                go.SetActive(false);
            }

            var spriteKey = key as SpriteTimelineKey;
            if (spriteKey != null)
            {
                //Set initial sprite information
                var sprite = go.AddComponent<SpriteRenderer>();
                //Hack to be able to animate the sortingOrder property
                go.AddComponent<SortingOrderUpdate>();
                sprite.sprite = AssetUtils.GetSpriteAtPath(spriteKey.File.Name, spriteFolder);
            }

            SetTransform(childRef, go.transform);

            return go;
        }
Esempio n. 3
0
 private GameObject MakePrefab(Ref childRef, GameObject root, string spriteFolder)
 {
     var timeline = childRef.Referenced.Timeline;
     var transform = root.transform.Find(timeline.Name);
     GameObject go;
     if(transform == null)
     {
         go = MakeGameObject(childRef, root, spriteFolder);
     }
     else
     {
         go = transform.gameObject;
     }
     return go;
 }
Esempio n. 4
0
        private void SetTransform(Ref childRef, Transform transform)
        {
            Vector3 localPosition;
            Vector3 localScale;
			Vector3 localEulerAngles;

            PrefabUtils.BakeTransforms(childRef, out localPosition, out localEulerAngles, out localScale);
            transform.localPosition = localPosition;
            transform.localScale = localScale;
			transform.localEulerAngles = localEulerAngles;
        }
        /// <summary>
        /// Creates an event to change the sprite for the specified Ref (if applicable)
        /// </summary>
        /// <param name="clip">Target AnimationClip for Event</param>
        /// <param name="time">Time at which event should be triggered</param>
        /// <param name="reference"></param>
        private void SetSpriteEvent(AnimationClip clip, float time, Ref reference)
        {
            //Bump any events at t=0 up slightly
            if (time < float.Epsilon) time = 0.001f;
            var spriteKey = reference.Referenced as SpriteTimelineKey;
            //Only add event for SpriteTimelineKey objects
            if (spriteKey != null)
            {
                //Pack parameters into a string - simplest way to pass multiple parameters currently
                string packedParam = string.Format("{0};{1};{2}",
                    reference.RelativePath,
                    spriteKey.File.Folder.Id,
                    spriteKey.File.Id);

                //Debug.Log(string.Format("Adding event: ChangeSprite(\"{0}\") at t={1}", packedParam, time));

                //Add events to a list - Unity forces us to set the entire array at once
                animationEvents.Add(new AnimationEvent() { functionName = "ChangeSprite", stringParameter = packedParam, time = time});
            }
        }
        private void SetGameObjectForRef(GameObject root, Ref childRef)
        {
            TimelineKey key = childRef.Referenced;

            //Get the relative path based on the current hierarchy, find the target GameObject
            var relativePath = childRef.RelativePath;
            var transform = root.transform.Find(relativePath);
            if (transform == null)
            {
                Debug.LogError("ERROR: Unable to find GameObject at relative path " + relativePath);
                return;
            }

            var gameObject = transform.gameObject;
            gameObject.SetActive(true);

            //Get transform data from ref
            Vector3 localPosition;
            Vector3 localScale;
            Vector3 localEulerAngles;

            childRef.BakeTransforms(out localPosition, out localEulerAngles, out localScale);

            //Set the current GameObject's transform data
            transform.localPosition = localPosition;
            transform.localScale = localScale;
            transform.localEulerAngles = localEulerAngles;

            //Get last-used game object for this Timeline - needed to clean up reparenting
            GameObject lastGameObject;
            if (lastGameObjectCache.TryGetValue(key.Timeline, out lastGameObject) && gameObject != lastGameObject)
            {
                //Let Unity handle the global->local position cruft for us
                lastGameObject.transform.position = transform.position;
                lastGameObject.transform.eulerAngles = transform.eulerAngles;

                //TODO: Also need to do something about scale - this is a little more tricky
                lastGameObject.transform.localScale = localScale;

                //Deactivate the old object
                lastGameObject.SetActive(false);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates an event to change the sprite for the specified Ref (if applicable)
        /// </summary>
        /// <param name="clip">Target AnimationClip for Event</param>
        /// <param name="time">Time at which event should be triggered</param>
        /// <param name="reference"></param>
        private void SetSpriteEvent(AnimationClip clip, float time, Ref reference)
        {
            var spriteKey = reference.Referenced as SpriteTimelineKey;
            //Only add event for SpriteTimelineKey objects
            if (spriteKey != null)
            {
                if (time < 0) time = spriteKey.Time;
                if (!spriteChangeKeys.ContainsKey(reference.RelativePath))
                {
                    spriteChangeKeys[reference.RelativePath] = new List<SpriteChangeKey>();
                }

                //Add the key to the dictionary to later build all the curves at once.
                spriteChangeKeys[reference.RelativePath].Add(new SpriteChangeKey() { Time = time, Sprite = AssetUtils.GetSpriteAtPath(spriteKey.File.Name, spriteBaseFolder) });
            }
        }
Esempio n. 8
0
        private void SetGameObjectForRef(GameObject root, Ref childRef, float time)
        {
            TimelineKey key = childRef.Referenced;
            if (time < 0) time = key.Time;

            TimelineKey lastKey;
            lastKeyframeCache.TryGetValue(key.Timeline, out lastKey);

            //Get the relative path based on the current hierarchy
            var relativePath = childRef.RelativePath;

            //If this is the root, skip it
            if (string.IsNullOrEmpty(relativePath))
            {
                Debug.Log("Skipping root node in SetGameObjectForRef (SHOULD NEVER HAPPEN)");
                return;
            }


            //Find the gameObject based on relative path
            var transform = root.transform.Find(relativePath);
            if (transform == null)
            {
                Debug.LogError("ERROR: Unable to find GameObject at relative path " + relativePath);
                return;
            }

            var gameObject = transform.gameObject;
            gameObject.SetActive(true);

            //Get transform data from ref
            Vector3 localPosition;
            Vector3 localScale;
            Vector3 localEulerAngles;

            childRef.BakeTransforms(out localPosition, out localEulerAngles, out localScale);

            //Set the current GameObject's transform data
            transform.localPosition = localPosition;
            transform.localScale = localScale;

            //Spin the object in the correct direction
            var oldEulerAngles = transform.localEulerAngles;
            
            if (oldEulerAngles.z - localEulerAngles.z > 180) localEulerAngles.z += 360;
            else if (localEulerAngles.z - oldEulerAngles.z > 180) localEulerAngles.z -= 360;
            /*
            switch(childRef.Unmapped.Spin)
            {
                case SpinDirection.Clockwise:
                    while (oldEulerAngles.z > localEulerAngles.z) localEulerAngles.z += 360;
                    break;
                case SpinDirection.CounterClockwise:
                    while (oldEulerAngles.z < localEulerAngles.z) localEulerAngles.z -= 360;
                    break;
            }*/
            transform.localEulerAngles = localEulerAngles;

            int zIndex = -1;
            var spriteKey = key as SpriteTimelineKey;
            if (spriteKey != null)
            {
                zIndex = ((ObjectRef)childRef).ZIndex;
                //transform.GetComponent<SpriteRenderer>().sortingOrder = zIndex;
            }

            acb.SetCurve(root.transform, transform, time, lastKey, zIndex);
           

            //Get last-used game object for this Timeline - needed to clean up reparenting
            GameObject lastGameObject;
            if (lastGameObjectCache.TryGetValue(key.Timeline, out lastGameObject) && gameObject != lastGameObject)
            {
                //Let Unity handle the global->local position cruft for us
                lastGameObject.transform.position = transform.position;
                lastGameObject.transform.eulerAngles = transform.eulerAngles;

                //TODO: Also need to do something about scale - this is a little more tricky
                lastGameObject.transform.localScale = localScale;

                //Deactivate the old object
                lastGameObject.SetActive(false);

                acb.SetCurve(root.transform, lastGameObject.transform, time, lastKey);
            }

            //Set cached value for last keyframe
            lastKeyframeCache[key.Timeline] = key;
        }
Esempio n. 9
0
 public IEnumerable <Ref> GetChildren(Ref parent)
 {
     return(refs.Where(obj => obj.Parent == parent));
 }