private GameObject prefabObject;    // The actual location of the prefab that is moving


    // MONO FUNCTIONS ----------------------------------------------------------------------------- |

    /*
     * This function is called when the game is booted and is used for initializations.
     *
     */
    void Start()
    {
        enter = transform.GetComponentInChildren <TriggerEnter>();
        // Event listeners
        IDied.AddListener(nullPing);
        IGotHit.AddListener(nullPing2);
        IShot.AddListener(nullPing2);
        IPerformed.AddListener(nullPing3);
        enter.addItemListener(triggered);

        speedDisplay = prefabObject.transform.Find("SpeedUp").gameObject;
        powerDisplay = prefabObject.transform.Find("Power").gameObject;
        speedDisplay.SetActive(false);
        powerDisplay.SetActive(false);

        gm = GameObject.Find("Main Camera").GetComponent <GameManager>();
        gm.addDamageListener(MyTeam, playerNumber, RecordHit);

        anim = prefabObject.transform.Find("Space_Soldier_A_LOD1").GetComponent <Animator>();
        part = prefabObject.GetComponent <ParticleSystem>();

        visible = new List <GameObject>();
        visibleEnemyLocations = new List <Vector3>();
        attackedFromLocations = new List <Vector3>();

        moveDestination = prefabObject.transform.position;

        // These functions are called every second. useful for timers and other time based events
        InvokeRepeating("reloadTimerCountdown", 0.0f, 1.0f);
        InvokeRepeating("respawnTimerCountdown", 0.0f, 1.0f);
        InvokeRepeating("enemyLocationTimerCountdown", 0.0f, 1.0f);
    }
 private void Start()
 {
     e.AddListener("Test1", Handler);
     e.AddListener("Test1", (p) => { Debug.Log("测试1----->2222"); });
     e.AddListener("Test2", (p) => { Debug.Log("测试2----->参数:" + p); });
     e.AddListener("Test2", (p) => { Debug.Log("测试2----->参数:" + p); });
 }
示例#3
0
    void Start()
    {
        //也可以使用+=,但是+=执行多次没有-=就会有隐患
        action1 = RunMyEvent1;
        action2 = RunMyEvent2;

        myEvent.AddListener(action1);
        myEvent.AddListener(action2);

        //如果需要删除的话就执行Remove
        //		myEvent.RemoveListener (action1);
        //		myEvent.RemoveListener (action2);
        //		myEvent.RemoveAllListeners ();
    }
 private UnityEvent <object> CreateNewEvent(string eventName, UnityAction <object> listener, UnityEvent <object> thisEvent)
 {
     thisEvent = new MyEvent();
     thisEvent.AddListener(listener);
     _eventDictionary.Add(eventName.ToString(), thisEvent);
     return(thisEvent);
 }
示例#5
0
    //开始监听指定事件
    public static void StartListening(string eventName, UnityAction <GameObject, string> listener)
    {
        if (instance == null)
        {
            instance = FindObjectOfType(typeof(EventManager)) as EventManager;
            if (instance == null)
            {
                Debug.Log("NO EVENTMANAGER!");
                return;
            }
        }

        MyEvent thisEvent = null;

        if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
        {
            thisEvent.AddListener(listener);
        }
        else
        {
            thisEvent = new MyEvent();
            thisEvent.AddListener(listener);
            instance.eventDictionary.Add(eventName, thisEvent);
        }
    }
示例#6
0
    /// <summary>
    /// Start listening specified event.
    /// </summary>
    /// <param name="eventName">Event name.</param>
    /// <param name="listener">Listener.</param>
    public static void StartListening(string eventName, UnityAction <GameObject, string> listener)
    {
        if (Instantiate == null)
        {
            Instantiate = FindObjectOfType(typeof(EventManager)) as EventManager;
            if (Instantiate == null)
            {
                Debug.Log("Have no event manager on scene");
                return;
            }
        }

        MyEvent thisEvent = null;

        if (Instantiate.eventDictionary.TryGetValue(eventName, out thisEvent))
        {
            thisEvent.AddListener(listener);
        }
        else
        {
            thisEvent = new MyEvent();
            thisEvent.AddListener(listener);
            Instantiate.eventDictionary.Add(eventName, thisEvent);
        }
    }
示例#7
0
    // Start is called before the first frame update
    void Start()
    {
        fruit_script = GameObject.Find("Fruits");
        testEvt      = new MyEvent();
        testEvt.AddListener(test);

        //带参数的事件唤醒方式
        testEvt.Invoke(fruit_script, 2);
    }
示例#8
0
 public static void StartListening(string eventName, UnityAction <object> listener)
 {
     if (Singleton.eventDictionary.TryGetValue(eventName, out var thisEvent))
     {
         thisEvent.AddListener(listener);
     }
     else
     {
         thisEvent = new MyEvent();
         thisEvent.AddListener(listener);
         Singleton.eventDictionary.Add(eventName, thisEvent);
     }
 }
示例#9
0
 /// <summary>
 /// 添加监听事件委托
 /// </summary>
 /// <param name="eventKey">事件Key</param>
 /// <param name="eventListener">事件监听器</param>
 public void AddEventListener(T1 eventKey, UnityAction <T1> action)
 {
     if (!_eventDictionary.ContainsKey(eventKey))
     {
         MyEvent myEvent = new MyEvent();
         myEvent.AddListener(action);
         _eventDictionary.Add(eventKey, myEvent);
     }
     else
     {
         _eventDictionary[eventKey].AddListener(action);
     }
 }
    public List <Card> cardList = new List <Card>();                 //实例化手牌

    protected override void Awake()
    {
        Instance = this;

        base.Awake();

        spawnPool = PoolManager.Pools["GameAssets"];

        action += Callback;
        playCardEvent.AddListener(action);

        m_closeButton.onClick.AddListener(OnCloseButtonClick);
        m_startButton.onClick.AddListener(OnPlayButtonClick);
    }
示例#11
0
    public static void StartListening(string eventName, UnityAction <Color> listener)
    {
        UnityEvent <Color> thisEvent = null;

        if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
        {
            thisEvent.AddListener(listener);
        }
        else
        {
            thisEvent = new MyEvent();
            thisEvent.AddListener(listener);
            instance.eventDictionary.Add(eventName, thisEvent);
        }
    }
示例#12
0
    public static void CriarEvento(string nome, UnityAction <GameObject, string> evento)
    {
        if (instancia == null)
        {
            instancia = FindObjectOfType(typeof(EventManager)) as EventManager;
            if (instancia == null)
            {
                Debug.Log("There is no EventManager");
                return;
            }
        }
        MyEvent esteEvento = null;

        if (instancia.eventos.TryGetValue(nome, out esteEvento))
        {
            esteEvento.AddListener(evento);
        }
        else
        {
            esteEvento = new MyEvent();
            esteEvento.AddListener(evento);
            instancia.eventos.Add(nome, esteEvento);
        }
    }
示例#13
0
 // Start is called before the first frame update
 void Start()
 {
     evt = new MyEvent();
     evt.AddListener(PrintNumber);
     evt.RemoveListener(PrintNumber);
 }