mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
更新Demo
更新Demo
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6eccec3101ad0714697d394a14c2ec65
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public static class ActorEventDefine
|
||||
{
|
||||
public static readonly int ScoreChange = RuntimeId.ToRuntimeId("ActorEventDefine.ScoreChange");
|
||||
public static readonly int GameOver = RuntimeId.ToRuntimeId("ActorEventDefine.GameOver");
|
||||
public static readonly int EnemyDead = RuntimeId.ToRuntimeId("ActorEventDefine.EnemyDead");
|
||||
public static readonly int PlayerDead = RuntimeId.ToRuntimeId("ActorEventDefine.PlayerDead");
|
||||
public static readonly int AsteroidExplosion = RuntimeId.ToRuntimeId("ActorEventDefine.AsteroidExplosion");
|
||||
public static readonly int EnemyFireBullet = RuntimeId.ToRuntimeId("ActorEventDefine.EnemyFireBullet");
|
||||
public static readonly int PlayerFireBullet = RuntimeId.ToRuntimeId("ActorEventDefine.PlayerFireBullet");
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de011fa2ea744cfe94ddb63030ebf031
|
||||
timeCreated: 1683946273
|
@@ -0,0 +1,39 @@
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityAsteroid : MonoBehaviour
|
||||
{
|
||||
public float MoveSpeed = -5f;
|
||||
public float Tumble = 5f;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
public void InitEntity()
|
||||
{
|
||||
_rigidbody.velocity = this.transform.forward * MoveSpeed;
|
||||
_rigidbody.angularVelocity = Random.insideUnitSphere * Tumble;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.transform.GetComponent<Rigidbody>();
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("player"))
|
||||
{
|
||||
GameEvent.Send(ActorEventDefine.AsteroidExplosion,this.transform.position, this.transform.rotation);
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("Boundary"))
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffef5a382eef32d46b1d6175c85f644e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,51 @@
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityBullet : MonoBehaviour
|
||||
{
|
||||
public float MoveSpeed = 20f;
|
||||
public float DelayDestroyTime = 5f;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
public void InitEntity()
|
||||
{
|
||||
_rigidbody.velocity = this.transform.forward * MoveSpeed;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.transform.GetComponent<Rigidbody>();
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("Boundary"))
|
||||
return;
|
||||
|
||||
var goName = this.gameObject.name;
|
||||
if (goName.StartsWith("enemy_bullet"))
|
||||
{
|
||||
if (name.StartsWith("enemy") == false)
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (goName.StartsWith("player_bullet"))
|
||||
{
|
||||
if (name.StartsWith("player") == false)
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("Boundary"))
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a9d4ddd3c4e60245b6bc4f9f1435291
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,16 @@
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityEffect : MonoBehaviour
|
||||
{
|
||||
public float DelayDestroyTime = 1f;
|
||||
|
||||
public void InitEntity()
|
||||
{
|
||||
Invoke(nameof(DelayDestroy), DelayDestroyTime);
|
||||
}
|
||||
private void DelayDestroy()
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 014c1f9b87e247446bd7d558f8bf143e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,95 @@
|
||||
using System.Collections;
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class EntityEnemy : MonoBehaviour
|
||||
{
|
||||
private const float Dodge = 5f;
|
||||
private const float Smoothing = 7.5f;
|
||||
|
||||
public RoomBoundary Boundary;
|
||||
public float MoveSpeed = 20f;
|
||||
public float FireInterval = 2f;
|
||||
|
||||
public Vector2 StartWait = new Vector2(0.5f, 1f);
|
||||
public Vector2 ManeuverTime = new Vector2(1, 2);
|
||||
public Vector2 ManeuverWait = new Vector2(1, 2);
|
||||
|
||||
private Transform _shotSpawn;
|
||||
private Rigidbody _rigidbody;
|
||||
private AudioSource _audioSource;
|
||||
private float _lastFireTime = 0f;
|
||||
private float _currentSpeed;
|
||||
private float _targetManeuver;
|
||||
|
||||
|
||||
public void InitEntity()
|
||||
{
|
||||
_rigidbody.velocity = this.transform.forward * -5f;
|
||||
_lastFireTime = Time.time;
|
||||
_currentSpeed = _rigidbody.velocity.z;
|
||||
_targetManeuver = 0f;
|
||||
StartCoroutine(Evade());
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.gameObject.GetComponent<Rigidbody>();
|
||||
_audioSource = this.gameObject.GetComponent<AudioSource>();
|
||||
_shotSpawn = this.transform.Find("shot_spawn");
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (Time.time - _lastFireTime >= FireInterval)
|
||||
{
|
||||
_lastFireTime = Time.time;
|
||||
_audioSource.Play();
|
||||
GameEvent.Send(ActorEventDefine.EnemyFireBullet,this._shotSpawn.position, this._shotSpawn.rotation);
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
float newManeuver = Mathf.MoveTowards(_rigidbody.velocity.x, _targetManeuver, Smoothing * Time.deltaTime);
|
||||
_rigidbody.velocity = new Vector3(newManeuver, 0.0f, _currentSpeed);
|
||||
_rigidbody.position = new Vector3
|
||||
(
|
||||
Mathf.Clamp(_rigidbody.position.x, Boundary.xMin, Boundary.xMax),
|
||||
0.0f,
|
||||
Mathf.Clamp(_rigidbody.position.z, Boundary.zMin, Boundary.zMax)
|
||||
);
|
||||
|
||||
float tilt = 10f;
|
||||
_rigidbody.rotation = Quaternion.Euler(0, 0, _rigidbody.velocity.x * -tilt);
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("player"))
|
||||
{
|
||||
GameEvent.Send(ActorEventDefine.EnemyDead,this.transform.position, this.transform.rotation);
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("Boundary"))
|
||||
{
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator Evade()
|
||||
{
|
||||
yield return new WaitForSeconds(Random.Range(StartWait.x, StartWait.y));
|
||||
while (true)
|
||||
{
|
||||
_targetManeuver = Random.Range(1, Dodge) * -Mathf.Sign(transform.position.x);
|
||||
yield return new WaitForSeconds(Random.Range(ManeuverTime.x, ManeuverTime.y));
|
||||
_targetManeuver = 0;
|
||||
yield return new WaitForSeconds(Random.Range(ManeuverWait.x, ManeuverWait.y));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a613426c4968b3149b8bf9bf88fe41c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class EntityPlayer : MonoBehaviour
|
||||
{
|
||||
public RoomBoundary Boundary;
|
||||
public float MoveSpeed = 10f;
|
||||
public float FireRate = 0.25f;
|
||||
|
||||
private float _nextFireTime = 0f;
|
||||
private Transform _shotSpawn;
|
||||
private Rigidbody _rigidbody;
|
||||
private AudioSource _audioSource;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.gameObject.GetComponent<Rigidbody>();
|
||||
_audioSource = this.gameObject.GetComponent<AudioSource>();
|
||||
_shotSpawn = this.transform.Find("shot_spawn");
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButton("Fire1") && Time.time > _nextFireTime)
|
||||
{
|
||||
_nextFireTime = Time.time + FireRate;
|
||||
_audioSource.Play();
|
||||
GameEvent.Send(ActorEventDefine.PlayerFireBullet,_shotSpawn.position, _shotSpawn.rotation);
|
||||
}
|
||||
}
|
||||
void FixedUpdate()
|
||||
{
|
||||
float moveHorizontal = Input.GetAxis("Horizontal");
|
||||
float moveVertical = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
|
||||
_rigidbody.velocity = movement * MoveSpeed;
|
||||
_rigidbody.position = new Vector3
|
||||
(
|
||||
Mathf.Clamp(GetComponent<Rigidbody>().position.x, Boundary.xMin, Boundary.xMax),
|
||||
0.0f,
|
||||
Mathf.Clamp(GetComponent<Rigidbody>().position.z, Boundary.zMin, Boundary.zMax)
|
||||
);
|
||||
|
||||
float tilt = 5f;
|
||||
_rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, _rigidbody.velocity.x * -tilt);
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var name = other.gameObject.name;
|
||||
if (name.StartsWith("enemy") || name.StartsWith("asteroid"))
|
||||
{
|
||||
GameEvent.Send(ActorEventDefine.PlayerDead,transform.position, transform.rotation);
|
||||
GameModule.Resource.FreeGameObject(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3933af4e188ec44683e3c52784eadb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[Serializable]
|
||||
public class RoomBoundary
|
||||
{
|
||||
public float xMin, xMax, zMin, zMax;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871ee1492e44425da07021fdc3100325
|
||||
timeCreated: 1683946064
|
@@ -0,0 +1,249 @@
|
||||
using System.Collections;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using GameLogic;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using AudioType = TEngine.AudioType;
|
||||
using Object = UnityEngine.Object;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
/// <summary>
|
||||
/// 战斗房间
|
||||
/// </summary>
|
||||
[Update]
|
||||
public class BattleSystem:BehaviourSingleton<BattleSystem>
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Ready,
|
||||
Spawn,
|
||||
WaitSpawn,
|
||||
WaitWave,
|
||||
GameOver,
|
||||
}
|
||||
|
||||
private GameObject _roomRoot;
|
||||
|
||||
// 关卡参数
|
||||
private const int EnemyCount = 10;
|
||||
private const int EnemyScore = 10;
|
||||
private const int AsteroidScore = 1;
|
||||
private readonly Vector3 _spawnValues = new Vector3(6, 0, 20);
|
||||
private readonly string[] _entityLocations = new string[]
|
||||
{
|
||||
"asteroid01", "asteroid02", "asteroid03", "enemy_ship"
|
||||
};
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
private int _totalScore = 0;
|
||||
private int _waveSpawnCount = 0;
|
||||
//
|
||||
// private UniTimer _startWaitTimer = UniTimer.CreateOnceTimer(1f);
|
||||
// private UniTimer _spawnWaitTimer = UniTimer.CreateOnceTimer(0.75f);
|
||||
// private UniTimer _waveWaitTimer = UniTimer.CreateOnceTimer(4f);
|
||||
|
||||
private float _startWaitTimer = 1f;
|
||||
private float _spawnWaitTimer = 0.75f;
|
||||
private float _waveWaitTimer = 4f;
|
||||
|
||||
/// <summary>
|
||||
/// 加载房间
|
||||
/// </summary>
|
||||
public async UniTaskVoid LoadRoom()
|
||||
{
|
||||
_startWaitTimer = 1f;
|
||||
|
||||
await UniTask.Yield();
|
||||
// 创建房间根对象
|
||||
_roomRoot = new GameObject("BattleRoom");
|
||||
|
||||
// 加载背景音乐
|
||||
GameModule.Audio.Play(AudioType.Music, "music_background", true);
|
||||
|
||||
// 创建玩家实体对象
|
||||
var handle = GameModule.Resource.LoadAsset<GameObject>("player_ship", _roomRoot.transform);
|
||||
var entity = handle.GetComponent<EntityPlayer>();
|
||||
|
||||
// 显示战斗界面
|
||||
GameModule.UI.ShowUIAsync<UIBattleWindow>();
|
||||
|
||||
// 监听游戏事件
|
||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerDead,OnPlayerDead);
|
||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyDead,OnEnemyDead);
|
||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.AsteroidExplosion,OnAsteroidExplosion);
|
||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerFireBullet,OnPlayerFireBullet);
|
||||
GameEvent.AddEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyFireBullet,OnEnemyFireBullet);
|
||||
|
||||
_steps = ESteps.Ready;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销毁房间
|
||||
/// </summary>
|
||||
public void DestroyRoom()
|
||||
{
|
||||
// 加载背景音乐
|
||||
GameModule.Audio.Stop(AudioType.Music, true);
|
||||
|
||||
// if (_entitySpawner != null)
|
||||
// {
|
||||
// _entitySpawner.DestroyAll(true);
|
||||
// }
|
||||
|
||||
if (_roomRoot != null)
|
||||
Object.Destroy(_roomRoot);
|
||||
|
||||
GameModule.UI.CloseWindow<UIBattleWindow>();
|
||||
|
||||
// 监听游戏事件
|
||||
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerDead,OnPlayerDead);
|
||||
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyDead,OnEnemyDead);
|
||||
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.AsteroidExplosion,OnAsteroidExplosion);
|
||||
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.PlayerFireBullet,OnPlayerFireBullet);
|
||||
GameEvent.RemoveEventListener<Vector3,Quaternion>(ActorEventDefine.EnemyFireBullet,OnEnemyFireBullet);
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
UpdateRoom();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新房间
|
||||
/// </summary>
|
||||
public void UpdateRoom()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.GameOver)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Ready)
|
||||
{
|
||||
_startWaitTimer -= Time.deltaTime;
|
||||
if (_startWaitTimer <= 0)
|
||||
{
|
||||
_steps = ESteps.Spawn;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Spawn)
|
||||
{
|
||||
var enemyLocation = _entityLocations[Random.Range(0, 4)];
|
||||
Vector3 spawnPosition = new Vector3(Random.Range(-_spawnValues.x, _spawnValues.x), _spawnValues.y, _spawnValues.z);
|
||||
Quaternion spawnRotation = Quaternion.identity;
|
||||
|
||||
if (enemyLocation == "enemy_ship")
|
||||
{
|
||||
// 生成敌人实体
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>(enemyLocation, _roomRoot.transform);
|
||||
gameObject.transform.position = spawnPosition;
|
||||
gameObject.transform.rotation = spawnRotation;
|
||||
var entity = gameObject.GetComponent<EntityEnemy>();
|
||||
entity.InitEntity();
|
||||
}
|
||||
else
|
||||
{
|
||||
// 生成小行星实体
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>(enemyLocation, _roomRoot.transform);
|
||||
gameObject.transform.position = spawnPosition;
|
||||
gameObject.transform.rotation = spawnRotation;
|
||||
var entity = gameObject.GetComponent<EntityAsteroid>();
|
||||
entity.InitEntity();
|
||||
}
|
||||
|
||||
_waveSpawnCount++;
|
||||
if (_waveSpawnCount >= EnemyCount)
|
||||
{
|
||||
_steps = ESteps.WaitWave;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.WaitSpawn;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitSpawn)
|
||||
{
|
||||
_spawnWaitTimer -= Time.deltaTime;
|
||||
if (_spawnWaitTimer <= 0)
|
||||
{
|
||||
_spawnWaitTimer = 0.75f;
|
||||
_steps = ESteps.Spawn;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.WaitWave)
|
||||
{
|
||||
_waveWaitTimer -= Time.deltaTime;
|
||||
if (_waveWaitTimer <= 0)
|
||||
{
|
||||
_waveWaitTimer = 4f;
|
||||
_waveSpawnCount = 0;
|
||||
_steps = ESteps.Spawn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region 接收事件
|
||||
|
||||
private void OnPlayerDead(Vector3 position,Quaternion rotation)
|
||||
{
|
||||
// 创建爆炸效果
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>("explosion_player", _roomRoot.transform);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.rotation = rotation;
|
||||
var entity = gameObject.GetComponent<EntityEffect>();
|
||||
entity.InitEntity();
|
||||
_steps = ESteps.GameOver;
|
||||
GameEvent.Send(ActorEventDefine.GameOver);
|
||||
}
|
||||
|
||||
private void OnEnemyDead(Vector3 position,Quaternion rotation)
|
||||
{
|
||||
// 创建爆炸效果
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>("explosion_enemy", _roomRoot.transform);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.rotation = rotation;
|
||||
var entity = gameObject.GetComponent<EntityEffect>();
|
||||
entity.InitEntity();
|
||||
|
||||
_totalScore += EnemyScore;
|
||||
GameEvent.Send(ActorEventDefine.ScoreChange,_totalScore);
|
||||
}
|
||||
|
||||
private void OnAsteroidExplosion(Vector3 position,Quaternion rotation)
|
||||
{
|
||||
// 创建爆炸效果
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>("explosion_asteroid", _roomRoot.transform);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.rotation = rotation;
|
||||
var entity = gameObject.GetComponent<EntityEffect>();
|
||||
entity.InitEntity();
|
||||
|
||||
_totalScore += AsteroidScore;
|
||||
GameEvent.Send(ActorEventDefine.ScoreChange,_totalScore);
|
||||
}
|
||||
|
||||
private void OnPlayerFireBullet(Vector3 position,Quaternion rotation)
|
||||
{
|
||||
// 创建子弹实体
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>("player_bullet", _roomRoot.transform);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.rotation = rotation;
|
||||
var entity = gameObject.GetComponent<EntityBullet>();
|
||||
entity.InitEntity();
|
||||
}
|
||||
|
||||
private void OnEnemyFireBullet(Vector3 position,Quaternion rotation)
|
||||
{
|
||||
// 创建子弹实体
|
||||
var gameObject = GameModule.Resource.LoadAsset<GameObject>("enemy_bullet", _roomRoot.transform);
|
||||
gameObject.transform.position = position;
|
||||
gameObject.transform.rotation = rotation;
|
||||
var entity = gameObject.GetComponent<EntityBullet>();
|
||||
entity.InitEntity();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4289f2d6df7432ca3f04870400571df
|
||||
timeCreated: 1683946643
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41a3231c52df1c14baa2d77e6d3a3b0e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class BhvApplicationQuit : MonoBehaviour
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this.gameObject);
|
||||
}
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
YooAssets.Destroy();
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cbcea01819f3d94ba5162624ad9c75f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class BhvBackgroundScroller : MonoBehaviour
|
||||
{
|
||||
public float ScrollSpeed;
|
||||
public float TileSizeZ;
|
||||
|
||||
private Vector3 _startPosition;
|
||||
|
||||
void Start ()
|
||||
{
|
||||
_startPosition = transform.position;
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
float newPosition = Mathf.Repeat(Time.time * ScrollSpeed, TileSizeZ);
|
||||
this.transform.position = _startPosition + Vector3.forward * newPosition;
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 814f6a7e3ec8a40aaa3a2057e2695924
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5119c9cc1ae24e3e8272dc88a33b8ede
|
||||
timeCreated: 1683947325
|
@@ -0,0 +1,76 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
[Window(UILayer.UI)]
|
||||
class UIBattleWindow : UIWindow
|
||||
{
|
||||
#region 脚本工具生成的代码
|
||||
|
||||
private Text m_textScore;
|
||||
private GameObject m_goOverView;
|
||||
private Button m_btnRestart;
|
||||
private Button m_btnHome;
|
||||
|
||||
public override void ScriptGenerator()
|
||||
{
|
||||
m_textScore = FindChildComponent<Text>("ScoreView/m_textScore");
|
||||
m_goOverView = FindChild("m_goOverView").gameObject;
|
||||
m_btnRestart = FindChildComponent<Button>("m_goOverView/m_btnRestart");
|
||||
m_btnHome = FindChildComponent<Button>("m_goOverView/m_btnHome");
|
||||
m_btnRestart.onClick.AddListener(UniTask.UnityAction(OnClickRestartBtn));
|
||||
m_btnHome.onClick.AddListener(UniTask.UnityAction(OnClickHomeBtn));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void RegisterEvent()
|
||||
{
|
||||
AddUIEvent<int>(ActorEventDefine.ScoreChange, OnScoreChange);
|
||||
AddUIEvent(ActorEventDefine.GameOver, OnGameOver);
|
||||
}
|
||||
|
||||
public override void OnRefresh()
|
||||
{
|
||||
m_textScore.text = "Score : 0";
|
||||
m_goOverView.SetActive(false);
|
||||
}
|
||||
|
||||
#region 事件
|
||||
|
||||
private async UniTaskVoid OnClickRestartBtn()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
await GameModule.Scene.LoadScene("scene_battle").ToUniTask();
|
||||
|
||||
BattleSystem.Instance.DestroyRoom();
|
||||
BattleSystem.Instance.LoadRoom().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid OnClickHomeBtn()
|
||||
{
|
||||
await UniTask.Yield();
|
||||
// yield return YooAssets.LoadSceneAsync("scene_home");
|
||||
// yield return UniWindow.OpenWindowAsync<UIHomeWindow>("UIHome");
|
||||
//
|
||||
// // 释放资源
|
||||
// var package = YooAssets.GetPackage("DefaultPackage");
|
||||
// package.UnloadUnusedAssets();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void OnScoreChange(int currentScores)
|
||||
{
|
||||
m_textScore.text = $"Score : {currentScores}";
|
||||
}
|
||||
|
||||
private void OnGameOver()
|
||||
{
|
||||
m_goOverView.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15d6c65ac046403185b3dd833e6e2a7e
|
||||
timeCreated: 1683947329
|
Reference in New Issue
Block a user