Beispiel #1
0
    private void OnValidate()
    {
        if (_screenFader == null)
        {
            _screenFader = GetComponentInChildren <ScreenFader> ();
        }

        if (_sceneController == null)
        {
            _sceneController = GetComponentInChildren <SceneController> ();
        }

        if (_eventManager == null)
        {
            _eventManager = GetComponentInChildren <EventManager> ();
        }

        if (_vfxController == null)
        {
            _vfxController = GetComponentInChildren <VFXController> ();
        }

        if (_backgroundMusicPlayer == null)
        {
            _backgroundMusicPlayer = GetComponentInChildren <BackgroundMusicPlayer> ();
        }
    }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
         DontDestroyOnLoad(this.gameObject);
         return;
     }
     Destroy(this.gameObject);
 }
Beispiel #3
0
 void Awake()
 {
     _instance                 = this;
     player                    = GameObject.FindGameObjectWithTag(PlayerTag);
     gameDialogueObject        = FindObjectOfType(typeof(GameDialogue)) as GameDialogue;
     scenarioControlObject     = FindObjectOfType(typeof(ScenarioControl)) as ScenarioControl;
     backGroundMusicPlayer     = FindObjectOfType(typeof(BackgroundMusicPlayer)) as BackgroundMusicPlayer;
     checkPointManager         = FindObjectOfType(typeof(CheckPointManager)) as CheckPointManager;
     playerRuntimeCameraConfig = FindObjectOfType(typeof(PlayerCameraRuntimeConfig)) as PlayerCameraRuntimeConfig;
 }
Beispiel #4
0
 void Awake()
 {
     if (instance != null)
     {
         Destroy(gameObject);
         print("Duplicate destroyed");
     }
     else
     {
         instance = this;
         GameObject.DontDestroyOnLoad(gameObject);
     }
 }
    void Awake()
    {
        // If there's already a player...
        if (Instance != null && Instance != this)
        {
            //...if it use the same music clip, we set the audio source to be at the same position, so music don't restart
            if (Instance.musicAudioClip == musicAudioClip)
            {
                m_TransferMusicTime = true;
            }

            //...if it use the same ambient clip, we set the audio source to be at the same position, so ambient don't restart
            if (Instance.ambientAudioClip == ambientAudioClip)
            {
                m_TransferAmbientTime = true;
            }

            // ... destroy the pre-existing player.
            m_OldInstanceToDestroy = Instance;
        }

        s_Instance = this;

        DontDestroyOnLoad(gameObject);

        m_MusicAudioSource      = gameObject.AddComponent <AudioSource> ();
        m_MusicAudioSource.clip = musicAudioClip;
        m_MusicAudioSource.outputAudioMixerGroup = musicOutput;
        m_MusicAudioSource.loop   = true;
        m_MusicAudioSource.volume = musicVolume;

        if (musicPlayOnAwake)
        {
            m_MusicAudioSource.time = 0f;
            m_MusicAudioSource.Play();
        }

        m_AmbientAudioSource      = gameObject.AddComponent <AudioSource>();
        m_AmbientAudioSource.clip = ambientAudioClip;
        m_AmbientAudioSource.outputAudioMixerGroup = ambientOutput;
        m_AmbientAudioSource.loop   = true;
        m_AmbientAudioSource.volume = ambientVolume;

        if (ambientPlayOnAwake)
        {
            m_AmbientAudioSource.time = 0f;
            m_AmbientAudioSource.Play();
        }
    }
    /////////////////////////////////////////////////////////////////////////////

    //
    //Initializers
    //

    private void Start()
    {
        //fill data
        gameData        = FindObjectOfType <GameData>();
        tempOptionData  = gameData.GameOptionData;
        backgroundMusic = FindObjectOfType <BackgroundMusicPlayer>();

        //default color preinitialization
        defaultDifficultyColor = easy.colors.normalColor;
        defaultEndlessBtnColor = endless.colors.normalColor;

        //fill data in UI components
        masterVolume.value = gameData.GameOptionData.masterVolume;
        if (tempOptionData.GameDifficulty == OptionData.Difficulty.Easy)
        {
            OnClickEasy();
        }
        else if (tempOptionData.GameDifficulty == OptionData.Difficulty.Normal)
        {
            OnClickNormal();
        }
        else
        {
            OnClickHard();
        }
        armyWidth.text    = tempOptionData.ArmySize.x.ToString();
        armyHeight.text   = tempOptionData.ArmySize.y.ToString();
        health.text       = tempOptionData.Health.ToString();
        maxScore.text     = tempOptionData.maxScore.ToString();
        scorePerKill.text = tempOptionData.ScorePerKill.ToString();
        SetEndless(tempOptionData.endless);

        //sign in to option UI events
        masterVolume.onValueChanged.AddListener(OnMasterVolumeChanged);
        easy.onClick.AddListener(OnClickEasy);
        normal.onClick.AddListener(OnClickNormal);
        hard.onClick.AddListener(OnClickHard);
        armyWidth.onEndEdit.AddListener(OnEndEditArmyWidth);
        armyHeight.onEndEdit.AddListener(OnEndEditArmyHeight);
        health.onEndEdit.AddListener(OnEndEditHealth);
        endless.onClick.AddListener(OnClickEndless);
        maxScore.onEndEdit.AddListener(OnEndEditMaxScore);
        defaultBtn.onClick.AddListener(OnClickDefault);
        applyBtn.onClick.AddListener(OnClickApply);
        //sign in to back button click event
        Button back = GameObject.Find("Back").transform.GetChild(0).GetComponent <Button>();

        back.onClick.AddListener(OnBackClick);
    }
    void Awake()
    {
        instance = this;

        radio = GetComponent <AudioSource>();

        try
        {
            radio.loop = true;
            radio.clip = backgroundMusicClip;
            radio.Play();
        }
        catch (Exception e)
        {
            Debug.LogWarning(e.Message);
        }
    }
    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            if (Instance.musicAudioClip == musicAudioClip)
            {
                transferMusicTime = true;
            }

            if (Instance.ambientAudioClip == ambientAudioClip)
            {
                transferAmbientTime = true;
            }

            oldInstanceToDestroy = Instance;
        }

        instance = this;

        DontDestroyOnLoad(gameObject);

        musicAudioSource      = gameObject.AddComponent <AudioSource>();
        musicAudioSource.clip = musicAudioClip;
        musicAudioSource.outputAudioMixerGroup = musicOutput;
        musicAudioSource.loop   = true;
        musicAudioSource.volume = musicVolume;

        if (musicPlayOnAwake)
        {
            musicAudioSource.time = 0f;
            musicAudioSource.Play();
        }

        ambientAudioSource      = gameObject.AddComponent <AudioSource>();
        ambientAudioSource.clip = ambientAudioClip;
        ambientAudioSource.outputAudioMixerGroup = ambientOutput;
        ambientAudioSource.loop   = true;
        ambientAudioSource.volume = ambientVolume;

        if (ambientPlayOnAwake)
        {
            ambientAudioSource.time = 0f;
            ambientAudioSource.Play();
        }
    }
 void Initialize()
 {
     if (singleton != null)
     {
         if (this == singleton)
         {
             InitializeSingleton();
         }
         else
         {
             Destroy(gameObject);
         }
     }
     else
     {
         singleton = this;
         InitializeSingleton();
     }
 }
Beispiel #10
0
 private void Awake()
 {
     _audioSourcePool = GetComponent <AudioSourcePool>();
     _musicPlayer     = GetComponent <BackgroundMusicPlayer>();
 }