|
@@ -1,10 +1,13 @@
|
|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
using System.Text;
|
|
|
+using Fort23.Core;
|
|
|
using Fort23.Mono;
|
|
|
using Fort23.UTool;
|
|
|
#if UNITY_EDITOR
|
|
|
+using System.IO;
|
|
|
using UnityEditor;
|
|
|
#endif
|
|
|
using UnityEngine.Experimental.Rendering;
|
|
@@ -251,6 +254,71 @@ namespace UnityEngine.UI
|
|
|
{
|
|
|
SetPack();
|
|
|
}
|
|
|
+#if UNITY_EDITOR
|
|
|
+
|
|
|
+ [ContextMenu("重新设置图片")]
|
|
|
+ public void SetPackEditor()
|
|
|
+ {
|
|
|
+ if (packInfo != null && CurrSpriteAtlas != null)
|
|
|
+ {
|
|
|
+ string assetName = icon_name;
|
|
|
+ if (string.IsNullOrEmpty(icon_name) && sprite != null)
|
|
|
+ {
|
|
|
+ assetName = sprite.name;
|
|
|
+ }
|
|
|
+
|
|
|
+ var loadSprite = CurrSpriteAtlas.GetSprite(assetName);
|
|
|
+ bool isoK = loadSprite != null;
|
|
|
+ if (isoK)
|
|
|
+ {
|
|
|
+ SetSprite(loadSprite);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ [ContextMenu("自动匹配图集")]
|
|
|
+ public void CompareSpritesInAtlas()
|
|
|
+ {
|
|
|
+ if(sprite == null || CurrSpriteAtlas!= null || icon_name != "")
|
|
|
+ return;
|
|
|
+ string targetPath = AssetDatabase.GetAssetPath(sprite);
|
|
|
+ if (string.IsNullOrEmpty(targetPath))
|
|
|
+ {
|
|
|
+ Debug.LogError("无法获取目标 Sprite 的源文件路径");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ string targetMD5 = MD5Helper.FileMD5("D:/FB/XiuXianGame/" + targetPath);
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var allPackgInfo in UGUICacheInfo.uguiPackDB.allPackgInfos)
|
|
|
+ {
|
|
|
+ string path = Application.dataPath + allPackgInfo.PackageJsonPath;
|
|
|
+
|
|
|
+
|
|
|
+ string jsonPath = File.ReadAllText(path);
|
|
|
+ TextrueJson textrueJson = JsonUtility.FromJson<TextrueJson>(jsonPath);
|
|
|
+
|
|
|
+ for (int i = 0; i < textrueJson.newTextureJson.Count; i++)
|
|
|
+ {
|
|
|
+ string texturePath = "/Art/UIAssets" + textrueJson.newTextureJson[i].filePath;
|
|
|
+
|
|
|
+ string spriteMD5 = MD5Helper.FileMD5(Application.dataPath + texturePath);
|
|
|
+
|
|
|
+ if (spriteMD5 == targetMD5)
|
|
|
+ {
|
|
|
+ LogTool.Log($"找到匹配的 Sprite: {textrueJson.newTextureJson[i].textrueName},所在图集: {allPackgInfo.packName},源文件: {targetPath}");
|
|
|
+ packInfo = allPackgInfo;
|
|
|
+ CurrSpriteAtlas = UGUICacheInfo.GetSpriteAtlas(allPackgInfo.packName);
|
|
|
+ icon_name = textrueJson.newTextureJson[i].textrueName;
|
|
|
+ ReashUI();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LogTool.Log("未找到任何匹配的 Sprite");
|
|
|
+ }
|
|
|
+#endif
|
|
|
|
|
|
private void SetPack()
|
|
|
{
|
|
@@ -306,12 +374,12 @@ namespace UnityEngine.UI
|
|
|
Vertical,
|
|
|
Horizontal
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
[SerializeField] private bool useGradient = false;
|
|
|
[SerializeField] private Color topOrLeftColor = Color.white;
|
|
|
[SerializeField] private Color bottomOrRightColor = Color.black;
|
|
|
[SerializeField] private GradientDirection direction = GradientDirection.Vertical;
|
|
|
-
|
|
|
+
|
|
|
public bool UseGradient
|
|
|
{
|
|
|
get => useGradient;
|
|
@@ -321,7 +389,7 @@ namespace UnityEngine.UI
|
|
|
SetVerticesDirty();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public Color TopOrLeftColor
|
|
|
{
|
|
|
get => topOrLeftColor;
|
|
@@ -331,7 +399,7 @@ namespace UnityEngine.UI
|
|
|
SetVerticesDirty();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public Color BottomOrRightColor
|
|
|
{
|
|
|
get => bottomOrRightColor;
|
|
@@ -341,7 +409,7 @@ namespace UnityEngine.UI
|
|
|
SetVerticesDirty();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public GradientDirection Direction
|
|
|
{
|
|
|
get => direction;
|
|
@@ -351,36 +419,36 @@ namespace UnityEngine.UI
|
|
|
SetVerticesDirty();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected override void OnPopulateMesh(VertexHelper vh)
|
|
|
{
|
|
|
base.OnPopulateMesh(vh);
|
|
|
-
|
|
|
+
|
|
|
if (!useGradient || vh.currentVertCount == 0)
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
List<UIVertex> verts = new List<UIVertex>();
|
|
|
vh.GetUIVertexStream(verts);
|
|
|
-
|
|
|
+
|
|
|
for (int i = 0; i < verts.Count; i += 6)
|
|
|
{
|
|
|
ApplyGradientToQuad(verts, i);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
vh.Clear();
|
|
|
vh.AddUIVertexTriangleStream(verts);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private void ApplyGradientToQuad(List<UIVertex> verts, int startIndex)
|
|
|
{
|
|
|
if (startIndex + 5 >= verts.Count)
|
|
|
return;
|
|
|
-
|
|
|
+
|
|
|
float top = verts[startIndex].position.y;
|
|
|
float bottom = verts[startIndex].position.y;
|
|
|
float left = verts[startIndex].position.x;
|
|
|
float right = verts[startIndex].position.x;
|
|
|
-
|
|
|
+
|
|
|
for (int i = 1; i < 6; i++)
|
|
|
{
|
|
|
var pos = verts[startIndex + i].position;
|
|
@@ -389,16 +457,16 @@ namespace UnityEngine.UI
|
|
|
left = Mathf.Min(left, pos.x);
|
|
|
right = Mathf.Max(right, pos.x);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
{
|
|
|
var vert = verts[startIndex + i];
|
|
|
var pos = vert.position;
|
|
|
-
|
|
|
+
|
|
|
float t = direction == GradientDirection.Vertical
|
|
|
? Mathf.InverseLerp(bottom, top, pos.y)
|
|
|
: Mathf.InverseLerp(left, right, pos.x);
|
|
|
-
|
|
|
+
|
|
|
Color gradientColor = Color.Lerp(bottomOrRightColor, topOrLeftColor, t);
|
|
|
gradientColor.r *= color.r;
|
|
|
gradientColor.g *= color.g;
|
|
@@ -408,9 +476,5 @@ namespace UnityEngine.UI
|
|
|
verts[startIndex + i] = vert;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|