1
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "BITFALL.GameMode.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:87bea3a21c744b1478660b70494160ba",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:be8fc6f1c44f14943887ab6381170c28",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:7efac18f239530141802fb139776f333"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
68
Assets/Artists/Scripts/GameMode/BotQuotaController.cs
Normal file
68
Assets/Artists/Scripts/GameMode/BotQuotaController.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITFALL.Scene;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.GameMode
|
||||
{
|
||||
public class BotQuotaController : MonoBehaviour
|
||||
{
|
||||
[BITCommand]
|
||||
public static void bot_quota(int quota)
|
||||
{
|
||||
Data.Set(BITConstant.Environment.bot_quota, quota);
|
||||
}
|
||||
[SerializeField] private Entity[] initialBots;
|
||||
[SerializeField] private Entity botPrefab;
|
||||
[SerializeReference,SubclassSelector] private ISpawnPointService _spawnPointService;
|
||||
private readonly List<Entity> _bots = new();
|
||||
private void Start()
|
||||
{
|
||||
foreach (var x in initialBots)
|
||||
{
|
||||
_bots.Add(x);
|
||||
}
|
||||
Data.AddListener<int>(BITConstant.Environment.bot_quota, OnBotQuotaChanged,true);
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
Data.RemoveListender<int>(BITConstant.Environment.bot_quota, OnBotQuotaChanged);
|
||||
});
|
||||
}
|
||||
private async void OnBotQuotaChanged(int quota)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(destroyCancellationToken);
|
||||
var currentQuota=_bots.Count;
|
||||
BIT4Log.Log<BotQuotaController>($"正在更改机器人配额,当前配额为{currentQuota},目标配额为{quota}");
|
||||
while (currentQuota < quota)
|
||||
{
|
||||
Matrix4x4 spawnPoint = _spawnPointService.RequestSpawnPoint();
|
||||
var instance = Instantiate(botPrefab,spawnPoint.GetPosition(),spawnPoint.rotation);
|
||||
_bots.Add(instance);
|
||||
BIT4Log.Log<BotQuotaController>("已添加bot");
|
||||
currentQuota++;
|
||||
}
|
||||
while (currentQuota > quota)
|
||||
{
|
||||
var bot = _bots.Last();
|
||||
_bots.Remove(bot);
|
||||
Destroy(bot.gameObject);
|
||||
BIT4Log.Log<BotQuotaController>($"已移除bot:{bot.gameObject.name}");
|
||||
currentQuota--;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
49
Assets/Artists/Scripts/GameMode/PlayerAutoSpawnController.cs
Normal file
49
Assets/Artists/Scripts/GameMode/PlayerAutoSpawnController.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.GameMode
|
||||
{
|
||||
public class PlayerAutoSpawnController : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IEntitiesService entitiesService;
|
||||
private void Start()
|
||||
{
|
||||
entitiesService.OnAdd += OnEntityAdded;
|
||||
destroyCancellationToken.Register(() =>
|
||||
{
|
||||
entitiesService.OnAdd -= OnEntityAdded;
|
||||
});
|
||||
}
|
||||
private void OnEntityAdded(IEntity obj)
|
||||
{
|
||||
if (obj.TryGetComponent<IHealth>(out var heal) is false) return;
|
||||
var token = destroyCancellationToken;
|
||||
if (obj is MonoBehaviour behaviour)
|
||||
{
|
||||
token = behaviour.destroyCancellationToken;
|
||||
}
|
||||
heal.OnSetAlive +=async alive =>
|
||||
{
|
||||
if(alive)return;
|
||||
var time = Data.Get<int>(BITConstant.Environment.mp_respawn_on_death);
|
||||
switch (time)
|
||||
{
|
||||
case 0:
|
||||
heal.HealthPoint = heal.MaxHealthPoint;
|
||||
return;
|
||||
case -1:
|
||||
return;
|
||||
default:
|
||||
await Task.Delay(TimeSpan.FromSeconds(time),token);
|
||||
heal.HealthPoint = heal.MaxHealthPoint;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user