Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
protected virtual bool TestVisibility(RAINAspect aAspect, float aSqrRange, Matrix4x4 aSensorSpace)
{
Vector3 position = aAspect.Position;
Vector3 vector4 = position - this.Position;
if (vector4.sqrMagnitude > aSqrRange)
{
return false;
}
Transform transform = aAspect.Entity.Form.transform;
if (aAspect.MountPoint != null)
{
transform = aAspect.MountPoint.transform;
}
if ((!this.CanDetectSelf && (transform != null)) && ((transform == this.AI.Body.transform) || transform.IsChildOf(this.AI.Body.transform)))
{
return false;
}
bool flag = true;
if ((this.HorizontalAngle == 360f) && (this.VerticalAngle == 360f))
{
flag = true;
}
else
{
position = aSensorSpace.MultiplyPoint(position);
Vector3 vector5 = new Vector3(position.x, 0f, position.z);
Vector3 normalized = vector5.normalized;
float num = Mathf.Acos(Mathf.Clamp(normalized.z, -1f, 1f)) * 57.29578f;
if (num > 180f)
{
num = 360f - num;
}
if (!Mathf.Approximately(normalized.sqrMagnitude, 0f) && (num > (this.HorizontalAngle / 2f)))
{
flag = false;
}
else
{
Vector3 vector6 = new Vector3(0f, position.y, position.z);
normalized = vector6.normalized;
float num2 = Mathf.Acos(Mathf.Clamp(normalized.z, -1f, 1f)) * 57.29578f;
if (num2 > 180f)
{
num2 = 360f - num2;
}
if (num2 > 90f)
{
num2 = 180f - num2;
}
if (!Mathf.Approximately(normalized.sqrMagnitude, 0f) && (num2 > (this.VerticalAngle / 2f)))
{
flag = false;
}
}
}
if (!flag)
{
return false;
}
if (this._lineOfSight)
{
Vector3 direction = aAspect.Position - this.Position;
RaycastHit[] hitArray = Physics.RaycastAll(this.Position, direction, direction.magnitude, (int) this._lineOfSightMask);
for (int i = 0; i < hitArray.Length; i++)
{
if ((hitArray[i].collider.isTrigger || (hitArray[i].transform == this.AI.Body.transform)) || hitArray[i].transform.IsChildOf(this.AI.Body.transform))
{
continue;
}
if (aAspect.MountPoint != null)
{
if ((hitArray[i].transform != aAspect.MountPoint.transform) && !hitArray[i].transform.IsChildOf(aAspect.MountPoint.transform))
{
goto Label_0331;
}
continue;
}
if ((aAspect.Entity.Form != null) && ((hitArray[i].transform == aAspect.Entity.Form.transform) || hitArray[i].transform.IsChildOf(aAspect.Entity.Form.transform)))
{
continue;
}
Label_0331:
return false;
}
}
return true;
}
Unity3d. Реализация зон видимости и слышимости