示例#1
0
 public void Remove(IsoTransform isoTransform)
 {
     if (SortingStrategy != null)
     {
         SortingStrategy.Remove(isoTransform);
     }
 }
示例#2
0
        /// <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);
        }
示例#3
0
        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);
        }
示例#4
0
 public void Resolve(IsoTransform isoTransform)
 {
     Dirty = true;
     if (SortingStrategy != null)
     {
         SortingStrategy.Resolve(isoTransform);
     }
 }
示例#5
0
 public override void Remove(IsoTransform isoTransform)
 {
     if (!_isoTransformToSortingState.ContainsKey(isoTransform))
     {
         return;
     }
     _nodes.Remove(_isoTransformToSortingState[isoTransform]);
     _isoTransformToSortingState.Remove(isoTransform);
 }
示例#6
0
        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;
            }
        }
示例#7
0
        public override void Remove(IsoTransform isoTransform)
        {
            int tileindex;

            if (!_inverseTileDictionary.TryGetValue(isoTransform, out tileindex))
            {
                return;
            }
            _tileDictionary[tileindex].Remove(isoTransform);
            _inverseTileDictionary.Remove(isoTransform);
        }
示例#8
0
            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);
            }
示例#9
0
        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);
        }
示例#10
0
 public abstract void Remove(IsoTransform isoTransform);
示例#11
0
 public override void Remove(IsoTransform isoTransform)
 {
     _entities.Remove(isoTransform);
 }
示例#12
0
 public override void Resolve(IsoTransform isoTransform)
 {
     isoTransform.transform.position = Isometric.IsoToUnitySpace(isoTransform.Position);
     _entities.Add(isoTransform);
 }
示例#13
0
 public SortingState(IsoTransform isotransform)
 {
     Isotransform = isotransform;
     Hexagon      = new Hexagon(Isotransform);
 }
示例#14
0
 private int GetTile(IsoTransform isoTransform)
 {
     return(Mathf.FloorToInt(isoTransform.Min.x + .5f) + Mathf.FloorToInt(isoTransform.Min.z + .5f));
 }