public static float GetViewDistance(Vector3 position, float viewDistance, bool isAlerted) { var count = Physics.OverlapSphereNonAlloc(position, 1, Colliders, Layers.Zones, QueryTriggerInteraction.Collide); _dark.Clear(); _light.Clear(); _grass.Clear(); for (int i = 0; i < count; i++) { { var zone = DarkZone.Get(Colliders[i].gameObject); if (zone != null) { _dark.Add(zone); } } { var zone = LightZone.Get(Colliders[i].gameObject); if (zone != null) { _light.Add(zone); } } { var zone = GrassZone.Get(Colliders[i].gameObject); if (zone != null) { _grass.Add(zone); } } } return(GetViewDistance(viewDistance, _dark, _light, _grass, isAlerted)); }
/// <summary> /// The actor leaves a dark area. /// </summary> public void OnLeaveDarkness(DarkZone zone) { if (_darkZones.Contains(zone)) { _darkZones.Remove(zone); } }
/// <summary> /// The actor enters a dark area. /// </summary> public void OnEnterDarkness(DarkZone zone) { if (!_darkZones.Contains(zone)) { _darkZones.Add(zone); } }
/// <summary> /// Notified of an entrance to a dark area. /// </summary> public void OnEnterDarkness(DarkZone zone) { _darkzoneCount++; if (_darkzoneCount == 1) { Message("OnNeedLight"); } }
/// <summary> /// Notified of an exit out of a dark area. /// </summary> public void OnLeaveDarkness(DarkZone zone) { _darkzoneCount--; if (_darkzoneCount == 0) { Message("OnDontNeedLight"); } }
public static void Register(DarkZone zone) { if (!_list.Contains(zone)) { _list.Add(zone); } _map[zone.gameObject] = zone; }
public static void Unregister(DarkZone zone) { if (_list.Contains(zone)) { _list.Remove(zone); } if (_map.ContainsKey(zone.gameObject)) { _map.Remove(zone.gameObject); } }
static void Gizmo(DarkZone zone, GizmoType type) { var isSelected = (type & GizmoType.Selected) != 0; var alpha = isSelected ? 0.8f : 0.4f; var collider = zone.GetComponent <BoxCollider>(); if (collider != null) { var bounds = collider.bounds; Gizmos.color = new Color(0.5f, 0.5f, 1.0f, alpha); Gizmos.DrawCube(bounds.center, bounds.extents * 2); } }