• 大小: 2.06MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-20
  • 语言: 其他
  • 标签: RVO;Navmesh  

资源简介

基于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.meta
     文件      662907  2018-02-24 12:32  Assets\kdtree_w01.asset
     文件         208  2018-02-24 12:32  Assets\kdtree_w01.asset.meta
     文件     1239850  2018-02-24 12:35  Assets\kdtree_w02.asset
     文件         208  2018-02-24 12:35  Assets\kdtree_w02.asset.meta
     文件       13153  2018-03-08 12:14  Assets\Main.unity
     文件         174  2017-12-25 15:43  Assets\Main.unity.meta
     文件        1812  2018-02-22 12:18  Assets\Manager.prefab
     文件         209  2017-12-25 15:42  Assets\Manager.prefab.meta
     目录           0  2018-02-22 12:18  Assets\Materials\
     文件         201  2018-02-22 12:18  Assets\Materials.meta
     文件        2080  2018-02-22 12:18  Assets\Materials\navmeshMat.mat
     文件         217  2018-02-22 12:18  Assets\Materials\navmeshMat.mat.meta
     文件         477  2018-02-24 12:30  Assets\MenuTools.asset
     文件         208  2018-01-23 01:25  Assets\MenuTools.asset.meta
     文件      377801  2018-02-10 15:58  Assets\navmesh.obj
     文件        2006  2018-02-10 15:58  Assets\navmesh.obj.meta
     目录           0  2018-03-08 12:14  Assets\scripts\
     文件         192  2017-12-14 11:37  Assets\scripts.meta
     文件        3121  2018-02-24 00:46  Assets\scripts\GameAgent.cs
     文件         263  2017-12-14 11:37  Assets\scripts\GameAgent.cs.meta
     文件        3053  2018-02-22 12:18  Assets\scripts\GameMainManager.cs
     文件         263  2017-12-14 11:37  Assets\scripts\GameMainManager.cs.meta
     目录           0  2018-02-13 13:36  Assets\scripts\LeanPool\
     文件         192  2017-12-14 11:37  Assets\scripts\LeanPool.meta
     目录           0  2018-02-13 13:36  Assets\scripts\LeanPool\Editor\
     文件         191  2017-12-25 17:38  Assets\scripts\LeanPool\Editor.meta
     文件        1372  2017-12-25 17:38  Assets\scripts\LeanPool\Editor\LeanPool_Editor.cs
     文件         262  2017-12-25 17:38  Assets\scripts\LeanPool\Editor\LeanPool_Editor.cs.meta
............此处省略648个文件信息

评论

共有 条评论

相关资源