zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Unity 笔记

笔记 Unity
2023-09-27 14:25:33 时间

复数
https://zhuanlan.zhihu.com/p/87793349
四元数
https://blog.csdn.net/candycat1992/article/details/41254799
https://www.cnblogs.com/leixinyue/p/13469155.html

在Unity中程序化生成的地牢环境
https://www.gameres.com/860585.html
Bowyer-Watson算法

using System.IO;
using UnityEditor;
using UnityEngine;

public class ReplaceDDS : Editor {

    [MenuItem("Tools/Replace DDS Texture")]
    public static void ToChangeMaterialsDDS () {

        string[] paths = AssetDatabase.GetAllAssetPaths();
        for (int i = 0; i < paths.Length; i++) {
            string path = paths[i];
            if (string.IsNullOrEmpty(path)) continue;
            if (path.IndexOf("Assets/") < 0) continue;
            string extension = Path.GetExtension(path).ToLower();

            if(extension == ".png") {
               // Debug.Log(path);
            }

            if (extension == ".fbx") {
                Object[] objects = AssetDatabase.LoadAllAssetRepresentationsAtPath(paths[i]);
                for (int j = 0; j < objects.Length; j++) {
                    Object obj = objects[j];
                    if (obj && obj is Material) {
                        ReplaceMaterialDDS((Material)obj);
                    }
                }
            } else {
                Material material = AssetDatabase.LoadAssetAtPath<Material>(path);
                if (material) {
                    ReplaceMaterialDDS(material);
                }
            }
        }

        //保存并刷新资源
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        EditorUtility.DisplayDialog("Complete", "Replace DDS texture complete", "OK");
    }

    public static void ReplaceMaterialDDS (Material material) {
        string[] propertyNames = { "_MainTex", "_BumpMap" };
        for (int i = 0; i < propertyNames.Length; i++) {
            string propertyName = propertyNames[i];
            Texture texture = material.GetTexture(propertyName);
            if (texture) {
                string texturePath = AssetDatabase.GetAssetPath(texture);
                string texturePathExtension = Path.GetExtension(texturePath).ToLower();
                if (texturePathExtension == ".dds") {
                    string newTextruePath = texturePath.Substring(0, texturePath.Length - texturePathExtension.Length) + ".png";
                    Texture newTexture = AssetDatabase.LoadAssetAtPath<Texture>(newTextruePath);
                    if (newTexture) {
                        material.SetTexture(propertyName, newTexture);
                    }
                }
            }
        }
    }

}