예제 #1
0
        void DrawFieldOfView(Transform owner, float viewAngle, float viewDistance, FieldOfViewUnit unit)
        {
            if (Model.disableRendering)
            {
                return;
            }

            int            stepCount     = Mathf.RoundToInt(viewAngle * Model.meshResolution);
            float          stepAngleSize = viewAngle / stepCount;
            List <Vector3> viewPoints    = new List <Vector3>();
            List <float>   viewAngles    = new List <float>();
            ViewCastInfo   oldViewCast   = new ViewCastInfo();
            float          startAngle    = viewAngle == 360.0f ? 0 : owner.eulerAngles.y;

            for (int i = 0; i <= stepCount; i++)
            {
                float        angle       = startAngle - viewAngle / 2 + stepAngleSize * i;
                ViewCastInfo newViewCast = ViewCast(owner, angle, viewDistance);

                if (i > 0)
                {
                    bool edgeDstThreshholdExceeded = Mathf.Abs(oldViewCast.dst - newViewCast.dst) > Model.edgeDistanceThreshhold;
                    if (oldViewCast.hit != newViewCast.hit || (oldViewCast.hit && edgeDstThreshholdExceeded))
                    {
                        EdgeInfo edge = FindEdge(owner, oldViewCast, newViewCast, viewDistance);

                        if (edge.pointA != Vector3.zero)
                        {
                            viewPoints.Add(owner.InverseTransformPoint(edge.pointA));
                            viewAngles.Add(edge.angleA);
                        }

                        if (edge.pointB != Vector3.zero)
                        {
                            viewPoints.Add(owner.InverseTransformPoint(edge.pointB));
                            viewAngles.Add(edge.angleB);
                        }
                    }
                }

                viewPoints.Add(owner.InverseTransformPoint(newViewCast.point));
                viewAngles.Add(angle);
                oldViewCast = newViewCast;
            }

            if (Model.ribbon && unit.RibbonViewMesh)
            {
                renderRibbon(viewPoints, viewAngles, unit.RibbonViewMesh, owner);
            }
            //Debug.Log("IT" + fovUnit.ViewMesh + " " + fan);
            if (Model.fan && unit.ViewMesh)
            {
                renderFan(viewPoints, viewAngles, unit.ViewMesh, owner);
            }
        }
예제 #2
0
        void OnSceneGUI()
        {
            FieldOfViewUnit  fow      = (FieldOfViewUnit)target;
            FieldOfViewModel fovModel = (FieldOfViewModel)fow.Model;

            foreach (FieldOfViewUnit unit in fovModel.units)
            {
                Handles.color = Color.yellow;
                if (unit != fow)
                {
                    Handles.DrawWireArc(unit.transform.position, Vector3.up, Vector3.forward, 360, unit.revealRadius);
                }
            }
            Handles.color = Color.white;
            Handles.DrawWireArc(fow.transform.position, Vector3.up, Vector3.forward, 360, fow.revealRadius);

            foreach (Transform target in fovModel.visibleTargets)
            {
                Handles.color = Color.red;

                Handles.DrawWireCube(target.transform.position, target.transform.localScale * 1.2f);
            }
        }