Unity(好用的Event事件脚本)

超级好用的event事件脚本

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

namespace Code.Frame
{
 public class Event where TClass : Event, new()
    {
        private static TClass instance = null;
        private static TClass Instance
        {
            get
            {
                if (instance == null) instance = new TClass();
                return instance;
            }
        }

        event Action Events;

        void listen(Action action)
        {
            Events += action;
        }
        void unlisten(Action action)
        {
            Events -= action;
        }
        void fire(TValue value)
        {
            if (Events != null) Events(value);
        }
        public static void Listen(Action action)
        {
            Instance.listen(action);
        }
        public static void Unlisten(Action action)
        {
            Instance.unlisten(action);
        }
        public static void Fire(TValue value)
        {
            Instance.fire(value);
        }
    }

    public class Event where TClass : Event, new()
    {
        private static TClass instance = null;
        private static TClass Instance
        {
            get
            {
                if (instance == null) instance = new TClass();
                return instance;
            }
        }

        event Action Events;

        void listen(Action action)
        {
            Events += action;
        }
        void unlisten(Action action)
        {
            Events -= action;
        }
        void fire(TValue1 value1, TValue2 value2)
        {
            if (Events != null) Events(value1,value2);
        }
        public static void Listen(Action action)
        {
            Instance.listen(action);
        }
        public static void Unlisten(Action action)
        {
            Instance.unlisten(action);
        }
        public static void Fire(TValue1 value1, TValue2 value2)
        {
            Instance.fire(value1, value2);
        }
    }


    public class Event where TClass : Event, new()
    {
        private static TClass instance = null;
        private static TClass Instance
        {
            get
            {
                if (instance == null) instance = new TClass();
                return instance;
            }
        }

        event Action Events;

        void listen(Action action)
        {
            Events += action;
        }
        void unlisten(Action action)
        {
            Events -= action;
        }
        void fire(TValue1 value1, TValue2 value2, TValue3 value3)
        {
            if (Events != null) Events(value1, value2, value3);
        }
        public static void Listen(Action action)
        {
            Instance.listen(action);
        }
        public static void Unlisten(Action action)
        {
            Instance.unlisten(action);
        }
        public static void Fire(TValue1 value1, TValue2 value2, TValue3 value3)
        {
            Instance.fire(value1, value2, value3);
        }
    }



    public class Event where TClass : Event, new()
    {
        private static TClass instance = null;
        private static TClass Instance
        {
            get
            {
                if (instance == null) instance = new TClass();
                return instance;
            }
        }

        event Action Events;

        void listen(Action action)
        {
            Events += action;
        }
        void unlisten(Action action)
        {
            Events -= action;
        }
        void fire()
        {
            if (Events != null) Events();
        }
        public static void Listen(Action action)
        {
            Instance.listen(action);
        }
        public static void Unlisten(Action action)
        {
            Instance.unlisten(action);
        }
        public static void Fire()
        {
            Instance.fire();
        }
    }
}

你可能感兴趣的:(Unity(好用的Event事件脚本))