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 ...
随机推荐
- ctrl+c,ctrl+d,ctrl+z在linux中意义
ctrl+c,ctrl+d,ctrl+z在linux中意义 ctrl+c和ctrl+z都是中断命令,但是他们的作用却不一样. ctrl+c是强制中断程序的执行. ctrl+z的是将任务中断 ...
- Python 爬虫笔记、多线程、xml解析、基础笔记(不定时更新)
1 Python学习网址:http://www.runoob.com/python/python-multithreading.html
- CF459E Pashmak and Graph (DP?
Codeforces Round #261 (Div. 2) E - Pashmak and Graph E. Pashmak and Graph time limit per test 1 seco ...
- [设计模式] javascript 之 组合模式
组合模式说明 组合模式用于简单化,一致化对单组件和复合组件的使用:其实它就是一棵树: 这棵树有且只有一个根,访问入口,如果它不是一棵空树,那么由一个或几个树枝节点以及子叶节点组成,每个树枝节点还包含自 ...
- ionic导航之后返回功能的说明
当我导航view之后,再使用$location.path("/path/origin")方法重新定位到初始页面,在深入进入其他的view之后使用这个方法就遇到了问题. 假设这个设置 ...
- firstchild.data与childNodes[0].nodeValue意思(转)
x.firstchild.data:获取元素第一个子节点的数据: x.childNodes[0]::获取元素第一个子节点; x.childNodes[0].nodeValue.:也是获取元素第一个子节 ...
- POJ 1061 青蛙的约会
青蛙的约会 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 82859 A ...
- 转载自安卓巴士 【收藏】2015必须推荐的Android框架,猿必读系列!
一.Guava Google的基于java1.6的类库集合的扩展项目,包括collections, caching, primitives support, concurrency libraries ...
- MongoDB的安全(五)
MongoDB用户管理操作: MongoDB开启权限认证的方式有两种一种是auth形式,一种是keyfile形式 MongoDB创建用户: 1. 创建用户语法:在MongoDB2.6版本之后使用cre ...
- Longest Common Substring
Given two strings, find the longest common substring. Return the length of it. Example Given A = &qu ...