/// <summary> /// 初始化FairyGUI,配置全局参数。 /// </summary> public void Awake() { Instance = this; baseUIContainer = ComponentFactory.Create <FairyGUIContainer>(); _LayerDictionary = new Dictionary <FairyGUIType, List <FairyGUIBaseUI> >(); _LayerDictionary.Add(ETModel.FairyGUIType.UITYPE_FIXED, new List <FairyGUIBaseUI>()); _LayerDictionary.Add(ETModel.FairyGUIType.UITYPE_POPUP, new List <FairyGUIBaseUI>()); //加载UI包 #if UNITY_EDITOR // UIPackage.AddPackage("UI/ASource"); #else //ResourcesComponent resourcesComponent = Game.Scene.GetComponent<ResourcesComponent>(); //resourcesComponent.LoadOneBundle($"ui"); //ABInfo abInfo = resourcesComponent.GetABInfoByName("ui"); //UIPackage.AddPackage(abInfo.AssetBundle); #endif //UI的配置 //Groot的参数初始化 //GRoot.inst.SetContentScaleFactor(1136, 640, ScreenMatchMode.MatchWidthOrHeight); // Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("uiaudio.unity3d"); //UIConfig.buttonSound = (AudioClip)UIPackage.GetItemAssetByURL("ui://ASource/buttonclick"); //GameObject bunddleObject = (GameObject)Game.Scene.GetComponent<ResourcesComponent>().GetAsset("uiaudio.unity3d", "UIAudio"); //UIConfig.buttonSound =bunddleObject.Get<AudioClip>("ButtonClickAudio"); //UIConfig.modalLayerColor = new Color(186f, 85f, 211f, 0.4f); }
/// <summary> /// 创建UI Mono层使用 /// </summary> /// <returns></returns> public T Create <T>() where T : FairyGUIBaseUI, new() { if (baseUIContainer.IsDisposed) { baseUIContainer = ComponentFactory.Create <FairyGUIContainer>(); } T t = baseUIContainer.GetComponent <T>(); if (t == null) { t = baseUIContainer.AddComponent <T>(); #if UNITY_EDITOR UIPackage.AddPackage("UI/" + t.pakName); #endif t.gObj = UIPackage.CreateObject(t.pakName, t.cmpName); //加入到对应层中。 _LayerDictionary[t.UIType].Add(t); } t.InitUI(); return(t); }