123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace LoyalSoftSDK
- {
- public class UIFormManager:MonoBehaviour
- {
- private static UIFormManager instance;
- public static UIFormManager GetInstance()
- {
- if(instance==null)
- {
- instance = new GameObject("UIFormManager").AddComponent<UIFormManager>();
- DontDestroyOnLoad(instance.transform);
- }
- return instance;
- }
- public int screenWidth = 0;
- public int screenHeight = 0;
- public string screenOrientation;
- public Transform canvasTransform;
- private Transform actionLayer;
- private Transform floatLayer;
- private Transform loadingLayer;
- //UI窗体的路径集合
- private Dictionary<string, string> uiFromPathDic;
- //所有已加载的UI集合
- private Dictionary<string, BaseUIForm> allUIFromDic;
- //支付界面实例,要接收支付结果的
- public PayPanel paypanl;
-
- public bool InitCanvas()
- {
- screenWidth = Screen.width;
- screenHeight = Screen.height;
- if (screenWidth > screenHeight)
- {
- screenOrientation = "landscape";
- }
- else
- {
- screenOrientation = "portrait";
- }
- if (screenOrientation.Equals("landscape"))
- {
- ResourLoadMananger.GetInstance().LoadAsset("LoyalSoftSDK/Canvas_landscape", false);
- }
- else
- {
- ResourLoadMananger.GetInstance().LoadAsset("LoyalSoftSDK/Canvas_portrait", false);
- }
- uiFromPathDic = new Dictionary<string, string>();
- allUIFromDic = new Dictionary<string, BaseUIForm>();
- canvasTransform = GameObject.FindGameObjectWithTag("SoftCanvas").transform;
- canvasTransform.SetAsLastSibling();
- DontDestroyOnLoad(canvasTransform);
- actionLayer = canvasTransform.Find("ActionLayer");
- floatLayer= canvasTransform.Find("FloatLayer");
- loadingLayer = canvasTransform.Find("LoadingLayer");
- //初始化UI窗体预设路径数据
- InitUIFormsPathsData();
- return true;
-
- }
- private void InitUIFormsPathsData()
- {
- uiFromPathDic.Add("AgreementPanel", "LoyalSoftSDK/UIPrefabs/AgreementPanel");
- uiFromPathDic.Add("AuthenticationPanel", "LoyalSoftSDK/UIPrefabs/AuthenticationPanel");
- uiFromPathDic.Add("CloseFloatPanel", "LoyalSoftSDK/UIPrefabs/CloseFloatPanel");
- uiFromPathDic.Add("ExitGamePanel", "LoyalSoftSDK/UIPrefabs/ExitGamePanel");
- uiFromPathDic.Add("GetPassPanel", "LoyalSoftSDK/UIPrefabs/GetPassPanel");
- uiFromPathDic.Add("LoginPanel", "LoyalSoftSDK/UIPrefabs/LoginPanel");
- uiFromPathDic.Add("LoginSueccesPanel", "LoyalSoftSDK/UIPrefabs/LoginSueccesPanel");
- uiFromPathDic.Add("PayPanel", "LoyalSoftSDK/UIPrefabs/PayPanel");
- uiFromPathDic.Add("PolicyPanel", "LoyalSoftSDK/UIPrefabs/PolicyPanel");
- uiFromPathDic.Add("RegisterPanel", "LoyalSoftSDK/UIPrefabs/RegisterPanel");
- uiFromPathDic.Add("ResetPassPanel", "LoyalSoftSDK/UIPrefabs/ResetPassPanel");
- uiFromPathDic.Add("InstallationWechatPanel", "LoyalSoftSDK/UIPrefabs/InstallationWechatPanel");
- uiFromPathDic.Add("PayInfoPanel", "LoyalSoftSDK/UIPrefabs/PayInfoPanel");
-
- uiFromPathDic.Add("FloatPanel", "LoyalSoftSDK/UIPrefabs/FloatPanel");
- uiFromPathDic.Add("LoadingPanel", "LoyalSoftSDK/UIPrefabs/LoadingPanel");
- uiFromPathDic.Add("MessagePanel", "LoyalSoftSDK/UIPrefabs/MessagePanel");
-
- uiFromPathDic.Add("TestPanel", "LoyalSoftSDK/UIPrefabs/TestPanel");
- }
- public void ShowUIForm(string uiname, BaseUIForm _parent, Dictionary<string, string> data)
- {
- // Debug.Log("showuif1");
- BaseUIForm baseUIForm = null;
- if (string.IsNullOrEmpty(name)) return;
- // Debug.Log("showuif2");
- baseUIForm = LoadFormsToAllUIFormsCache(uiname);
- if (baseUIForm == null) return;
- // Debug.Log("showuif3");
- if (uiname.Equals("PayPanel"))
- {
- // Debug.Log("showuif4");
- paypanl = baseUIForm as PayPanel;
- }
- // Debug.Log("showuif5");
- baseUIForm.Display(_parent,data);
-
- }
- public void CloseUIForm(string uiname)
- {
- BaseUIForm baseUIForm = null;
- if (string.IsNullOrEmpty(name)) return;
- baseUIForm = LoadFormsToAllUIFormsCache(uiname);
- if (baseUIForm == null) return;
- baseUIForm.Hiding();
- }
- public void OnEscape()
- {
- bool needOpenExit = true;
- foreach(BaseUIForm baseUIForm in allUIFromDic.Values)
- {
- if(baseUIForm.OnEscape())
- {
- needOpenExit = false;
- }
- }
- if(needOpenExit)
- {
- ShowUIForm("ExitGamePanel", null, null);
- }
- }
- public void OnEscapeTest()
- {
- bool needOpenExit = true;
- foreach (BaseUIForm baseUIForm in allUIFromDic.Values)
- {
- if (baseUIForm.OnEscape())
- {
- needOpenExit = false;
- }
- }
- if (needOpenExit)
- {
- Dictionary<string, string> data = new Dictionary<string, string>();
- data.Add("action", "ExitGame");
- data.Add("title", "退出游戏!");
- //UIFormManager.GetInstance().ShowUIForm("TestPanel", null, data);
- }
- }
- #region
- private BaseUIForm LoadFormsToAllUIFormsCache(string uiname)
- {
- BaseUIForm baseUIResult = null;
- allUIFromDic.TryGetValue(uiname, out baseUIResult);
- if (baseUIResult == null)
- {
- baseUIResult = LoadUIForm(uiname);
- }
- return baseUIResult;
- }
- private BaseUIForm LoadUIForm(string uiname)
- {
- string uiFormPath = null;
- GameObject uiFormPrefab = null;
- BaseUIForm baseUiForm = null;
- uiFromPathDic.TryGetValue(uiname, out uiFormPath);
- if (!string.IsNullOrEmpty(uiFormPath))
- {
- uiFormPrefab = ResourLoadMananger.GetInstance().LoadAsset(uiFormPath, false);
- }
- if (canvasTransform != null && uiFormPrefab != null)
- {
- baseUiForm = uiFormPrefab.GetComponent<BaseUIForm>();
- if (baseUiForm == null)
- {
- Debug.LogError("baseUiForm==null! ,请先确认窗体预设对象上是否加载了baseUIForm的子类脚本! 参数 uiFormName=" + uiname);
- return null;
- }
- switch (baseUiForm.curUIType)
- {
- case UIType.Normal:
- uiFormPrefab.transform.SetParent(actionLayer,false);
- break;
- case UIType.Float:
- uiFormPrefab.transform.SetParent(floatLayer, false);
- break;
- case UIType.Loading:
- uiFormPrefab.transform.SetParent(loadingLayer, false);
- break;
- default:
- break;
- }
- baseUiForm.Init();
- uiFormPrefab.SetActive(false);
- allUIFromDic.Add(uiname, baseUiForm);
- return baseUiForm;
- }
- else
- {
- Debug.LogError("_TraCanvasTransfrom==null Or goCloneUIPrefabs==null!! ,Plese Check!, 参数uiname=" + uiname);
- }
- Debug.Log("出现不可以预估的错误,请检查,参数 uiname=" + uiname);
- return null;
- }
- #endregion
- //void Update()
- //{
- // if (Input.GetKeyDown(KeyCode.Escape))
- // {
- // LoyalGameSDK.Instance.ExitGame(null);
- // }
- //}
- }
- }
|