using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GCGame.Table; using Module.Log; using System; public class FunctionLimitRoot : MonoBehaviour { public static FunctionLimitRoot Instance; private void Awake() { Instance = this; } private void OnDestroy() { Instance = null; } void ReqTime() { ReqSyncOnLineTime req = new ReqSyncOnLineTime(); req._functionId = _functionId; req.SendMsg(); } public Image _descIcon; public UICameraTexture _cameraTexture; public Text _limitDesc; private int _functionId = -1; private Tab_FunctionOpen _fucntionOpenTab; public void ShowFunctionLimitInfo(int functionId) { _functionId = functionId; ReqTime(); _fucntionOpenTab = TableManager.GetFunctionOpenByID(functionId, 0); if(_fucntionOpenTab == null) { LogModule.ErrorLog("_fucntionOpenTab找不到ID : " + functionId); return; } LoadAssetBundle.Instance.SetImageSprite(_descIcon, _fucntionOpenTab.ShowImageBundlePath); var strId = "#{" + _fucntionOpenTab.StrdicId + "}"; _limitDesc.text = StrDictionary.GetClientDictionaryString(strId, _fucntionOpenTab.OpenLevel); //_limitDesc.text = StrDictionary.GetClientDictionaryString(strId, // GameManager.gameManager.PlayerDataPool.FuncionOnlineTimeDic.ContainsKey(_functionId) ? GameManager.gameManager.PlayerDataPool.FuncionOnlineTimeDic[functionId] : 0); StartCoroutine(initModel()); } IEnumerator initModel() { yield return new WaitForEndOfFrame(); var charModel = TableManager.GetCharModelByID(_fucntionOpenTab.ShowModelid, 0); if (charModel == null) { LogModule.ErrorLog("找不到模型: " + _fucntionOpenTab.ShowModelid); yield break; } _cameraTexture.InitModelPath(charModel.ResPath, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true); yield break; } public void OnActiveFunctionBtnClick() { ReqActiveFunction req = new ReqActiveFunction(); req._functionId = _functionId; req.SendMsg(); } public void OnCloseBtnClick() { UIManager.CloseUI(UIInfo.FunctionLimitRoot); } private Int64 onlineTime; public void RefreshOnLineTime(Int64 _onlineTime) { //onlineTime = _onlineTime; //if(onlineTime > 0) //开始计时 //{ // StopAllCoroutines(); // StartCoroutine(CounTimeAsyc()); //} } //开始一秒一次的计时,真棒! IEnumerator CounTimeAsyc() { while(true) { if (!gameObject.activeInHierarchy) yield break; if (_fucntionOpenTab != null) { var strId = "#{" + _fucntionOpenTab.StrdicId + "}"; _limitDesc.text = StrDictionary.GetClientDictionaryString(strId, GetOnLineTimeDesc(++onlineTime)); } yield return new WaitForSeconds(1.0f); } } //不足一小时就分钟 不足一分钟就秒(真棒!) public string GetOnLineTimeDesc(Int64 _onlineTime) { if(_onlineTime < 60)//秒 { return StrDictionary.GetClientDictionaryString("#{68600}", _onlineTime); }else if(_onlineTime >= 60 && _onlineTime < 3600)//分钟 { return StrDictionary.GetClientDictionaryString("#{68601}", _onlineTime / 60); } else//小时 { return StrDictionary.GetClientDictionaryString("#{68602}", _onlineTime / 3600); } } }