Commit d7e6bca6 authored by mercury233's avatar mercury233

add GetTexture2DFromZip

parent 2b482758
Pipeline #12288 failed with stages
in 29 minutes and 13 seconds
using System; using Ionic.Zip;
using System.Collections.Generic; using System;
using System.Diagnostics; using System.Collections.Generic;
using System.Globalization; using System.Diagnostics;
using System.IO; using System.Globalization;
using System.Linq; using System.IO;
using System.Runtime.InteropServices; using System.Linq;
using System.Text; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Text;
using UnityEngine; using System.Threading.Tasks;
using UnityEngine.Rendering; using UnityEngine;
using YGOSharp.OCGWrapper.Enums; using UnityEngine.Rendering;
using Debug = UnityEngine.Debug; using YGOSharp.OCGWrapper.Enums;
using Object = UnityEngine.Object; using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object;
public static class UIHelper
{ public static class UIHelper
public delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam); {
public delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam);
public enum RenderingMode
{ public enum RenderingMode
Opaque, {
Cutout, Opaque,
Fade, Cutout,
Transparent Fade,
} Transparent
}
private static IntPtr myHWND = IntPtr.Zero;
private static IntPtr myHWND = IntPtr.Zero;
public static Dictionary<string, Texture2D> faces = new Dictionary<string, Texture2D>();
public static Dictionary<string, Texture2D> faces = new Dictionary<string, Texture2D>();
[DllImport("user32")]
private static extern bool FlashWindow(IntPtr handle, bool invert); [DllImport("user32")]
private static extern bool FlashWindow(IntPtr handle, bool invert);
[DllImport("user32", SetLastError = true)]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam); [DllImport("user32", SetLastError = true)]
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
[DllImport("user32", SetLastError = true)]
private static extern IntPtr GetParent(IntPtr hWnd); [DllImport("user32", SetLastError = true)]
private static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr lpdwProcessId); [DllImport("user32")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr lpdwProcessId);
[DllImport("user32")]
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpString, [DllImport("user32")]
int nMaxCount); private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpString,
int nMaxCount);
[DllImport("user32")]
private static extern bool IsZoomed(IntPtr hWnd); [DllImport("user32")]
private static extern bool IsZoomed(IntPtr hWnd);
[DllImport("user32")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("kernel32")]
private static extern void SetLastError(uint dwErrCode); [DllImport("kernel32")]
private static extern void SetLastError(uint dwErrCode);
private static IntPtr GetProcessWnd()
{ private static IntPtr GetProcessWnd()
if (myHWND != IntPtr.Zero) {
return myHWND; if (myHWND != IntPtr.Zero)
return myHWND;
var ptrWnd = IntPtr.Zero;
var pid = (IntPtr) Process.GetCurrentProcess().Id; // 当前进程 ID var ptrWnd = IntPtr.Zero;
var pid = (IntPtr) Process.GetCurrentProcess().Id; // 当前进程 ID
var bResult = EnumWindows(delegate(IntPtr hwnd, IntPtr mypid)
{ var bResult = EnumWindows(delegate(IntPtr hwnd, IntPtr mypid)
var id = IntPtr.Zero; {
var id = IntPtr.Zero;
var ClassName = new StringBuilder(256);
GetClassNameW(hwnd, ClassName, ClassName.Capacity); var ClassName = new StringBuilder(256);
GetClassNameW(hwnd, ClassName, ClassName.Capacity);
if (string.Compare(ClassName.ToString(), "UnityWndClass", true, CultureInfo.InvariantCulture) == 0)
{ if (string.Compare(ClassName.ToString(), "UnityWndClass", true, CultureInfo.InvariantCulture) == 0)
GetWindowThreadProcessId(hwnd, ref id); {
if (id == mypid) // 找到进程对应的主窗口句柄 GetWindowThreadProcessId(hwnd, ref id);
{ if (id == mypid) // 找到进程对应的主窗口句柄
ptrWnd = hwnd; // 把句柄缓存起来 {
SetLastError(0); // 设置无错误 ptrWnd = hwnd; // 把句柄缓存起来
return false; // 返回 false 以终止枚举窗口 SetLastError(0); // 设置无错误
} return false; // 返回 false 以终止枚举窗口
} }
}
return true;
}, pid); return true;
}, pid);
if (!bResult && Marshal.GetLastWin32Error() == 0) myHWND = ptrWnd;
if (!bResult && Marshal.GetLastWin32Error() == 0) myHWND = ptrWnd;
return myHWND;
} return myHWND;
}
public static void Flash()
{ public static void Flash()
FlashWindow(GetProcessWnd(), true); {
} FlashWindow(GetProcessWnd(), true);
}
public static bool isMaximized()
{ public static bool isMaximized()
#if UNITY_STANDALONE_WIN {
return IsZoomed(GetProcessWnd()); #if UNITY_STANDALONE_WIN
#else return IsZoomed(GetProcessWnd());
// not a easy thing to check window status on non-windows desktop... #else
return false; // not a easy thing to check window status on non-windows desktop...
#endif return false;
} #endif
}
public static void MaximizeWindow()
{ public static void MaximizeWindow()
#if UNITY_STANDALONE_WIN {
ShowWindow(GetProcessWnd(), 3); // SW_MAXIMIZE #if UNITY_STANDALONE_WIN
#endif ShowWindow(GetProcessWnd(), 3); // SW_MAXIMIZE
} #endif
}
public static void RestoreWindow()
{ public static void RestoreWindow()
#if UNITY_STANDALONE_WIN {
ShowWindow(GetProcessWnd(), 9); // SW_RESTORE #if UNITY_STANDALONE_WIN
#endif ShowWindow(GetProcessWnd(), 9); // SW_RESTORE
} #endif
}
public static bool shouldMaximize()
{ public static bool shouldMaximize()
return fromStringToBool(Config.Get("maximize_", "0")); {
} return fromStringToBool(Config.Get("maximize_", "0"));
}
public static void SetMaterialRenderingMode(Material material, RenderingMode renderingMode)
{ public static void SetMaterialRenderingMode(Material material, RenderingMode renderingMode)
switch (renderingMode) {
{ switch (renderingMode)
case RenderingMode.Opaque: {
material.SetInt("_SrcBlend", (int) BlendMode.One); case RenderingMode.Opaque:
material.SetInt("_DstBlend", (int) BlendMode.Zero); material.SetInt("_SrcBlend", (int) BlendMode.One);
material.SetInt("_ZWrite", 1); material.SetInt("_DstBlend", (int) BlendMode.Zero);
material.DisableKeyword("_ALPHATEST_ON"); material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.DisableKeyword("_ALPHABLEND_ON");
material.renderQueue = -1; material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
break; material.renderQueue = -1;
case RenderingMode.Cutout: break;
material.SetInt("_SrcBlend", (int) BlendMode.One); case RenderingMode.Cutout:
material.SetInt("_DstBlend", (int) BlendMode.Zero); material.SetInt("_SrcBlend", (int) BlendMode.One);
material.SetInt("_ZWrite", 1); material.SetInt("_DstBlend", (int) BlendMode.Zero);
material.EnableKeyword("_ALPHATEST_ON"); material.SetInt("_ZWrite", 1);
material.DisableKeyword("_ALPHABLEND_ON"); material.EnableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.DisableKeyword("_ALPHABLEND_ON");
material.renderQueue = 2450; material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
break; material.renderQueue = 2450;
case RenderingMode.Fade: break;
material.SetInt("_SrcBlend", (int) BlendMode.SrcAlpha); case RenderingMode.Fade:
material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha); material.SetInt("_SrcBlend", (int) BlendMode.SrcAlpha);
material.SetInt("_ZWrite", 0); material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha);
material.DisableKeyword("_ALPHATEST_ON"); material.SetInt("_ZWrite", 0);
material.EnableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHATEST_ON");
material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.EnableKeyword("_ALPHABLEND_ON");
material.renderQueue = 3000; material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
break; material.renderQueue = 3000;
case RenderingMode.Transparent: break;
material.SetInt("_SrcBlend", (int) BlendMode.One); case RenderingMode.Transparent:
material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha); material.SetInt("_SrcBlend", (int) BlendMode.One);
material.SetInt("_ZWrite", 0); material.SetInt("_DstBlend", (int) BlendMode.OneMinusSrcAlpha);
material.DisableKeyword("_ALPHATEST_ON"); material.SetInt("_ZWrite", 0);
material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHATEST_ON");
material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.DisableKeyword("_ALPHABLEND_ON");
material.renderQueue = 3000; material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
break; material.renderQueue = 3000;
} break;
} }
}
internal static void registEvent(UIButton btn, Action function)
{ internal static void registEvent(UIButton btn, Action function)
if (btn != null) {
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>(); var d = btn.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>();
btn.onClick.Clear(); d.actionInMono = function;
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Clear();
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
internal static Texture2D[] sliceField(Texture2D textureField_)
{ internal static Texture2D[] sliceField(Texture2D textureField_)
var textureField = ScaleTexture(textureField_, 1024, 819); {
var returnValue = new Texture2D[3]; var textureField = ScaleTexture(textureField_, 1024, 819);
returnValue[0] = new Texture2D(textureField.width, textureField.height); var returnValue = new Texture2D[3];
returnValue[1] = new Texture2D(textureField.width, textureField.height); returnValue[0] = new Texture2D(textureField.width, textureField.height);
returnValue[2] = new Texture2D(textureField.width, textureField.height); returnValue[1] = new Texture2D(textureField.width, textureField.height);
var zuo = textureField.width * 69f / 320f; returnValue[2] = new Texture2D(textureField.width, textureField.height);
var you = textureField.width * 247f / 320f; var zuo = textureField.width * 69f / 320f;
for (var w = 0; w < textureField.width; w++) var you = textureField.width * 247f / 320f;
for (var h = 0; h < textureField.height; h++) for (var w = 0; w < textureField.width; w++)
{ for (var h = 0; h < textureField.height; h++)
var c = textureField.GetPixel(w, h); {
if (c.a < 0.05f) c.a = 0; var c = textureField.GetPixel(w, h);
if (w < zuo) if (c.a < 0.05f) c.a = 0;
{ if (w < zuo)
returnValue[0].SetPixel(w, h, c); {
returnValue[1].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[0].SetPixel(w, h, c);
returnValue[2].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[1].SetPixel(w, h, new Color(0, 0, 0, 0));
} returnValue[2].SetPixel(w, h, new Color(0, 0, 0, 0));
else if (w > you) }
{ else if (w > you)
returnValue[2].SetPixel(w, h, c); {
returnValue[0].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[2].SetPixel(w, h, c);
returnValue[1].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[0].SetPixel(w, h, new Color(0, 0, 0, 0));
} returnValue[1].SetPixel(w, h, new Color(0, 0, 0, 0));
else }
{ else
returnValue[1].SetPixel(w, h, c); {
returnValue[0].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[1].SetPixel(w, h, c);
returnValue[2].SetPixel(w, h, new Color(0, 0, 0, 0)); returnValue[0].SetPixel(w, h, new Color(0, 0, 0, 0));
} returnValue[2].SetPixel(w, h, new Color(0, 0, 0, 0));
} }
}
returnValue[0].Apply();
returnValue[1].Apply(); returnValue[0].Apply();
returnValue[2].Apply(); returnValue[1].Apply();
return returnValue; returnValue[2].Apply();
} return returnValue;
}
private static Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight)
{ private static Texture2D ScaleTexture(Texture2D source, int targetWidth, int targetHeight)
var result = new Texture2D(targetWidth, targetHeight, source.format, false); {
var result = new Texture2D(targetWidth, targetHeight, source.format, false);
var incX = 1.0f / targetWidth;
var incY = 1.0f / targetHeight; var incX = 1.0f / targetWidth;
var incY = 1.0f / targetHeight;
for (var i = 0; i < result.height; ++i)
for (var j = 0; j < result.width; ++j) for (var i = 0; i < result.height; ++i)
{ for (var j = 0; j < result.width; ++j)
var newColor = source.GetPixelBilinear(j / (float) result.width, i / (float) result.height); {
result.SetPixel(j, i, newColor); var newColor = source.GetPixelBilinear(j / (float) result.width, i / (float) result.height);
} result.SetPixel(j, i, newColor);
}
result.Apply();
return result; result.Apply();
} return result;
}
public static T getByName<T>(GameObject father, string name) where T : Component
{ public static T getByName<T>(GameObject father, string name) where T : Component
T return_value = null; {
var all = father.transform.GetComponentsInChildren<T>(); T return_value = null;
for (var i = 0; i < all.Length; i++) var all = father.transform.GetComponentsInChildren<T>();
if (all[i].name == name) for (var i = 0; i < all.Length; i++)
return_value = all[i]; if (all[i].name == name)
return return_value; return_value = all[i];
} return return_value;
}
public static void InterGameObject(GameObject father)
{ public static void InterGameObject(GameObject father)
var all = father.transform.GetComponentsInChildren<UILabel>(); {
for (var i = 0; i < all.Length; i++) var all = father.transform.GetComponentsInChildren<UILabel>();
if (all[i].name.Length > 1 && all[i].name[0] == '!' || all[i].name == "yes_" || all[i].name == "no_") for (var i = 0; i < all.Length; i++)
all[i].text = InterString.Get(all[i].text); if (all[i].name.Length > 1 && all[i].name[0] == '!' || all[i].name == "yes_" || all[i].name == "no_")
} all[i].text = InterString.Get(all[i].text);
}
public static GameObject getByName(GameObject father, string name)
{ public static GameObject getByName(GameObject father, string name)
GameObject return_value = null; {
var all = father.transform.GetComponentsInChildren<Transform>(); GameObject return_value = null;
for (var i = 0; i < all.Length; i++) var all = father.transform.GetComponentsInChildren<Transform>();
if (all[i].name == name) for (var i = 0; i < all.Length; i++)
return_value = all[i].gameObject; if (all[i].name == name)
return return_value; return_value = all[i].gameObject;
} return return_value;
}
public static T getByName<T>(GameObject father) where T : Component
{ public static T getByName<T>(GameObject father) where T : Component
var return_value = father.transform.GetComponentInChildren<T>(); {
return return_value; var return_value = father.transform.GetComponentInChildren<T>();
} return return_value;
}
public static UILabel getLabelName(GameObject father, string name)
{ public static UILabel getLabelName(GameObject father, string name)
UILabel return_value = null; {
var all = father.transform.GetComponentsInChildren<UILabel>(); UILabel return_value = null;
for (var i = 0; i < all.Length; i++) var all = father.transform.GetComponentsInChildren<UILabel>();
if (all[i].name == name for (var i = 0; i < all.Length; i++)
|| if (all[i].name == name
all[i].transform.parent != null && all[i].transform.parent.name == name ||
|| all[i].transform.parent != null && all[i].transform.parent.name == name
all[i].transform.parent.parent != null && all[i].transform.parent.parent.name == name ||
|| all[i].transform.parent.parent != null && all[i].transform.parent.parent.name == name
all[i].transform.parent.parent.parent != null && all[i].transform.parent.parent.parent.name == name ||
) all[i].transform.parent.parent.parent != null && all[i].transform.parent.parent.parent.name == name
return_value = all[i]; )
for (var i = 0; i < all.Length; i++) return_value = all[i];
if (all[i].name == name) for (var i = 0; i < all.Length; i++)
return_value = all[i]; if (all[i].name == name)
return return_value; return_value = all[i];
} return return_value;
}
internal static int[] get_decklieshuArray(int count)
{ internal static int[] get_decklieshuArray(int count)
var ret = new int[4]; {
ret[0] = 10; var ret = new int[4];
ret[1] = 10; ret[0] = 10;
ret[2] = 10; ret[1] = 10;
ret[3] = 10; ret[2] = 10;
for (var i = 41; i <= count; i++) ret[3] = 10;
{ for (var i = 41; i <= count; i++)
var index = i % 4; {
index--; var index = i % 4;
if (index == -1) index = 3; index--;
ret[index]++; if (index == -1) index = 3;
} ret[index]++;
}
return ret;
} return ret;
}
public static void trySetLableText(GameObject father, string name, string text)
{ public static void trySetLableText(GameObject father, string name, string text)
var l = getLabelName(father, name); {
if (l != null) var l = getLabelName(father, name);
l.text = text; if (l != null)
else l.text = text;
Program.DEBUGLOG("NO Lable" + name); else
} Program.DEBUGLOG("NO Lable" + name);
}
public static string tryGetLableText(GameObject father, string name)
{ public static string tryGetLableText(GameObject father, string name)
var l = getLabelName(father, name); {
if (l != null) return l.text; var l = getLabelName(father, name);
if (l != null) return l.text;
return "";
} return "";
}
public static string[] Split(this string str, string s)
{ public static string[] Split(this string str, string s)
return str.Split(new[] {s}, StringSplitOptions.RemoveEmptyEntries); {
} return str.Split(new[] {s}, StringSplitOptions.RemoveEmptyEntries);
}
public static void registEvent(GameObject father, string name,
Action<GameObject, Servant.messageSystemValue> function, Servant.messageSystemValue value, string name2 = "") public static void registEvent(GameObject father, string name,
{ Action<GameObject, Servant.messageSystemValue> function, Servant.messageSystemValue value, string name2 = "")
var input = getByName<UIInput>(father, name); {
if (input != null) var input = getByName<UIInput>(father, name);
{ if (input != null)
var d = input.gameObject.GetComponent<MonoListenerRMS_ized>(); {
if (d == null) d = input.gameObject.AddComponent<MonoListenerRMS_ized>(); var d = input.gameObject.GetComponent<MonoListenerRMS_ized>();
d.actionInMono = function; if (d == null) d = input.gameObject.AddComponent<MonoListenerRMS_ized>();
d.value = value; d.actionInMono = function;
input.onSubmit.Clear(); d.value = value;
input.onSubmit.Add(new EventDelegate(d, "function")); input.onSubmit.Clear();
var btns = getByName<UIButton>(father, name2); input.onSubmit.Add(new EventDelegate(d, "function"));
if (btns != null) var btns = getByName<UIButton>(father, name2);
{ if (btns != null)
btns.onClick.Clear(); {
btns.onClick.Add(new EventDelegate(d, "function")); btns.onClick.Clear();
} btns.onClick.Add(new EventDelegate(d, "function"));
}
return;
} return;
}
var btn = getByName<UIButton>(father, name);
if (btn != null) var btn = getByName<UIButton>(father, name);
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoListenerRMS_ized>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoListenerRMS_ized>(); var d = btn.gameObject.GetComponent<MonoListenerRMS_ized>();
d.actionInMono = function; if (d == null) d = btn.gameObject.AddComponent<MonoListenerRMS_ized>();
d.value = value; d.actionInMono = function;
btn.onClick.Clear(); d.value = value;
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Clear();
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static void registEventbtn(GameObject father, string name, Action function)
{ public static void registEventbtn(GameObject father, string name, Action function)
var btn = getByName<UIButton>(father, name); {
if (btn != null) var btn = getByName<UIButton>(father, name);
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>(); var d = btn.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>();
btn.onClick.Clear(); d.actionInMono = function;
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Clear();
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static void registEvent(GameObject father, string name, Action function)
{ public static void registEvent(GameObject father, string name, Action function)
var slider = getByName<UISlider>(father, name); {
if (slider != null) var slider = getByName<UISlider>(father, name);
{ if (slider != null)
var d = slider.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = slider.gameObject.AddComponent<MonoDelegate>(); var d = slider.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = slider.gameObject.AddComponent<MonoDelegate>();
slider.onChange.Add(new EventDelegate(d, "function")); d.actionInMono = function;
return; slider.onChange.Add(new EventDelegate(d, "function"));
} return;
}
var list = getByName<UIPopupList>(father, name);
if (list != null) var list = getByName<UIPopupList>(father, name);
{ if (list != null)
var d = list.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = list.gameObject.AddComponent<MonoDelegate>(); var d = list.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = list.gameObject.AddComponent<MonoDelegate>();
list.onChange.Add(new EventDelegate(d, "function")); d.actionInMono = function;
return; list.onChange.Add(new EventDelegate(d, "function"));
} return;
}
var tog = getByName<UIToggle>(father, name);
if (tog != null) var tog = getByName<UIToggle>(father, name);
{ if (tog != null)
var d = tog.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = tog.gameObject.AddComponent<MonoDelegate>(); var d = tog.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = tog.gameObject.AddComponent<MonoDelegate>();
tog.onChange.Clear(); d.actionInMono = function;
tog.onChange.Add(new EventDelegate(d, "function")); tog.onChange.Clear();
return; tog.onChange.Add(new EventDelegate(d, "function"));
} return;
}
var input = getByName<UIInput>(father, name);
if (input != null) var input = getByName<UIInput>(father, name);
{ if (input != null)
var d = input.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = input.gameObject.AddComponent<MonoDelegate>(); var d = input.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = input.gameObject.AddComponent<MonoDelegate>();
input.onSubmit.Clear(); d.actionInMono = function;
input.onSubmit.Add(new EventDelegate(d, "function")); input.onSubmit.Clear();
return; input.onSubmit.Add(new EventDelegate(d, "function"));
} return;
}
var bar = getByName<UIScrollBar>(father, name);
if (bar != null) var bar = getByName<UIScrollBar>(father, name);
{ if (bar != null)
var d = bar.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = bar.gameObject.AddComponent<MonoDelegate>(); var d = bar.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = bar.gameObject.AddComponent<MonoDelegate>();
bar.onChange.Clear(); d.actionInMono = function;
bar.onChange.Add(new EventDelegate(d, "function")); bar.onChange.Clear();
return; bar.onChange.Add(new EventDelegate(d, "function"));
} return;
}
var btn = getByName<UIButton>(father, name);
if (btn != null) var btn = getByName<UIButton>(father, name);
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>(); var d = btn.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>();
btn.onClick.Clear(); d.actionInMono = function;
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Clear();
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static void addButtonEvent_toolShift(GameObject father, string name, Action function)
{ public static void addButtonEvent_toolShift(GameObject father, string name, Action function)
var btn = getByName<UIButton>(father, name); {
if (btn != null) var btn = getByName<UIButton>(father, name);
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>(); var d = btn.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = btn.gameObject.AddComponent<MonoDelegate>();
btn.onClick.Clear(); d.actionInMono = function;
btn.onClick.Add(new EventDelegate(btn.gameObject.GetComponent<toolShift>(), "shift")); btn.onClick.Clear();
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Add(new EventDelegate(btn.gameObject.GetComponent<toolShift>(), "shift"));
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static void registClickListener(GameObject father, string name, Action<GameObject> ES_listenerForGameObject)
{ public static void registClickListener(GameObject father, string name, Action<GameObject> ES_listenerForGameObject)
var btn = getByName<UIButton>(father, name); {
if (btn != null) var btn = getByName<UIButton>(father, name);
{ if (btn != null)
var d = btn.gameObject.GetComponent<MonoListener>(); {
if (d == null) d = btn.gameObject.AddComponent<MonoListener>(); var d = btn.gameObject.GetComponent<MonoListener>();
d.actionInMono = ES_listenerForGameObject; if (d == null) d = btn.gameObject.AddComponent<MonoListener>();
btn.onClick.Clear(); d.actionInMono = ES_listenerForGameObject;
btn.onClick.Add(new EventDelegate(d, "function")); btn.onClick.Clear();
} btn.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static Vector2 get_hang_lie(int index, int meihangdegeshu)
{ public static Vector2 get_hang_lie(int index, int meihangdegeshu)
var return_value = Vector2.zero; {
return_value.x = index / meihangdegeshu; var return_value = Vector2.zero;
return_value.y = index % meihangdegeshu; return_value.x = index / meihangdegeshu;
return return_value; return_value.y = index % meihangdegeshu;
} return return_value;
}
internal static Vector2 get_hang_lieArry(int v, int[] hangshu)
{ internal static Vector2 get_hang_lieArry(int v, int[] hangshu)
var return_value = Vector2.zero; {
for (var i = 0; i < 4; i++) var return_value = Vector2.zero;
if (v < hangshu[i]) for (var i = 0; i < 4; i++)
{ if (v < hangshu[i])
return_value.x = i; {
return_value.y = v; return_value.x = i;
return return_value; return_value.y = v;
} return return_value;
else }
{ else
v -= hangshu[i]; {
} v -= hangshu[i];
}
return return_value;
} return return_value;
}
public static int get_zuihouyihangdegeshu(int zongshu, int meihangdegeshu)
{ public static int get_zuihouyihangdegeshu(int zongshu, int meihangdegeshu)
var re = 0; {
re = zongshu % meihangdegeshu; var re = 0;
if (re == 0) re = meihangdegeshu; re = zongshu % meihangdegeshu;
return re; if (re == 0) re = meihangdegeshu;
} return re;
}
public static bool get_shifouzaizuihouyihang(int zongshu, int meihangdegeshu, int index)
{ public static bool get_shifouzaizuihouyihang(int zongshu, int meihangdegeshu, int index)
return index / meihangdegeshu == zongshu / meihangdegeshu; {
} return index / meihangdegeshu == zongshu / meihangdegeshu;
}
public static int get_zonghangshu(int zongshu, int meihangdegeshu)
{ public static int get_zonghangshu(int zongshu, int meihangdegeshu)
return (zongshu - 1) / meihangdegeshu + 1; {
} return (zongshu - 1) / meihangdegeshu + 1;
}
public static void registEvent(UIScrollView uIScrollView, Action function)
{ public static void registEvent(UIScrollView uIScrollView, Action function)
uIScrollView.onScrolled = new UIScrollView.OnDragNotification(function); {
} uIScrollView.onScrolled = new UIScrollView.OnDragNotification(function);
}
public static void registEvent(UIScrollBar scrollBar, Action function)
{ public static void registEvent(UIScrollBar scrollBar, Action function)
var d = scrollBar.gameObject.GetComponent<MonoDelegate>(); {
if (d == null) d = scrollBar.gameObject.AddComponent<MonoDelegate>(); var d = scrollBar.gameObject.GetComponent<MonoDelegate>();
d.actionInMono = function; if (d == null) d = scrollBar.gameObject.AddComponent<MonoDelegate>();
scrollBar.onChange.Clear(); d.actionInMono = function;
scrollBar.onChange.Add(new EventDelegate(d, "function")); scrollBar.onChange.Clear();
} scrollBar.onChange.Add(new EventDelegate(d, "function"));
}
public static void registUIEventTriggerForClick(GameObject gameObject, Action<GameObject> listenerForClicked)
{ public static void registUIEventTriggerForClick(GameObject gameObject, Action<GameObject> listenerForClicked)
var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>(); {
boxCollider.gameObject.name = gameObject.name; var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>();
if (boxCollider != null) boxCollider.gameObject.name = gameObject.name;
{ if (boxCollider != null)
var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>(); {
var d = boxCollider.gameObject.AddComponent<MonoListener>(); var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>();
d.actionInMono = listenerForClicked; var d = boxCollider.gameObject.AddComponent<MonoListener>();
uIEventTrigger.onClick.Add(new EventDelegate(d, "function")); d.actionInMono = listenerForClicked;
} uIEventTrigger.onClick.Add(new EventDelegate(d, "function"));
} }
}
public static void registUIEventTriggerForHoverOver(GameObject gameObject, Action<GameObject> listenerForHoverOver)
{ public static void registUIEventTriggerForHoverOver(GameObject gameObject, Action<GameObject> listenerForHoverOver)
var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>(); {
if (boxCollider != null) var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>();
{ if (boxCollider != null)
var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>(); {
var d = boxCollider.gameObject.AddComponent<MonoListener>(); var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>();
d.actionInMono = listenerForHoverOver; var d = boxCollider.gameObject.AddComponent<MonoListener>();
uIEventTrigger.onHoverOver.Add(new EventDelegate(d, "function")); d.actionInMono = listenerForHoverOver;
} uIEventTrigger.onHoverOver.Add(new EventDelegate(d, "function"));
} }
}
internal static GameObject getRealEventGameObject(GameObject gameObject)
{ internal static GameObject getRealEventGameObject(GameObject gameObject)
GameObject re = null; {
var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>(); GameObject re = null;
if (boxCollider != null) re = boxCollider.gameObject; var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>();
return re; if (boxCollider != null) re = boxCollider.gameObject;
} return re;
}
internal static GameObject getGameObject(GameObject gameObject, string name)
{ internal static GameObject getGameObject(GameObject gameObject, string name)
var t = getByName<Transform>(gameObject, name); {
if (t != null) var t = getByName<Transform>(gameObject, name);
return t.gameObject; if (t != null)
return null; return t.gameObject;
} return null;
}
internal static void trySetLableText(GameObject gameObject, string p)
{ internal static void trySetLableText(GameObject gameObject, string p)
try {
{ try
gameObject.GetComponentInChildren<UILabel>().text = p; {
} gameObject.GetComponentInChildren<UILabel>().text = p;
catch (Exception) }
{ catch (Exception)
} {
} }
}
internal static void registEvent(GameObject gameObject, Action act)
{ internal static void registEvent(GameObject gameObject, Action act)
registEvent(gameObject, gameObject.name, act); {
} registEvent(gameObject, gameObject.name, act);
}
internal static void trySetLableTextList(GameObject father, string text)
{ internal static void trySetLableTextList(GameObject father, string text)
try {
{ try
var p = father.GetComponentInChildren<UITextList>(); {
p.Clear(); var p = father.GetComponentInChildren<UITextList>();
p.Add(text); p.Clear();
} p.Add(text);
catch (Exception) }
{ catch (Exception)
Program.DEBUGLOG("NO LableList"); {
} Program.DEBUGLOG("NO LableList");
} }
}
internal static int get_decklieshu(int zongshu)
{ internal static int get_decklieshu(int zongshu)
var return_value = 10; {
for (var i = 0; i < 100; i++) var return_value = 10;
if ((zongshu + i) % 4 == 0) for (var i = 0; i < 100; i++)
{ if ((zongshu + i) % 4 == 0)
return_value = (zongshu + i) / 4; {
break; return_value = (zongshu + i) / 4;
} break;
}
return return_value;
} return return_value;
}
internal static void clearITWeen(GameObject gameObject)
{ internal static void clearITWeen(GameObject gameObject)
var iTweens = gameObject.GetComponents<iTween>(); {
for (var i = 0; i < iTweens.Length; i++) Object.DestroyImmediate(iTweens[i]); var iTweens = gameObject.GetComponents<iTween>();
} for (var i = 0; i < iTweens.Length; i++) Object.DestroyImmediate(iTweens[i]);
}
internal static float get_left_right_index(float left, float right, int i, int count)
{ internal static float get_left_right_index(float left, float right, int i, int count)
float return_value = 0; {
if (count == 1) float return_value = 0;
{ if (count == 1)
return_value = left + right; {
return_value /= 2; return_value = left + right;
} return_value /= 2;
else }
{ else
return_value = left + (right - left) * i / (count - 1); {
} return_value = left + (right - left) * i / (count - 1);
}
return return_value;
} return return_value;
}
internal static float get_left_right_indexZuo(float v1, float v2, int v3, int count, int v4)
{ internal static float get_left_right_indexZuo(float v1, float v2, int v3, int count, int v4)
if (count >= v4) {
return get_left_right_index(v1, v2, v3, count); if (count >= v4)
return get_left_right_index(v1, v2, v3, v4); return get_left_right_index(v1, v2, v3, count);
} return get_left_right_index(v1, v2, v3, v4);
}
internal static float get_left_right_indexEnhanced(float left, float right, int i, int count, int illusion)
{ internal static float get_left_right_indexEnhanced(float left, float right, int i, int count, int illusion)
float return_value = 0; {
if (count > illusion) float return_value = 0;
{ if (count > illusion)
if (count == 1) {
{ if (count == 1)
return_value = left + right; {
return_value /= 2; return_value = left + right;
} return_value /= 2;
else }
{ else
return_value = left + (right - left) * i / (count - 1); {
} return_value = left + (right - left) * i / (count - 1);
} }
else }
{ else
if (illusion == 1) {
{ if (illusion == 1)
return_value = left + right; {
return_value /= 2; return_value = left + right;
} return_value /= 2;
else }
{ else
var l = left; {
var r = right; var l = left;
var per = (right - left) / (illusion - 1); var r = right;
var length = per * (count + 1); var per = (right - left) / (illusion - 1);
l = (left + right) / 2f - length / 2f; var length = per * (count + 1);
r = (left + right) / 2f + length / 2f; l = (left + right) / 2f - length / 2f;
return_value = l + per * (i + 1); r = (left + right) / 2f + length / 2f;
} return_value = l + per * (i + 1);
} }
}
return return_value;
} return return_value;
}
internal static void registUIEventTriggerForMouseDown(GameObject gameObject,
Action<GameObject> listenerForMouseDown) internal static void registUIEventTriggerForMouseDown(GameObject gameObject,
{ Action<GameObject> listenerForMouseDown)
var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>(); {
if (boxCollider != null) var boxCollider = gameObject.transform.GetComponentInChildren<BoxCollider>();
{ if (boxCollider != null)
var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>(); {
var d = boxCollider.gameObject.AddComponent<MonoListener>(); var uIEventTrigger = boxCollider.gameObject.AddComponent<UIEventTrigger>();
d.actionInMono = listenerForMouseDown; var d = boxCollider.gameObject.AddComponent<MonoListener>();
uIEventTrigger.onPress.Add(new EventDelegate(d, "function")); d.actionInMono = listenerForMouseDown;
} uIEventTrigger.onPress.Add(new EventDelegate(d, "function"));
} }
}
internal static void iniFaces()
{ internal static void iniFaces()
try {
{ try
var fileInfos = new DirectoryInfo("texture/face").GetFiles(); {
for (var i = 0; i < fileInfos.Length; i++) var fileInfos = new DirectoryInfo("texture/face").GetFiles();
if (fileInfos[i].Name.Length > 4) for (var i = 0; i < fileInfos.Length; i++)
if (fileInfos[i].Name.Substring(fileInfos[i].Name.Length - 4, 4) == ".png") if (fileInfos[i].Name.Length > 4)
{ if (fileInfos[i].Name.Substring(fileInfos[i].Name.Length - 4, 4) == ".png")
var name = fileInfos[i].Name.Substring(0, fileInfos[i].Name.Length - 4); {
if (!faces.ContainsKey(name)) var name = fileInfos[i].Name.Substring(0, fileInfos[i].Name.Length - 4);
try if (!faces.ContainsKey(name))
{ try
faces.Add(name, GetTexture2D("texture/face/" + fileInfos[i].Name)); {
} faces.Add(name, GetTexture2D("texture/face/" + fileInfos[i].Name));
catch (Exception e) }
{ catch (Exception e)
Debug.Log(e); {
} Debug.Log(e);
} }
} }
catch (Exception e) }
{ catch (Exception e)
Debug.Log(e); {
} Debug.Log(e);
} }
}
internal static Texture2D getFace(string name)
{ internal static Texture2D getFace(string name)
Texture2D re = null; {
if (faces.TryGetValue(name, out re)) Texture2D re = null;
if (re != null) if (faces.TryGetValue(name, out re))
return re; if (re != null)
var buffer = Encoding.UTF8.GetBytes(name); return re;
var sum = 0; var buffer = Encoding.UTF8.GetBytes(name);
for (var i = 0; i < buffer.Length; i++) sum += buffer[i]; var sum = 0;
sum = sum % 100; for (var i = 0; i < buffer.Length; i++) sum += buffer[i];
return Program.I().face.faces[sum]; sum = sum % 100;
} return Program.I().face.faces[sum];
}
public static Texture2D GetTexture2D(string path)
{ public static Texture2D GetTexture2D(string path)
var pic = new Texture2D(0, 0); {
pic.LoadImage(File.ReadAllBytes(path)); var pic = new Texture2D(0, 0);
return pic; pic.LoadImage(File.ReadAllBytes(path));
} return pic;
}
public static async Task<Texture2D> GetTexture2DAsync(string path)
{ public static async Task<Texture2D> GetTexture2DAsync(string path)
var pic = new Texture2D(0, 0); {
// Unity < 2021.2 var pic = new Texture2D(0, 0);
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true); // Unity < 2021.2
var data = new byte[stream.Length]; var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
await stream.ReadAsync(data, 0, (int) stream.Length); var data = new byte[stream.Length];
pic.LoadImage(data); await stream.ReadAsync(data, 0, (int) stream.Length);
// Unity >= 2021.2 pic.LoadImage(data);
// pic.LoadImage(await File.ReadAllBytesAsync(path)); // Unity >= 2021.2
return pic; // pic.LoadImage(await File.ReadAllBytesAsync(path));
} return pic;
}
internal static void shiftButton(UIButton btn, bool enabled)
{ public static async Task<Texture2D> GetTexture2DFromZipAsync(ZipFile zip, string file)
if (enabled) {
btn.gameObject.transform.localScale = new Vector3(1, 1, 1); var pic = new Texture2D(0, 0);
else MemoryStream stream = new MemoryStream();
btn.gameObject.transform.localScale = new Vector3(0, 0, 0); ZipEntry entry = zip[file];
//try entry.Extract(stream);
//{ //await Task.Run(() => { entry.Extract(stream); });
// BoxCollider boxCollider = btn.gameObject.GetComponentInChildren<BoxCollider>(); pic.LoadImage(stream.ToArray());
// UILabel label = btn.gameObject.GetComponentInChildren<UILabel>(); return pic;
// label.text = hint; }
// boxCollider.enabled = enabled;
// if (enabled) internal static void shiftButton(UIButton btn, bool enabled)
// { {
// label.color = Color.white; if (enabled)
// } btn.gameObject.transform.localScale = new Vector3(1, 1, 1);
// else else
// { btn.gameObject.transform.localScale = new Vector3(0, 0, 0);
// label.color = Color.gray; //try
// } //{
//} // BoxCollider boxCollider = btn.gameObject.GetComponentInChildren<BoxCollider>();
//catch (Exception) // UILabel label = btn.gameObject.GetComponentInChildren<UILabel>();
//{ // label.text = hint;
//} // boxCollider.enabled = enabled;
} // if (enabled)
// {
internal static void shiftUIToggle(UIToggle tog, bool canClick, bool canChange, string hint) // label.color = Color.white;
{ // }
try // else
{ // {
tog.canChange = canChange; // label.color = Color.gray;
var boxCollider = tog.gameObject.GetComponentInChildren<BoxCollider>(); // }
var label = tog.gameObject.GetComponentInChildren<UILabel>(); //}
label.text = hint; //catch (Exception)
boxCollider.enabled = canClick; //{
if (canClick) //}
getByName<UISprite>(tog.gameObject, "Background").color = Color.white; }
//getByName<UISprite>(tog.gameObject, "Checkmark").color = Color.white;
else internal static void shiftUIToggle(UIToggle tog, bool canClick, bool canChange, string hint)
getByName<UISprite>(tog.gameObject, "Background").color = Color.black; {
//getByName<UISprite>(tog.gameObject, "Checkmark").color = Color.gray; try
} {
catch (Exception) tog.canChange = canChange;
{ var boxCollider = tog.gameObject.GetComponentInChildren<BoxCollider>();
} var label = tog.gameObject.GetComponentInChildren<UILabel>();
} label.text = hint;
boxCollider.enabled = canClick;
internal static string getBufferString(byte[] buffer) if (canClick)
{ getByName<UISprite>(tog.gameObject, "Background").color = Color.white;
var returnValue = ""; //getByName<UISprite>(tog.gameObject, "Checkmark").color = Color.white;
foreach (var item in buffer) returnValue += (int) item + "."; else
return returnValue; getByName<UISprite>(tog.gameObject, "Background").color = Color.black;
} //getByName<UISprite>(tog.gameObject, "Checkmark").color = Color.gray;
}
internal static string getTimeString() catch (Exception)
{ {
return DateTime.Now.ToString("MM-dd「HH:mm:ss」"); }
} }
internal static bool fromStringToBool(string s) internal static string getBufferString(byte[] buffer)
{ {
return s == "1"; var returnValue = "";
} foreach (var item in buffer) returnValue += (int) item + ".";
return returnValue;
internal static string fromBoolToString(bool s) }
{
if (s) internal static string getTimeString()
return "1"; {
return "0"; return DateTime.Now.ToString("MM-dd「HH:mm:ss」");
} }
internal static Vector3 getCamGoodPosition(Vector3 v, float l) internal static bool fromStringToBool(string s)
{ {
var screenposition = Program.I().main_camera.WorldToScreenPoint(v); return s == "1";
return Program.I().main_camera.ScreenToWorldPoint(new Vector3(screenposition.x, screenposition.y, }
screenposition.z + l));
} internal static string fromBoolToString(bool s)
{
public const string sort = "sortByTimeDeck"; if (s)
return "1";
public static IOrderedEnumerable<FileInfo> SortDeck(this IOrderedEnumerable<FileInfo> source) return "0";
{ }
return Config.Get(sort, "1") == "1"
? source.ThenByDescending(f => f.LastWriteTime) internal static Vector3 getCamGoodPosition(Vector3 v, float l)
: source.ThenBy(f => f.Name); {
} var screenposition = Program.I().main_camera.WorldToScreenPoint(v);
return Program.I().main_camera.ScreenToWorldPoint(new Vector3(screenposition.x, screenposition.y,
public static IEnumerable<string> GetDecks(string search = "") screenposition.z + l));
{ }
var deckInUse = Config.Get("deckInUse", "miaowu");
var deckInUsePath = Path.GetFullPath($"deck/{deckInUse}.ydk"); public const string sort = "sortByTimeDeck";
return new DirectoryInfo("deck").EnumerateFiles("*.ydk", SearchOption.AllDirectories)
.Where(f => search == "" || f.Name.Contains(search)) public static IOrderedEnumerable<FileInfo> SortDeck(this IOrderedEnumerable<FileInfo> source)
.OrderByDescending(f => f.FullName == deckInUsePath) {
.ThenBy(f => f.DirectoryName) return Config.Get(sort, "1") == "1"
.SortDeck() ? source.ThenByDescending(f => f.LastWriteTime)
.Select(f => : source.ThenBy(f => f.Name);
f.DirectoryName == Path.GetFullPath("deck") }
? Path.GetFileNameWithoutExtension(f.Name)
: $"{Path.GetFileName(f.DirectoryName)}/{Path.GetFileNameWithoutExtension(f.Name)}"); public static IEnumerable<string> GetDecks(string search = "")
} {
var deckInUse = Config.Get("deckInUse", "miaowu");
public static int CompareTime(object x, object y) var deckInUsePath = Path.GetFullPath($"deck/{deckInUse}.ydk");
{ return new DirectoryInfo("deck").EnumerateFiles("*.ydk", SearchOption.AllDirectories)
if (x == null && y == null) return 0; .Where(f => search == "" || f.Name.Contains(search))
if (x == null) return -1; .OrderByDescending(f => f.FullName == deckInUsePath)
if (y == null) return 1; .ThenBy(f => f.DirectoryName)
var xInfo = (FileInfo) x; .SortDeck()
var yInfo = (FileInfo) y; .Select(f =>
return yInfo.LastWriteTime.CompareTo(xInfo.LastWriteTime); f.DirectoryName == Path.GetFullPath("deck")
} ? Path.GetFileNameWithoutExtension(f.Name)
: $"{Path.GetFileName(f.DirectoryName)}/{Path.GetFileNameWithoutExtension(f.Name)}");
public static int CompareName(object x, object y) }
{
if (x == null && y == null) return 0; public static int CompareTime(object x, object y)
if (x == null) return -1; {
if (y == null) return 1; if (x == null && y == null) return 0;
var xInfo = (FileInfo) x; if (x == null) return -1;
var yInfo = (FileInfo) y; if (y == null) return 1;
return xInfo.FullName.CompareTo(yInfo.FullName); var xInfo = (FileInfo) x;
} var yInfo = (FileInfo) y;
return yInfo.LastWriteTime.CompareTo(xInfo.LastWriteTime);
internal static void playSound(string p, float val) }
{
if (Ocgcore.inSkiping) return; public static int CompareName(object x, object y)
var path = "sound/" + p + ".mp3"; {
if (File.Exists(path) == false) path = "sound/" + p + ".wav"; if (x == null && y == null) return 0;
if (File.Exists(path) == false) path = "sound/" + p + ".ogg"; if (x == null) return -1;
if (File.Exists(path) == false) return; if (y == null) return 1;
path = Environment.CurrentDirectory.Replace("\\", "/") + "/" + path; var xInfo = (FileInfo) x;
path = "file:///" + path; var yInfo = (FileInfo) y;
var audio_helper = Program.I().ocgcore.create_s(Program.I().mod_audio_effect); return xInfo.FullName.CompareTo(yInfo.FullName);
audio_helper.GetComponent<audio_helper>().play(path, Program.I().setting.soundValue()); }
Program.I().destroy(audio_helper, 5f);
} internal static void playSound(string p, float val)
{
internal static string getGPSstringLocation(GPS p1) if (Ocgcore.inSkiping) return;
{ var path = "sound/" + p + ".mp3";
var res = ""; if (File.Exists(path) == false) path = "sound/" + p + ".wav";
if (p1.controller == 0) if (File.Exists(path) == false) path = "sound/" + p + ".ogg";
res += ""; if (File.Exists(path) == false) return;
else path = Environment.CurrentDirectory.Replace("\\", "/") + "/" + path;
res += InterString.Get("对方"); path = "file:///" + path;
if ((p1.location & (uint) CardLocation.Deck) > 0) res += InterString.Get("卡组"); var audio_helper = Program.I().ocgcore.create_s(Program.I().mod_audio_effect);
if ((p1.location & (uint) CardLocation.Extra) > 0) res += InterString.Get("额外"); audio_helper.GetComponent<audio_helper>().play(path, Program.I().setting.soundValue());
if ((p1.location & (uint) CardLocation.Grave) > 0) res += InterString.Get("墓地"); Program.I().destroy(audio_helper, 5f);
if ((p1.location & (uint) CardLocation.Hand) > 0) res += InterString.Get("手牌"); }
if ((p1.location & (uint) CardLocation.MonsterZone) > 0) res += InterString.Get("前场");
if ((p1.location & (uint) CardLocation.Removed) > 0) res += InterString.Get("除外"); internal static string getGPSstringLocation(GPS p1)
if ((p1.location & (uint) CardLocation.SpellZone) > 0) res += InterString.Get("后场"); {
return res; var res = "";
} if (p1.controller == 0)
res += "";
//internal static string getGPSstringPosition(GPS p1) else
//{ res += InterString.Get("对方");
// string res = ""; if ((p1.location & (uint) CardLocation.Deck) > 0) res += InterString.Get("卡组");
// if ((p1.location & (UInt32)CardLocation.Overlay) > 0) if ((p1.location & (uint) CardLocation.Extra) > 0) res += InterString.Get("额外");
// { if ((p1.location & (uint) CardLocation.Grave) > 0) res += InterString.Get("墓地");
// res += InterString.Get("(被叠放)"); if ((p1.location & (uint) CardLocation.Hand) > 0) res += InterString.Get("手牌");
// } if ((p1.location & (uint) CardLocation.MonsterZone) > 0) res += InterString.Get("前场");
// else if ((p1.location & (uint) CardLocation.Removed) > 0) res += InterString.Get("除外");
// { if ((p1.location & (uint) CardLocation.SpellZone) > 0) res += InterString.Get("后场");
// if ((p1.position & (UInt32)CardPosition.FaceUpAttack) > 0) return res;
// { }
// res += InterString.Get("(表侧攻击)");
// } //internal static string getGPSstringPosition(GPS p1)
// else if ((p1.position & (UInt32)CardPosition.FaceUp_DEFENSE) > 0) //{
// { // string res = "";
// res += InterString.Get("(表侧守备)"); // if ((p1.location & (UInt32)CardLocation.Overlay) > 0)
// } // {
// else if ((p1.position & (UInt32)CardPosition.FaceDownAttack) > 0) // res += InterString.Get("(被叠放)");
// { // }
// res += InterString.Get("(里侧攻击)"); // else
// } // {
// else if ((p1.position & (UInt32)CardPosition.FaceDown_DEFENSE) > 0) // if ((p1.position & (UInt32)CardPosition.FaceUpAttack) > 0)
// { // {
// res += InterString.Get("(里侧守备)"); // res += InterString.Get("(表侧攻击)");
// } // }
// else if ((p1.position & (UInt32)CardPosition.Attack) > 0) // else if ((p1.position & (UInt32)CardPosition.FaceUp_DEFENSE) > 0)
// { // {
// res += InterString.Get("(攻击)"); // res += InterString.Get("(表侧守备)");
// } // }
// else if ((p1.position & (UInt32)CardPosition.POS_DEFENSE) > 0) // else if ((p1.position & (UInt32)CardPosition.FaceDownAttack) > 0)
// { // {
// res += InterString.Get("(守备)"); // res += InterString.Get("(里侧攻击)");
// } // }
// else if ((p1.position & (UInt32)CardPosition.FaceUp) > 0) // else if ((p1.position & (UInt32)CardPosition.FaceDown_DEFENSE) > 0)
// { // {
// res += InterString.Get("(表侧)"); // res += InterString.Get("(里侧守备)");
// } // }
// else if ((p1.position & (UInt32)CardPosition.POS_DEFENSE) > 0) // else if ((p1.position & (UInt32)CardPosition.Attack) > 0)
// { // {
// res += InterString.Get("(里侧)"); // res += InterString.Get("(攻击)");
// } // }
// } // else if ((p1.position & (UInt32)CardPosition.POS_DEFENSE) > 0)
// {
// return res; // res += InterString.Get("(守备)");
//} // }
// else if ((p1.position & (UInt32)CardPosition.FaceUp) > 0)
internal static string getGPSstringName(gameCard card, bool green = false) // {
{ // res += InterString.Get("(表侧)");
var res = ""; // }
res += getGPSstringLocation(card.p) + "\n「" + getSuperName(card.get_data().Name, card.get_data().Id) + "」"; // else if ((p1.position & (UInt32)CardPosition.POS_DEFENSE) > 0)
if (green) return "[00ff00]" + res + "[-]"; // {
return res; // res += InterString.Get("(里侧)");
} // }
// }
internal static string getSuperName(string name, int code)
{ // return res;
var res = ""; //}
res = "[url=" + code + "][u]" + name + "[/u][/url]";
return res; internal static string getGPSstringName(gameCard card, bool green = false)
} {
var res = "";
internal static string getDName(string name, int code) res += getGPSstringLocation(card.p) + "\n「" + getSuperName(card.get_data().Name, card.get_data().Id) + "」";
{ if (green) return "[00ff00]" + res + "[-]";
var res = ""; return res;
res = "「[url=" + code + "][u]" + name + "[/u][/url]」"; }
return res;
} internal static string getSuperName(string name, int code)
{
internal static float getScreenDistance(GameObject a, GameObject b) var res = "";
{ res = "[url=" + code + "][u]" + name + "[/u][/url]";
var sa = Program.I().main_camera.WorldToScreenPoint(a.transform.position); return res;
sa.z = 0; }
var sb = Program.I().main_camera.WorldToScreenPoint(b.transform.position);
sb.z = 0; internal static string getDName(string name, int code)
return Vector3.Distance(sa, sb); {
} var res = "";
res = "「[url=" + code + "][u]" + name + "[/u][/url]」";
internal static void setParent(GameObject child, GameObject parent) return res;
{ }
child.transform.SetParent(parent.transform, true);
var Transforms = child.GetComponentsInChildren<Transform>(); internal static float getScreenDistance(GameObject a, GameObject b)
foreach (var achild in Transforms) {
achild.gameObject.layer = parent.layer; var sa = Program.I().main_camera.WorldToScreenPoint(a.transform.position);
} sa.z = 0;
var sb = Program.I().main_camera.WorldToScreenPoint(b.transform.position);
internal static Vector3 get_close(Vector3 input_vector, Camera cam, float l) sb.z = 0;
{ return Vector3.Distance(sa, sb);
var o = Vector3.zero; }
var scr = cam.WorldToScreenPoint(input_vector);
scr.z -= l; internal static void setParent(GameObject child, GameObject parent)
o = cam.ScreenToWorldPoint(scr); {
return o; child.transform.SetParent(parent.transform, true);
} var Transforms = child.GetComponentsInChildren<Transform>();
foreach (var achild in Transforms)
achild.gameObject.layer = parent.layer;
}
internal static Vector3 get_close(Vector3 input_vector, Camera cam, float l)
{
var o = Vector3.zero;
var scr = cam.WorldToScreenPoint(input_vector);
scr.z -= l;
o = cam.ScreenToWorldPoint(scr);
return o;
}
} }
\ No newline at end of file
using System.Collections.Generic; using Ionic.Zip;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
...@@ -88,6 +89,26 @@ public class GameTextureManager ...@@ -88,6 +89,26 @@ public class GameTextureManager
{ {
if (code == 0) return zero; if (code == 0) return zero;
if (loadedPicture.TryGetValue(code, out var cached)) return await cached; if (loadedPicture.TryGetValue(code, out var cached)) return await cached;
foreach (ZipFile zip in GameZipManager.Zips)
{
if (zip.Name.ToLower().EndsWith("script.zip"))
continue;
foreach (string file in zip.EntryFileNames)
{
foreach (var extname in new[] { ".png", ".jpg" })
{
var path = $"pics/{code}{extname}";
if (file.ToLower() == path)
{
var result = UIHelper.GetTexture2DFromZipAsync(zip, file);
loadedPicture.Add(code, result);
return await result;
}
}
}
}
foreach (var extname in new[] {".png", ".jpg"}) foreach (var extname in new[] {".png", ".jpg"})
{ {
var path = $"picture/card/{code}{extname}"; var path = $"picture/card/{code}{extname}";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment