void Awake()
        {
            string lang = PlayerPrefs.GetString("Language", "");

            if (!string.IsNullOrEmpty(lang))
            {
                if (Enum.TryParse <Language>(lang, out var language))
                {
                    currentLanguage = language;
                    return;
                }
                DebugOnly.Error($"Invalid language in settings: {lang}");
            }

            var sysLang = Application.systemLanguage;

            switch (sysLang)
            {
            case SystemLanguage.Russian: currentLanguage = Language.Russian; return;

            case SystemLanguage.English: currentLanguage = Language.English; return;
            }

            DebugOnly.Error($"Unsupported system language \"{sysLang}\", using English instead.");
            currentLanguage = Language.English;
        }
Esempio n. 2
0
 public void Dispose()
 {
     if (List != null)
     {
         List.Remove(this);
         DebugOnly.Check(List == null, "Handle was not properly removed from the list.");
     }
 }
Esempio n. 3
0
        public void Push(ISceneState state)
        {
            DebugOnly.Check(!states.Contains(state), $"GameState is already on the stack.");

            states.Add(state);
            statesListChanged = true;
            (state as ISceneStateInternal)?.InternalActivate();
        }
 public ISoundChannel GetChannel(string name)
 {
     if (channelDict.TryGetValue(name, out var channel))
     {
         return(channel);
     }
     DebugOnly.Error($"Sound channel '{name}' was not found.");
     return(null);
 }
        internal void InternalInit(AudioMixer mixer)
        {
            channelEnabled = PlayerPrefs.GetInt($"{Name}Enabled", 1) != 0;
            volume         = PlayerPrefs.GetFloat($"{Name}Volume", 1.0f);
            volumeChanged  = true;

            var groups = mixer.FindMatchingGroups(Name);

            DebugOnly.Check(groups.Length > 0, $"Didn't find mixer group for \"{Name}\".");
            mixerGroup = groups[0];
        }
        void Awake()
        {
            channelDict = new Dictionary <string, ISoundChannel>();
            foreach (var channel in Channels)
            {
                DebugOnly.Check(!channelDict.ContainsKey(channel.Name), $"Duplicate channel name: '{channel.Name}'.");
                channelDict[channel.Name] = channel;
                channel.InternalInit(Mixer);
            }

            Sfx   = GetChannel("Sfx");
            Music = GetChannel("Music");
        }
Esempio n. 7
0
        public void Pop(ISceneState state)
        {
            statesListChanged = true;
            states.Remove(state);

            if (CurrentState == state)
            {
                (CurrentState as ISceneStateInternal)?.InternalResignTopmost();
                CurrentState = null;
            }

            (state as ISceneStateInternal)?.InternalDeactivate();

            DebugOnly.Check(states.Count != 0, "GameState stack is empty.");
        }
Esempio n. 8
0
        public void Add(ref ObserverHandle handle, T observer)
        {
            if (handle == null)
            {
                handle = new ObserverHandle();
            }

            DebugOnly.Check(observer != null, "Observer is null.");
            DebugOnly.Check(handle.List == null, "Handle is already in use.");

            handle.Index = list.Count;
            handle.List  = this;
            list.Add(new Item {
                handle = handle, observer = observer
            });
        }
Esempio n. 9
0
        public void Remove(ObserverHandle handle)
        {
            DebugOnly.Check(handle != null, "Handle is null.");
            DebugOnly.Check(handle.List == this, "Handle is not registered with this list.");

            int lastIndex = list.Count - 1;

            if (handle.Index != lastIndex)
            {
                var replacement = list[lastIndex];
                list[handle.Index]       = replacement;
                replacement.handle.Index = handle.Index;
            }

            handle.List = null;
            list.RemoveAt(lastIndex);
        }
Esempio n. 10
0
 void IObserverList.Add(ref ObserverHandle handle, object observer)
 {
     if (observer is T typedObserver)
     {
         Add(ref handle, typedObserver);
     }
     else
     {
         if (observer == null)
         {
             DebugOnly.Error("Observer is null.");
         }
         else
         {
             DebugOnly.Error($"Was expecting type {typeof(T)}, got type {observer.GetType().Name}.");
         }
     }
 }
        public void Stop(SoundHandle handle)
        {
            if (!handle.IsValid)
            {
                DebugOnly.Error("Attempted to stop sound with an invalid SoundHandle.");
                return;
            }

            int n = soundSources.Count;

            while (n-- > 0)
            {
                if (soundSources[n] == handle.Source)
                {
                    soundSources.RemoveAt(n);
                    handle.Source.Dispose();
                    return;
                }
            }

            DebugOnly.Error("Attempted to stop sound that is not playing in this channel.");
        }
Esempio n. 12
0
 public void DOKill(bool complete)
 {
     DebugOnly.Check(IsValid, "Attempted to kill tweens with an invalid SoundHandle.");
     Source.DOKill(complete);
 }
Esempio n. 13
0
 public Tweener DOFade(float endValue, float time)
 {
     DebugOnly.Check(IsValid, "Attempted to fade volume with an invalid SoundHandle.");
     return(Source.DOFade(endValue, time));
 }