private void RemoveClip(RuntimeAnimationClip rtClip)
        {
            int index = m_rtClips.IndexOf(rtClip);

            if (index == ClipIndex)
            {
                m_animation.Stop();
                m_isPlaying = false;
            }

            if (index >= 0)
            {
                m_rtClips.RemoveAt(index);
                if (m_animation.clip == rtClip.Clip)
                {
                    m_animation.RemoveClip(m_animation.clip.name);
                    m_animation.clip = null;
                }
            }

            if (ClipIndex >= m_rtClips.Count)
            {
                ClipIndex = m_rtClips.Count - 1;
            }
        }
Ejemplo n.º 2
0
        private void LoadState(byte[][] state)
        {
            ISerializer serializer = IOC.Resolve <ISerializer>();
            Type        animType   = GetSurrogateType(typeof(RuntimeAnimation));
            Type        clipType   = GetSurrogateType(typeof(RuntimeAnimationClip));

            if (serializer == null || animType == null || clipType == null)
            {
                return;
            }

            IPersistentSurrogate animationSurrogate = (IPersistentSurrogate)serializer.Deserialize(state[0], animType);

            animationSurrogate.WriteTo(Target);

            IList <RuntimeAnimationClip> clips = Target.Clips;

            for (int i = 0; i < clips.Count; ++i)
            {
                RuntimeAnimationClip clip = clips[i];
                if (clip == null)
                {
                    clips[i] = clip = ScriptableObject.CreateInstance <RuntimeAnimationClip>();
                }

                IPersistentSurrogate clipSurrogate = (IPersistentSurrogate)serializer.Deserialize(state[1 + i], clipType);
                clipSurrogate.WriteTo(clip);
            }
        }
Ejemplo n.º 3
0
        private byte[][] SaveState()
        {
            ISerializer serializer = IOC.Resolve <ISerializer>();
            Type        animType   = GetSurrogateType(typeof(RuntimeAnimation));
            Type        clipType   = GetSurrogateType(typeof(RuntimeAnimationClip));

            if (serializer == null || animType == null || clipType == null)
            {
                return(new byte[0][]);
            }

            IList <RuntimeAnimationClip> clips = Target.Clips;

            byte[][] state = new byte[1 + clips.Count][];

            IPersistentSurrogate animationSurrogate = (IPersistentSurrogate)Activator.CreateInstance(animType);
            IPersistentSurrogate clipSurrogate      = (IPersistentSurrogate)Activator.CreateInstance(clipType);

            animationSurrogate.ReadFrom(Target);
            state[0] = serializer.Serialize(animationSurrogate);
            for (int i = 0; i < clips.Count; ++i)
            {
                RuntimeAnimationClip clip = clips[i];
                clipSurrogate.ReadFrom(clip);
                state[1 + i] = serializer.Serialize(clipSurrogate);
            }

            return(state);
        }
        private void SetAnimationClip(RuntimeAnimationClip clip, GameObject go)
        {
            RuntimeAnimation animation = go.GetComponent <RuntimeAnimation>();

            animation.Clips = new List <RuntimeAnimationClip> {
                clip
            };
            animation.ClipIndex = 0;

            UpdateTargetAnimation();
            m_propertiesView.Target = animation;
            m_timelineView.Target   = animation;

            CurrentClip = clip;

            ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();

            if (exposeToEditor != null && animation != null)
            {
                exposeToEditor.ReloadComponentEditor(animation, true);
            }

            animation.Refresh();
            UpdateCreateViewState();
        }
 public void ResolveComponents(RuntimeAnimationClip clip, RuntimeAnimation animation)
 {
     foreach (RuntimeAnimationProperty property in clip.Properties)
     {
         _ResolveComponents(property, animation);
     }
 }
Ejemplo n.º 6
0
 private void SetCurrentClip(RuntimeAnimationClip value)
 {
     //m_timelineView.SetSample(0);
     m_propertiesView.Clip = value;
     m_timelineView.Clip   = value;
     if (m_target != null)
     {
         m_target.ClipIndex = m_target.Clips.IndexOf(value);
         m_target.Refresh();
     }
 }
        private void OnSaveCompleted(ISaveAssetDialog sender, UnityObject asset)
        {
            sender.SaveCompleted -= OnSaveCompleted;

            if (asset == null)
            {
                return;
            }

            RuntimeAnimationClip clip = (RuntimeAnimationClip)asset;
            GameObject           go   = TargetGameObject;

            ExposeToEditor exposeToEditor = go.GetComponent <ExposeToEditor>();

            if (exposeToEditor != null)
            {
                Editor.Undo.BeginRecord();
                if (!exposeToEditor.GetComponent <RuntimeAnimation>())
                {
                    Editor.Undo.AddComponent(exposeToEditor, typeof(RuntimeAnimation));
                }
                Editor.Undo.CreateRecord(redoRecord =>
                {
                    SetAnimationClip(clip, go);
                    return(true);
                },
                                         undoRecord =>
                {
                    RuntimeAnimation animation = exposeToEditor.GetComponent <RuntimeAnimation>();
                    if (animation != null)
                    {
                        animation.Clips = null;
                    }
                    UpdateTargetAnimation();
                    m_propertiesView.Target = null;
                    m_timelineView.Target   = null;
                    UpdateCreateViewState();
                    return(true);
                });
                Editor.Undo.EndRecord();
            }
            else
            {
                if (!go.GetComponent <RuntimeAnimation>())
                {
                    go.AddComponent <RuntimeAnimation>();
                }
            }

            SetAnimationClip(clip, go);
        }
Ejemplo n.º 8
0
        private void OnCreateClick()
        {
            IOC.Resolve <IWindowManager>().CreateDialogWindow(RuntimeWindowType.SaveAsset.ToString(), m_localization.GetString("ID_RTEditor_AnimationView_SaveAnimationClip", "Save Animation Clip"),
                                                              (sender, args) => {});

            ISaveAssetDialog     saveAssetDialog = IOC.Resolve <ISaveAssetDialog>();
            RuntimeAnimationClip clip            = ScriptableObject.CreateInstance <RuntimeAnimationClip>();

            clip.name = m_localization.GetString("ID_RTEditor_AnimationView_NewAnimationClip", "New Animation Clip");

            saveAssetDialog.Asset          = clip;
            saveAssetDialog.AssetIcon      = Resources.Load <Sprite>("RTE_AnimationClip");
            saveAssetDialog.SaveCompleted += OnSaveCompleted;
        }
        public void SetClips(IList <RuntimeAnimationClip> clips, int currentClipIndex)
        {
            m_isPlaying = false;

            if (m_animation == null)
            {
                m_animation = gameObject.GetComponent <Animation>();
                if (m_animation == null)
                {
                    m_animation = gameObject.AddComponent <Animation>();
                }
                m_animation.playAutomatically = false;
                m_animation.Stop();
                if (m_animation.clip != null)
                {
                    m_animation.RemoveClip(m_animation.clip.name);
                }
                m_animation.clip = null;
            }

            m_rtClips.Clear();

            if (clips != null)
            {
                foreach (RuntimeAnimationClip clip in clips)
                {
                    m_rtClips.Add(clip);
                }
                m_clipIndex = currentClipIndex;
                RuntimeAnimationClip currentClip = m_rtClips[m_clipIndex];
                if (currentClip != null)
                {
                    if (currentClip.Clip != null)
                    {
                        m_animation.AddClip(currentClip.Clip, currentClip.Clip.name);
                    }
                    m_animation.clip = currentClip.Clip;
                }
            }
            else
            {
                m_clipIndex = -1;
            }
        }
Ejemplo n.º 10
0
        public void Refresh()
        {
            if (ClipIndex >= 0)
            {
                RuntimeAnimationClip clip = m_rtClips[ClipIndex];
                if (clip == null)
                {
                    m_isPlaying = false;
                    m_animation.Stop();
                    return;
                }
                clip.Refresh();
                clip.Clip.wrapMode = WrapMode.ClampForever;

                float          speed          = 0;
                float          normalizedTime = 0;
                AnimationState animationState;
                if (m_animation.isPlaying)
                {
                    animationState = m_animation[clip.Clip.name];
                    if (animationState != null)
                    {
                        speed = animationState.speed;
                        if (!m_isPlaying)
                        {
                            speed = 0;
                        }
                        normalizedTime = animationState.normalizedTime;
                    }
                }

                m_animation.Stop();
                if (m_animation.clip != null)
                {
                    m_animation.RemoveClip(m_animation.clip.name);
                }
                m_animation.clip = null;
                if (clip.Clip != null)
                {
                    m_animation.AddClip(clip.Clip, clip.Clip.name);
                }
                m_animation.clip = clip.Clip;
                m_animation.Play(clip.Clip.name);

                if (m_animation.isPlaying)
                {
                    m_isPlaying          = !clip.Clip.empty && speed > 0;
                    animationState       = m_animation[clip.Clip.name];
                    animationState.speed = speed;
                    if (float.IsInfinity(normalizedTime) || float.IsNaN(normalizedTime))
                    {
                        normalizedTime = 0;
                    }
                    animationState.normalizedTime = normalizedTime;
                }
                else
                {
                    m_isPlaying = false;
                }
            }
            else
            {
                m_isPlaying = false;
                m_animation.Stop();
            }
        }