Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 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();
         }
     }
 }
Ejemplo n.º 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);
             }
         }
     }
 }
Ejemplo n.º 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;
    }