• 【Unity3D】Tank对战


    1 需求实现

            项目代码见→坦克大战1.1.0

            1)人机交互

    • 玩家通过 ↑ ↓ ← → 键(或 W、S、A、D)键控制己方坦克平移
    • 玩家通过滑动鼠标右键控制己方坦克左右旋转
    • 玩家通过鼠标左键(或空格键)控制己方坦克发射炮弹
    • 玩家通过 ESC 键控制窗口全屏恢复
    • 玩家通过 Q 键控制退出游戏

            2)相机

    • 主相机跟随:主相机始终在玩家后上方的位置,并保持与玩家的相对位置不变;
    • 次相机实现小地图:次相机俯拍战场,并将影像在屏幕右上角显示;
    • 单击小地图,小地图全屏,再单击,小地图恢复,在全屏和恢复的过程中有缩放动效

            3)坦克属性

    • 坦克属性:血量、移动速度、旋转速度、颜色、初始位置、初始方位。

            4)炮弹属性

    • 炮弹属性:伤害、飞行速度、冷却时间、射程、颜色。

            5)敌方坦克生成策略

    • 敌方坦克根据能力值分三个级别,对应比例为 3:2:1,颜色分别为灰、浅蓝、黄;
    • 敌方坦克初始生成 10 个,之后每隔 2 秒生成一个,总共 50 个坦克;
    • 敌方坦克生成位置和朝向都是随机的,并且能够保证坦克位置不会重叠

            6)敌方坦克作战策略

    • 转向再开炮:玩家在敌方坦克 0.5 倍射程范围内,敌方坦克转向玩家,再向玩家开炮;
    • 转向再靠近并开炮:玩家在敌方坦克 1 倍射程范围内,敌方坦克转向玩家,再向玩家移动,同时向玩家开炮
    • 转向再靠近:玩家在敌方坦克 1.5 倍射程范围内,敌方坦克转向玩家,再向玩家移动;
    • 随机巡逻:玩家在敌方坦克在 1.5 倍射程范围外,敌方坦克随机巡逻:将其 10 ~ 30米外的随机一处位置作为目标位置,转向目标位置,再向目标位置移动;如果到中途满足以上条件,则执行相应操作;如果不满足,继续向目标位置移动;如果中途发现前方 5 米范围内有友军,重新换一个目标位置继续巡逻;如果达到目标位置仍不满足以上条件,再换一个目标位置继续巡逻。

            7)血条

    • 玩家血条显示在屏幕左上角,玩家被命中时,扣除相应血量,血量进度条向左滑动,血量比例更新;
    • 敌方坦克血条显示在坦克的上方,随坦克一起运动,坦克被命中时,血量进度条向左滑动;
    • 敌方坦克在运动时,其血条始终朝向主相机

            8)杀敌计数

    • 在屏幕左上角、玩家血条下方显示杀敌计数

            9)摇杆

    • 摇杆显示在屏幕左下角,拖拽摇杆可以控制己方坦克平移
    • ↑ ↓ ← → 键(或 W、S、A、D 键)除了能控制己方坦克平移,还能控制摇杆移动

            10)死亡策略

    • 坦克在死亡时,停止运动并停止发射炮弹,渐变为透明
    • 己方坦克死亡时,生成一个空对象替换己方坦克,使得玩家可以通过 ↑ ↓ ← → 键(或 W、S、A、D 键)及鼠标右键,继续查看战场

    2 相关技术栈

    3 游戏对象

            1)游戏界面

            2)游戏对象层级结构

            Hierarchy 窗口游戏对象:

             预设体游戏对象:

            3)Transform组件参数

            1. Tank Transform 组件参数

    NameTypePositionRotationScale
    TankEmpty(0, 0.25, 0)(0, 0, 0)(1, 1, 1)
    BottonCube(0, 0, 0)(0, 0, 0)(2, 0.5, 2)
    TopCube(0, 0.5, 0)(0, 0, 0)(1, 0.5, 1)
    GunCylinder(0, 0, 1.5)(90, 0, 0)(0.2, 1, 0.4)
    FirePointEmpty(0, 1.15, 0)(0, 0, 0)(1, 1, 1)

            补充:Tank 游戏对象添加了刚体组件,并修改 Mass = 100,Drag = 1,AngularDrag = 0.5,Tank 作为预设体拖拽到 Assets/Resources/Prefabs 目录下,敌方坦克和己方坦克共用 Tank 预设体。

            2. 玩家 Blood RectTransform 组件参数

    NameTypePosWidth/HeightAnchorsPivotColor/Texture
    BloodEmpty(25, -30, 0)(0, 0)(0, 1), (0, 1)(0.5, 0.5)——
    ProgressEmpty(45, 0, 0)(0, 0)(0, 0.5), (0, 0.5)(0, 0.5)——
    BackgroundImage(0, 0, 0)(200, 20)(0, 0.5), (0, 0.5)(0, 0.5)#FFFFFFFF
    ValueImage(0, 0, 0)(200, 20)(0, 0.5), (0, 0.5)(0, 0.5)#F63C3CFF
    RateText(5, 0, 0)(60, 30)(0, 0.5), (0, 0.5)(0, 0.5)——
    DescriptionText(0, 0, 0)(50, 20)(0, 0.5), (0, 0.5)(0, 0.5)——

            补充:Value 的 ImageType 设置为 Filled,Fill Method 设置为 Horizontal,Fill Origin 设置为 Left。

            3. Kill RectTransform 组件参数

    NameTypePosWidth/HeightAnchorsPivotColor/Texture
    KillEmpty(25, -60, 0)(0, 0)(0, 1), (0, 1)(0.5, 0.5)——
    ProgressEmpty(45, 0, 0)(0, 0)(0, 0.5), (0, 0.5)(0, 0.5)——
    BackgroundImage(0, 0, 0)(200, 20)(0, 0.5), (0, 0.5)(0, 0.5)#FFFFFFFF
    ValueImage(0, 0, 0)(200, 20)(0, 0.5), (0, 0.5)(0, 0.5)#3CB8F6FF
    RateText(5, 0, 0)(60, 30)(0, 0.5), (0, 0.5)(0, 0.5)——
    DescriptionText(0, 0, 0)(50, 20)(0, 0.5), (0, 0.5)(0, 0.5)——

            补充:Value 的 ImageType 设置为 Filled,Fill Method 设置为 Horizontal,Fill Origin 设置为 Left。

            4. Stick RectTransform 组件参数

    NameTypePosWidth/HeightAnchorsPivotSprite
    StickEmpty(75, 70, 0)(0, 0)(0, 0), (0, 0)(0.5, 0.5)——
    BackgroundImage(0, 0, 0)(100, 100)(0.5, 0.5), (0.5, 0.5)(0.5, 0.5)stick_bg
    BallImage(0, 0, 0)(40, 40)(0.5, 0.5), (0.5, 0.5)(0.5, 0.5)stick_ball

            5. 敌人 Blood RectTransform 组件参数

    NameTypePosWidth/HeightColor/Texture
    BloodCanvas(0, 0.85, 0)(2, 0.2)——
    BackgroundImage(0, 0, 0)(2, 0.2)#FFFFFFFF
    ValueImage(0, 0, 0)(2, 0.2)#F63C3CFF

            补充: 敌人 Blood 的 Canvas 渲染模式是 World Space,Value 的 ImageType 设置为 Filled,Fill Method 设置为 Horizontal,Fill Origin 设置为 Right。

            6. Plane、Bullet、MinimapCamera Transform 组件参数

    NameTypePositionRotationScaleColor/Texture
    PlanePlane(0, 0, 0)(0, 0, 0)(10, 10, 10)GrassRockyAlbedo
    BulletSphere(0, 0.5, -5)(0, 0, 0)(0.3, 0.3, 0.3)#228439FF
    MinimapCameraCamera(0, 12, 0)(90, 0, 0)(1, 1, 1)——

            补充:Bullet 作为预设体拖拽到 Assets/Resources/Prefabs 目录下,并且添加了刚体组件,己方坦克和敌方坦克使用的炮弹预设体都是 Bullet;MinimapCamera 是次相机,用于渲染小地图,其Viewport Rect 为 (0.8, 0.7, 0.2, 0.3)。

    4 游戏框架

    5 代码实现

            BaseCreater.cs

    1. using System;
    2. using UnityEngine;
    3. public class BaseCreater : MonoBehaviour {
    4. protected GameObject tankPrefab; // 坦克预设体
    5. protected Action dyingAction; // 死亡活动
    6. protected void LoadPrefab() { // 加载预设体
    7. tankPrefab = (GameObject) Resources.Load("Prefabs/Tank");
    8. }
    9. protected GameObject CreateTank(TankInfo info) { // 创建坦克
    10. GameObject tank = Instantiate(tankPrefab, info.tankInitPosition, Quaternion.Euler(info.tankInitRotation));
    11. tank.name = info.GetName();
    12. UpdateColor(tank, info.tankColor);
    13. return tank;
    14. }
    15. private void UpdateColor(GameObject tank, Color color) { // 更新坦克颜色
    16. ForAllChildren(tank, obj => {
    17. MeshRenderer renderer = obj.GetComponent();
    18. if (renderer != null) {
    19. renderer.material.color = color;
    20. }
    21. });
    22. }
    23. private void ForAllChildren(GameObject obj, Action action) { // 每个子孙对象(包含自己)执行委托动作
    24. if (obj == null) {
    25. return;
    26. }
    27. foreach(Transform child in obj.GetComponentsInChildren()) {
    28. action(child.gameObject);
    29. }
    30. }
    31. }

            PlayerCreater.cs

    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class PlayerCreater : BaseCreater {
    5. [Header("坦克信息")]
    6. public TankInfo tankInfo;
    7. private void Awake() {
    8. LoadPrefab();
    9. tankInfo = TankParamsManager.GetInstance().GetPlayerTankInfo();
    10. GameObject tank = CreateTank(tankInfo);
    11. dyingAction += () => {
    12. Camera.main.GetComponent().PlayerDying(); // 玩家死亡, 相机重新跟随一个空对象
    13. };
    14. tank.AddComponent()
    15. .SetDiedAction(dyingAction)
    16. .SetTankInfo(tankInfo);
    17. }
    18. }

            说明:PlayerCreater 脚本组件挂在 PlayerCreater 游戏对象上。

            EnemyCreater.cs

    1. using System;
    2. using UnityEngine;
    3. public class EnemyCreater : BaseCreater {
    4. protected GameObject bloodPrefab; // 血条预设体
    5. public EnemiesInfo enemiesInfo = null;
    6. private Transform player; // 玩家
    7. private KillHelper killHelper; // 杀敌助手
    8. private float waitTime = 0; // 距离上次坦克生成已等待的时间
    9. private void Awake() {
    10. LoadPrefab();
    11. enemiesInfo = new EnemiesInfo();
    12. killHelper = new KillHelper(enemiesInfo.GetTotalNum());
    13. dyingAction += () => {
    14. enemiesInfo.CurrDes();
    15. killHelper.KillEnemy();
    16. };
    17. }
    18. private void Start() {
    19. player = GameObject.Find("Player/Top").transform;
    20. CreateInitEnemies();
    21. }
    22. private void Update() {
    23. if (waitTime > EnemiesInfo.ENTER_INTERVAL && enemiesInfo.GetAppeardNum() < EnemiesInfo.TOTAL_NUM) {
    24. CreateTank();
    25. waitTime = 0;
    26. }
    27. waitTime += Time.deltaTime;
    28. }
    29. protected new void LoadPrefab() { // 加载预设体
    30. base.LoadPrefab();
    31. bloodPrefab = (GameObject) Resources.Load("Prefabs/Blood");
    32. }
    33. private void CreateInitEnemies() {
    34. for (int i = 0; i < EnemiesInfo.INIT_NUM; i++) {
    35. CreateTank();
    36. }
    37. }
    38. private GameObject CreateTank() { // 创建坦克
    39. int level = enemiesInfo.GetRandomLevel();
    40. TankInfo tankInfo = TankParamsManager.GetInstance().GetEnemyTankInfo(level);
    41. Vector3 position = GetEnemyPosition();
    42. Vector3 rotation = GetEnemyRotation();
    43. tankInfo.tankInitPosition = position;
    44. tankInfo.tankInitRotation = rotation;
    45. GameObject tank = CreateTank(tankInfo);
    46. CreateHealth(tank);
    47. tank.AddComponent()
    48. .SetPlayer(player)
    49. .SetDiedAction(dyingAction)
    50. .SetTankInfo(tankInfo);
    51. enemiesInfo.CurrAdd();
    52. return tank;
    53. }
    54. private Vector3 GetEnemyPosition() { // 获取敌人随机位置
    55. Vector3 position = new Vector3(0f, 0.25f, 0f);
    56. do {
    57. position.x = UnityEngine.Random.Range(-49f, 49f);
    58. position.z = UnityEngine.Random.Range(-49f, 49f);
    59. } while (IsOccupied(position));
    60. return position;
    61. }
    62. private Vector3 GetEnemyRotation() { // 获取敌人随机方向
    63. int y = UnityEngine.Random.Range(0, 360);
    64. return new Vector3(0, y, 0);
    65. }
    66. private bool IsOccupied(Vector3 pos) { // 检测指定位置是否被占用
    67. Vector3 halfExtents = new Vector3(2, 0.1f, 2);
    68. return Physics.CheckBox(pos, halfExtents);
    69. }
    70. private void CreateHealth(GameObject tank) { // 创建血条
    71. Vector3 pos = tank.transform.position;
    72. Vector3 realPos = new Vector3(pos.x, pos.y + 1.5f, pos.z);
    73. GameObject blood = Instantiate(bloodPrefab, realPos, Quaternion.identity, tank.transform);
    74. blood.name = "Blood";
    75. }
    76. }

            说明:EnemyCreater 脚本组件挂在 EnemyCreater 游戏对象上。

            TankController.cs

    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class TankController : MonoBehaviour {
    5. protected TankInfo tankInfo; // 坦克信息
    6. protected GameObject bulletPrefab; // 炮弹预设体
    7. protected Transform firePoint; // 开火点
    8. protected BloodHelper bloodHelper; // 血量助手
    9. protected float fireWaitTime = float.MaxValue; // 距离上次开火已等待的时间
    10. protected volatile bool isDying = false; // 死亡中
    11. protected Action diedAction; // 敌人死亡活动
    12. protected void LoadBullet() {
    13. bulletPrefab = (GameObject) Resources.Load("Prefabs/Bullet");
    14. firePoint = transform.Find("Top/Gun/FirePoint");
    15. }
    16. public TankController SetTankInfo(TankInfo info) {
    17. tankInfo = info;
    18. return this;
    19. }
    20. public TankController SetDiedAction(Action action) {
    21. diedAction = action;
    22. return this;
    23. }
    24. protected void Fire() { // 开炮
    25. if (fireWaitTime > tankInfo.bullet.bulletCoolTime) {
    26. BulletInfo info = tankInfo.bullet.Clone() as BulletInfo;
    27. info.SetFlyDir(transform.forward);
    28. GameObject bullet = Instantiate(bulletPrefab, firePoint.position, Quaternion.identity);
    29. bullet.AddComponent().SetBulletInfo(info);
    30. fireWaitTime = 0f;
    31. }
    32. }
    33. public void BuckleBlood(int damage) { // 扣血
    34. isDying = bloodHelper.BuckleBlood(damage);
    35. }
    36. public bool IsDying() {
    37. return isDying;
    38. }
    39. protected void Dying() { // 坦克死亡中, 渐变为透明
    40. ForAllChildren(gameObject, obj => {
    41. Renderer renderer = obj.GetComponent();
    42. if (renderer != null) {
    43. Color color = renderer.material.color;
    44. // 材质球的 Rendering Mode 需要设置为 Fade 或 Transparent, 渐变才会生效
    45. renderer.material.color = new Color(color.r, color.g, color.b, color.a - Time.deltaTime / 3);
    46. }
    47. Image image = obj.GetComponent();
    48. if (image != null) {
    49. Color color = image.color;
    50. image.color = new Color(color.r, color.g, color.b, color.a - Time.deltaTime / 3);
    51. }
    52. });
    53. }
    54. protected bool CheckFallDeath() { // 检验摔死
    55. if (!isDying && transform.position.y < -5) {
    56. isDying = true;
    57. Destroy(gameObject, 3);
    58. diedAction.Invoke();
    59. return true;
    60. }
    61. return false;
    62. }
    63. protected void ForAllChildren(GameObject obj, Action action) { // 每个子孙对象(包含自己)执行委托动作
    64. if (obj == null) {
    65. return;
    66. }
    67. foreach(Transform child in obj.GetComponentsInChildren()) {
    68. action(child.gameObject);
    69. }
    70. }
    71. }

            PlayerController.cs

    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class PlayerController : TankController {
    5. private MoveHelper moveHelper; // 交互助手
    6. private StickController stick; // 摇杆控制器
    7. private void Awake() {
    8. LoadBullet();
    9. stick = GameObject.Find("UI/Stick/Ball").GetComponent();
    10. moveHelper = new MoveHelper(transform);
    11. }
    12. private void Start() {
    13. diedAction += () => {
    14. stick.PlayerDying();
    15. };
    16. moveHelper.Init(tankInfo.tankMoveSpeed, tankInfo.tankRotateSpeed);
    17. LoadBlood();
    18. }
    19. private void Update() {
    20. if (isDying || CheckFallDeath()) {
    21. Dying();
    22. return;
    23. }
    24. fireWaitTime += Time.deltaTime;
    25. moveHelper.Move();
    26. moveHelper.Rotate();
    27. if (Input.GetMouseButtonDown(0) && !stick.IsMouseInStickArea()
    28. || Input.GetKeyDown(KeyCode.Space)) {
    29. Fire();
    30. }
    31. }
    32. private void LoadBlood() {
    33. Image bloodValueImg = GameObject.Find("UI/Blood/Progress/Value").GetComponent();
    34. Text bloodRateTxt = GameObject.Find("UI/Blood/Progress/Rate").GetComponent();
    35. bloodHelper = new BloodHelper(bloodValueImg, bloodRateTxt, tankInfo, diedAction);
    36. }
    37. public void Move(float hor, float ver) { // 坦克移动
    38. moveHelper.Move(hor, ver);
    39. }
    40. }

            说明:PlayerController 脚本组件挂在 Player 游戏对象上。

            EnemyController.cs

    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class EnemyController : TankController {
    5. private Transform player; // 玩家
    6. private Transform top; // 炮头
    7. private Vector3 tempTarget; // 临时目标点,巡逻时使用
    8. private bool isFoundPlayer = false; // 是否发现了玩家
    9. private float findTargetTime = 0; // 巡逻时寻找目标花费的时间
    10. private void Awake() {
    11. LoadBullet();
    12. top = transform.Find("Top");
    13. Vector3 pos = top.position;
    14. tempTarget = new Vector3(pos.x, pos.y, pos.z);
    15. }
    16. private void Start(){
    17. LoadBlood();
    18. }
    19. private void Update() {
    20. if (isDying || CheckFallDeath()) {
    21. Dying();
    22. return;
    23. }
    24. bloodHelper.BloodLookAtCamera();
    25. float distance = GetDistance();
    26. if (distance < 1.5f * tankInfo.bullet.bulletFireRange) { // 发现了玩家
    27. if (distance < tankInfo.bullet.bulletFireRange / 2 || distance < 5) {
    28. Fire();
    29. } else if (distance < tankInfo.bullet.bulletFireRange) {
    30. MoveToTarget(player.position);
    31. Fire();
    32. } else {
    33. MoveToTarget(player.position);
    34. }
    35. isFoundPlayer = true;
    36. findTargetTime = 0;
    37. } else {
    38. Patrol();
    39. isFoundPlayer = false;
    40. }
    41. fireWaitTime += Time.deltaTime;
    42. }
    43. public EnemyController SetPlayer(Transform transform) {
    44. player = transform;
    45. return this;
    46. }
    47. protected new void Fire() { // 开炮
    48. if (LookAtTarget(player.position)) {
    49. base.Fire();
    50. }
    51. }
    52. private bool LookAtTarget(Vector3 target) { // 转向目标
    53. Vector3 dir = target - top.position;
    54. float angle = Vector3.Angle(dir, top.forward);
    55. if (angle > 5) {
    56. int axis = Vector3.Dot(Vector3.Cross(dir, top.forward), Vector3.up) > 0 ? -1 : 1;
    57. GetComponent().angularVelocity = axis * Vector3.up * tankInfo.tankRotateSpeed;
    58. return false;
    59. }
    60. GetComponent().angularVelocity = Vector3.zero;
    61. return true;
    62. }
    63. private void MoveToTarget(Vector3 target) { // 向目标移动
    64. if (LookAtTarget(target)) {
    65. Vector3 dir = (target - top.position).normalized;
    66. GetComponent().velocity = tankInfo.tankMoveSpeed * dir;
    67. findTargetTime += Time.deltaTime;
    68. }
    69. }
    70. private void Patrol() { // 巡逻
    71. GetNextPatrolTarget();
    72. MoveToTarget(tempTarget);
    73. }
    74. private float GetDistance() { // 获取坦克距离玩家的距离
    75. if (player == null) {
    76. return float.MaxValue;
    77. }
    78. return Vector3.Distance(player.position, top.position);
    79. }
    80. private void GetNextPatrolTarget() { // 获取下一个巡逻目标点
    81. if (isFoundPlayer || Vector3.Distance(tempTarget, top.position) < 0.1f
    82. || ForwardHasFriends() && findTargetTime > 1) {
    83. float angle = top.eulerAngles.y + UnityEngine.Random.Range(-120f, 120f);
    84. angle = angle * Mathf.PI / 180f;
    85. float radius = UnityEngine.Random.Range(10f, 30f);
    86. tempTarget.x = Mathf.Clamp(top.position.x + radius * Mathf.Cos(angle), -49, 49);
    87. tempTarget.z = Mathf.Clamp(top.position.z + radius * Mathf.Sin(angle), -49, 49);
    88. findTargetTime = 0;
    89. }
    90. }
    91. private bool ForwardHasFriends() { // 前方有友军
    92. return Physics.BoxCast(top.position, new Vector3(1, 0.5f, 1), top.forward, top.rotation, 5, ~(1 << 8));
    93. }
    94. private void LoadBlood() {
    95. Transform blood = transform.Find("Blood");
    96. Image bloodValueImg = blood.Find("Value").GetComponent();
    97. bloodHelper = new BloodHelper(bloodValueImg, null, tankInfo, diedAction);
    98. bloodHelper.setTransform(blood);
    99. }
    100. }

            说明:EnemyController 脚本组件挂在 Enemy 游戏对象上。

            BulletController.cs

    1. using UnityEngine;
    2. public class BulletController : MonoBehaviour {
    3. private BulletInfo bulletInfo; // 炮弹信息
    4. private bool isDying = false;
    5. private void Start () {
    6. GetComponent().material.color = bulletInfo.bulletColor;
    7. float lifeTime = bulletInfo.bulletFireRange / bulletInfo.bulletSpeed; // 存活时间
    8. Destroy(gameObject, lifeTime);
    9. }
    10. private void Update () {
    11. transform.GetComponent().velocity = bulletInfo.GetFlyDir() * bulletInfo.bulletSpeed;
    12. }
    13. private void OnCollisionEnter(Collision other) {
    14. TankController tankController = other.gameObject.GetComponent();
    15. if (isDying || tankController == null || tankController.IsDying()) {
    16. return;
    17. }
    18. if (isHitEnemy(bulletInfo.GetName(), other.gameObject.name)
    19. || isHitPlayer(bulletInfo.GetName(), other.gameObject.name)) {
    20. tankController.BuckleBlood(bulletInfo.bulletDamage);
    21. if (tankController.IsDying()) {
    22. Destroy(other.gameObject, 3f);
    23. }
    24. }
    25. isDying = true;
    26. Destroy(gameObject, 0.3f);
    27. }
    28. public void SetBulletInfo(BulletInfo info) {
    29. bulletInfo = info;
    30. }
    31. private bool isHitEnemy(string bulletName, string roleName) { // 击中敌军
    32. return "PlayerBullet".Equals(bulletName) && "Enemy".Equals(roleName);
    33. }
    34. private bool isHitPlayer(string bulletName, string roleName) { // 击中玩家
    35. return "EnemyBullet".Equals(bulletName) && "Player".Equals(roleName);
    36. }
    37. }

            说明:BulletController 脚本组件挂在 Bullet 游戏对象上。

            CameraController.cs

    1. using UnityEngine;
    2. public class CameraController : MonoBehaviour {
    3. protected Transform player; // 玩家
    4. protected Transform visitor; // 游客
    5. protected Vector3 relaPlayerPos; // 相机在玩家坐标系中的位置
    6. protected void InitPlayer() {
    7. GameObject obj = GameObject.Find("Player/Top");
    8. if (obj != null) {
    9. player = obj.transform;
    10. CompCameraPos(player);
    11. }
    12. }
    13. public void PlayerDying() { // 玩家死亡时, 游客替换玩家的位置, 使相机跟随游客
    14. GameObject visitorObj = new GameObject("Visitor");
    15. visitorObj.AddComponent();
    16. visitor = visitorObj.transform;
    17. visitor.position = player.position;
    18. visitor.rotation = player.rotation;
    19. player = null;
    20. }
    21. protected Transform getVisitor() { // 给小地图相机使用
    22. GameObject visitorObj = GameObject.Find("Visitor");
    23. if (visitorObj != null) {
    24. return visitorObj.transform;
    25. }
    26. return visitor;
    27. }
    28. // 求以origin为原点, locX, locY, locZ 为坐标轴的本地坐标系中的向量 vec 在世界坐标系中对应的向量
    29. protected Vector3 transformVecter(Vector3 vec, Vector3 origin, Vector3 locX, Vector3 locY, Vector3 locZ) {
    30. return vec.x * locX + vec.y * locY + vec.z * locZ + origin;
    31. }
    32. protected void CompCameraPos(Transform target) { // 计算相机位置
    33. }
    34. }

            MainCameraController.cs

    1. using UnityEngine;
    2. public class MainCameraController : CameraController {
    3. private float targetDistance = 30f; // 相机看向玩家前方的位置
    4. private void Start() {
    5. relaPlayerPos = new Vector3(0, 8, -12);
    6. InitPlayer();
    7. }
    8. private void LateUpdate() {
    9. if (player != null) {
    10. CompCameraPos(player);
    11. } else if (visitor == null) {
    12. visitor = getVisitor();
    13. } else {
    14. CompCameraPos(visitor);
    15. }
    16. }
    17. protected new void CompCameraPos(Transform target) { // 计算相机坐标
    18. transform.position = transformVecter(relaPlayerPos, target.position, target.right, target.up, target.forward);
    19. if (transform.position.y < 0) { // 避免坦克翻面时相机朝天
    20. transform.position = new Vector3(transform.position.x, -transform.position.y, transform.position.z);
    21. }
    22. Vector3 lookPos = target.position + target.forward * targetDistance;
    23. if (lookPos .y > 1) { // 避免坦克扬起时相机朝天
    24. lookPos = new Vector3(lookPos.x, 1, lookPos.z);
    25. }
    26. transform.rotation = Quaternion.LookRotation(lookPos - transform.position);
    27. }
    28. }

            说明:MainCameraController 脚本组件挂在 MainCamera 游戏对象上。 

            MinimapCameraController.cs

    1. using UnityEngine;
    2. public class MinimapCameraController : CameraController {
    3. private CameraController mainCamera;
    4. private bool isFullscreen = false; // 小地图相机是否全屏
    5. private Rect minViewport; // 小地图视口位置和大小(相对值)
    6. private Rect fullViewport; // 全屏时视口位置和大小(相对值)
    7. private Rect targetViewport; // 目标视口大小, 用于动效
    8. private float switchRectInternal = 0.3f; // 切换小地图尺寸时间间隔
    9. private float switchWaitTime = float.MaxValue; // 切换小地图等待时间
    10. private bool isSwitching = false; // 切换中, 用于标记执行切换动效中
    11. private void Start() {
    12. mainCamera = Camera.main.GetComponent();
    13. minViewport = GetComponent().rect;
    14. fullViewport = new Rect(0, 0, 1, 1);
    15. relaPlayerPos = new Vector3(0, 50, 0);
    16. InitPlayer();
    17. }
    18. private void Update() {
    19. switchWaitTime += Time.deltaTime;
    20. if (switchWaitTime > switchRectInternal && !isSwitching) {
    21. SwitchRect();
    22. }
    23. if (isSwitching) {
    24. SwitchAnimation();
    25. }
    26. }
    27. private void LateUpdate() {
    28. if (player != null) {
    29. CompCameraPos(player);
    30. } else if (visitor == null) {
    31. visitor = getVisitor();
    32. } else {
    33. CompCameraPos(visitor);
    34. }
    35. }
    36. private void SwitchRect() { // 切换小地图尺寸
    37. if (Input.GetMouseButtonDown(0) && IsClickMinimap()) {
    38. if (isFullscreen) { // 小地图缩小
    39. targetViewport = minViewport;
    40. } else { // 小地图放大
    41. targetViewport = fullViewport;
    42. }
    43. isFullscreen = !isFullscreen;
    44. isSwitching = true;
    45. switchWaitTime = 0;
    46. }
    47. }
    48. private void SwitchAnimation() { // 切换动效
    49. Rect rect = GetComponent().rect;
    50. rect.position = Vector2.Lerp(rect.position, targetViewport.position, 0.5f);
    51. rect.size = Vector2.Lerp(rect.size, targetViewport.size, 0.5f);
    52. GetComponent().rect = rect;
    53. if (Vector2.Distance(rect.position, targetViewport.position) < 0.01f) {
    54. GetComponent().rect = targetViewport;
    55. isSwitching = false;
    56. }
    57. }
    58. protected new void CompCameraPos(Transform target) { // 计算相机坐标
    59. transform.position = target.position + relaPlayerPos;
    60. }
    61. public bool IsClickMinimap() { // 是否单击到小地图区域
    62. Vector3 pos = Input.mousePosition;
    63. if (isFullscreen || isSwitching) {
    64. return true;
    65. }
    66. if (pos.x / Screen.width > minViewport.xMin && pos.y / Screen.height > minViewport.yMin) {
    67. return true;
    68. }
    69. return false;
    70. }
    71. }

            说明:MinimapCameraController 脚本组件挂在 MinimapCamera 游戏对象上。

            VisitorController.cs

    1. using UnityEngine;
    2. public class VisitorController : MonoBehaviour {
    3. private MoveHelper moveHelper; // 交互助手
    4. private void Awake() {
    5. moveHelper = new MoveHelper(transform);
    6. moveHelper.Init(6, 10);
    7. }
    8. private void Update() {
    9. moveHelper.Move();
    10. moveHelper.Rotate();
    11. }
    12. }

            说明:VisitorController 脚本组件挂在 Visitor 游戏对象上。

            StickController.cs

    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3. public class StickController : MonoBehaviour, IDragHandler, IEndDragHandler {
    4. private Vector3 originPos; // 鼠标开始拖拽时位置
    5. private Vector3 currPos; // 鼠标当前位置
    6. private float radius; // 遥杆半径
    7. private PlayerController player; // 玩家控制器
    8. private Vector3 dire = Vector3.zero; // 摇杆球的方位
    9. private void Start () {
    10. originPos = transform.position;
    11. radius = 50;
    12. player = GameObject.Find("Player").GetComponent();
    13. }
    14. private void Update () {
    15. if (player != null && !Vector3.zero.Equals(dire)) {
    16. player.Move(dire.x, dire.y);
    17. }
    18. }
    19. public void OnDrag(PointerEventData eventData) {
    20. Vector3 vec = Input.mousePosition - originPos;
    21. dire = vec.normalized * Mathf.Min(vec.magnitude / radius, 1);
    22. UpdateStick(dire);
    23. }
    24. public void OnEndDrag(PointerEventData eventData) {
    25. transform.position = originPos;
    26. dire = Vector3.zero;
    27. }
    28. public void UpdateStick(Vector3 dire) { // 更新摇杆位置
    29. transform.position = originPos + dire * radius;
    30. }
    31. public void PlayerDying() {
    32. player = null;
    33. UpdateStick(Vector3.zero);
    34. }
    35. public bool IsMouseInStickArea() { // 鼠标在Stick区域
    36. Vector3 pos = Input.mousePosition;
    37. return pos.x < 150 && pos.y < 150;
    38. }
    39. }

            说明:StickController 脚本组件挂在 Stick 游戏对象上。

            BloodHelper.cs

    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. public class BloodHelper {
    5. private Transform transform; // 血条Transform
    6. private Image bloodValueImg; // 血条Image
    7. private Text bloodRateTxt; // 血量比率Text
    8. private TankInfo tankInfo; // 坦克信息
    9. private Action diedAction; // 死亡活动
    10. public BloodHelper(Image bloodValueImg, Text bloodRateTxt, TankInfo tankInfo, Action diedAction) {
    11. this.bloodValueImg = bloodValueImg;
    12. this.bloodRateTxt = bloodRateTxt;
    13. this.tankInfo = tankInfo;
    14. this.diedAction = diedAction;
    15. bloodValueImg.fillAmount = 1;
    16. if (bloodRateTxt != null) {
    17. bloodRateTxt.text = "" + tankInfo.GetFullBlood() + " / " + tankInfo.GetFullBlood();
    18. }
    19. }
    20. public bool BuckleBlood(int damage) { // 扣血
    21. bloodValueImg.fillAmount = tankInfo.BuckleBlood(damage);
    22. if (bloodRateTxt != null) {
    23. bloodRateTxt.text = "" + tankInfo.GetCurrBlood() + " / " + tankInfo.GetFullBlood();
    24. }
    25. bool isDying = tankInfo.IsDying();
    26. if (isDying) {
    27. diedAction.Invoke();
    28. }
    29. return isDying;
    30. }
    31. public void setTransform(Transform transform) {
    32. this.transform = transform;
    33. }
    34. public void BloodLookAtCamera() { // 血条朝向相机
    35. Vector3 cameraPos = Camera.main.transform.position;
    36. Vector3 target = new Vector3(cameraPos.x, transform.position.y, cameraPos.z);
    37. transform.LookAt(target);
    38. }
    39. }

            KillHelper.cs

    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. public class KillHelper {
    4. private Image killValueImg; // 杀敌Image
    5. private Text killRateTxt; // 杀敌比率Text
    6. private int enemiesNum; // 敌人总数
    7. private int currKillEnemies; // 当前杀敌数
    8. public KillHelper(int enemiesNum) {
    9. this.enemiesNum = enemiesNum;
    10. currKillEnemies = 0;
    11. killValueImg = GameObject.Find("UI/Kill/Progress/Value").GetComponent();
    12. killRateTxt = GameObject.Find("UI/Kill/Progress/Rate").GetComponent();
    13. UpdateUI();
    14. }
    15. public void KillEnemy() { // 杀敌
    16. lock(this) {
    17. currKillEnemies++;
    18. UpdateUI();
    19. }
    20. }
    21. private void UpdateUI() {
    22. killValueImg.fillAmount = 1.0f * currKillEnemies / enemiesNum;
    23. killRateTxt.text = "" + currKillEnemies + " / " + enemiesNum;
    24. }
    25. }

            MoveHelper.cs

    1. using UnityEngine;
    2. public class MoveHelper {
    3. private Transform transform; // 交互对象的变换组件
    4. protected StickController stick; // 摇杆控制器
    5. private Vector3 predownMousePoint; // 鼠标右键按下时的位置
    6. private Vector3 currMousePoint; // 鼠标右键滑动过程中的位置
    7. private float moveSpeed; // 移动速度
    8. private float rotateSpeed; // 旋转速度
    9. public MoveHelper(Transform transform) {
    10. this.transform = transform;
    11. stick = GameObject.Find("UI/Stick/Ball").GetComponent();
    12. }
    13. public void Init(float moveSpeed, float rotateSpeed) {
    14. this.moveSpeed = moveSpeed;
    15. this.rotateSpeed = rotateSpeed;
    16. }
    17. public void Move() { // 移动
    18. float hor = Input.GetAxis("Horizontal");
    19. float ver = Input.GetAxis("Vertical");
    20. Move(hor, ver);
    21. if (Mathf.Abs(hor) > float.Epsilon || Mathf.Abs(ver) > float.Epsilon) {
    22. updateStick(hor, ver);
    23. }
    24. }
    25. public void Move(float hor, float ver) { // 移动
    26. if (Mathf.Abs(hor) > float.Epsilon || Mathf.Abs(ver) > float.Epsilon) {
    27. Rigidbody rigidbody = transform.GetComponent();
    28. if (rigidbody != null) {
    29. Vector3 vec = transform.forward * ver + transform.right * hor;
    30. rigidbody.velocity = vec * moveSpeed;
    31. } else {
    32. transform.Translate(new Vector3(hor, 0, ver) * Time.deltaTime * moveSpeed);
    33. }
    34. RestrictBoundary();
    35. }
    36. }
    37. public void Rotate() { // 旋转
    38. if (Input.GetMouseButtonDown(1)) {
    39. predownMousePoint = Input.mousePosition;
    40. } else if (Input.GetMouseButton(1)) {
    41. currMousePoint = Input.mousePosition;
    42. Vector3 vec = currMousePoint - predownMousePoint;
    43. Rigidbody rigidbody = transform.GetComponent();
    44. if (rigidbody != null) {
    45. rigidbody.angularVelocity = Vector3.up * rotateSpeed * vec.x;
    46. } else {
    47. transform.Rotate(Vector3.up * vec.x * Time.deltaTime * rotateSpeed);
    48. }
    49. predownMousePoint = currMousePoint;
    50. }
    51. }
    52. private void updateStick(float hor, float ver) { // 更新摇杆
    53. Vector3 dire = new Vector3(hor, ver, 0);
    54. dire = dire.normalized * Mathf.Min(dire.magnitude, 1);
    55. stick.UpdateStick(dire);
    56. }
    57. private void RestrictBoundary() { // 限制边界
    58. Vector3 pos = transform.position;
    59. if (Mathf.Abs(pos.x) > 49) {
    60. transform.position = new Vector3(Mathf.Sign(pos.x) * 49, pos.y, pos.z);
    61. } else if (Mathf.Abs(pos.z) > 49) {
    62. transform.position = new Vector3(pos.x, pos.y, Mathf.Sign(pos.z) * 49);
    63. }
    64. }
    65. }

            TankInfo.cs

    1. using System;
    2. using UnityEngine;
    3. [Serializable]
    4. public class TankInfo : ICloneable {
    5. [Header("坦克满血量")]
    6. [Range(30, 100)]
    7. public int fullBlood = 30;
    8. [Header("坦克移动速度")]
    9. [Range(1, 5)]
    10. public float tankMoveSpeed = 3f;
    11. [Header("坦克旋转速度")]
    12. [Range(1, 4)]
    13. public float tankRotateSpeed = 2f;
    14. [Header("坦克颜色")]
    15. public Color tankColor = Color.green;
    16. [Header("坦克初始位置")]
    17. public Vector3 tankInitPosition = new Vector3(0f, 0.25f, 0f);
    18. [Header("坦克初始方位")]
    19. public Vector3 tankInitRotation = new Vector3(0, 0, 0);
    20. [Header("炮弹信息")]
    21. public BulletInfo bullet;
    22. private String name = "Enemy"; // 坦克角色名
    23. private int currBlood = 30; // 坦克当前血量
    24. public TankInfo(String name) {
    25. this.name = name;
    26. bullet = new BulletInfo(name + "Bullet");
    27. }
    28. public object Clone() { // 克隆坦克
    29. TankInfo info = new TankInfo(this.name);
    30. info.fullBlood = this.fullBlood;
    31. info.tankMoveSpeed = this.tankMoveSpeed;
    32. info.tankRotateSpeed = this.tankRotateSpeed;
    33. info.tankColor = this.tankColor;
    34. info.tankInitPosition = this.tankInitPosition;
    35. info.tankInitRotation = this.tankInitRotation;
    36. info.bullet = this.bullet.Clone() as BulletInfo;
    37. info.SetCurrBlood(this.currBlood);
    38. return info;
    39. }
    40. public void SetCurrBlood(int blood) { // 设置当前血量
    41. currBlood = blood;
    42. }
    43. public int GetCurrBlood() { // 获取当前血量
    44. return currBlood;
    45. }
    46. public int GetFullBlood() { // 获取满血量
    47. return fullBlood;
    48. }
    49. public float BuckleBlood(int damage) { // 扣血, 返回剩余血量比例
    50. currBlood = Math.Max(currBlood - damage, 0);
    51. return 1.0f * currBlood / fullBlood;
    52. }
    53. public bool IsDying() {
    54. return currBlood == 0;
    55. }
    56. public String GetName() {
    57. return name;
    58. }
    59. }

            BulletInfo.cs

    1. using System;
    2. using UnityEngine;
    3. [Serializable]
    4. public class BulletInfo : ICloneable {
    5. [Header("炮弹伤害")]
    6. [Range(2, 10)]
    7. public int bulletDamage = 2;
    8. [Header("炮弹飞行速度")]
    9. [Range(5, 20)]
    10. public int bulletSpeed = 10;
    11. [Header("炮弹冷却时间")]
    12. [Range(0.1f, 1.5f)]
    13. public float bulletCoolTime = 0.3f;
    14. [Header("炮弹射程")]
    15. [Range(5, 15)]
    16. public float bulletFireRange = 10;
    17. [Header("炮弹颜色")]
    18. public Color bulletColor = Color.red;
    19. private String name = "EnemyBullet"; // 炮弹名
    20. private Vector3 flyDir; // 炮弹飞行方向
    21. public BulletInfo(String name) {
    22. this.name = name;
    23. }
    24. public void SetFlyDir(Vector3 flyDir) {
    25. this.flyDir = flyDir;
    26. }
    27. public Vector3 GetFlyDir() {
    28. return flyDir;
    29. }
    30. public String GetName() {
    31. return name;
    32. }
    33. public object Clone() { // 克隆炮弹
    34. BulletInfo info = new BulletInfo(this.name);
    35. info.bulletDamage = this.bulletDamage;
    36. info.bulletSpeed = this.bulletSpeed;
    37. info.bulletCoolTime = this.bulletCoolTime;
    38. info.bulletFireRange = this.bulletFireRange;
    39. info.bulletColor = this.bulletColor;
    40. return info;
    41. }
    42. }

            EnemiesInfo.cs

    1. using UnityEngine;
    2. public class EnemiesInfo {
    3. public const int TOTAL_NUM = 50; // 敌人总数
    4. public const int INIT_NUM = 10; // 敌人初始入场个数
    5. public const int ENTER_INTERVAL = 2; // 敌人入场时间间隔
    6. public const int LEVEL_1_WEIGHT = 3; // 一级敌人个数权重
    7. public const int LEVEL_2_WEIGHT = 2; // 二级敌人个数权重
    8. public const int LEVEL_3_WEIGHT = 1; // 三级敌人个数权重
    9. private volatile int appeardNum = 0; // 已入场的敌人数
    10. private volatile int currentNum = 0; // 当前敌人数
    11. private int totalWeight; // 总权重
    12. public EnemiesInfo() {
    13. totalWeight = LEVEL_1_WEIGHT + LEVEL_2_WEIGHT + LEVEL_3_WEIGHT;
    14. }
    15. public void CurrAdd() {
    16. lock(this) {
    17. appeardNum ++;
    18. currentNum ++;
    19. }
    20. }
    21. public void CurrDes() {
    22. lock(this) {
    23. currentNum --;
    24. }
    25. }
    26. public int GetRandomLevel() {
    27. float random = Random.Range(0f, totalWeight);
    28. if (random < LEVEL_1_WEIGHT) {
    29. return 1;
    30. }
    31. if (random < LEVEL_1_WEIGHT + LEVEL_2_WEIGHT) {
    32. return 2;
    33. }
    34. return 3;
    35. }
    36. public int GetAppeardNum() {
    37. return appeardNum;
    38. }
    39. public int GetTotalNum() {
    40. return TOTAL_NUM;
    41. }
    42. }

            TankParamsManager.cs

    1. using UnityEngine;
    2. public class TankParamsManager {
    3. private const int MIN_ENEMY_LEVEL = 1;
    4. private const int MAX_ENEMY_LEVEL = 3;
    5. private static TankParamsManager tankParamsManager;
    6. private TankInfo LEVEL_0 = new TankInfo("Player"); // 玩家
    7. private TankInfo LEVEL_1 = new TankInfo("Enemy"); // 敌军1级
    8. private TankInfo LEVEL_2 = new TankInfo("Enemy"); // 敌军2级
    9. private TankInfo LEVEL_3 = new TankInfo("Enemy"); // 敌军3级
    10. private TankParamsManager() {
    11. Level0Params();
    12. Level1Params();
    13. Level2Params();
    14. Level3Params();
    15. }
    16. public static TankParamsManager GetInstance() {
    17. if (tankParamsManager == null) {
    18. tankParamsManager = new TankParamsManager();
    19. }
    20. return tankParamsManager;
    21. }
    22. public TankInfo GetPlayerTankInfo() {
    23. return LEVEL_0.Clone() as TankInfo;
    24. }
    25. public TankInfo GetEnemyTankInfo(int level) {
    26. level = Camp(level, MIN_ENEMY_LEVEL, MAX_ENEMY_LEVEL);
    27. switch (level) {
    28. case 1:
    29. return LEVEL_1.Clone() as TankInfo;
    30. case 2:
    31. return LEVEL_2.Clone() as TankInfo;
    32. case 3:
    33. return LEVEL_3.Clone() as TankInfo;
    34. }
    35. return LEVEL_1;
    36. }
    37. private void Level0Params() {
    38. LEVEL_0.fullBlood = 500;
    39. // LEVEL_0.fullBlood = 2;
    40. LEVEL_0.tankColor = Color.green;
    41. LEVEL_0.tankMoveSpeed = 4;
    42. LEVEL_0.tankRotateSpeed = 2;
    43. LEVEL_0.SetCurrBlood(LEVEL_0.fullBlood);
    44. LEVEL_0.bullet.bulletDamage = 10;
    45. LEVEL_0.bullet.bulletColor = Color.red;
    46. LEVEL_0.bullet.bulletCoolTime = 0.15f;
    47. LEVEL_0.bullet.bulletFireRange = 15;
    48. LEVEL_0.bullet.bulletSpeed = 10;
    49. }
    50. private void Level1Params() {
    51. LEVEL_1.fullBlood = 30;
    52. LEVEL_1.tankColor = Color.gray;
    53. LEVEL_1.tankMoveSpeed = 1;
    54. LEVEL_1.tankRotateSpeed = 0.85f;
    55. LEVEL_1.SetCurrBlood(LEVEL_1.fullBlood);
    56. LEVEL_1.bullet.bulletDamage = 2;
    57. LEVEL_1.bullet.bulletColor = Color.gray;
    58. LEVEL_1.bullet.bulletCoolTime = 2f;
    59. LEVEL_1.bullet.bulletFireRange = 10;
    60. LEVEL_1.bullet.bulletSpeed = 5;
    61. }
    62. private void Level2Params() {
    63. LEVEL_2.fullBlood = 40;
    64. LEVEL_2.tankColor = Color.cyan;
    65. LEVEL_2.tankMoveSpeed = 1.3f;
    66. LEVEL_2.tankRotateSpeed = 0.9f;
    67. LEVEL_2.SetCurrBlood(LEVEL_2.fullBlood);
    68. LEVEL_2.bullet.bulletDamage = 3;
    69. LEVEL_2.bullet.bulletColor = Color.gray;
    70. LEVEL_2.bullet.bulletCoolTime = 1.7f;
    71. LEVEL_2.bullet.bulletFireRange = 11;
    72. LEVEL_2.bullet.bulletSpeed = 6;
    73. }
    74. private void Level3Params() {
    75. LEVEL_3.fullBlood = 50;
    76. LEVEL_3.tankColor = Color.yellow;
    77. LEVEL_3.tankMoveSpeed = 1.6f;
    78. LEVEL_3.tankRotateSpeed = 1f;
    79. LEVEL_3.SetCurrBlood(LEVEL_3.fullBlood);
    80. LEVEL_3.bullet.bulletDamage = 4;
    81. LEVEL_3.bullet.bulletColor = Color.yellow;
    82. LEVEL_3.bullet.bulletCoolTime = 1.4f;
    83. LEVEL_3.bullet.bulletFireRange = 12;
    84. LEVEL_3.bullet.bulletSpeed = 7;
    85. }
    86. private int Camp(int value, int min, int max) {
    87. if (value > max) {
    88. return max;
    89. }
    90. if (value < min) {
    91. return min;
    92. }
    93. return value;
    94. }
    95. }

            WindowController.cs

    1. using UnityEngine;
    2. public class WindowController : MonoBehaviour {
    3. private bool fullscreen = true; // 全屏
    4. private void Update () {
    5. if (Input.GetKeyDown(KeyCode.Escape)) {
    6. fullscreen = !fullscreen;
    7. Screen.fullScreen = fullscreen;
    8. }
    9. if (Input.GetKeyDown(KeyCode.Q)) {
    10. Application.Quit();
    11. }
    12. }
    13. }

            说明:WindowController 脚本组件挂在 Window 游戏对象上。 

    6 运行效果

  • 相关阅读:
    读书笔记:Java8 Streams用法总结大全 之 Stream中的常见操作
    15 -python之文件操作
    Hive用户中文使用手册系列(一)
    基于ssm企业人事管理系统
    【移远QuecPython】EC800M物联网开发板调用网络API(使用SIM卡联网并调用高德地图API的定位坐标转换)
    只会 Windows 也能轻松搭建远程桌面 RustDesk 自用服务器
    java-php-python-ssm-乌托邦宿舍管理系统2021计算机毕业设计
    第六十章 IIS 7 或更高版本的替代选项 (Windows) - 替代选项 3:将 ISAPI 模块与 NSD (CSPcms.dll) 一起使用
    如何成为优秀的产品经理?新人必看!
    HJ20 密码验证合格程序
  • 原文地址:https://blog.csdn.net/m0_37602827/article/details/126132666