void AutoRotateFlag()
 {
     if (grid.GetType() != typeof(GFPolarGrid))
     {
         return;
     }
     autoRotating = EditorGUILayout.Toggle("Auto-Rotating", autoRotating);
 }
    public void Awake()
    {
        levelGrid = GetComponent<GFGrid>();
        blocks = new List<GameObject>();

        // if and how much we need to shift the objects depends on the type of grid
        // This just just a matter of different grid coordinate systems. Try playing
        // with the numbers to see the difference.
        offset = Vector3.zero;
        // offset by 0.5 horizontal and vertical in rectangular grids
        if (levelGrid.GetType() == typeof(GFRectGrid) ) { offset.x += 0.5f; offset.y -= 0.5f; }
        // Add 1 for polar grids because we don't want the origin
        if (levelGrid.GetType() == typeof(GFPolarGrid)) { offset.x += 1; }

        BuildLevel(levelData[currentLevel], levelGrid);
    }
	public void BuildLevel(TextAsset levelData, GFGrid levelGrid){
		//abort if there are no prefabs to instantiate
		if(!red || !green || !blue)
			return;
		
		//loop though the list of old blocks and destroy all of them, we don't want the new level on top of the old one
		foreach(GameObject go in blocks){
			if(go)
				Destroy(go);
		}
		//destroying the blocks doesn't remove the reference to them in the list, so clear the list
		blocks.Clear();
		
		//setup the reader, a variable for storing the read line and keep track of the number of the row we just read
		reader = new StringReader(levelData.text);
		string line;
		int row = 0;
		
		//read the text file line by line as long as there are lines
		while((line = reader.ReadLine()) != null){
			//read each line character by character
			for(int i = 0; i < line.Length; i++){
				//first set the target position based on where in the text file we are, then place a block there (add 1 for polar grids because we don't want the origin)
				Vector3 targetPosition = levelGrid.GridToWorld(new Vector3(i + shift + (levelGrid.GetType() == typeof(GFPolarGrid) ? 1 : 0), -row - shift, 0)); //offset by 0.5
				CreateBlock(line[i], targetPosition);
			}
			//we read a row, now it's time to read the next one; increment the counter
			row++;
		}
	}
	public void Awake(){
		levelGrid = GetComponent<GFGrid>();
		blocks = new List<GameObject>();
		// if and how much we need to shift the objects depends on the type of grid
		shift = levelGrid.GetType() == typeof(GFRectGrid) ? 0.5f : 0;
		BuildLevel(levelData[currentLevel], levelGrid);
	}
Exemple #5
0
 public void Awake()
 {
     levelGrid = GetComponent <GFGrid>();
     blocks    = new List <GameObject>();
     // if and how much we need to shift the objects depends on the type of grid
     shift = levelGrid.GetType() == typeof(GFRectGrid) ? 0.5f : 0;
     BuildLevel(levelData[currentLevel], levelGrid);
 }
    public void Awake()
    {
        levelGrid = GetComponent <GFGrid>();
        blocks    = new List <GameObject>();

        // if and how much we need to shift the objects depends on the type of grid
        // This just just a matter of different grid coordinate systems. Try playing
        // with the numbers to see the difference.
        offset = Vector3.zero;
        // offset by 0.5 horizontal and vertical in rectangular grids
        if (levelGrid.GetType() == typeof(GFRectGrid))
        {
            offset.x += 0.5f; offset.y -= 0.5f;
        }
        // Add 1 for polar grids because we don't want the origin
        if (levelGrid.GetType() == typeof(GFPolarGrid))
        {
            offset.x += 1;
        }

        BuildLevel(levelData[currentLevel], levelGrid);
    }
Exemple #7
0
    public static bool IsAdjacent(this GFGrid theGrid, Vector3 position, Vector3 reference)
    {
        //convert to Grid Space first
        Vector3 gridPosition  = theGrid.WorldToGrid(position);       //the light we want to test
        Vector3 gridReference = theGrid.WorldToGrid(reference);      //the light that was pressed

        //pick the implentation based on the type of grid
        if (theGrid.GetType() == typeof(GFRectGrid))
        {
            return(RectIsAdjacent((GFRectGrid)theGrid, gridPosition, gridReference));
        }
        else if (theGrid.GetType() == typeof(GFHexGrid))
        {
            return(HexIsAdjacent((GFHexGrid)theGrid, gridPosition, gridReference));
        }
        else if (theGrid.GetType() == typeof(GFPolarGrid))
        {
            return(PolarIsAdjacent((GFPolarGrid)theGrid, gridPosition, gridReference));
        }
        else
        {
            return(false);
        }
    }
Exemple #8
0
    public void BuildLevel(TextAsset levelData, GFGrid levelGrid)
    {
        //abort if there are no prefabs to instantiate
        if (!red || !green || !blue)
        {
            return;
        }

        //loop though the list of old blocks and destroy all of them, we don't want the new level on top of the old one
        foreach (GameObject go in blocks)
        {
            if (go)
            {
                Destroy(go);
            }
        }
        //destroying the blocks doesn't remove the reference to them in the list, so clear the list
        blocks.Clear();

        //setup the reader, a variable for storing the read line and keep track of the number of the row we just read
        reader = new StringReader(levelData.text);
        string line;
        int    row = 0;

        //read the text file line by line as long as there are lines
        while ((line = reader.ReadLine()) != null)
        {
            //read each line character by character
            for (int i = 0; i < line.Length; i++)
            {
                //first set the target position based on where in the text file we are, then place a block there (add 1 for polar grids because we don't want the origin)
                Vector3 targetPosition = levelGrid.GridToWorld(new Vector3(i + shift + (levelGrid.GetType() == typeof(GFPolarGrid) ? 1 : 0), -row - shift, 0));                 //offset by 0.5
                CreateBlock(line[i], targetPosition);
            }
            //we read a row, now it's time to read the next one; increment the counter
            row++;
        }
    }