/// <summary> /// 获取索引对应玩家内容信息(ID 和 名字),失败为空 /// </summary> /// <param name="index">索引值</param> /// <returns>返回信息</returns> private GUIContent GetContentByPlayerIndex(int index) { content = new GUIContent(); if (GameMathf.ValueInRange(0, playerInfoList.Count - 1, index)) { content.text = string.Format("ID : {0} Name : {1}", playerInfoList[index].id, playerInfoList[index].name); } return(content); }
public override void SetDefaultValue() { base.SetDefaultValue(); body = target as TankModuleBody; body.leftWheelTop = GameMathf.Round(moduleBounds.center + new Vector3(-moduleBounds.extents.x, -moduleBounds.extents.y, 0)); body.rightWheelTop = GameMathf.Round(moduleBounds.center + new Vector3(moduleBounds.extents.x, -moduleBounds.extents.y, 0)); body.raycastPos = body.anchors.forward; body.forwardUp = new Vector3(body.anchors.forward.x, body.anchors.up.y, body.anchors.forward.z); body.backUp = new Vector3(body.anchors.back.x, body.anchors.up.y, body.anchors.back.z); }
/// <summary> /// 更新按钮冷却时间 /// </summary> private void Update() { if (!UpdateCoolDownAndCheck() || !isCharging) { return; } CurrentValue += Time.deltaTime * chargeRate; sliderFullImg.fillAmount = GameMathf.Persents(minValue, maxValue, CurrentValue); }
/// <summary> /// 设置默认值 /// </summary> virtual public void SetDefaultValue() { module.anchors.center = GameMathf.Round(moduleBounds.center); module.anchors.forward = GameMathf.Round(moduleBounds.center + new Vector3(0, 0, moduleBounds.extents.z)); module.anchors.back = GameMathf.Round(moduleBounds.center + new Vector3(0, 0, -moduleBounds.extents.z)); module.anchors.left = GameMathf.Round(moduleBounds.center + new Vector3(-moduleBounds.extents.x, 0, 0)); module.anchors.right = GameMathf.Round(moduleBounds.center + new Vector3(moduleBounds.extents.x, 0, 0)); module.anchors.up = GameMathf.Round(moduleBounds.center + new Vector3(0, moduleBounds.extents.y, 0)); module.anchors.down = GameMathf.Round(moduleBounds.center + new Vector3(0, -moduleBounds.extents.y, 0)); }
public float tolerance = 1f; // 相对自己停止距离的容差 public override void Act(StateController controller) { // 有目标、没有正在计算路程、眼前捕获到敌人(避免拐角处两个卡死)、两者距离在停留范围内 if (controller.instancePrefs.Contains(CommonCode.ChaseEnemy) && !controller.navMeshAgent.pathPending && (bool)controller.statePrefs[CommonCode.CatchEnemy] == true && GameMathf.TwoPosInRange(((Transform)controller.instancePrefs[CommonCode.ChaseEnemy]).position, controller.transform.position, controller.navMeshAgent.stoppingDistance - tolerance)) { controller.rigidbodySelf.position += -1 * controller.transform.forward.normalized * controller.navMeshAgent.speed * Time.deltaTime; } }
/// <summary> /// 更新轨道位置,以及结束后调用响应事件 /// </summary> private IEnumerator UpdateTrackPosition() { while (director.state != PlayState.Paused) { GameMathf.CopyPositionAndRotation(trackCamera.LookAt, cameraTrackTransfrom); yield return(null); } isPlaying = false; endOfAnimationEvent.Invoke(); yield return(null); }
/// <summary> /// 设置地板纹理物体 /// </summary> /// <returns></returns> public List <GameObject> SetGroundItems(CaveRegion region, uint count, Transform parent) { List <GameObject> objs = new List <GameObject>(); for (int i = 0; i < count; i++) { item = groundItemList.GetRandomItem(); obj = Instantiate(item.prefab, map.GetPosition(region.GetRandomCoord()), Quaternion.Euler(GameMathf.RandomY()), parent); obj.transform.localScale = new Vector3(obj.transform.localScale.x * GameMathf.RandomPlusOrMinus(), obj.transform.localScale.y, obj.transform.localScale.z); objs.Add(obj); } return(objs); }
private void OnDrawGizmos() { if (map) { Gizmos.color = green; Gizmos.DrawCube(Vector3.zero, new Vector3(map.width, 1, map.height)); } Gizmos.color = red; for (int i = 0; i < rooms.Count; i++) { Gizmos.DrawCube(rooms[i].pos, GameMathf.Vec2ToVec3XZ(rooms[i].size)); } }
/// <summary> /// 更新区域所有点的方差和标准差,需要确保更新了平均点 /// </summary> public void UpdateVarianceAndDeviation() { float x = 0, y = 0; for (int i = 0; i < tiles.Count; i++) { x += GameMathf.Pow2(tiles[i].tileX - averageCoord.tileX); y += GameMathf.Pow2(tiles[i].tileY - averageCoord.tileY); } variance = new Vector2(x / tiles.Count, y / tiles.Count); deviation.x = Mathf.Sqrt(variance.x); deviation.y = Mathf.Sqrt(variance.y); }
public float distance = 30f; //停止追逐的最远距离 public override bool Decide(StateController controller) { if (!controller.instancePrefs.Contains(CommonCode.ChaseEnemy)) { controller.UpdateNextWayPoint(true); return(true); } if (!GameMathf.TwoPosInRange(controller.transform.position, ((Transform)controller.instancePrefs[CommonCode.ChaseEnemy]).position, distance)) { controller.instancePrefs.Remove(CommonCode.ChaseEnemy); controller.UpdateNextWayPoint(true); return(true); } return(false); }
// 更新房间边缘瓦片集 public void UpdateEdgeTiles(TileType[,] map) { edgeTiles.Clear(); // 遍历上下左右四格,判断是否有墙 foreach (CaveCoord tile in tiles) { for (int i = 0; i < 4; i++) { int x = tile.tileX + GameMathf.UpDownLeftRight[i, 0]; int y = tile.tileY + GameMathf.UpDownLeftRight[i, 1]; if (GameMathf.XYIsInRange(x, y, map.GetLength(0), map.GetLength(1)) && map[x, y] == TileType.Wall) { edgeTiles.Add(tile); continue; } } } }
public override void Act(StateController controller) { controller.statePrefs.AddIfNotContains(CommonCode.SoucePos, controller.transform.position); controller.statePrefs.AddIfNotContains(CommonCode.FrozenActionCD, new CountDownTimer(checkTime, true)); // 更新倒计时 if (!((CountDownTimer)controller.statePrefs[CommonCode.FrozenActionCD]).IsTimeUp) { return; } // 判断如果过了检测时间后,当前位置和之前位置的距离是否小于限定距离 if (GameMathf.TwoPosInRange((Vector3)controller.statePrefs[CommonCode.SoucePos], controller.transform.position, maxRadius)) { controller.UpdateNextWayPoint(true); } controller.statePrefs[CommonCode.SoucePos] = controller.transform.position; }
//获取该点周围8个点为实体墙(map[x,y] == TileType.Wall)的个数。 private int GetSurroundingWallCount(int gridX, int gridY) { int wallCount = 0; for (int neighbourX = gridX - 1; neighbourX <= gridX + 1; neighbourX++) { for (int neighbourY = gridY - 1; neighbourY <= gridY + 1; neighbourY++) { if (!GameMathf.XYIsInRange(neighbourX, neighbourY, width, height)) // 如果不在地图范围内,直接假定为墙 { wallCount++; } else if (!(neighbourX == gridX && neighbourY == gridY)) // 在范围内,且不是本身的点 { wallCount += map[neighbourX, neighbourY] == TileType.Wall ? 1 : 0; } } } return(wallCount); }
/// <summary> /// 查找半径范围内所有符合条件的对象,并发送信息 /// </summary> private IEnumerator FindAndSend(StateController controller, SignalExpand signal) { while (!signal.Timer.IsTimeUp) { for (int i = 0; i < AllPlayerManager.Instance.Count; i++) { if (AllPlayerManager.Instance[i] != controller.playerManager && AllPlayerManager.Instance[i].gameObject.activeInHierarchy && GameMathf.TwoPosInRange(controller.transform.position, AllPlayerManager.Instance[i].transform.position, signal.CurrentPercent * radius)) { TankManager target = AllPlayerManager.Instance[i] as TankManager; if (target == null) { continue; } switch (acceptType) { case AcceptType.All: break; case AcceptType.Teammates: if (AllPlayerManager.Instance[i].Team != controller.Team) { continue; } break; case AcceptType.Enemy: if (AllPlayerManager.Instance[i].Team == controller.Team) { continue; } break; } target.stateController.statePrefs.AddIfNotContains(CommonCode.BroadcastMessage, messages); } } yield return(null); } }
/// <summary> /// 找到合适的大小 /// </summary> /// <returns></returns> private float FindRequiredSize() { float orthographicSize = 0f; Vector3 desiredPosToTarget; if (actualTargets.Count == 1) // 只有一个就直接返回最小值 { return(minSize); } // 找到最大需要的修改尺寸 for (int i = 0; i < actualTargets.Count; i++) { desiredPosToTarget = GameMathf.Abs(transform.InverseTransformVector(actualTargets[i].position - averagePos)); orthographicSize = Mathf.Max(orthographicSize, desiredPosToTarget.y, desiredPosToTarget.x / camera.aspect); } // 加上边界 orthographicSize += screenEdgeBuffer; orthographicSize = Mathf.Max(orthographicSize, minSize); return(orthographicSize); }
/// <summary> /// 设置主要物件 /// </summary> public GameObject SetMainItems(CaveRegion region, Transform parent) { float scale = 0f; item = mainItemList.GetRandomItem(region.RegionSize, ref scale, approximate); if (item == null) { item = mainItemList.GetRandomItem(region.RegionSize, ref scale, approximate + 1); } pos = map.GetPosition(region.averageCoord) + item.offset; if (item.randomRotationY) { quat = Quaternion.Euler(GameMathf.RandomY()); } else { quat = Quaternion.Euler(0, GameMathf.RandomNumber(0, 180) - GameMathf.RadianToAngle(Mathf.Atan2(region.deviation.y, region.deviation.x)), 0); } obj = Instantiate(item.prefab, pos, quat, parent); obj.transform.localScale = Vector3.one * scale; return(obj); }
} // 宽高比 /// <summary> /// 获取随机缩放值 /// </summary> public Vector3 GetRandomScale() { return(GameMathf.RandomVector3(minScale, maxScale)); }
/// <summary> /// 获取目标的血条,计算扣血量并给给扣血。 /// </summary> /// <param name="targetHealth">目标的血条</param> protected void TakeDamage(HealthManager targetHealth) { // 计算目标距离爆炸中心比例值(0 ~ 1,0为中),越靠近伤害越大,线性的 targetHealth.SetHealthAmount(-1 * Mathf.Max(0f, GameMathf.Persents(explosionRadius, 0, (targetHealth.transform.position - transform.position).magnitude) * damage), launcher); }