Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static class Constants
- {
- public static readonly string[] TopTierEntities =
- {
- "assets/prefabs/building/door.hinged/door.hinged.toptier.prefab",
- "assets/prefabs/building/door.double.hinged/door.double.hinged.toptier.prefab",
- "assets/prefabs/building/wall.window.bars/wall.window.bars.toptier.prefab",
- //"assets/prefabs/building/wall.window.reinforcedglass/wall.window.glass.reinforced.prefab"
- };
- }
- public static bool IsVisible(BasePlayer player, Vector3 position, bool onlyTopTier = false)
- {
- Vector3 a = player.eyes.position - position;
- float magnitude = a.magnitude;
- if (magnitude < Mathf.Epsilon)
- return true;
- Vector3 vector = a / magnitude;
- Vector3 b = vector * Mathf.Min(magnitude, 0.01f);
- var ray = new Ray(position + b, vector);
- RaycastHit playerToPos;
- if (ray.origin.IsNaNOrInfinity() || ray.direction.IsNaNOrInfinity() || ray.direction == Vector3.zero ||
- !player.WorldSpaceBounds().Trace(ray, out playerToPos))
- return false;
- RaycastHit hit;
- if (!GamePhysics.Trace(ray, 0f, out hit, float.PositiveInfinity, onlyTopTier ? 2097152 : 1218519041))
- return true;
- if (hit.distance > playerToPos.distance)
- return true;
- if (!onlyTopTier)
- return false;
- var ent = hit.GetEntity();
- if (Array.Exists(Constants.TopTierEntities, x => x == ent.PrefabName))
- return false;
- var buildingBlock = ent as BuildingBlock;
- return buildingBlock == null || buildingBlock.grade != BuildingGrade.Enum.TopTier;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement