59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public static class Tool
|
|
{
|
|
[MenuItem("KopTools/MakeTexture")]
|
|
public static void MakeTextureArray()
|
|
{
|
|
MakeTexture();
|
|
}
|
|
|
|
private static void MakeTexture()
|
|
{
|
|
TextAsset textAsset = Resources.Load<TextAsset>("TerrainInfo");
|
|
string[] terrainInfos = textAsset.text.Split("\n");
|
|
|
|
Texture2D texture2D = new Texture2D(2048, 2048);
|
|
for (int i = 0; i < 2048; i++)
|
|
{
|
|
for (int j = 0; j < 2048; j++)
|
|
{
|
|
texture2D.SetPixel(i, j, Color.black);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < terrainInfos.Length; i++)
|
|
{
|
|
string infoItem = terrainInfos[i];
|
|
if (string.IsNullOrEmpty(infoItem))
|
|
continue;
|
|
|
|
string[] infos = infoItem.Split("\t", StringSplitOptions.RemoveEmptyEntries);
|
|
if (infos is { Length: < 2 })
|
|
continue;
|
|
|
|
string texName = Path.GetFileNameWithoutExtension(infos[1]);
|
|
string texFilePath = $"Textures/{texName}";
|
|
|
|
int startX = i * 256 % 2048;
|
|
int startY = (63 - i) / 8 * 256;
|
|
|
|
Texture2D texture = Resources.Load<Texture2D>(texFilePath);
|
|
if (texture)
|
|
{
|
|
var pixels = texture.GetPixels();
|
|
texture2D.SetPixels(startX, startY, texture.width, texture.height, pixels);
|
|
}
|
|
|
|
Debug.Log($"i:{i} | startX:{startX} | startY:{startY} | {texFilePath}");
|
|
}
|
|
|
|
// save
|
|
File.WriteAllBytes($"Assets/TerrainTex.png", texture2D.EncodeToPNG());
|
|
}
|
|
} |