Changed to using Runtime sets
Handlers are now using runtime sets instead of owning lists. Entities that are instantiated assign themselves to their respective Runtime sets. Heavily inspired by: https://www.youtube.com/watch?v=raQ3iHhE_Kk https://github.com/roboryantron/Unite2017
This commit is contained in:
parent
4151ba0050
commit
f89ab59fdf
|
@ -2,13 +2,12 @@
|
|||
"name": "AsteroidGame",
|
||||
"rootNamespace": "AsteroidGame",
|
||||
"references": [
|
||||
"GUID:bc7863ca0989b494d84426bfd28432fa",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:5041af1ee0cf75e4a9a52f5f23a0bfae",
|
||||
"GUID:857695c8a9ee988459c9b50e4e75e660",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:f008ecc6829887e478aeb5eb004eb01b",
|
||||
"GUID:17a5862fcd6383b4b97bad4dcb1e2e5d",
|
||||
"GUID:f26d68a0bdefa1043b120b820f55e190",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c"
|
||||
"GUID:eb3099ff524d60545a136315a154d67b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 1260fd8b7346bdf41a685d24b968a231, type: 3}
|
||||
m_Name: AvailableEnemies
|
||||
m_EditorClassIdentifier:
|
||||
_list: []
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 00c435d92e1df55499826c91b4f1e62f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -412,6 +412,8 @@ MonoBehaviour:
|
|||
_centerPosition: {fileID: 3291032053430181389}
|
||||
_basePosition: {fileID: 2692714622321691895}
|
||||
_uiFriendlyName: Enemy
|
||||
_entityBaseSet: {fileID: 11400000, guid: c5542e77624472441a67b1f34e19a116, type: 2}
|
||||
_enemyBaseSet: {fileID: 11400000, guid: 5f6dc84d75dbd9a459e519de42279066, type: 2}
|
||||
--- !u!1 &6940800288144322101
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities.Enemies.Scripts
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
public class EnemyBase : EntityBase
|
||||
{
|
||||
[SerializeField] private SEnemyBaseRuntimeSet _enemyBaseSet;
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
_enemyBaseSet.Add(this);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_enemyBaseSet.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@
|
|||
"name": "Entities",
|
||||
"rootNamespace": "AsteroidGame",
|
||||
"references": [
|
||||
"GUID:17a5862fcd6383b4b97bad4dcb1e2e5d"
|
||||
"GUID:17a5862fcd6383b4b97bad4dcb1e2e5d",
|
||||
"GUID:eb3099ff524d60545a136315a154d67b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
|
|
@ -17,6 +17,9 @@ namespace AsteroidGame.Entities
|
|||
[Header("UI")]
|
||||
[SerializeField] protected string _uiFriendlyName;
|
||||
|
||||
[Space]
|
||||
[SerializeField] private SEntityBaseRuntimeSet _entityBaseSet;
|
||||
|
||||
#region Props
|
||||
|
||||
public bool IsInvulnerable => _isInvulnerable;
|
||||
|
@ -24,6 +27,16 @@ namespace AsteroidGame.Entities
|
|||
|
||||
#endregion
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_entityBaseSet.Add(this);
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
_entityBaseSet.Remove(this);
|
||||
}
|
||||
|
||||
#region Methods
|
||||
|
||||
public void ModifyHealth(int healthChange)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 857695c8a9ee988459c9b50e4e75e660
|
||||
AssemblyDefinitionImporter:
|
||||
guid: 3b846d413af4ba14ab89d5f44be1a3b7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
|
@ -0,0 +1,15 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 33f48df2d03212c4986fe2c47c5de796, type: 3}
|
||||
m_Name: ActiveEnemies
|
||||
m_EditorClassIdentifier:
|
||||
_list: []
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f6dc84d75dbd9a459e519de42279066
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 9da2d6a0206101c47a22881a0ba2ece2, type: 3}
|
||||
m_Name: ActiveEntities
|
||||
m_EditorClassIdentifier:
|
||||
_list: []
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c5542e77624472441a67b1f34e19a116
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,15 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fbc6f67c9903cc8448f793da64d840cf, type: 3}
|
||||
m_Name: ActiveStructures
|
||||
m_EditorClassIdentifier:
|
||||
_list: []
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bccdf438a1004a444bc24492728d6fbd
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91195dc9638557a4aa7380bb7bb3c5cc
|
||||
guid: f690b649bafc7be4595cacba515c2c11
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
|
@ -0,0 +1,12 @@
|
|||
using System.Collections.Generic;
|
||||
using AsteroidGame.Entities.Enemies.Scripts;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newEnemyList", menuName = "Enemies/EnemyList")]
|
||||
public class SEnemyBaseList : ScriptableObject
|
||||
{
|
||||
public List<EnemyBase> _list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1260fd8b7346bdf41a685d24b968a231
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
using AsteroidGame.Entities.Enemies.Scripts;
|
||||
using AsteroidGame.ScriptableObjects;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newEnemyBaseRuntimeSet", menuName = "RuntimeSet/EnemyBase")]
|
||||
public class SEnemyBaseRuntimeSet : SRuntimeSet<EnemyBase>
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 33f48df2d03212c4986fe2c47c5de796
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using AsteroidGame.ScriptableObjects;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newEntityBaseRuntimeSet", menuName = "RuntimeSet/EntityBase")]
|
||||
public class SEntityBaseRuntimeSet : SRuntimeSet<EntityBase>
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9da2d6a0206101c47a22881a0ba2ece2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newStructureList", menuName = "Structures/StructureList")]
|
||||
public class SStructureBaseList : ScriptableObject
|
||||
{
|
||||
public List<StructureBase> _structureList;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using AsteroidGame.ScriptableObjects;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newStructureBaseRuntimeSet", menuName = "RuntimeSet/StructureBase")]
|
||||
public class SStructureBaseRuntimeSet : SRuntimeSet<StructureBase>
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fbc6f67c9903cc8448f793da64d840cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -52,6 +52,7 @@ MonoBehaviour:
|
|||
_centerPosition: {fileID: 1841478903898566568}
|
||||
_basePosition: {fileID: 493861824998956378}
|
||||
_uiFriendlyName: Power\nPlant
|
||||
_entityBaseSet: {fileID: 11400000, guid: c5542e77624472441a67b1f34e19a116, type: 2}
|
||||
_cost: 100
|
||||
_buildPlacementBlocked: 0
|
||||
_buildTimer: 0
|
||||
|
@ -59,6 +60,7 @@ MonoBehaviour:
|
|||
_isConsumer: 0
|
||||
_maxPower: 100
|
||||
_currentPower: 0
|
||||
_structureBaseSet: {fileID: 11400000, guid: bccdf438a1004a444bc24492728d6fbd, type: 2}
|
||||
--- !u!1 &1863277996181035512
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
public class Disabler : MonoBehaviour
|
||||
{
|
||||
[FormerlySerializedAs("Set")]
|
||||
[SerializeField] private SStructureBaseRuntimeSet _set;
|
||||
|
||||
[ContextMenu("Disable All")]
|
||||
public void DisableAll()
|
||||
{
|
||||
// Loop backwards since the list may change when disabling
|
||||
for (int i = _set._list.Count - 1; i >= 0; i--)
|
||||
{
|
||||
_set._list[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
[ContextMenu("Disable Random")]
|
||||
public void DisableRandom()
|
||||
{
|
||||
int index = Random.Range(0, _set._list.Count);
|
||||
_set._list[index].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f60f8a4b6b214b04083229f46bf1170b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
using AsteroidGame.Interfaces;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -16,6 +17,9 @@ namespace AsteroidGame.Entities
|
|||
[SerializeField] protected int _maxPower;
|
||||
[SerializeField] protected int _currentPower;
|
||||
|
||||
[Header("Configuration")]
|
||||
[SerializeField] private SStructureBaseRuntimeSet _structureBaseSet;
|
||||
|
||||
#region Private
|
||||
|
||||
#endregion
|
||||
|
@ -28,12 +32,20 @@ namespace AsteroidGame.Entities
|
|||
|
||||
#endregion
|
||||
|
||||
private void OnEnable()
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
if (!_isConsumer && !_isGenerator)
|
||||
{
|
||||
Debug.LogWarning("Power consumer/generator not set!");
|
||||
}
|
||||
_structureBaseSet.Add(this);
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_structureBaseSet.Remove(this);
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.Entities
|
||||
{
|
||||
[CreateAssetMenu(fileName = "newStructureList", menuName = "Structures/StructureList")]
|
||||
public class StructureBaseScriptableObject : ScriptableObject
|
||||
{
|
||||
public List<StructureBase> _structureList;
|
||||
}
|
||||
|
||||
// public static class MakeScriptableObject
|
||||
// {
|
||||
// [MenuItem("Assets/Create/ScriptableObject:AvailableStructures")]
|
||||
// public static void CreateMyAsset()
|
||||
// {
|
||||
// StructureBaseScriptableObject asset = ScriptableObject.CreateInstance<StructureBaseScriptableObject>();
|
||||
//
|
||||
// AssetDatabase.CreateAsset(asset, "Assets/Entities/Structures/AvailableStructures.asset");
|
||||
// AssetDatabase.SaveAssets();
|
||||
//
|
||||
// EditorUtility.FocusProjectWindow();
|
||||
//
|
||||
// Selection.activeObject = asset;
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -22,14 +22,16 @@ namespace AsteroidGame.Entities
|
|||
[SerializeField] private Transform _barrel;
|
||||
|
||||
#region Privates
|
||||
[Header("Target")]
|
||||
[SerializeField] private SEnemyBaseRuntimeSet _activeEnemies;
|
||||
[SerializeField] private EnemyBase _targetEnemy;
|
||||
|
||||
[SerializeField] private enum TargetStrategy
|
||||
{
|
||||
ClosestEnemy,
|
||||
LowestHealth
|
||||
};
|
||||
|
||||
[SerializeField] private EnemyBase _targetEnemy;
|
||||
|
||||
[SerializeField] private Transform[] _buildingParts;
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -748,6 +748,7 @@ MonoBehaviour:
|
|||
_centerPosition: {fileID: 5103935544759496321}
|
||||
_basePosition: {fileID: 8324879816836607384}
|
||||
_uiFriendlyName: Turret
|
||||
_entityBaseSet: {fileID: 11400000, guid: c5542e77624472441a67b1f34e19a116, type: 2}
|
||||
_cost: 10
|
||||
_buildPlacementBlocked: 0
|
||||
_buildTimer: 0
|
||||
|
@ -755,6 +756,7 @@ MonoBehaviour:
|
|||
_isConsumer: 1
|
||||
_maxPower: 10
|
||||
_currentPower: 0
|
||||
_structureBaseSet: {fileID: 11400000, guid: bccdf438a1004a444bc24492728d6fbd, type: 2}
|
||||
_weaponRange: 40
|
||||
_damage: 1
|
||||
_fireRate: 1
|
||||
|
@ -763,5 +765,6 @@ MonoBehaviour:
|
|||
_score: 0
|
||||
_turretHead: {fileID: 5103935544653627402}
|
||||
_barrel: {fileID: 5103935545559248087}
|
||||
_activeEnemies: {fileID: 11400000, guid: 5f6dc84d75dbd9a459e519de42279066, type: 2}
|
||||
_targetEnemy: {fileID: 0}
|
||||
_buildingParts: []
|
||||
|
|
|
@ -1,30 +1,28 @@
|
|||
using System.Collections.Generic;
|
||||
using AsteroidGame.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AsteroidGame.Handlers
|
||||
{
|
||||
public class BuildingHandler : HandlerBase
|
||||
{
|
||||
[Header("Config")]
|
||||
[Header("Config")]
|
||||
[SerializeField] private Color _colorGhost = new Color(1f, 1f, 1f, 0.12f);
|
||||
[SerializeField] private Color _colorBuildingBlocked = new Color(1f, 0f, 0f, 0.12f);
|
||||
[SerializeField] private Material _ghostStructureMaterial;
|
||||
|
||||
[Header("State")]
|
||||
[Header("State")]
|
||||
[SerializeField] private bool _isBuilding;
|
||||
[SerializeField] private int _buildingSelector;
|
||||
|
||||
[Header("Structures")]
|
||||
[SerializeField] private StructureBaseScriptableObject _availableStructuresObject;
|
||||
[FormerlySerializedAs("_availableStructures")]
|
||||
[Header("Structures")]
|
||||
[SerializeField] private SStructureBaseList _availableSStructures;
|
||||
|
||||
#region Private
|
||||
|
||||
private readonly Dictionary<int, StructureBase> _availableStructures = new();
|
||||
private Color _colorCurrent;
|
||||
private Camera _camera;
|
||||
[SerializeField] private List<StructureBase> _activeStructures;
|
||||
private Vector3 _tempVec;
|
||||
private Plane _buildPlane;
|
||||
private StructureBase _tempStructure;
|
||||
|
@ -32,17 +30,18 @@ namespace AsteroidGame.Handlers
|
|||
private MeshRenderer[] _ghostStructureMeshRenderers;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
for (int i = 0; i < _availableStructuresObject._structureList.Count; i++)
|
||||
{
|
||||
_availableStructures.Add(i, _availableStructuresObject._structureList[i]);
|
||||
}
|
||||
// for (int i = 0; i < _availableStructuresObject._structureList.Count; i++)
|
||||
// {
|
||||
// _availableStructures.Add(i, _availableStructuresObject._structureList[i]);
|
||||
// }
|
||||
|
||||
_camera = Camera.main;
|
||||
_buildPlane = new Plane(Vector3.up, Vector3.zero);
|
||||
_activeStructures.Clear();
|
||||
//_activeStructures.Clear();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
@ -89,7 +88,6 @@ namespace AsteroidGame.Handlers
|
|||
}
|
||||
|
||||
SpawnStructure();
|
||||
|
||||
}
|
||||
|
||||
private void AbortPlaceStructure()
|
||||
|
@ -109,7 +107,8 @@ namespace AsteroidGame.Handlers
|
|||
|
||||
private void SpawnGhostStructure()
|
||||
{
|
||||
_ghostStructure = Instantiate(_availableStructures[_buildingSelector], GetPlanePoint(), Quaternion.identity, transform);
|
||||
_ghostStructure = Instantiate(_availableSStructures._structureList[_buildingSelector], GetPlanePoint(), Quaternion.identity,
|
||||
transform);
|
||||
_ghostStructure.name = "GhostStructure";
|
||||
|
||||
var rb = _ghostStructure.gameObject.AddComponent<Rigidbody>();
|
||||
|
@ -132,12 +131,14 @@ namespace AsteroidGame.Handlers
|
|||
|
||||
private void SpawnStructure()
|
||||
{
|
||||
_tempStructure = Instantiate(_availableStructures[_buildingSelector], GetPlanePoint(), Quaternion.identity, transform);
|
||||
_activeStructures.Add(_tempStructure);
|
||||
_tempStructure = Instantiate(_availableSStructures._structureList[_buildingSelector], GetPlanePoint(), Quaternion.identity,
|
||||
transform);
|
||||
// _activeStructures.Add(_tempStructure);
|
||||
// _buildingLists[0].Add(_tempStructure);
|
||||
}
|
||||
|
||||
#region Getters
|
||||
|
||||
|
||||
private Vector3 GetPlanePoint()
|
||||
{
|
||||
Ray ray = _camera.ScreenPointToRay(Mouse.current.position.ReadValue());
|
||||
|
@ -145,20 +146,20 @@ namespace AsteroidGame.Handlers
|
|||
{
|
||||
return ray.GetPoint(distance);
|
||||
}
|
||||
|
||||
|
||||
print("BuildPlaneNotHit");
|
||||
return Vector3.zero;
|
||||
}
|
||||
|
||||
public Dictionary<int, StructureBase> GetAvailableStructures()
|
||||
{
|
||||
return _availableStructures;
|
||||
}
|
||||
|
||||
public List<StructureBase> GetActiveStructures()
|
||||
{
|
||||
return _activeStructures;
|
||||
}
|
||||
|
||||
// public List<StructureBase> GetAvailableStructures()
|
||||
// {
|
||||
// return _availableStructures._structureList;
|
||||
// }
|
||||
|
||||
// public List<StructureBase> GetActiveStructures()
|
||||
// {
|
||||
// return _activeStructures;
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -170,6 +171,5 @@ namespace AsteroidGame.Handlers
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
|
@ -49,5 +49,4 @@ MonoBehaviour:
|
|||
_ghostStructureMaterial: {fileID: 2100000, guid: dc919a35edbf85647939132e73b39642, type: 2}
|
||||
_isBuilding: 0
|
||||
_buildingSelector: 0
|
||||
_availableStructuresObject: {fileID: 11400000, guid: f789f54c47873664284d6e8544724693, type: 2}
|
||||
_activeStructures: []
|
||||
_availableSStructures: {fileID: 11400000, guid: f789f54c47873664284d6e8544724693, type: 2}
|
||||
|
|
|
@ -1,46 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
using AsteroidGame.Entities;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
|
||||
namespace AsteroidGame.Handlers
|
||||
{
|
||||
public class EnemyHandler : HandlerBase
|
||||
{
|
||||
[Header("Parameters")]
|
||||
[SerializeField] [Range(0.1f, 60f)] float _spawnRate = 60f;
|
||||
[SerializeField] int _objectPoolSize = 15;
|
||||
[SerializeField] [Range(0.1f, 60f)] private float _spawnRate = 60f;
|
||||
[SerializeField] private int _objectPoolSize = 15;
|
||||
|
||||
[Header("Prefabs")]
|
||||
[SerializeField] GameObject _objectPool;
|
||||
[SerializeField] List<GameObject> _enemyPrefabs = new List<GameObject>();
|
||||
[Header("Configuration")]
|
||||
[SerializeField] private SEnemyBaseList _availableEnemies;
|
||||
|
||||
[Header("Lists")]
|
||||
[SerializeField] List<GameObject> _enemyPools = new List<GameObject>();
|
||||
[SerializeField] List<GameObject> _allEnemies = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void AddEnemyToAllEnemies(GameObject enemy)
|
||||
{
|
||||
_allEnemies.Add(enemy);
|
||||
}
|
||||
|
||||
public void RemoveEnemy(GameObject enemy)
|
||||
{
|
||||
_allEnemies.Remove(enemy);
|
||||
}
|
||||
|
||||
public List<GameObject> ReturnAllEnemies()
|
||||
{
|
||||
return _allEnemies;
|
||||
}
|
||||
|
||||
public void NotifyEnemiesOfNewPath()
|
||||
{
|
||||
BroadcastMessage("RecalculatePath", SendMessageOptions.DontRequireReceiver);
|
||||
}
|
||||
[SerializeField] private SEnemyBaseRuntimeSet _activeEnemies;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -46,7 +46,5 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
_spawnRate: 60
|
||||
_objectPoolSize: 15
|
||||
_objectPool: {fileID: 0}
|
||||
_enemyPrefabs: []
|
||||
_enemyPools: []
|
||||
_allEnemies: []
|
||||
_availableEnemies: {fileID: 11400000, guid: 00c435d92e1df55499826c91b4f1e62f, type: 2}
|
||||
_activeEnemies: {fileID: 11400000, guid: 5f6dc84d75dbd9a459e519de42279066, type: 2}
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "Handlers",
|
||||
"rootNamespace": "AsteroidGame",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:f008ecc6829887e478aeb5eb004eb01b",
|
||||
"GUID:f26d68a0bdefa1043b120b820f55e190",
|
||||
"GUID:5041af1ee0cf75e4a9a52f5f23a0bfae",
|
||||
"GUID:bc7863ca0989b494d84426bfd28432fa",
|
||||
"GUID:17a5862fcd6383b4b97bad4dcb1e2e5d"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AsteroidGame.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
|
@ -13,26 +12,13 @@ namespace AsteroidGame.Handlers
|
|||
[SerializeField] private float _powerFactor;
|
||||
|
||||
[Header("Connections")]
|
||||
[SerializeField] private BuildingHandler _buildingHandler;
|
||||
|
||||
#region Private
|
||||
|
||||
[SerializeField] private List<StructureBase> _activeStructures = new();
|
||||
|
||||
#endregion
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
_buildingHandler = FindObjectOfType<BuildingHandler>();
|
||||
_activeStructures = _buildingHandler.GetActiveStructures();
|
||||
}
|
||||
|
||||
[SerializeField] private SStructureBaseRuntimeSet _activeStructures;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_powerConsumption = 0;
|
||||
_powerCapacity = 0;
|
||||
foreach (var structure in _activeStructures)
|
||||
foreach (var structure in _activeStructures._list)
|
||||
{
|
||||
if (structure.IsConsumer)
|
||||
{
|
||||
|
|
|
@ -47,5 +47,4 @@ MonoBehaviour:
|
|||
_powerConsumption: 0
|
||||
_powerCapacity: 0
|
||||
_powerFactor: 0
|
||||
_buildingHandler: {fileID: 0}
|
||||
_activeStructures: []
|
||||
_activeStructures: {fileID: 11400000, guid: bccdf438a1004a444bc24492728d6fbd, type: 2}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AsteroidGame.Handlers
|
||||
{
|
||||
|
|
|
@ -274,6 +274,51 @@ Transform:
|
|||
m_CorrespondingSourceObject: {fileID: 5263199550015624126, guid: 2e352ad6389b4234083764d15d4e6a5f, type: 3}
|
||||
m_PrefabInstance: {fileID: 5263199549561108292}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &732841883
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 732841885}
|
||||
- component: {fileID: 732841884}
|
||||
m_Layer: 0
|
||||
m_Name: Disabler
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &732841884
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 732841883}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: f60f8a4b6b214b04083229f46bf1170b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_set: {fileID: 11400000, guid: bccdf438a1004a444bc24492728d6fbd, type: 2}
|
||||
--- !u!4 &732841885
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 732841883}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: -1.8230318, y: 5.3787107, z: -4.0428505}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!4 &991542217 stripped
|
||||
Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 493861824998956378, guid: 57a75520298c47140a928041b05d7f3c, type: 3}
|
||||
|
@ -751,6 +796,18 @@ PrefabInstance:
|
|||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 664620742648054781, guid: 3a89f87af6ee84a459d98a4c296dd1be, type: 3}
|
||||
propertyPath: _availableStructures
|
||||
value:
|
||||
objectReference: {fileID: 11400000, guid: f789f54c47873664284d6e8544724693, type: 2}
|
||||
- target: {fileID: 664620742648054781, guid: 3a89f87af6ee84a459d98a4c296dd1be, type: 3}
|
||||
propertyPath: _buildingLists.Array.size
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 664620742648054781, guid: 3a89f87af6ee84a459d98a4c296dd1be, type: 3}
|
||||
propertyPath: _buildingLists.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 11400000, guid: bccdf438a1004a444bc24492728d6fbd, type: 2}
|
||||
- target: {fileID: 664620742648054783, guid: 3a89f87af6ee84a459d98a4c296dd1be, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: BuildingHandler
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b8bc87700fc5a44b88c1b13c4bdb3cf
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AsteroidGame.ScriptableObjects
|
||||
{
|
||||
public abstract class SRuntimeSet<T> : ScriptableObject
|
||||
{
|
||||
public List<T> _list;
|
||||
|
||||
public void Add(T component)
|
||||
{
|
||||
_list.Add(component);
|
||||
}
|
||||
|
||||
public void Remove(T component)
|
||||
{
|
||||
_list.Remove(component);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e81b384c7f010b4fa3c1b8f293a4c42
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,10 +1,7 @@
|
|||
{
|
||||
"name": "Scripts",
|
||||
"name": "ScriptableObjects",
|
||||
"rootNamespace": "AsteroidGame",
|
||||
"references": [
|
||||
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||
"GUID:f008ecc6829887e478aeb5eb004eb01b"
|
||||
],
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 896bd127e4aae4c4d86d99385f967c0c
|
||||
guid: eb3099ff524d60545a136315a154d67b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 624b0cf4f0dd38a459121c046c909786
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -3,13 +3,15 @@ using AsteroidGame.Entities;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using AsteroidGame.Handlers;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AsteroidGame.UI
|
||||
{
|
||||
public class BuildMenuUiController : MonoBehaviour
|
||||
{
|
||||
[FormerlySerializedAs("_availableStructuresObject")]
|
||||
[Header("Structures")]
|
||||
[SerializeField] private StructureBaseScriptableObject _availableStructuresObject;
|
||||
[SerializeField] private SStructureBaseList _availableSStructuresObject;
|
||||
|
||||
private VisualElement _mRoot;
|
||||
private VisualElement _mSlotContainer;
|
||||
|
@ -18,7 +20,7 @@ namespace AsteroidGame.UI
|
|||
|
||||
private void OnEnable()
|
||||
{
|
||||
_buildings = _availableStructuresObject._structureList;
|
||||
_buildings = _availableSStructuresObject._structureList;
|
||||
_buildingHandler = FindObjectOfType<BuildingHandler>();
|
||||
|
||||
//Store the root from the UI Document component
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cscripts_005Cscriptableobjects/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
|
@ -1,6 +1,7 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cenemies/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cenemies_005Cscripts/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cscriptableobjects/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cstructures/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cstructures_005Cpowerplant/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Centities_005Cstructures_005Cscriptableobjects/@EntryIndexedValue">True</s:Boolean>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cscripts/@EntryIndexedValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=assets_005Cscripts_005Cscriptableobjects/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
Reference in New Issue