public static string[] AllNamesCSVFilesAtResources(string path = null)
        {
            var csvPaths = Directory.GetFiles((Directory.GetCurrentDirectory() + "/Assets/Resources/" + path.OrEmpty()), "*.csv");

            ArrayTools.DoTimes(() => csvPaths.Length, index => {
                csvPaths[index] = csvPaths[index].Replace((Directory.GetCurrentDirectory() + "/Assets/Resources/" + path.OrEmpty()), string.Empty).Replace(".csv", string.Empty);
            });
            return(csvPaths);
        }
        public static string[] AllNamesPrefabsAtResources(string path = null)
        {
            var prefabPaths = Directory.GetFiles((Directory.GetCurrentDirectory() + "/Assets/Resources/" + path.OrEmpty()), "*.prefab");

            ArrayTools.DoTimes(() => prefabPaths.Length, index => {
                prefabPaths[index] = prefabPaths[index].Replace((Directory.GetCurrentDirectory() + "/Assets/Resources/" + path.OrEmpty()), string.Empty).Replace(".prefab", string.Empty);
            });
            return(prefabPaths);
        }
Beispiel #3
0
        public static string GetRandomKey(int size)
        {
            var builder = new System.Text.StringBuilder();

            ArrayTools.DoTimes(() => size, index => {
                builder.Append(System.Convert.ToChar(System.Convert.ToInt32(Mathf.Floor(26f * Random.Range(0.0f, 1.0f) + 65f))));
            });
            return(builder.ToString());
        }
Beispiel #4
0
        public static bool ThrowDice(float percent)
        {
            percent = Mathf.Clamp01(percent);
            var count     = ( int )(percent * 100f + 0.5f);
            var selection = new bool[100];

            ArrayTools.DoTimes(() => selection.Length, index => {
                selection[index] = index < count;
            });
            return(selection[Random.Range(0, selection.Length)]);
        }
Beispiel #5
0
            public StringBuilder Build(StringBuilder builder = null)
            {
                builder = builder ?? new StringBuilder();
                if (!messages.IsNullOrEmpty())
                {
#if UNITY_EDITOR
                    builder.Append(string.Format(COLOR_TAG_PREFIX, ColorToHex(color)));
#endif
                    var times = messages.Length;
                    ArrayTools.DoTimes(() => times, index => {
                        ((index > 0) ? builder.Append(separator) : builder).Append(messages[index].IsNull() ? NULL_TAG : messages[index].ToString());
                    });
#if UNITY_EDITOR
                    builder.Append(COLOR_TAG_POSTFIX);
#endif
                }
                return(builder);
            }
Beispiel #6
0
        public static T ThrowDice <T>(T[] weights) where T : IWeight
        {
            var sum = 0f;

            foreach (T weight in weights)
            {
                sum += weight.Value;
            }
            var selection = new T[0];

            foreach (T weight in weights)
            {
                var count = ( int )(weight.Value * 100f / sum + 0.5f);
                ArrayTools.DoTimes(() => count, index => {
                    ArrayTools.Add(ref selection, weight);
                });
            }
            return(selection[Random.Range(0, selection.Length)]);
        }
Beispiel #7
0
        static void DebugLog(LogEnum type, char separator, params object[] messages)
        {
#if ECHO_DEBUG
            var builder = new StringBuilder();
            builder.Append("DEBUG:");
            var times = messages.Length;
            ArrayTools.DoTimes(() => times, index => {
                var message = messages[index];
                if (message.IsNull())
                {
                    builder.Append(separator).Append(NULL_TAG);
                }
                else if (message is ColoredLog)
                {
                    var coloredMessage = message as ColoredLog;
                    coloredMessage.Build(builder.Append(separator));
                    coloredMessage.Dispose();
                }
                else
                {
                    builder.Append(separator).Append(message.ToString());
                }
            });
            switch (type)
            {
            case LogEnum.Message:
                Debug.Log(builder.ToString());
                break;

            case LogEnum.Warning:
                Debug.LogWarning(builder.ToString());
                break;

            case LogEnum.Error:
                Debug.LogError(builder.ToString());
                break;
            }
            builder.Clear();
#endif
        }
 public void DrawInspector()
 {
     if (enabled && !Application.isPlaying)
     {
         EditorTools.DrawInBox(Color.yellow, () => {
             var style = new GUIStyle(EditorStyles.boldLabel)
             {
                 alignment = TextAnchor.MiddleCenter,
                 wordWrap  = true
             };
             EditorTools.DrawLabel("It will playing automatically after load scene in play mode! (Uncheck enable if you need)", style);
         });
     }
     EditorTools.DrawInLine(() => {
         EditorTools.DrawLabel("Method", 70f);
         TweenMethod = ( Method )EditorGUILayout.EnumPopup(tweenMethod);
     });
     EditorTools.DrawInLine(() => {
         EditorTools.DrawLabel("Style", 70f);
         TweenStyle = ( Style )EditorGUILayout.EnumPopup(tweenStyle);
         if (tweenStyle != Style.Once)
         {
             EditorTools.DrawLabel("Cycles", 50f);
             CycleCount = EditorGUILayout.IntField(cycleCount);
         }
     });
     EditorTools.DrawInLine(() => {
         EditorTools.DrawLabel("Duration", 70f);
         Duration = EditorGUILayout.FloatField(tweenDuration);
         EditorTools.DrawLabel("Delay", 50f);
         startDelay = EditorGUILayout.FloatField(startDelay);
     });
     EditorTools.DrawInLine(() => {
         var parametersForCreate = new [] {
             typeof(TransformTweening),
             typeof(ColorTweening),
             typeof(AlphaTweening),
             typeof(RectSizeTweening),
             typeof(FontSizeTweening),
             typeof(ScaleTweening),
             typeof(PositionTweening),
             typeof(ActiveTweening),
             typeof(WheelFrictionsTweening)
         };
         EditorTools.DrawLabel("New Parameter", 100f);
         EditorTools.DrawSelector("Select for Add...", Color.green, parametersForCreate, parameter => parameter.Name, selected => AddParameter(selected));
     });
     parameters = GetComponents <TweeningParameter>();
     ArrayTools.DoTimes(() => parameters.Length, index => {
         parameters[index].hideFlags = HideFlags.HideInInspector;
         EditorTools.DrawInBox(() => {
             if (parameters[index].needRemove)
             {
                 var colors = new[] { EditorGUIUtility.isProSkin?Color.yellow: Color.black, Color.red, Color.green };
                 EditorTools.DrawQuestionDialogInLine("Remove this parameter?", 110f, () => {
                     DestroyImmediate(parameters[index]);
                     ArrayTools.RemoveAt(ref parameters, index);
                     index--;
                 }, () => {
                     parameters[index].needRemove = false;
                 }, colors);
             }
             else
             {
                 EditorTools.DrawInLine(() => {
                     EditorTools.DrawButton("R", "Remove", () => parameters[index].needRemove = true, EditorStyles.miniButton, Color.red, 20f);
                     parameters[index].DrawTitle();
                 });
                 parameters[index].DrawInspector();
             }
         });
         return(index);
     });
 }