Esempio n. 1
0
 private void AlignOnCorrectWall(SpawnableBox objToUse)
 {
     SpawnableBox.BoxLocation loc = objToUse.GetBoxLocation();
     switch (loc) {
         case SpawnableBox.BoxLocation.North:
             transform.position = new Vector3(objToUse.transform.position.x, transform.position.y, objToUse.transform.position.z + 0.49f); // +/- the amount to reach the wall surface
             transform.rotation = Quaternion.Euler(0, 0, 0);
             break;
         case SpawnableBox.BoxLocation.East:
             transform.position = new Vector3(objToUse.transform.position.x + 0.49f, transform.position.y, objToUse.transform.position.z);
             transform.rotation = Quaternion.Euler(0, 90, 0);
             break;
         case SpawnableBox.BoxLocation.South:
             transform.position = new Vector3(objToUse.transform.position.x, transform.position.y, objToUse.transform.position.z - 0.49f);
             transform.rotation = Quaternion.Euler(0, 180, 0);
             break;
         case SpawnableBox.BoxLocation.West:
             transform.position = new Vector3(objToUse.transform.position.x - 0.49f, transform.position.y, objToUse.transform.position.z);
             transform.rotation = Quaternion.Euler(0, 270, 0);
             break;
     }
 }
Esempio n. 2
0
 private void CorrectPositionBasedOnNewSpot(SpawnableBox objToUse, SpawnableBox extraSpotToUse)
 {
     Vector3 placedPos = objToUse.transform.position;
     Vector3 targetPos = extraSpotToUse.transform.position;
     float offset = 0.5f;
     SpawnableBox.BoxLocation loc = objToUse.GetBoxLocation();
     switch (loc) {
         case SpawnableBox.BoxLocation.North:
             //Debug.Log("North: " + gameObject.name + " initial pos: " + transform.position);
             if (targetPos.x > placedPos.x)
                 transform.position = new Vector3(transform.position.x + offset, transform.position.y, transform.position.z);
             else if (targetPos.x < placedPos.x)
                 transform.position = new Vector3(transform.position.x - offset, transform.position.y, transform.position.z);
             break;
         case SpawnableBox.BoxLocation.East:
             //Debug.Log("East: " + gameObject.name + " initial pos: " + transform.position);
             if (targetPos.z > placedPos.z)
                 transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + offset);
             else if (targetPos.z < placedPos.z)
                 transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - offset);
             break;
         case SpawnableBox.BoxLocation.South:
             //Debug.Log("South: " + gameObject.name + " initial pos: " + transform.position);
             if (targetPos.x > placedPos.x)
                 transform.position = new Vector3(transform.position.x + offset, transform.position.y, transform.position.z);
             else if (targetPos.x < placedPos.x)
                 transform.position = new Vector3(transform.position.x - offset, transform.position.y, transform.position.z);
             break;
         case SpawnableBox.BoxLocation.West:
             Debug.LogWarning("West wall too occupied for large painting. Error in correcting placement for: " + gameObject.name);
             break;
         default:
             Debug.LogWarning("Error in correcting placement for: " + gameObject.name);
             break;
     }
 }
Esempio n. 3
0
    private SpawnableBox FindCollidingFreeBoxes(SpawnableBox box)
    {
        // First check all colliding spawnedBoxes for neighbors
        Collider[] _colliders = Physics.OverlapSphere(box.transform.position, box.GetComponent<Collider>().bounds.size.x);
        //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        //sphere.transform.position = box.transform.position;
        //sphere.transform.localScale = new Vector3(box.GetComponent<Collider>().bounds.size.x, box.GetComponent<Collider>().bounds.size.y, box.GetComponent<Collider>().bounds.size.z);
        // If we found some
        if (_colliders.Length > 2) {
            foreach (var obj in _colliders) {
                SpawnableBox sbx = obj.GetComponent<SpawnableBox>();
                if (sbx) {
                    //Debug.Log(box.name + " collides with: " + sbx.name);
                    if (sbx.name != box.name && sbx.GetBoxLocation() == box.GetBoxLocation() && sbx.GetWallObject() == null
                            && sbx.GetBoxCondition() != SpawnableBox.BoxCondition.Occupied && sbx.GetBoxCondition() != SpawnableBox.BoxCondition.Tall) {
                        //Debug.Log(box.name + " found possible placement: " + sbx.name);
                        return sbx; // return 1 spots only everytime
                    }
                }
            }
        }

        return box;
    }