update sample
This commit is contained in:
-21
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class BackgroundScroller : 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;
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 814f6a7e3ec8a40aaa3a2057e2695924
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BattleEventDefine
|
||||
{
|
||||
public class ScoreChange : IEventMessage
|
||||
{
|
||||
public int CurrentScores;
|
||||
}
|
||||
|
||||
public class GameOver : IEventMessage
|
||||
{
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 523858f19dde4204aad79345f342b0ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class BattleEventDispatcher
|
||||
{
|
||||
public static void SendScoreChangeMsg(int currentScores)
|
||||
{
|
||||
BattleEventDefine.ScoreChange msg = new BattleEventDefine.ScoreChange();
|
||||
msg.CurrentScores = currentScores;
|
||||
EventManager.SendMessage(msg);
|
||||
}
|
||||
|
||||
public static void SendGameOverMsg()
|
||||
{
|
||||
BattleEventDefine.GameOver msg = new BattleEventDefine.GameOver();
|
||||
EventManager.SendMessage(msg);
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5915c7b5006a8384dbefdf32da34a3e6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,110 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[Serializable]
|
||||
public class RoomBoundary
|
||||
{
|
||||
public float xMin, xMax, zMin, zMax;
|
||||
}
|
||||
|
||||
public class BattleRoom : MonoBehaviour
|
||||
{
|
||||
public static BattleRoom Instance;
|
||||
|
||||
public Vector3 SpawnValues;
|
||||
public int EnemyCount = 10;
|
||||
public float SpawnWait = 0.75f;
|
||||
public float StartWait = 1f;
|
||||
public float WaveWait = 4f;
|
||||
|
||||
private int _totalScore = 0;
|
||||
private bool _gameOver = false;
|
||||
private string[] _enemyLocations = new string[]
|
||||
{
|
||||
"asteroid01", "asteroid02", "asteroid03", "enemy_ship"
|
||||
};
|
||||
|
||||
private AssetOperationHandle _panelHandle;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
var canvas = GameObject.Find("Canvas");
|
||||
_panelHandle = YooAssets.LoadAssetSync<GameObject>("UIBattle");
|
||||
var go = _panelHandle.InstantiateSync(canvas.transform);
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>("player_ship");
|
||||
var go = handle.InstantiateSync();
|
||||
var bhv = go.GetComponent<EntityPlayer>();
|
||||
bhv.InitEntity(handle);
|
||||
|
||||
StartCoroutine(SpawnWaves());
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
Instance = null;
|
||||
|
||||
if(_panelHandle != null)
|
||||
{
|
||||
_panelHandle.Release();
|
||||
_panelHandle = null;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator SpawnWaves()
|
||||
{
|
||||
yield return new WaitForSeconds(StartWait);
|
||||
while (true)
|
||||
{
|
||||
for (int i = 0; i < EnemyCount; i++)
|
||||
{
|
||||
var enemyLocation= _enemyLocations[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 handle = YooAssets.LoadAssetSync<GameObject>(enemyLocation);
|
||||
var go = handle.InstantiateSync(spawnPosition, spawnRotation);
|
||||
var bhv = go.GetComponent<EntityEnemy>();
|
||||
bhv.InitEntity(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>(enemyLocation);
|
||||
var go = handle.InstantiateSync(spawnPosition, spawnRotation);
|
||||
var bhv = go.GetComponent<EntityAsteroid>();
|
||||
bhv.InitEntity(handle);
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(SpawnWait);
|
||||
}
|
||||
yield return new WaitForSeconds(WaveWait);
|
||||
|
||||
if (_gameOver)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GameOver()
|
||||
{
|
||||
_gameOver = true;
|
||||
BattleEventDispatcher.SendGameOverMsg();
|
||||
}
|
||||
|
||||
public void AddScore(int score)
|
||||
{
|
||||
_totalScore += score;
|
||||
BattleEventDispatcher.SendScoreChangeMsg(_totalScore);
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 43ab5a1b8ae5c2b4a8995952e7e01f3f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class EntityAsteroid : MonoBehaviour
|
||||
{
|
||||
private AssetOperationHandle _ownerHandle;
|
||||
|
||||
public float MoveSpeed = -5f;
|
||||
public float Tumble = 5f;
|
||||
|
||||
public void InitEntity(AssetOperationHandle ownerHandle)
|
||||
{
|
||||
_ownerHandle = ownerHandle;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var rigidBody = this.transform.GetComponent<Rigidbody>();
|
||||
rigidBody.velocity = this.transform.forward * MoveSpeed;
|
||||
rigidBody.angularVelocity = Random.insideUnitSphere * Tumble;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ownerHandle != null)
|
||||
{
|
||||
_ownerHandle.Release();
|
||||
_ownerHandle = null;
|
||||
}
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("PlayerBullet"))
|
||||
{
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>("explosion_asteroid");
|
||||
var go = handle.InstantiateSync(other.transform.position, Quaternion.identity);
|
||||
var bhv = go.GetComponent<EntityEffect>();
|
||||
bhv.InitEntity(handle);
|
||||
|
||||
BattleRoom.Instance.AddScore(1);
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Boundary"))
|
||||
{
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ffef5a382eef32d46b1d6175c85f644e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class EntityBullet : MonoBehaviour
|
||||
{
|
||||
private AssetOperationHandle _ownerHandle;
|
||||
|
||||
public float MoveSpeed = 20f;
|
||||
public float DelayDestroyTime = 5f;
|
||||
|
||||
public void InitEntity(AssetOperationHandle ownerHandle)
|
||||
{
|
||||
_ownerHandle = ownerHandle;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var rigidBody = this.transform.GetComponent<Rigidbody>();
|
||||
rigidBody.velocity = this.transform.forward * MoveSpeed;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ownerHandle != null)
|
||||
{
|
||||
_ownerHandle.Release();
|
||||
_ownerHandle = null;
|
||||
}
|
||||
}
|
||||
void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Boundary"))
|
||||
return;
|
||||
|
||||
if (this.gameObject.CompareTag("EnemyBullet"))
|
||||
{
|
||||
if (other.CompareTag("Enemy") == false)
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
if (this.gameObject.CompareTag("PlayerBullet"))
|
||||
{
|
||||
if (other.CompareTag("Player") == false)
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Boundary"))
|
||||
{
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a9d4ddd3c4e60245b6bc4f9f1435291
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,34 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class EntityEffect : MonoBehaviour
|
||||
{
|
||||
private AssetOperationHandle _ownerHandle;
|
||||
|
||||
public float DelayDestroyTime = 1f;
|
||||
|
||||
public void InitEntity(AssetOperationHandle ownerHandle)
|
||||
{
|
||||
_ownerHandle = ownerHandle;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Invoke(nameof(DelayDestroy), DelayDestroyTime);
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ownerHandle != null)
|
||||
{
|
||||
_ownerHandle.Release();
|
||||
_ownerHandle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void DelayDestroy()
|
||||
{
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 014c1f9b87e247446bd7d558f8bf143e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,117 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
public class EntityEnemy : MonoBehaviour
|
||||
{
|
||||
private const float Dodge = 5f;
|
||||
private const float Smoothing = 7.5f;
|
||||
|
||||
private AssetOperationHandle _ownerHandle;
|
||||
|
||||
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;
|
||||
|
||||
float _currentSpeed;
|
||||
float targetManeuver;
|
||||
|
||||
public void InitEntity(AssetOperationHandle ownerHandle)
|
||||
{
|
||||
_ownerHandle = ownerHandle;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.gameObject.GetComponent<Rigidbody>();
|
||||
_audioSource = this.gameObject.GetComponent<AudioSource>();
|
||||
_shotSpawn = this.transform.Find("shot_spawn");
|
||||
|
||||
_rigidbody.velocity = this.transform.forward * -5f;
|
||||
_currentSpeed = _rigidbody.velocity.z;
|
||||
StartCoroutine(Evade());
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
_lastFireTime = Time.time;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ownerHandle != null)
|
||||
{
|
||||
_ownerHandle.Release();
|
||||
_ownerHandle = null;
|
||||
}
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (Time.time - _lastFireTime >= FireInterval)
|
||||
{
|
||||
_lastFireTime = Time.time;
|
||||
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>("enemy_bullet");
|
||||
var go = handle.InstantiateSync(_shotSpawn.position, _shotSpawn.rotation);
|
||||
var bhv = go.GetComponent<EntityBullet>();
|
||||
bhv.InitEntity(handle);
|
||||
|
||||
_audioSource.Play();
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (other.CompareTag("PlayerBullet"))
|
||||
{
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>("explosion_enemy");
|
||||
var go = handle.InstantiateSync(this.transform.position, this.transform.rotation);
|
||||
var bhv = go.GetComponent<EntityEffect>();
|
||||
bhv.InitEntity(handle);
|
||||
|
||||
BattleRoom.Instance.AddScore(10);
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Boundary"))
|
||||
{
|
||||
GameObject.Destroy(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a613426c4968b3149b8bf9bf88fe41c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,83 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class EntityPlayer : MonoBehaviour
|
||||
{
|
||||
private AssetOperationHandle _ownerHandle;
|
||||
|
||||
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;
|
||||
|
||||
public void InitEntity(AssetOperationHandle ownerHandle)
|
||||
{
|
||||
_ownerHandle = ownerHandle;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_rigidbody = this.gameObject.GetComponent<Rigidbody>();
|
||||
_audioSource = this.gameObject.GetComponent<AudioSource>();
|
||||
_shotSpawn = this.transform.Find("shot_spawn");
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
if (_ownerHandle != null)
|
||||
{
|
||||
_ownerHandle.Release();
|
||||
_ownerHandle = null;
|
||||
}
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButton("Fire1") && Time.time > _nextFireTime)
|
||||
{
|
||||
_nextFireTime = Time.time + FireRate;
|
||||
|
||||
var handle = YooAssets.LoadAssetSync<GameObject>("player_bullet");
|
||||
var go = handle.InstantiateSync(_shotSpawn.position, _shotSpawn.rotation);
|
||||
var bhv = go.GetComponent<EntityBullet>();
|
||||
bhv.InitEntity(handle);
|
||||
|
||||
_audioSource.Play();
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (other.CompareTag("Enemy") || other.CompareTag("EnemyBullet") || other.CompareTag("Asteroid"))
|
||||
{
|
||||
var explosionHandle = YooAssets.LoadAssetSync<GameObject>("explosion_player");
|
||||
var go = explosionHandle.InstantiateSync(this.transform.position, this.transform.rotation);
|
||||
var bhv = go.GetComponent<EntityEffect>();
|
||||
bhv.InitEntity(explosionHandle);
|
||||
|
||||
BattleRoom.Instance.GameOver();
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3933af4e188ec44683e3c52784eadb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user