// this one is very similar to the rectangular case, expect for one difference
 private static bool PolarIsAdjacent(GFPolarGrid theGrid, Vector3 position, Vector3 reference)
 {
     // note the last condition: if the last and first tile in a circle are adjacent as well, this simulates the wrapping.
     bool isAdjacent = Mathf.Abs(position.x-reference.x) <= 1.25f && (Mathf.Abs(position.y-reference.y) <= 1.25f || Mathf.Abs(position.y-reference.y) > theGrid.sectors - 1.25f);
     bool isDiagonal = 0.25f <= Mathf.Abs(position.x-reference.x) && 0.25f <= Mathf.Abs(position.y-reference.y) && isAdjacent;
     return isAdjacent && !isDiagonal;
 }
Exemple #2
0
    // this one is very similar to the rectangular case, expect for one difference
    private static bool PolarIsAdjacent(GFPolarGrid theGrid, Vector3 position, Vector3 reference)
    {
        // note the last condition: if the last and first tile in a circle are adjacent as well, this simulates the wrapping.
        bool isAdjacent = Mathf.Abs(position.x - reference.x) <= 1.25f && (Mathf.Abs(position.y - reference.y) <= 1.25f || Mathf.Abs(position.y - reference.y) > theGrid.sectors - 1.25f);
        bool isDiagonal = 0.25f <= Mathf.Abs(position.x - reference.x) && 0.25f <= Mathf.Abs(position.y - reference.y) && isAdjacent;

        return(isAdjacent && !isDiagonal);
    }
Exemple #3
0
    void Awake()
    {
        // store the components for later reference
        GFPolarGrid  grid     = GetComponent <GFPolarGrid> ();
        MeshFilter   filter   = GetComponent <MeshFilter> ();
        MeshCollider collider = GetComponent <MeshCollider> ();

        // this is the mesh we will build
        Mesh disc = new Mesh();

        disc.Clear();

        // we need to fill every sector and each sector is made os smaller secors given by the smoothness
        int segments = grid.sectors * grid.smoothness;

        Vector3[] vertices = new Vector3[segments + 2]; // +1 for the origin and +1 too loop around
        vertices [0] = Vector3.zero;                    // the origin
        for (int i = 1; i <= segments; i++)
        {
            //the world points around the grid in local space
            vertices [i] = transform.InverseTransformPoint(grid.GridToWorld(new Vector3(grid.size.x / grid.radius, 0, (float)i / (float)grid.smoothness)));
        }
        vertices[segments + 1] = vertices[1];    // loop around after one full circle
        disc.vertices          = vertices;       // assign the vertices

        int[] triangles = new int[segments * 3]; // the amount of triangles times three
        int   counter   = 0;

        for (int i = 1; i <= segments; i++)  // assign the triangels in a clockwise rotation
        {
            triangles [counter]     = 0;     //origin
            triangles [counter + 1] = i + 1; // upper
            triangles [counter + 2] = i;     // lower
            counter += 3;                    // increment the counter for the next three vertices
        }
        disc.triangles = triangles;          // assign the triangles

        // add some dummy UVs to keep the shader happy or else it complains, but they are not used in this example
        Vector2[] uvs = new Vector2[vertices.Length];
        for (int k = 0; k < uvs.Length; k++)
        {
            uvs[k] = new Vector2(vertices[k].x, vertices[k].y);
        }
        disc.uv = uvs;

        // the usual cleanup
        disc.RecalculateNormals();
        disc.RecalculateBounds();
        disc.Optimize();

        // assign the mesh
        filter.sharedMesh   = disc;
        collider.sharedMesh = disc;
    }
	private Transform _transform; // we will do quite a lot of loops, so cache this
	
	public void Awake () {
		// cache components
		grid = GetComponent<GFPolarGrid>();
		_transform = transform;
		layers = Mathf.FloorToInt(grid.size.x / grid.radius);
		
		for (int i = 0; i < layers; i++) { // loop throught the layers
			for (int j = 0; j < grid.sectors; j++) { // loop through the sectorsof each layer
				GameObject go = BuildObject(i, j); // create the object at the current cell's centre
				SetComponents(go, i, j); // Set up its components
			}
		}
	}
    public void Awake()
    {
        // get components
        grid = GetComponent<GFPolarGrid>();
        layers = Mathf.FloorToInt(grid.size.x / grid.radius);

        for (int layer = 0; layer < layers; layer++) { // loop throught the layers
            for (int sector = 0; sector < grid.sectors; sector++) { // loop through the sectorsof each layer
                GameObject go = BuildObject(layer, sector); // create the object at the current cell's centre
                SetComponents(go, layer, sector); // Set up its components
            }
        }
    }
    public void Awake()
    {
        // get components
        grid   = GetComponent <GFPolarGrid>();
        layers = Mathf.FloorToInt(grid.size.x / grid.radius);

        for (int layer = 0; layer < layers; layer++)              // loop throught the layers
        {
            for (int sector = 0; sector < grid.sectors; sector++) // loop through the sectorsof each layer
            {
                GameObject go = BuildObject(layer, sector);       // create the object at the current cell's centre
                SetComponents(go, layer, sector);                 // Set up its components
            }
        }
    }
    private Transform _transform; // we will do quite a lot of loops, so cache this

    public void Awake()
    {
        // cache components
        grid       = GetComponent <GFPolarGrid>();
        _transform = transform;
        layers     = Mathf.FloorToInt(grid.size.x / grid.radius);

        for (int i = 0; i < layers; i++)           // loop throught the layers
        {
            for (int j = 0; j < grid.sectors; j++) // loop through the sectorsof each layer
            {
                GameObject go = BuildObject(i, j); // create the object at the current cell's centre
                SetComponents(go, i, j);           // Set up its components
            }
        }
    }
	void Awake () {
		// store the components for later reference
		grid = GetComponent<GFPolarGrid> ();
		MeshFilter filter = GetComponent<MeshFilter> ();
		MeshCollider collider = GetComponent<MeshCollider> ();

		// this is the mesh we will build
		Mesh disc = new Mesh ();
		disc.Clear();

		// we need to fill every sector and each sector is made os smaller secors given by the smoothness
		int segments = grid.sectors * grid.smoothness;
		Vector3[] vertices = new Vector3[segments + 2]; // +1 for the origin and +1 too loop around
		vertices [0] = Vector3.zero; // the origin
		for (int i = 1; i <= segments; i++) {
			//the world points around the grid in local space
			vertices [i] = AssignVertex(i);
		}
		vertices[segments + 1] = vertices[1]; // loop around after one full circle
		disc.vertices = vertices; // assign the vertices

		int[] triangles = new int[segments * 3]; // the amount of triangles times three
		int counter = 0;
		for (int i = 1; i <= segments; i++) { // assign the triangels in a clockwise rotation
			triangles [counter] = 0; //origin
			triangles [counter + 1] = i + 1; // upper
			triangles [counter + 2] = i; // lower
			counter += 3; // increment the counter for the next three vertices
		}
		disc.triangles = triangles; // assign the triangles

		// add some dummy UVs to keep the shader happy or else it complains, but they are not used in this example
		Vector2[] uvs = new Vector2[vertices.Length];
		for (int k = 0; k < uvs.Length; k++) {
			uvs[k] = new Vector2(vertices[k].x, vertices[k].y);
		}
		disc.uv = uvs;

		// the usual cleanup
		disc.RecalculateNormals();
		disc.RecalculateBounds();
		disc.Optimize();

		// assign the mesh
		filter.sharedMesh = disc;
		collider.sharedMesh = disc;
	}
 void AlignRotateTransforms(GFPolarGrid pGrid, List <Transform> allTransforms)
 {
     foreach (Transform curTransform in allTransforms)
     {
         if (!(ignoreRootObjects && curTransform.parent == null && curTransform.childCount > 0) && (affectedLayers.value & 1 << curTransform.gameObject.layer) != 0)
         {
             pGrid.AlignRotateTransform(curTransform, lockAxes);
             if (inculdeChildren)
             {
                 foreach (Transform child in curTransform)
                 {
                     pGrid.AlignRotateTransform(child, lockAxes);
                 }
             }
         }
     }
 }
    private void RemoveAlignedRotated(ref List <Transform> transformList, GFPolarGrid pGrid)
    {
        //we'll keep a counter for the amount of objects in the list to avoid calling transformList.Count each iteration
        int counter = transformList.Count;

        for (int i = 0; i <= counter - 1; i++)
        {
            if (AlreadyAlignedRotated(transformList[i], pGrid))
            {
                transformList.RemoveAt(i);
                i--;                  //reduce the indexer because we removed an entry from list
                counter--;            //reduce the counter since the list has become smaller
            }
        }

        transformList.Remove(grid.transform);
    }
 void AlignRotateSomething(GFPolarGrid pGrid, List <Transform> allTransforms, string name)
 {
     RemoveAlignedRotated(ref allTransforms, pGrid);
     if (allTransforms.Count == 0)
     {
         return;
     }
             #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
     Undo.RegisterSceneUndo(name);
             #else
     Undo.RecordObjects(allTransforms.ToArray(), name);
             #endif
     AlignRotateTransforms(pGrid, allTransforms);
     foreach (Transform t in allTransforms)
     {
         EditorUtility.SetDirty(t);
     }
 }
Exemple #12
0
 void Awake()
 {
     grid = GetComponent<GFPolarGrid> ();
     mc = GetComponent<MeshCollider> ();
     _transform = transform;
 }
 void AlignRotateTransforms(GFPolarGrid pGrid, List<Transform> allTransforms)
 {
     foreach(Transform curTransform in allTransforms){
         if(!(ignoreRootObjects && curTransform.parent == null && curTransform.childCount > 0) && (affectedLayers.value & 1<<curTransform.gameObject.layer) != 0){
             pGrid.AlignRotateTransform(curTransform, lockAxes);
             if(inculdeChildren){
                 foreach(Transform child in curTransform){
                     pGrid.AlignRotateTransform(child, lockAxes);
                 }
             }
         }
     }
 }
 void RotateTransform(GFPolarGrid pGrid, Transform theTransform)
 {
     theTransform.rotation = pGrid.World2Rotation(theTransform.position);
 }
Exemple #15
0
 void Awake()
 {
     grid       = GetComponent <GFPolarGrid> ();
     mc         = GetComponent <MeshCollider> ();
     _transform = transform;
 }
    private void RemoveAlignedRotated(ref List<Transform> transformList, GFPolarGrid pGrid)
    {
        //we'll keep a counter for the amount of objects in the list to avoid calling transformList.Count each iteration
        int counter = transformList.Count;
        for(int i = 0; i <= counter - 1; i++){
            if(AlreadyAlignedRotated(transformList[i], pGrid)){
                transformList.RemoveAt(i);
                i --; //reduce the indexer because we removed an entry from list
                counter --; //reduce the counter since the list has become smaller
            }
        }

        transformList.Remove(grid.transform);
    }
 void RotateTransform(GFPolarGrid  pGrid, Transform theTransform)
 {
     theTransform.rotation = pGrid.World2Rotation (theTransform.position);
 }
 private bool AlreadyAlignedRotated(Transform trans, GFPolarGrid pGrid)
 {
     return AlreadyAligned(trans) && AlreadyRotated(trans, pGrid);
 }
 bool AlreadyRotated(Transform trans, GFPolarGrid pGrid)
 {
     return Quaternion.Angle (trans.rotation, pGrid.World2Rotation (trans.position)) < 0.1;
 }
 void AlignRotateSomething(GFPolarGrid pGrid, List<Transform> allTransforms, string name)
 {
     RemoveAlignedRotated(ref allTransforms, pGrid);
     if(allTransforms.Count == 0)
         return;
     #if UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
     Undo.RegisterSceneUndo(name);
     #else
     Undo.RecordObjects (allTransforms.ToArray (), name);
     #endif
     AlignRotateTransforms (pGrid, allTransforms);
     foreach (Transform t in allTransforms)
         EditorUtility.SetDirty (t);
 }
 void AlignRotateSelected(GFPolarGrid pGrid)
 {
     AlignRotateSomething(pGrid, new List <Transform>((Transform[])Selection.transforms), "Align & Rotate Selected");
 }
 void AlignRotateSelected(GFPolarGrid pGrid)
 {
     AlignRotateSomething (pGrid, new List<Transform>((Transform[])Selection.transforms), "Align & Rotate Selected");
 }
 void AlignRotateScene(GFPolarGrid pGrid)
 {
     AlignRotateSomething (pGrid, new List<Transform>((Transform[])Transform.FindObjectsOfType(typeof(Transform))), "Align & Rotate Scene");
 }
 void AlignRotateScene(GFPolarGrid pGrid)
 {
     AlignRotateSomething(pGrid, new List <Transform>((Transform[])Transform.FindObjectsOfType(typeof(Transform))), "Align & Rotate Scene");
 }
 private bool AlreadyAlignedRotated(Transform trans, GFPolarGrid pGrid)
 {
     return(AlreadyAligned(trans) && AlreadyRotated(trans, pGrid));
 }
 bool AlreadyRotated(Transform trans, GFPolarGrid pGrid)
 {
     return(Quaternion.Angle(trans.rotation, pGrid.World2Rotation(trans.position)) < 0.1);
 }