This commit is contained in:
Caiyanpeng committed 2021-12-28 11:25:09 +08:00
1 parent a2b44262f7
commit 2b390717c2
130 files changed
+21774 -2581

No files matched your search

+72 -15
View File
@@ -1,25 +1,21 @@
using Assets.Scripts.UI.Control;
using DG.Tweening;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
namespace Assets.Scripts
{
public static class Utils
{
/*获取ip*/
@@ -76,6 +72,19 @@ namespace Assets.Scripts
}
return output;
}
/// <summary>
///
/// </summary>
/// <param name="rect"></param>
/// <param name="point">直接输入面板坐标即可</param>
/// <returns></returns>
public static Vector3 GetTruePosition(this Transform rect, Vector2 point)
{
if (!rect.parent) return point;
RectTransform myRect = rect.GetComponent<RectTransform>()
,prect = rect.parent.GetComponent<RectTransform>();
return new Vector2(point.x + prect.sizeDelta.x * (myRect.pivot.x - prect.pivot.x), point.y + prect.sizeDelta.y * (myRect.pivot.y - prect.pivot.y));
}
public static bool isPointInTransfrom(this RectTransform rect,Vector2 point)
{
var MainCanvas = UIManager.Instance.MainCanvas;
@@ -143,9 +152,20 @@ namespace Assets.Scripts
_deviceDict = value;
}
}
/// <summary>
///
/// </summary>
/// <param name="p"></param>
/// <param name="text"></param>
/// <param name="duration"></param>
/// <param name="type">0 错误 1 正确</param>
/// <param name="stopFunc"></param>
/// <param name="isLowest"></param>
/// <param name="showSeconds"></param>
/// <param name="endCallback"></param>
/// <param name="_parent"></param>
public static void showToast(GameObject p, string text, int duration = 2, int type = 0, Func<bool> stopFunc = null, bool isLowest = false,bool showSeconds = false,Action endCallback = null,PFUIPanel _parent = null)
{
//type 0错误 1正确
var parent = UIManager.Instance.ModalsPanel;
if (parent == null)
{
@@ -322,7 +342,7 @@ namespace Assets.Scripts
}
public static Dictionary<string, Texture> propTextureCache = new Dictionary<string, Texture>();
public delegate Coroutine StartCoroutine(IEnumerator routine);
public static void DisplayImage(RawImage img, string url, bool cache = false,Dictionary<string,Texture> caches = null)
public static void DisplayImage(MaskableGraphic img, string url, bool cache = false,Dictionary<string,Texture> caches = null)
{
if (string.IsNullOrEmpty(url))
return;
@@ -340,7 +360,15 @@ namespace Assets.Scripts
{
if (propTextureCache.ContainsKey(url))
{
img.texture = propTextureCache[url];
var texture = propTextureCache[url];
if (img.GetComponent<RawImage>())
{
img.GetComponent<RawImage>().texture = texture;
}
else if (img.GetComponent<Image>())
{
img.GetComponent<Image>().ShowImageWithTexture(texture);
}
return;
}
}
@@ -358,7 +386,7 @@ namespace Assets.Scripts
/// <param name="img"></param>
/// <param name="url"></param>
/// <param name="caches"></param>
public static void DisplayImageTempDict(RawImage img, string url, Dictionary<string, Texture> caches = null)
public static void DisplayImageTempDict(MaskableGraphic img, string url, Dictionary<string, Texture> caches = null)
{
if (string.IsNullOrEmpty(url))
return;
@@ -366,7 +394,15 @@ namespace Assets.Scripts
{
if (caches.ContainsKey(url))
{
img.texture = caches[url];
var texture = caches[url];
if (img.GetComponent<RawImage>())
{
img.GetComponent<RawImage>().texture = texture;
}
else if (img.GetComponent<Image>())
{
img.GetComponent<Image>().ShowImageWithTexture(texture);
}
return;
}
}
@@ -402,7 +438,7 @@ namespace Assets.Scripts
}
}
}
static IEnumerator DownloadImage(RawImage img,string MediaUrl, Action<Texture> action = null)
static IEnumerator DownloadImage(MaskableGraphic img,string MediaUrl, Action<Texture> action = null)
{
UnityWebRequest request = UnityWebRequest.Get(MediaUrl);
yield return request.SendWebRequest();
@@ -411,10 +447,19 @@ namespace Assets.Scripts
else if (img != null)
{
var data = request.downloadHandler.data;
img.texture = Utils.GetDownloadTexture(MediaUrl, data);
var texture = Utils.GetDownloadTexture(MediaUrl, data);
if (img.GetComponent<RawImage>())
{
img.GetComponent<RawImage>().texture = texture;
}
else if(img.GetComponent<Image>())
{
img.GetComponent<Image>().ShowImageWithTexture(texture);
}
if (action != null)
{
action.Invoke(img.texture);
action.Invoke(texture);
}
}
}
@@ -640,17 +685,29 @@ namespace Assets.Scripts
}
}
/*下载文件*/
public static void DisplayHead(RawImage raw, string s)
public static void DisplayHead(MaskableGraphic raw, string s)
{
if (string.IsNullOrEmpty(s))
{
raw.texture = Resources.Load<Texture>("Images/icon-1024");
var t = Resources.Load<Texture>("Images/icon-1024");
if (raw.GetComponent<RawImage>())
{
raw.GetComponent<RawImage>().texture = Resources.Load<Texture>("Images/icon-1024");
}
else if (raw.GetComponent<Image>())
{
raw.GetComponent<Image>().ShowImageWithTexture(t);
}
}
else
{
DisplayImage(raw, s);
}
}
public static void ShowImageWithTexture(this Image img, Texture t)
{
img.sprite = Sprite.Create((Texture2D)t, new Rect(0, 0, t.width, t.height), Vector2.zero);
}
public static void SetTextWithEllipsis(this Text textComponent, string value)
{
var generator = new TextGenerator();