Exemplo n.º 1
0
 public async void ShowInfo(string iconName)
 {
     IconFertilizer.sprite = await ABManager.GetAssetAsync <Sprite>(iconName);
 }
Exemplo n.º 2
0
 void Awake()
 {
     Init();
     instance = this;
 }
Exemplo n.º 3
0
    /// <summary>
    /// 展示数据
    /// </summary>
    async void ShwoData()
    {
        if (_currShowData == null)
        {
            return;
        }

        _newLabelTra.gameObject.SetActive(!WarehouseTool.DataIsSave(_currShowData));
        //_newLabelTra.gameObject.SetActive(false);//_newLabelTra.gameObject.SetActive(_currShowData._isNewData);
        switch (_currShowData._data.Rarity)
        {
        case Company.Cfg.TypeRarity.None:
        case Company.Cfg.TypeRarity.Primary:
            _rarityLabelTra.gameObject.SetActive(true);
            _rarityLabelTra.Find("One").gameObject.SetActive(true);
            _rarityLabelTra.Find("Two").gameObject.SetActive(false);
            _rarityLabelTra.Find("Therr").gameObject.SetActive(false);
            break;

        case Company.Cfg.TypeRarity.Intermediate:
            _rarityLabelTra.gameObject.SetActive(true);
            _rarityLabelTra.Find("One").gameObject.SetActive(false);
            _rarityLabelTra.Find("Two").gameObject.SetActive(true);
            _rarityLabelTra.Find("Therr").gameObject.SetActive(false);
            break;

        case Company.Cfg.TypeRarity.Senior:
            _rarityLabelTra.gameObject.SetActive(true);
            _rarityLabelTra.Find("One").gameObject.SetActive(false);
            _rarityLabelTra.Find("Two").gameObject.SetActive(false);
            _rarityLabelTra.Find("Therr").gameObject.SetActive(true);
            break;
        }
        _lockLabelTra.gameObject.SetActive(_currShowData._isLock);

        if (_currShowData._data.Grade > 0)
        {
            _gradeLabelTra.gameObject.SetActive(true);
            _gradeLabelTra.Find("GradeText").GetComponent <Text>().text = StaticData.GetMultilingual(120035);
            _gradeLabelText.text = _currShowData._data.Grade.ToString();
        }
        else
        {
            _gradeLabelTra.gameObject.SetActive(false);
        }

        _numberText.text = _currShowData._number.ToString();
        Sprite iconSprite = null;

        try
        {
            iconSprite = await ABManager.GetAssetAsync <Sprite>(_currShowData._data.Icon);
        }
        catch (System.Exception er)
        {
            Debug.Log("道具icon未找到");
        }

        _iconImage.sprite = iconSprite;

        _nameText.text = StaticData.GetMultilingual(_currShowData._data.ItemName);
        //_iconImage.SetNativeSize();
    }
Exemplo n.º 4
0
    private async void Start()
    {
        //启动UniTask Player Loop 注册事件
        PlayerLoopHelper.Init();
        if (isShowDebugWindow)
        {
            goDebug.SetActive(true);
        }
        else
        {
            goDebug.SetActive(false);
        }

        if (isShowFPS)
        {
            ResourcesHelper.InstantiatePrefabFromResourceSetDefault("UIFrameShow", UIRoot.instance.GetUIRootCanvasTop().transform);
        }

        Screen.sleepTimeout                    = SleepTimeout.NeverSleep;
        Application.runInBackground            = true;
        Application.targetFrameRate            = TargetFrameRate;
        StaticData.IsABNotFromServer           = isABNotFromServer;
        StaticData.isABUsedYunSever            = isABUsedYunSever;
        StaticData.SelfResourceServerIpAndPort = selfResourceServerIpAndPort;
        StaticData.localVersionGameCode        = versionGameCode;
        StaticData.isOpenGuide                 = isOpenGuide;
#if UNITY_EDITOR
        StaticData.linguisticType = LanguageType;
#else
        switch (Application.systemLanguage)
        {
        case SystemLanguage.Chinese:
        case SystemLanguage.ChineseSimplified:
            StaticData.linguisticType = LinguisticType.Simplified;
            break;

        case SystemLanguage.ChineseTraditional:
            StaticData.linguisticType = LinguisticType.Complex;
            break;

        case SystemLanguage.English:
        case SystemLanguage.Unknown:
            StaticData.linguisticType = LinguisticType.English;
            break;

        default:
            StaticData.linguisticType = LinguisticType.English;
            break;
        }
#endif
        StaticData.GameShowVersion = GameShowVersion;
        StaticData.isShowSelfLog   = isShowSelfLog;
        try
        {
            //播放背景音乐
            GameSoundPlayer.Instance.PlayBgMusic(MusicHelper.BgMusicLogin);
            StaticData.isUseAssetBundle = isUseAssetBundle;
            DontDestroyOnLoad(gameObject);
            gameObject.AddComponentIfNull <GlobalConfigComponent>();
            gameObject.AddComponentIfNull <ResourcesComponent>();
            BundleDownloaderComponent bundleDownloaderComponent = gameObject.AddComponentIfNull <BundleDownloaderComponent>();
            var IsGameVersionCodeEqual = await BundleHelper.IsGameVersionCodeEqual();

            if (!IsGameVersionCodeEqual)
            {
                return;
            }
            // 下载ab包
            await BundleHelper.DownloadBundle();

            GameObject.Destroy(bundleDownloaderComponent);
            //初始化ABManager
            ABManager.Init();
            //数据表格解析
            ParseExcelData parseExcelData = new ParseExcelData();
            StaticData.configExcel = parseExcelData.Init();
            //用来拿取服务器
            StaticData.IsiosRelease     = StaticData.configExcel.GetVertical().IsiosRelease;
            StaticData.IsAndoridRelease = StaticData.configExcel.GetVertical().IsAndoridRelease;
            //Test Excel
            int WarehouseTotal = StaticData.configExcel.GetVertical().WarehouseTotal;
            Debug.Log($"WarehouseTotal:{WarehouseTotal}");
            ////下载好了,声音ab绑定到固定的地方
            //await ResetSoundPlayers();
            //GameSoundPlayer.Instance.PlayBgMusic("BGM");
            //GameSoundPlayer.Instance.PlaySoundEffect("PrintPhotos");
            //ResourcesHelper.CreateUI("UIWait");
            await UniTask.DelayFrame(1);

            //添加SceneManager
            GameObject goSceneManager = new GameObject("SceneManager");
            goSceneManager.transform.parent = transform;
            goSceneManager.AddComponent <SceneManagerComponent>();

            // 设置请求短链接参数
            StaticData.IsUsedLocalDataNotServer = IsUsedLocalDataNotServer;

            /*
             * //加载网关
             * TextAsset gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfo");
             * switch (typeGate)
             * {
             *  case TypeGateWay.Stable:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfo");
             *      break;
             *  case TypeGateWay.MZQ:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoMZQ");
             *      break;
             *  case TypeGateWay.YQX:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoYQX");
             *      break;
             *  case TypeGateWay.JLF:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoJLF");
             *      break;
             *  case TypeGateWay.Extranet:
             *      gatewayInfo = await ABManager.GetAssetAsync<TextAsset>("GateWayInfoExtranet");
             *      break;
             * }
             *
             * GateWayInfo gateWayInfo=LitJson.JsonMapper.ToObject<GateWayInfo>(gatewayInfo.text);
             * //StaticData.DebugGreen($"gateWayInfo ip:{gateWayInfo.ipGateWay} port:{gateWayInfo.portGateWay} timeout:{gateWayInfo.timeout}");
             * bool isGateWayReturn = false;
             * string urlGateWay = $"{gateWayInfo.ipGateWay}:{gateWayInfo.portGateWay}";
             * if (!StaticData.IsUsedLocalDataNotServer)
             * {
             *  CSLinkInfo csLinkInfo = new CSLinkInfo() { Sole = SystemInfo.deviceUniqueIdentifier };
             *  csLinkInfo.Sole = string.Empty;//授权使用的唯一id
             *  csLinkInfo.Platform = RegisterPlatform.None;//授权平台
             *
             *  //发起链接请求
             *  StartCoroutine(HttpGateWayManager.Post(urlGateWay, csLinkInfo, gateWayInfo.timeout, (ip, port, Uid) =>
             *  {
             *      StaticData.ipWebSocket = ip;
             *      StaticData.portWebSocket = port;
             *      StaticData.Uid = Uid;
             *      StaticData.DebugGreen($"玩家的uid:{Uid}");
             *      isGateWayReturn = true;
             *  }, (WebErrorCode webErrorCode) =>
             *  {
             *      StaticData.DebugGreen($"webErrorCode:{webErrorCode.ToString()}");
             *      isGateWayReturn = false;
             *  }));
             *
             *  await UniTask.WaitUntil(() => isGateWayReturn == true);
             *  //进行长连接 使用WebSocket
             *  WebSocketComponent._instance.Init();
             * }
             *
             * //获取用户信息
             * bool isGetUserInfo = false;
             * CSEmptyAccountInfo csEmptyAccountInfo = new CSEmptyAccountInfo();
             * OtherProtoHelper.GetUserInfo(csEmptyAccountInfo,(userInfo)=> {
             *  StaticData.playerInfoData.userInfo = userInfo;
             *  TimeHelper.LoginServerTime = StaticData.playerInfoData.userInfo.PresentTime;
             *  StaticData.DebugGreen($"ServerTime:{TimeHelper.ServerTime(TimeHelper.LoginServerTime)}");
             *  isGetUserInfo = true;
             * });
             * await UniTask.WaitUntil(() => isGetUserInfo == true);
             * //加载本地存储的私聊信息/文件
             * StaticData.LoadPrivateChatFile();
             */

            //登录界面
            await StaticData.OpenUILogin(typeGate, null);

            //关闭Init背景
            UIRoot.instance.GoBgInit.SetActive(false);
        }
        catch (Exception e)
        {
            Debug.LogError(e);
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// 初始化入场券的icon
    /// </summary>
    private void InitAdmissionTickeIcon()
    {
        string path = StaticData.configExcel.GetGameItemByID(StaticData.configExcel.GetVertical().AdmissionGoodsId).Icon;

        _admissionTickeIcon.sprite = ABManager.GetAsset <Sprite>(path);
    }
Exemplo n.º 6
0
    /// <summary>
    /// 展示数据
    /// </summary>
    /// <param name="goodsData"></param>
    public async void ShowData(GoodsData goodsData)
    {
        if (!_isInitial)
        {
            Initial();
        }
        _currData      = goodsData;
        _nameText.text = StaticData.GetMultilingual(_currData._data.ItemName);
        RectTransform desRect = _desText.transform.GetComponent <RectTransform>();

        if (_currData._data.ItemType == Company.Cfg.TypeGameItem.Seed)
        {
            /// 收获经验显示
            _reapExperienceText.text = StaticData.GetSeedExperience(_currData._data.ID).ToString();

            /// 成熟时间显示
            _matureTimeText.text = StaticData.GetSeedRipeningTime(_currData._data.ID);
            ///获取结果数量
            _numberText.text = StaticData.GetSeedFruitNumber(_currData._data.ID).ToString();
            //获取果实单价
            _priceText.text = StaticData.GetSeedEstimateTheValueOf(_currData._data.ID).ToString();
            _fruitInformationBoxTra.gameObject.SetActive(true);
            desRect.sizeDelta     = new Vector2(desRect.sizeDelta.x, 169.2016f);
            desRect.localPosition = new Vector3(desRect.localPosition.x, -239.3992f);
        }
        else
        {
            _fruitInformationBoxTra.gameObject.SetActive(false);
            desRect.sizeDelta     = new Vector2(desRect.sizeDelta.x, 264.9064f);
            desRect.localPosition = new Vector3(desRect.localPosition.x, 14.2f);
        }

        Sprite iconSprite = null;

        try
        {
            iconSprite = await ABManager.GetAssetAsync <Sprite>(_currData._data.Icon);
        }
        catch (Exception er)
        {
            Debug.Log("获取道具icon失败");
        }
        _iconImage.sprite = iconSprite;

        switch (_currData._data.Rarity)
        {
        case Company.Cfg.TypeRarity.None:
            _valuableTableTra.sprite = _valuableTableSprites[0];
            break;

        case Company.Cfg.TypeRarity.Primary:
            _valuableTableTra.sprite = _valuableTableSprites[0];
            break;

        case Company.Cfg.TypeRarity.Intermediate:
            _valuableTableTra.sprite = _valuableTableSprites[1];
            break;

        case Company.Cfg.TypeRarity.Senior:
            _valuableTableTra.sprite = _valuableTableSprites[2];
            break;
        }
        if (_currData._data.Grade > 0)
        {
            _gradeText.text = _currData._data.Grade.ToString();
            _gradeText.transform.parent.gameObject.SetActive(true);
        }
        else
        {
            _gradeText.transform.parent.gameObject.SetActive(false);
        }

        _haveNumber.text = _currData._number.ToString();

        _desText.text = StaticData.GetMultilingual(_currData._data.Description);
        bool isSell = WarehouseTool.IsGoodsSell(_currData);

        _saleBtn.gameObject.SetActive(isSell);
        if (isSell)
        {
            _lockBtn.gameObject.SetActive(!_currData._isLock);
            _noLockBtn.gameObject.SetActive(_currData._isLock);
        }
        else
        {
            _lockBtn.gameObject.SetActive(false);
            _noLockBtn.gameObject.SetActive(false);
        }

        _useBtn.gameObject.SetActive(_currData._data.Use != 0);
        gameObject.SetActive(true);
    }
Exemplo n.º 7
0
        public static async void Start()
        {
            try
            {
                Debug.Log("Begin ETHotfix.Init.Start");
                Game.Scene.ModelScene = ETModel.Game.Scene;
                ////Test
                //UnityEngine.Sprite sprite = await ABManager.GetAssetAsync<UnityEngine.Sprite>(Hotfix.ABMapping.ArrowUp1);
                //Debug.Log($"{Hotfix.ABMapping.ArrowUp1}:{sprite.name}");
                GameSoundPlayer.Instance.PlayBgMusic("BgMusicHotfix");
                GameSoundPlayer.Instance.PlaySoundEffect("laugh2D");
                GameSoundPlayer.Instance.PlaySoundEffect("water", Vector3.zero);
                // 注册热更层回调
                ETModel.Game.Hotfix.Update             = () => { Update(); };
                ETModel.Game.Hotfix.LateUpdate         = () => { LateUpdate(); };
                ETModel.Game.Hotfix.OnApplicationQuit  = () => { OnApplicationQuit(); };
                ETModel.Game.Hotfix.OnApplicationFocus = () => { OnApplicationFocus(); };

                Game.Scene.AddComponent <UIComponent>();
                ////预加载一些资源
                //await PreLoad();
                //var taskLoadSceneRes1 = PreLoad1();
                // 加载热更配置
                await ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundleAsync("config.unity3d");

                Game.Scene.AddComponent <ConfigComponent>();
                ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d");

                await ETModel.Game.Scene.GetComponent <ResourcesComponent>().LoadBundleAsync <UnityEngine.Sprite>("icon.unity3d");

                //解析数据表
                var tabtoyText = await ABManager.GetAssetAsync <TextAsset>(Hotfix.ABMapping.tabtoyData);

                //读取
                MemoryStream ms           = null;
                var          il           = new ILSerial();
                Config       configTabtoy = il.ReadFileBytes <Config>(tabtoyText.bytes, out ms);
                StaticTool.TabToyDataConfig = configTabtoy;
                ms.Close();
                var define = configTabtoy.Test[0];
                Debug.LogError($"热更层 解析数据表不建议使用float,float数组会导致解析错误,最好用int32替代");
                Debug.LogError($"热更层 数据表中string要加\"\",否则会解析出错");
                Debug.LogError($"热更层 Test define.TestInt:{define.TestInt} define.TestLong:{define.TestLong}");
                Debug.LogError($"热更层 Test define.TestFloat:{define.TestFloat}");
                Debug.LogError($"热更层 Test define.TestString:{define.TestString}");
                Debug.LogError($"热更层 Test define.TestIntArr:{define.TestIntArr[0]} {define.TestIntArr[1]} {define.TestIntArr[2]} {define.TestIntArr[3]} {define.TestIntArr[4]} {define.TestIntArr[5]}");
                Debug.LogError($"热更层 Test define.TestFloat2:{define.TestFloat2}");
                Debug.LogError($"热更层 Test define.TestStringArr:{define.TestStringArr[0]} {define.TestStringArr[1]} {define.TestStringArr[2]}");
                Debug.LogError($"热更层 Test define.TestEnum0:{define.TestEnum0} define.TestEnum1:{define.TestEnum1}");
                Debug.LogError($"热更层 Test define.TestClass:{define.TestClass.DropID} {define.TestClass.DropNumber}");

                //初始化ab字典
                ETModel.Game.Scene.GetComponent <ResourcesComponent>().InitDicABRequest();
                ////测试DoTween插件
                //UI uiDoTweenTest = Game.Scene.GetComponent<UIComponent>().Create(UIType.UIDoTweenTest);
                Debug.Log("Begin ETHotfix.Init.Start UIType.UIFrameShow");
                await Game.Scene.GetComponent <UIComponent>().CreateAsync(UIType.UIFrameShow);

                Debug.Log("End ETHotfix.Init.Start UIType.UIFrameShow");
                Debug.Log("Begin ETHotfix.Init.Start UIType.UILogin");
                UI ui = await Game.Scene.GetComponent <UIComponent>().CreateAsync(UIType.UILogin);

                Debug.Log("End ETHotfix.Init.Start UIType.UILogin");
                ETModel.Game.Scene.GetComponent <ETModel.UIComponent>().Remove(ETModel.UIType.UILoading);//关闭进度条
                Debug.Log("End ETHotfix.Init.Start Remove ETModel.UIType.UILoading");
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 协程加载Assetbundle,加载完后执行callback
        /// </summary>
        /// <param name="url">资源的url</param>
        /// <param name="callback"></param>
        /// <param name="callbackArgs"></param>
        /// <returns></returns>
        private IEnumerator CoLoad(string url)
        {
            if (AppConfig.IsLogAbInfo)
            {
                Log.Info("[Request] WWW, {1}", url);
            }

            // 潜规则:不用LoadFromCache~它只能用在.assetBundle
#pragma warning disable 0618
            Www = new WWW(url);
#pragma warning restore 0618
            BeginLoadTime = Time.time;
            WWWLoadingCount++;

            //设置AssetBundle解压缩线程的优先级
            Www.threadPriority = Application.backgroundLoadingPriority; // 取用全局的加载优先速度
            while (!Www.isDone)
            {
                Progress = Www.progress;
                yield return(null);
            }

            yield return(Www);

            WWWLoadingCount--;
            Progress = 1;
            if (IsReadyDisposed)
            {
                Log.Error("[KWWWLoader]Too early release: {0}", url);
                OnFinish(null);
                yield break;
            }
            if (!string.IsNullOrEmpty(Www.error))
            {
                if (Application.platform == RuntimePlatform.Android)
                {
                    // TODO: Android下的错误可能是因为文件不存在!
                }

                string fileProtocol = KResourceModule.GetFileProtocol();
                if (url.StartsWith(fileProtocol))
                {
                    string fileRealPath = url.Replace(fileProtocol, "");
                    Log.Error("File {0} Exist State: {1}", fileRealPath, System.IO.File.Exists(fileRealPath));
                }
                Log.Error("[KWWWLoader:Error]{0} {1}", Www.error, url);

                OnFinish(null);
                yield break;
            }
            else
            {
                if (WWWFinishCallback != null)
                {
                    WWWFinishCallback(url);
                }

                Desc = string.Format("{0}K", Www.bytes.Length / 1024f);
                OnFinish(Www);
            }

            // 预防WWW加载器永不反初始化, 造成内存泄露~
            if (Application.isEditor)
            {
                while (ABManager.GetCount <KWWWLoader>() > 0)
                {
                    yield return(null);
                }

                yield return(new WaitForSeconds(5f));

                while (!IsReadyDisposed)
                {
                    Log.Error("[KWWWLoader]Not Disposed Yet! : {0}", this.Url);
                    yield return(null);
                }
            }
        }
Exemplo n.º 9
0
 private void Update()
 {
     //NOTE 在Unity2019中有渐近式GC,而此处不会调用GC.Collect,仅仅对已加载的ab进行检查是否需要Unload
     ABManager.CheckGcCollect();
 }
Exemplo n.º 10
0
    static void Init()
    {
        ABManager w = (ABManager)EditorWindow.GetWindow(typeof(ABManager), false, "ABManager", true);

        w.Show();
    }
Exemplo n.º 11
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="sceneType"></param>
    /// <param name="isCloseLoadingAfter">为true需要自己关闭进度条</param>
    /// <returns></returns>
    public async Task ChangeSceneAsync(EnumScene sceneType, bool isCloseLoadingAfter = false)
    {
        //加载进度条
        await UIComponent.CreateUIAsync(UIType.UISceneLoading, isTopCanvas : true);

        uISceneLoadingComponent.Reset();

        //关闭聊天相关界面
        ChatTool.CloseChat();
        var scencePath = EnumScene.Empty.ToString();

        _currSceneTage = sceneType;
        //加载空场景
        scencePath = "Scenes/" + scencePath;
        SceneManager.LoadScene(scencePath);
        var bundleType = sceneType.ToString();

        if (sceneType != EnumScene.Empty)//空场景为退出到大厅
        {
            List <string> bundleNameList = new List <string>();

            if (preLoadMap.ContainsKey(sceneType))
            {
                bundleNameList.AddRange(preLoadMap[sceneType]);
            }
            //加上自己的场景ab包
            var sceneBundleName = ABManager.GetBundleNameByAssetNameAndType(sceneType.ToString(), typeof(GameObject));
            bundleNameList.Add($"{sceneBundleName}");

            List <string> allBundleNameList = new List <string>();
            foreach (var bundleName in bundleNameList)
            {
                string[] dependencies = ResourcesHelper.GetSortedDependencies(bundleName.ToLower());
                if (dependencies != null)
                {
                    foreach (var item in dependencies)
                    {
                        if (allBundleNameList.Contains(item))
                        {
                            continue;
                        }
                        allBundleNameList.Add(item);
                    }
                }
            }
            ResourcesComponent resourcesComponent = ResourcesComponent.instance;
            for (int i = 0; i < allBundleNameList.Count; i++)
            {
                await resourcesComponent.LoadOneBundleAsync(allBundleNameList[i], (real) => UpdateProgress(i, allBundleNameList.Count, real, allBundleNameList[i]));
            }
        }


        await AddSceneAsyncTask(bundleType, LoadSceneMode.Single);

        //await StaticData.CreateChatMini();
        if (isCloseLoadingAfter == false)
        {
            UIComponent.HideUI(UIType.UISceneLoading);
        }
    }