Exemplo n.º 1
0
 private void ArrayShuffle(SpawnableBox[] sbxs)
 {
     // Knuth shuffle algorithm :: courtesy of Wikipedia :)
     for (int t = 0; t < sbxs.Length; t++) {
         SpawnableBox tmp = sbxs[t];
         int r = UnityEngine.Random.Range(t, sbxs.Length);
         sbxs[t] = sbxs[r];
         sbxs[r] = tmp;
     }
 }
Exemplo n.º 2
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;
     }
 }
Exemplo n.º 3
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;
     }
 }
Exemplo n.º 4
0
 private void Resetter(SpawnableBox sbx)
 {
     if (sbx.GetFurniture() == gameObject)
         sbx.ReSetFurniture();
     else if (sbx.GetCarpet() == gameObject)
         sbx.ReSetCarpet();
 }
Exemplo n.º 5
0
    private void PlaceInMidRoomVersionTwo(SpawnableBox objToUse)
    {
        if (objToUse != null) {
            Vector3 V = new Vector3();
            V.x = objToUse.transform.position.x;
            //V.y = _myBounds.y - _myBounds.y / 2f;
            V.y = transform.position.y;
            V.z = objToUse.transform.position.z;

            transform.position = V;

            // Randomize y rotation
            // Giving an extra 270 for leverage
            List<int> myValues = new List<int>(new int[] { 0, 90, 180, 270, 270 });
            ListShuffle(myValues);
            IEnumerable<int> oneRandom = myValues.OrderBy(x => _rndO.Next()).Take(1);
            transform.rotation = Quaternion.Euler(0, oneRandom.First(), 0);

            // Allign on Spawning boxes based on bounds and rotation
            Vector3 targetPos = transform.position;
            if (transform.rotation.eulerAngles.y == 0) {
                transform.position = new Vector3(targetPos.x + _myBounds.x, targetPos.y, targetPos.z);
            } else if (transform.rotation.eulerAngles.y == 90) {
                transform.position = new Vector3(targetPos.x, targetPos.y, targetPos.z - _myBounds.z);
            } else if (transform.rotation.eulerAngles.y == 180) {
                transform.position = new Vector3(targetPos.x - _myBounds.x, targetPos.y, targetPos.z);
            } else if (transform.rotation.eulerAngles.y == 270) {
                transform.position = new Vector3(targetPos.x, targetPos.y, targetPos.z + _myBounds.z);
            }
        }
    }
Exemplo n.º 6
0
 private void PlaceLargeWallObj(SpawnableBox objToUse)
 {
     SpawnableBox extraSpotToUse = FindCollidingFreeBoxes(objToUse);
     //Debug.Log(extraSpotToUse.name + " compared with: " + objToUse.name);
     if (extraSpotToUse != objToUse) {
         _swo.RemoveSpot(extraSpotToUse);
         _usedSpotTwo = extraSpotToUse;
         extraSpotToUse.SetWallObject(this);
         _swo.RemoveSpot(objToUse);
         _usedSpotOne = objToUse;
         objToUse.SetWallObject(this);
         AlignOnCorrectWall(objToUse);
         CorrectPositionBasedOnNewSpot(objToUse, extraSpotToUse);
     } else {
         //Debug.LogWarning("1: No space for: " + gameObject.name + " disabling.");
         gameObject.SetActive(false);
     }
 }
Exemplo n.º 7
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;
    }
Exemplo n.º 8
0
 public void RemoveSpot(SpawnableBox box)
 {
     _possibleSpots.Remove(box);
 }
Exemplo n.º 9
0
 public void AddSpot(SpawnableBox box)
 {
     _possibleSpots.Add(box);
 }