Unity3d 保存和使用地形高度
TerrainHeightProcesser 地形高度存储工具
TerrainHeightData 地形高度数据
// class TerrainHeightProcesser
using UnityEngine;
using System.Collections;
using System.IO;
using UnityEditor;
using System.Collections.Generic; /*
* 地形高度处理器
*/
public class TerrainHeightProcesser : ScriptableWizard
{ public int mapWdith;
public int mapHeight; [MenuItem("Tools/Save Terrain Height File")]
public static void OpenDialog()
{
DisplayWizard<TerrainHeightProcesser>("Save Terrain Height", "Save", "Cancel");
} public void SaveTerrainHeightFile()
{ //以每米为间隔从高空向下发射射线
Vector3 pos = Vector3.zero;
pos.y = 100;
Ray ray = new Ray(pos, -Vector3.up);
Vector3 targetPos = Vector3.zero; //创建一个对象
TerrainHeightData th = ScriptableObject.CreateInstance<TerrainHeightData>();
th.MapWidth = mapWdith;
th.MapHeight = mapHeight;
th.List = new List<float>(); //纵向
for (short i = 0; i < mapHeight; i++)
{
pos.z = i;
//横向
for (short j = 0; j < mapWdith; j++)
{
targetPos = Vector3.zero;//默认zero pos.x = j;
ray.origin = pos;
RaycastHit result;
if (Physics.Raycast(ray, out result))
{
targetPos = result.point;
}
th.List.Add(targetPos.y);
}
} //计算file name
string sceneName = UnityEditor.EditorApplication.currentScene;
int start = sceneName.LastIndexOf('/') + 1;
int count = sceneName.LastIndexOf('.')-start;
sceneName = sceneName.Substring(start, count);
string path = "Assets/ArtAsset/TerrainHeightData/" + sceneName + ".asset"; //保存
AssetDatabase.CreateAsset(th, path);
AssetDatabase.Refresh(); string str = string.Empty;
str += "mapHeight=" + mapHeight.ToString() + " ";
str += "mapWdith=" + mapWdith.ToString();
EditorUtility.DisplayDialog("SUCCESS", "file:" + path + "\n" + str, "OK");
} void OnWizardCreate()
{
SaveTerrainHeightFile();
} void OnWizardOtherButton()
{
Close();
} }
//TerrainHeightData
using UnityEngine;
using System.Collections;
using System.IO;
using System.Collections.Generic; public class TerrainHeightData : ScriptableObject
{
[SerializeField]
public int MapWidth = 0; [SerializeField]
public int MapHeight = 0; [SerializeField]
public List<float> List; public float GetTerrainHeight(float x,float z)
{
int w = (int)Mathf.Floor(x);
int h = (int)Mathf.Floor(z);
if (w < 0 || w >= MapWidth || h < 0 || h >= MapHeight)
return 0.0f; int idx = h*MapWidth+w;
if (idx < 0 || idx >= MapWidth * MapHeight || idx >= List.Count)
return 0.0f; return List[idx];
} }
Unity3d 保存和使用地形高度的更多相关文章
- Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本]
Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本] 2013-02-19 15:29:33 我来说两句 作者:nnsword 收藏 我要投稿 其中涉及,移动速度, ...
- Unity3D教程:无缝地形场景切换的解决方法
http://www.unitymanual.com/6718.html 当我们开发一个大型项目的时候-会遇到这样的问题(地形场景的切换)这个只是字面意思-并不是重场景1的100 100 100坐标 ...
- Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);var ray,posit ...
- unity3d WorldComposer1 卫星地图生成地形
http://blog.csdn.net/myarrow/article/details/42709113 1. 简介 1.1 TerrainComposer(TC) 一个Unity扩展工具,可用于创 ...
- Unity3D游戏开发从零单排(三) - 极速创建狂拽酷炫的游戏地形
提要 在Unity工作流程内,地形是一个必不可少的重要元素.不论是游戏或虚拟现实都会使用到各种类型的地形效果,在这个教学中我们须要了解到地形的制作基本概念与,当中对于Unity的地形操作部分须要大量的 ...
- unity3D绘画手册-----地形及术语解释
Unity3D教程:设置地形(Terrain) Posted on 2013年04月18日 by U3d / Unity3D 基础教程 /被围观 1,901 次 新建地形: 在菜单中新建一个地形. U ...
- Cesium原理篇:3最长的一帧之地形(2:高度图)
这一篇,接着上一篇,内容集中在高度图方式构建地球网格的细节方面. 此时,Globe对每一个切片(GlobeSurfaceTile)创建对应的TileTerrain类,用来维 ...
- Unity3d NavMesh获得地面高度
UnityPro内置的NavMesh有几个API很有用 NavMesh.SamplePosition 根据给的点进行采样,可传入最大距离,返回true说明采样到了点,否则采样失败(可以用来获得地形高度 ...
- Directx11学习笔记【二十二】 用高度图实现地形
本文由zhangbaochong原创,转载请注明出处http://www.cnblogs.com/zhangbaochong/p/5827714.html 在前面我们曾经实现过简单的地形(Direct ...
随机推荐
- Mongodb 资源
一.资源 1.C# 驱动下载地址 https://github.com/mongodb/mongo-csharp-driver/releases 2. Mongodb 管理工具 mongochef 下 ...
- yaf自动加载文件
models下面的文件 例如:Article.php 类名必须是:ArticleModel 调用时:$article_models = new ArticleModel(); library下面的文件 ...
- vim如何在多个文件中切换
如果我们一次打开多个文件 看一下当前目录里面的文件: wangkongming@Vostro /data/webroot/testRoot/application/modules/Admin/view ...
- vim基础命令
2015-06-04 by komilevim基础命令 打开一个文件 vim index.php 几种模式说明Normal Mode也就是最一般的普通模式,默认进入vim之后,处于这种模式.Inser ...
- 我的linux桌面
经过几次尝试安装linux系统之后,终于把自己的系统安装成了linux系统. wangkongming@ThinkPad-T410 ~ $ lsb_release -a No LSB modules ...
- jquery eval解析JSON中的注意点介绍
在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式:使用eval()函数.使用Function对象来进行返回解析,下面有个示例,感兴趣的朋友可以参考下 在JS中将JSON的字符串解析 ...
- [译]Mongoose指南 - Connection
使用mongoose.connect()方法创建连接 mongoose.conect('mongodb://localhost/myapp'); 上面的代码是通过默认端口27017链接到mongodb ...
- 关于Html编码问题,例如字符:·
我写的WCF服务突然报错了... 然后我发现传过来的字符不完整 {"完整":"尼古拉·奥斯特洛夫斯基的信息"} 然后传过来的是:{"完整": ...
- nyoj 10 skiing 搜索+动归
整整两天了,都打不开网页,是不是我提交的次数太多了? nyoj 10: #include<stdio.h> #include<string.h> ][],b[][]; int ...
- 【学习】一本案例驱动的jQuery Mobile入门书
清华大学出版社推出的<构建跨平台APP:jQuery Mobile移动应用实战> 提供的全是jQuery Mobile的案例: 手机入侵 题库应用 音乐专辑 通讯录 新闻列表 销售排名 九 ...