Example #1
0
 /// <summary>
 /// Plaies the sound.
 /// </summary>
 /// <param name="soundName">Sound name. (with ext  e.g. click.mp3)</param>
 /// <param name="valume">Valume.</param>
 public static void PlaySound(string soundName, float valume)
 {
     if (!MgrData.GetBool(MgrData.appSettingsName, "XLAF.sound", true))
     {
         return;
     }
     if (soundName.IndexOf(".") < 0)
     {
         XLAFInnerLog.Warning("You must use soundName's extension, for example \"click.mp3\"");
         return;
     }
                 #if UNITY_ANDROID && !UNITY_EDITOR
     int soundId = 0;
     if (androidSoundIds.TryGetValue(soundName, out soundId))
     {
         audioCenter.Call("PlaySound", soundId, valume);
     }
                 #else
     AudioClip clip = Resources.Load <AudioClip> (_GetAudioSource(soundName.Split(new char[] { '.' }) [0]));
     if (clip != null)
     {
         soundSource.volume = valume;
         soundSource.PlayOneShot(clip);
     }
                 #endif
 }
Example #2
0
        public static void PlayMusic(string musicName, bool loop = true, float fadeInTime = 0f)
        {
            if (!MgrData.GetBool(MgrData.appSettingsName, "XLAF.music", true))
            {
                return;
            }
            if (musicName.IndexOf(".") < 0)
            {
                XLAFInnerLog.Warning("You must use musicName's extension, for example \"click.mp3\"");
                return;
            }
            AudioClip clip = Resources.Load <AudioClip> (_GetAudioSource(musicName.Split(new char[] { '.' }) [0]));

            musicSource.loop = loop;
            musicSource.clip = clip;
            musicSource.Play();
            if (fadeInTime <= 0f)
            {
                musicSource.volume = maxMusicVolume;
            }
            else
            {
                _FadeInOutVolume(musicSource, fadeInTime, 0, maxMusicVolume);
            }
        }
Example #3
0
        /// <summary>
        /// Preloads the audio.
        /// </summary>
        /// <param name="soundName">Sound name. (with ext  e.g. click.mp3)</param>
        public static void PreloadAudio(string soundName)
        {
            if (soundName.IndexOf(".") < 0)
            {
                XLAFInnerLog.Warning("You must use soundName's extension, for example \"click.mp3\"");
                return;
            }
            int id = audioCenter.Call <int> ("LoadSound", _GetAudioSource(soundName));

            androidSoundIds.Add(soundName, id);
        }
Example #4
0
 /// <summary>
 /// Sets the scene object.<para></para>
 /// !WAINNING!<para></para>
 /// This function is use for SceneObject ONLY.
 /// You should NOT call this function.
 /// </summary>
 /// <param name="obj">Object.</param>
 internal void SetSceneObject(SceneObject obj)
 {
     if (_sceneObject == null)
     {
         this._sceneObject = obj;
     }
     else
     {
         XLAFInnerLog.Warning("You can't change sceneObject");
     }
 }
Example #5
0
 /// <summary>
 /// Sets the name of the scene.<para></para>
 /// !WAINNING!<para></para>
 /// This function is use for SceneObject ONLY.
 /// You should NOT call this function.
 /// </summary>
 /// <param name="name">Name.</param>
 internal void SetSceneName(string name)
 {
     if (string.IsNullOrEmpty(this._sceneName))
     {
         this._sceneName = name;
     }
     else
     {
         XLAFInnerLog.Warning("You can't change sceneName");
     }
 }
Example #6
0
        /// <summary>
        /// Removes the listener.
        /// </summary>
        /// <param name="eventName">Event name.</param>
        /// <param name="handler">Handler.</param>
        public static void RemoveListener(object eventName, Action <XLAF_Event> handler)
        {
            List <XLAF_Event> list;

            if (!listeners.TryGetValue(eventName, out list))
            {
                XLAFInnerLog.Warning("No callback functions names ", eventName);
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list [i].action == handler)
                {
                    list.Remove(list [i]);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Dispatch the data with event name.
        /// </summary>
        /// <param name="eventName">Event name.</param>
        /// <param name="data">Data.</param>
        public static void Dispatch(object eventName, object data = null)
        {
            List <XLAF_Event> list;

            if (!listeners.TryGetValue(eventName, out list))
            {
                XLAFInnerLog.Warning("No callback functions names ", eventName);
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list [i].action != null)
                {
                    list [i].data = data;
                    list [i].action(list [i]);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Adds the click.
        /// </summary>
        /// <param name="go">Go.</param>
        /// <param name="preventDoubleClickTime">Prevent double click time (second).</param>
        /// <param name="onUIEvent">On user interface event.</param>
        public static void AddClick(GameObject go, float preventDoubleClickTime, Action <XLAF_UIEvent> onUIEvent)
        {
            bool isDelaying = false;

            XLAFEventTriggerListener.Get(go).onClick = (GameObject g, PointerEventData e) => {
                if (isDelaying)
                {
                    XLAFInnerLog.Warning(string.Format("You pressed {0} in {1} second(s), will not response.", g.name, preventDoubleClickTime));
                    return;
                }
                isDelaying = true;
                ModUtils.DelayCall(preventDoubleClickTime, () => {
                    isDelaying = false;
                });
                XLAF_UIEvent evt = new XLAF_UIEvent();
                evt.eventData = e;
                evt.target    = g;
                evt.phase     = Phase.Click;
                onUIEvent(evt);
            };
        }
Example #9
0
        /// <summary>
        /// Dispatch the XLAF_Event.
        /// </summary>
        /// <param name="e">XLAF_Event.</param>
        public static void Dispatch(XLAF_Event e)
        {
            if (e.name == null)
            {
                XLAFInnerLog.Error("Event is not right", e);
                return;
            }
            List <XLAF_Event> list;

            if (!listeners.TryGetValue(e.name, out list))
            {
                XLAFInnerLog.Warning("No callback functions names ", e.name);
                return;
            }
            for (int i = 0; i < list.Count; i++)
            {
                if (list [i].action != null)
                {
                    list [i].data = e.data;
                    list [i].action(list [i]);
                }
            }
        }