Beispiel #1
0
        public static string DecodeZZZ(byte[] bytes)
        {
            string res = "";

            try {
                if (Encoding.UTF8.GetString(bytes, 0, 3) == "zzz")
                {
                    List <byte> lst = new List <byte> ();
                    for (int i = 3, index = 1; i < bytes.Length; i++, index++)
                    {
                        int r = (int)bytes [i];
                        int n = index + (int)Mathf.Floor(1.0f * index / _zzz_key_len);
                        n = (n - 1) % _zzz_key_len + 1;
                        int key = (int)_zzz_key_bytes [n - 1];
//					XLAFInnerLog.Debug ("before:", n, r, key);
                        r = r - key - 88;
                        r = (r + 256) % 256;
                        lst.Add((byte)r);
                    }
                    res = Encoding.UTF8.GetString(lst.ToArray());
                }
            } catch (Exception e) {
                XLAFInnerLog.Error(e.ToString());
            }
            return(res);
        }
Beispiel #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);
            }
        }
Beispiel #3
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
 }
Beispiel #4
0
        private static void Load()
        {
            TextAsset str = Resources.Load <TextAsset> ("Lang/" + currentLanguage);

            LanguageConfigs = JSONNode.Parse(str.ToString());
            XLAFInnerLog.Debug("bytes", LanguageConfigs);
        }
Beispiel #5
0
        /// <summary>
        /// Changes the size.
        /// </summary>
        /// <param name="t">gameobject.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        public static void ChangeSize(GameObject t, float?width = null, float?height = null)
        {
            RectTransform rect = t.GetComponent <RectTransform> ();

            if (rect == null)
            {
                XLAFInnerLog.Error("RectTransform is null");
            }
            ChangeSize(rect, width, height);
        }
Beispiel #6
0
        /// <summary>
        /// Changes the position.
        /// </summary>
        /// <param name="t">button.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public static void ChangePos(Button t, float?x = null, float?y = null)
        {
            RectTransform rect = t.image.rectTransform;

            if (rect == null)
            {
                XLAFInnerLog.Error("RectTransform is null");
            }
            ChangePos(rect, x, y);
        }
Beispiel #7
0
        /// <summary>
        /// Adds the setting.
        /// </summary>
        /// <param name="settingsName">Settings name.</param>
        /// <param name="filePathName">File path name.</param>
        /// <param name="defaultFilePathName">Default file path name.</param>
        public static void AddSetting(string settingsName, string filePathName, string defaultFilePathName)
        {
            if (DATA.ContainsKey(settingsName))
            {
                XLAFInnerLog.Error(settingsName + " already exist!");
                return;
            }

            DATA.Add(settingsName, new SettingsData(filePathName, defaultFilePathName));
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XLAF.Public.SceneObject"/> class without asset bundle.
        /// </summary>
        /// <param name="fullSceneNamePath">Full scene name path.</param>
        public SceneObject(string fullSceneNamePath)
        {
            string[] tmp = fullSceneNamePath.Split('/');
            this._sceneName = tmp [tmp.Length - 1];
            UnityEngine.Object _prefab = Resources.Load(fullSceneNamePath);
            XLAFInnerLog.Debug(fullSceneNamePath);
            GameObject scene = (GameObject)UnityEngine.Object.Instantiate(_prefab);

            initAttr(scene, _sceneName);
        }
Beispiel #9
0
 private void TimeOutEnded()
 {
     if (!isRunning)
     {
         return;
     }
     XLAFInnerLog.Debug("TimeOutEnded");
     isRunning = false;
     MgrBackdoor.clickedTimes = 0;
 }
Beispiel #10
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");
     }
 }
Beispiel #11
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);
        }
Beispiel #12
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");
     }
 }
Beispiel #13
0
        //		/// <summary>
        //		/// Loads the bundle.
        //		/// </summary>
        //		/// <returns>The bundle all.</returns>
        //		/// <param name="path">Path.</param>
        //		/// <param name="sceneName">Scene name.</param>
        //		private IEnumerator LoadBundle (string path, string sceneName)
        //		{
        //			WWW bundle = new WWW (path);
        //			yield return bundle;
        //			GameObject scene = (GameObject)UnityEngine.Object.Instantiate (bundle.assetBundle.LoadAsset (sceneName));
        //			initAttr (scene, sceneName);
        //			yield return 1;
        //		}

        /// <summary>
        /// Initializes a new instance of the <see cref="XLAF.Public.SceneObject"/> class with asset bundle.
        /// </summary>
        /// <param name="assetBundleFullPathName">AssetBundle full path name. <para></para>
        /// e.g. /StreamingAssets/Android/all.assetbundle</param>
        /// <param name="sceneName">Scene name.  e.g. Pop1</param>
        public SceneObject(string assetBundleFullPathName, string sceneName)
        {
            XLAFInnerLog.Debug("New SceneObject:", assetBundleFullPathName, sceneName);
            //use async load will cause setParent not right
            //MgrCoroutine.DoCoroutine (LoadBundle (assetBundleFullPathName, sceneName));
            WWW        bundle = new WWW(assetBundleFullPathName);
            GameObject scene  = (GameObject)UnityEngine.Object.Instantiate(bundle.assetBundle.LoadAsset(sceneName));

            bundle.assetBundle.Unload(false);
            this._sceneName = sceneName;
            initAttr(scene, sceneName);
        }
Beispiel #14
0
 private static bool _CheckSettingsName(string settingsName, out SettingsData sd)
 {
     if (DATA.TryGetValue(settingsName, out sd))
     {
         return(true);
     }
     else
     {
         XLAFInnerLog.Error(settingsName + " is not added, please call AddSetting before!");
         return(false);
     }
 }
Beispiel #15
0
        /// <summary>
        /// Gets the string from current language config file with placeholder.<para></para>
        /// e.g. <code>"congratulations! you have got {0} points! rank No. {1}"</code>
        /// </summary>
        /// <returns>The string.</returns>
        /// <param name="stringKeyName">String key name.</param>
        /// <param name="args">Arguments.</param>
        public static string GetString(string stringKeyName, params object[] args)
        {
            string ret = "";

            try {
                ret = LanguageConfigs [stringKeyName].Value;
                ret = string.Format(ret, args);
            } catch (Exception e) {
                XLAFInnerLog.Error("error in MgrMultiLanguage|GetString:", e);
            }

            return(ret);
        }
Beispiel #16
0
        /// <summary>
        /// Gets the child form a transform.
        /// </summary>
        /// <returns>The child.</returns>
        /// <param name="parent">Transform parent.</param>
        /// <param name="childName">Child name.</param>
        /// <typeparam name="T">The type of the child.</typeparam>
        public static T GetChild <T> (Transform parent, string childName)
        {
            Transform t = parent.Find(childName);

            if (t != null)
            {
                return(t.GetComponent <T> ());
            }
            else
            {
                XLAFInnerLog.Error("error! find child null");
                return(default(T));
            }
        }
Beispiel #17
0
        public static void Set(string settingsName, string key, object value, bool autoSave = true)
        {
            SettingsData sd;

            if (DATA.TryGetValue(settingsName, out sd))
            {
                sd.Set(key, value, autoSave);
            }
            else
            {
                XLAFInnerLog.Error(settingsName + " is not added, please call AddSetting before!");
                return;
            }
        }
Beispiel #18
0
        /// <summary>
        /// Gets the child form a transform.
        /// </summary>
        /// <returns>The child.</returns>
        /// <param name="parent">Transform parent.</param>
        /// <param name="childName">Child name.</param>
        public static Transform GetChild(Transform parent, string childName)
        {
            Transform t = parent.Find(childName);

            if (t != null)
            {
                return(t);
            }
            else
            {
                XLAFInnerLog.Error("error! find child null");
                return(null);
            }
        }
Beispiel #19
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]);
                }
            }
        }
Beispiel #20
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]);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Gets the asset bundle path.
        /// </summary>
        /// <returns>The asset bundle path.</returns>
        /// <param name="sceneName">Scene name.</param>
        public static string GetAssetBundlePath(string sceneName)
        {
            if (jsonData == null)
            {
                XLAFInnerLog.Error("please call LoadAssetBundleConfig(path) first");
                return("");
            }
            string v = jsonData [sceneName].Value;

            if (string.IsNullOrEmpty(v))
            {
                return("");
            }
            if (!v.StartsWith("/"))
            {
                v = "/" + v;
            }
            return(v);
        }
Beispiel #22
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);
            };
        }
Beispiel #23
0
 /// <summary>
 /// AES decoder
 /// </summary>
 /// <param name="str">string you want decode with Base64.</param>
 /// <returns>string </returns>
 public static string DecodeAES(string base64Str)
 {
     try {
         byte[]             cipherText = Convert.FromBase64String(base64Str);
         SymmetricAlgorithm des        = Rijndael.Create();
         des.Key = Encoding.UTF8.GetBytes(_aes_key);
         des.IV  = _aes_IV;
         byte[] decryptBytes = new byte[cipherText.Length];
         using (MemoryStream ms = new MemoryStream(cipherText)) {
             using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Read)) {
                 cs.Read(decryptBytes, 0, decryptBytes.Length);
                 cs.Close();
                 ms.Close();
             }
         }
         return(Encoding.UTF8.GetString(decryptBytes).Replace("\0", ""));                    ///remove \0
     } catch (Exception e) {
         XLAFInnerLog.Error(e.ToString());
     }
     return("");
 }
Beispiel #24
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]);
                }
            }
        }
Beispiel #25
0
 /// <summary>
 /// AES encoder
 /// </summary>
 /// <param name="str">string you want to encode.</param>
 /// <returns>encode string with Base64.</returns>
 public static string EncodeAES(string str)
 {
     try {
         SymmetricAlgorithm des        = Rijndael.Create();
         byte[]             inputBytes = Encoding.UTF8.GetBytes(str);
         des.Key = Encoding.UTF8.GetBytes(_aes_key);
         des.IV  = _aes_IV;
         byte[] cipherBytes = null;
         using (MemoryStream ms = new MemoryStream()) {
             using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) {
                 cs.Write(inputBytes, 0, inputBytes.Length);
                 cs.FlushFinalBlock();
                 cipherBytes = ms.ToArray();                         //get byte array
                 cs.Close();
                 ms.Close();
             }
         }
         return(Convert.ToBase64String(cipherBytes));
     } catch (Exception e) {
         XLAFInnerLog.Error(e.ToString());
     }
     return("");
 }
Beispiel #26
0
 /// <summary>
 /// Shows the alert.
 /// </summary>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 /// <param name="okLabel">Ok label.</param>
 /// <param name="cancelLabel">Cancel label.</param>
 /// <param name="neutralLabel">Neutral label.</param>
 /// <param name="actionOK">Action O.</param>
 /// <param name="actionCancel">Action cancel.</param>
 /// <param name="actionNeutral">Action neutral.</param>
 public static void ShowAlert(string title, string message, string okLabel, string cancelLabel, string neutralLabel,
                              Action actionOK, Action actionCancel, Action actionNeutral)
 {
     //!!TODO!!
     XLAFInnerLog.Debug(title, message);
 }
Beispiel #27
0
 /// <summary>
 /// Shows the alert.
 /// </summary>
 /// <param name="title">Title.</param>
 /// <param name="message">Message.</param>
 /// <param name="okLabel">Ok label.</param>
 /// <param name="actionOK">Action O.</param>
 public static void ShowAlert(string title, string message, string okLabel, Action actionOK)
 {
     //!!TODO!!
     XLAFInnerLog.Debug(title, message);
 }
Beispiel #28
0
 /// <summary>
 /// Determines if has asset bundle the specified sceneName.
 /// </summary>
 /// <returns><c>true</c> if has asset bundle the specified sceneName; otherwise, <c>false</c>.</returns>
 /// <param name="sceneName">Scene name.</param>
 public static bool HasAssetBundle(string sceneName)
 {
     XLAFInnerLog.Debug("HasAssetBundle()", jsonData, sceneName, GetAssetBundlePath(sceneName) != "");
     return(GetAssetBundlePath(sceneName) != "");
 }
Beispiel #29
0
 static ModUtils()
 {
     XLAFInnerLog.Info("documentsDirectory", ModUtils.documentsDirectory);
     XLAFInnerLog.Info("temporaryDirectory", ModUtils.temporaryDirectory);
     XLAFInnerLog.Info("streamingDirectory", ModUtils.streamingDirectory);
 }
Beispiel #30
0
 static MgrMultiLanguage()
 {
     currentLanguage = MgrData.GetString(MgrData.appSettingsName, "XLAF.language", DEFAULT_LANGUAGE);
     XLAFInnerLog.Debug("currentLanguage", currentLanguage);
     Load();
 }