Ejemplo n.º 1
0
    private void Awake()
    {
        grid = GridManager.Instance.Grid;

        grid.AlignTransform(transform);
        oldPosition = transform.position;
        Personality p = this.transform.GetComponent <Personality>();

        if (p != null)
        {
            p.Happy += () => {
                lastTile.MoodTile(happyTile);
            };
            p.Sad += () => {
                lastTile.MoodTile(sadTile);
            };
            p.Scared += () => {
                lastTile.MoodTile(scaredTile);
            };
            p.Angry += () => {
                lastTile.MoodTile(angryTile);
            };
        }
        SetupRigidbody();
    }
Ejemplo n.º 2
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
                Vector3 targetPosition = levelGrid.GridToWorld(new Vector3(i + shift, -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++;
        }
    }
Ejemplo n.º 3
0
 public static void AddGrid(GFGrid grid)
 {
     if (!gridList.Contains(grid))
     {
         gridList.Add(grid);
     }
 }
Ejemplo n.º 4
0
 public static void RemoveGrid(GFGrid grid)
 {
     if (gridList.Contains(grid))
     {
         gridList.Remove(grid);
     }
 }
Ejemplo n.º 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);
	}
Ejemplo n.º 6
0
    public static Vector3 GridToWorldFixed(this GFGrid grid, Vector3 gridPosition)
    {
        Vector3 worldPosition = grid.GridToWorld(gridPosition);
        Vector3 fixedPosition = new Vector3(worldPosition.x * 0.75f, worldPosition.y * 1.15f, worldPosition.z);

        return(fixedPosition);
    }
Ejemplo n.º 7
0
    public static Vector3 WorldToGridFixed(this GFGrid grid, Vector3 worldPosition)
    {
        Vector3 fixedPosition = new Vector3(worldPosition.x * 1.25f, worldPosition.y * 0.85f, worldPosition.z);
        Vector3 gridPosition  = grid.WorldToGrid(fixedPosition);

        return(gridPosition);
    }
Ejemplo n.º 8
0
 public void Awake()
 {
     characterPlaceholder = GameObject.FindGameObjectWithTag("Placeholder").transform;
     grid       = GridManager.Instance.Grid;
     characters = new List <Personality>();
     movements  = new List <Movement>();
 }
Ejemplo n.º 9
0
 void OnEnable()
 {
     _grid = target as GFGrid;
     //_showDrawSettings = EditorPrefs.HasKey("GFGridShowDraw") ? EditorPrefs.GetBool("GFGridShowDraw") : true;
     _showDrawSettings = !EditorPrefs.HasKey("GFGridShowDraw") || EditorPrefs.GetBool("GFGridShowDraw");
     //_showOffsets = EditorPrefs.HasKey ("GFGridShowOffset") ? EditorPrefs.GetBool ("GFGridShowOffset") : false;
     _showOffsets = EditorPrefs.HasKey("GFGridShowOffset") && EditorPrefs.GetBool("GFGridShowOffset");
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
0
 /// <summary></summary>
 /// <param name="theSwitch">Position of the switch that was pressed.</param>
 /// <param name="referenceGrid">Grid we use for gameplay.</param>
 /// This function broadcasts a signal (an event) once a switch has been hit.
 /// Static means we don't need to use any specific instance of this function.
 public static void SendSignal(Vector3 theSwitch, GFGrid referenceGrid)
 {
     //always make sure there a subscribers to the event, or you get errors
     if (OnHitSwitch != null)
     {
         OnHitSwitch(theSwitch, referenceGrid);
     }
 }
Ejemplo n.º 12
0
    // makes the object snap to the bottom of the grid, respecting the grid's rotation
    public static Vector3 CalculateOffsetY(GFGrid grid, Transform targetTrans)
    {
        //first store the objects position in grid coordinates
        Vector3 gridPosition = grid.WorldToGrid(targetTrans.position);

        //then change only the Y coordinate
        gridPosition.y = 0.5f * targetTrans.lossyScale.y;
        //convert the result back to world coordinates
        return(grid.GridToWorld(gridPosition));
    }
Ejemplo n.º 13
0
	//this function gets called upon the event "onHitSwitch" (switchPosition is in grid coordinates)
	void OnHitSwitch (Vector3 switchPosition, GFGrid theGrid){
		//don't do anything if this light doesn't belong to the grid we use
		if(theGrid != connectedGrid)
			return;
		
		//check if this light is adjacent to the switch; this is an extenion method that always picks
		//the method that belongs to the specific grid type. The implementation is in another file
		if(theGrid.IsAdjacent(cachedTransform.position, switchPosition)){
			//flip the state of this switch
			isOn = !isOn;
		}
		//change the lights (won't do anything if the state hasn't changed)
		SwitchLights();
	}
Ejemplo n.º 14
0
    void OnGUI()
    {
        grid = (GFGrid)EditorGUILayout.ObjectField("Grid:", grid, typeof(GFGrid), true);
        if (GUI.changed && grid)
        {
            if (grid)
            {
                gridTransform = grid.transform;
            }
            else
            {
                gridTransform = null;
            }
        }
        ignoreRootObjects = EditorGUILayout.Toggle("Ignore Root Objects", ignoreRootObjects);
        affectedLayers    = LayerMaskField("Affected Layers", affectedLayers);

        inculdeChildren = EditorGUILayout.Toggle("Include Children", inculdeChildren);

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Align Scene"))
        {
            AlignScene();
        }
        if (GUILayout.Button("Align Selected"))
        {
            AlignSelected();
        }
        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Scale Scene"))
        {
            ScaleScene();
        }
        if (GUILayout.Button("Scale Selected"))
        {
            ScalenSelected();
        }
        EditorGUILayout.EndHorizontal();

        autoSnapping = EditorGUILayout.Toggle("Auto-Snapping", autoSnapping);

        GUILayout.Label("Lock axes for Aligning");
        ++EditorGUI.indentLevel;
        lockAxes[0] = EditorGUILayout.Toggle("X", lockAxes[0]);
        lockAxes[1] = EditorGUILayout.Toggle("Y", lockAxes[1]);
        lockAxes[2] = EditorGUILayout.Toggle("Z", lockAxes[2]);
    }
Ejemplo n.º 15
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
        // 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);
    }
Ejemplo n.º 16
0
    //this function gets called upon the event "onHitSwitch" (switchPosition is in grid coordinates)
    void OnHitSwitch(Vector3 switchPosition, GFGrid theGrid)
    {
        //don't do anything if this light doesn't belong to the grid we use
        if (theGrid != connectedGrid)
        {
            return;
        }

        //check if this light is adjacent to the switch; this is an extenion method that always picks
        //the method that belongs to the specific grid type. The implementation is in another file
        if (theGrid.IsAdjacent(cachedTransform.position, switchPosition))
        {
            //flip the state of this switch
            isOn = !isOn;
        }
        //change the lights (won't do anything if the state hasn't changed)
        SwitchLights();
    }
Ejemplo n.º 17
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
        // 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);
    }
Ejemplo n.º 18
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++;
        }
    }
Ejemplo n.º 19
0
    /// <summary>Spawns blocks based on a text file and a grid.</summary>
    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 column = 0; column < line.Length; column++)
            {
                Vector3 targetPosition = levelGrid.GridToWorld(new Vector3(column, -row, 0) + offset);
                CreateBlock(line[column], targetPosition);
            }
            //we read a row, now it's time to read the next one; increment the counter
            row++;
        }
    }
Ejemplo n.º 20
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);
        }
    }
Ejemplo n.º 21
0
 //this function broadcasts a signal (an event) once a switch has been hit.
 //Static means I don't need to use any specific instance of this function.
 public static void SendSignal(Vector3 theSwitch, GFGrid referenceGrid)
 {
     //always make sure there a subscribers to the even, or you get errors
     if(onHitSwitch != null)
         onHitSwitch(theSwitch, referenceGrid);
 }
Ejemplo n.º 22
0
	void Awake()
	{
		grid = GameObject.FindGameObjectWithTag ("Grid").GetComponent<GFGrid> ();
		gridCollider = grid.GetComponent<Collider> ();
	}
Ejemplo n.º 23
0
    private GFGrid grid;              // the grid component

    void Awake()                      // store components for later reference
    {
        col  = GetComponent <Collider>();
        grid = GetComponent <GFGrid> ();
    }
Ejemplo n.º 24
0
 void GridField()
 {
     grid = (GFGrid) EditorGUILayout.ObjectField("Grid:", grid, typeof(GFGrid), true);
 }
Ejemplo n.º 25
0
 public static void AlignTransformFixed(this GFGrid grid, Transform transform)
 {
     grid.AlignTransform(transform);
     transform.position = new Vector3(transform.position.x * 0.75f, transform.position.y * 1.15f, transform.position.z);
 }
Ejemplo n.º 26
0
	private GFGrid grid; // the grid component

	void Awake () { // store components for later reference
		col = collider;
		grid = GetComponent<GFGrid> ();
	}
Ejemplo n.º 27
0
 public void Awake()
 {
     grid = GridManager.Instance.Grid;
 }
Ejemplo n.º 28
0
	private Transform cachedTransform; //cache the transform for performance

	void Awake()
	{
		cachedTransform = this.transform;
		grid = GameObject.FindGameObjectWithTag ("Grid").GetComponent<GFGrid> ();
		gridCollider = grid.GetComponent<Collider> ();
	}
Ejemplo n.º 29
0
 void GridField()
 {
     grid = (GFGrid)EditorGUILayout.ObjectField("Grid:", grid, typeof(GFGrid), true);
 }
Ejemplo n.º 30
0
 public static void RemoveGrid(GFGrid grid)
 {
     if(gridList.Contains(grid))
         gridList.Remove(grid);
 }
Ejemplo n.º 31
0
 public static void AddGrid(GFGrid grid)
 {
     if(!gridList.Contains(grid))
         gridList.Add(grid);
 }
Ejemplo n.º 32
0
 public TransformCache(GFGrid grid)
 {
     _gridTransform = grid._transform;
     Recache();
 }
Ejemplo n.º 33
0
    void OnGUI()
    {
        grid = (GFGrid) EditorGUILayout.ObjectField("Grid:", grid, typeof(GFGrid), true);
        if(GUI.changed && grid){
            if(grid){
                gridTransform = grid.transform;
            } else{
                gridTransform = null;
            }
        }
        ignoreRootObjects = EditorGUILayout.Toggle("Ignore Root Objects", ignoreRootObjects);
        affectedLayers = LayerMaskField("Affected Layers", affectedLayers);

        inculdeChildren = EditorGUILayout.Toggle("Include Children", inculdeChildren);

        EditorGUILayout.BeginHorizontal();
        if(GUILayout.Button("Align Scene")){
            AlignScene();
        }
        if(GUILayout.Button("Align Selected")){
            AlignSelected();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if(GUILayout.Button("Scale Scene")){
            ScaleScene();
        }
        if(GUILayout.Button("Scale Selected")){
            ScalenSelected();
        }
        EditorGUILayout.EndHorizontal();

        autoSnapping = EditorGUILayout.Toggle("Auto-Snapping", autoSnapping);

        GUILayout.Label("Lock axes for Aligning");
        ++EditorGUI.indentLevel;
        lockAxes[0] = EditorGUILayout.Toggle("X", lockAxes[0]);
        lockAxes[1] = EditorGUILayout.Toggle("Y", lockAxes[1]);
        lockAxes[2] = EditorGUILayout.Toggle("Z", lockAxes[2]);
    }
Ejemplo n.º 34
0
 public TransformCache(GFGrid grid)
 {
     _gridTransform = grid._transform;
     Recache();
 }
Ejemplo n.º 35
0
 void OnEnable()
 {
     _grid = target as GFGrid;
     //_showDrawSettings = EditorPrefs.HasKey("GFGridShowDraw") ? EditorPrefs.GetBool("GFGridShowDraw") : true;
     _showDrawSettings = !EditorPrefs.HasKey("GFGridShowDraw") || EditorPrefs.GetBool("GFGridShowDraw");
     //_showOffsets = EditorPrefs.HasKey ("GFGridShowOffset") ? EditorPrefs.GetBool ("GFGridShowOffset") : false;
     _showOffsets = EditorPrefs.HasKey ("GFGridShowOffset") && EditorPrefs.GetBool ("GFGridShowOffset");
 }
Ejemplo n.º 36
0
	protected static string docsDir = "file://" + Application.dataPath + "/WebPlayerTemplates/GridFrameworkHTMLDocs/html/"; //directory of doc files

	#region enable <-> disable
	void OnEnable () {
		grid = target as GFGrid;
		showDrawSettings = EditorPrefs.HasKey("GFGridShowDraw") ? EditorPrefs.GetBool("GFGridShowDraw") : true;
		showOffsets = EditorPrefs.HasKey ("GFGridShowOffset") ? EditorPrefs.GetBool ("GFGridShowOffset") : false;
	}
Ejemplo n.º 37
0
 // Use this for initialization
 void Start()
 {
     grid = GameObject.Find ("Grid").GetComponent<GFGrid>();
 }
Ejemplo n.º 38
0
    protected static string docsDir = "file://" + Application.dataPath + "/WebPlayerTemplates/GridFrameworkHTMLDocs/html/";     //directory of doc files

    #region enable <-> disable
    void OnEnable()
    {
        grid             = target as GFGrid;
        showDrawSettings = EditorPrefs.HasKey("GFGridShowDraw") ? EditorPrefs.GetBool("GFGridShowDraw") : true;
        showOffsets      = EditorPrefs.HasKey("GFGridShowOffset") ? EditorPrefs.GetBool("GFGridShowOffset") : false;
    }