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 ...
随机推荐
- CSS学习点滴
1.CSS :link 选择器 a:link { background-color:yellow;text-decoration:none } 参考:http://www.w3school.com.c ...
- 浅谈JavaScript中的事件
引言 Html页面与JavaScript之间的交互是通过事件来完成的.事件,就是文档或者浏览器窗口中发生的一些特定的交互瞬间.可以使用侦听器(处理程序)来预订事件,以便事件发生时执行相应的代码.这在传 ...
- CSS3导航效果
来自codepen http://codepen.io/mouradhamoud/pen/RRvVZp <!DOCTYPE html> <html> <head> ...
- 安装windows后重新修复grub2的引导
前段时间,我的用的双系统windows8.1 + fedora 21 workstation,使用grub2引导fedora和windows8.1的启动.由于一些原因,导致我的windows8.1无法 ...
- [译]Node.js : Building RESTful APIs using Loopback and MySQL
国庆后可能就要使用StrongLoop那套东西来做项目了 原文:http://www.javabeat.net/loopback-mysql/ Loopback是什么? Loopback是一个开源的N ...
- hdu4751 Divide Groups
This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is goi ...
- JSON/XML序列化与反序列化(非构造自定义类)
隔了很长时间再重看自己的代码,觉得好陌生..以后要养成多注释的好习惯..直接贴代码..对不起( ▼-▼ ) 保存保存:进行序列化后存入应用设置里 ApplicationDataContainer _a ...
- mysql explain用法和结果的含义
重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...
- Jquery中的事件和动画
在学习Jquery中的过程中我们绝大部分都用到了事件的操作,也可以说事件是Jquery中必不可少的一部分,我们常见的一些事件有单击事件,鼠标事件,键盘事件等等.在Jquery中的学习中为了能使让页面以 ...
- ReactiveCocoa源码拆分解析(一)
(整个关于ReactiveCocoa的工程可以在https://github.com/qianhongqiang/QHQReactive下载) ReactiveCocoa的介绍我就不说了,可以自行百度 ...