三国卡牌客户端基础资源仓库
ca289dee2ba0c9a59cfebf6fed963a2c458670dd..d43529e2d01bc7b153501ff5c15e00629a5dfb63
2025-06-19 hch
0312 图集
d43529 对比 | 目录
2025-06-19 hch
0312 psd导入拼图后文本和图片的处理
6fe592 对比 | 目录
1个文件已修改
2个文件已添加
169 ■■■■■ 已修改文件
Assets/Editor/SpritePacking/SpriteSettings.asset 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ChangeTextAndImage.cs 136 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/Tool/ChangeTextAndImage.cs.meta 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Assets/Editor/SpritePacking/SpriteSettings.asset
@@ -849,3 +849,25 @@
      maxTextureSize: 2048
      textureCompression: 1
      textureFormat: 50
  - folderName: MainUI
    blockOffset: 1
    enableRotation: 0
    enableTightPacking: 0
    padding: 4
    readable: 0
    generateMipMaps: 0
    sRGB: 1
    filterMode: 1
    platformSettings:
    - name: Standalone
      maxTextureSize: 2048
      textureCompression: 1
      textureFormat: 4
    - name: Android
      maxTextureSize: 2048
      textureCompression: 1
      textureFormat: 50
    - name: iPhone
      maxTextureSize: 2048
      textureCompression: 1
      textureFormat: 50
Assets/Editor/Tool/ChangeTextAndImage.cs
New file
@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public class ChangeTextAndImage : EditorWindow {
    [MenuItem("程序/替换层次视图中预制体的文本或图片")]
    public static void Open()
    {
        EditorWindow.GetWindow(typeof(ChangeTextAndImage));
    }
    static GameObject tagetObj;
    void OnGUI()
    {
        GUILayout.Label("Hierarchy 层次视图中的预制体");
        if (GUILayout.Button("将Text更换为TextEx"))
        {
            ChangeText();
            Debug.LogError("文字替换成功, 后续制作量不用bestfit的情况下 让字体显示范围最大化兼容海外版本的文字");
        }
        if (GUILayout.Button("将Image更换为ImageEx"))
        {
            ChangeImage();
        }
    }
    void ChangeText()
    {
        //将指定的tagetObj预制体中的所有Text更换为TextEx
        //Selection.activeObject;
        tagetObj = Selection.activeObject as GameObject;
        if (tagetObj == null)
        {
            Debug.LogError("请将预制体拖到Hierarchy 层次视图 并选中");
            return;
        }
        Text[] texts = tagetObj.GetComponentsInChildren<Text>(true);
        //将Text[]转成 List<GameObject>
        List<GameObject> golist = new List<GameObject>();
        foreach (var item in texts)
        {
            golist.Add(item.gameObject);
        }
        for (int i = 0; i < golist.Count; i++)
        {
            var go = golist[i];
            Text text = go.GetComponent<Text>();
            if (text as TextEx != null)
            {
                continue;
            }
            var textContent = text.text;
            var textFontSize = text.fontSize;
            var textColor = text.color;
            //删除Text
            DestroyImmediate(text);
            // 替换之后文字可能不可见,需手动调整各个组件的宽高
            // 尽量不用bestfit的情况下 让字体显示范围最大化兼容海外版本的文字
            TextEx textEx = go.AddMissingComponent<TextEx>();
            textEx.text = textContent;
            textEx.font = FontUtility.preferred;
            textEx.fontSize = textFontSize;
            textEx.raycastTarget = false;
            textEx.alignment = TextAnchor.MiddleCenter;
            textEx.horizontalOverflow = HorizontalWrapMode.Wrap;
            textEx.verticalOverflow = VerticalWrapMode.Truncate;
            textEx.resizeTextForBestFit = false;
            textEx.color = textColor;
        }
    }
    void ChangeImage()
    {
        //将指定的tagetObj预制体中的所有Image更换为ImageEx
        //Selection.activeObject;
        tagetObj = Selection.activeObject as GameObject;
        if (tagetObj == null)
        {
            Debug.LogError("请将预制体拖到Hierarchy 层次视图 并选中");
            return;
        }
        Image[] images = tagetObj.GetComponentsInChildren<Image>(true);
        //将Image[]转成 List<GameObject>
        List<GameObject> golist = new List<GameObject>();
        foreach (var item in images)
        {
            golist.Add(item.gameObject);
        }
        for (int i = 0; i < golist.Count; i++)
        {
            var go = golist[i];
            Image image = go.GetComponent<Image>();
            if (image as ImageEx != null)
            {
                continue;
            }
            var imageSprite = image.sprite;
            var imageColor = image.color;
            //删除Image
            DestroyImmediate(image);
            ImageEx imageEx = go.AddMissingComponent<ImageEx>();
            imageEx.sprite = imageSprite;
            imageEx.raycastTarget = false;
        }
    }
}
Assets/Editor/Tool/ChangeTextAndImage.cs.meta
New file
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: edda728257d3f8d4e9ab068c742ccb07
MonoImporter:
  externalObjects: {}
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant: