private int CalculateGridOrder() { List <IsoGrid> grids = new List <IsoGrid>(FindObjectsOfType <IsoGrid>()); List <IsoGrid> ordered = new List <IsoGrid>(); // Get the closest to the camera while (grids.Count > 0) { IsoGrid closest = grids[0]; //grids.Remove(closest); foreach (IsoGrid g in grids) { if ((Camera.main.transform.position - g.transform.position).magnitude > (Camera.main.transform.position - closest.transform.position).magnitude) { closest = g; } } grids.Remove(closest); ordered.Add(closest); } for (int i = 0; i < ordered.Count; i++) { if (ordered[i] == this) { return(i); } } return(-1); }
// This supports non-rectangular data, because the X and Z "grid coordinates" are stored in the payload itself private void AssignElements(IEnumerable <MutableObject> mutables) { foreach (var element in mutables) { IsoGrid.AddEntry(XAxis.GetLastKeyValue(element), ZAxis.GetLastKeyValue(element), element); } }
public IsoPathfinder(IsoGrid world) { World = world; First = new Point (-1, -1); Last = new Point (-1, -1); Path = new List<Point> (); }
protected override IEnumerator ProcessPayload(VisualPayload payload) { Debug.LogWarning("[BOUND DEBUG] IsoGrid rendering to bound.", payload.VisualData.Bound); IsoGrid = VisualizerFactory.InstantiateIsoGrid(); IsoGrid.Initialize(this, payload); //payload.VisualData.Bound.ChildVisualizer(this, IsoGrid); IsoGrid.DrawBackgrounds = ShowBackgrounds.GetLastKeyValue(payload.Data); IsoGrid.InitializeIsoGrid(payload.VisualData.Bound); IsoGrid.AllowSlicer = AllowSlicerField.GetLastKeyValue(payload.Data); AssignStates(IsoGrid); var entries = EntryField.GetFirstValue(payload.Data); if (entries == null) { throw new Exception("Illegal mutable field here! " + EntryField.AbsoluteKey + " is not an enumerable of mutables!"); } // Determine the full size of the entire isogrid int numCellsXAxis = 0; int numCellsZAxis = 0; if (entries.Any()) { numCellsXAxis = XAxis.GetEntries(payload.Data).Max(e => XAxis.GetValue(e)) + 1; numCellsZAxis = ZAxis.GetEntries(payload.Data).Max(e => ZAxis.GetValue(e)) + 1; } IsoGrid.UpdateHorizontalScale(numCellsXAxis); IsoGrid.UpdateDepthScale(numCellsZAxis); AssignElements(entries); var iterator = IsoGrid.Apply(); while (iterator.MoveNext( )) { yield return(null); } // PROCESS the label stuff, that was specified by the author: LabelSystem.Render(payload, IsoGrid.transform, IsoGrid.SelectionManager); }
private IsoGrid[] GetOrderedGrids() { List <IsoGrid> grids = new List <IsoGrid>(FindObjectsOfType <IsoGrid>()); List <IsoGrid> ordered = new List <IsoGrid>(); // Order from farthest to nearest while (grids.Count > 0) { IsoGrid closest = grids[0]; foreach (IsoGrid g in grids) { if ((Camera.main.transform.position - g.transform.position).magnitude > (Camera.main.transform.position - closest.transform.position).magnitude) { closest = g; } } grids.Remove(closest); ordered.Add(closest); } return(ordered.ToArray()); }
void Awake() { currentGrid = FindObjectOfType <IsoGrid>(); renderer = GetComponent <SpriteRenderer>(); }
void Start() { _isoGrid = FindObjectOfType <IsoGrid>(); _isoGrid.removeTransformFromGrid(this.GetComponentInChildren <SpriteRenderer>().transform); }
public IsoTile(IsoGrid world, int x, int y) { World = world; Index = new Point (x, y); }
private void OnEnable() { isoGrid = (IsoGrid)target; }