Exemple #1
0
 public void CloseAllUnfinished()
 {
     foreach (Transform door in unfinishedDoors)
     {
         DoorScript ds = door.GetComponent <DoorScript>();
         ds.ClosePermanent();
     }
 }
Exemple #2
0
    public void BuildOnePart()
    {
        if (unfinishedDoors.Count != 0)
        {
            // Find door to expand
            Transform originalDoor = unfinishedDoors[UnityEngine.Random.Range(0, unfinishedDoors.Count)];
            unfinishedDoors.Remove(originalDoor);

            int triesLeft = maxTriesPerPart;
outherWhile:
            while (triesLeft > 0)
            {
                triesLeft--;

                // Spawn the object
                int        partNumber = UnityEngine.Random.Range(0, partList.Count);
                GameObject partPrefab = partList[partNumber];
                GameObject newPart    = Instantiate(partPrefab, new Vector3(0, 0, 0), Quaternion.identity);

                // Match the doors
                List <Transform> newDoors = GetDoors(newPart.transform);

                Transform newDoorToMatch = newDoors[UnityEngine.Random.Range(0, newDoors.Count)];
                newDoors.Remove(newDoorToMatch);

                newPart.transform.rotation = originalDoor.transform.rotation * Quaternion.Inverse(newDoorToMatch.rotation) * Quaternion.Euler(0, 180, 0);
                newPart.transform.position = originalDoor.transform.position - (newDoorToMatch.position - newPart.transform.position);

                // Make it detect detection
                Bounds bounds       = GetMaxBounds(newPart);
                float  boundsMargin = 1f;
                bounds.size = bounds.size - new Vector3(boundsMargin, 0, boundsMargin);

                foreach (Bounds b in dungeonBounds)
                {
                    if (bounds.Intersects(b))
                    {
                        Destroy(newPart);
                        Debug.Log("Bounds has collision adding failled. Part id: " + partNumber);
                        goto outherWhile;
                    }
                }

                dungeonBounds.Add(bounds);
                parts.Add(newPart);

                // Add new doors as unfinished
                foreach (Transform t in newDoors)
                {
                    unfinishedDoors.Add(t);
                }

                break;
            }

            if (triesLeft == 0)
            {
                Debug.Log("Closing door");
                DoorScript ds = originalDoor.GetComponent <DoorScript>();
                ds.ClosePermanent();
            }
        }
        else
        {
            Debug.LogWarning("Now places left to place a part");
        }
    }