/// <summary> /// 检测范围内单位 /// </summary> /// <param name="graphics">范围图形</param> /// <param name="myCamp">当前单位阵营</param> /// <param name="isExceptMyCamp">是否排除己方阵营</param> /// <returns>范围内单位</returns> public IList <PositionObject> CheckRange(ICollisionGraphics graphics, int myCamp = -1, bool isExceptMyCamp = false) { var memberInSightScope = GetPositionObjectListByGraphics(graphics); IList <PositionObject> list = new List <PositionObject>(); if (memberInSightScope != null) { foreach (var member in memberInSightScope) { // 单位有效 // 区分空地属性 // 区分阵营 if (member != null && member.AllData.MemberData.CurrentHP > 0 && (myCamp == -1 || (isExceptMyCamp && member.AllData.MemberData.Camp != myCamp) || (!isExceptMyCamp && member.AllData.MemberData.Camp == myCamp)) && member.CouldSelect) { list.Add(member); } } } return(list); }
/// <summary> /// 初始化 /// </summary> /// <param name="mapBaseParam">绘制数据</param> /// <param name="mapCenter">地图中心</param> /// <param name="graphics">绘制范围</param> /// <param name="type">绘制类型</param> public void Init([NotNull] MapBase mapBaseParam, Vector3 mapCenter, ICollisionGraphics graphics, int type = 0) { Clear(); mapBase = mapBaseParam; drawGraphics = graphics == null ? new RectGraphics(Vector2.zero, 0, 0, 0) : graphics; UnitWidth = mapBaseParam.UnitWidth; ChangeDrawGraphics(graphics); }
/// <summary> /// 方方碰撞检测 /// </summary> /// <param name="rect1">方形1</param> /// <param name="rect2">方形2</param> /// <returns>是否碰撞</returns> public static bool CheckRectAndRect(ICollisionGraphics rect1, ICollisionGraphics rect2) { // 转换类型 var rectGraphics1 = rect1 as RectGraphics; var rectGraphics2 = rect2 as RectGraphics; if (rectGraphics1 != null && rectGraphics2 != null) { //建立投影, 如果在法线上任意两投影不重合, 说明不想交, 否则相交 var axisArray = new[] { rectGraphics1.HorizonalAxis, rectGraphics1.VerticalAxis, rectGraphics2.HorizonalAxis, rectGraphics2.VerticalAxis, }; //var positionV3 = new Vector3(rectGraphics1.Postion.x, 0, rectGraphics1.Postion.y); //var rightV3 = new Vector3(rectGraphics1.HorizonalAxis.x, 0, rectGraphics1.HorizonalAxis.y); //var topV3 = new Vector3(rectGraphics1.VerticalAxis.x, 0, rectGraphics1.VerticalAxis.y); //Debug.DrawLine(positionV3, positionV3 + rightV3 * rectGraphics1.Width, Color.red); //Debug.DrawLine(positionV3, positionV3 + topV3 * rectGraphics1.Height, Color.red); //positionV3 = new Vector3(rectGraphics2.Postion.x, 0, rectGraphics2.Postion.y); //rightV3 = new Vector3(rectGraphics2.HorizonalAxis.x, 0, rectGraphics2.HorizonalAxis.y); //topV3 = new Vector3(rectGraphics2.VerticalAxis.x, 0, rectGraphics2.VerticalAxis.y); //Debug.DrawLine(positionV3, positionV3 + rightV3 * rectGraphics2.Width, Color.red); //Debug.DrawLine(positionV3, positionV3 + topV3 * rectGraphics2.Height, Color.red); var positionOffset = rectGraphics1.Postion - rectGraphics2.Postion; for (var i = 0; i < axisArray.Length; i++) { var axis = axisArray[i]; var dot = Math.Abs(Vector2.Dot(axis, positionOffset)); // 映射对角线到四个轴上进行对比 var projection1 = Math.Abs(Vector2.Dot(axis, rectGraphics1.Diagonal1)) * 0.5f; var projection2 = Math.Abs(Vector2.Dot(axis, rectGraphics1.Diagonal2)) * 0.5f; var projection3 = Math.Abs(Vector2.Dot(axis, rectGraphics2.Diagonal1)) * 0.5f; var projection4 = Math.Abs(Vector2.Dot(axis, rectGraphics2.Diagonal2)) * 0.5f; projection1 = projection1 > projection2 ? projection1 : projection2; projection3 = projection3 > projection4 ? projection3 : projection4; if (projection1 + projection3 <= dot) { return(false); } } return(true); } return(false); }
/// <summary> /// 获取图形范围内的单位 /// </summary> /// <param name="graphics">图形对象</param> /// <returns>范围内单位列表</returns> public IList <PositionObject> GetPositionObjectListByGraphics(ICollisionGraphics graphics) { if (targetList == null) { return(null); } Utils.DrawGraphics(graphics, Color.white); IList <PositionObject> result = targetList.QuadTree.GetScope(graphics); return(result); }
/// <summary> /// 获取该位置的Rect /// </summary> /// <returns>该位置的Rect</returns> public virtual ICollisionGraphics GetGraphics() { // 如果位置有变更则更新Rect if (X != historyX || Y != historyY) { var unitWidth = MapDrawer.Single.UnitWidth; historyX = X; historyY = Y; historyRect = new RectGraphics(new Vector2(X * unitWidth - MapDrawer.Single.MapWidth * unitWidth * 0.5f, Y * unitWidth - MapDrawer.Single.MapHeight * unitWidth * 0.5f), unitWidth, unitWidth, 0); } return(historyRect); }
/// <summary> /// 拷贝 /// </summary> /// <param name="graphics"></param> public override void Copy(ICollisionGraphics graphics) { if (graphics.GraphicType == GraphicType.Circle) { var sourceCircle = graphics as CircleGraphics; this.Postion = sourceCircle.Postion; this.Radius = sourceCircle.Radius; } else { Debug.Log("试图拷贝:" + graphics.GraphicType + "类型到圆形"); } }
///// <summary> ///// 扇形扇形碰撞检测 ///// </summary> ///// <param name="sector1">扇形1</param> ///// <param name="sector2">扇形2</param> ///// <returns>是否碰撞</returns> //public static bool CheckSectorAndSector(ICollisionGraphics sector1, ICollisionGraphics sector2) //{ // var result = false; // return result; //} /// <summary> /// 圆与线碰撞 /// </summary> /// <param name="circle">圆形</param> /// <param name="lineP1">线点1</param> /// <param name="lineP2">线点2</param> /// <returns>是否碰撞</returns> public static bool CheckCircleAndLine(ICollisionGraphics circle, Vector2 lineP1, Vector2 lineP2) { var result = false; var circleGraphics = circle as CircleGraphics; if (circleGraphics != null) { result = CheckCircleAndLine(circleGraphics.Postion, circleGraphics.Radius, lineP1, lineP2); } return(result); }
/// <summary> /// 绘制当前单位 /// </summary> /// <param name="leftdown">地图左下点位置</param> /// <param name="unitWidth">地图单位宽度</param> public override void Draw(Vector3 leftdown, int unitWidth) { base.Draw(leftdown, unitWidth); // 绘制塔内单位 DrawTowerCell(); if (isNotSetGraphics) { graphics = new CircleGraphics(GameObj.transform.position, 10 * unitWidth); isNotSetGraphics = false; } //StepAction(this); }
/// <summary> /// 拷贝 /// </summary> /// <param name="graphics"></param> public override void Copy(ICollisionGraphics graphics) { if (graphics.GraphicType == GraphicType.Sector) { var sourceSector = graphics as SectorGraphics; this.Postion = sourceSector.Postion; this.Rotation = sourceSector.Rotation; this.Radius = sourceSector.Radius; this.OpenAngle = sourceSector.OpenAngle; } else { Debug.Log("试图拷贝:" + graphics.GraphicType + "类型到扇形"); } }
/// <summary> /// 拷贝 /// </summary> /// <param name="graphics"></param> public override void Copy(ICollisionGraphics graphics) { if (graphics.GraphicType == GraphicType.Rect) { var sourceRect = graphics as RectGraphics; this.Postion = sourceRect.Postion; this.Width = sourceRect.Width; this.Height = sourceRect.Height; this.rotation = sourceRect.rotation; } else { Debug.Log("试图拷贝:" + graphics.GraphicType + "类型到矩形"); } }
static int DrawGraphics(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ICollisionGraphics arg0 = (ICollisionGraphics)ToLua.CheckObject(L, 1, typeof(ICollisionGraphics)); UnityEngine.Color arg1 = ToLua.ToColor(L, 2); Utils.DrawGraphics(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 圆圆碰撞检测 /// </summary> /// <param name="circle1">圆1</param> /// <param name="circle2">圆2</param> /// <returns>是否碰撞</returns> public static bool CheckCircleAndCircle(ICollisionGraphics circle1, ICollisionGraphics circle2) { var result = false; var circleGraphics1 = circle1 as CircleGraphics; var circleGraphics2 = circle2 as CircleGraphics; if (circleGraphics1 != null && circleGraphics2 != null) { // 检查两圆的半径与距离大小 var distance = (circleGraphics1.Postion - circleGraphics2.Postion).magnitude; result = distance < circleGraphics1.Radius + circleGraphics2.Radius; } return(result); }
static int GetPositionObjectListByGraphics(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); ClusterManager obj = (ClusterManager)ToLua.CheckObject(L, 1, typeof(ClusterManager)); ICollisionGraphics arg0 = (ICollisionGraphics)ToLua.CheckObject(L, 2, typeof(ICollisionGraphics)); System.Collections.Generic.IList <PositionObject> o = obj.GetPositionObjectListByGraphics(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
///// <summary> ///// 删除单位 ///// </summary> ///// <param name="t">被删除单位</param> //public void Remove(T t) //{ // if (t == null) // { // return; // } // // 列表中不存在单位 // if (!root.itemMap.ContainsKey(t)) // { // return; // } // // 获取四叉树中子节点位置 // QuadTree<T> node = this; // var pos = itemMap[t]; // long nowPos = 0; // while ((nowPos = pos % 8) < 4) // { // } //} /// <summary> /// 返回传入对象可能会有碰撞的对向列表 /// TODO 分块交界处会有问题 /// </summary> /// <param name="rectangle">碰撞对象</param> /// <returns>可能碰撞的列表, 对量性质: 在传入rect所在的最底层自己点的对量+其上各个父级的边缘节点</returns> public IList <T> Retrieve(ICollisionGraphics rectangle) { var result = new List <T>(); var index = GetIndex(rectangle); // 如果未在子节点则从当前节点返回所有对象 if (index != -1 && nodes[0] != null) { result.AddRange(nodes[index].Retrieve(rectangle)); } result.AddRange(itemsList); return(result); }
static int get_MyCollisionGraphics(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PositionObject obj = (PositionObject)o; ICollisionGraphics ret = obj.MyCollisionGraphics; ToLua.PushObject(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index MyCollisionGraphics on a nil value" : e.Message)); } }
static int set_MyCollisionGraphics(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PositionObject obj = (PositionObject)o; ICollisionGraphics arg0 = (ICollisionGraphics)ToLua.CheckObject(L, 2, typeof(ICollisionGraphics)); obj.MyCollisionGraphics = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index MyCollisionGraphics on a nil value" : e.Message)); } }
/// <summary> /// 设置单位的spaceSet空间值 /// </summary> /// <param name="graphics">图形单位</param> /// <param name="spaceSet">空间值</param> /// <param name="unitWidth">单位宽度</param> public static void SetGraphicsSpaceSet(ICollisionGraphics graphics, float spaceSet, int unitWidth = 1) { if (graphics != null && spaceSet > 0) { var circle = graphics as CircleGraphics; if (circle != null) { circle.Radius = spaceSet * unitWidth; return; } var rect = graphics as RectGraphics; if (rect != null) { rect.Width = spaceSet * 1.414f * unitWidth; rect.Height = spaceSet * 1.414f * unitWidth; return; } } }
/// <summary> /// 按照矩形返回获取范围内对向列表 /// TODO 优化 /// </summary> /// <param name="scopeRect">范围rect</param> /// <returns></returns> public IList <T> GetScope(ICollisionGraphics scopeRect) { List <T> result = null; // 判断与当前四叉树的相交 if (scopeRect != null) { result = new List <T>(); T tmpItem; // 遍历当前节点中的对象列表, 是否有相交 for (var i = 0; i < itemsList.Count; i++) { tmpItem = itemsList[i]; if (tmpItem.MyCollisionGraphics.CheckCollision(scopeRect)) { result.Add(tmpItem); } } if (rect.CheckCollision(scopeRect)) { if (nodes[0] != null) { for (int i = 0; i < nodes.Length; i++) { if (nodes[i].rect.CheckCollision(scopeRect)) { result.AddRange(nodes[i].GetScope(scopeRect)); } } } // 划定范围, 获取范围内子对象中符合范围的对象 // 判断是否与该区域相交 相交则取该区域内对象判断, 并获取其子节点判断是否相交 // 获取子列表中的对象 //var log = ""; //foreach (var item in result) //{ // log += (item as PositionObject).name + ","; //} //UnityEngine.Debug.LogError(log); } } return(result); }
/// <summary> /// 绘制地图 /// </summary> public void DrawMap(ICollisionGraphics rect) { // 遍历地图 foreach (var kv in mapDataGroupDic) { foreach (var kv2 in kv.Value) { foreach (var item in kv2.Value) { item.Draw(Leftdown, unitWidth); } } } NeedDraw = false; // 判断变更 // 绘制变更 // 否则跳过 }
/// <summary> /// 圆方碰撞检测 /// </summary> /// <param name="circle">圆</param> /// <param name="rect">方</param> /// <returns>是否碰撞</returns> public static bool CheckCircleAndRect(ICollisionGraphics circle, ICollisionGraphics rect) { // 转换格式 var circleGraphics = circle as CircleGraphics; var rectGraphics = rect as RectGraphics; if (circleGraphics != null && rectGraphics != null) { var positionOffset = circleGraphics.Postion - rectGraphics.Postion; var axis = rectGraphics.HorizonalAxis; var dot = Math.Abs(Vector2.Dot(axis, positionOffset)); // 映射对角线到四个轴上进行对比 var projection1 = Math.Abs(Vector2.Dot(axis, rectGraphics.Diagonal1)) * 0.5f; var projection2 = Math.Abs(Vector2.Dot(axis, rectGraphics.Diagonal2)) * 0.5f; var projection3 = circleGraphics.Radius; projection1 = projection1 > projection2 ? projection1 : projection2; if (projection1 + projection3 <= dot) { return(false); } axis = rectGraphics.VerticalAxis; dot = Math.Abs(Vector2.Dot(axis, positionOffset)); // 映射对角线到四个轴上进行对比 projection1 = Math.Abs(Vector2.Dot(axis, rectGraphics.Diagonal1)) * 0.5f; projection2 = Math.Abs(Vector2.Dot(axis, rectGraphics.Diagonal2)) * 0.5f; projection3 = circleGraphics.Radius; projection1 = projection1 > projection2 ? projection1 : projection2; if (projection1 + projection3 <= dot) { return(false); } return(true); } return(false); }
/// <summary> /// 范围伤害(任意图形) /// </summary> /// <param name="attacker">攻击者数据</param> /// <param name="effectKey">范围特效</param> /// <param name="targetPos">目标点位置</param> /// <param name="graphics">范围检测图形</param> /// <param name="durTime">持续时间</param> /// <param name="callback">结束回调</param> /// <param name="callbackForEveryOne">每个受击单位的回调</param> /// <returns></returns> public IGeneralAttack GetPositionScopeGeneralAttack(PositionObject attacker, string effectKey, Vector3 targetPos, ICollisionGraphics graphics, float durTime, Action callback, Action <GameObject> callbackForEveryOne = null) { IGeneralAttack result = null; result = new PositionScopeGeneralAttack(attacker, effectKey, targetPos, graphics, durTime, callback, callbackForEveryOne); return(result); }
/// <summary> /// 判断单位是否完全在当前节点的矩形内 /// </summary> /// <param name="item">被检测单位</param> /// <param name="testRect">检测矩形</param> /// <returns>被检测单位是否在当前几点的范围内</returns> public bool IsInner(ICollisionGraphics item, RectGraphics testRect) { if (item == null) { return(false); } // 获得图形的外接矩形 var itemExternalRect = item.GetExternalRect(); // 判断是否在范围内 var itemExternalRectHalfWidth = itemExternalRect.Width * 0.5f; var nodeRectHalfWidth = testRect.Width * 0.5f; var itemExternalRectHalfHeight = itemExternalRect.Height * 0.5f; var nodeRectHalfHeight = testRect.Height * 0.5f; // 是否在范围内 return(itemExternalRect.Postion.x + itemExternalRectHalfWidth <= testRect.Postion.x + nodeRectHalfWidth && itemExternalRect.Postion.x - itemExternalRectHalfWidth >= testRect.Postion.x - nodeRectHalfWidth && itemExternalRect.Postion.y + itemExternalRectHalfHeight <= testRect.Postion.y + nodeRectHalfHeight && itemExternalRect.Postion.y - itemExternalRectHalfHeight >= testRect.Postion.y - nodeRectHalfHeight); }
/// <summary> /// 初始化 /// </summary> /// <param name="attacker">攻击者数据</param> /// <param name="effectKey">范围特效</param> /// <param name="targetPos">目标点位置</param> /// <param name="graphics">范围检测图形</param> /// <param name="durTime">持续时间</param> /// <param name="callback">结束回调</param> /// <param name="callbackForEveryOne">每个受击单位的回调</param> public PositionScopeGeneralAttack(PositionObject attacker, string effectKey, Vector3 targetPos, ICollisionGraphics graphics, float durTime, Action callback, Action <GameObject> callbackForEveryOne = null) { if (attacker == null) { //throw new Exception("攻击者数据为null"); return; } this.attacker = attacker; this.effectKey = effectKey; this.targetPos = targetPos; this.graphics = graphics; this.durTime = durTime; this.callback = callback; this.callbackForEveryOne = callbackForEveryOne; }
/// <summary> /// 初始化 /// </summary> /// <param name="attacker">攻击者数据</param> /// <param name="effectKey">范围特效</param> /// <param name="targetPos">目标位置</param> /// <param name="scopeRaduis">范围半径</param> /// <param name="durTime">持续时间</param> /// <param name="callback">结束回调</param> /// <param name="callbackForEveryOne">每个受击单位的回调</param> public PositionScopeGeneralAttack(PositionObject attacker, string effectKey, Vector3 targetPos, float scopeRaduis, float durTime, Action callback = null, Action <GameObject> callbackForEveryOne = null) { if (attacker == null) { //throw new Exception("攻击者数据为null"); return; } this.attacker = attacker; this.effectKey = effectKey; this.targetPos = targetPos; graphics = new CircleGraphics(new Vector2(targetPos.x, targetPos.z), scopeRaduis); this.durTime = durTime; this.callback = callback; this.callbackForEveryOne = callbackForEveryOne; }
/// <summary> /// 扇圆碰撞检测 /// </summary> /// <param name="sector">扇形</param> /// <param name="circle">圆形</param> /// <returns></returns> public static bool CheckSectorAndCircle(ICollisionGraphics sector, ICollisionGraphics circle) { var sectorGraphics = sector as SectorGraphics; var circleGraphics = circle as CircleGraphics; if (sectorGraphics != null && circleGraphics != null) { // 如果不在扇形圆半径内, 则不相交 if ((sectorGraphics.Postion - circleGraphics.Postion).magnitude > sectorGraphics.Radius + circleGraphics.Radius) { return(false); } // 获取扇形两角的点位置 var halfAngle = sectorGraphics.OpenAngle * 0.5f; // 两个点相对圆心方向 var pointForCorner1 = new Vector2((float)Math.Sin(sectorGraphics.Rotation + halfAngle), (float)Math.Cos(sectorGraphics.Rotation + halfAngle)); var pointForCorner2 = new Vector2((float)Math.Sin(sectorGraphics.Rotation - halfAngle), (float)Math.Cos(sectorGraphics.Rotation - halfAngle)); // 如果圆心在扇形角度内则相交 var distance1 = EvaluatePointToLine(circleGraphics.Postion, pointForCorner1, sectorGraphics.Postion); var distance2 = EvaluatePointToLine(circleGraphics.Postion, sectorGraphics.Postion, pointForCorner2); if (distance1 >= 0 && distance2 >= 0) { // 圆心在扇形开口角度内 return(true); } // 如果与两线相交则相交 if (CheckCircleAndLine(circle, sectorGraphics.Postion, pointForCorner1) || CheckCircleAndLine(circle, sectorGraphics.Postion, pointForCorner2)) { return(true); } } return(false); }
/// <summary> /// 绘制全局 /// </summary> public override void Draw() { Utils.DrawGraphics(drawGraphics, Color.yellow); // 当前范围是否移动, 如果移动则更新列表, 如果未移动则使用旧列表数据 if (drawGraphics == null || historyGraphics == null || drawGraphics.Postion != historyGraphics.Postion || mapBase.NeedDraw) { // 局部绘制控制(只有地板) mapBase.Foreach(drawAction); // 全绘制(除了地板) mapBase.DrawMap(drawGraphics); // 记录绘制范围 if (historyGraphics == null) { historyGraphics = drawGraphics.Clone(); } historyGraphics.Copy(drawGraphics); } // 判断是否有移动单位变更 }
static int CheckRange(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(ClusterManager), typeof(ICollisionGraphics), typeof(int), typeof(bool))) { ClusterManager obj = (ClusterManager)ToLua.ToObject(L, 1); ICollisionGraphics arg0 = (ICollisionGraphics)ToLua.ToObject(L, 2); int arg1 = (int)LuaDLL.lua_tonumber(L, 3); bool arg2 = LuaDLL.lua_toboolean(L, 4); System.Collections.Generic.IList <PositionObject> o = obj.CheckRange(arg0, arg1, arg2); ToLua.PushObject(L, o); return(1); } else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(ClusterManager), typeof(UnityEngine.Vector2), typeof(float), typeof(int), typeof(bool))) { ClusterManager obj = (ClusterManager)ToLua.ToObject(L, 1); UnityEngine.Vector2 arg0 = ToLua.ToVector2(L, 2); float arg1 = (float)LuaDLL.lua_tonumber(L, 3); int arg2 = (int)LuaDLL.lua_tonumber(L, 4); bool arg3 = LuaDLL.lua_toboolean(L, 5); System.Collections.Generic.IList <PositionObject> o = obj.CheckRange(arg0, arg1, arg2, arg3); ToLua.PushObject(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: ClusterManager.CheckRange")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 扇方碰撞检测 /// </summary> /// <param name="sector">扇形</param> /// <param name="rect">方形</param> /// <returns>是否碰撞</returns> public static bool CheckSectorAndRect(ICollisionGraphics sector, ICollisionGraphics rect) { var sectorGraphics = sector as SectorGraphics; var rectGraphics = rect as RectGraphics; if (sectorGraphics != null && rectGraphics != null) { var sectorR = (sectorGraphics.Postion - rectGraphics.Postion).magnitude; if (sectorR > sectorGraphics.Radius + rectGraphics.Width && sectorR > sectorGraphics.Radius + rectGraphics.Height) { return(false); } // TODO 检测举行位置 // 获取扇形两角的点位置 var halfAngle = sectorGraphics.OpenAngle * 0.5f; // 两个点相对圆心方向 var pointForCorner1 = new Vector2((float)Math.Sin(sectorGraphics.Rotation + halfAngle), (float)Math.Cos(sectorGraphics.Rotation + halfAngle)); var pointForCorner2 = new Vector2((float)Math.Sin(sectorGraphics.Rotation - halfAngle), (float)Math.Cos(sectorGraphics.Rotation - halfAngle)); var distance1 = EvaluatePointToLine(rectGraphics.Postion, pointForCorner1, sectorGraphics.Postion); var distance2 = EvaluatePointToLine(rectGraphics.Postion, sectorGraphics.Postion, pointForCorner2); if (distance1 >= 0 && distance2 >= 0) { // 圆心在扇形开口角度内 return(true); } //// 如果与两线相交则相交 //if (CheckCircleAndLine(circle, sectorGraphics.Postion, pointForCorner1) || CheckCircleAndLine(circle, sectorGraphics.Postion, pointForCorner2)) //{ // return true; //} } return(false); }
/// <summary> /// 绘制图形 /// </summary> /// <param name="graphics">图形对象</param> public static void DrawGraphics(ICollisionGraphics graphics, Color color) { if (!Debug.unityLogger.logEnabled) { return; } if (graphics == null) { return; } switch (graphics.GraphicType) { case GraphicType.Circle: var circle = graphics as CircleGraphics; if (circle != null) { DrawCircle(new Vector3(circle.Postion.x, circle.Postion.y), circle.Radius, color); } break; case GraphicType.Rect: var rect = graphics as RectGraphics; if (rect != null) { DrawRect(new Vector3(rect.Postion.x, rect.Postion.y), rect.Width, rect.Height, rect.Rotation, color); } break; case GraphicType.Sector: var sector = graphics as SectorGraphics; if (sector != null) { DrawSector(new Vector3(sector.Postion.x, sector.Postion.y), sector.Radius, sector.Rotation, sector.OpenAngle, color); } break; } }
/// <summary> /// 根据rect获取该rect所在的节点 /// </summary> /// <param name="item">对象</param> /// <returns>节点编号</returns> public int GetIndex(ICollisionGraphics item) { var result = -1; var tmpResult = -1; // 获得当前节点rect的中心点 //var midPointX = this.rect.Postion.x;// + this.rect.Width/2; //var midPointY = this.rect.Postion.y;// + this.rect.Height/2; // 判断如果当前图形边框超出子节点则不放入其中 var collisionSubNodeCount = 0; if (nodes != null && item != null) { for (var i = 0; i < nodes.Length; i++) { var node = nodes[i]; if (node != null && node.GetRectangle().CheckCollision(item)) { if (collisionSubNodeCount > 0) { break; } tmpResult = i; collisionSubNodeCount++; } } if (collisionSubNodeCount == 1) { // 判断是否超出当前节点外框 var node = nodes[tmpResult]; var nodeRect = node.GetRectangle(); var rect = item.GetExternalRect(); if (IsInner(item, nodeRect)) { result = tmpResult; } } } //var topContians = (item.Postion.y > midPointY); //var bottomContians = (item.Postion.y < midPointY); //if (item.Postion.x < midPointX) //{ // if (topContians) // { // // 左上角 // result = 3; // } // else if (bottomContians) // { // // 左下角 // result = 2; // } //} //else if (item.Postion.x > midPointX) //{ // if (topContians) // { // // 右上角 // result = 0; // } // else if (bottomContians) // { // // 右下角 // result = 1; // } //} return(result); }