|
|
@@ -1008,9 +1008,7 @@ public class NewRoomBuilder : MonoBehaviour
|
|
|
|
|
|
// Create entrance with proper rotation
|
|
|
GameObject entrance = CreateEntrancePrefab();
|
|
|
- entrance.transform.position = entrancePosition;
|
|
|
-
|
|
|
- // Set rotation based on wall orientation
|
|
|
+ entrance.transform.position = entrancePosition; // Set rotation based on wall orientation
|
|
|
if (isNorthSouthWall)
|
|
|
{
|
|
|
// For North/South walls (extending in X), entrance should face along Z-axis
|
|
|
@@ -1043,7 +1041,11 @@ public class NewRoomBuilder : MonoBehaviour
|
|
|
// Get the original wall's material to maintain consistency
|
|
|
Material originalMaterial = originalWall.GetComponent<Renderer>()?.material;
|
|
|
|
|
|
- Debug.Log($"Splitting wall: {originalWall.name} at position {wallPos} with scale {wallScale}");
|
|
|
+ if (wallPrefab == null)
|
|
|
+ {
|
|
|
+ Debug.LogError("WallPrefab is null! Cannot create wall segments. Aborting split operation.");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if (isNorthSouthWall)
|
|
|
{
|
|
|
@@ -1057,50 +1059,74 @@ public class NewRoomBuilder : MonoBehaviour
|
|
|
|
|
|
Debug.Log($"North/South wall split: wallLeft={wallLeft}, wallRight={wallRight}, entranceLeft={entranceLeft}, entranceRight={entranceRight}");
|
|
|
|
|
|
- // Create left segment if there's enough space
|
|
|
- if (entranceLeft - wallLeft > 0.5f)
|
|
|
+ float leftSegmentLength = entranceLeft - wallLeft;
|
|
|
+ float rightSegmentLength = wallRight - entranceRight;
|
|
|
+ Debug.Log($"Segment lengths: left={leftSegmentLength}, right={rightSegmentLength}"); // Create left segment if there's enough space
|
|
|
+ if (leftSegmentLength > 0.5f)
|
|
|
{
|
|
|
- float leftLength = entranceLeft - wallLeft;
|
|
|
- Vector3 leftCenter = new Vector3(wallLeft + leftLength / 2f, wallPos.y, wallPos.z);
|
|
|
+ Vector3 leftCenter = new Vector3(wallLeft + leftSegmentLength / 2f, wallPos.y, wallPos.z);
|
|
|
|
|
|
GameObject leftWall = Instantiate(wallPrefab, leftCenter, wallRotation);
|
|
|
leftWall.SetActive(true);
|
|
|
leftWall.name = $"{originalWall.name}_Left_Entrance";
|
|
|
- leftWall.transform.localScale = new Vector3(leftLength, wallScale.y, wallScale.z);
|
|
|
+ leftWall.transform.localScale = new Vector3(leftSegmentLength, wallScale.y, wallScale.z);
|
|
|
leftWall.tag = "Wall";
|
|
|
|
|
|
- // Apply original material if available
|
|
|
+ // Apply original material if available, with error checking
|
|
|
if (originalMaterial != null)
|
|
|
{
|
|
|
- leftWall.GetComponent<Renderer>().material = originalMaterial;
|
|
|
+ Renderer leftRenderer = leftWall.GetComponent<Renderer>();
|
|
|
+ if (leftRenderer != null)
|
|
|
+ {
|
|
|
+ leftRenderer.material = originalMaterial;
|
|
|
+ Debug.Log($"Applied original material to left wall segment");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogWarning($"Left wall segment {leftWall.name} has no Renderer component - cannot apply material");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
walls.Add(leftWall);
|
|
|
-
|
|
|
- Debug.Log($"Created left wall segment: scale {leftWall.transform.localScale} at {leftWall.transform.position}");
|
|
|
+ Debug.Log($"SUCCESS: Created left wall segment: {leftWall.name}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"LEFT SEGMENT TOO SMALL: {leftSegmentLength} <= 0.5f, not creating");
|
|
|
}
|
|
|
|
|
|
// Create right segment if there's enough space
|
|
|
- if (wallRight - entranceRight > 0.5f)
|
|
|
+ if (rightSegmentLength > 0.5f)
|
|
|
{
|
|
|
- float rightLength = wallRight - entranceRight;
|
|
|
- Vector3 rightCenter = new Vector3(entranceRight + rightLength / 2f, wallPos.y, wallPos.z);
|
|
|
+ Vector3 rightCenter = new Vector3(entranceRight + rightSegmentLength / 2f, wallPos.y, wallPos.z);
|
|
|
|
|
|
GameObject rightWall = Instantiate(wallPrefab, rightCenter, wallRotation);
|
|
|
rightWall.SetActive(true);
|
|
|
rightWall.name = $"{originalWall.name}_Right_Entrance";
|
|
|
- rightWall.transform.localScale = new Vector3(rightLength, wallScale.y, wallScale.z);
|
|
|
+ rightWall.transform.localScale = new Vector3(rightSegmentLength, wallScale.y, wallScale.z);
|
|
|
rightWall.tag = "Wall";
|
|
|
|
|
|
- // Apply original material if available
|
|
|
+ // Apply original material if available, with error checking
|
|
|
if (originalMaterial != null)
|
|
|
{
|
|
|
- rightWall.GetComponent<Renderer>().material = originalMaterial;
|
|
|
+ Renderer rightRenderer = rightWall.GetComponent<Renderer>();
|
|
|
+ if (rightRenderer != null)
|
|
|
+ {
|
|
|
+ rightRenderer.material = originalMaterial;
|
|
|
+ Debug.Log($"Applied original material to right wall segment");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogWarning($"Right wall segment {rightWall.name} has no Renderer component - cannot apply material");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
walls.Add(rightWall);
|
|
|
-
|
|
|
- Debug.Log($"Created right wall segment: scale {rightWall.transform.localScale} at {rightWall.transform.position}");
|
|
|
+ Debug.Log($"SUCCESS: Created right wall segment: {rightWall.name}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"RIGHT SEGMENT TOO SMALL: {rightSegmentLength} <= 0.5f, not creating");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -1115,57 +1141,88 @@ public class NewRoomBuilder : MonoBehaviour
|
|
|
|
|
|
Debug.Log($"East/West wall split: wallFront={wallFront}, wallBack={wallBack}, entranceFront={entranceFront}, entranceBack={entranceBack}");
|
|
|
|
|
|
- // Create front segment if there's enough space
|
|
|
- if (entranceFront - wallFront > 0.5f)
|
|
|
+ float frontSegmentLength = entranceFront - wallFront;
|
|
|
+ float backSegmentLength = wallBack - entranceBack;
|
|
|
+ Debug.Log($"Segment lengths: front={frontSegmentLength}, back={backSegmentLength}"); // Create front segment if there's enough space
|
|
|
+ if (frontSegmentLength > 0.5f)
|
|
|
{
|
|
|
- float frontLength = entranceFront - wallFront;
|
|
|
- Vector3 frontCenter = new Vector3(wallPos.x, wallPos.y, wallFront + frontLength / 2f);
|
|
|
+ Vector3 frontCenter = new Vector3(wallPos.x, wallPos.y, wallFront + frontSegmentLength / 2f);
|
|
|
|
|
|
+ Debug.Log($"Creating front segment at {frontCenter} with scale ({wallScale.x}, {wallScale.y}, {frontSegmentLength})");
|
|
|
GameObject frontWall = Instantiate(wallPrefab, frontCenter, wallRotation);
|
|
|
frontWall.SetActive(true);
|
|
|
frontWall.name = $"{originalWall.name}_Front_Entrance";
|
|
|
- frontWall.transform.localScale = new Vector3(wallScale.x, wallScale.y, frontLength);
|
|
|
+ frontWall.transform.localScale = new Vector3(wallScale.x, wallScale.y, frontSegmentLength);
|
|
|
frontWall.tag = "Wall";
|
|
|
|
|
|
- // Apply original material if available
|
|
|
+ // Apply original material if available, with error checking
|
|
|
if (originalMaterial != null)
|
|
|
{
|
|
|
- frontWall.GetComponent<Renderer>().material = originalMaterial;
|
|
|
+ Renderer frontRenderer = frontWall.GetComponent<Renderer>();
|
|
|
+ if (frontRenderer != null)
|
|
|
+ {
|
|
|
+ frontRenderer.material = originalMaterial;
|
|
|
+ Debug.Log($"Applied original material to front wall segment");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogWarning($"Front wall segment {frontWall.name} has no Renderer component - cannot apply material");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
walls.Add(frontWall);
|
|
|
-
|
|
|
- Debug.Log($"Created front wall segment: scale {frontWall.transform.localScale} at {frontWall.transform.position}");
|
|
|
+ Debug.Log($"SUCCESS: Created front wall segment: {frontWall.name}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"FRONT SEGMENT TOO SMALL: {frontSegmentLength} <= 0.5f, not creating");
|
|
|
}
|
|
|
|
|
|
// Create back segment if there's enough space
|
|
|
- if (wallBack - entranceBack > 0.5f)
|
|
|
+ if (backSegmentLength > 0.5f)
|
|
|
{
|
|
|
- float backLength = wallBack - entranceBack;
|
|
|
- Vector3 backCenter = new Vector3(wallPos.x, wallPos.y, entranceBack + backLength / 2f);
|
|
|
+ Vector3 backCenter = new Vector3(wallPos.x, wallPos.y, entranceBack + backSegmentLength / 2f);
|
|
|
|
|
|
+ Debug.Log($"Creating back segment at {backCenter} with scale ({wallScale.x}, {wallScale.y}, {backSegmentLength})");
|
|
|
GameObject backWall = Instantiate(wallPrefab, backCenter, wallRotation);
|
|
|
backWall.SetActive(true);
|
|
|
backWall.name = $"{originalWall.name}_Back_Entrance";
|
|
|
- backWall.transform.localScale = new Vector3(wallScale.x, wallScale.y, backLength);
|
|
|
+ backWall.transform.localScale = new Vector3(wallScale.x, wallScale.y, backSegmentLength);
|
|
|
backWall.tag = "Wall";
|
|
|
|
|
|
- // Apply original material if available
|
|
|
+ // Apply original material if available, with error checking
|
|
|
if (originalMaterial != null)
|
|
|
{
|
|
|
- backWall.GetComponent<Renderer>().material = originalMaterial;
|
|
|
+ Renderer backRenderer = backWall.GetComponent<Renderer>();
|
|
|
+ if (backRenderer != null)
|
|
|
+ {
|
|
|
+ backRenderer.material = originalMaterial;
|
|
|
+ Debug.Log($"Applied original material to back wall segment");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.LogWarning($"Back wall segment {backWall.name} has no Renderer component - cannot apply material");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
walls.Add(backWall);
|
|
|
-
|
|
|
- Debug.Log($"Created back wall segment: scale {backWall.transform.localScale} at {backWall.transform.position}");
|
|
|
+ Debug.Log($"SUCCESS: Created back wall segment: {backWall.name}");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Debug.Log($"BACK SEGMENT TOO SMALL: {backSegmentLength} <= 0.5f, not creating");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Remove original wall
|
|
|
+ Debug.Log($"REMOVING ORIGINAL WALL: {originalWall.name} (active: {originalWall.activeInHierarchy})");
|
|
|
walls.Remove(originalWall);
|
|
|
+
|
|
|
+ // Try multiple removal methods to ensure it's gone
|
|
|
+ originalWall.SetActive(false);
|
|
|
DestroyImmediate(originalWall);
|
|
|
- Debug.Log("Removed original wall after splitting for entrance");
|
|
|
+
|
|
|
+ Debug.Log("Original wall removal completed");
|
|
|
}
|
|
|
private GameObject CreateEntrancePrefab()
|
|
|
{
|
|
|
@@ -1528,37 +1585,36 @@ public class NewRoomBuilder : MonoBehaviour
|
|
|
Vector3 wallCenter = wall.transform.position;
|
|
|
Vector3 wallScale = wall.transform.localScale;
|
|
|
|
|
|
- // Determine wall orientation based on scale (not rotation)
|
|
|
- bool isNorthSouthWall = wallScale.x > wallScale.z;
|
|
|
-
|
|
|
+ // Use the wall's actual transform directions instead of world axes
|
|
|
Vector3 wallDirection;
|
|
|
float wallLength;
|
|
|
|
|
|
+ // Determine wall orientation based on scale
|
|
|
+ bool isNorthSouthWall = wallScale.x > wallScale.z;
|
|
|
+
|
|
|
if (isNorthSouthWall)
|
|
|
{
|
|
|
- // Wall extends in X direction (North/South wall)
|
|
|
- wallDirection = Vector3.right;
|
|
|
+ // Wall extends in X direction - use the wall's right vector (local X axis)
|
|
|
+ wallDirection = wall.transform.right;
|
|
|
wallLength = wallScale.x;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- // Wall extends in Z direction (East/West wall)
|
|
|
- wallDirection = Vector3.forward;
|
|
|
+ // Wall extends in Z direction - use the wall's forward vector (local Z axis)
|
|
|
+ wallDirection = wall.transform.forward;
|
|
|
wallLength = wallScale.z;
|
|
|
}
|
|
|
|
|
|
- // Project mouse onto wall line
|
|
|
+ // Project mouse position onto the wall's direction vector
|
|
|
Vector3 toMouse = mousePos - wallCenter;
|
|
|
float projection = Vector3.Dot(toMouse, wallDirection);
|
|
|
|
|
|
// Clamp to wall bounds
|
|
|
- projection = Mathf.Clamp(projection, -wallLength / 2f + doorWidth / 2f, wallLength / 2f - doorWidth / 2f);
|
|
|
+ float clampedProjection = Mathf.Clamp(projection, -wallLength / 2f + doorWidth / 2f, wallLength / 2f - doorWidth / 2f);
|
|
|
|
|
|
- Vector3 doorPos = wallCenter + wallDirection * projection;
|
|
|
+ Vector3 doorPos = wallCenter + wallDirection * clampedProjection;
|
|
|
doorPos.y = 0f; // Set door at ground level
|
|
|
|
|
|
- Debug.Log($"Door position calculation: wallCenter={wallCenter}, wallDirection={wallDirection}, projection={projection}, doorPos={doorPos}");
|
|
|
-
|
|
|
return doorPos;
|
|
|
}
|
|
|
|