@@ -475,21 +475,23 @@ public override void FinishBuildAimControls(bool isCancel)
475475
476476 public void FindAndSetBuildingAreaByAxes ( Vector2 aimAxes )
477477 {
478- Vector3 tempVector3 = CacheTransform . position + ( GameplayUtils . GetDirectionByAxes ( CacheGameplayCameraTransform , aimAxes . x , aimAxes . y ) * ConstructingBuildingEntity . BuildDistance ) ;
479- LoopSetBuildingArea ( physicFunctions . Raycast ( tempVector3 , Vector3 . down , 100f , CurrentGameInstance . GetBuildLayerMask ( ) ) ) ;
478+ Vector3 raycastPosition = CacheTransform . position + ( GameplayUtils . GetDirectionByAxes ( CacheGameplayCameraTransform , aimAxes . x , aimAxes . y ) * ConstructingBuildingEntity . BuildDistance ) ;
479+ LoopSetBuildingArea ( physicFunctions . RaycastDown ( raycastPosition , CurrentGameInstance . GetBuildLayerMask ( ) ) , raycastPosition ) ;
480480 }
481481
482482 public void FindAndSetBuildingAreaByMousePosition ( )
483483 {
484- LoopSetBuildingArea ( physicFunctions . RaycastPickObjects ( CacheGameplayCamera , InputManager . MousePosition ( ) , CurrentGameInstance . GetBuildLayerMask ( ) , 100f , out _ ) ) ;
484+ Vector3 worldPosition2D ;
485+ LoopSetBuildingArea ( physicFunctions . RaycastPickObjects ( CacheGameplayCamera , InputManager . MousePosition ( ) , CurrentGameInstance . GetBuildLayerMask ( ) , 100f , out worldPosition2D ) , worldPosition2D ) ;
485486 }
486487
487488 /// <summary>
488489 /// Return true if found building area
489490 /// </summary>
490491 /// <param name="count"></param>
492+ /// <param name="raycastPosition"></param>
491493 /// <returns></returns>
492- private bool LoopSetBuildingArea ( int count )
494+ private bool LoopSetBuildingArea ( int count , Vector3 raycastPosition )
493495 {
494496 IGameEntity gameEntity ;
495497 BuildingArea buildingArea ;
@@ -499,7 +501,8 @@ private bool LoopSetBuildingArea(int count)
499501 {
500502 tempTransform = physicFunctions . GetRaycastTransform ( tempCounter ) ;
501503 tempVector3 = GameplayUtils . ClampPosition ( CacheTransform . position , physicFunctions . GetRaycastPoint ( tempCounter ) , ConstructingBuildingEntity . BuildDistance ) ;
502- tempVector3 . y = physicFunctions . GetRaycastPoint ( tempCounter ) . y ;
504+ if ( CurrentGameInstance . DimensionType == DimensionType . Dimension3D )
505+ tempVector3 . y = physicFunctions . GetRaycastPoint ( tempCounter ) . y ;
503506
504507 buildingArea = tempTransform . GetComponent < BuildingArea > ( ) ;
505508 if ( buildingArea == null )
@@ -526,22 +529,45 @@ private bool LoopSetBuildingArea(int count)
526529 ConstructingBuildingEntity . Position = GetBuildingPlacePosition ( tempVector3 ) ;
527530 return true ;
528531 }
532+ if ( CurrentGameInstance . DimensionType == DimensionType . Dimension2D )
533+ {
534+ ConstructingBuildingEntity . BuildingArea = null ;
535+ ConstructingBuildingEntity . Position = GetBuildingPlacePosition ( raycastPosition ) ;
536+ }
529537 return false ;
530538 }
531539
532540 private Vector3 GetBuildingPlacePosition ( Vector3 position )
533541 {
534- if ( buildGridSnap )
535- position = new Vector3 ( Mathf . Round ( position . x / buildGridSize ) * buildGridSize , position . y , Mathf . Round ( position . z / buildGridSize ) * buildGridSize ) + buildGridOffsets ;
542+ if ( CurrentGameInstance . DimensionType == DimensionType . Dimension3D )
543+ {
544+ if ( buildGridSnap )
545+ position = new Vector3 ( Mathf . Round ( position . x / buildGridSize ) * buildGridSize , position . y , Mathf . Round ( position . z / buildGridSize ) * buildGridSize ) + buildGridOffsets ;
546+ }
547+ else
548+ {
549+ if ( buildGridSnap )
550+ position = new Vector3 ( Mathf . Round ( position . x / buildGridSize ) * buildGridSize , Mathf . Round ( position . y / buildGridSize ) * buildGridSize ) + buildGridOffsets ;
551+ }
536552 return position ;
537553 }
538554
539- private Quaternion GetBuildingPlaceRotation ( float anglesY )
555+ private Quaternion GetBuildingPlaceRotation ( float angles )
540556 {
541557 Vector3 eulerAngles = Vector3 . zero ;
542- // Make Y rotation set to 0, 90, 180
543- if ( buildRotationSnap )
544- eulerAngles . y = Mathf . Round ( anglesY / 90 ) * 90 ;
558+ if ( CurrentGameInstance . DimensionType == DimensionType . Dimension3D )
559+ {
560+ if ( buildRotationSnap )
561+ {
562+ // Make Y rotation set to 0, 90, 180
563+ eulerAngles . y = Mathf . Round ( angles / 90 ) * 90 ;
564+ }
565+ else
566+ {
567+ // Rotate by set angles
568+ eulerAngles . y = angles ;
569+ }
570+ }
545571 return Quaternion . Euler ( eulerAngles ) ;
546572 }
547573 }
0 commit comments