c# - Unity:从大图到地图/地形/纹理
问题描述
在 Unity 中,我想从一个大图像文件(9650 12573)生成 2D 地图。我已经有一个平铺/图像块生成器,但它生成了 1900 个图像 256 256,并且像这样手动创建地图似乎很困难(而且我有不止一个大图像要处理......)。
这些图像片段是这样排序的:
x/y.png
其中x从左到右开始,y从上到下。
正如 MelvMay在这里建议我的那样,我应该使用纹理来实现这一点,但是如何实现呢?
您对如何以编程方式实现这一目标有任何想法吗?或者可能与现有捆绑包一起使用?
非常感谢!
[编辑] 作为一种解决方法,我尝试了这个:
public class MapGenerator : MonoBehaviour {
private Renderer m_Renderer;
private Texture2D m_MainTexture;
// Use this for initialization
void Start () {
//Fetch the Renderer from the GameObject
m_Renderer = GetComponent<Renderer> ();
m_MainTexture = LoadPNG("Assets/Tiles/Ressources/Map/0/3.png");
m_Renderer.material.mainTexture = m_MainTexture;
}
private Texture2D LoadPNG(string filePath) {
Texture2D tex = null;
byte[] fileData;
if (File.Exists(filePath)) {
UnityEngine.Debug.Log(filePath);
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
}
return tex;
}
}
但即使我将它应用到一个空对象上,我也只能在检查器中看到我的动态纹理,而不是在我按下运行时的场景中......
解决方案
推荐阅读
- android - 蓝牙自动连接
- python - 为什么这两个循环返回不同的结果?
- html - 如何相对于文本定位图像?
- c# - 在整个程序中登录
- scipy - 用功率谱密度检验 Parseval 定理
- node.js - Mongoose 5.3.8 - 无法使用 MultiLineString 和 $push 提取地理键
- android - 陀螺仪传感器:- 如何在 Android 应用中实现基于运动的动作(使用 Android Studio)
- regex - Apache 位置反向代理 URL 不起作用
- python - 向下移动一行,然后重命名该列
- javascript - 将字符串匹配到组件 React