Exemplo n.º 1
0
        /// <summary>
        /// Initialize.
        /// </summary>
        private static void _Initialize()
        {
            if (mApplicationObject == null)
            {
                string objName = typeof(MyApplicationEvent).Name;

                mApplicationObject = MyUtilities.FindObjectInRoot(objName);

                if (mApplicationObject == null)
                {
                    mApplicationObject = new GameObject(objName);
                }

                GameObject.DontDestroyOnLoad(mApplicationObject);
            }

            if (mApplicationEventInstance == null)
            {
                mApplicationEventInstance = mApplicationObject.GetComponent <ApplicationInstance>();

                if (mApplicationEventInstance == null)
                {
                    mApplicationEventInstance = mApplicationObject.AddComponent(typeof(ApplicationInstance)) as ApplicationInstance;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check text contains forbidden text.
        /// </summary>
        /// <param name="text">a text which needs to check</param>
        /// <param name="isNormalizeWhitespaces">normalize whitespaces before handling</param>
        /// <param name="isIgnoreCase">ignore case while finding forbidden words</param>
        public static bool ExistForbiddenWord(string text, bool isNormalizeWhitespaces = false, bool isIgnoreCase = true)
        {
            if (mForbiddenTexts == null)
            {
                LoadData();
            }

            if (text[0] == ' ' && text.Trim().Length == 0)
            {
                return(true);
            }

            if (isNormalizeWhitespaces)
            {
                text = MyUtilities.NormalizeWhitespaces(text);
            }

            StringComparison comparison        = isIgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
            string           textForComparison = isIgnoreCase ? text.ToLower() : text;

            int count = mForbiddenTexts.Length;

            for (int i = 0; i < count; i++)
            {
                if (textForComparison.IndexOf(mForbiddenTexts[i], comparison) >= 0)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Rotate the specified point around another point.
        /// </summary>
        public static void RotatePointAroundAnother(this Vector2 point, Vector2 centerPoint, float angle)
        {
            Vector3 euler = Vector3.zero;

            euler.z = angle;
            point   = MyUtilities.RotatePointAroundPivot(point, centerPoint, euler);
        }
        /// <summary>
        /// Initialize.
        /// </summary>
        private static void _Initialize()
        {
            if (mCoroutineObject == null)
            {
                string objName = typeof(MyCoroutiner).Name;

                mCoroutineObject = MyUtilities.FindObjectInRoot(objName);

                if (mCoroutineObject == null)
                {
                    mCoroutineObject = new GameObject(objName);
                }

                GameObject.DontDestroyOnLoad(mCoroutineObject);

                mDictionaryRoutine = new Dictionary <string, IEnumerator>();
            }

            if (mCoroutineInstance == null)
            {
                mCoroutineInstance = mCoroutineObject.GetComponent <CoroutineInstance>();

                if (mCoroutineInstance == null)
                {
                    mCoroutineInstance = mCoroutineObject.AddComponent(typeof(CoroutineInstance)) as CoroutineInstance;
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Shuffle a list.
        /// </summary>
        public static void Shuffle <T>(List <T> list)
        {
            int count = list.Count;

            for (int i = 0; i < count; i++)
            {
                MyUtilities.Swap(list, i, Random.Range(i, count));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Find and replace forbidden words in a text.
        /// </summary>
        /// <param name="text">a text which needs to handle</param>
        /// <param name="isTrim">trim text before handling</param>
        /// <param name="isNormalizeWhitespaces">normalize whitespaces before handling</param>
        /// <param name="isIgnoreCase">ignore case while finding forbidden words</param>
        /// <param name="charReplace">a string which replaces every illegal character in forbidden word</param>
        public static string ReplaceForbiddenWords(string text, bool isTrim = true, bool isNormalizeWhitespaces = false, bool isIgnoreCase = true, string charReplace = "*")
        {
            if (mForbiddenTexts == null)
            {
                LoadData();
            }

            if (isTrim)
            {
                text = text.Trim();
            }

            if (isNormalizeWhitespaces)
            {
                text = MyUtilities.NormalizeWhitespaces(text);
            }

            return(_ReplaceForbiddenWords(text, charReplace, isIgnoreCase));
        }
        /// <summary>
        /// Provide an available object. If no objects are present in the pool, a new object is created and returned.
        /// </summary>
        /// <param name="isForceCreate">always create new object</param>
        public GameObject Use(string path, bool isForceCreate = false)
        {
            if (mDictPooler.ContainsKey(path))
            {
                if (isForceCreate)
                {
                    return(mDictPooler[path].Create());
                }

                return(mDictPooler[path].Use());
            }

            GameObject root = MyUtilities.FindObjectInFirstLayer(gameObject, path);

            if (root == null)
            {
                root = new GameObject(path);
                root.transform.SetParent(transform, false);
            }

            GameObject rootFree = MyUtilities.FindObjectInFirstLayer(root, "Free");

            if (rootFree == null)
            {
                rootFree = new GameObject("Free");
                rootFree.transform.SetParent(root.transform, false);
            }

            GameObject rootOccupied = MyUtilities.FindObjectInFirstLayer(root, "Occupied");

            if (rootOccupied == null)
            {
                rootOccupied = new GameObject("Occupied");
                rootOccupied.transform.SetParent(root.transform, false);
            }

            mDictPooler.Add(path, new MyPool(path, rootFree, rootOccupied));

            return(Use(path, isForceCreate));
        }
        /// <summary>
        /// Provide an available object. If no objects are present in the pool, a new object is created and returned.
        /// </summary>
        public GameObject Use(GameObject prefab)
        {
            if (mDictPooler.ContainsKey(prefab.name))
            {
                mDictPooler[prefab.name].SetTemplate(prefab);
                return(mDictPooler[prefab.name].Use());
            }

            GameObject root = MyUtilities.FindObjectInFirstLayer(gameObject, prefab.name);

            if (root == null)
            {
                root = new GameObject(prefab.name);
                root.transform.SetParent(transform, false);
            }

            GameObject rootFree = MyUtilities.FindObjectInFirstLayer(root, "Free");

            if (rootFree == null)
            {
                rootFree = new GameObject("Free");
                rootFree.transform.SetParent(root.transform, false);
            }

            GameObject rootOccupied = MyUtilities.FindObjectInFirstLayer(root, "Occupied");

            if (rootOccupied == null)
            {
                rootOccupied = new GameObject("Occupied");
                rootOccupied.transform.SetParent(root.transform, false);
            }

            mDictPooler.Add(prefab.name, new MyPool(prefab.name, rootFree, rootOccupied));

            mDictPooler[prefab.name].SetTemplate(prefab);
            return(Use(prefab.name, false));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Print items in array.
 /// </summary>
 public static void Log(this string[] array)
 {
     Debug.Log(MyUtilities.ToString(array));
 }
 /// <summary>
 /// Print items in list.
 /// </summary>
 public static void LogWarning(this List <int> list)
 {
     Debug.LogWarning(MyUtilities.ToString(list));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Print items in array.
 /// </summary>
 public static void LogWarning(this bool[] array)
 {
     Debug.LogWarning(MyUtilities.ToString(array));
 }
 /// <summary>
 /// Print items in list.
 /// </summary>
 public static void Log(this List <bool> list)
 {
     Debug.Log(MyUtilities.ToString(list));
 }
 /// <summary>
 /// Print items in list.
 /// </summary>
 public static void LogError(this List <byte> list)
 {
     Debug.LogError(MyUtilities.ToString(list));
 }
 /// <summary>
 /// Rotate the specified point around a pivot.
 /// </summary>
 public static void RotateAroundPivot(this Vector3 point, Vector3 pivot, Vector3 euler)
 {
     point = MyUtilities.RotatePointAroundPivot(point, pivot, euler);
 }
 /// <summary>
 /// Rotate the specified point around a pivot.
 /// </summary>
 public static void RotateAroundPivot(this Vector3 point, Vector3 pivot, Quaternion angle)
 {
     point = MyUtilities.RotatePointAroundPivot(point, pivot, angle);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Print items in array.
 /// </summary>
 public static void LogError(this int[] array)
 {
     Debug.LogError(MyUtilities.ToString(array));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Print items in array.
 /// </summary>
 public static void LogWarning(this int[][] arrays)
 {
     Debug.LogWarning(MyUtilities.ToString(arrays));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Print items in array.
 /// </summary>
 public static void LogError(this float[][] arrays)
 {
     Debug.LogError(MyUtilities.ToString(arrays));
 }
 /// <summary>
 /// Rotate the specified object around a pivot.
 /// </summary>
 public static void RotateAroundPivot(this Transform transform, Vector3 pivot, Quaternion angle)
 {
     transform.position = MyUtilities.RotatePointAroundPivot(transform.position, pivot, angle);
 }
 /// <summary>
 /// Rotate the specified object around a pivot.
 /// </summary>
 public static void RotateAroundPivot(this Transform transform, Vector3 pivot, Vector3 euler)
 {
     transform.position = MyUtilities.RotatePointAroundPivot(transform.position, pivot, euler);
 }