Example #1
0
    [CYFEventFunction] public void Remove(string eventName)
    {
        GameObject go = GameObject.Find(eventName);

        if (!go)
        {
            Debug.LogWarning("Event.Remove: The event " + eventName + " doesn't exist but you tried to remove it.");
        }
        else
        {
            EventOW ev = go.GetComponent <EventOW>();
            if (ev != null)
            {
                if (!(ev.name.Contains("Image") || ev.name.Contains("Tone")))
                {
                    if (GlobalControls.EventData.ContainsKey(ev.name))
                    {
                        GlobalControls.EventData.Remove(ev.name);
                    }

                    try {
                        GameState.EventInfos ei = new GameState.EventInfos()
                        {
                            CurrPage = ev.actualPage,
                            CurrSpriteNameOrCYFAnim = ev.GetComponent <CYFAnimator>()
                                ? ev.GetComponent <CYFAnimator>().specialHeader
                                : EventManager.instance.sprCtrls[ev.name].img.GetComponent <SpriteRenderer>()
                                    ? EventManager.instance.sprCtrls[ev.name].img.GetComponent <SpriteRenderer>().sprite.name
                                    : EventManager.instance.sprCtrls[ev.name].img.GetComponent <Image>().sprite.name,
                            NoCollision = ev.gameObject.layer == 0,
                            Anchor      = UnitaleUtil.VectorToVect(ev.GetComponent <RectTransform>().anchorMax),
                            Pivot       = UnitaleUtil.VectorToVect(ev.GetComponent <RectTransform>().pivot)
                        };
                        GlobalControls.EventData.Add(ev.name, ei);
                    } catch { }
                }
            }

            if (EventManager.instance.eventScripts.ContainsKey(go))
            {
                if (EventManager.instance.coroutines.ContainsKey(EventManager.instance.eventScripts[go]))
                {
                    EventManager.instance.coroutines.Remove(EventManager.instance.eventScripts[go]);
                }
                EventManager.instance.eventScripts.Remove(go);
            }
            EventManager.instance.sprCtrls.Remove(eventName);
            EventManager.instance.events.Remove(go);
            if (go.transform.parent != null)
            {
                if (go.transform.parent.name == "SpritePivot")
                {
                    go = go.transform.parent.gameObject;
                }
            }
            Object.Destroy(go); //NEED PARENTAL REMOVE
        }
        if (appliedScript != null && (EventManager.instance.ScriptLaunched || EventManager.instance.coroutines.ContainsKey(appliedScript)))
        {
            appliedScript.Call("CYFEventNextCommand");
        }
    }