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 保存和使用地形高度的更多相关文章

  1. Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本]

    Unity3d 实现鼠标左键点击地形使角色移动到指定地点[脚本] 2013-02-19 15:29:33     我来说两句      作者:nnsword 收藏    我要投稿 其中涉及,移动速度, ...

  2. Unity3D教程:无缝地形场景切换的解决方法

    http://www.unitymanual.com/6718.html 当我们开发一个大型项目的时候-会遇到这样的问题(地形场景的切换)这个只是字面意思-并不是重场景1的100  100 100坐标 ...

  3. Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。

    var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);var ray,posit ...

  4. unity3d WorldComposer1 卫星地图生成地形

    http://blog.csdn.net/myarrow/article/details/42709113 1. 简介 1.1 TerrainComposer(TC) 一个Unity扩展工具,可用于创 ...

  5. Unity3D游戏开发从零单排(三) - 极速创建狂拽酷炫的游戏地形

    提要 在Unity工作流程内,地形是一个必不可少的重要元素.不论是游戏或虚拟现实都会使用到各种类型的地形效果,在这个教学中我们须要了解到地形的制作基本概念与,当中对于Unity的地形操作部分须要大量的 ...

  6. unity3D绘画手册-----地形及术语解释

    Unity3D教程:设置地形(Terrain) Posted on 2013年04月18日 by U3d / Unity3D 基础教程 /被围观 1,901 次 新建地形: 在菜单中新建一个地形. U ...

  7. Cesium原理篇:3最长的一帧之地形(2:高度图)

           这一篇,接着上一篇,内容集中在高度图方式构建地球网格的细节方面.        此时,Globe对每一个切片(GlobeSurfaceTile)创建对应的TileTerrain类,用来维 ...

  8. Unity3d NavMesh获得地面高度

    UnityPro内置的NavMesh有几个API很有用 NavMesh.SamplePosition 根据给的点进行采样,可传入最大距离,返回true说明采样到了点,否则采样失败(可以用来获得地形高度 ...

  9. Directx11学习笔记【二十二】 用高度图实现地形

    本文由zhangbaochong原创,转载请注明出处http://www.cnblogs.com/zhangbaochong/p/5827714.html 在前面我们曾经实现过简单的地形(Direct ...

随机推荐

  1. abrtd是什么进程

    abrtd 是一个守护进程监控的应用程序崩溃.当发生崩溃时,它将收集的崩溃(核心文件的命令行, etc .)application ,并采取措施根据类型崩溃并根据 abrt.conf config 文 ...

  2. Java学习笔记(二)不定时更新

    Java语言画图 package cn.witksy.dev; import javax.imageio.ImageIO; import java.awt.*; import java.awt.ima ...

  3. mongodb在WEB开发中的应用与实践

    一.mongodb是什么? 一套高性能.易开发的文档型数据库.他使用键值对形式存放数据,能够存放包括字符串.数组.数据序列.图片.视频等在内的大多数数据文档.MongoDB完善的设计,搞笑的可编程性使 ...

  4. poj2391 Ombrophobic Bovines 题解

    http://poj.org/problem?id=2391 floyd+网络流+二分 题意:有一个有向图,里面每个点有ai头牛,快下雨了牛要躲进雨棚里,每个点有bi个雨棚,每个雨棚只能躲1头牛.牛可 ...

  5. jQuery 学习之路(1):引子

    一.主流 javascript 库 除 jQuery 外,还有 Prototype.Dojo.YUI.ExtJS.MooTools ,其中 Prototype 较老,结构设计较为松散,ExtJS 界面 ...

  6. [译]在Mac上运行ASP.NET 5

    原文:http://stephenwalther.com/archive/2015/02/03/asp-net-5-and-angularjs-part-7-running-on-a-mac 这篇文章 ...

  7. jquery获取datagrid多选值

    var checkedItems = $('#dg').datagrid('getChecked'); $.each(checkedItems, function (index, item) { al ...

  8. ThinkPHP报错处理

    1,当运行结果提示:找不到该页面(控制器),怎么办? 建造一个空页面:EmptyController <?php namespace Home\Controller; use Think\Con ...

  9. JAVA-Excel文件操作

    使用环境:JAVA 1.8 一.安装 1.下载Poi包 Apache POI 当前最新稳定版本为3.14.下载poi-bin-3.14.zip即可. 2.将下载下来的压缩包解压,将其中的所有jar文件 ...

  10. CSS技巧-rgba函数的妙用

    先简单介绍一下: rgba()函数是平时开发中经常遇到的,这篇文章也做了一个比较详细的解读以及一系列的应用. 对它的工作原理做一番分析:就是具有一定透明度的盒子: 还比较了rgba()函数和不透明度属 ...