Exemplo n.º 1
0
    public void Switch(TsSceneSwitcher.ESceneType eSceneType)
    {
        if (!TsSceneSwitcher.IsValidSceneType(eSceneType))
        {
            TsLog.LogWarning("Invalid SceneType= " + eSceneType, new object[0]);
            return;
        }
        GameObject x = this._GetSwitchData_RootSceneGO(eSceneType);

        if (x == null)
        {
            return;
        }
        foreach (KeyValuePair <GameObject, TsSceneSwitcher._SwitchDataList> current in this._switchDataDic)
        {
            bool flag = false;
            if (x == current.Key)
            {
                flag = true;
            }
            foreach (TsSceneSwitcher.SwitchData current2 in current.Value)
            {
                try
                {
                    if (current2.TargetGO)
                    {
                        this._SetSwitchData(current2.TargetGO, current2);
                        NkUtil.SetChildActiveExceptChar(current2.TargetGO, flag);
                        if (current2.TargetGO.activeInHierarchy)
                        {
                            if (current2.EnableRender != TsSceneSwitcher.SwitchData.ERender.Not_Have)
                            {
                                current2.TargetGO.renderer.enabled = (current2.EnableRender == TsSceneSwitcher.SwitchData.ERender.Enable);
                            }
                            if (current2.IsPlayingAudio != TsSceneSwitcher.SwitchData.EAudio.Not_Have && current2.IsPlayingAudio == TsSceneSwitcher.SwitchData.EAudio.Playing)
                            {
                                TsAudioAdapter component = current2.TargetGO.GetComponent <TsAudioAdapter>();
                                if (component != null)
                                {
                                    component.GetAudioEx().RestoreToPlay();
                                }
                            }
                            if (current2.IsPlayingAnimation != TsSceneSwitcher.SwitchData.EAnimation.Not_Have && current2.IsPlayingAnimation == TsSceneSwitcher.SwitchData.EAnimation.Playing)
                            {
                                Animation animation = current2.TargetGO.animation;
                                if (null != animation)
                                {
                                    AnimationState animationState = current2.TargetGO.animation[animation.clip.name];
                                    if (null != animationState)
                                    {
                                        float time = UnityEngine.Random.Range(0f, animationState.length);
                                        animationState.time = time;
                                        animation.Play();
                                    }
                                }
                            }
                            Terrain componentInChildren = current2.TargetGO.GetComponentInChildren <Terrain>();
                            if (componentInChildren != null)
                            {
                                componentInChildren.enabled = flag;
                            }
                            Camera componentInChildren2 = current2.TargetGO.GetComponentInChildren <Camera>();
                            if (componentInChildren2 != null)
                            {
                                componentInChildren2.enabled = flag;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    TsLog.LogError("DataName= " + current2.TargetGOName + "   Exception= " + ex.ToString(), new object[0]);
                }
            }
        }
        this.CurrentSceneType = eSceneType;
    }