BeauRoutine icon indicating copy to clipboard operation
BeauRoutine copied to clipboard

Executing routines in edit mode?

Open MostHated opened this issue 5 years ago • 0 comments

Hey there, I am quite impressed at all the things it looks like this package is capable of. Seems like it might be a great choice. I seem to be having a bit of an issue, though. What lead me to find this package was I am trying to do some light tweening at edit time in the scene view. I am trying to make it so when I click on items, such as my waypoint indicators in the sceneview that they animate a bit.

I first tried to use DoTween, but it just doesn't do well outside of playmode. So then I tried implementing this light package that uses normal coroutines which almost seemed like it was going to work. I clicked on a waypoint and it would begin to animate for about 1/4 of a second and then stop. I know the animation was still going because if I manually moved something else around while it was running, the waypoint would animate like it should, but I believe that since it was using normal coroutines, they don't force a sceneview repaint like moving something manually does.

Which is what lead me here, I was hoping that something that was outside of the standard coroutine might be just the thing I needed to bring this all together. The first thing I tried was taking the tween package I was currently trying out and simply replacing it's "StartCoroutine" with a BeauRoutine as seen below:

Excerpt from tween library
    [ExecuteInEditMode]
...
        private Routine routine;

        protected virtual void Init()
        {
            m_Tween = new Tweener<Vector3>(GenericKeys(keys), duration, delay, wrap);
            if (m_Tween.Loop != null)
            {
                m_Tween.OnSetValue += OnSetValue;
                m_Tween.OnMoveValue += OnMoveValue;
                // StartCoroutine(m_Tween.Loop);
                routine = Routine.Start(m_Tween.Loop); // Swapping in BeauRoutine
            }
        }

        protected virtual void Dispose()
        {
            if (m_Tween.Loop != null)
            {
                m_Tween.OnSetValue -= OnSetValue;
                m_Tween.OnMoveValue -= OnMoveValue;
                // StopCoroutine(m_Tween.Loop);
                routine.Stop();
            }
        }

Unfortunately though, I tested that out, and at the point in which the prior coroutine would do the partial tween for 1/4 of a second, I got no response from BeauRoutine. So, I figured I would try to set up a new Tween using BeauRoutine for the whole setup, so I implemented the following:

Excerpt from new tween setup
    [ExecuteInEditMode]
    public class ArrowVisual : MonoBehaviour
    {
        public Tween beauTween;
        public Routine beauRoutine;

        public void PlayAnim()
        {
            var pos = transform.position;
            var currentHeight = new Vector3();
            beauTween = Tween.Vector(
                new Vector3(pos.x, 1.0f, pos.z),
                new Vector3(pos.x, 1.2f, pos.z),
                x => currentHeight = x,
                1f);
            beauTween.OnUpdate(x => transform.position = currentHeight);
            beauRoutine = beauTween.Play();
        }

        public void StopAnim()
        {
            beauRoutine.Stop();
        }
    }

Though now, using the "pure Beau" method, I seem to just get the following message in the console:

Exception message
[Exception] InvalidOperationException: The following game object is invoking the DontDestroyOnLoad method: Routine::Manager. Notice that DontDestroyOnLoad can only be used in play mode and, as such, cannot be part of an editor script.
Manager.Initialize() at /BeauRoutine/Routine/Internal/Manager.cs:309
307:   Host.Initialize(this);
308:   hostGO.hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSaveInEditor;
-->309:   GameObject.DontDestroyOnLoad(hostGO);
311:   Log("Initialize() -- Version " + VERSION.ToString());

Is there any chance of me getting edit time tweening working with this package, or am I barking up the wrong tree, so to speak?

Thanks! -MH

MostHated avatar Jul 18 '20 20:07 MostHated