资源简介
基于rvo2的rvo模块,替换了原本的float类型,全部采用封装类的定点数,并使用kframework,比如command达到友元函数的效果,属性注册
代码片段和文件信息
using System;
using System.Collections;
using System.Collections.Generic;
using RVO;
using UnityEngine;
using Random = System.Random;
using KframeWork;
//using Vector2 = RVO.Vector2;
public class GameAgent : MonoBehaviour
{
[HideInInspector] public int sid = -1;
/** Random number generator. */
private Random m_random = new Random();
private Vector3 targetpos;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (sid >= 0)
{
Vector2 pos = Simulator.Instance.getAgentPosition(sid);
Vector2 vel = Simulator.Instance.getAgentPrefVelocity(sid);
transform.position = new Vector3(pos.x transform.position.y pos.y);
if (Math.Abs(vel.x) > 0.01f && Math.Abs(vel.y) > 0.01f)
transform.forward = new Vector3(vel.x 0 vel.y).normalized;
}
if (!Input.GetMouseButton(1))
{
Simulator.Instance.setAgentPrefVelocity(sid KInt2.zero);
return;
}
KInt2 goalVector = GameMainManager.Instance.mousePosition - Simulator.Instance.getAgentPosition(sid);//GameMainManager.Instance.mousePosition
if (RVOMath.absSq(goalVector) > 1)
{
goalVector = RVOMath.normalize(goalVector);
}
Simulator.Instance.setAgentPrefVelocity(sid goalVector);
/* Perturb a little to avoid deadlocks due to perfect symmetry. */
float angle = (float) m_random.NextDouble()*2.0f*(float) Math.PI;
float dist = (float) m_random.NextDouble()*0.0001f;
Simulator.Instance.setAgentPrefVelocity(sid Simulator.Instance.getAgentPrefVelocity(sid) +
dist*
new KInt2((float) Math.Cos(angle) (float) Math.Sin(angle)));
}
#if UNITY_EDITOR
public void OnDrawGizmos()
{
Gizmos.color = new Color(240 / 255f 213 / 255f 30 / 255f);
Gizmos.DrawWireSphere(transform.position Simulator.Instance.getAgentRadius(this.sid).floatvalue);
KInt2 point = KInt2.zero;
if(Simulator.Instance.ClosedObstaclePoint(sidref point))
{
Gizmos.color = Color.black;
Gizmos.DrawLine(transform.position new Vector3(point.x0 point.y));
}
if(Simulator.Instance.isInEdge(sid))
{
GUIstyle style = new GUIstyle();
style.normal.textColor = Color.red;
UnityEditor.Handles.Label(transform.position (“最近距离“ + Simulator.Instance.ClosedEdgeDist(sid)) + “ 在角落 “ + Simulator.Instance.isInEdge(sid) style);
}
else
{
GUIstyle style = new GUIstyle();
style.normal.textColor = Color.green;
UnityEditor.Handles.Label(transform.position (“最近距离“ + Simulator.Instance.ClosedEdgeDist(sid)) +
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-03-08 12:14 Assets\
文件 5518 2017-12-25 16:15 Assets\GameAgent.prefab
文件 210 2017-12-14 11:37 Assets\GameAgent.prefab.me
文件 662907 2018-02-24 12:32 Assets\kdtree_w01.asset
文件 208 2018-02-24 12:32 Assets\kdtree_w01.asset.me
文件 1239850 2018-02-24 12:35 Assets\kdtree_w02.asset
文件 208 2018-02-24 12:35 Assets\kdtree_w02.asset.me
文件 13153 2018-03-08 12:14 Assets\Main.unity
文件 174 2017-12-25 15:43 Assets\Main.unity.me
文件 1812 2018-02-22 12:18 Assets\Manager.prefab
文件 209 2017-12-25 15:42 Assets\Manager.prefab.me
目录 0 2018-02-22 12:18 Assets\Materials\
文件 201 2018-02-22 12:18 Assets\Materials.me
文件 2080 2018-02-22 12:18 Assets\Materials\navmeshMat.mat
文件 217 2018-02-22 12:18 Assets\Materials\navmeshMat.mat.me
文件 477 2018-02-24 12:30 Assets\MenuTools.asset
文件 208 2018-01-23 01:25 Assets\MenuTools.asset.me
文件 377801 2018-02-10 15:58 Assets\navmesh.obj
文件 2006 2018-02-10 15:58 Assets\navmesh.obj.me
目录 0 2018-03-08 12:14 Assets\sc
文件 192 2017-12-14 11:37 Assets\sc
文件 3121 2018-02-24 00:46 Assets\sc
文件 263 2017-12-14 11:37 Assets\sc
文件 3053 2018-02-22 12:18 Assets\sc
文件 263 2017-12-14 11:37 Assets\sc
目录 0 2018-02-13 13:36 Assets\sc
文件 192 2017-12-14 11:37 Assets\sc
目录 0 2018-02-13 13:36 Assets\sc
文件 191 2017-12-25 17:38 Assets\sc
文件 1372 2017-12-25 17:38 Assets\sc
文件 262 2017-12-25 17:38 Assets\sc
............此处省略648个文件信息
评论
共有 条评论