Example #1
0
    // Draws a dragable handle in the scene view and detect if it has moved
    private void DrawHandle(GridCheck g, GeneratedObject ge, Color color, int hIndex)
    {
        EditorGUI.BeginChangeCheck();

        // Draw a separate handle to visualize that this object has been selected
        if (objectSelected && hIndex == selectedHandleIndex + 1)
        {
            Handles.color = Color.red;
            Handles.FreeMoveHandle(9999, g.transform.position, Quaternion.identity, 0.55f, Vector3.one, Handles.CircleHandleCap);
        }

        Handles.color = color;                // Se the colour of the actual handle
        startPos      = g.transform.position; // Set the starting position before the handle starts moving

        // Draw the actual handle and save it's position in a variable
        //Vector3 dPos = Handles.FreeMoveHandle(hIndex, g.transform.position, Quaternion.identity, 0.45f, Vector3.one, Handles.CircleHandleCap);
        Vector3 dPos = Handles.FreeMoveHandle(hIndex, g.transform.position, Quaternion.identity, 0.225f, Vector3.one, Handles.DotHandleCap);

        if (dPos != startPos) // Check if this handle has moved and set the scene to dirty if it has,
        {                     // Because even though it's moving a gameobject the scene can't detect a chance so it doesn't save...
            EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
        }

        g.transform.position = dPos;   // Set the new position have to set this twice because of the way obstacles are set up
        dPos = g.GetPosition(lg.grid); // Get the nearest grid position of the set position
        g.transform.position = dPos;   // Set the new position on the grid
        ge.position          = dPos;   // Set the position for the generator to track and save

        EditorGUI.EndChangeCheck();
    }
Example #2
0
    // Spawns selected object in a random position and parents it accordingly
    private GridCheck SpawnObject(GameObject objToSpawn, Transform parent)
    {
        GridCheck gridCheck    = null;
        int       attemptCount = 10;

        while (attemptCount > 0)         // Limit the number of attempts so we don't hang
        {
            GameObject go = PrefabUtility.InstantiatePrefab(objToSpawn) as GameObject;
            if (go != null)
            {
                go.transform.position = lg.RandomPosition;
                go.transform.rotation = Quaternion.identity;

                GridCheck gc = go.GetComponent <GridCheck>();

                go.transform.position = gc.GetPosition(GridManager.Grid);


                if (!gc.CanPlace())                 // Checks if the object can be placed in the specified location, destroys if it can't
                {
                    DestroyImmediate(go);
                    attemptCount--;                     // Minus attempt count so we can break out if the object can't find a position
                    continue;
                }

                gridCheck = gc;
                go.transform.SetParent(parent);
                go.name = objToSpawn.name;
                lg.SpawnedObjectsCount++;
            }
            break;
        }

        return(gridCheck);
    }
Example #3
0
    private bool CheckGrid(Room room)
    {
        GridCheck check      = new GridCheck();
        int       num_floors = check.FloorCount(room.grid);

        if (num_floors < (room.grid.GetLength(0) * room.grid.GetLength(1)) / 4 || !check.ContinuousFloor(room.grid, num_floors))
        {
            return(false);
        }
        return(PlaceDoorways(room));
    }
Example #4
0
    public bool SpawnFire()     // Spawns a fire
    {
        GridCheck gridComp = SpawnObject(lg.obstacleList.Fire, lg.fireParent);

        if (gridComp != null)
        {
            lg.fireGridList.Add(gridComp);
            lg.data.Fires.Add(new GeneratedObject(0, gridComp.transform.position));
            lg.NumFiresToSpawn--;
            return(true);
        }
        return(false);
    }
Example #5
0
    public bool SpawnObstacle(int i)     // Spawns specified obstacle
    {
        GridCheck gridComp = SpawnObject(lg.obstacleList.Obstacles[i], lg.obstacleParent);

        if (gridComp != null)
        {
            lg.obstacleGridList.Add(gridComp);
            lg.data.Obstacles.Add(new GeneratedObject(i, gridComp.transform.position));
            lg.NumObstaclesToSpawn--;
            return(true);
        }
        return(false);
    }
Example #6
0
    [HideInInspector] public bool showStats;          // Show stats for debugging

    // Emergency reset
    public void ClearEverything()
    {
        obstacleGridList = new List <GridCheck>();
        fireGridList     = new List <GridCheck>();
        dogGrid          = null;
        exitGrid         = null;

        SpawnedObjectsCount = 0;
        routineStarted      = false;

        NumObstaclesToSpawn = 10;
        NumFiresToSpawn     = 5;

        data = new GeneratedData();
    }
Example #7
0
    public bool SpawnExit()     // Spawns the exit, deletes any existing exits in the scene
    {
        GridCheck gc = SpawnObject(lg.obstacleList.Exit, lg.genericParent);

        if (gc != null)
        {
            if (lg.exitGrid != null)
            {
                DestroyImmediate(lg.exitGrid.gameObject);
            }

            lg.exitGrid  = gc;
            lg.data.Exit = new GeneratedObject(0, gc.transform.position);
            return(true);
        }
        return(false);
    }