using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
public class Utility : MonoBehaviour
{}
public static class X
{
public static void x(int code) {Debug.Log("X" + code);}
public static void e(int code) {Debug.Log("TERMINAL " + code);}
public static void Log(string b) {Debug.Log(b);}
public static void Log(int code, string b) {Debug.Log("X" + code + ": " + b);}
public static void Error(int code, string em) {Debug.LogError("Error:X(" + code + "): " + em);}
public static void Error(string em) {Debug.LogError(em);}
}
//$ Administrator, Ut, ObjectC, PenManager
public abstract class ClassX
{
public Administrator admin;
public Ut ut;
public ObjectC objectC;
public DataX data;
public ClassX()
{
admin = Ut.Admin();
ut = new Ut();
objectC = new ObjectC();
}
public Cross.Sprite Sprite(string key) {return admin.GetSprite(key);}
public Cross.TextC Text() {return admin._text;}
public void TextContext(string key) {admin._text.key = key;}
public PenManager Tablet => admin.PenManager;
public MonitorC Monitor(int id=1) {return admin.Monitors[id - 1];}
//% More
//$ Cursor
public void ShowCursor(bool b=true) {Cursor.visible = b;}
public void HideCursor() {Cursor.visible = false;}
public bool CursorVisible() {return Cursor.visible;}
public float mousex() {return admin.MousePosition.x;}
public float mousey() {return admin.MousePosition.y;}
public Vector2 mousepos() {return admin.MousePosition;}
public float cursorx() {return admin.GameMousePos.x;}
public float cursory() {return admin.GameMousePos.y;}
public Vector2 cursorpos() {return admin.GameMousePos;}
//$
}
//$ ClassX but MonoBehaviour
public abstract class MonoX : MonoBehaviour
{
[HideInInspector]
public Administrator admin;
public Ut ut;
public ObjectC objectC;
public DataX data;
void Awake()
{
admin = Ut.Admin();
ut = new Ut();
objectC = new ObjectC();
_text = new Cross.TextC();
}
public Cross.Sprite Sprite(string key) {if(admin == null) {return null;} return admin.GetSprite(key);}
private Cross.TextC _text;
public Cross.TextC Text() {return _text;}
public Cross.TextC Text(string key) {_text.key = key; return _text;}
public Cross.TextC TextA() {return admin._text;}
public PenManager Tablet => admin.PenManager;
public MonitorC Monitor(int id=1) {return admin.Monitors[id - 1];}
//% More
//$ Cursor
public void ShowCursor(bool b=true) {Cursor.visible = b;}
public void HideCursor() {Cursor.visible = false;}
public bool CursorVisible() {return Cursor.visible;}
public float mousex() {return admin.MousePosition.x;}
public float mousey() {return admin.MousePosition.y;}
public Vector2 mousepos() {return admin.MousePosition;}
public float cursorx() {return admin.GameMousePos.x;}
public float cursory() {return admin.GameMousePos.y;}
public Vector2 cursorpos() {return admin.GameMousePos;}
//$
}
public class MonitorC
{
private TMPro.TextMeshPro text;
public MonitorC(TMPro.TextMeshPro setText) {text = setText;}
public void Show(bool b=true) {text.enabled = b;}
public void Hide() {text.enabled = false;}
public void Display(string displayText) {text.text = displayText;}
}
public class CameraC : ClassX
{
public Cross.Sprite camera;
public string target;
public Vector4 borders;
public CameraC() {LockOn("CameraFocus"); SetBorders(-100f, -5f, 100f, 100f); camera = admin.GetSprite("Main Camera");}
public void LockOn(string key) {target = key;}
public void SetBorders(float x1, float y1, float x2, float y2) {borders = new Vector4(x1, y1, x2, y2);}
public (float x1, float y1, float x2, float y2) Borders() {return (borders.x, borders.y, borders.z, borders.w);}
public (float x1, float y1, float x2, float y2) camBorders()
{
return (borders.x + World.xBordersLocal(), borders.y + World.yBordersLocal(), borders.z - World.xBordersLocal(), borders.w - World.yBordersLocal());
}
public Vector2 Position() {return camera.xypos();}
public Vector2 Positioning()
{
return new Vector2(
(Position().x - camBorders().x1) / (camBorders().x2 - camBorders().x1),
(Position().y - camBorders().y1) / (camBorders().y2 - camBorders().y1)
);
}
public Vector2 PositioningP()
{
return ((Positioning() - new Vector2(0.5f, 0.5f)) * 2f);
}
public void Update()
{
camera.xySet(Sprite(target).xypos()); // Makes target the exact center.
if(camera.xpos() - World.xBordersLocal() < Borders().x1) {camera.xSet(Borders().x1 + World.xBordersLocal());}
if(camera.xpos() + World.xBordersLocal() > Borders().x2) {camera.xSet(Borders().x2 - World.xBordersLocal());}
if(camera.ypos() - World.yBordersLocal() < Borders().y1) {camera.ySet(Borders().y1 + World.yBordersLocal());}
if(camera.ypos() + World.yBordersLocal() > Borders().y2) {camera.ySet(Borders().y2 - World.yBordersLocal());}
camera.zSet(-10f);
}
}
namespace InputC
{
public class Key
{
public static string[] KeyStr = new string[146]
{
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
"up", "down", "left", "right",
"[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]", "[8]", "[9]", "[0]", "[+]", "[-]", "[*]", "[/]", "[.]", "enter", "insert", "home", "end", "page up", "page down",
"backspace", "delete", "tab", "clear", "return", "pause", "escape", "space",
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
"!", "@", "#", "$", "%", "^", "&", "*", "(", ")",
"-", "=", "_", "+", "[", "]", "\\", "{", "}", "|", ";", "'", ":", "\"", ",", ".", "/", "<", ">", "?", "`", "~",
"numlock", "caps lock", "scroll lock", "right shift", "left shift", "right ctrl", "left ctrl", "right alt", "left alt", "right cmd", "left cmd", "right super", "left super",
"alt gr", "compose", "help", "print screen", "sys req", "break", "menu", "power", "euro", "undo",
"mouse 0", "mouse 1", "mouse 2", "mouse 3", "mouse 4", "mouse 5", "mouse 6"
};
private Dictionary<string, int> KeyInt = new Dictionary<string, int>();
private Soul B = new Soul();
public Key()
{
KeyInt.Clear();
for(int i = 0; i < KeyStr.Length; i++)
{
KeyInt.Add(KeyStr[i], i);
}
B.TryAdd(147, Cup.Bool);
}
public Key(Dictionary<string, int> keyintref)
{
KeyInt = keyintref;
}
public bool Pressed(string keyPress)
{
if(Input.GetKey(keyPress) && !B.Bool(KeyInt[keyPress] + 1))
{
B.Set(KeyInt[keyPress] + 1, true);
return true;
}
Release(keyPress);
return false;
}
public bool PressedAny()
{
return Input.anyKeyDown;
}
public bool Hold(string keyPress)
{
if(!KeyInt.ContainsKey(keyPress)) {return false;}
return Input.GetKey(keyPress);
}
public bool HoldAny()
{
return Input.anyKey;
}
public bool Release(string keyPress)
{
if(!Input.GetKey(keyPress) && B.Bool(KeyInt[keyPress] + 1))
{
B.Set(KeyInt[keyPress] + 1, false);
return true;
}
return false;
}
}
public class Mouse
{
private Soul B;
private int s = 0;
public Mouse(int s1)
{
B = new Soul();
s = s1;
if(s != 0 && s != 1) {s = 0;}
}
public bool Pressed(int id)
{
if(Input.GetMouseButton(s) && !B.Bool(id)) {B.Set(id, true); return true;}
if(!Input.GetMouseButton(s) && B.Bool(id)) {B.Set(id, false);}
return false;
}
public bool Hold()
{
return Input.GetMouseButton(s);
}
public void Reset(int id)
{
B.Set(id, true);
}
}
}
public static class Sono
{
public static float counter(float time1) {return (Time.deltaTime / time1);}
public static float repeat(int repeats) {return (repeats * fps(60));}
public static float repeat(int repeats, int frames) {return repeats * fps(frames);}
public static float repeated(float time1) {return (time1 / fps(60));}
public static float repeated(int frames, float time1) {return (time1 * frames);}
public static float countrep(int repeats) {return (Time.deltaTime / repeat(repeats));}
public static float count() {return Time.deltaTime;}
public static float fps(int fps) {return (1f / fps);}
public static float fraction(float a, float b) {return a/b;}
public static float fraction(int a, int b) {return a/b;}
}
public static class ColorC
{
public static Color HSVToRGB(float h, float s, float v, float a=1f)
{
Color tempcolor = Color.HSVToRGB(h, s, v); tempcolor.a = a;
return tempcolor;
}
public static Color HSVToRGB(HSV hsv1)
{
Color tempcolor = Color.HSVToRGB(hsv1.h, hsv1.s, hsv1.v); tempcolor.a = hsv1.a;
return tempcolor;
}
public static Color32 HSVToColor(float h, float s, float v, float a=255f)
{
Color32 tempcolor = Color.HSVToRGB(h, s, v); tempcolor.a = (byte)(a);
return tempcolor;
}
public static Color32 HSVToColor(HSV hsv1)
{
Color32 tempcolor = Color.HSVToRGB(hsv1.h, hsv1.s, hsv1.v); tempcolor.a = (byte)(hsv1.a * 255f);
return tempcolor;
}
public static HSV RGBToHSV(Color color1)
{
return new HSV(color1);
}
public static HSV AddHSV(HSV hsv1 , HSV hsv2)
{
HSV c = new HSV();
c.h = hsv1.h + hsv2.h; c.s = hsv1.s + hsv2.s; c.v = hsv1.v + hsv2.v; c.a = hsv1.a + hsv2.a;
return c;
}
public static HSV AddHSV(Color color1, Color color2)
{
return AddHSV(RGBToHSV(color1), RGBToHSV(color2));
}
public static Color AddColors(HSV hsv1, HSV hsv2)
{
return HSVToRGB(AddHSV(hsv1, hsv2));
}
public static Color AddColors(Color color1, Color color2)
{
return AddColors(RGBToHSV(color1), RGBToHSV(color2));
}
public static HSV ToHSV(Vector3 v3) {return new HSV(v3.x, v3.y, v3.z);}
public static HSV ToHSV(Vector4 v4) {return new HSV(v4.x, v4.y, v4.z, v4.w);}
public static bool CompareColor32(Color32 color1, Color32 color2)
{
return (color1.r == color2.r && color1.g == color2.g && color1.b == color2.b && color1.a == color2.a);
}
public static Color32 BlendColor32(Color32 color1, Color32 color2)
{
Color32 color3 = new Color32();
color3.r = (byte)(color1.r + ((color2.r - color1.r) * (color2.a / 255)));
color3.g = (byte)(color1.g + ((color2.g - color1.g) * (color2.a / 255)));
color3.b = (byte)(color1.b + ((color2.b - color1.b) * (color2.a / 255)));
color3.a = (byte)(color2.a + ((color1.a / 255) * (255 - color2.a)));
return color3;
}
public static Color32 BlendColor32(Color32 color1, float h, float s, float v, float a=255f)
{
Color32 color2 = Color.HSVToRGB(h, s, v); color2.a = (byte)(a);
Color32 color3 = new Color32();
color3.r = (byte)(color1.r + ((color2.r - color1.r) * (color2.a / 255)));
color3.g = (byte)(color1.g + ((color2.g - color1.g) * (color2.a / 255)));
color3.b = (byte)(color1.b + ((color2.b - color1.b) * (color2.a / 255)));
color3.a = (byte)(color2.a + ((color1.a / 255) * (255 - color2.a)));
return color3;
}
}
[System.Serializable]
public class HSV
{
public float h, s, v, a;
private Color rgb;
public HSV()
{
h = 0f; s = 0f; v = 1f; a = 1f;
}
public HSV(float h1, float s1, float v1)
{
h = h1; s = s1; v = v1; a = 1f;
}
public HSV(float h1, float s1, float v1, float a1)
{
h = h1; s = s1; v = v1; a = a1;
}
public HSV(Vector3 v3)
{
h = v3.x; s = v3.y; v = v3.z; a = 1f;
}
public HSV(Color color1)
{
Color.RGBToHSV(color1, out h, out s, out v);
a = color1.a;
}
public void Set(float h1, float s1, float v1, float a1) {h = h1; s = s1; v = v1; a = a1; CheckBounds();}
public void Set(float h1, float s1, float v1) {h = h1; s = s1; v = v1; CheckBounds();}
public void Set(HSV hsva) {h = hsva.h; s = hsva.s; v = hsva.v; a = hsva.a;}
public void By(float h1, float s1, float v1, float a1=0f) {h += h1; s += s1; v += v1; a += a1; CheckBounds();}
private void CheckBounds()
{
if(h > 1f) {h = 1f;} else if(h < 0f) {h = 0f;}
if(s > 1f) {s = 1f;} else if(s < 0f) {s = 0f;}
if(v > 1f) {v = 1f;} else if(v < 0f) {v = 0f;}
if(a > 1f) {a = 1f;} else if(a < 0f) {a = 0f;}
}
public Vector3 GetHSV() {return new Vector3(h, s, v);}
public HSV Copy() {HSV temphsv = new HSV(); temphsv.h = h; temphsv.s = s; temphsv.v = v; temphsv.a = a; return temphsv;}
public Color GetColor() {rgb = Color.HSVToRGB(h, s, v); return new Color(rgb.r, rgb.g, rgb.b, a);}
public void SetColor(Color color1)
{
rgb = color1; Color.RGBToHSV(color1, out h, out s, out v); a = color1.a;
}
public string ToString() {return "HSV: {" + h + ", " + s + ", " + v + " a:" + a + "}";}
}
public class TextT
{
public HSV hsva = new HSV();
}
public class TextM : ClassX
{
private Dictionary<string, TextT> textdict = new Dictionary<string, TextT>();
private TextT nullable = new TextT();
public TextM() {}
public TextT TryGet(string key) {if(textdict.ContainsKey(key)) {return textdict[key];} return nullable;}
public TextT Get(string key) {return textdict[key];}
public void Add(string key) {textdict.Add(key, new TextT());}
public void Update()
{
foreach(KeyValuePair<string, TextT> iter in textdict)
{
TextContext(iter.Key); Text().Update(iter.Value);
}
}
}
public class ObjectC
{
private Administrator admin;
private Ut ut;
public ObjectC() {admin = Ut.Admin(); ut = new Ut();}
public GameObject Create(string prefabname, string objectname, string parentname="")
{
//! "tempref" is used instead of GetObject() because multiple objects of the same name {objectname} may exist and the function
//! might return a different object. Usually better to just avoid multiple names but just for the safety. There's no loss here
GameObject tempref = GameObject.Instantiate(GetObject(prefabname));
tempref.transform.name = objectname;
ut.CacheM().cGameObject.CacheIn(objectname);
ut.CacheM().TryCache(objectname);
if(parentname != "") {SetParent(objectname, parentname);}
return tempref;
}
public GameObject GetObject(string key) {return ut.CacheM().cGameObject.Get(key);}
public T GetComponent<T>(string key) {return ut.CacheM().cGameObject.Get(key).GetComponent<T>();}
public SpriteRenderer GetRender(string key) {return ut.CacheM().cSpriteRenderer.Get(key);}
public PolygonCollider2D GetPCollider(string key) {return ut.CacheM().cPolygonCollider2D.Get(key);}
public CircleCollider2D GetCCollider(string key) {return ut.CacheM().cCircleCollider2D.Get(key);}
public BoxCollider2D GetBCollider(string key) {return ut.CacheM().cBoxCollider2D.Get(key);}
public TMPro.TextMeshPro GetText(string key) {return ut.CacheM().cTextMeshPro.Get(key);}
public AudioSource GetAudio(string key) {return ut.CacheM().cAudioSource.Get(key);}
public void SetParent(string key, string parentkey) {GetObject(key).transform.SetParent(GetObject(parentkey).transform);}
public string Parent(string key) {return GetObject(key).transform.parent.transform.name;}
public void SetName(string key, string newkey)
{
GetObject(key).transform.name = newkey;
ut.CacheM().ChangeName(key, newkey);
}
public bool HasComponent<T>(GameObject gObj)
{
string temp1 = "" + gObj.GetComponent<T>();
return (temp1 != "null" && temp1 != "");
}
public bool HasComponent<T>(string key) where T : Component
{
string temp1 = "" + GetObject(key).GetComponent<T>();
return (temp1 != "null" && temp1 != "");
}
public void AddComponent<T>(string key) where T : Component
{
GetObject(key).AddComponent<T>();
ut.CacheM().TryCache(key);
}
}
public static class MathC
{
public static float Pi() {return 3.141592653589f;}
public static float Eu() {return 2.718281828459f;}
public static float EulerExpo(float expo) {return Mathf.Pow(Eu(), expo);}
public static float EulerLn(float logf) {return MathC.Branch(logf < 0f, 0f, Mathf.Log(logf, Eu()));}
public static float Branch(bool returner, float return1, float return2=0f) {if(returner) {return return1;} else {return return2;}}
public static int Branch(bool returner, int return1=1, int return2=0) {if(returner) {return return1;} else {return return2;}}
public static string Branch(bool returner, string return1, string return2="") {if(returner) {return return1;} return return2;}
public static T Branch<T>(bool returner, T return1, T return2) {if(returner) {return return1;} return return2;}
public static int BranchEnum(params bool[] returners)
{for(int i = 0; i < returners.Length; i++) {if(returners[i]) {return (i + 1);}} return 0;}
public static T EnumBranch<T>(int enumer, params T[] returns)
{if(enumer > returns.Length) {return default(T);} return returns[enumer - 1];}
public static T EnumBranch<T>(params (bool returner, T returned)[] returns)
{
int i;
for(i = 0; i < returns.Length; i++)
{
if(returns[i].returner)
{
return returns[i].returned;
}
}
return returns[i - 1].returned;
}
public static float binrsF(bool rs) {return rs ? 1f : -1f;}
public static int binrsI(bool rs) {return rs ? 1 : -1;}
public static float sign(float value) {return value < 0f ? -1f : 1f;}
public static int sign(int value) {return value < 0 ? -1 : 1;}
public static float abs(float value) {return value < 0f ? value * -1f : value;}
public static int abs(int value) {return value < 0 ? value * -1 : value;}
//$ Limiters
public static float Max(float value, float valueMax) {if(value > valueMax) {return valueMax;} else {return value;}}
public static int Max(int value, int valueMax) {if(value > valueMax) {return valueMax;} else {return value;}}
public static float PickMax(float x, float y) {if(x > y) {return x;} else {return y;}}
public static int PickMax(int x, int y) {if(x > y) {return x;} else {return y;}}
public static float PickMin(float x, float y) {if(x < y) {return x;} else {return y;}}
public static int PickMin(int x, int y) {if(x < y) {return x;} else {return y;}}
public static float LimitMax(float x, float y) {if(x > y) {return y;} return x;}
public static int LimitMax(int x, int y) {if(x > y) {return y;} return x;}
public static float LimitMin(float x, float y) {if(x < y) {return y;} return x;}
public static int LimitMin(int x, int y) {if(x < y) {return y;} return x;}
public static float LimitRange(float min, float x, float max) {if(x < min) {return min;} if(x > max) {return max;} return x;}
public static int LimitRange(int min, int x, int max) {if(x < min) {return min;} if(x > max) {return max;} return x;}
public static bool InRange(float min, float x, float max) {if(x >= min && x <= max) {return true;} return false;}
public static bool InRange(int min, int x, int max) {if(x >= min && x <= max) {return true;} return false;}
//$
public static float Pow2(float x) {return (x * x);}
public static float Pow3(float x) {return (x * x * x);}
public static float Pow4(float x) {return (x * x * x * x);}
public static float Round(float f1, int digits=0)
{
if(digits == 0) {return Mathf.Floor(f1);}
return Mathf.Round(f1 * Mathf.Pow(10, digits)) / Mathf.Pow(10, digits);
}
public static float Trunc(float f1, int digits=0)
{
if(digits == 0)
{
if(f1 > 0) {return Mathf.Floor(f1);}
if(f1 < 0) {return Mathf.Ceil(f1);}
return 0f;
}
if(f1 > 0) {return Mathf.Floor(f1 * Mathf.Pow(10, digits)) / Mathf.Pow(10, digits);}
else if(f1 < 0) {return Mathf.Ceil(f1 * Mathf.Pow(10, digits)) / Mathf.Pow(10, digits);}
return 0f;
}
public static int fDivision(float value1, float value2)
{
return (int)Mathf.Floor(value1 / value2);
}
public static int cDivisionF(float value1, float value2)
{
return (int)Mathf.Ceil(value1 / value2);
}
public static float SafeDivision(float x) {if(x != 0) {return 1f / x;} return 0;}
public static float SafeDivision(int x) {if(x != 0) {return 1f / x;} return 0f;}
//$ Random
public static float Random(float x, float y) {return UnityEngine.Random.Range(x, y);}
public static int Random(int x, int y) {return UnityEngine.Random.Range(x, y + 1);}
public static bool Random() {if(Random(0, 1) == 1) {return true;} return false;}
public static float RandomSelect(float x, float y) {if(Random()) {return x;} return y;}
public static int RandomSelect(int x, int y) {if(Random()) {return x;} return y;}
//$
}
public static class Geometry
{
public static float TriangleArea(float a, float b, float c)
{
float p = (a + b + c) / 2f;
return Mathf.Sqrt(p * (p - a) * (p - b) * (p - c));
}
public static int GetVectorRectArea((int x, int y) pos1, (int x, int y) pos2)
{
return MathC.abs((pos2.x - pos1.x) * (pos2.y = pos1.y));
}
}
public static class Trig
{
public static float Sin(float theta) {return Mathf.Sin(Mathf.Deg2Rad * theta);}
public static float Asin(float theta) {return Mathf.Asin(theta) * Mathf.Rad2Deg;}
public static float Cos(float theta) {return Mathf.Cos(Mathf.Deg2Rad * theta);}
public static float Acos(float theta) {return Mathf.Acos(theta) * Mathf.Rad2Deg;}
public static float Tan(float theta) {return Mathf.Tan(Mathf.Deg2Rad * theta);}
public static float Atan(float theta) {return Mathf.Atan(theta) * Mathf.Rad2Deg;}
}
public static class World
{
public static (float x, float y) GridPlacement(int gP, int gX, int gY, float scale, float sI=0f)
{
(float x, float y) fG;
(int x, int y) grid;
float bX, bY;
if(gP % gX == 0) {grid.x = gX; grid.y = (int)(gP / gX);}
else {grid.x = (gP % gX); grid.y = (int)(MathC.cDivisionF(gP, gX));}
bX = (gX * scale) + ((gX - 1) * sI); bY = (gY * scale) + ((gY - 1) * sI);
fG.x = (bX / -2f) + (scale / 2f) + ((grid.x - 1) * (scale + sI));
fG.y = (bY / -2f) + (scale / 2f) + ((grid.y - 1) * (scale + sI));
return fG;
}
public static float xBorders() {return (xBordersLocal() + Camera.main.transform.position.x);}
public static float xBordersLocal() {return ((16f / 9f) * Camera.main.orthographicSize);}
public static float yBorders() {return (yBordersLocal() + Camera.main.transform.position.y);}
public static float yBordersLocal() {return (Camera.main.orthographicSize);}
public static float Distance(Vector2 pos1, Vector2 pos2) {return Mathf.Sqrt(MathC.Pow2(pos2.x - pos1.x) + MathC.Pow2(pos2.y - pos1.y));}
public static float Distance(float x1, float y1, float x2, float y2) {return Mathf.Sqrt(MathC.Pow2(x2 - x1) + MathC.Pow2(y2 - y1));}
public static RaycastHit2D Raycast(Vector2 pos, Vector2 dir, float distance, int layerid)
{
return Physics2D.Raycast(pos, dir, distance, LayerMask.GetMask(LayerMask.LayerToName(layerid)));
}
public static RaycastHit2D Raycast(Vector2 pos, Vector2 dir, float distance, string layer)
{
if(LayerMask.NameToLayer(layer) == -1) {Debug.Log("X603: No Layer \"" + layer + "\" found. "); return new RaycastHit2D();}
return Physics2D.Raycast(pos, dir, distance, LayerMask.GetMask(layer));
}
public static class Physics
{
public static double GravConst => (6.67408d * Math.Pow(10, -11));
public static double EarthMass => (5.972d * Math.Pow(10, 24));
public static double EarthRadius => 6371000d;
public static float GravAccelerate(float height, float mass=1f)
{
return (float)((GravConst * EarthMass * mass) / (Math.Pow(EarthRadius + height, 2)));
}
public static double GravAccelerate(double height, double mass=1d)
{
return (GravConst * EarthMass * mass) / (Math.Pow(EarthRadius + height, 2));
}
}
}
public static class FileC
{
public static string checkstr = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-=_+[]{}\\|;':\",./<>?`~";
public static string[] ReadLines(string text)
{
return text.Split('\n');
}
public static string[] ReadPath(string path)
{
string[] temparr = new string[File.ReadLines(path).Count()];
int i = 0;
foreach(string line in File.ReadLines(path))
{
temparr[i] = line;
i++;
}
return temparr;
}
public static string NumericToJP(string num)
{
string tempnum = "";
for(int i = 0; i < num.Length; i++)
{
if(num[i] == '.')
{
tempnum += "\uff0e";
}
else if(Ut.Types.ParseDigit(num[i]))
{
switch(num[i])
{
case '0': tempnum += "\uff10"; break;
case '1': tempnum += "\uff11"; break;
case '2': tempnum += "\uff12"; break;
case '3': tempnum += "\uff13"; break;
case '4': tempnum += "\uff14"; break;
case '5': tempnum += "\uff15"; break;
case '6': tempnum += "\uff16"; break;
case '7': tempnum += "\uff17"; break;
case '8': tempnum += "\uff18"; break;
case '9': tempnum += "\uff19"; break;
}
}
else if(num[i] == '%')
{
tempnum += "\uff05";
}
}
return tempnum;
}
public static string FloatWithDecimal(string num)
{
int i;
for(i = 0; i < num.Length; i++)
{
if(num[i] == '.') {i = -1; break;}
}
if(i != -1) {return num + ".0";}
return num;
}
}
public class Ut
{
private Administrator admin;
public Ut() {admin = Admin();}
public static Administrator Admin() {return GameObject.Find("Administrator").gameObject.GetComponent<Administrator>();}
public ManageSound SoundManager() {return Admin().SoundManager;}
public CacheManager CacheM() {return Admin().CacheManager;}
public TextM TextM() {return Admin().TextManager;}
public static class Types
{
public static float StringToFloat(string b)
{
return (float.Parse(b));
}
public static int StringToInt(string b)
{
return (int.Parse(b));
}
public static string StringColor(Color color1)
{
return "Color: {" + color1.r + ", " + color1.g + ", " + color1.b + ", " + color1.a + "}";
}
public static string StringList<T>(List<T> listF, bool print=false)
{
string a = "";
for(int i = 0; i < listF.Count; i++)
{
a += ""+listF[i];
if(i + 1 < listF.Count) {a += "\n";}
}
if(print) {Debug.Log("Ut.Types.StringList(List<"+typeof(T)+">): "+a);}
return a;
}
public static bool ParseDigit(char b)
{
switch(b)
{
case '.':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': return true;
default: return false;
}
}
public static int GetParseDigit(char b)
{
switch(b)
{
case '.': return 0;
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default: return 0;
}
}
public static string ParseVector(Vector2 v) {return "(" + v.x + ", " + v.y + ")";}
}
}
public class DataX
{
public Administrator admin;
public DataX()
{
admin = Ut.Admin();
}
//$ Data
private string datacontext = "";
public void DataContext(string ckey) {datacontext = ckey;}
public void IntSet(string key, int id, int val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).IntSet(id, val);}}
public void IntSet(string ckey, string key, int id, int val) {admin.DataManager.GetSheet(ckey, key).IntSet(id, val);}
public void FloatSet(string key, int id, float val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).FloatSet(id, val);}}
public void FloatSet(string ckey, string key, int id, float val) {admin.DataManager.GetSheet(ckey, key).FloatSet(id, val);}
public void BoolSet(string key, int id, bool val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).BoolSet(id, val);}}
public void BoolSet(string ckey, string key, int id, bool val) {admin.DataManager.GetSheet(ckey, key).BoolSet(id, val);}
public void StringSet(string key, int id, string val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).StringSet(id, val);}}
public void StringSet(string ckey, string key, int id, string val) {admin.DataManager.GetSheet(ckey, key).StringSet(id, val);}
public void IntBy(string key, int id, int val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).IntBy(id, val);}}
public void IntBy(string ckey, string key, int id, int val) {admin.DataManager.GetSheet(ckey, key).IntBy(id, val);}
public void FloatBy(string key, int id, float val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).FloatBy(id, val);}}
public void FloatBy(string ckey, string key, int id, float val) {admin.DataManager.GetSheet(ckey, key).FloatBy(id, val);}
public void BoolTog(string key, int id) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).Toggle(id);}}
public void BoolTog(string ckey, string key, int id) {admin.DataManager.GetSheet(ckey, key).Toggle(id);}
public void StringAppend(string key, int id, string val) {if(datacontext != "") {admin.DataManager.GetSheet(datacontext, key).StringAppend(id, val);}}
public void StringAppend(string ckey, string key, int id, string val) {admin.DataManager.GetSheet(ckey, key).StringAppend(id, val);}
public int Int(string key, int id) {if(datacontext != "") {return admin.DataManager.GetSheet(datacontext, key).Int(id);} return 0;}
public int Int(string ckey, string key, int id) {return admin.DataManager.GetSheet(ckey, key).Int(id);}
public float Float(string key, int id) {if(datacontext != "") {return admin.DataManager.GetSheet(datacontext, key).Float(id);} return 0f;}
public float Float(string ckey, string key, int id) {return admin.DataManager.GetSheet(ckey, key).Float(id);}
public bool Bool(string key, int id) {if(datacontext != "") {return admin.DataManager.GetSheet(datacontext, key).Bool(id);} return false;}
public bool Bool(string ckey, string key, int id) {return admin.DataManager.GetSheet(ckey, key).Bool(id);}
public string String(string key, int id) {if(datacontext != "") {return admin.DataManager.GetSheet(datacontext, key).String(id);} return "";}
public string String(string ckey, string key, int id) {return admin.DataManager.GetSheet(ckey, key).String(id);}
public void SaveToFile(string filename)
{if(datacontext == "") {X.Log(205, "FAILED TO SAVE TO FILENAME \"" + filename + "\"");} else {admin.DataManager.SaveToFile(datacontext, Application.streamingAssetsPath + "/" + filename);}}
public void SaveToFile(string ckey, string filename) {admin.DataManager.SaveToFile(ckey, Application.streamingAssetsPath + "/" + filename);}
public void SaveToPath(string path)
{if(datacontext == "") {X.Log(205, "FAILED TO SAVE TO PATH \"" + path + "\"");} else {admin.DataManager.SaveToFile(datacontext, path);}}
public void SaveToPath(string ckey, string path) {admin.DataManager.SaveToFile(ckey, path);}
//$
}
public static class Build
{
public static Dictionary<T, E> Dict<T, E>(params (T Key, E Value)[] elements)
{
Dictionary<T, E> temp = new Dictionary<T, E>();
for(int i = 0; i < elements.Length; i++)
{
temp.Add(elements[i].Key, elements[i].Value);
}
return temp;
}
public static List<T> List<T>(params T[] elements)
{
List<T> temp = new List<T>();
for(int i = 0; i < elements.Length; i++)
{
temp.Add(elements[i]);
}
return temp;
}
//$ NEW
public static List<T>[] NewListArr<T>(int count)
{
List<T>[] temp = new List<T>[count];
for(int i = 0; i < count; i++)
{
temp[i] = new List<T>();
}
return temp;
}
//$ PRINT
public static string Print<T>(T[] arr)
{
string temp = "Array<" + typeof(T) + ">(";
for(int i = 0; i < arr.Length; i++)
{
temp += arr[i];
if(i + 1 < arr.Length) {temp += ", ";}
}
temp += ");";
return temp;
}
public static string Print<T>(List<T> arr)
{
string temp = "List<" + typeof(T) + ">(";
for(int i = 0; i < arr.Count; i++)
{
temp += arr[i];
if(i + 1 < arr.Count) {temp += ", ";}
}
temp += ");";
return temp;
}
}