public void Remove(IsoTransform isoTransform) { if (SortingStrategy != null) { SortingStrategy.Remove(isoTransform); } }
/// <summary> /// Returns if a should be drawn behind b /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static bool ADependsOnB(IsoTransform a, IsoTransform b) { //avoid multiple calculations var aMin = a.Min; var aMax = a.Max; var bMin = b.Min; var bMax = b.Max; var aMaxBehindbMin = aMax.x > bMin.x && bMax.y > aMin.y && aMax.z > bMin.z; var bMaxBehindaMin = bMax.x > aMin.x && aMax.y > bMin.y && bMax.z > aMin.z; if (!aMaxBehindbMin || !bMaxBehindaMin) { return(aMaxBehindbMin); } //bounds intersect var bMinToAMax = new Vector3(aMax.x - bMin.x, bMax.y - aMin.y, aMax.z - bMin.z); var aMinToBMax = new Vector3(bMax.x - aMin.x, aMax.y - bMin.y, bMax.z - aMin.z); var dist = bMinToAMax - aMinToBMax; var intersection = a.Size + b.Size - new Vector3(Mathf.Abs(dist.x), Mathf.Abs(dist.y), Mathf.Abs(dist.z)); //find min intersection axis if (intersection.x <= intersection.z && intersection.x <= intersection.y) { return(bMinToAMax.x > aMinToBMax.x); } if (intersection.z <= intersection.x && intersection.z <= intersection.y) { return(bMinToAMax.z > aMinToBMax.z); } return(bMinToAMax.y > aMinToBMax.y); }
public override void Resolve(IsoTransform isoTransform) { Remove(isoTransform); var xyPos = Isometric.IsoToUnitySpace(isoTransform.Position); isoTransform.transform.position = new Vector3(xyPos.x, xyPos.y, isoTransform.transform.position.z); var index = GetTile(isoTransform); int insertIndex; if (!_tileDictionary.ContainsKey(index)) { _tileDictionary[index] = new List <IsoTransform>(); insertIndex = ~_sortedIndices.BinarySearch(index); _sortedIndices.Insert(insertIndex, index); } insertIndex = _tileDictionary[index].BinarySearch(isoTransform, _yComparer); if (insertIndex < 0) { insertIndex = ~insertIndex; } _tileDictionary[index].Insert(insertIndex, isoTransform); _inverseTileDictionary.Add(isoTransform, index); }
public void Resolve(IsoTransform isoTransform) { Dirty = true; if (SortingStrategy != null) { SortingStrategy.Resolve(isoTransform); } }
public override void Remove(IsoTransform isoTransform) { if (!_isoTransformToSortingState.ContainsKey(isoTransform)) { return; } _nodes.Remove(_isoTransformToSortingState[isoTransform]); _isoTransformToSortingState.Remove(isoTransform); }
private void UpdateOnMouseCallbacks() { //raycast IsoRaycastHit hit; if (IsoPhysics.Raycast(Isometric.MouseToIsoRay(), out hit)) { if (_mouseOverIsoTransform != null) { if (hit.IsoTransform != _mouseOverIsoTransform) { _mouseOverIsoTransform.SendMessage("OnMouseExit", SendMessageOptions.DontRequireReceiver); hit.IsoTransform.SendMessage("OnMouseEnter", SendMessageOptions.DontRequireReceiver); } else { _mouseOverIsoTransform.SendMessage("OnMouseOver", SendMessageOptions.DontRequireReceiver); } } else { hit.IsoTransform.SendMessage("OnMouseEnter", SendMessageOptions.DontRequireReceiver); } _mouseOverIsoTransform = hit.IsoTransform; if (Input.GetMouseButtonDown(0)) { _mouseOverIsoTransform.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver); } if (Input.GetMouseButtonUp(0)) { _mouseOverIsoTransform.SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver); } } else { if (_mouseOverIsoTransform != null) { _mouseOverIsoTransform.SendMessage("OnMouseExit", SendMessageOptions.DontRequireReceiver); if (Input.GetMouseButtonDown(0)) { _mouseOverIsoTransform.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver); } if (Input.GetMouseButtonUp(0)) { _mouseOverIsoTransform.SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver); } } _mouseOverIsoTransform = null; } }
public override void Remove(IsoTransform isoTransform) { int tileindex; if (!_inverseTileDictionary.TryGetValue(isoTransform, out tileindex)) { return; } _tileDictionary[tileindex].Remove(isoTransform); _inverseTileDictionary.Remove(isoTransform); }
public Hexagon(IsoTransform isoTransform) { var isoMin = isoTransform.Position - isoTransform.Size / 2; var isoMax = isoTransform.Position + isoTransform.Size / 2; _min = new Vector2(isoMin.x + isoMin.y, isoMin.z + isoMin.y); _max = new Vector2(isoMax.x + isoMax.y, isoMax.z + isoMax.y); var left = Isometric.IsoToUnitySpace(isoTransform.Position + new Vector3(-isoTransform.Size.x / 2, -isoTransform.Size.y / 2, isoTransform.Size.z / 2)).x; var right = Isometric.IsoToUnitySpace(isoTransform.Position + new Vector3(isoTransform.Size.x / 2, -isoTransform.Size.y / 2, -isoTransform.Size.z / 2)).x; _h = new Vector2(left, right); }
public override void Resolve(IsoTransform isoTransform) { if (isoTransform == null) { return; } //apply xy screen position var posXY = Isometric.IsoToUnitySpace(isoTransform.Position); isoTransform.transform.position = new Vector3(posXY.x, posXY.y, isoTransform.transform.position.z); //add if not exists SortingState sortingState; if (!_isoTransformToSortingState.TryGetValue(isoTransform, out sortingState)) { sortingState = new SortingState(isoTransform); _nodes.Add(sortingState); _isoTransformToSortingState.Add(isoTransform, sortingState); } //remove from parent dependencies for (int i = 0; i < sortingState.ParentDependencies.Count; i++) { sortingState.ParentDependencies[i].ChildDependencies.Remove(sortingState); } sortingState.ParentDependencies.Clear(); //remove from child dependencies for (int i = 0; i < sortingState.ChildDependencies.Count; i++) { var childDependency = sortingState.ChildDependencies[i]; childDependency.ParentDependencies.Remove(sortingState); } sortingState.ChildDependencies.Clear(); sortingState.Hexagon = new Hexagon(isoTransform); CalculateDependencies(sortingState); }
public abstract void Remove(IsoTransform isoTransform);
public override void Remove(IsoTransform isoTransform) { _entities.Remove(isoTransform); }
public override void Resolve(IsoTransform isoTransform) { isoTransform.transform.position = Isometric.IsoToUnitySpace(isoTransform.Position); _entities.Add(isoTransform); }
public SortingState(IsoTransform isotransform) { Isotransform = isotransform; Hexagon = new Hexagon(Isotransform); }
private int GetTile(IsoTransform isoTransform) { return(Mathf.FloorToInt(isoTransform.Min.x + .5f) + Mathf.FloorToInt(isoTransform.Min.z + .5f)); }