static void UpdateData()
    {
        var GUIDs = AssetDatabase.FindAssets("t:MDL");

        foreach (var GUID in GUIDs)
        {
            var mdlPath = AssetDatabase.GUIDToAssetPath(GUID);

            var name     = Path.GetFileNameWithoutExtension(mdlPath);
            var parent   = mdlPath.Substring(0, mdlPath.LastIndexOf('/'));
            var dataPath = parent + "/" + name + "_data.asset";

            if (AssetUtils.AssetPathExists(dataPath))
            {
                var mdl  = AssetDatabase.LoadAssetAtPath <MDL>(mdlPath);
                var data = AssetDatabase.LoadAssetAtPath <MonsterData>(dataPath);


                AssetDatabase.SaveAssets();
            }
        }
    }
Beispiel #2
0
    private static Material[] GenerateSkins(BSPFile bsp, string name, string destPath, TextureAtlas atlas)
    {
        var skinsPath = destPath + "/skins";

        AssetUtils.CreateFolder(skinsPath);

        string textureName = FileUtilEx.FixFilename(name);
        var    texturePath = skinsPath + "/" + textureName + ".png";

        if (!AssetUtils.AssetPathExists(texturePath))
        {
            atlas.WriteTexture(texturePath);
            AssetDatabase.Refresh();
        }

        int    index        = texturePath.LastIndexOf('.');
        string materialPath = texturePath.Substring(0, index) + ".mat";

        if (!AssetUtils.AssetPathExists(materialPath))
        {
            TextureImporter importer = TextureImporter.GetAtPath(texturePath) as TextureImporter;
            importer.textureType    = TextureImporterType.Default;
            importer.wrapMode       = TextureWrapMode.Repeat;
            importer.filterMode     = FilterMode.Point;
            importer.maxTextureSize = 2048;
            importer.textureFormat  = TextureImporterFormat.DXT1;
            importer.SaveAndReimport();

            var material = new Material(Shader.Find("Standard"));
            material.mainTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath);
            material.SetFloat("_Glossiness", 0.0f);

            AssetDatabase.CreateAsset(material, materialPath);
        }

        return(new Material[] { AssetDatabase.LoadAssetAtPath <Material>(materialPath) });
    }
Beispiel #3
0
    static Material[] GenerateSkins(MDLFile mdl, string destPath)
    {
        List <string>   textures  = new List <string>();
        List <Material> materials = new List <Material>();

        var skinsPath = destPath + "/skins";

        AssetUtils.CreateFolder(skinsPath);

        int skinId = 0;

        foreach (var skin in mdl.skins)
        {
            var textureName = mdl.skins.Length > 1 ?
                              string.Format("{0}_skin_{1}.png", mdl.name, skinId++) :
                              string.Format("{0}_skin.png", mdl.name);
            var texturePath = skinsPath + "/" + textureName;
            if (!AssetUtils.AssetPathExists(texturePath))
            {
                Texture2D tex    = new Texture2D(skin.width, skin.height);
                Color32[] pixels = new Color32[skin.width * skin.height];
                for (int i = 0, j = 0; i < pixels.Length; ++i)
                {
                    pixels[i] = new Color32(skin.data[j++], skin.data[j++], skin.data[j++], skin.data[j++]);
                }

                for (int x = 0; x < skin.width; ++x)
                {
                    for (int y = 0; y < skin.height / 2; ++y)
                    {
                        int from = y * skin.width + x;
                        int to   = (skin.height - y - 1) * skin.width + x;
                        var temp = pixels[to];
                        pixels[to]   = pixels[from];
                        pixels[from] = temp;
                    }
                }

                tex.SetPixels32(pixels);
                File.WriteAllBytes(AssetUtils.GetAbsoluteAssetPath(texturePath), tex.EncodeToPNG());
            }

            textures.Add(texturePath);
        }
        AssetDatabase.Refresh();

        foreach (var texture in textures)
        {
            int    index        = texture.LastIndexOf('.');
            string materialPath = texture.Substring(0, index) + ".mat";
            if (!AssetUtils.AssetPathExists(materialPath))
            {
                TextureImporter importer = TextureImporter.GetAtPath(texture) as TextureImporter;
                importer.textureType    = TextureImporterType.Default;
                importer.wrapMode       = TextureWrapMode.Repeat;
                importer.filterMode     = FilterMode.Point;
                importer.maxTextureSize = 2048;
                importer.textureFormat  = TextureImporterFormat.DXT1;
                importer.SaveAndReimport();

                var material = new Material(Shader.Find("Standard"));
                material.mainTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texture);
                material.SetFloat("_Glossiness", 0.0f);

                AssetDatabase.CreateAsset(material, materialPath);
            }

            materials.Add(AssetDatabase.LoadAssetAtPath <Material>(materialPath));
        }

        AssetDatabase.SaveAssets();

        return(materials.ToArray());
    }
Beispiel #4
0
    static IList <Material> GenerateMaterials(BSPFile bsp, string destPath)
    {
        List <string>   textures  = new List <string>();
        List <Material> materials = new List <Material>();

        string materialsPath = destPath + "/materials";

        AssetUtils.CreateFolder(materialsPath);

        int tex_id = 0;

        foreach (var t in bsp.textures)
        {
            string textureName = string.Format("{0}.png", FileUtilEx.FixFilename(t.name));
            string texturePath = materialsPath + "/" + textureName;

            float progress = ((float)++tex_id) / bsp.textures.Length;
            if (EditorUtility.DisplayCancelableProgressBar("Level", "Reading texture: " + texturePath, progress))
            {
                return(null);
            }

            if (!AssetUtils.AssetPathExists(texturePath))
            {
                Texture2D tex    = new Texture2D(t.width, t.height);
                Color32[] pixels = new Color32[t.width * t.height];
                for (int i = 0, j = 0; i < pixels.Length; ++i)
                {
                    pixels[i] = new Color32(t.data[j++], t.data[j++], t.data[j++], t.data[j++]);
                }

                for (int x = 0; x < t.width; ++x)
                {
                    for (int y = 0; y < t.height / 2; ++y)
                    {
                        int from = y * t.width + x;
                        int to   = (t.height - y - 1) * t.width + x;
                        var temp = pixels[to];
                        pixels[to]   = pixels[from];
                        pixels[from] = temp;
                    }
                }

                tex.SetPixels32(pixels);
                File.WriteAllBytes(AssetUtils.GetAbsoluteAssetPath(texturePath), tex.EncodeToPNG());
            }

            textures.Add(texturePath);
        }
        AssetDatabase.Refresh();

        int materialNum = 0;

        foreach (var texture in textures)
        {
            int    index        = texture.LastIndexOf('.');
            string materialPath = texture.Substring(0, index) + ".mat";

            float progress = ((float)++materialNum) / bsp.textures.Length;
            if (EditorUtility.DisplayCancelableProgressBar("Level", "Generating material: " + materialPath, progress))
            {
                return(null);
            }

            if (!AssetUtils.AssetPathExists(materialPath))
            {
                TextureImporter importer = TextureImporter.GetAtPath(texture) as TextureImporter;
                importer.textureType    = TextureImporterType.Default;
                importer.wrapMode       = TextureWrapMode.Repeat;
                importer.filterMode     = FilterMode.Point;
                importer.maxTextureSize = 2048;
                importer.textureFormat  = TextureImporterFormat.DXT1;
                importer.SaveAndReimport();

                var material = new Material(Shader.Find("Standard"));
                material.mainTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texture);
                material.SetFloat("_Glossiness", 0.0f);

                AssetDatabase.CreateAsset(material, materialPath);
            }

            materials.Add(AssetDatabase.LoadAssetAtPath <Material>(materialPath));
        }

        return(materials);
    }