Beispiel #1
0
    public static int CountEntitiesInArea(GameObject entityPrefab, Vector3 center, float range)
    {
#if DEBUG && VERBOSE
        Log.LogDebug("WorldSpawnSessionManager.CountEntitiesInArea");
#endif
        try
        {
            ZdoPrefabQuery query;
            if (center == Vector3.zero && range == 0)
            {
                // TODO: Consider lowering the range, or making it configurable.
                query = new ZdoPrefabQuery(Context.SpawnerZdo.m_position, 250);
            }
            else
            {
                query = new ZdoPrefabQuery(center, (int)range);
            }

            var prefabHash = entityPrefab.name.GetStableHashCode();

            return(query.CountEntities(prefabHash));
        }
        catch (Exception e)
        {
            Log.LogError($"Error while attempting to count nearby entities {entityPrefab}", e);
            return(0);
        }
    }
Beispiel #2
0
    public static bool AnyInRange(GameObject prefab, Vector3 center, int radius)
    {
#if DEBUG && VERBOSE
        Log.LogDebug("WorldSpawnSessionManager.AnyInRange");
#endif
        try
        {
            var query      = new ZdoPrefabQuery(center, radius);
            var prefabHash = prefab.name.GetStableHashCode();

            return(query.HasAny(prefabHash));
        }
        catch (Exception e)
        {
            Log.LogError($"Error while attempting to find any entity {prefab} nearby", e);
            return(false);
        }
    }