荣耀彩票代理

  • 热门专题

Unity3d开发(十八)监听编辑器状态改变 制定自定义回调

作者:  发布日期:2016-11-24 21:08:05
  • WENZHANGZUOZHE:SONGYANG

    荣耀彩票代理BENWENCHUZI AXIULUODAO,JINZHIYONGYUSHANGYEYONGTU,ZHUANZAIQINGZHUMINGCHUCHU。

    YUANWENLIANJIE:http://blog.csdn.net/fansongy/article/details/53318791

     

     

     

     

     

     

     

     

     



     


     

    荣耀彩票代理ZUOBIANJIQICHAJIANSHI,WOZONGSHIXIANGYAONADAOJIANTINGBIANJIQIDEZHUANGTAIBIANHUA。BIRUZAIDAKAIBIANJIQIKAISHIYUNXINGZIJIDEFUWU。ZHEISHIJIUXUYAOYONGHUDAKAIBIANJIQIDESHIJIAN。ZAIBIRUWOXIWANGZAIYOUXITUICHUYUNXINGMOSHIZHIQIAN,BAYIXIEBIANJIDEDONGXIHUANCUNCHULAI,RANHOUDUIZHEIXIESHUJUZUOZIDONGHUACHULI,NEIMEWOJIUXUYAOTUICHUYUNXINGMOSHIDESHIJIAN。ZHURUCILEIBA。

    LINGYIFANGMIAN,WOXIWANGYONGGUANCHAZHEMOSHI,BINGQIENENGZIDONGHUAZHUCE。YINWEIWOZHUYIDAO,DAORUZIYUANSHIDEAssetImporterHUIDIAOJIUSHIZHEIYANGZUODE。YONGHUZHIXUYAOSHIXIANYIGEJIEKOU,JIUKEYISHOUDAOHUIDIAO。JIDADEJIANHUALEKUOZHANLIUCHENG。BIANJIQIDAIMAYOUBUBIKAOLVXIAOLVWENTI,JIEZHUC#DEFANSHE,KEYIHENRONGYIDESHIXIANZHEIZHONGGONGNENG。

    概述

    荣耀彩票代理ZHENGTAOKUANGJIADEQIDONGHEXINSHISHUXINGInitializeOnLoad。DANGUnity3dYUNXINGHUOQIDONGSHI,HUIZHONGXINJIAZAIYOUJIAOBEN。DANGSHIYONGZHEIGEHONGSHI,BIANJIQIHUIZIDONGJIANGBEIBIAOZHUDELEISHILIHUADAONEICUNZHONG。YINCIWOMENKEYILIYONGZHEIGETEXING,ZAITADEGOUZAOHANSHUZHONGLAQIWOMENZHENGGEFUWU。 ZHEILIYOUGEXIAOJIQIAO。ZAIQIDONGUnityBIANJIQIDEQINGKUANGXIA,RUGUOZAIGOUZAOHANSHUZHONGCHUANGJIANDUIXIANG,HUIBEIQITAQINGCHUHANSHUGANDIAO。WORENWEISHIJIAOBENCHUSHIHUASHUNXU,HUOSHICHANGJINGQIEHUANYINQIDE,JUTIYUANYINDEWENUnityLE。WEILEJIEJUEZHEIGEWENTI,WOJIEZHULEupdateHANSHU,TIAOLEYIZHENZHIXINGYINGYOUDELUOJI。

    荣耀彩票代理ZIDONGZHUCESHIJIEZHUC#DEFANSHE,TONGGUOGetAssembliesHEGetTypesHUOQUDAOSUOYOUDELEI,RANHOUCHUANGJIANCHUDUIYINGDESHILI。

    包装

    荣耀彩票代理ZHEIGELEIWOJUEDEYOUGETEBIESHIHEDEMINGZI——NightWatch。RUGUONIMEIKANGUOBINGYUHUOZHIGE,KENENGLIJIEZHEIGEKUANGJIAHAISUANYOUDIANNANDU。ZONGDESHUOLAI,ZHEIGEKUANGJIAJIANGSHULEYIGESHAONIANJIARUSHOUYERENDUIWU,BINGQUZHANGCHENGZHIWAIZHANDOUDEGUSHI...

    实现

    JIEKOULEIRUXIA:

    public interface ICrow
    {
        /// <summary>
        /// Join the Nights Watch 
        /// </summary>
        void Enroll();
    
        /// <summary>
        /// Before to Enter Wild
        /// </summary>
        void PrepareForBattle();
    
        /// <summary>
        /// To the Weirwood outside the wall
        /// </summary>
        void FaceWeirwood();
    
        /// <summary>
        /// Back To the Castle Black
        /// </summary>
        void OpenTheGate();
    
        /// <summary>
        /// Tell Vow to the Old God
        /// </summary>
        void Vow();
    }

    SHILILEIRUXIA:

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEditor;
    
    [InitializeOnLoad]
    public class NightsWatch
    {
        #region Public Attributes
    
        #endregion
    
        #region Private Attributes
        private static List<ICrow> m_crows = new List<ICrow>();
        #endregion
    
        #region Public Methods
    
        static NightsWatch()
        {
            if (!EditorApplication.isPlayingOrWillChangePlaymode)
            {
                EditorApplication.update += WelcomeToCastleBlack;
            }
            else 
            {
                EditorApplication.update += BeyondTheWall;
            }
        }
    
        static void WelcomeToCastleBlack()
        {
            EditorApplication.update -= WelcomeToCastleBlack;
    
            //Debug.Log("Welcome To castle black");
            m_crows.Clear();
            var crows = GetAllImplementTypes<ICrow>(System.AppDomain.CurrentDomain);
            foreach (var eachCrow in crows)
            {
                eachCrow.Enroll();
                m_crows.Add(eachCrow);
            }
    
            EditorApplication.update += WaitForWild;
        }
    
        static void WaitForWild()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                foreach (var eachCrow in m_crows)
                {
                    eachCrow.PrepareForBattle();
                }
                EditorApplication.update -= WaitForWild;
            }
        }
    
        static void BeyondTheWall()
        {
            EditorApplication.update -= BeyondTheWall;
    
            //Debug.Log("Welcome To The Wild");
            m_crows.Clear();
            var crows = GetAllImplementTypes<ICrow>(System.AppDomain.CurrentDomain);
            foreach (var eachCrow in crows)
            {
                eachCrow.FaceWeirwood();
                m_crows.Add(eachCrow);
            }
    
            EditorApplication.update += WaitForCrowReturn;
        }
        
        static void WaitForCrowReturn()
        {
            if (!EditorApplication.isPlayingOrWillChangePlaymode )
            {
                //Debug.Log("Open the Door");
                EditorApplication.update -= WaitForCrowReturn;
                foreach (var eachCrow in m_crows)
                {
                    eachCrow.OpenTheGate();
                }
                EditorApplication.update += WelcomeToCastleBlack;
            }
        }
    
        public static void CrowsVow()
        {
            foreach (var eachCrow in m_crows)
            {
                eachCrow.Vow();
            }
        }
    
        [MenuItem("Land/CastleBlack")]
        public static void MakeVow()
        {
            NightsWatch.CrowsVow();
        }
        #endregion
    
        #region Override Methods
    
        #endregion
    
        #region Private Methods
        public static T[] GetAllImplementTypes<T>(System.AppDomain aAppDomain) where T : class
        {
            var result = new List<T>();
            var assemblies = aAppDomain.GetAssemblies();
            foreach (var assembly in assemblies)
            {
                var types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (typeof(T).IsAssignableFrom(type))
                    {
                        if (!type.IsAbstract)
                        {
                            var tar = assembly.CreateInstance(type.FullName) as T;
                            result.Add(tar);
                        }
                    }
                }
            }
            return result.ToArray();
        }
        #endregion
    }
    

    JIANDANJIESHIYIXIA,SUOYOUDEJIEKOUDOUSHIANZHAOBINGYUHUOZHIGEZHONGDEJUQINGDINGYI。DANGZAIBIANJIZHUANGTAIXIASHI,HUICHUANGJIANDUIYINGDESHILILEI,BINGDIAOYONGEnrollHANSHU,ZHEIXIANGDANGYUJonGANGGANGJINRUCastleBlack。DANGDIANJIPlayYUNXINGSHI,HUIXIANDIAOYONGPrepareForBattle,XIANGDANGYUZAICHENGBAOZHONGZHUNBEICHUZHENG。DANGYOUXIKAISHIYUNXINGSHI,HUIDIAOYONGFaceToWeirWood,ZHEILIDUIYINGDESHICHENGWAINEIKEYULIANGMU,YIBANCHUZHENGZHIQIANDOUSHIYAOQUQIDAOYIXIA。RANHOUDANGYOUXIYUNXINGJIESHUSHI,HUIDIAOYONGOpenTheGate,DUIYINGCHUZHENGHUILAI,ZAIZHANGCHENGXIAMIANHANMEN。RANHOUYOUGEVowJIEKOU,ZHEIGESHIYONGLAIDIANMINGDE,CHENGBAOLIDEWUYADOUYAOLIEDUIDA“DAO”。

    使用

    XINJIANLIANGGESHILI: YIGESHIJonSnow:

    public class JonSnow :  ICrow
    {
        public void Enroll()
        {
            Debug.Log(this + " join the NightWatch!");
        }
    
        public void PrepareForBattle()
        {
            Debug.Log(this + " follow your lead!");
        }
    
        public void FaceWeirwood()
        {
            Debug.Log("I'm the wolf in the north");
        }
    
        public void OpenTheGate()
        {
            Debug.Log(this + " request enter Castle Black");
        }
    
        public void Vow()
        {
            Debug.Log(this + " For The Watch");
        }
    }

    荣耀彩票代理YIGESHISamwell:

    public class Samwell :  ICrow
    {
        public void Enroll()
        {
            Debug.Log(this + " I came form Lord Randyll Tarly,and I even his oldest son ...");
        }
    
        public void PrepareForBattle()
        {
            Debug.Log(this + " is not ready yet...");
        }
    
        public void FaceWeirwood()
        {
            Debug.Log("I'm a useless warrior,but may be ... helpful");
        }
    
        public void OpenTheGate()
        {
            Debug.Log(this + " also want enter");
        }
    
        public void Vow()
        {
            Debug.Log(this + " For The ... alive");
        }
    }

    测试

    DANGXIEHAODAIMABIANYIWANCHENGSHI,JIUNENGZAISHUCHUZHONGKANDAOTALIANGDAOZHANGCHENGQUBAODAOLE。DIANJIYUNXINGCHENGXU,GUANBIYUNXINGCHENGXU,HUIFENBIEYOURIZHISHUCHU,XIAOGUORUXIA:


    荣耀彩票代理QIZHONGHONGXIANSHIDIANJIPlayCAOZUO,LVXIANSHITINGZHIUnityYUNXINGDECAOZUO,HONGXIANYISHANGDERIZHISHIDAKAIunityHUOZHONGXINBIANYISHISHUCHUDE。YIQIEANZHAOYUQISHIXIAN,SHOUGONG。

    如果你觉得这篇文章对你有帮助,可以顺手点个顶,不但不会喜当爹,还能让更多人能看到它...
     

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规