public static GameObject CreateGameObjectWithAudio(string goName, TsAudio.BaseData baseData, AudioClip clip, bool loop, bool isDontDestroyOnLoad)
    {
        if (string.IsNullOrEmpty(goName))
        {
            goName = "_Audio: " + clip.name;
        }
        TsAudio tsAudio = TsAudioCreator.Create(baseData);

        if (tsAudio == null)
        {
            TsLog.LogError("CreateGameObjectWithAudio()~! Failed Create~! goName= " + goName, new object[0]);
            return(null);
        }
        GameObject gameObject = new GameObject(goName, new Type[]
        {
            typeof(AudioSource)
        });

        tsAudio.RefAudioSource = gameObject.audio;
        tsAudio.RefAudioClip   = clip;
        TsAudioAdapter tsAudioAdapter = TsAudioAdapter.TryToAddAdapter(gameObject, tsAudio);

        tsAudioAdapter.GetAudioEx().baseData.Loop = loop;
        tsAudioAdapter.GetAudioEx().baseData.IsDontDestroyOnLoad = isDontDestroyOnLoad;
        return(gameObject);
    }
Exemple #2
0
 private void _SetSwitchData(GameObject go, TsSceneSwitcher.SwitchData switchData)
 {
     switchData.TargetGO = go;
     if (go.renderer != null)
     {
         switchData.EnableRender = ((!go.renderer.enabled) ? TsSceneSwitcher.SwitchData.ERender.Disable : TsSceneSwitcher.SwitchData.ERender.Enable);
     }
     if (go.audio != null)
     {
         TsAudioAdapter component = switchData.TargetGO.GetComponent <TsAudioAdapter>();
         if (component != null)
         {
             switchData.IsPlayingAudio = ((!component.GetAudioEx().PlayOnDownload) ? TsSceneSwitcher.SwitchData.EAudio.Stop : TsSceneSwitcher.SwitchData.EAudio.Playing);
             component.GetAudioEx().Stop();
         }
     }
     if (go.animation != null)
     {
         Animation animation = switchData.TargetGO.animation;
         if (animation != null)
         {
             switchData.IsPlayingAnimation = ((!animation.playAutomatically || !(animation.clip != null)) ? TsSceneSwitcher.SwitchData.EAnimation.Stop : TsSceneSwitcher.SwitchData.EAnimation.Playing);
             animation.Stop();
         }
     }
 }
Exemple #3
0
 private void _SearchAudioAdapter()
 {
     this._currentPlayAudios.Clear();
     this._currentStopAudios.Clear();
     TsAudioAdapter[] array = UnityEngine.Object.FindObjectsOfType(typeof(TsAudioAdapter)) as TsAudioAdapter[];
     if (array.Length >= 1)
     {
         TsAudioAdapter[] array2 = array;
         for (int i = 0; i < array2.Length; i++)
         {
             TsAudioAdapter tsAudioAdapter = array2[i];
             if (tsAudioAdapter.GetAudioEx().isPlaying)
             {
                 this._currentPlayAudios.Add(tsAudioAdapter);
             }
             if (tsAudioAdapter.GetAudioEx().IsForceStop)
             {
                 this._currentStopAudios.Add(tsAudioAdapter);
             }
         }
     }
 }
Exemple #4
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;
    }
Exemple #5
0
    public static TsAudioAdapter TryToAddAdapter(GameObject go, TsAudio audioEx)
    {
        if (go == null)
        {
            return(null);
        }
        TsAudioAdapter tsAudioAdapter = go.GetComponent <TsAudioAdapter>();

        if (tsAudioAdapter != null && tsAudioAdapter.AudioType != audioEx.baseData.AudioType)
        {
            UnityEngine.Object.DestroyImmediate(tsAudioAdapter);
            tsAudioAdapter = null;
        }
        if (tsAudioAdapter == null)
        {
            if (go.audio != null)
            {
                go.audio.playOnAwake = false;
            }
            switch (audioEx.baseData.AudioType)
            {
            case EAudioType.SFX:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterSFX>();
                break;

            case EAudioType.BGM:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterBGM>();
                break;

            case EAudioType.AMBIENT:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterAmbient>();
                break;

            case EAudioType.UI:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterUI>();
                break;

            case EAudioType.VOICE:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterVoice>();
                break;

            case EAudioType.SYSTEM:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterSystem>();
                break;

            case EAudioType.GAME_DRAMA:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterGameDrama>();
                break;

            case EAudioType.ENVIRONMENT:
                tsAudioAdapter = go.AddComponent <TsAudioAdapterEnvironment>();
                break;

            default:
                TsLog.Assert(false, "Check the AudioType~!!! Invalid Type= {0}", new object[]
                {
                    audioEx.baseData.AudioType
                });
                break;
            }
        }
        if (tsAudioAdapter == null)
        {
            TsLog.LogError("Check the EAudioType~! is Invaild Value EAudioType = " + audioEx.baseData.AudioType, new object[0]);
            return(null);
        }
        if (!tsAudioAdapter._InitAudioEx(audioEx))
        {
            UnityEngine.Object.Destroy(tsAudioAdapter);
            return(null);
        }
        audioEx.CheckAndSetNeedRefs(tsAudioAdapter);
        return(tsAudioAdapter);
    }