private void CheckContacts() { Collider[] Colliders = PhysicExtension.GetNeighborsTypesBySphere <Collider>(transform.position, Radius, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower())); for (int i = 0; i < Colliders.Length; i++) { SocketBehaviour Socket = Colliders[i].GetComponent <SocketBehaviour>(); if (Socket != null) { if (Socket != this) { if (Socket.AllowPart(Socket.AttachedPart)) { for (int x = 0; x < BusySpaces.Count; x++) { Socket.AddOccupancy(BusySpaces[x].Part); } } } } } if (DisableOnGroundContact) { Colliders = PhysicExtension.GetNeighborsTypesBySphere <Collider>(transform.position, Radius, LayerMask.NameToLayer(Constants.LAYER_DEFAULT.ToLower())); for (int i = 0; i < Colliders.Length; i++) { if (Colliders[i] as TerrainCollider || Colliders[i].GetComponentInParent <VoxelandCollider>() || Colliders[i].GetComponentInParent <VoxelandCollider>()) { DisableCollider(); } } } }
/// <summary> /// This method allows to update the placement preview. /// </summary> public void UpdatePreview() { HasSocket = false; if (CameraType == RayType.TopDown) { Physics.Raycast(GetRay(), out TopDownHit, Mathf.Infinity, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()), QueryTriggerInteraction.Ignore); } if (RayDetection == DetectionType.Overlap) { SocketBehaviour[] Sockets = PhysicExtension.GetNeighborsTypesBySphere <SocketBehaviour>(GetTransform.position, ActionDistance, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower())); if (Sockets.Length > 0) { UpdateSnapsMovement(Sockets); } else { UpdateFreeMovement(); } } else { SocketBehaviour Socket = null; if (Physics.Raycast(GetRay(), out RaycastHit Hit, ActionDistance, LayerMask.NameToLayer(Constants.LAYER_SOCKET.ToLower()))) { if (Hit.collider.GetComponent <SocketBehaviour>() != null) { Socket = Hit.collider.GetComponent <SocketBehaviour>(); } } Debug.Log(Socket); if (Socket != null) { UpdateSnapsMovement(new SocketBehaviour[1] { Socket }); } else { UpdateFreeMovement(); } } if (CurrentMode == BuildMode.Placement || CurrentMode == BuildMode.Edition) { foreach (SocketBehaviour Socket in BuildManager.Instance.Sockets) { if (Socket != null) { Socket.EnableColliderByPartType(SelectedPrefab.Type); } } } AllowPlacement = !HasCollision(); if (AllowPlacement && CurrentPreview.RequireSockets && !HasSocket) { AllowPlacement = false; } if (AllowPlacement && OutOfRangeDistance != 0) { AllowPlacement = Vector3.Distance(GetTransform.position, CurrentPreview.transform.position) < ActionDistance; } CurrentPreview.gameObject.ChangeAllMaterialsColorInChildren(CurrentPreview.Renderers.ToArray(), AllowPlacement ? BuildManager.Instance.PreviewAllowedColor : BuildManager.Instance.PreviewDeniedColor, SelectedPrefab.PreviewColorLerpTime, SelectedPrefab.PreviewUseColorLerpTime); }