// Takes snapshot recursively
        private void TakeHierarchySnapshot(Transform transform)
        {
            TransformSnapshot snapshot = new TransformSnapshot(transform);

            _snapshotList.Add(snapshot);

            for (int i = 0; i != transform.childCount; ++i)
            {
                TakeHierarchySnapshot(transform.GetChild(i));
            }
        }
Esempio n. 2
0
 public void TakeChildSnapshots()
 {
     if (ChildrenSnapshots != null)
     {
         return;
     }
     ChildrenSnapshots = new TransformSnapshot[Transform.childCount];
     for (int i = 0; i != ChildrenSnapshots.Length; ++i)
     {
         ChildrenSnapshots[i] = new TransformSnapshot(Transform.GetChild(i), true);
     }
 }
Esempio n. 3
0
        public override void Init()
        {
            if (Application.isPlaying && _snapshot == null)
            {
                _snapshot = new TransformSnapshot(Owner);
            }

            if (Owner.GetComponent <Animator>() == null)
            {
                Owner.gameObject.AddComponent <Animator>();
            }

            base.Init();
        }
Esempio n. 4
0
        protected override void OnTrigger(float timeSinceTrigger)
        {
            if (_snapshot == null)
            {
                _snapshot = new TransformSnapshot(Owner);
            }

            if (_anchor != null)
            {
                Owner.position = _anchor.position;
                Owner.rotation = _anchor.rotation;
            }

            if (_parentToAnchor)
            {
                Owner.parent = _anchor;
            }
        }
Esempio n. 5
0
        protected override void OnTrigger(float timeSinceTrigger)
        {
            base.OnTrigger(timeSinceTrigger);

            if (_newObj != null)
            {
                _newSnapshot = new TransformSnapshot(_newObj.transform, false);
            }

            if (_oldObj != null)
            {
                _oldObj.SetActive(false);
            }
            if (_newObj != null)
            {
                _newObj.transform.parent           = _oldObj.transform.parent;
                _newObj.transform.localPosition    = _offset;
                _newObj.transform.localEulerAngles = _eulerAngles;
            }
        }
Esempio n. 6
0
        public static TransformSnapshot GetSnapshot(FSequence sequence, Transform transform)
        {
            if (transform == null)
            {
                return(null);
            }

            Dictionary <Transform, TransformSnapshot> sequenceSnapshots = null;

            if (!_snapshots.TryGetValue(sequence, out sequenceSnapshots))
            {
                sequenceSnapshots = new Dictionary <Transform, TransformSnapshot>();
                _snapshots.Add(sequence, sequenceSnapshots);
            }

            TransformSnapshot result = null;

            if (!sequenceSnapshots.TryGetValue(transform, out result))
            {
                result = new TransformSnapshot(transform);
                sequenceSnapshots.Add(transform, result);
            }
            return(result);
        }
Esempio n. 7
0
        protected override bool BuildInternal()
        {
            _tracksCached = GetAnimationTracks();
            _validFrameRanges.Clear();

            if (_tracksCached.Count == 0 || Animator == null || Animator.runtimeAnimatorController == null)
            {
                return(false);
            }

            // build preview
#if FLUX_DEBUG
            Debug.LogWarning("Creating Preview");
#endif

            TransformSnapshot transformSnapshot = new TransformSnapshot(Track.Owner);

            FSequence sequence = Track.Sequence;

            if (_tracksCached[0].Snapshot != null)
            {
                _tracksCached[0].Snapshot.Restore();
            }

            //			_snapshot = Application.isPlaying ? null : new GameObjectSnapshot( Track.Owner.gameObject );

            bool ownerIsActive = Track.Owner.gameObject.activeSelf;

            float speed = sequence.Speed;
            if (speed != 1)
            {
                sequence.Speed = 1f;
            }

            Animator.speed = 1f;

            int  currentFrame = sequence.CurrentFrame;
            bool isPlaying    = sequence.IsPlaying;

            if (!sequence.IsStopped)
            {
                sequence.Stop();
            }

            if (!sequence.IsInit)
            {
                sequence.Init();
            }

            if (!ownerIsActive)
            {
                HideFlags hideFlags = Track.Owner.gameObject.hideFlags;
                Track.Owner.gameObject.hideFlags |= HideFlags.DontSave;
                Track.Owner.gameObject.SetActive(true);
                Track.Owner.gameObject.hideFlags = hideFlags;
            }

            FrameRange currentFrameRange = new FrameRange();

            foreach (FAnimationTrack animTrack in _tracksCached)
            {
                animTrack.Cache = null;
                animTrack.Stop(); // we need to force stop them to clear the currentEvent index
            }

            // set culling to get around Unity bug of recording at the start
            AnimatorCullingMode animatorCullingMode = Animator.cullingMode;
            Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

            Animator.enabled = true;

            for (int i = 0; i != Animator.layerCount; ++i)
            {
                Animator.SetLayerWeight(i, 0f);
            }

            Animator.StartRecording(-1);

            bool success = Animator.recorderMode == AnimatorRecorderMode.Record;

            if (success)
            {
                Animator.enabled = false;

                float delta = 1f / sequence.FrameRate;
                int   frame = 0;

                while (frame <= sequence.Length)
                {
                    bool wasEnabled = Animator.enabled;

                    foreach (FTrack track in _tracksCached)
                    {
                        track.UpdateEvents(frame, frame * delta);
                    }

                    if (wasEnabled)
                    {
                        currentFrameRange.End += 1;
                        if (Animator.enabled)
                        {
                            Animator.Update(delta);
                        }
                        else
                        {
                            Animator.enabled = true;
                            Animator.Update(delta);
                            Animator.enabled = false;
                            _validFrameRanges.Add(currentFrameRange);
                        }
                    }
                    else if (Animator.enabled)
                    {
                        Animator.Update(0);
                        currentFrameRange = new FrameRange(frame, frame);
                    }

                    ++frame;
                }

                foreach (FAnimationTrack animTrack in _tracksCached)
                {
                    animTrack.Cache = this;
                }

                Track = _tracksCached[0];

                Animator.StopRecording();
            }

            if (!ownerIsActive)
            {
                HideFlags hideFlags = Track.Owner.gameObject.hideFlags;
                Track.Owner.gameObject.hideFlags |= HideFlags.DontSave;
                Track.Owner.gameObject.SetActive(false);
                Track.Owner.gameObject.hideFlags = hideFlags;
            }

            if (speed != 1)
            {
                sequence.Speed = speed;
            }

            Animator.cullingMode = animatorCullingMode;

            sequence.Stop(true);

            if (currentFrame >= 0)
            {
                if (isPlaying)
                {
                    sequence.Play(currentFrame);
                }
                else
                {
                    sequence.SetCurrentFrame(currentFrame);
                }

                transformSnapshot.Restore();
            }

            return(success);
        }
Esempio n. 8
0
        public override void Init()
        {
            base.Init();

            _snapshot = GetSnapshot(Sequence, Owner);
        }
Esempio n. 9
0
 protected override void SetDefaultValues()
 {
     base.SetDefaultValues();
     _target         = transform;
     _targetSnapshot = new TransformSnapshot(_target, false);
 }