// 得到物体变幻形状 public SceneShape GetTransformShape(Vector2 pos, float radians) { if (mShapeParam == null) { mShapeParam = new SceneShapeParam(); mShapeParam.mType = ShapeType.ShapeType_Round; mShapeParam.mParams.Add(GetRadius()); } if (mTransformShape == null) { mTransformShape = SceneShapeUtilities.Create(mShapeParam, pos, radians); } else { mTransformShape = SceneShapeUtilities.refresh(ref mTransformShape, mShapeParam, pos, radians); } return(mTransformShape); }
// 得到物体形状 public SceneShape GetShape() { if (mShapeParam == null) { mShapeParam = new SceneShapeParam(); mShapeParam.mType = ShapeType.ShapeType_Round; mShapeParam.mParams.Add(GetRadius()); } if (mShape == null) { mShape = SceneShapeUtilities.Create(mShapeParam, new Vector2(GetPosition().x, GetPosition().z), GetDirection()); } else if (!typeof(BuildObj).IsAssignableFrom(GetType())) { mShape = SceneShapeUtilities.refresh(ref mShape, mShapeParam, new Vector2(GetPosition().x, GetPosition().z), GetDirection()); } return(mShape); }
// 相交 override public bool intersect(SceneShape shape) { if (typeof(SceneShapeRect).IsAssignableFrom(shape.GetType())) { return(SceneShapeUtilities.overlap(this, shape as SceneShapeRect)); } else if (typeof(SceneShapeRound).IsAssignableFrom(shape.GetType())) { return(SceneShapeUtilities.overlap(this, shape as SceneShapeRound)); } else if (typeof(SceneShapePolygon).IsAssignableFrom(shape.GetType())) { return(SceneShapeUtilities.overlap(this, shape as SceneShapePolygon)); } else if (typeof(SceneShapeLine).IsAssignableFrom(shape.GetType())) { return(SceneShapeUtilities.overlap(this, shape as SceneShapeLine)); } GameDebug.LogError("SceneShapeLine.intersect() 未知的图形类别"); return(false); }
/// <summary> /// 根据目标选择参数, 以centerPosition为中心选择目标. /// </summary> /// <param name="attackerAttr">攻击者的数据</param> /// <param name="centerPosition">选择的中心点</param> /// <param name="attackerDirection">攻击者的方向(对于矩形, 扇形时用到)</param> /// <param name="res">目标选择的资源</param> /// <returns>目标集合, 不会为null.</returns> public static ArrayList SelectTargets(AttackerAttr attackerAttr, Vector3 centerPosition, float attackerDirection, TargetSelectionTableItem targetSelRes) { BaseScene scn = SceneManager.Instance.GetCurScene(); if (scn == null) { return(null); } SceneShapeRect selRect = null; ArrayList result = null; SceneShape shape = null; switch (targetSelRes.shape) { // 假设目标最大半径为5.0f米 case ShapeType.ShapeType_Round: { float radius = targetSelRes.CircleRadius * 2.0f + 5.0f; selRect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), radius, radius); shape = new SceneShapeRound(new Vector2(centerPosition.x, centerPosition.z), targetSelRes.CircleRadius); } break; case ShapeType.ShapeType_Rect: { float radius = targetSelRes.RectLength + targetSelRes.RectWidth + 5.0f; selRect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), radius, radius); SceneShapeRect rect = new SceneShapeRect(new Vector2(centerPosition.x, centerPosition.z), targetSelRes.RectLength, targetSelRes.RectWidth); shape = SceneShapeUtilities.rotate(rect, new Vector2(centerPosition.x, centerPosition.z), attackerDirection * Mathf.Rad2Deg); } break; case ShapeType.ShapeType_Invalid: break; default: ResourceInvalidParam("targetselection", (uint)targetSelRes.resID, "形状"); break; } if (shape != null && selRect != null) { ArrayList lst = scn.SearchObject(selRect, ObjectType.OBJ_SEARCH_BATTLEUNIT); if (lst != null && lst.Count > 0) { result = new ArrayList(); for (int i = 0; i < lst.Count; i++) { ObjectBase obj = lst[i] as ObjectBase; if (obj == null) { continue; } if (shape.intersect(obj.GetShape())) { result.Add(obj); } } } } if (result == null) { result = new ArrayList(); } // 根据阵营筛选. FilterTargetsBy(result, filterTargetsByLeague, attackerAttr, targetSelRes.leagueSel); // 最多只能选择maxTargetCount个单位. RandomSampling(result, targetSelRes.maxTargetCount); return(result); }