阶段性完成
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace
|
||||
{
|
||||
/// <summary>
|
||||
/// FimpossibleC: Extensions methods which can be helpful when using Colors
|
||||
/// </summary>
|
||||
public static class FColorMethods
|
||||
{
|
||||
/// <summary>
|
||||
/// Changing color's alpha value
|
||||
/// </summary>
|
||||
public static Color ChangeColorAlpha(this Color color, float alpha)
|
||||
{
|
||||
return new Color(color.r, color.g, color.b, alpha);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove HDR values, clamp to max 1 value
|
||||
/// </summary>
|
||||
/// <param name="hdrColor"></param>
|
||||
/// <returns></returns>
|
||||
public static Color ToGammaSpace(Color hdrColor)
|
||||
{
|
||||
float getMax = hdrColor.r;
|
||||
if (hdrColor.g > getMax) getMax = hdrColor.g;
|
||||
if (hdrColor.b > getMax) getMax = hdrColor.b;
|
||||
if (hdrColor.a > getMax) getMax = hdrColor.a;
|
||||
|
||||
if (getMax <= 0f) return Color.clear;
|
||||
return hdrColor / getMax;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changing color brightness or darkness value (adding / subliming .r .g .b) -1 to 1 value
|
||||
/// </summary>
|
||||
public static Color ChangeColorsValue(this Color color, float brightenOrDarken = 0f)
|
||||
{
|
||||
return new Color(color.r + brightenOrDarken, color.g + brightenOrDarken, color.b + brightenOrDarken, color.a);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converting colors from hexadecimal to rgba color
|
||||
/// </summary>
|
||||
public static Color32 HexToColor(this string hex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(hex))
|
||||
{
|
||||
Debug.Log("<color=red>Trying convert from hex to color empty string!</color>");
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
uint rgba = 0x000000FF;
|
||||
|
||||
hex = hex.Replace("#", "");
|
||||
hex = hex.Replace("0x", "");
|
||||
|
||||
if (!uint.TryParse(hex, System.Globalization.NumberStyles.HexNumber, null, out rgba))
|
||||
{
|
||||
Debug.Log("Error during converting hex string.");
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
return new Color32((byte)((rgba & -16777216) >> 0x18),
|
||||
(byte)((rgba & 0xff0000) >> 0x10),
|
||||
(byte)((rgba & 0xff00) >> 8),
|
||||
(byte)(rgba & 0xff));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Coverting color32 to hex string
|
||||
/// </summary>
|
||||
public static string ColorToHex(this Color32 color, bool addHash = true)
|
||||
{
|
||||
string hex = "";
|
||||
|
||||
if (addHash) hex = "#";
|
||||
|
||||
hex += System.String.Format("{0}{1}{2}{3}"
|
||||
, color.r.ToString("X").Length == 1 ? System.String.Format("0{0}", color.r.ToString("X")) : color.r.ToString("X")
|
||||
, color.g.ToString("X").Length == 1 ? System.String.Format("0{0}", color.g.ToString("X")) : color.g.ToString("X")
|
||||
, color.b.ToString("X").Length == 1 ? System.String.Format("0{0}", color.b.ToString("X")) : color.b.ToString("X")
|
||||
, color.a.ToString("X").Length == 1 ? System.String.Format("0{0}", color.a.ToString("X")) : color.a.ToString("X"));
|
||||
|
||||
return hex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Coverting color to hex string
|
||||
/// </summary>
|
||||
public static string ColorToHex(this Color color, bool addHash = true)
|
||||
{
|
||||
Color32 col32 = new Color32((byte)(color.r * 255), (byte)(color.g * 255), (byte)(color.b * 255), (byte)(color.a * 255));
|
||||
return ColorToHex(col32, addHash);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Doing linear interpolation with deltaTime to change material color smoothly
|
||||
/// </summary>
|
||||
public static void LerpMaterialColor(this Material mat, string property, Color targetColor, float deltaMultiplier = 8f)
|
||||
{
|
||||
if (mat == null) return;
|
||||
|
||||
if (!mat.HasProperty(property))
|
||||
{
|
||||
Debug.LogError("Material " + mat.name + " don't have property '" + property + "' " + " in shader " + mat.shader.name);
|
||||
return;
|
||||
}
|
||||
|
||||
Color currentColor = mat.GetColor(property);
|
||||
mat.SetColor(property, Color.Lerp(currentColor, targetColor, Time.deltaTime * deltaMultiplier));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2a20a2000093084e84d0fc02e3581bf
|
||||
timeCreated: 1528881308
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace FIMSpace
|
||||
{
|
||||
/// <summary>
|
||||
/// FMoeglich: Class with methods which can be helpful in using Unity Console.
|
||||
/// Recommending to use some console extensions like Console Enchanced or other.
|
||||
/// </summary>
|
||||
public static class FDebug
|
||||
{
|
||||
public static void Log(string log)
|
||||
{
|
||||
Debug.Log("LOG: " + log);
|
||||
}
|
||||
|
||||
public static void Log(string log, string category)
|
||||
{
|
||||
Debug.Log(MarkerColor("#1A6600") + "[" + category + "]" + EndColorMarker() + " " + log);
|
||||
}
|
||||
|
||||
public static void LogRed(string log)
|
||||
{
|
||||
Debug.Log(MarkerColor("red") + log + EndColorMarker());
|
||||
}
|
||||
|
||||
public static void LogOrange(string log)
|
||||
{
|
||||
Debug.Log(MarkerColor("#D1681D") + log + EndColorMarker());
|
||||
}
|
||||
|
||||
public static void LogYellow(string log)
|
||||
{
|
||||
Debug.Log(MarkerColor("#E0D300") + log + EndColorMarker());
|
||||
}
|
||||
|
||||
private static readonly System.Diagnostics.Stopwatch _debugWatch = new System.Diagnostics.Stopwatch();
|
||||
public static void StartMeasure()
|
||||
{
|
||||
_debugWatch.Reset();
|
||||
_debugWatch.Start();
|
||||
}
|
||||
|
||||
public static void PauseMeasure()
|
||||
{
|
||||
_debugWatch.Stop();
|
||||
}
|
||||
|
||||
public static void ResumeMeasure()
|
||||
{
|
||||
_debugWatch.Start();
|
||||
}
|
||||
|
||||
public static void EndMeasureAndLog(string v)
|
||||
{
|
||||
_debugWatch.Stop();
|
||||
_LastMeasureMilliseconds = _debugWatch.ElapsedMilliseconds;
|
||||
_LastMeasureTicks = _debugWatch.ElapsedTicks;
|
||||
UnityEngine.Debug.Log("Measure " + v + ": " + _debugWatch.ElapsedTicks + " ticks " + _debugWatch.ElapsedMilliseconds + "ms");
|
||||
}
|
||||
|
||||
public static long EndMeasureAndGetTicks()
|
||||
{
|
||||
_debugWatch.Stop();
|
||||
_LastMeasureMilliseconds = _debugWatch.ElapsedMilliseconds;
|
||||
_LastMeasureTicks = _debugWatch.ElapsedTicks;
|
||||
return _debugWatch.ElapsedTicks;
|
||||
}
|
||||
|
||||
public static long _LastMeasureMilliseconds = 0;
|
||||
public static long _LastMeasureTicks = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Rich text marker for color
|
||||
/// </summary>
|
||||
public static string MarkerColor(string color)
|
||||
{
|
||||
return "<color='" + color + "'>";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// close rich text marker for color
|
||||
/// </summary>
|
||||
public static string EndColorMarker()
|
||||
{
|
||||
return "</color>";
|
||||
}
|
||||
|
||||
|
||||
public static void DrawBounds2D(this Bounds b, Color c, float y = 0f, float scale = 1f, float duration = 1.1f)
|
||||
{
|
||||
Vector3 fr1 = new Vector3(b.max.x, y, b.max.z) * scale;
|
||||
Vector3 br1 = new Vector3(b.max.x, y, b.min.z) * scale;
|
||||
Vector3 bl1 = new Vector3(b.min.x, y, b.min.z) * scale;
|
||||
Vector3 fl1 = new Vector3(b.min.x, y, b.max.z) * scale;
|
||||
Debug.DrawLine(fr1, br1, c, duration);
|
||||
Debug.DrawLine(br1, bl1, c, duration);
|
||||
Debug.DrawLine(br1, bl1, c, duration);
|
||||
Debug.DrawLine(bl1, fl1, c, duration);
|
||||
Debug.DrawLine(fl1, fr1, c, duration);
|
||||
}
|
||||
|
||||
public static void DrawBounds3D(this Bounds b, Color c, float scale = 1f, float time = 1.01f)
|
||||
{
|
||||
Vector3 fr1 = new Vector3(b.max.x, b.min.y, b.max.z) * scale;
|
||||
Vector3 br1 = new Vector3(b.max.x, b.min.y, b.min.z) * scale;
|
||||
Vector3 bl1 = new Vector3(b.min.x, b.min.y, b.min.z) * scale;
|
||||
Vector3 fl1 = new Vector3(b.min.x, b.min.y, b.max.z) * scale;
|
||||
Debug.DrawLine(fr1, br1, c, time);
|
||||
Debug.DrawLine(br1, bl1, c, time);
|
||||
Debug.DrawLine(br1, bl1, c, time);
|
||||
Debug.DrawLine(bl1, fl1, c, time);
|
||||
Debug.DrawLine(fl1, fr1, c, time);
|
||||
|
||||
Vector3 fr = new Vector3(b.max.x, b.max.y, b.max.z) * scale;
|
||||
Vector3 br = new Vector3(b.max.x, b.max.y, b.min.z) * scale;
|
||||
Vector3 bl = new Vector3(b.min.x, b.max.y, b.min.z) * scale;
|
||||
Vector3 fl = new Vector3(b.min.x, b.max.y, b.max.z) * scale;
|
||||
Debug.DrawLine(fr, br, c, time);
|
||||
Debug.DrawLine(br, bl, c, time);
|
||||
Debug.DrawLine(br, bl, c, time);
|
||||
Debug.DrawLine(bl, fl, c, time);
|
||||
Debug.DrawLine(fl, fr, c, time);
|
||||
|
||||
Debug.DrawLine(fr1, fr1, c,time);
|
||||
Debug.DrawLine(br, br1, c, time);
|
||||
Debug.DrawLine(bl1, bl, c, time);
|
||||
Debug.DrawLine(fl1, fl, c, time);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ddaf37d5aa608345adae3324d191ed6
|
||||
timeCreated: 1528881308
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,178 @@
|
||||
|
||||
namespace FIMSpace
|
||||
{
|
||||
/// <summary>
|
||||
/// FM: Class which contains many helpful methods which operates
|
||||
/// </summary>
|
||||
public static class FStringMethods
|
||||
{
|
||||
/// <summary>
|
||||
/// Converting int to strig
|
||||
/// </summary>
|
||||
/// <param name="value">value to show</param>
|
||||
/// <param name="signs">How many signs, value = 8, signs = 3 -> 008</param>
|
||||
public static string IntToString(this int value, int signs)
|
||||
{
|
||||
string output = value.ToString();
|
||||
|
||||
int missingZeros = signs - output.Length;
|
||||
|
||||
if (missingZeros > 0)
|
||||
{
|
||||
string missing = "0";
|
||||
|
||||
for (int i = 1; i < missingZeros; i++)
|
||||
{
|
||||
missing += 0;
|
||||
}
|
||||
|
||||
output = missing + output;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changing first letter to uppercase and rest to lowercase
|
||||
/// </summary>
|
||||
public static string CapitalizeOnlyFirstLetter(this string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
return text[0].ToString().ToUpper() + (text.Length > 1 ? text.Substring(1) : "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Chanigng first letter to uppercase and rest without changes
|
||||
/// </summary>
|
||||
public static string CapitalizeFirstLetter(this string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return text;
|
||||
|
||||
return text[0].ToString().ToUpper() + text.Substring(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changing space signs to underline signs
|
||||
/// </summary>
|
||||
public static string ReplaceSpacesWithUnderline(this string text)
|
||||
{
|
||||
if (text.Contains(" "))
|
||||
{
|
||||
text = text.Replace(" ", "_");
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returning string from end to the separator, for GetEndOfStringFromSeparator("ask/ddd/aaa", new char[] { '\\', '/' }) will return "aaa"
|
||||
/// </summary>
|
||||
/// <param name="source"> Base string, from which you need only part of it </param>
|
||||
/// <param name="separators"> separators array to define, when stop checking new char[] { '\\', '/' } </param>
|
||||
/// <param name="which"> how many occurences of separator should happen </param>
|
||||
/// <param name="fromEnd"> start checking from end or from start of base string </param>
|
||||
/// <returns></returns>
|
||||
public static string GetEndOfStringFromSeparator(this string source, char[] separators, int which = 1, bool fromEnd = false)
|
||||
{
|
||||
bool separated = false;
|
||||
int counter = 0;
|
||||
int steps = 0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (i = source.Length - 1; i >= 0; i--)
|
||||
{
|
||||
steps++;
|
||||
|
||||
for (int c = 0; c < separators.Length; c++)
|
||||
{
|
||||
if (source[i] == separators[c])
|
||||
{
|
||||
counter++;
|
||||
|
||||
if (counter == which)
|
||||
{
|
||||
i++;
|
||||
|
||||
separated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (separated) break;
|
||||
}
|
||||
|
||||
if (separated)
|
||||
{
|
||||
if (!fromEnd)
|
||||
{
|
||||
return source.Substring(0, source.Length - (steps));
|
||||
}
|
||||
else
|
||||
{
|
||||
return source.Substring(i, source.Length - i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Same as above GetEndOfStringFromSeparator() but here you define separators as strings, so for GetEndOfStringFromStringSeparator("ask/ddd/aaa", new string[] { "ask" }) will return "/ddd/aaa"
|
||||
/// </summary>
|
||||
public static string GetEndOfStringFromStringSeparator(this string source, string[] separators, int which = 1, bool rest = false)
|
||||
{
|
||||
bool separated = false;
|
||||
int counter = 0;
|
||||
int steps = 0;
|
||||
|
||||
int i = 0;
|
||||
for (i = 0; i < source.Length; i++)
|
||||
{
|
||||
steps++;
|
||||
|
||||
for (int c = 0; c < separators.Length; c++)
|
||||
{
|
||||
if (i + separators[c].Length > source.Length) break;
|
||||
|
||||
if (source.Substring(i, separators[c].Length) == separators[c])
|
||||
{
|
||||
counter++;
|
||||
|
||||
if (counter == which)
|
||||
{
|
||||
i++;
|
||||
|
||||
i += separators[c].Length - 1;
|
||||
|
||||
separated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (separated) break;
|
||||
}
|
||||
|
||||
if (separated)
|
||||
{
|
||||
if (rest)
|
||||
{
|
||||
return source.Substring(0, source.Length - (steps));
|
||||
}
|
||||
else
|
||||
{
|
||||
return source.Substring(i, source.Length - i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 624de49f8d4dd534ba80e893e1269f46
|
||||
timeCreated: 1508272082
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user