Ejemplo n.º 1
0
        /// <summary>
        /// 实际切换Stage的内部方法
        /// </summary>
        /// <param name="newStage"></param>
        private void switchStage(StageControllerBase newStage)
        {
            if (m_CurrentStage != null)
            {
                if (m_CurrentStage == newStage)
                {
                    return;
                }
                else
                {
                    var last_stage = m_CurrentStage;

                    #region Exit Event 广播退出事件
                    XEvent.Call(GameStageEventConst.OnStageExit, new string[] { last_stage.StageName, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
                    XEvent.Call($"{GameStageEventConst.OnStageExit}{last_stage.StageName}", newStage.StageName, GameStageEventConst.GameStageEventGroupName);
                    #endregion

                    m_CurrentStage.OnExit(newStage.StageName);
                    m_CurrentStage = newStage;
                    Debug.Log($"[{GameStageConst.ServiceName}]{(XCore.GetMainInstance().IsCmnHans() ? "切换Stage:" : "Switch Stage:")}" +
                              $"<color=#{TinaX.Internal.XEditorColorDefine.Color_Normal_Pure_16}>{last_stage.StageName}</color> --> <color=#{TinaX.Internal.XEditorColorDefine.Color_Emphasize_16}>{newStage.StageName}</color>");

                    newStage.OnEnter(last_stage.StageName);

                    #region Enter Event 广播进入事件
                    XEvent.Call(GameStageEventConst.OnStageEnter, new string[] { newStage.StageName, last_stage.StageName }, GameStageEventConst.GameStageEventGroupName);
                    XEvent.Call($"{GameStageEventConst.OnStageExit}{newStage.StageName}", last_stage.StageName, GameStageEventConst.GameStageEventGroupName);
                    #endregion

                    //广播切换事件
                    XEvent.Call(GameStageEventConst.OnStageChanged, new string[] { last_stage.StageName, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
                }
            }
            else
            {
                m_CurrentStage = newStage;

                bool isHans = XCore.GetMainInstance().IsCmnHans();
                Debug.Log($"[{GameStageConst.ServiceName}]{(isHans ? "切换Stage:" : "Switch Stage:")}" +
                          $"<color=#{TinaX.Internal.XEditorColorDefine.Color_Safe_16}>*{(isHans?"空 Stage":"No Stage")}*</color> --> <color=#{TinaX.Internal.XEditorColorDefine.Color_Emphasize_16}>{newStage.StageName}</color>");


                newStage.OnEnter(string.Empty);

                //广播进入事件
                XEvent.Call(GameStageEventConst.OnStageEnter, new string[] { newStage.StageName, string.Empty }, GameStageEventConst.GameStageEventGroupName);
                XEvent.Call($"{GameStageEventConst.OnStageExit}{newStage.StageName}", string.Empty, GameStageEventConst.GameStageEventGroupName);

                //广播切换事件
                XEvent.Call(GameStageEventConst.OnStageChanged, new string[] { string.Empty, newStage.StageName }, GameStageEventConst.GameStageEventGroupName);
            }
        }
Ejemplo n.º 2
0
        private async Task useRegion(XRegion region)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            mDicts.Clear();
            if (region.JsonDicts != null && region.JsonDicts.Count > 0)
            {
                List <Task <I18NTable> > load_task = new List <Task <I18NTable> >();
                List <int> load_task_index         = new List <int>();
                for (var i = 0; i < region.JsonDicts.Count; i++)
                {
                    if (!region.JsonDicts[i].LoadPath.IsNullOrEmpty())
                    {
                        load_task.Add(this.getJsonDict(region.JsonDicts[i].LoadPath));
                        load_task_index.Add(i);
                    }
                }

                if (load_task.Count > 0)
                {
                    await Task.WhenAll(load_task);

                    for (var i = 0; i < load_task.Count; i++)
                    {
                        foreach (var item in load_task)
                        {
                            var    json_obj     = item.Result;
                            bool   base64_value = region.JsonDicts[load_task_index[i]].Base64Value;
                            string groupName    = region.JsonDicts[load_task_index[i]].GroupName;
                            if (groupName.IsNullOrEmpty())
                            {
                                groupName = I18NConst.DefaultGroupName;
                            }

                            foreach (var kv in json_obj.data)
                            {
                                if (!mDicts.ContainsKey(groupName))
                                {
                                    mDicts.Add(groupName, new Dictionary <string, string>());
                                }
                                if (!mDicts[groupName].ContainsKey(kv.k))
                                {
                                    if (base64_value)
                                    {
                                        try
                                        {
                                            string _value = kv.v.DecodeBase64();
                                            mDicts[groupName].Add(kv.k, _value);
                                        }
                                        catch
                                        {
                                            Debug.LogError($"[TinaX.I18N] Decode base64 error: Json: {region.JsonDicts[load_task_index[i]].LoadPath}   | Key: {kv.k}");
                                        }
                                    }
                                    else
                                    {
                                        mDicts[groupName].Add(kv.k, kv.v);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (region.AssetDicts != null && region.AssetDicts.Count > 0)
            {
                foreach (var item in region.AssetDicts)
                {
                    if (item.Asset == null)
                    {
                        continue;
                    }
                    string groupName = item.GroupName.IsNullOrEmpty() ? I18NConst.DefaultGroupName : item.GroupName;
                    foreach (var kv in item.Asset.data)
                    {
                        if (!mDicts.ContainsKey(groupName))
                        {
                            mDicts.Add(groupName, new Dictionary <string, string>());
                        }
                        if (!mDicts[groupName].ContainsKey(kv.k))
                        {
                            mDicts[groupName].Add(kv.k, kv.v);
                        }
                    }
                }
            }

            mRegionName = region.Name;
            XEvent.Call(I18NEventConst.OnUseRegion, region.Name, TinaX.Const.FrameworkConst.FrameworkEventGroupName);
        }
Ejemplo n.º 3
0
        private async Task useRegion(XRegion region)
        {
            if (region == null)
            {
                throw new ArgumentNullException(nameof(region));
            }

            mDicts.Clear();
            if (region.JsonDicts != null && region.JsonDicts.Count > 0)
            {
                List <Task <I18NTable> > load_task = new List <Task <I18NTable> >();
                List <int> load_task_index         = new List <int>();
                for (var i = 0; i < region.JsonDicts.Count; i++)
                {
                    if (!region.JsonDicts[i].LoadPath.IsNullOrEmpty())
                    {
                        load_task.Add(this.getJsonDict(region.JsonDicts[i].LoadPath));
                        load_task_index.Add(i);
                    }
                }

                if (load_task.Count > 0)
                {
                    await Task.WhenAll(load_task);

                    for (var i = 0; i < load_task.Count; i++)
                    {
                        foreach (var item in load_task)
                        {
                            var    json_obj     = item.Result;
                            bool   base64_value = region.JsonDicts[load_task_index[i]].Base64Value;
                            string groupName    = region.JsonDicts[load_task_index[i]].GroupName;
                            if (groupName.IsNullOrEmpty())
                            {
                                groupName = I18NConst.DefaultGroupName;
                            }

                            foreach (var kv in json_obj.data)
                            {
                                if (!mDicts.ContainsKey(groupName))
                                {
                                    mDicts.Add(groupName, new Dictionary <string, string>());
                                }
                                if (!mDicts[groupName].ContainsKey(kv.k))
                                {
                                    if (base64_value)
                                    {
                                        try
                                        {
                                            string _value = kv.v.DecodeBase64();
                                            mDicts[groupName].Add(kv.k, _value);
                                        }
                                        catch
                                        {
                                            Debug.LogError($"[TinaX.I18N] Decode base64 error: Json: {region.JsonDicts[load_task_index[i]].LoadPath}   | Key: {kv.k}");
                                        }
                                    }
                                    else
                                    {
                                        mDicts[groupName].Add(kv.k, kv.v);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (region.AssetDicts != null && region.AssetDicts.Count > 0)
            {
                foreach (var item in region.AssetDicts)
                {
                    if (item.Asset == null)
                    {
                        continue;
                    }
                    string groupName = item.GroupName.IsNullOrEmpty() ? I18NConst.DefaultGroupName : item.GroupName;
                    foreach (var kv in item.Asset.data)
                    {
                        if (!mDicts.ContainsKey(groupName))
                        {
                            mDicts.Add(groupName, new Dictionary <string, string>());
                        }
                        if (!mDicts[groupName].ContainsKey(kv.k))
                        {
                            mDicts[groupName].Add(kv.k, kv.v);
                        }
                    }
                }
            }

            m_RegionName = region.Name;
            this.m_CurrentLanguageNames = region.BindLanguage.Select(l => l.ToString()).ToArray();
            this.m_CurrentLanguages     = region.BindLanguage.ToArray();
            Debug.Log($"[{I18NConst.ServiceName}] {(IsCmnHans() ? "使用区域:" : "Use region: ")} <color=#{TinaX.Internal.XEditorColorDefine.Color_Emphasize_16}>{region.Name}</color>");
            XEvent.Call(I18NEventConst.OnUseRegion, region.Name, TinaX.Const.FrameworkConst.FrameworkEventGroupName);
        }