RaycastCrafter
A class in Root.Township, the global namespace.
Places a pickup onto a surface when it is let go: raycasts in a set direction and either sticks the pickup there or replaces it with another prefab. The server does the placing and syncs it; used by things like wall hooks.
- Listed in Global namespace: Q to R
- Inherits or implements
NetworkEntityBehaviour,ISavable<RaycastCrafterSaveData>,ISavableSave<RaycastCrafterSaveData>,ISavableSaveBase - Derived types
FireStatusRaycastCrafter,RaycastCrafterSaveData - Nested types
PlacedItem - Documented in Crafting
Constructors
| Member | What it is |
|---|---|
RaycastCrafter() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
21 private and internal fields
| Member | What it is |
|---|---|
private Quaternion additionalRotation | Extra rotation applied after facing the surface normal. |
private AltaEvent crafted | Event fired when the pickup is placed. When loading as placed it only fires on the server. |
private Coroutine currentCoroutine | The running preview or placing coroutine. |
private Vector3 direction | Raycast direction. Defaults to down. |
private float distance | Raycast length. Defaults to 1. |
private PooledObjectDefinition effect | Pooled effect shown at the surface while the pickup is held. |
private const int entityPileSizeToConsiderGriefing | Number of overlapping entities (10) that counts as a griefing pile. |
private static HashSet<uint> foundEntities | Shared set of entity IDs counted during a griefing check. |
private Func<Vector3> getDirection | Either WorldSpaceDirection or LocalSpaceDirection, set from isWorldSpace. |
private bool isBeingReplacedByPrefabOnCrafted | If true, placing spawns prefabToReplaceWith and destroys this pickup instead of sticking it. |
private bool isWorldSpace | If true, direction is in world space; otherwise it rotates with the object. |
private LayerMask layerMask | Layers the raycast can hit. |
private float maximumNormal | Highest surface normal Y the pickup can be placed on. |
private float minimumNormal | Lowest surface normal Y the pickup can be placed on. Both default to 1, so flat ground only. |
private static Collider[] overlap | Shared buffer for the griefing overlap check (20 colliders). |
private Pickup pickup | The pickup on this object. |
private PooledObject pooled | Preview effect currently shown, if any. |
private NetworkPrefab prefabToReplaceWith | Prefab spawned at the hit point when isBeingReplacedByPrefabOnCrafted is on. |
private MethodSync syncNotPlaced | Method sync on SyncA for unplacing. |
private MethodSyncStruct<RaycastCrafter.PlacedItem> syncPlace | Method sync on SyncPlaced for placing. |
private List<PooledObject> usingPooled | All preview effects taken from the pool and not yet released. |
Properties
| Member | What it is |
|---|---|
bool IsCrafted { get; private set; } | True while the pickup is placed on a surface. Saved; loading as placed fires crafted on the server. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Hooks the pickup's grab and release events, picks world or local direction and creates the syncs. |
override void OnConnected(Player player) | Sends the placed transform to a joining player if the pickup is placed. |
protected virtual void OnSpawn(NetworkEntity entity) | Virtual hook called on the new entity after ReplaceByPrefab spawns it. Empty here. |
21 private and internal methods
| Member | What it is |
|---|---|
private static bool ColliderCountsTowardsGriefingLimit(Collider collider, HashSet<uint> foundEntitiyIdentifiers) | True if the collider belongs to a network entity not already counted in the set. |
private IEnumerator DelayToPlace() (iterator) | One frame after release, raycasts and places or replaces the pickup; kicks the player if the spot is a griefing pile. |
private void FinishPooled() | Stops the surface preview particles and releases them after two seconds. |
private void InteractionEnded(Interactable interactable, Interactor interactor) | When the last hand lets go, places the pickup on the server (or locally if not replaced), else syncs not placed. |
private void InteractionStarted(Interactable interactable, Interactor interactor) | Shows the surface preview on clients, turns the pickup's physics sync back on and clears IsCrafted. |
private static bool IsGriefingAction(RaycastHit hit) | True when 10 or more distinct entities overlap within 0.1 m of the hit point. |
private IEnumerator KillPooled(PooledObject pooled) (iterator) | Coroutine that releases a preview effect after two seconds. |
private Vector3 LocalSpaceDirection() | Returns direction rotated by the object's rotation. |
private IEnumerator LookForSurface() (iterator) | Client coroutine that moves a preview effect to the raycast hit every frame while held. |
private void OnDisable() | Releases all preview effects back to the pool. |
private void OnDrawGizmosSelected() | Draws the raycast line in the editor. |
private void OnValidate() | Reselects world or local direction when the setting changes in play mode. |
private RaycastCrafter.PlacedItem PlaceOnSurface(RaycastHit hit) | Drops the pickup, moves it to the hit point facing the surface normal and freezes it. Fires crafted on the server. |
private bool Raycast(out RaycastHit hit) | Raycasts from the object along the direction and accepts the hit only if its normal's Y is between the min and max. |
private RaycastCrafter.PlacedItem ReplaceByPrefab(RaycastHit hit) | Spawns prefabToReplaceWith at the hit point facing the surface normal, frozen. The old pickup is destroyed after. |
private void SwapCoroutine(IEnumerator to) | Stops the running coroutine and starts a new one, if given. |
private void SyncNotPlaced(IPlayer player, Stream stream) | Method sync that marks the pickup as not placed and unfreezes it unless docked. |
private void SyncPlaced(IPlayer player, Stream stream, RaycastCrafter.PlacedItem placedItem) | Method sync with the placed entity, position and rotation. Clients freeze it in place and fire crafted. |
private static bool TryGetColliderEntity(Collider overlappingCollider, out NetworkEntity entity) | Gets the network entity on the collider's attached rigidbody, if any. |
private static bool WillNotReachGriefingLimit(HashSet<uint> foundEntities, int overlapCount, int i) | True if the colliders left can't bring the entity count up to 10. |
private Vector3 WorldSpaceDirection() | Returns direction as is. |
Used in
Members of other types that take, return or hold a RaycastCrafter: