I'm experiencing an unexpected behaviour from the new event system, I'm not sure if it is working as intended or not:
I've made a small test program using a clean project & v3.0.3d
when I register a call back using a UItween the EventDelegate system still calls previously registered objects with no regard for the tween instance being used.
and I can Remove a delegate using any tween instance?
(this was't the case in the 2.x system)
so this program will:
- fade a sprite out
- log completion of the fade
- run a fade in
- Log completion of the fade in; but also completion of the previous tween instance, even though the previous tween should now be out of scope?
so now it loops, as the previous event has been called again.
The loop can be exited with a Remove, but using a temporary tween instance, no need to reference the tween used in the original registration?
using UnityEngine;
using System.Collections;
public class FadeTest : MonoBehaviour
{
float fadeTime = 1f;
int fadeoutCounter = 1;
// Use this for initialization
void Start ()
{
fadeOut ();
}
public void fadeIn ()
{
TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 1f);
EventDelegate.Add (twn.onFinished, fadeInComplete);
}
public void fadeOut ()
{
Debug.Log ("fadeOut called once");
TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 0f);
EventDelegate.Add (twn.onFinished, fadeOutComplete);
}
void fadeOutComplete ()
{
Debug.Log ("fadeOutCompleted " + fadeoutCounter + " times");
fadeoutCounter++;
fadeIn ();
if (fadeoutCounter > 5){
Debug.Log("running dodgy remove");
TweenAlpha twn = TweenAlpha.Begin (transform.gameObject, fadeTime, 0f);
EventDelegate.Remove (twn.onFinished, fadeOutComplete);
}
}
void fadeInComplete ()
{
Debug.Log ("fadeInComplete ");
}
}