Esempio n. 1
0
        /// <summary>
        /// 游戏框架组件初始化。
        /// </summary>
        protected override void Awake()
        {
            base.Awake();

            m_SoundMethods = CentorPivot.This.GetComponent <SoundComponent>();
            if (m_SoundMethods == null)
            {
                Log.Fatal("Sound manager is invalid.");
                return;
            }

            m_AudioListener = gameObject.GetOrAddComponent <AudioListener>();

            SceneManager.sceneLoaded   += OnSceneLoaded;
            SceneManager.sceneUnloaded += OnSceneUnloaded;

            if (EventComponent.This == null)
            {
                Log.Fatal("Event component is invalid.");
                return;
            }

            m_SoundMethods.SetResourceManager(CentorPivot.This.GetComponent <ResourceComponent>());

            SoundHelperBase soundHelper = (SoundHelperBase)CreateHelper.Create(m_SoundHelperTypeName);

            if (soundHelper == null)
            {
                Log.Error("Can not create sound helper.");
                return;
            }

            m_SoundMethods.SetSoundHelper(soundHelper);

            if (m_InstanceRoot == null)
            {
                m_InstanceRoot = new GameObject("Sound Instances").transform;
                m_InstanceRoot.SetParent(gameObject.transform);
                m_InstanceRoot.localScale = Vector3.one;
            }

            for (int i = 0; i < m_SoundGroups.Length; i++)
            {
                if (!AddSoundGroup(m_SoundGroups[i].Name, m_SoundGroups[i].AvoidBeingReplacedBySamePriority, m_SoundGroups[i].Mute, m_SoundGroups[i].Volume, m_SoundGroups[i].AgentHelperCount))
                {
                    Log.Warning("Add sound group '{0}' failure.", m_SoundGroups[i].Name);
                    continue;
                }
            }
        }