Commit 492a9c8d authored by mercury233's avatar mercury233

lf

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