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. 总结一下安装linux系统经验-版本选择-安装ubuntu

    linux版本选择: 初次接触,建议选 Ubuntu 或者 Fedora,这两个发行版都很容易上手,而且两者都有很强大的中文社区,遇到问题比较容易解决,而且都有国内的源,安装或者更新软件时体验相对会好 ...

  2. NSOperation GCD 对比 (附NSOperation演练)

    项目中使用NSOperation的优点是NSOperation是对线程的高度抽象,在项目中使用它,会使项目的程序结构更好子类化NSOperation的设计思路,是具有面向对象的优点(复用.封装),使得 ...

  3. gvim如何显示html属性代码提示? vim 如何显示 javascript属性及方法提示?

    gvim如何显示html属性代码 可以在vim中 显示 html, css, js等的属性/方法 提示: 一是: 在 ~/.vim/after/syntax/ 目录中 安装 css-color.vim ...

  4. Python 爬虫笔记、多线程、xml解析、基础笔记(不定时更新)

    1  Python学习网址:http://www.runoob.com/python/python-multithreading.html

  5. 2014 牡丹江区域赛 B D I

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=358 The 2014 ACM-ICPC Asia Mudanj ...

  6. mysql 调用外部程序

    一.下载 lib_mysqludf_sys: 下载地址:https://github.com/mysqludf/repositories 二.配置与使用: 1.解压之后,已经有了我们需要的 lib_m ...

  7. 包介绍 - Fluent Validation (用于验证)

    Install-Package FluentValidation 如果你使用MVC5 可以使用下面的包 Install-Package FluentValidation.MVC5 例子: public ...

  8. EF-error 0152: No Entity Framework provider found...

    突然就报这个错了... ... 哈哈··· 原来是 "EntityFramework.SqlServer.dll" 没有引用··· 添加引用就好了... ... 还好不了?那就不知 ...

  9. WP8.1下 Cortana语音命令 VCD文件 设计

    Windows Phone8.1下的Cortana,可以通过语音的方式,打开.设置应用,进行页面跳转.执行任务. 我们先要创建VCD(VoiceCommand.xml)文件 <?xml vers ...

  10. IEnumerable<> ICollection <> IList<> 区别

    IEnumerable< ICollection < IList区别 public interface IEnumerable { IEnumerator GetEnumerator(); ...