游戏框架(UI框架夯实篇_YanlzUIFramework)

《游戏框架》

##《游戏框架》发布说明:

++++“游戏框架”还是“游戏架构”,立钻哥哥还是以“游戏框架”来命名这个主题吧。

++++“游戏框架”作为整个游戏的框架,具有核心的地位,一个游戏的层次和后期维护性就取决于游戏框架。

++++《游戏框架》当然也是一个探索篇,作为这个分类的第一篇博文,还是先探索一段时间,后期根据需要再推出一个精品博文。

====>立钻哥哥带您学游戏框架。


##《游戏框架》目录:

#第一篇:框架入门篇

#第二篇:框架夯实篇

#第三篇:框架实战篇

#第四篇:框架进阶篇

#第五篇:框架高级实战篇

#第六篇:立钻哥哥带您学框架



#第二篇:框架夯实篇

++第二篇:框架夯实篇

++++第一章:UI框架夯实篇

++++第二章:UI框架实战篇

++++第三章:战斗框架实战篇

++++第四章:立钻哥哥带您学框架


##第一章:UI框架夯实篇

++第一章:UI框架夯实篇

++++1.1UI框架概述

++++1.2UI框架剖析

++++1.3、立钻哥哥带您学UI框架


###1.1UI框架概述

++1.1UI框架概述

++++框架(Framework):是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法。(一个框架是一个可复用的设计构件,它规定了应用的体系结构,阐明了整个设计、协作构件之间的依赖关系、责任分配和控制流程,表现为一组抽象类以及其实例之间协作的方法,它为构件复用提供了上下文(Context)关系。)

++++一个框架是一个可复用设计,它是由一组抽象类及其实例间协作关系来表达的。(框架的最大好处就是重用。)

++++软件架构设计要达到的目标如下:

--可靠性(Reliable):软件系统对于用户的商业经营和管理来说极为重要,因此软件系统必须非常可靠。

--安全性(Secure):软件系统所承担的交易的商业价值极高,系统的安全性非常重要。

--可伸缩性(Scalable):软件必须能够在用户的使用率、用户的数目增加很快的情况下,保持合理的性能。(只有这样,才能适应用户的市场扩展的可能性。)

--可定制化(Customizable):同样的一套软件,可以根据客户群的不同和市场需求的变化进行调整。

--可扩展性(Extensible):在新技术出现的时候,一个软件系统应当允许导入新技术,从而对现有系统进行功能和性能的扩展。

--可维护性(Maintainable):软件系统的维护包括两方面:一是排除现有的错误,二是将新的软件需求反映到现有系统中去。(一个易于维护的系统可以有效地降低技术支持的花费。)

--客户体验(Customer Experience):软件系统必须易于使用。

--市场时机(Time to Market):软件用户要面临同业竞争,软件提供商也要面临同业竞争。(以最快的速度争夺市场先机非常重要。)


###1.2UI框架剖析

++1.2UI框架剖析

++++立钻哥哥将用“UI框架实战”剖析UI框架。




##第二章:UI框架实战篇

++第二章:UI框架实战篇

++++前端开发中实际上大量的编码工作都在UI编码上,基本上占前端编码的70%左右。(一个良好的UI框架决定了前端的开发效率和后期的维护成本。)

++++UI框架涉及内容:BaseUIUIManagerResourceManagerSingletonBaseModuleModuleManager、自定义事件系统、BaseSceneSceneManagerCommonUINetWork等:

--BaseUI】:UI界面的基类,定义了统一的UI功能接口(事件,开关,动画,声音。)

--UIManager】:管理UI的管理器,管理是否缓存UI对象,是否需要互斥UI对象,管理一些通用UI

--ResourceManager】:资源管理器,资源加载统一管理,资源加载方式选择(同步、异步、本地、ABObjPool...),资源缓存,资源释放等。

--Singleton】:通用单例类的基类。

--BaseModule】:逻辑模块基类,定义模块的通用功能,处理不同系统的数据逻辑。

--ModuleManager】:逻辑模块管理器,管理游戏内所有逻辑的注册销毁等。

--【自定义事件系统】:不同模块直接的通信,模块内界面和数据逻辑分离。

--BaseScene】:场景逻辑基类。

--SceneManager】:管理项目所有场景切换,加载等。

--CommonUI】:项目中一些通用UI,继承BaseUI可重用UI

--NetWork】:如何在我们的框架中添加网络模块。



++YanlzUIFramework框架实战:

++++Scripts/GameLogic/GameController.cs

++++Scripts/GameLogic/Module/TestOneModule.cs

++++Scripts/GameLogic/UI/TestOne.cs

++++Scripts/GameLogic/UI/TestTwo.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseActor.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseController.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseModel.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseModule.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseScene.cs

++++Scripts/YanlzUIFramework/BaseClass/BaseUI.cs

++++Scripts/YanlzUIFramework/BaseClass/PropertyItem.cs

++++Scripts/YanlzUIFramework/Common/Extended/MethodExtension.cs

++++Scripts/YanlzUIFramework/Common/Message/Message.cs

++++Scripts/YanlzUIFramework/Common/Message/MessageCenter.cs

++++Scripts/YanlzUIFramework/Common/Message/MessageType.cs

++++Scripts/YanlzUIFramework/Common/Singleton/DDOLSingleton.cs

++++Scripts/YanlzUIFramework/Common/Singleton/Singleton.cs

++++Scripts/YanlzUIFramework/Common/Singleton/SingletonException.cs

++++Scripts/YanlzUIFramework/Common/Tools/EventTriggerListener.cs

++++Scripts/YanlzUIFramework/Defines/Definces.cs

++++Scripts/YanlzUIFramework/Interface/IDynamicProperty.cs

++++Scripts/YanlzUIFramework/Interface/Interface.cs

++++Scripts/YanlzUIFramework/Manager/CoroutineController.cs

++++Scripts/YanlzUIFramework/Manager/ModuleManager.cs

++++Scripts/YanlzUIFramework/Manager/ResManager.cs

++++Scripts/YanlzUIFramework/Manager/SceneManager.cs

++++Scripts/YanlzUIFramework/Manager/UIManager.cs




###2.1GameController.cs

###2.1GameController.cs

++2.1Scripts/GameLogic/GameController.cs

++++public class GameController : DDOLSingleton<GameController>{}

++++void Start(){}

++++private IEnumerator AutoUpdateGold(){}

++++private IEnumerator<int> AsyncLoadData(){}


++2.1.1GameController.cs

//立钻哥哥:游戏控制器(Scripts/GameLogic/GameController.cs

using UnityEngine;

using System.Collections;

using System.Collections.Generic;

using YanlzUIFramework;

using System;

 

public class GameController : DDOLSingleton<GameController>{

    //Use this for initialization

    void Start(){

        ModuleManager.Instance.RegisterAllModules();

        SceneManager.Instance.RegisterAllScene();

    }

 

    private IEnumerator AutoUpdateGold(){

        int gold = 0;

        while(true){

            gold++;

            yield return new WaitForSeconds(1.0f);

        

            Message message = new Message(MessageType.Net_MessageTestOne.ToString(), this);

            message[“gold”] = gold;

            MessageCenter.Instance.SendMessage(message);

        }

    }

 

   private IEnumerator<int> AsyncLoadData(){

        int i = 0;

        while(true){

            Debug.Log(立钻哥哥:----> + i);

            yield return i;

            i++;

        }

    }

}




###2.2TestOneModule.cs

###2.2TestOneModule.cs

++2.2Scripts/GameLogic/Module/TestOneModule.cs

++++public class TestOneModule : BaseModule{}

++++pubic int Gold{}

++++public TestOneModule(){}

++++protected override void OnLoad(){}

++++protected override void OnRelease(){}

++++private void UpdateGold(Message message){}


++2.2.1TestOneModule.cs

//立钻哥哥:数据模块(Scripts/GameLogic/Module/TestOneModule.cs

using System;

using YanlzUIFramework;

 

public class TestOneModule : BaseModule{

    public int Gold{  get;    private set;  }

 

    public TestOneModule(){

        this.AutoRegister = true;

    }

 

    protected override void OnLoad(){

        MessageCenter.Instance.AddListener(MessageType.Net_MessageTestOne, UpdateGold);

        base.OnLoad();

    }

 

    protected override void OnRelease(){

        MessageCenter.Instance.RemoveListener(MessageType.Net_MessageTestOne, UpdateGold);

        base.OnRelease();

    }

 

    private void UpdateGold(Message message){

        int gold = (int)message[“gold”];

        if(gold >= 0){

            Gold = gold;

            Message temp = new Message(“AutoUpdateGold”, this);

            temp[“gold”] = gold;

            temp.Send();

        }

    }

}




###2.3TestOne.cs

###2.3TestOne.cs

++2.3Scripts/GameLogic/UI/TestOne.cs

++++public class TestOne : BaseUI{}

++++private TestOneModule oneModule;

++++private Button btn;

++++private Text text;

++++public override EnumUIType GetUIType(){}

++++void Start(){}

++++protected override void OnAwake(){}

++++protected override void OnRelease(){}

++++private void UpdateGold(Message message){}

++++private void OnClickBtn(){}

++++private void Close(GameObject _listener, object _args, params object[] _params){}


++2.3.1TestOne.cs

//立钻哥哥:第一个UI测试界面(GameLogic/UI/TestOne.cs

using UnityEngine;

using System.Collections;

using UnityEngine.UI;

using YanlzUIFramework;

 

public class TestOne : BaseUI{

    private TestOneModule oneModule;

    private Button btn;

    private Text text;

 

    #region implemented abstract member of BaseUI

    public override EnumUIType GetUIType(){

        return EnumUIType.TestOne;

    }

    #endregion

 

    //Use this for initialization

    void Start(){

        text = transform.Find(“Panel/Text”).GetComponent<Text>();

    

        EventTriggerListener listener = EventTriggerListener.Get(transform.Find(“Panel/Button”).gameObject);

        listener.SetEventHandle(EnumTouchEventType.OnClick, Close, 1, “1234”);

 

        oneModule = ModuleManager.Instance.Get<TestOneModule>();

        text.text = “Gold: ” + oneModule.Gold;

    }

 

    protected override void OnAwake(){

        MessageCenter.Instance.AddListener(“AutoUpdateGold”, UpdateGold);

        base.OnAwake();

    }

 

    protected override void OnRelease(){

        MessageCenter.Instance.RemoveListener(“AutoUpdateGold”, UpdateGold);

        base.OnRelease();

    }

 

    private void Update(Message message){

        int gold = (int)message[“gold”];

        Debug.Log(立钻哥哥:TestOne UpdateGold:  + gold);

 

        text.text = “Gold: ” + gold;

    }

 

    private void OnClickBtn(){

        UIManager.Instance.OpenUICloseOthers(EnumUIType.TestTwo);

    }

 

    private void Close(GameObject _listener, object _args, params object[] _params){

        int i = (int) _params[0];

        string s = (string)_params[1];

        Debug.Log(i);

        Debug.Log(s);

 

        UIManager.Instance.OpenUICloseOthers(EnumUIType.TestTwo);

    }

}




###2.4TestTwo.cs

###2.4TestTwo.cs

++2.4Scripts/GameLogic/UI/TestTwo.cs

++++public class TestTwo : BaseUI{}

++++private Button btn;

++++public override EnumType GetUIType(){}

++++void Start(){}

++++private void OnClickBtn(){}

++++private void Close(){}


++2.4.1TestTwo.cs

//立钻哥哥:第二个UI测试界面(GameLogic/UI/TestTwo.cs

using UnityEngine;

using System.Collections;

using UnityEngine.UI;

using YanlzUIFramework;

 

public class TestTwo : BaseUI{

    private Button btn;

 

    #region implemented abstract members of BaseUI

    public override EnumType GetUIType(){

        return EnumType.TestTwo;

    }

    #endregion

 

    //Use this for initialization

    void Start(){

        btn = transform.Find(“Panel/Button”).GetComponent<Button>();

        btn.onClick.AddListener(OnClickBtn);

    }

 

    private void OnClickBtn(){

        UIManager.Instance.OpenUICloseOthers(EnumUIType.TestOne);

    }

 

    private void Close(){

        Destroy(gameObject);

    }

}




###2.5BaseActor.cs

###2.5BaseActor.cs

++2.5Scripts/YanlzUIFramework/BaseClass/BaseActor.cs

++++namespace YanlzUIFramework{}

++++public class BaseActor : IDynamicProperty{}

++++protected Dictionary<int, PropertyItem> dicProperty = null;

++++public event PropertyChangedHandle PropertyChanged;

++++public EnumActorType ActorType{}

++++public int ID{}

++++private BaseScene currentScene;

++++public BaseScene CurrentScene{}

++++public virtual void AddProperty(EnumPropertyType propertyType, object content){}

++++public virtual void AddProperty(int id, object content){}

++++public virtual void AddProperty(PropertyItem property){}

++++public void RemoveProperty(EnumPropertyType propertyType){}

++++public void RemoveProperty(int id){}

++++public void ClearProperty(){}

++++public virtual PropertyItem GetProperty(EnumPropertyType propertyType){}

++++protected virtual void OnPropertyChanged(int id, object oldValue, object newValue){}

++++public void DoChangeProperty(int id, object oldValue, object newValue){}

++++public PropertyItem GetProperty(int id){}

++++public BaseActor(){}


++2.5.1BaseActor.cs

//立钻哥哥:角色基类(YanlzUIFramework/BaseClass/BaseActor.cs

using System;

using System.Collections.Generic;

using UnityEngine;

 

namespace YanlzUIFramework{

    public class BaseActor : IDynamicProperty{

        protected Dictionary<int, PropertyItem> dicProperty = null;

 

        public event PropertyChangedHandle PropertyChanged;

 

        public EnumActorType ActorType{  set;    get;  }

        public int ID{  set;    get;  }

 

        private BaseScene currentScene;

        public BaseScene CurrentScene{

            set{

                currentScene = value;

            }

            get{

                return currentScene;

            }

        }

 

        public virtual void AddProperty(EnumPropertyType propertyType, object content){

            AddProperty((int)propertyType, content);

        }

 

        public virtual void AddProperty(int id, object content){

            PropertyItem property = new PropertyItem(id, content);

            AddProperty(property);

        }

 

        public virtual void AddProperty(PropertyItem property){

            if(null == dicProperty){

                dicProperty = new Dictionary<int, PropertyItem>();

           }

 

            if(dicProperty.ContainsKey(property.ID)){

            }

 

            dicProperty.Add(property.ID, property);

            property.Owner = this;

        }

 

        public void RemoveProperty(EnumPropertyType propertyType){

            RemoveProperty((int)propertyType);

        }

 

        public void RemoveProperty(int id){

            if(null != dicProperty && dicProperty.ContainsKey(id)){

                dicProperty.Remove(id);

            }

        }

 

        public void ClearProperty(){

            if(null != dicProperty){

                dicProperty.Clear();

                dicProperty = null;

            }

        }

 

        public virtual PropertyItem GetProperty(EnumPropertyType propertyType){

            return GetProperty((int)propertyType);

        }

 

        protected virtual void OnPropertyChanged(int id, object oldValue, object newValue){

        }

 

        #region IDynamicProperty implementation

        public void DoChangeProperty(int id, object oldValue, object newValue){

            OnPropertyChanged(id, oldValue, newValue);

            if(null != PropertyChanged){

                PropertyChanged(this, id, oldValue, newValue);

            }

        }

 

        public PropertyItem GetProperty(int id){

            if(null == dicProperty){

                return null;

            }

 

            if(dicProperty.ContainsKey(id)){

                return dicProperty[id];

           }

 

            Debug.LogWarning(立钻哥哥:Actor dicProperty non Property ID :  + id);

            return null;

        }

        #endregion

 

        public BaseActor(){

        }

 

    }    //立钻哥哥:public class BaseActor : IDynamicProperty{}

 

}    //立钻哥哥:namespace YanlzUIFramework




###2.6BaseController.cs

###2.6BaseController.cs

++2.6Scripts/YanlzUIFramework/BaseClass/BaseController.cs

++++namespace YanlzUIFramework{}

++++public class BaseController{}

++++public BaseController(){}


++2.6.1BaseController.cs

//立钻哥哥:控制器基类(YanlzUIFramework/BaseClass/BaseController.cs

using System;

 

namespace YanlzUIFramework{

    public class BaseController{

        public BaseController(){

        }

    }

}




###2.7BaseModel.cs

###2.7BaseModel.cs

++2.7Scripts/YanlzUIFramework/BaseClass/BaseModel.cs

++++namespace YanlzUIFramework{}

++++public class BaseModel{}

++++public BaseModel(){}


++2.7.1BaseModel.cs

//立钻哥哥:模型基类(YanlzUIFramework/BaseClass/BaseModel.cs

using System;

 

namespace YanlzUIFramework{

    public class BaseModel{

        public BaseModel(){

        }

    }

}




###2.8BaseModule.cs

###2.8BaseModule.cs

++2.8Scripts/YanlzUIFramework/BaseClass/BaseModule.cs

++++namespace YanlzUIFramework{}

++++public class BaseModule{}

++++public enum EnumRegisterMode{}

++++private EnumObjectState state = EnumObjectState.Initial;

++++public EnumObjectState State{}

++++public event StateChangedEvent StateChanged;

++++protected virtual void OnStateChanged(EnumObjectState newState, EnumObjecttate oldState){}

++++private EnumRegisterMode registerMode = EnumRegisterMode.NotRegister;

++++public bool AutoRegister{}

++++public bool HasRegistered{}

++++public void Load(){}

++++protected virtual void OnLoad(){}

++++public void Release(){}

++++protected virtual void OnRelease(){}


++2.8.1BaseModule.cs

//立钻哥哥:数据逻辑处理模块基类(YanlzUIFramework/BaseClass/BaseModule.cs

using System;

 

namespace YanlzUIFramework{

    public class BaseModule{

        public enum EnumRegisterMode{

            NotRegister,

            AutoRegister,

            AlreadyRegister,

        }

 

        private EnumObjectState state = EnumObjectState.Initial;

 

        public EnumObjectState State{

            get{

                return state;

            }

 

            set{

                if(state == value){

                    return;

                }

 

                EnumObjectState oldState = state;

                State = value;

 

                if(null != StateChanged){

                    StateChanged(this, state, oldState);

                }

               OnStateChanged(state, oldState);

            }

        }

 

        public event StateChangedEvent StateChanged;

 

        protected virtual void OnStateChanged(EnumObjectState newState, EnumObjectState oldState){

        }

 

        private EnumRegisterMode registerMode = EnumRegisterMode.NotRegister;

 

        public bool AutoRegister{

            get{

                return registerMode == EnumRegisterMode.NotRegister ? false : true;

            }

 

            set{

                if(registerMode == EnumRegisterMode.NotRegister || registerMode == EnumRegisterMode.AutoRegister){

                     registerMode = value ? EnumRegisterMode.AutoRegister : EnumRegisterMode.NotRegister;

                }

            }

        }

 

        public bool HasRegistered{

            get{

                return registerMode == EnumRegisterMode.AlreadyRegister;

            }

        }

 

        public void Load(){

            if(State != EnumObjectState.Initial){

                return;

            }

 

            if(registerMode == EnumRegisterMode.AutoRegister){

                ModuleManager.Instance.Register(this);    //立钻哥哥:register

                registerMode = EnumRegisterMode.AlreadyRegister;

            }

 

            OnLoad();

            State = EnumObjectState.Ready;

        }

 

        protected virtual void OnLoad(){

        }

 

        public void Release(){

            if(State != EnumObjectState.Disabled){

                State = EnumObjectState.Disabled;

 

                if(registerMode == EnumRegisterMode.AlreadyRegister){

                    ModuleManager.Instance.UnRegister(this);    //立钻哥哥:unregister

                    registerMode = EnumRegisterMode.AutoRegister;

                }

 

                OnRelease();

            }

        }

 

        protected virtual void OnRelease(){

        }

 

    }    //立钻哥哥:public class BaseModule{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.9BaseScene.cs

###2.9BaseScene.cs

++2.9Scripts/YanlzUIFramework/BaseClass/BaseScene.cs

++++namespace YanlzUIFramework{}

++++public class BaseScene : BaseModule{}

++++protected List<BaseActor> actorList = null;

++++public BaseScene(){}

++++public void AddActor(BaseActor actor){}

++++public void RemoveActor(BaseActor actor){}

++++public virtual BaseActor GetActorByID(int id){}

++++protected void OnActorPropertyChanged(BaseActor actor, int id, object oldValue, object newValue){}


++2.9.1BaseScene.cs

//立钻哥哥:场景基类(YanlzUIFramework/BaseClass/BaseScene.cs

using System;

using System.Collection.Generic;

 

namespace YanlzUIFramework{

    public class BaseScene : BaseModule{

        protected List<BaseActor> actorList = null;

    

        public BaseScene(){

            actorList = new List<BaseActor>();

        }

 

        public void AddActor(BaseActor actor){

            if(null != actor && !actorList.Contains(actor)){

                actorList.Add(actor);

                actor.CurrentScene = this;

                actor.PropertyChanged += OnActorPropertyChanged;

            }

        }

 

        public void RemoveActor(BaseActor actor){

            if(null != actor && actorList.Contains(actor)){

                actorList.Remove(actor);

                actor.PropertyChanged -= OnActorPropertyChanged;

                actor = null;

            }

        }

 

        public virtual BaseActor GetActorByID(int id){

            if(null != actorList && actorList.Count > 0){

                for(int i = 0;  i < actorList.Count;  i++){

                    if(actorList[i].ID == id){

                        return actorList[i];

                    }

                }

            }

 

            return null;

        }

 

        protected void OnActorPropertyChanged(BaseActor actor, int id, object oldValue, object newValue){

        }

 

    }    //立钻哥哥:public class BaseScene : BaseModule{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.10BaseUI.cs

###2.10BaseUI.cs

++2.10Scripts/YanlzUIFramework/BaseClass/BaseUI.cs

++++namespace YanlzUIFramework{}

++++public abstract class BaseUI : MonoBehaviour{}

++++private Transform _CachedTransform;

++++public Transform cachedTransfor{}

++++private GameObject _CachedGameObject;

++++public GameObject cachedGameObject{};

++++protected EnumObjectState state = EnumObjectState.None;

++++public event StateChangedEvent StateChanged;

++++public EnumObjectState State{}

++++public abstract EnumUIType GetUIType();

++++protected virtual void SetDepthToTop(){}

++++void Start(){}

++++void Awake(){}

++++void Update(){}

++++public void Release(){}

++++protected virtual void OnStart(){}

++++protected virtual void OnUpdate(float deltaTime){}

++++protected virtual void OnRelease(){}

++++protected virtual void OnPlayOpenUIAudio(){}

++++protected virtual void OnPlayCloseUIAudio(){}

++++protected virtual void SetUI(params object[] uiParams){}

++++public virtual void SetUIparam(params object[] uiParams){}

++++protected virtual void OnLoadData(){}

++++public void SetUIWhenOpening(param object[] uiParams){}

++++private IEnumerator AsyncOnLoadData(){}


++2.10.1BaseUI.cs

//立钻哥哥:UI公共基类(YanlzUIFramework/BaseClass/BaseUI.cs

using UnityEngine;

using System.Collections;

 

namespace YanlzUIFramework{

    public abstract class BaseUI : MonoBehaviour{

        #region Cache gameObject & transform

        private Transform _CachedTransform;

        public Transform cachedTransform{

            get{

                if(!_CachedTransform){

                    _CachedTransform = this.transform;

                }

                return _CachedTransform;

            }

        }

 

        private GameObject _CachedGameObject;

        public GameObject cachedGameObject{

            get{

                if(!_CachedGameObject){

                    _CachedGameObject = this.gameObject;

                }

                return _CachedGameObject;

            }

        }

        #endregion

 

        #region UIType & EnumObjectState

        protected EnumObjectState state = EnumObjectState.None;

 

        public event StateChangedEvent StateChanged;

 

        public EnumObjectState State{

            protected set{

                if(value != state){

                    EnumObjectState oldState = state;

                    state = value;

                    if(null != StateChanged){

                        StateChanged(this, state, oldState);

                    }

                }

            }

 

            get{

                return this.state;

            }

        }

 

        public abstract EnumType GetUIType();

        #endregion

 

        protected virtual void SetDepthToTop(){

        }

 

        //Use this for initialization

        void Start(){

            OnStart();

        }

 

        void Awake(){

            this.State = EnumObjectState.Initial;

            OnAwake();

        }

 

        //Update is called once per frame

        void Update(){

            if(EnumObjectState.Ready == this.state){

                OnUpdate(Time.deltaTime);

            }

        }

 

        public void Release(){

            this.State = EnumObjectState.Closing;

            GameObject.Destroy(cachedGameObject);

            OnRelease();

        }

 

        protected virtual void OnStart(){

        }

 

        protected virtual void OnAwake(){

            this.State = EnumObjectState.Loading;

            this.OnPlayOpenUIAudio();    //立钻哥哥:播放音乐

        }

 

        protected virtual void OnUpdate(float deltaTime){

        }

 

        protected virtual void OnRelease(){

            this.OnPlayCloseUIAudio();

        }

 

        //立钻哥哥:播放打开界面音乐

        protected virtual void OnPlayOpenUIAudio(){

        }

 

        //立钻哥哥:播放关闭界面音乐

        protected virtual void OnPlayCloseUIAudio(){

        }

 

        protected virtual void SetUI(params object[] uiParams){

            this.State = EnumObjectState.Loading;

        }

 

        public virtual void SetUIparams(params object[] uiParams){

        }

 

        protected virtual void OnLoadData(){

        }

 

        public void SetUIWhenOpening(params object[] uiParams){

            SetUI(uiParams);

            CoroutineController.Instance.StartCoroutine(AsyncOnLoadData());

        }

 

        private IEnumerator AsyncOnLoadData(){

            yield return new WaitForSeconds(0);

            if(this.State == EnumObjectState.Loading){

                this.OnLoadData();

                this.State = EnumObjectState.Ready;

            }

        }

 

    }    //立钻哥哥:public abstract class BaseUI : MonoBehaviour{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.11PropertyItem.cs

###2.11PropertyItem.cs

++2.11Scripts/YanlzUIFramework/BaseClass/PropertyItem.cs

++++namespace YanlzUIFramework{}

++++public class PropertyItem{}

++++public int ID{}

++++private object content;

++++private object rawContent;

++++private bool canRandom = false;

++++private int curRandomInt;

++++private float curRandomFloat;

++++private Type propertyType;

++++public IDynamicProperty Owner = null;

++++public object Content{}

++++public void SetValueWithoutEvent(object content){}

++++public object RawContent{}

++++public PropertyItem(int id, object content){}

++++private void SetContent(object content){}

++++private object GetContent(){}


++2.11.1PropertyItem.cs

//立钻哥哥:属性类(YanlzUIFramework/BaseClass/PropertyItem.cs

using System;

 

namespace YanlzUIFramework{

    public class PropertyItem{

        public int ID{  get;    set;  }

        private object content;

        private object rawContent;

        private bool canRandom = false;

        private int curRandomInt;

        private float curRandomFloat;

        private Type propertyType;

        public IDynamicProperty Owner = null;

 

        public object Content{

            get{

                return GetContent();

            }

 

            set{

                if(value != GetContent()){

                    object oldCount = GetContent();

                    SetContent(value);

                    if(Owner != null){

                        Owner.DoChangeProperty(ID, oldContent, value);

                    }

                }

            }

        }

 

        public void SetValueWithoutEvent(object content){

            if(content != GetContent()){

                object oldContent = GetContent();

                SetContent(content);

            }

        }

 

        public object RawContent{

            get{  return rawContent;  }

        }

 

        public PropertyItem(int id, object content){

            propertyType = content.GetType();

            if(propertyType == typeof(System.Int32) || propertyType == typeof(System.Single)){

                canRandom = true;

            }

 

            ID = id;

            SetContent(content);

        }

 

        private void SetContent(object content){

            rawContent = content;

            if(canRandom){

                if(propertyType == typeof(System.Int32)){

                    curRandomInt = UnityEngine.Random.Range(1, 1000);

                    this.content = (int)content + curRandomInt;

                }else if(propertyType == typeof(System.Single)){

                    curRandomFloat = UnityEngine.Random.Range(1.0f, 1000.0f);

                    this.content = (float)content + curRandomFloat;

                }

            }else{

                this.content = content;

            }

        }

 

        private object GetContent(){

            if(canRandom){

                if(propertyType == typeof(System.Int32)){

                    int ret = (int)this.content - curRandomInt;

                    if((object)ret != rawContent){

                        Message message = new Message(“PropertyItemDataException”, this, ID);

                        message.Send();

                    }

 

                    return ret;

 

                }else if(propertyType == typeof(System.Single)){

                    float ret = (float)this.content - curRandomFloat;

                    if((object)ret != rawContent){

                        Message message = new Message(“PropertyItemDataException”, this, ID);

                        message.Send();

                    }

 

                    return ret;

                }

            }

 

            return this.content;

        }

 

    }    //立钻哥哥:public class PropertyItem{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.12MethodExtension.cs

###2.12MethodExtension.cs

++2.12Scripts/YanlzUIFramework/Common/Extended/MethodExtension.cs

++++namespace YanlzUIFramework{}

++++static public class MethodExtension{}

++++static public T GetOrAddCompoent<T>(this GameObject go) where T : Component{}


++2.12.1MethodExtension.cs

//立钻哥哥:方法扩展(YanlzUIFramework/Common/Extended/MethodExtension.cs

using System;

using UnityEngine;

 

namespace YanlzUIFramework{

    static public T GetOrAddComponent<T>(this GameObject go) where T : Component{

        T ret = go.GetComponent<T>();

        if(null == ret){

            ret = go.AddComponent<T>();

        }

 

        return ret;

    }

}




###2.13Message.cs

###2.13Message.cs

++2.13Scripts/YanlzUIFramework/Common/Message/Message.cs

++++namespace YanlzUIFramework{}

++++public class Message : IEnumerable<KeyValuePair<string, object>>{}

++++private Dictionary<string, object> dicDatas = null;

++++public string Name{}

++++public object Sender{}

++++public object Content{}

++++public object this[string key]{}

++++public IEnumerator<KeyValuePair<string, object>> GetEnumerator(){}

++++IEnumerator IEnumerable.GetEnumerator(){}

++++public Message(string name, object sender){}

++++public Message(string name, object sender, object content){}

++++public Message(string name, object sender, object content, params object[] _dicParams){}

++++public Message(Message message){}

++++public void Add(string key, object value){}

++++public void Remove(string key){}

++++public void Send(){}


++2.13.1Message.cs

//立钻哥哥:消息(YanlzUIFramework/Common/Message/Message.cs

using System;

using System.Collections;

using System.Collections.Generic;

 

namespace YanlzUIFramework{

    public class Message : IEnumerable<KeyValuePair<string, object>>{

        private Dictionary<string, object> dicDatas = null;

 

        public string Name{  get;    private set;  }

        public object Sender{  get;    private set;  }

        public object Content{  get;    set;  }

 

        #region message[key] = value or data = message[key]

        public object this[string key]{

            get{

                if(null == dicDatas || !dicDatas.ContainsKey(key)){

                    return null;

                }

 

               return dicDatas[key];

           }

 

            set{

                if(null == dicDatas){

                    dicDatas = new Dictionary<string, object>();

                }

 

                if(dicDatas.ContainsKey(key)){

                    dicDatas[key] = value;

                }else{

                    dicDatas.Add(key, value);

                }

            }

        }

        #endregion

 

        #region IEnumerable implementation

        public IEnumerator<KeyValuePair<string, object>> GetEnumerator(){

            if(null == dicDatas){

                yield break;

            }

 

            foreach(KeyValuePair<string, object> kvp in dicDatas){

                yield return kvp;

            }

        }

        #endregion

 

        #region IEnumerable implementation

        IEnumerator IEnumerable.GetEnumerator(){

            return dicDatas.GetEnumerator();

        }

        #endregion

 

        #region Message Construction Function

        public Message(string name, object sender){

            Name = name;

            Sender = sender;

            Content = null;

        }

 

        public Message(string name, object sender, object content){

            Name = name;

            Sender = sender;

            Content = content;

        }

 

        public Message(string name, object sender, object content, params object[] _dicParams){

            Name = name;

            Sender = sender;

            Content = content;

 

            if(_dicParams.GetType() == typeof(Dictionary<string, object>)){

                foreach(object _dicParam in _dicParams){

                    foreach(KeyValuePair<string, object> kvp in _dicParam as Dictionary<string, object>){

                        //dicDatas[kvp.Key] = kvp.Value;    //立钻哥哥:error

                        this[kvp.Key] = kvp.Value;

                    }

                }

            }

        }

 

        public Message(Message message){

            Name = message.Name;

            Sender = message.Sender;

            Content = message.Content;

 

            foreach(KeyValuePair<string, object> kvp in message.dicDatas){

                this[kvp.Key] = kvp.Value;

            }

        }

        #endregion

 

        #region Add & Remove

        public void Add(string key, object value){

            this[key] = value;

        }

 

        public void Remove(string key){

            if(null != dicDatas && dicDatas.ContainsKey(key)){

                dicDatas.Remove(key);

            }

        }

        #endregion

 

        #region Send()

        public void Send(){

            MessageCenter.Instance.SendMessage(this);

        }

        #endregion

 

    }    //立钻哥哥:public class Message : IEnumerable>{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.14MessageCenter.cs

###2.14MessageCenter.cs

++2.14Scripts/YanlzUIFramework/Common/Message/MessageCenter.cs

++++namespace YanlzUIFramework{}

++++public class MessageCenter : Singleton<MessageCenter>{}

++++private Dictionary<string, List<MessageEvent>> dicMessageEvents = null;

++++public override void Init(){}

++++public void AddListener(string messageName, MessageEvent messageEvent){}

++++public void RemoveListener(string messageName, MessageEvent messageEvent){}

++++public void RemoveAllListener(){}

++++public void SendMessage(Message message){}

++++public void SendMessage(string name, object sender){}

++++public void SendMessage(stirng name, object sender, object content){}

++++public void SendMessage(string name, object sender, object content, param object[] dicParams){}

++++private void DoMessageDispatcher(Message message){}


++2.14.1MessageCenter.cs

//立钻哥哥:消息中心(YanlzUIFramework/Common/Message/MessageCenter.cs

using System;

using System.Collections.Generic;

using UnityEngine;

 

namespace YanlzUIFramework{

    public class MessageCenter : Singleton<MessageCenter>{

        private Dictionary<string, List<MessageEvent>> dicMessageEvents = null;

    

        public override void Init(){

            dicMessageEvents = new Dictionary<string, List<MessageEvent>>();

        }

 

        #region Add & Remove Listener

        public void AddListener(string messageName, MessageEvent messageEvent){

            Debug.Log(立钻哥哥:AddListener Name:  + messageName);

            List<MessageEvent> list = null;

 

            if(dicMessageEvents.ContainsKey(messageName)){

                list = dicMessageEvents[messageName];

            }else{

                list = new List<MessageEvent>();

               dicMessageEvents.Add(messageName, list);

            }

 

            //立钻哥哥:no same messageEvent then add

            if(!list.Contains(messageEvent)){

                list.Add(messageEvent);

            }

        }

 

        public void RemoveListener(string messageName, MessageEvent messageEvent){

            Debug.Log(立钻哥哥:RemoveListener Name:  + messageName);

 

            if(dicMessageEvents.ContainsKey(messageName)){

                List<MessageEvent> list = dicMessageEvents[messageName];

                if(list.Contains(messageEvent)){

                    list.Remove(messageEvent);

                }

 

                if(list.Count <= 0){

                    dicMessageEvents.Remove(messageName);

                }

            }

        }

 

        public void RemoveAllListener(){

            dicMessageEvents.Clear();

        }

        #endregion

 

        #region Send Message

        public void SendMessage(Message message){

            DoMessageDispatcher(message);

        }

 

        public void SendMessage(string name, object sender){

            SendMessage(new Message(name, sender));

        }

 

        public void SendMessage(string name, object sender, object content){

            SendMessage(new Message(name, sender, content));

        }

 

        public void SendMessage(string name, object sender, object content, params object[] dicParams){

            SendMessage(new Message(name, sender, content, dicParams));

        }

 

        private void DoMessageDispatcher(){

            Debug.Log(立钻哥哥:DoMessageDispatcher Name: + message.Name);

 

            if(dicMessageEvents == null || dicMessageEvents.ContainsKey(message.Name)){

                return;

             }

 

            List<MessageEvent> list = dicMessageEvents[message.Name];

            for(int i = 0;  i < list.Count;  i++){

                MessageEvent messageEvent = list[i];

                if(null != messageEvent){

                    messageEvent(message);

                }

            }

        }

        #endregion

 

    }    //立钻哥哥:public class MessageCenter : Singleton{}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.15MessageType.cs

###2.15MessageType.cs

++2.15Scripts/YanlzUIFramework/Common/Message/MessageType.cs

++++namespace YanlzUIFramework{}

++++public class MessageType{}

++++public static string Net_MessageTestOne = Net_MessageTestOne;

++++public static string Net_MessageTestTwo = Net_MessageTestTwo;


++2.15.1MessageType.cs

//立钻哥哥:消息类型(YanlzUIFramework/Common/Message/MessageType.cs

using System;

 

namespace YanlzUIFramework{

    public class MessageType{

        public static string Net_MessageTestOne = “Net_MessageTestOne”;

        public static string Net_MessageTestTwo = “Net_MessageTestTwo”;

    }

}




###2.16DDOLSingleton.cs

###2.16DDOLSingleton.cs

++2.16Scripts/YanlzUIFramework/Common/Singleton/DDOLSingleton.cs

++++public abstract class DDOLSingleton<T> : MonoBehaviour where T : DDOLSingleton<T>{}

++++protected static T _Instance = null;

++++public static T Instance{}

++++private void OnApplicationQuit(){}


++2.16.1DDOLSingleton.cs

//立钻哥哥:继承MonoBehaviour的单例基类(/Common/Singleton/DDOLSingleton.cs

using UnityEngine;

using System.Collections;

 

public abstract class DDOLSingleton<T> : MonoBehaviour where T : DDOLSingleton<T>{

    protected static T _Instance = null;

 

    public static T Instance{

        get{

            if(null == _Instance){

                GameObject go = GameObject.Find(“DDOLGameObject”);

                if(null == go){

                    go = new GameObject(“DDOLGameObject”);

                    DontDestroyOnLoad(go);

                }

 

                _Instance = go.AddComponent<T>();

            }

 

            return _Instance;

            }

        }

 

        private void OnApplicationQuit(){

            _Instance = null;

        }

 

}    //立钻哥哥:public abstract class DDOLSingleton : MonoBehaviour{}




###2.17Singleton.cs

###2.17Singleton.cs

++2.17Scripts/YanlzUIFramework/Common/Singleton/Singleton.cs

++++namespace YanlzUIFramework{}

++++public abstract class Singleton<T> where T : class, new(){}

++++protected static T _Instance = null;

++++public static T Instance{}

++++protected Singleton(){}

++++public virtual void Init(){}


++2.17.1Singleton.cs

//立钻哥哥:单例基类(YanlzUIFramework/Common/Singleton/Singleton.cs

using System;

using UnityEngine;

 

namespace YanlzUIFramework{

    #region Singleton<> first version

    public abstract class Singleton<T> where T : class, new(){

        public static readonly T Instance = new T();

        public virtual void Init(){}

    }

    #endregion

 

    #region Singleton<> second version

    public abstract class Singleton<T> where T : class, new(){

        protected static T _Instance = null;

    

        public static T Instance{

            get{

                if(null == _Instance){

                    _Instance = new T();

                }

 

                return _Instance;

            }

        }

 

        protected Singleton(){

            if(null != _Instance){

                throw new SingletonException(立钻哥哥:This ” + (typeof(T)).ToString() + “ Singleton Instance is not null!”);

 

                Init();

            }

        }

        #endregion

 

        public virtual void Init(){

        }

 

    }    //立钻哥哥:public abstract class Singleton where T : class, new(){}

}    //立钻哥哥:namespace YanlzUIFramework{}




###2.18SingletonException.cs

###2.18SingletonException.cs

++2.18Scripts/YanlzUIFramework/Common/Singleton/SingletonException.cs

++++namespace YanlzUIFramework{}

++++public class SingletonException : System.Exception{}

++++public SingletonException(string msg) : base(msg){}


++2.18.1SingletonException.cs

//立钻哥哥:异常类(YanlzUIFramework/Common/Singleton/SingletonException.cs

using System;

 

namespace YanlzUIFramework{

    public class SingletonException : System.Exception{

        public SingletonException(string msg) : base(msg){

        }

    }

}




###2.19EventTriggerListener.cs

###2.19EventTriggerListener.cs

++2.19Scripts/YanlzUIFramework/Common/Tools/EventTriggerListener.cs

++++namespace YanlzUIFramework{}

++++public class TouchHandle{}

++++private event OnTouchEventHandle eventHandle = null;

++++private object[] handleParams;

++++public TouchHandle(OnTouchEventHandle _handle, params object[] _params){}

++++public TouchHandle(){}

++++public void SetHandle(OnTouchEventHandle _handle, params object[] _params){}

++++public void CallEventHandle(GameObject _listener, object _args){}

++++public void DestroyHandle(){}

++++public class EventTriggerListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IUpdateSelectedHandler, IDeselectHandler, IDragHandler, IEndDragHandler, IDropHandler, IScrollHandler, IMoveHandler{}

++++static public EventTriggerListener Get(GameObject go){}

++++void OnDestroy(){}

++++private void RemoveAllHandle(){}

++++private void RemoveHandle(TouchHandle _handle){}

++++public void OnDrag(PointerEventData eventData){}

++++public void OnEndDrag(PointerEventData eventData){}

++++public void OnDrop(PointerEventData eventData){}

++++public void OnPointerClick(PointerEventData eventData){}

++++public void OnPointerDown(PointerEventData eventData){}

++++public void OnPointerUp(PointerEventData eventData){}

++++public void OnPointerEnter(PointerEventData eventData){}

++++public void OnPointerExit(PointerEventData eventData){}

++++public void OnSelect(BaseEventData eventData){}

++++public void OnUpdateSelected(BaseEventData eventData){}

++++public void OnDeselect(BaseEventData eventData){}

++++public void OnScroll(PointerEventData eventData){}

++++public void OnMove(AxisEventData eventData){}

++++public void SetEventHandle(EnumTouchEventType _type, OnTouchEventHandle _handle, params object[] _params){}


++2.19.1EventTriggerListener.cs

//立钻哥哥:事件监听(YanlzUIFramework/Common/Tools/EventTriggerListener.cs

using UnityEngine;

using System.Collections;

using UnityEngine.EventSystems;

 

namespace YanlzUIFramework{

    public class TouchHandle{

        private event OnTouchEventHandle eventHandle = null;

        private object[] handleParams;

 

        public TouchHandle(OnTouchEventHandle _handle, params object[] _params){

            SetHandle(_handle, _params);

        }

 

        public TouchHandle(){

        }

 

        public void SetHandle(OnTouchEventHandle _handle, params object[] _params){

            DestroyHandle();

            eventHandle += _handle;

            handleParams = _params;

        }

 

        public void CallEventHandle(GameObject _listener, object _args){

            if(null != eventHandle){

                eventHandle(_listener, _args, handleParams);

            }

        }

 

        public void DestroyHandle(){

            if(null != eventHandle){

                eventHandle -= eventHandle;

                eventHandle = null;

            }

        }

 

    }    //立钻哥哥:public class TouchHandle{}

 

    public class EventTriggerListener : MonoBehaviour,

        IPointerClickHandler,

        IPointerDownHandler,

        IPointerUpHandler,

        IPointerEnterHandler,

        IPointerExitHandler,

 

        ISelectHandler,

        IUpdateSelectedHandler,

        IDeselectHandler,

 

        IDragHandler,

        IEndDragHandler,

        IDropHandler,

        IScrollHandler,

        IMoveHandler{

 

        public TouchHandle onClick;

        public TouchHandle onDoubleClick;

        public TouchHandle onDown;

        public TouchHandle onEnter;

        public TouchHandle onExit;

        public TouchHandle onUp;

        public TouchHandle onSelect;

        public TouchHandle onUpdateSelect;

        public TouchHandle onDeSelect;

        public TouchHandle onUpdateSelect;

        public TouchHandle onDeSelect;

        public TouchHandle onDrag;

        public TouchHandle onDragEnd;

        public TouchHandle onDrop;

        public TouchHandle onScroll;

        public TouchHandle onMove;

 

        static public EventTriggerListener Get(GameObject go){

            return go.GetOrAddComponent<EventTriggerListener>()

        }

 

        void OnDestroy(){

            this.RemoveAllHandle();

        }

 

        private void RemoveAllHandle(){

            this.RemoveHandle(onClick);

            this.RemoveHandle(onDoubleClick);

            this.RemoveHandle(onDown);

            this.RemoveHandle(onEnter);

            this.RemoveHandle(onExit);

            this.RemoveHandle(onUp);

            this.RemoveHandle(onDrop);

            this.RemoveHandle(onDrag);

            this.RemoveHandle(onDragEnd);

            this.RemoveHandle(onScroll);

            this.RemoveHandle(onMove);

            this.RemoveHandle(onUpdateSelect);

            this.RemoveHandle(onSelect);

            this.RemoveHandle(onDeSelect);

        }

 

        private void RemoveHandle(TouchHandle _handle){

            if(null != _handle){

                _handle.DestroyHandle();

                _handle = null;

            }

        }

 

        #region IDragHandle implementation

        public void OnDrag(PointerEventData eventData){

            if(onDrag != null){

                onDrag.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IEndDragHandler implementation

        public void OnEndDrag(PointerEventData eventData){

            if(onDragEnd != null){

                onDragEnd.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IDropHandler implementation

        public void OnDrop(PointerEventData eventData){

            if(onDrop != null){

                onDrop.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IPointerClickHandler implementation

        public void OnPointerClick(PointerEventData eventData){

            if(onClick != null){

                onClick.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IPointerDownHandler implementation

        public void OnPointerDown(PointerEventData eventData){

            if(onDown != null){

                onDown.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IPointerUpHandler implementation

        public void OnPointerUp(PointerEventData eventData){

            if(onUp != null){

                onUp.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IPointerEnterHandle implementation

        public void OnPointerEnter(PointerEventData eventData){

            if(onEnter != null){

                onEnter.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IPointerExitHandle implementation

        public void OnPointerExit(PointerEventData eventData){

            if(onExit != null){

                onExit.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region ISelectHandler implementation

        public void OnSelect(BaseEventData eventData){

            if(onSelect != null){

                onSelect.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IUpdateSelectedHandler implementation

        public void OnUpdateSelected(BaseEventData eventData){

            if(onUpdateSelected != null){

                onUpdateSelect.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IDeselectHandler implementation

        public void OnDeselect(BaseEventData eventData){

            if(onDeSelect != null){

                onDeSelect.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IScrollHandler implementation

        public void OnScroll(PointerEventData eventData){

            if(onScroll != null){

                onScroll.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        #region IMoveHandler implementation

        public void OnMove(AxisEventData eventData){

            if(onMove != null){

                onMove.CallEventHandle(this.gameObject, eventData);

            }

        }

        #endregion

 

        public void SetEventHandle(EnumTouchEventType _type, OnTouchEventHandle _handle, params object[] _params){

                switch(_type){

                    case EnumTouchEventType.OnClick:{

                        if(null == onClick){

                            onClick = new TouchHandle();

                        }

                        onClick.SetHandle(_handle, _params);

                        break;

                    }

 

                     case EnumTouchEventType.OnDoubleClick:{

                         if(null == onDoubleClick){

                             onDoubleClick = new TouchHandle();

                         }

                        onDoubleClick.SetHandle(_handle, _params);

                        break;

                    }

 

                    case EnumTouchEventType.OnDown:{

                        if(onDown == null){

                            onDown = new TouchHandle();

                        }

                       onDown.SetHandle(_handle, _params);

                       break;

                   }

 

                    case EnumTouchEventType.OnUp:{

                         if(onUp == null){

                            onUp == new TouchHandle();

                        }

                        onUp.SetHandle(_handle, _params);

                        break;

                    }

 

                    case EnumTouchEventType.OnEnter:{

                        if(onEnter == null){

                            onEnter = new TouchHandle();

                        }

                        onEnter.SetHandle(_handle, _params);

                        break;

                    }

 

                    case EnumTouchEventType.OnExit:{

                         if(onExit == null){

                             onExit = new TouchHandle();

                         }

                         onExit.SetHandle(_handle, _params);

                         break;

                     }

 

                     case EnumTouchEventType.OnDrag:{

                          if(onDrag == null){

                              onDrag = new TouchHandle();

                          }

                         onDrag.SetHandle(_handle, _params);

                         break;

                     }

 

                     case EnumTouchEventType.OnDragEnd:{

                         if(onDragEnd == null){

                             onDragEnd = new TouchHandle();

                         }

                         onDragEnd.SetHandle(_handle, _params);

                         break;

                     }

 

                     case EnumTouchEventType.OnSelect:{

                          if(onSelect == null){

                             onSelect = new TouchHandle();

                         }

                         onSelect.SetHandle(_handle, _params);

                         break;

                     }

 

                    case EnumTouchEventType.OnUpdateSelect:{

                         if(onUpdateSelect == null){

                             onUpdateSelect = new TouchHandle();

                         }

                         onUpdateSelect.SetHandle(_handle, _params);

                         break;

                     }

 

                    case EnumTouchEventType.OnDeSelect:{

                         if(onDeSelect == null){

                             onDeSelect = new TouchHandle();

                         }

                         onDeSelect.SetHandle(_handle, _params);

                         break;

                     }

 

                    case EnumTouchEventType.OnScroll:{

                         if(onScroll == null){

                            onScroll = new TouchHandle();

                        }

                       onScroll.SetHandle(_handle, _params);

                       break;

                   }

 

                    case EnumTouchEventType.OnMove:{

                         if(onMove == null){

                            onMove = new TouchHandle();

                        }

                        onMove.SetHandle(_handle, _params);

                        break;

                    }

 

            }

        }

 

    }    //立钻哥哥:public class EventTriggerListener : MonBehaviour,...{}

}    //立钻哥哥:namespace YanlzUIFramework{}





###2.20Defines.cs

###2.20Defines.cs

++2.20Scripts/YanlzUIFramework/Defines/Defines.cs

++++namespace YanlzUIFramework{}

++++public delegate void StateChangedEvent(object sender, EnumOjbectState newState, EnumObjectState oldState);

++++public delegate void MessageEvent(Message message);

++++public delegate void OnTouchEventHandle(GameObject _listener, object _args, params object[] _params);

++++public delegate void PropertyChangedHandle(BaseActor actor, int id, object oldValue, object newValue);

++++public enum EnumObjectState{}

++++public enum EnumUIType : int{}

++++public enum EnumTouchEventType{}

++++public enum EnumPropertyType : int{}

++++public enum EnumActorType{}

++++public enum EnumSceneType{}

++++public static class UIPathDefines{}

++++public class Defines : MonoBehaviour{}


++2.20.1Defines

//立钻哥哥:自定义空间和类(YanlzUIFramework/Defines/Defines.cs

using UnityEngine;

using System.Collections;

 

namespace YanlzUIFramework{

    #region Global delegate 委托

    public delegate void StateChangedEvent(object sender, EnumObjectState newState, EnumObjectState oldState);

    public delegate void MessageEvent(Message message);

    public delegate void OnTouchEventHandle(GameObject _listener, object _args, params object[] _params);

    public delegate void PropertyChangedHandle(BaseActor actor, int id, object oldValue, object newValue);

    #endregion

 

    #region Global enum枚举

 

    //立钻哥哥:对象当前状态

    public enum EnumObjectState{

        None,

        Initial,

        Loading,

        Ready,

        Disabled,

        Closing

    }

 

    //立钻哥哥:UI面板类型

    public enum EnumUIType : int{

        None = -1,

        TestOne,

        TestTwo,

    }

 

    public enum EnumTouchEventType{

        OnClick,

        OnDoubleClick,

        OnDown,

        OnUp,

        OnEnter,

        OnExit,

        OnSelect,

        OnUpdateSelect,

        OnDeSelect,

        OnDrag,

        OnDragEnd,

        OnDrop,

        OnScroll,

        OnMove,

    }

 

    public enum EnumPropertyType : int{

        RoleName = 1,    //立钻哥哥:角色名

        Sex,    //性别

        RoleID,    //Role ID

        Gold,    //宝石(元宝)

        Coin,    //金币(铜板)

        Level,    //等级

        Exp,    //当前经验

 

        AttackSpeed,    //立钻哥哥:攻击速度

        HP,    //当前HP

        HPMax,    //生命最大值

        Attack,    //普通攻击(点数)

        Water,    //水系攻击(点数)

        Fire,    //火系攻击(点数)

    }

 

    public enum EnumActorType{

        None = 0,

        Role,

        Monster,

        NPC,

    }

 

    public enum EnumSceneType{

        None = 0,

        StartGame,

        LoadingScene,

        MainScene,

        CopyScene,

        PVPScene,

        PVEScene,

    }

 

    #endregion

 

    #region Defines static class & const

 

    //立钻哥哥:路径定义

    public static class UIPathDefines{

        public const string UI_PREFAB = “Prefabs/”;    //立钻哥哥:UI预设

        public const string UI_CONTROLS_PREFABS = “UIPrefab/Control/”;  //UI小控件预设

        public const string UI_SUBUI_PREFAB = “UIPrefab/SubUI/”;    //UI子页面预设

        public const string UI_IOCN_PATH = “UI/Icon/”;    //icon路径

    

        public static string GetPrefabPathByType(EnumType _uiType){

            string _path = string.Empty;

            switch(_uiType){

                case EnumUIType.TestOne:{

                    _path = UI_PREFAB + “TestUIOne”;

                    break;

                }

 

                case EnumUIType.TestTwo:{

                     _path = UI_PREFAB + “TestUITwo”;

                    break;

                }

 

                default:{

                    Debug.Log(立钻哥哥:Not Find EnumUIType! Type:  + _uiType.ToString());

                }

            }

 

            return _path;

        }

 

        public static System.Type GetUIScriptByType(EnumUIType _uiType){

            System.Type _scriptType = null;

    

            switch(_uiType){

                case EnumUIType.TestOne:{

                    _scriptType = typeof(TestOne);

                    break;

                }

 

                case EnumUIType.TestTwo:{

                    _scriptType = typeof(TestTwo);

                    break;

                }

 

                default:{

                    Debug.Log(立钻哥哥:Not Find EnumUIType! Type:  + _uiType.ToString());

                    break;

                }

            }

 

            return _scriptType;

        }

 

    }    //立钻哥哥:public static class UIPathDefines

 

    #endregion

 

    public class Defines : MonoBehaviour{

         //Use this for initialization

        void Start(){

        }

 

        //Update is called once per frame

        void Update(){

        }

 

    }    //立钻哥哥:public class Defines : MonoBehaviour{}

 

}    //立钻哥哥:namespace YanlzUIFramework{}





###2.21IDynamicProperty.cs

###2.21IDynamicProperty.cs

++2.21Scripts/YanlzUIFramework/Interface/IDynamicProperty.cs

++++namespace YanlzUIFramework{}

++++public interface IDynamicProperty{}

++++void DoChangeProperty(int id, object oldValue, object newValue);

++++PropertyItem GetProperty(int id);


++2.21.1IDynamicProperty.cs

//立钻哥哥:属性接口(YanlzUIFramework/Interface/IDynamicProperty.cs

using System;

 

namespace YanlzUIFramework{

    public interface IDynamicProperty{

        void DoChangeProperty(int id, object oldValue, object newValue);

        PropertyItem GetProperty(int id);

    }

}





###2.22Interface.cs

###2.22Interface.cs

++2.22Scripts/YanlzUIFramework/Interface/Interface.cs

++++public class Interface : MonoBehaviour{}

++++void Start(){}

++++void Update(){}


++2.22.1Interface.cs

//立钻哥哥:接口(YanlzUIFramework/Interface/Interface.cs

using UnityEngine;

using System.Collections;

 

public class Interface : MonoBehaviour{

    //Use this for initialization

    void Start(){

    }

 

    //Update is called once per frame

    void Update(){

    }

}





###2.23CoroutineController.cs

###2.23CoroutineController.cs

++2.23Scripts/YanlzUIFramework/Manager/CoroutineController.cs

++++namespace YanlzUIFramework{}

++++public class CoroutineController : DDOLSingleton<CoroutineController>{}


++2.23.1CoroutineController.cs

//立钻哥哥:协程管理器(YanlzUIFramework/Manager/CoroutineController.cs

using UnityEngine;

using System.Collections;

 

namespace YanlzUIFramework{

    public class CoroutineController : DDOLSingleton<CoroutineController>{

    }

}





###2.24ModuleManager.cs

###2.24ModuleManager.cs

++2.24Scripts/YanlzUIFramework/Manager/ModuleManager.cs

++++namespace YanlzUIFramework{}

++++public class ModuleManager : Singleton<ModuleManager>{}

++++private Dictionary<string, BaseModule> dicModules = null;

++++public override void Init(){}

++++public BaseModule Get(string key){}

++++public T Get<T>() where T : BaseModule{}

++++public void RegisterAllModules(){}

++++private void LoadModule(Type moduleType);

++++public void Register(BaseModule module){}

++++public void Register(string key, BaseModule module);

++++public void UnRegister(BaseModule module);

++++public void UnRegister(string key);

++++public void UnRegisterAll(){}


++2.24.1ModuleManager.cs

//立钻哥哥:模块管理器(YanlzUIFramework/Manager/ModuleManager.cs

using System;

using System.Collections.Generic;

 

namespace YanlzUIFramework{

    public class ModuleManager : Singleton<MouduleManager>{

        private Dictionary<string, BaseModule> dicModules = null;

    

        public override void Init(){

            dicModules = new Dictionary<string, BaseModule>();

        }

 

        #region Get Module

        public BaseModule Get(string key){

            if(dicModules.ContainsKey(key)){

                return dicModules[key];

            }

 

            return null;

        }

 

        public T Get<T>() where T : BaseModule{

            Type t = typeof(T);

 

            if(dicModules.ContainsKey(t.ToString())){

                return dicModules[t.ToString()] as T;

            }

 

            return null;

        }

        #endregion

 

        public void RegisterAllModules(){

            LoadModule(typeof(TestOneModule));

            //LoadModule(typeof(MailModule));

        }

 

        private void LoadModule(Type moduleType){

            BaseModule bm = System.Activator.CreateInstance(moduleType) as BaseModule;

            bm.Load();

        }

 

        #region Register Module By Module Type

        public void Register(BaseModule module){

            Type t = module.GetType();

            Register(t.ToString(), module);

        }

 

        public void Register(string key, BaseModule module){

            if(!dicModules.ContainsKey(key)){

                dicModules.Add(key, module);

            }

        }

        #endregion

 

        #region Un Register Module

        public void UnRegister(BaseModule module){

            Type t = module.GetType();

            UnRegister(t.ToString());

        }

 

        public void UnRegister(string key){

            if(dicModules.ContainsKey(key)){

                BaseModule module = dicModules[key];

                module.Release();

                dicModules.Remove(key);

                module = null;

            }

        }

 

        public void UnRegisterAll(){

            List<string> _keyList = new List<string>(dicModules.Keys);

            for(int i = 0;  i < _keyList.Count;  i++){

                UnRegister(_keyList[i]);

            }

            dicModules.Clear();

        }

        #endregion

 

    }    //立钻哥哥:public class ModuleManager : Singleton{}

}    //立钻哥哥:namespace YanlzUIFramework{}





###2.25ResManager.cs

###2.25ResManager.cs

++2.25Scripts/YanlzUIFramework/Manager/ResManager.cs

++++namespace YanlzUIFramework{}

++++public class AssetInfo{}

++++private UnityEngine.Object _Object;

++++public Type AssetType{}

++++public string Path{}

++++public int RefCount{}

++++public bool IsLoaded{}

++++public UnityEngine.Object AssetObject{}

++++public IEnumerator GetCoroutineObject(Action<UnityEngine.Object> _loaded){}

++++private void _ResourcesLoad(){}

++++public IEnumerator GetAsyncObject(Action<UnityEngine.Object> _loaded){}

++++public IEnumerator GetAsyncObject(Action<UnityEngine.Object> _loaded, Action<float> _progress){}

++++public class ResManager : Singleton<ResManager>{}

++++private Dictionary<string, AssetInfo> dicAssetInfo = null;

++++public override void Init(){}

++++public UnityEngine.Object LoadInstance(string _path){}

++++public void LoadCoroutineInstance(string _path, Action<UnityEngine.Object> _loaded){}

++++public void LoadAsyncInstance(string _path, Action<UnityEngine.Object> _loaded){}

++++public void LoadAsyncInstance(string _path, Action<UnityEngine.Object> _loaded, Action<float> _progress){}

++++public UnityEngine.Object Load(string _path){}

++++public void LoadCoroutine(string _path, Action<UnityEngine.Object> _loaded);

++++public void LoadAsync(string _path, Action<UnityEngine.Object> _loaded){}

++++public void LoadAsync(string _path, Action<UnityEngine.Object> _loaded, Action<float> _progress){}

++++private AssetInfo GetAssetInfo(string _path){}

++++private AssetInfo GetAssetInfo(string _path, Action<UnityEngine.Object> _loaded){}

++++private UnityEngine.Object Instantiate(UnityEngine.Object obj){}

++++private UnityEngine.Object Instantiate(UnityEngine.Object _obj, Action<UnityEngine.Object> _loaded){}


++2.25.1ResManager.cs

//立钻哥哥:资源管理器(YanlzFramework/Manager/ResManager.cs

using System;

using UnityEngine;

using System.Collections.Generic;

using System.Collections;

 

namespace YanlzUIFramework{

    public class AssetInfo{

        private UnityEngine.Object _Object;

        public Type AssetType{  get;    set;  }

        public string Path{  get;    set;  }

        public int RefCount{  get;    set;  }

    

        public bool IsLoaded{

            get{

                return null != _Object;

            }

        }

 

        public UnityEngine.Object AssetObject{

            get{

                if(null == _Object){

                    _ResourcesLoad();

                }

 

                return _Object;

            }

        }

 

        public IEnumerator GetCoroutineObject(Action<UnityEngine.object> _loaded){

            while(true){

                yield return null;

 

                if(null == _Object){

                    _ResourcesLoad();

                    yield return null;

                }

 

                if(null != _loaded){

                     _loaded(_Object);

                 }

 

                yield break;

            }

        }

 

         private void _ResourcesLoad(){

            try{

                _Object = Resources.Load(path);

                if(null == _Object){

                    Debug.Log(立钻哥哥:Resources Load Failure! Path:  + Path);

                }

            }catch(Exception e){

               Debug.LogError(e.ToString());

           }

        }

 

        public IEnumerator GetAsyncObject(Action<UnityEngine.Object> _loaded){

            return GetAsyncObject(_loaded, null);

        }

 

        public IEnumerator GetAsyncObject(Action<UnityEngine.Object> _loaded, Action<float> _progress){

            //立钻哥哥:have Object

            if(null != _Object){

                _loaded(_Object);

                yield break;

            }

 

            //Object null. Not Load Resources

            ResourceRequest _resRequest = Resource.LoadAsync(Path);

 

            while(_resRequest.progress < 0.9){

                if(null != _progress){

                    _progress(_resRequest.progress);

                }

 

                yield return null;

            }

 

            while(!_resRequest.isDone){

                if(null != _progress){

                    _progress(_resRequest.progress);

                }

 

                yield return null;

            }

 

            //立钻哥哥:???

            _Object = _resRequest.asset;

            if(null != _loaded){

                _loaded(_Object);

            }

 

            yield return _resRequest;

        }

 

    }    //立钻哥哥:public class AssetInfo{}

 

    public class ResManager : Singleton<ResManager>{

        private Dictionary<string, AssetInfo> dicAssetInfo = null;

 

        public override void Init(){

            dicAssetInfo = new Dictionary<string, AssetInfo>();

        }

 

        #region Load Resources & Instantiate Object

        public UnityEngine.Object LoadInstance(string _path){

            UnityEngine.Object _obj = Load(_path);

            return Instantiate(_obj);

        }

 

        public void LoadCoroutineInstance(string _path, Action<UnityEngine.Object> _loaded){

            LoadCoroutine(_path, (_obj)=>{  Instantiate(_obj, _loaded);  });

        }

 

        public void LoadAsyncInstance(string _path, Action<UnityEngine.Object> _loaded){

            LoadAsync(_path, (_obj)=>{  Instantiate(_obj, _loaded);  });

        }

 

        public void LoadAsyncInstance(string _path, Action<UnityEngine.Object> _loaded, Action<float> _progress){

            LoadAsync(_path, (_obj)=>{  Instantiate(_obj, _loaded);  },  _progress);

        }

 

        #endregion

 

        #region Load Resources

        public UnityEngine.Object Load(string _path){

            AssetInfo _assetInfo = GetAssetInfo(_path);

            if(null != assetInfo){

                return _assetInfo.AssetObject;

            }

 

            return null;

        }

        #endregion

 

        #region Load Coroutine Resources

        public void LoadCoroutine(string _path, Action<UnityEngine.Object> _loaded){

            AssetInfo _assetInfo = GetAssetInfo(_path, _loaded);

            if(null != _assetInfo){

                CoroutineController.Instance.StartCoroutine(_assetInfo.GetCoroutineObject(_loaded));

            }

        }

        #endregion

 

        #region Load Async Resources

        public void LoadAsync(string _path, Action<UnityEngine.Object> _loaded){

            LoadAsync(_path, _loaded, null);

        }

 

        public void LoadAsync(string _path, Action<UnityEngine.Object> _loaded, Action<float> _progress){

            AssetInfo _assetInfo = GetAssetInfo(_path, _loaded);

            if(null != _assetInfo){

                CoroutineController.Instance.StartCoroutine(_assetInfo.GetAsyncObject(_loaded, _progress));

            }

        }

        #endregion

 

        #region GetAssetInfo & Instantiate Object

        private AssetInfo GetAssetInfo(string _path){

            return GetAssetInfo(_path, null);

        }

 

        private AssetInfo GetAssetInfo(string _path, Action<UnityEngine.Object> _loaded){

            if(string.IsNullOrEmpty(_path)){

                Debug.LogError(立钻哥哥:Error: null _path name.);

                if(null != _loaded){

                    _loaded(null);

                }

            }

 

            //立钻哥哥:Load Res ...

           AssetInfo _assetInfo = null;

           if(!dicAssetInfo.TryGetValue(_path, out _assetInfo)){

               _assetInfo = new AssetInfo();

               _assetInfo.Path = _path;

               dicAssetInfo.Add(_path, _assetInfo);

           }

           _assetInfo.RefCount++;

 

             return _assetInfo;

        }

 

        private UnityEngine.Object Instantiate(UnityEngine.Object _obj){

            return Instantiate(_obj, null);

        }

 

        private UnityEngine.Object Instantiate(UnityEngine.Object _obj, Action<UnityEngine.Object> _loaded){

            UnityEngine.Object _retObj = null;

 

            if(null != _retObj){

                _retObj = MonoBehaviour.Instantiate(_obj);

        

                if(null != _retObj){

                    if(null != _loaded){

                        _loaded(_retObj);

                        return null;

                    }

 

                    return _retObj;

 

                }else{

                   Debug.LogError(立钻哥哥:Error: null Instantiate _retObj.);

               }

 

            }else{

               Debug.LogError(立钻哥哥:Error: null Resources Load return _obj.);

            }

 

            return null;

        }

 

        #endregion

 

    }    //立钻哥哥:public class ResManager : Singleton{}

}    //立钻哥哥:namespace YanlzUIFramework{}





###2.26SceneManager.cs

###2.26SceneManager.cs

++2.26Scripts/YanlzUIFramework/Manager/SceneManager.cs

++++namespace YanlzUIFramework{}

++++public class SceneManager : Singleton<SceneManager>{}

++++public class SceneInfoData{}

++++private Dictionary<EnumSceneType, SceneInfoData> dicSceneInfos = null;

++++private BaseScene currentScene = new BaseScene();

++++public EnumSceneType LastSceneType{}

++++public EnumSceneType changeSceneType{}

++++private EnumUIType sceneOpenUIType = EnumUIType.None;

++++private object[] sceneOpenUIParams = null;

++++public BaseScene CurrentScene{}

++++public override void Init(){}

++++public void RegisterAllScene(){}

++++public void RegisterScene(EnumSceneType _sceneID, string _sceneName, Type _sceneType, params object[] _params){}

++++public void UnRegisterScene(EnumSceneType _sceneID){}

++++public bool IsRegisterScene(EnumSceneType _sceneID){}

++++internal BaseScene GetBaseScene(EnumSceneType _sceneType){}

++++public SceneInfoData GetSceneInfo(EnumSceneType _sceneID){}

++++public string GetSceneName(EnumSceneType _sceneID){}

++++public void ClearScene(){}

++++public void ChangeSceneDirect(EnumSceneType _sceneType){}

++++public void ChangeSceneDirect(EnumSceneType _sceneType, EnumUIType _uiType, params object[] _params){}

++++private IEnumerator<AsyncOperation> AsyncLoadScene(string sceneName){}

++++public void ChangeScene(EnumSceneType _sceneType){}

++++public void ChangeScene(EnumSceneType _sceneType, EnumUIType _uiType, params object[] _params){}

++++private IEnumerator AsyncLoadOtherScene(){}

++++void SceneLoadCompleted(object sender, EventArgs s){}


++2.26.1SceneManager.cs

//立钻哥哥:场景管理器(YanlzUIFramework/Manager/SceneManager.cs

using System;

using System.Collections.Generic;

using UnityEngine;

using System.Collections;

 

namesapce YanlzUIFramework{

    public class SceneManager : Singleton<SceneManager>{

        #region SceneInfoData class

        public class SceneInfoData{

            public Type SceneType{  get;    private set;  }

            public string SceneName{  get;    private set;  }

            public object[] Params{  get;    private set;  }

        

            public SceneInfoData(string _sceneName, Type _sceneType, params object[] _params){

                this.SceneType = _sceneType;

                this.SceneName = _sceneName;

                this.Params = _params;

            }

        }

        #endregion

 

        private Dictionary<EnumSceneType, SceneInfoData> dicSceneInfos = null;

        private BaseScene currentScene = new BaseScene();

        public EnumSceneType LastSceneType{  get;    set;  }

        public EnumSceneType ChangeSceneType{  get;    private set;  }

        private EnumUIType sceneOpenUIType = EnumUIType.None;

        private object[] sceneOpenUIParams = null;

 

        public BaseScene CurrentScene{

            get{

                return currentScene;

            }

 

            set{

                currentScene = value;

            }

        }

 

        public override void Init(){

            dicSceneInfos = new Dictionary<EnumSceneType, SceneInfoData>();

        }

 

        public void RegisterAllScene(){

            RegisterScene(EnumSceneType.StartGame, “StartGameScene”, null, null);

            RegisterScene(EnumSceneType.LoginScene, “LoginScene”, typeof(BaseScene), null);

            RegisterScene(EnumSceneType.MainScene, “MainScene”, null, null);

            RegisterScene(EnumSceneType.CopyScene, “CopyScene”, null, null);

        }

 

        public void RegisterScene(EnumSceneType _sceneID, string _sceneName, Type _sceneType, params object[] _params){

                if(_sceneType == null || _sceneType.BaseType != typeof(BaseScene)){

                    throw new Exception(立钻哥哥:Register scene type must not null and extends BaseScene!”);

                }

 

                if(!dicSceneInfos.ContainsKey(_sceneID)){

                    SceneInfoData sceneInfo = new SceneInfoData(_sceneName, _sceneType, _params);

                    dicSceneInfos.Add(_sceneID, sceneInfo);

                }

        }

 

        public void UnRegisterScene(EnumSceneType _sceneID){

            if(dicSceneInfos.ContainsKey(_sceneID)){

                dicSceneInfos.Remove(_sceneID);

            }

        }

 

        public bool IsRegisterScene(EnumSceneType _sceneID){

            return dicSceneInfos.ContainsKey(_sceneID);

        }

 

        internal BaseScene GetBaseScene(EnumSceneType _sceneType){

            Debug.Log(立钻哥哥:GetBaseScene sceneId =  + _sceneType.ToString());

            SceneInfoData sceneInfo = GetSceneInfo(_sceneType);

            if(sceneInfo == null || sceneInfo.SceneType == null){

                return null;

            }

 

            BaseScene scene = System.Activator.CreateInstance(sceneInfo.SceneType) as BaseScene;

            return scene;

        }

 

        public SceneInfoData GetSceneInfo(EnumSceneType _sceneID){

            if(dicSceneInfos.ContainsKey(_sceneID)){

                return dicSceneInfos[_sceneID];

            }

 

            Debug.LogError(立钻哥哥:This Scene is not register! ID:  + _sceneID.ToString());

            return null;

        }

 

        public string GetSceneName(EnumSceneType _sceneID){

            if(dicSceneInfos.ContainsKey(_sceneID)){

                return dicSceneInfos[_sceneID].SceneName;

            }

 

            Debug.LogError(立钻哥哥:This Scene is not register! ID: + _sceneID.ToString());

            return null;

        }

 

        public void ClearScene(){

            dicSceneInfos.Clear();

        }

 

        #region Change Scene

        public void ChangeSceneDirect(EnumSceneType _sceneType){

            UIManager.Instance.CloseUIAll();

    

            if(CurrentScene != null){

                CurrentScene.Release();

                CurrentScene = null;

            }

 

            LastSceneType = ChangeSceneType;

            ChangeSceneType = _sceneType;

            string sceneName = GetSceneName(_sceneType);

            CoroutineController.Instance.StartCoroutine(AsyncLoadScene(sceneName));

        }

 

        public void ChangeSceneDirect(EnumSceneType _sceneType, EnumUIType _uiType, params object[] _params){

                sceneOpenUIType = _uiType;

                sceneOpenUIParams = _params;

 

                if(LastSceneType == _sceneType){

                    if(sceneOpenUIType == EnumUIType.None){

                        return;

                    }

                   UIManager.Instance.OpenUI(sceneOpenUIType, sceneOpenUIParams);

                   sceneOpenUIType = EnumUIType.None;

 

                }else{

                   ChangeSceneDirect(_sceneType);

                }

        }

 

        private IEnumerator<AsyncOperation> AsyncLoadScene(string sceneName){

            AsyncOperation oper = Application.LoadLevelAsync(sceneName);

            yield return oper;

 

            if(sceneOpenUIType != EnumUIType.None){

                UIManager.Instance.OpenUI(sceneOpenUIType, sceneOpenUIParams);

                sceneOpenUIType = EnumUIType.None;

            }

        }

        #endregion

 

        public void ChangeScene(EnumSceneType _sceneType){

            UIManager.Instance.CloseUIAll();

 

            if(CurrentScene != null){

                CurrentScene.Release();

                CurrentScene = null;

            }

 

            LastSceneType = ChangeSceneType;

            ChangeSceneType = _sceneType;

            CoroutineController.Instance.StartCoroutine(AsyncLoadOtherScene());

        }

 

        public void ChangeScene(EnumSceneType _sceneType, EnumUIType _uiType, params object[] _params){

            sceneOpenUIType = _uiType;

            sceneOpenUIParams = _params;

 

            if(LastSceneType == _sceneType){

                if(sceneOpenUIType == EnumUIType.None){

                    return;

                }

               UIManager.Instance.OpenUI(sceneOpenUIType, sceneOpenUIParams);

               sceneOpenUIType = EnumUIType.None;

 

            }else{

                ChangeScene(_sceneType);

            }

        }

 

        private IEnumerator AsyncLoadOtherScene(){

            string sceneName = GetSceneName(EnumSceneType.LoadingScene);

            AsyncOperation oper = Application.LoadLevelAsync(sceneName);

            yield return oper;

 

            //立钻哥哥:message send

            if(oper.isDone){

                GameObject go = GameObject.Find(“LoadingScenePanel”);

                LoadingSceneUI loadingSceneUI = go.GetComponent<LoadingSceneUI>();

 

                BaseScene scene = CurrentScene;

                if(null != scene){

                    scene.CurrentSceneId = ChangeSceneId;

                }

 

                //立钻哥哥:检测是否注册该场景

                if(!SceneManager.Instance.isRegisterScene(ChangeSceneId)){

                    Debug.Log(立钻哥哥:没有注册此场景 + ChangeSceneId.ToString());

                }

                LoadingSceneUI.Load(changeSceneId);

                LoadingSceneUI.LoadCompleted += SceneLoadCompleted;

            }

        }

 

        void SceneLoadCompleted(object sender, EventArgs e){

            Debug.Log(立钻哥哥:切换场景完成 +  + sender as String);

            //立钻哥哥:场景切换完成

            MessageCenter.Instance.SendMessage(MessageType.GAMESCENE_CHSNGECOMPLETE, this, null, false);

    

            //立钻哥哥:有要打开的UI

            if(sceneOpenUIType != EnumUIType.None){

                UIManager.Instance.OpenUI(false, sceneOpenUIType, sceneOpenUIParams);

                sceneOpenUIType = EnumUIType.None;

            }

        }

 

        //立钻哥哥:加载场景

        private IEnumerator AsyncLoadedNextScene(){

            string fileName = SceneManager.Instance.GetSceneName(ChangeSceneId);

            AsyncOperation oper = Application.LoadLevelAsync(fileName);

            yield return oper;

 

            if(oper.isDone){

                if(LoadCompleted != null){

                    LoadCompleted(changeSceneId, null);

                }

            }

        }

 

        //BaseScene scene = Game.Instance.GetBaseScene(Game.Instance.ChangeSceneId);

        //CurrentScene = scene;

        //scene.Load();

 

    }    //立钻哥哥:public class SceneManager : Singleton{}

}    //立钻哥哥:namespace YanlzUIFramework





###2.27UIManager.cs

###2.27UIManager.cs

++2.27Scripts/YanlzUIFramework/Manager/UIManager.cs

++++namespace YanlzUIFramework{}

++++public class UIManager : Singleton<UIManager>{}

++++class UIInfoData{}

++++private Dictionary<EnumUIType, GameObject> dicOpenUIs = null;

++++private Stack<UIInfoData> stackOpenUIs = null;

++++public override void Init(){}

++++public T GetUI<T>(EnumUIType _uiType) where T : BaseUI{}

++++public GameObject GetUIObject(EnumUIType _uiType){}

++++public void PreloadUI(EnumUIType[] _uiTypes){}

++++public void PreloadUI(EnumUIType _uiType){}

++++public void OpenUI(EnumUIType[] uiTypes){}

++++public void OpenUI(EnumUIType uiType, params object[] uiObjParams){}

++++public void OpenUICloseOthers(EnumUIType[] uiTypes){}

++++public void OpenUICloseOthers(EnumUIType uiType, params object[] uiObjParams){}

++++public void OpenUI(bool _isCloseOthers, EnumUIType[] _uiTypes, params object[] _uiParams){}

++++private IEnumerator<int> AsyncLoadData(){}

++++public void CloseUI(EnumUIType _uiType){}

++++public void CloseUI(EnumUIType[] _uiTypes){}

++++public void CloseUIAll(){}

++++private void CloseUI(EnumUIType _uiType, GameObject _uiObj){}

++++private void CloseUIHandler(object _sender, EnumObjectState _newState, EnumObjectState _oldState){}


++2.27.1UIManager.cs

//立钻哥哥:UI管理类(YanlzUIFramework/Manager/UIManager.cs

using System;

using System.Collection.Generic;

using UnityEngine;

 

namespace YanlzUIFramework{

    public class UIManager : Singleton<UIManager>{

        #region UIInfoData class

        class UIInfoData{

            public EnumUIType UIType{  get;    private set;  }

            public Type ScriptType{  get;    private set;  }

            public string Path{  get;    private set;  }

            public object[] UIParams{  get;    private set;  }

 

            public UIInfoData(EnumUIType _uiType, string _path, params object[] _uiParams){

                this.UIType = _uiType;

                this.Path = _path;

                this.UIParams = _uiParams;

                this.ScriptType = UIPathDefines.GetUIScriptByType(this.UIType);

            }

        }

        #endregion

 

        private Dictionary<EnumUIType, GameObject> dicOpenUIs = null;

        private Stack<UIInfoData> stackOpenUIs = null;

 

        public override void Init(){

            dicOpenUIs = new Dictionary<EnumUIType, GameObject>();

            stackOpenUIs = new Stack<UIInfoData>();

        }

 

        #region Get UI & UIObject By EnumUIType

        public T GetUI<T>(EnumUIType _uiType) where T : BaseUI{

            GameObject _retObj = GetUIObject(_uiType);

            if(_retObj != null){

                return _retObj.GetComponent<T>();

            }

 

            return null;

        }

 

        public GameObject GetUIObject(EnumUIType _uiType){

            GameObject _retObj = null;

            if(!dicOpenUIs.TryGetValue(_uiType, out _retObj)){

                throw new Exception(立钻哥哥:dicOpenUIs TryGetValue Failure! _uiType: ” + _uiType.ToString());

            }

 

            return _retObj;

        }

        #endregion

 

        #region Preload UI Prefab By EnumUIType

        public void PreloadUI(EnumUIType[] _uiTypes){

            for(int i = 0;  i < _uiTypes.Length;  i++){

                PreloadUI(_uiTypes[i]);

            }

        }

 

        public void PreloadUI(EnumUIType _uiType){

            string path = UIPathDefines.GetPrefabPathByType(_uiType);

            Resources.Load(path);

            //ResManager.Instance.ResourcesLoad(path);

        }

        #endregion

 

        #region Open UI By EnumUIType

        public void OpenUI(EnumUIType[] uiTypes){

            OpenUI(false, uiTypes, null);

        }

 

        public void OpenUI(EnumUIType uiType, params object[] uiObjParams){

            EnumUIType[] uiTypes = new EnumUIType[1];

            uiTypes[0] = uiType;

            OpenUI(false, uiTypes, uiObjParams);

        }

 

        public void OpenUICloseOthers(EnumUIType[] uiTypes){

            OpenUI(true, uiTypes, null);

        }

 

        public void OpenUICloseOthers(EnumUIType uiType, params objcet[] uiObjParams){

            EnumUIType[] uiTypes = new EnumTypes[1];

            uiTypes[0] = uiType;

            OpenUI(true, uiTypes, uiObjParams);

        }

 

        private void OpenUI(bool _isCloseOthers, EnumUIType[] _uiTypes, params object[] _uiParams){

            //立钻哥哥:Close Others UI.

            if(_isCloseOthers){

                CloseUIAll();

            }

 

            //立钻哥哥:push _uiTypes in Stack.

            for(int i = 0;  i < _uiTypes.Length;  i++){

                EnumUIType _uiType = _uiTypes[i];

                if(!dicOpenUIs.ContainsKey(_uiType)){

                    string _path = UIPathDefines.GetPrefabPathByType(_uiType);

                    stackOpenUIs.Push(new UIInfoData(_uiType, _path, _uiParams));

                }

            }

 

            //立钻哥哥:Open UI.

            if(stackOpenUis.Count > 0){

                CoroutineController.Instance.StartCoroutine(AsyncLoadData());

            }

        }

 

        private IEnumerator<int> AsyncLoadData(){

            UIInfoData _uiInfoData = null;

            UnityEngine.Object _prefabObj = null;

            GameObject _uiObject = null;

 

            if(stackOpenUIs != null && stackOpenUIs.Count > 0){

                do{

                    _uiInfoData = stackOpenUIs.Pop();

                    _prefabObj = Resources.Load(_uiInfoData.Path);

            

                    if(_prefabObj != null){

                        //_uiObject = NGUITools.AddChild(Game.Instance.mainUICamera.gameObject, _prefabObj as GameObject);

                        _uiObject = MonoBehaviour.Instantiate(_prefabObj) as GameObject;

                        BaseUI _baseUI = _uiObject.GetComponent<BaseUI>();

            

                        if(null == _baseUI){

                            _baseUI = _uiObject.AddComponent(_uiInfoData.ScriptType) as BaseUI;

                        }

 

                        if(null != _baseUI){

                            _baseUI.SetUIWhenOpening(_uiInfoData.UIParams);

                        }

 

                        dicOpenUIs.Add(_uiInfoData.UIType, _uiObject);

                    }

 

                }while(stackOpenUIs.Count > 0);

            }

 

            yield return 0;

        }

 

        #endregion

 

        #region Close UI By EnumUIType

        //立钻哥哥:关闭界面

        public void CloseUI(EnumUIType _uiType){

            GameObject _uiObj = null;

            if(!dicOpenUIs.TryGetValue(_uiType, out _uiObj)){

                Debug.Log(立钻哥哥:dicOpenUIs TryGetValue Failure! _uiType:  + _uiType.ToString());

                return;

            }

 

            CloseUI(_uiType, _uiObj);

        }

 

        public void CloseUI(EnumUIType[] _uiTypes){

            for(int i = 0;  i < _uiTypes.Length;  i++){

                CloseUI(_uiTypes[i]);

            }

        }

 

        //立钻哥哥:关闭所有UI界面

        public void CloseUIAll(){

            List<EnumUIType> _keyList = new List<EnumUIType>(dicOpenUIs.Keys);

            foreach(EnumUIType _uiType in _keyList){

                GameObject _uiObj = dicOpenUIs[_uiType];

                CloseUI(_uiType, _uiObj);

            }

 

            dicOpenUIs.Clear();

        }

 

        private void CloseUI(EnumUIType _uiType, GameObject _uiObj){

            if(_uiObj == null){

                dicOpenUIs.Remove(_uiType);

            }else{

                BaseUI _baseUI = _uiObj.GetComponent<BaseUI>();

                if(_baseUI != null){

                    _baseUI.StateChanged += CloseUIHandler;

                    _baseUI.Release();

                }else{

                    GameObject.Destroy(_uiObj);

                    dicOpenUIs.Remove(_uiType);

                }

            }

        }

 

        private void CloseUIHandler(object _sender, EnumObjectState _newState, EnumObjectState _oldState){

            if(_newState == EnumObjectState.Closing){

                BaseUI _baseUI = _sender as BaseUI;

                dicOpenUIs.Remove(_baseUI.GetUIType());

                _baseUI.StateChanged -= CloseUIHandler;

            }

        }

        #endregion

 

    }    //立钻哥哥:public class UIManager : Singleton{}

}    //立钻哥哥:namespace YanlzUIFramework{}



 

++立钻哥哥推荐的拓展学习链接(Link_Url

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/

++++游戏框架(UI框架夯实篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80781140

++++游戏框架(初探篇)https://blog.csdn.net/VRunSoftYanlz/article/details/80630325

++++设计模式简单整理https://blog.csdn.net/vrunsoftyanlz/article/details/79839641

++++U3D小项目参考https://blog.csdn.net/vrunsoftyanlz/article/details/80141811

++++UML类图https://blog.csdn.net/vrunsoftyanlz/article/details/80289461

++++Unity知识点0001https://blog.csdn.net/vrunsoftyanlz/article/details/80302012

++++U3D_Shader编程(第一篇:快速入门篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372071

++++U3D_Shader编程(第二篇:基础夯实篇)https://blog.csdn.net/vrunsoftyanlz/article/details/80372628

++++Unity引擎基础https://blog.csdn.net/vrunsoftyanlz/article/details/78881685

++++Unity面向组件开发https://blog.csdn.net/vrunsoftyanlz/article/details/78881752

++++Unity物理系统https://blog.csdn.net/vrunsoftyanlz/article/details/78881879

++++Unity2D平台开发https://blog.csdn.net/vrunsoftyanlz/article/details/78882034

++++UGUI基础https://blog.csdn.net/vrunsoftyanlz/article/details/78884693

++++UGUI进阶https://blog.csdn.net/vrunsoftyanlz/article/details/78884882

++++UGUI综合https://blog.csdn.net/vrunsoftyanlz/article/details/78885013

++++Unity动画系统基础https://blog.csdn.net/vrunsoftyanlz/article/details/78886068

++++Unity动画系统进阶https://blog.csdn.net/vrunsoftyanlz/article/details/78886198

++++Navigation导航系统https://blog.csdn.net/vrunsoftyanlz/article/details/78886281

++++Unity特效渲染https://blog.csdn.net/vrunsoftyanlz/article/details/78886403

++++Unity数据存储https://blog.csdn.net/vrunsoftyanlz/article/details/79251273

++++Unity中Sqlite数据库https://blog.csdn.net/vrunsoftyanlz/article/details/79254162

++++WWW类和协程https://blog.csdn.net/vrunsoftyanlz/article/details/79254559

++++Unity网络https://blog.csdn.net/vrunsoftyanlz/article/details/79254902

++++C#事件https://blog.csdn.net/vrunsoftyanlz/article/details/78631267

++++C#委托https://blog.csdn.net/vrunsoftyanlz/article/details/78631183

++++C#集合https://blog.csdn.net/vrunsoftyanlz/article/details/78631175

++++C#泛型https://blog.csdn.net/vrunsoftyanlz/article/details/78631141

++++C#接口https://blog.csdn.net/vrunsoftyanlz/article/details/78631122

++++C#静态类https://blog.csdn.net/vrunsoftyanlz/article/details/78630979

++++C#中System.String类https://blog.csdn.net/vrunsoftyanlz/article/details/78630945

++++C#数据类型https://blog.csdn.net/vrunsoftyanlz/article/details/78630913

++++Unity3D默认的快捷键https://blog.csdn.net/vrunsoftyanlz/article/details/78630838

++++游戏相关缩写https://blog.csdn.net/vrunsoftyanlz/article/details/78630687

++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/


--_--VRunSoft : lovezuanzuan--_--

你可能感兴趣的:(框架编程,unity,framework,UI框架,框架编程,实战)