也是挺久没更新了,活跃也是在数创论坛活跃,同步一下我在那发的帖子吧。
Github: https://github.com/CrashWork-Dev/AnnoyingUtils
开源许可证: Unlicense license
关联项目: https://github.com/cneicy/Rouge
用法:下载后直接解压到Assets/Scripts下。
目前拥有键盘键位自定义、自定义相机比例、对象池功能。
如果你有更好的解决方案或者有功能需求,欢迎你在评论区或Github Issues留言。
键位自定义功能
游戏内改键
KeySettingManager为单例类
在KeySettingManager的LoadKeySettings()中填写自己需要的键位对即可。
调用GetKey(string actionName)获取行为对应的KeyCode
调用SetKey(string actionName, KeyCode newKeyCode)设置行为对应KeyCode
相机比例
将ScreenAspect.cs挂载相机上即可生效
public float TargetAspect = 16f / 9f;
修改以上数值即可设置相机比例。
对象池
新建一个对象池类继承SingletonObjectPool<T>后,在UnityEditor中会自动创建以类名为名称的单例实例。
1 2 3
| public class EnemyPool : SingletonObjectPool<Enemy> { }
|
用法示例如下方刷怪圈
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| public class EnemySpawner : MonoBehaviour { public GameObject enemyPrefab; public int initialPoolSize = 5; public int maxPoolSize = 10; public float spawnInterval = 3f; public int spawnCount = 1; public float spawnRadius = 5f;
private void Start() { SingletonObjectPool<Enemy>.Instance.Init(enemyPrefab.GetComponent<Enemy>(), initialPoolSize, maxPoolSize); StartCoroutine(SpawnEnemiesCoroutine()); }
private IEnumerator SpawnEnemiesCoroutine() { while (true) { yield return new WaitForSeconds(spawnInterval); SpawnEnemies(); } }
private void SpawnEnemies() { for (var i = 0; i < spawnCount; i++) { var spawnPosition = transform.position + (Vector3)Random.insideUnitCircle * spawnRadius; SingletonObjectPool<Enemy>.Instance.Spawn(transform).transform.position = spawnPosition; } } }
|