How can i find cupboard based on a given Vector3 position with the new buidling 3.0.
This is what i used before the update:
Code:private BuildingPrivlidge GetCupboard(Vector3 position) { List<Collider> colliders = Facepunch.Pool.GetList<Collider>(); Vis.Colliders(position, 0.1f, colliders, LayerMask.GetMask("Trigger")); foreach (Collider collider in colliders) { BuildingPrivlidge tc = collider.GetComponentInParent<BuildingPrivlidge>(); if (tc == null) continue; return tc; } return null; }
Getting TC from position
Discussion in 'Rust Development' started by xehbit, Dec 8, 2017.
-
Wtf???? Why you use GetComponentInParent? it's very slow
Use ToBaseEntity -
-
From what i know, it's necessary to find the nearest BuildingBlock, get Building from BuildingManager by its ID and check if this structure has TC.
There could be better ways, probably, but i haven't found them yet. -
I can find all building blocks that belongs to a cupboard, but isn't that expensive to loop over each building entity?
-
-
Haven't tested it yet, but it seems FacePunch uses the following code to check for building priv's based on OBB input;
Code:public BuildingPrivlidge GetBuildingPrivilege(OBB obb) { BuildingBlock buildingBlock1 = (BuildingBlock) null; BuildingPrivlidge buildingPrivlidge = (BuildingPrivlidge) null; System.Collections.Generic.List<BuildingBlock> list = Facepunch.Pool.GetList<BuildingBlock>(); Vis.Entities<BuildingBlock>(obb.position, 16f + obb.extents.magnitude, list, 2097152, QueryTriggerInteraction.Collide); for (int index = 0; index < list.Count; ++index) { BuildingBlock buildingBlock2 = list[index]; if (buildingBlock2.isServer == this.isServer && buildingBlock2.IsOlderThan((BaseEntity) buildingBlock1) && (double) obb.Distance(buildingBlock2.WorldSpaceBounds()) <= 16.0) { BuildingManager.Building building = buildingBlock2.GetBuilding(); if (building != null) { BuildingPrivlidge buildingPrivilege = building.GetDominatingBuildingPrivilege(); if (!((UnityEngine.Object) buildingPrivilege == (UnityEngine.Object) null)) { buildingBlock1 = buildingBlock2; buildingPrivlidge = buildingPrivilege; } } } } Facepunch.Pool.FreeList<BuildingBlock>(ref list); return buildingPrivlidge; }
-
-