资源简介
该资源,是Unity 3D路径跟随,可以选择闭合曲线和非闭合曲线,目标跟随时可以选择旋转跟随和非旋转跟随,曲线的绘制采用Hermite曲线。
代码片段和文件信息
using UnityEngine;
using System.Collections;
public class Curve : MonoBehaviour {
public Gameobject[] vertexs;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Debug.DrawLine(new Vector3(0 0 0) new Vector3(10 10 10) Color.blue);
}
void OnGUI()
{
}
void OnPostRender()
{
}
//绘制小物件:如果你想绘制可被点选的gizmos,执行这个函数。
void OnDrawGizmos()
{
//Gizmos.Color = Gizmos.color.white;
for (int i = 0; i < 6; i++)
{
Vector3 start = getver4(vertexs[0].transform.position vertexs[1].transform.position vertexs[2].transform.position vertexs[3].transform.position (i) / 6f);
Vector3 end = getver4(vertexs[0].transform.position vertexs[1].transform.position vertexs[2].transform.position vertexs[3].transform.position (i+1) / 6f);
Gizmos.DrawLine(startend);
start = getver5(vertexs[0].transform.position vertexs[1].transform.position vertexs[2].transform.position vertexs[3].transform.position (i) / 6f);
end = getver5(vertexs[0].transform.position vertexs[1].transform.position vertexs[2].transform.position vertexs[3].transform.position (i + 1) / 6f);
Gizmos.DrawLine(start end);
}
}
//绘制小物件:选中状态
void OnDrawGizmosSelected()
{
Gizmos.DrawWireCube(new Vector3(0 0 0) new Vector3(1 1 1));
}
//贝塞尔 3次方程
Vector3 getver(Vector3 v0 Vector3 v1 Vector3 v2 Vector3 v3float t)
{
Vector3 v;
v = (1 - t) * (1 - t) * (1 - t) * v0 + (1 - t) * (1 - t) * t * v1 + (1 - t) * t * t * v2 + t * t * t * v3;
return v;
}
//贝塞尔 2次方程
Vector3 getver2(Vector3 v0 Vector3 v1 Vector3 v2 Vector3 v3 float t)
{
Vector3 v;
v = (1 - t) * (1 - t) * v0 + (1 - t) * t * v1 + t * t * v2;
return v;
}
Vector3 getver3(Vector3 v0 Vector3 v1 Vector3 v2 Vector3 v3 float t)
{
Vector3 v;
//v = (1 - t) * (1 - t) * v0 + (1 - t) * t * v1 + t * t * v2;
v = v0 + t*(v1-v0) + t*t*(v2-v1) + t*t*t*(v3-v2);
return v;
}
//hermite 曲线
Vector3 getver4(Vector3 v0 Vector3 v1 Vector3 v2 Vector3 v3 float t)
{
Vector3 v;
float h1 = 2 * t * t * t - 3 * t * t + 1;
float h2 = -2 * t * t * t + 3 * t * t;
float h3 = t * t * t - 2 * t * t + t;
float h4 = t * t * t - t * t;
v = h1 * v0 + h2 * v1 + h3 * (v0 - v0)/2.0f + h4 * (v3 - v1)/2.0f;
return v;
}
//hermite 曲线
Vector3 getver5(Vector3 v0 Vector3 v1 Vector3 v2 Vector3 v3 float t)
{
Vector3 v;
float h1 = 2 * t * t * t - 3 * t * t + 1;
float h2 = -2 * t * t * t + 3 * t * t;
float h3 = t * t * t - 2 * t * t + t;
float h4 = t * t * t - t * t;
v = h1 * v1 + h2 * v2 + h3 * (v3 - v1) + h4 * (v2 - v2);
return v;
}
void OnSceneGUI()
{
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.....H. 8198 2015-12-17 12:57 HermiteCurve\.docstates.suo
文件 7095 2015-12-17 11:30 HermiteCurve\Assembly-CSharp-Editor.csproj
文件 4422 2015-12-17 20:59 HermiteCurve\Assembly-CSharp.csproj
文件 2869 2015-12-16 14:40 HermiteCurve\Assets\Curve\Curve.cs
..A..H. 262 2015-12-07 09:59 HermiteCurve\Assets\Curve\Curve.cs.me
文件 361 2015-12-17 13:50 HermiteCurve\Assets\Curve\Curve_Root.cs
..A..H. 262 2015-12-09 11:26 HermiteCurve\Assets\Curve\Curve_Root.cs.me
文件 9036 2015-12-17 17:46 HermiteCurve\Assets\Curve\HermitCurve.cs
..A..H. 262 2015-12-09 11:26 HermiteCurve\Assets\Curve\HermitCurve.cs.me
..A..H. 191 2015-12-09 11:25 HermiteCurve\Assets\Curve.me
I.A.... 14924 2015-12-17 21:06 HermiteCurve\Assets\test.unity
..A..H. 174 2015-12-09 09:44 HermiteCurve\Assets\test.unity.me
文件 1547 2015-12-17 20:59 HermiteCurve\curveTest.sln
.....H. 16390 2015-12-17 17:17 HermiteCurve\curveTest.sln.docstates.suo
..A..H. 48128 2015-12-17 17:17 HermiteCurve\curveTest.suo
I.A.... 4120 2015-12-07 09:54 HermiteCurve\Library\AnnotationManager
I.A.... 1446492 2015-12-17 21:06 HermiteCurve\Library\assetDataba
I.A.... 6 2015-12-07 09:54 HermiteCurve\Library\AssetImportState
I.A.... 4756 2015-12-17 21:06 HermiteCurve\Library\AssetServerCacheV3
I.A.... 14336 2015-12-17 20:59 HermiteCurve\Library\AssetVersioning.db
I.A.... 0 2015-12-07 09:54 HermiteCurve\Library\BuildPla
I.A.... 4128 2015-12-07 09:54 HermiteCurve\Library\BuildSettings.asset
I.A.... 39612 2015-12-17 21:06 HermiteCurve\Library\CurrentLayout.dwlt
I.A.... 34180 2015-12-10 10:27 HermiteCurve\Library\CurrentMaximizeLayout.dwlt
I.A.... 4220 2015-12-07 09:54 HermiteCurve\Library\EditorUserBuildSettings.asset
I.A.... 4148 2015-12-07 09:54 HermiteCurve\Library\EditorUserSettings.asset
I.A.... 6516 2015-12-17 21:06 HermiteCurve\Library\expandedItems
I.A.... 4172 2015-12-15 11:36 HermiteCurve\Library\InspectorExpandedItems.asset
文件 65 2015-12-07 09:54 HermiteCurve\Library\LibraryFormatVersion.txt
I.A.... 4285 2015-12-07 09:54 HermiteCurve\Library\me
............此处省略409个文件信息
- 上一篇:jackson电动力学答案
- 下一篇:ieee830-1998.pdf
相关资源
- Unity3d动态创建excel并写入数据
- mipai.unitypackage
- Unity3D模型-喷火龙
- MineSweeper
- 延迟消息机
- Unity3D.4.0.0简体中文汉化补丁
- unity2018版汉化包
- KinectWrapperPackage for KinectSDK1.6
- Unity 3D虚拟现实场景作品
- unity3d光影插件
- Unity3D内置Shader源码与详解解释文档
- networkViewDEMO.unitypackage
- Unity Unity SnowPackage下雪效果插件
- unity开发基础教程,全面
- unity模拟流动的水的液体物理效果
- Unity开发的斗地主,自带AI,直接编译
- Unity4.3Sourcecode
- unity喷泉效果
- LED 字体 unity可用
- Unity3D《最后一战》全套完整源代码
- 基于Shader开发的Unity碎屏特效
- unity iTweenPath 动画插件
-
unity3d读取xm
l插件Mono.xm l - Unity3d背包物品拖拽
- 无限滚动TableView
- Unity中使用语音识别
- Unity3D使用socket通讯源码
- 塔防游戏源码
- Unity合并网格Demo
- zxing.unity.dll
评论
共有 条评论