Refactor. One class for bots and player
This commit is contained in:
parent
4f188bc304
commit
0b0ac51fb6
@ -352,6 +352,9 @@ AnimatorStateMachine:
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 9222683897014232595}
|
||||
m_Position: {x: 490, y: 330, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: -1414219465498408593}
|
||||
m_Position: {x: 70, y: -10, z: 0}
|
||||
m_ChildStateMachines: []
|
||||
m_AnyStateTransitions:
|
||||
- {fileID: -4341192428833849287}
|
||||
@ -386,6 +389,32 @@ AnimatorStateTransition:
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1102 &-1414219465498408593
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: New State
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
m_Mirror: 0
|
||||
m_SpeedParameterActive: 0
|
||||
m_MirrorParameterActive: 0
|
||||
m_CycleOffsetParameterActive: 0
|
||||
m_TimeParameterActive: 0
|
||||
m_Motion: {fileID: 7400000, guid: 5badc0a8e5470a8499375c487e54213d, type: 2}
|
||||
m_Tag:
|
||||
m_SpeedParameter:
|
||||
m_MirrorParameter:
|
||||
m_CycleOffsetParameter:
|
||||
m_TimeParameter:
|
||||
--- !u!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -400,49 +429,55 @@ AnimatorController:
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: BackToIdle
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Build
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: TreeAttack
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Move
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: SuperJump
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Frozen
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: isMoving
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
- m_Name: Death
|
||||
m_Type: 9
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
@ -456,6 +491,31 @@ AnimatorController:
|
||||
m_IKPass: 0
|
||||
m_SyncedLayerAffectsTiming: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
--- !u!1101 &166200867799722436
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name:
|
||||
m_Conditions:
|
||||
- m_ConditionMode: 1
|
||||
m_ConditionEvent: Death
|
||||
m_EventTreshold: 0
|
||||
m_DstStateMachine: {fileID: 0}
|
||||
m_DstState: {fileID: -1414219465498408593}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 0
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.53125
|
||||
m_HasExitTime: 1
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &354894258193955894
|
||||
AnimatorStateTransition:
|
||||
m_ObjectHideFlags: 1
|
||||
@ -805,6 +865,7 @@ AnimatorState:
|
||||
- {fileID: 1079191915755825572}
|
||||
- {fileID: -7864811333266388210}
|
||||
- {fileID: -9016822592688904379}
|
||||
- {fileID: 166200867799722436}
|
||||
m_StateMachineBehaviours: []
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
|
@ -1668,7 +1668,7 @@ Animator:
|
||||
m_GameObject: {fileID: 3762867976042010436}
|
||||
m_Enabled: 1
|
||||
m_Avatar: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000, guid: 6c6726efa8f26a44c89dbcc255bf46f9, type: 2}
|
||||
m_Controller: {fileID: 9100000, guid: 9e1a6090cd4d65d4599676c24fcb5cff, type: 2}
|
||||
m_CullingMode: 0
|
||||
m_UpdateMode: 0
|
||||
m_ApplyRootMotion: 0
|
||||
|
@ -14,6 +14,6 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
fieldDataPath: FieldData
|
||||
cameraDataPath: CameraData
|
||||
playerDataPath: PlayerData
|
||||
unitDataPath: UnitsData
|
||||
weaponDataPath: WeaponsData
|
||||
enemyDataPath: EnemyData
|
||||
uiDataPath: UIData
|
||||
|
@ -40,3 +40,7 @@ MonoBehaviour:
|
||||
_texture: {fileID: 2800000, guid: 1a76a79d5a83143479c76f4f37c4b896, type: 3}
|
||||
_vfxPrefab: {fileID: 5732852186060375560, guid: 54d847a18c62f57479c53469d4398ceb,
|
||||
type: 3}
|
||||
- _unitColor: 4
|
||||
_texture: {fileID: 2800000, guid: 779719648deedb4478ddebb3b81751ef, type: 3}
|
||||
_vfxPrefab: {fileID: 1651852338557341938, guid: fa6c1fc3da7c8d24c85a88b00cf598d4,
|
||||
type: 3}
|
||||
|
@ -9,17 +9,8 @@ MonoBehaviour:
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2d46325a4e4e45338d7e9733fb8d6013, type: 3}
|
||||
m_Name: PlayerData
|
||||
m_Script: {fileID: 11500000, guid: d802c0065ac04effbd7685b3eddc7574, type: 3}
|
||||
m_Name: UIData
|
||||
m_EditorClassIdentifier:
|
||||
spawnPos:
|
||||
x: 7
|
||||
z: 8
|
||||
playerPrefab: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055,
|
||||
type: 3}
|
||||
joystickView: {fileID: 4385872142190176059, guid: 4df6913b39f4979429158c344680d83f,
|
||||
type: 3}
|
||||
color: 3
|
||||
manaRegen: 10
|
||||
maxMana: 100
|
||||
maxHP: 100
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd53832b22ec4e74690abaff5d2df858
|
||||
guid: 304619b28daaa9849806b3cbd0b76bee
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
45
Assets/Resources/Data/UnitsData.asset
Normal file
45
Assets/Resources/Data/UnitsData.asset
Normal file
@ -0,0 +1,45 @@
|
||||
%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: 2d46325a4e4e45338d7e9733fb8d6013, type: 3}
|
||||
m_Name: UnitsData
|
||||
m_EditorClassIdentifier:
|
||||
_units:
|
||||
- isPlayer: 1
|
||||
spawnPos:
|
||||
x: 9
|
||||
z: 10
|
||||
unitPrefa: {fileID: 7527582019267571087, guid: f102085e8bc4cad4992d43b84dee1055,
|
||||
type: 3}
|
||||
color: 3
|
||||
manaRegen: 10
|
||||
maxMana: 100
|
||||
maxHP: 100
|
||||
- isPlayer: 0
|
||||
spawnPos:
|
||||
x: 0
|
||||
z: 0
|
||||
unitPrefa: {fileID: 3762867976042010436, guid: d00f156879942114488e4db0689a3fb7,
|
||||
type: 3}
|
||||
color: 4
|
||||
manaRegen: 10
|
||||
maxMana: 100
|
||||
maxHP: 100
|
||||
- isPlayer: 0
|
||||
spawnPos:
|
||||
x: 3
|
||||
z: 10
|
||||
unitPrefa: {fileID: 742650227762578155, guid: 97b4a76c55741764e880b63d6e1514a9,
|
||||
type: 3}
|
||||
color: 0
|
||||
manaRegen: 10
|
||||
maxMana: 100
|
||||
maxHP: 100
|
8
Assets/Resources/Data/UnitsData.asset.meta
Normal file
8
Assets/Resources/Data/UnitsData.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee407bd2eae9bbf4d9d40a8ac08462e6
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,125 +0,0 @@
|
||||
using Data;
|
||||
using DG.Tweening;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Chars
|
||||
{
|
||||
public class Enemy : IUnit
|
||||
{
|
||||
|
||||
private EnemyInfo _data;
|
||||
private HexCell _cell;
|
||||
private HexGrid _grid;
|
||||
private GameObject _instance;
|
||||
private bool _isAlive;
|
||||
private UnitView _unitView;
|
||||
private bool _isBusy;
|
||||
private Animator _animator;
|
||||
private AnimLength _animLength;
|
||||
private BarCanvas _barCanvas;
|
||||
private float _mana;
|
||||
private float _hp;
|
||||
|
||||
public UnitView EnemyView => _unitView;
|
||||
public bool IsBusy => _isBusy;
|
||||
|
||||
public Enemy(EnemyInfo enemyInfo, HexGrid grid)
|
||||
{
|
||||
_data = enemyInfo;
|
||||
_grid = grid;
|
||||
_isAlive = false;
|
||||
}
|
||||
public void Move(HexDirection direction)
|
||||
{
|
||||
if (_cell.GetNeighbor(direction))
|
||||
{
|
||||
_isBusy = true;
|
||||
_cell = _cell.GetNeighbor(direction);
|
||||
_instance.transform.DOLookAt(_cell.transform.position, 0.1f);
|
||||
_animator.SetTrigger("Move");
|
||||
_animator.SetBool("isMoving", _isBusy);
|
||||
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAnimLength()
|
||||
{
|
||||
AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips;
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
switch (clip.name)
|
||||
{
|
||||
case "MoveJump":
|
||||
_animLength.Move = clip.length;
|
||||
break;
|
||||
case "Attack":
|
||||
_animLength.Attack = clip.length;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateCanvas()
|
||||
{
|
||||
if (_hp > _data.maxHP)
|
||||
_hp = _data.maxHP;
|
||||
if (_mana > _data.maxMana)
|
||||
_mana = _data.maxMana;
|
||||
|
||||
float hp = _hp;
|
||||
float mana = _mana;
|
||||
float maxHp = _data.maxHP;
|
||||
float maxMana = _data.maxMana;
|
||||
_barCanvas.ManaBar.DOFillAmount(mana / maxMana, 0.5f).SetEase(Ease.InQuad);
|
||||
_barCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
|
||||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
if(!_isAlive)
|
||||
{
|
||||
_cell = _grid.GetCellFromCoord(_data.spawnPos);
|
||||
_instance = Object.Instantiate(_data.playerPrefab, _cell.transform.parent);
|
||||
_instance.transform.localPosition = _cell.transform.localPosition;
|
||||
_cell.PaintHex(_data.color);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
_cell.GetNeighbor((HexDirection)i).PaintHex(_data.color);
|
||||
}
|
||||
|
||||
_isAlive = true;
|
||||
_unitView = _instance.GetComponent<UnitView>();
|
||||
_animator = _instance.GetComponent<Animator>();
|
||||
_barCanvas = _unitView.BarCanvas.GetComponent<BarCanvas>();
|
||||
_hp = _data.maxHP;
|
||||
_mana = _data.maxMana;
|
||||
SetAnimLength();
|
||||
SetUpActions();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetUpActions()
|
||||
{
|
||||
_unitView.OnHit += Damage;
|
||||
}
|
||||
public void Death()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void StartAttack(Vector2 direction)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public void Damage(int dmg)
|
||||
{
|
||||
_hp -= dmg;
|
||||
UpdateCanvas();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a9b8eff7bb74f8ca38e1d6d8e9a2757
|
||||
timeCreated: 1639488978
|
@ -1,15 +0,0 @@
|
||||
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Chars
|
||||
{
|
||||
public interface IUnit
|
||||
{
|
||||
public void Move(HexDirection direction);
|
||||
public void Spawn();
|
||||
public void Death();
|
||||
public void StartAttack(Vector2 direction);
|
||||
public void Damage(int dmg);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 478a54a7aa274988b997c4f96761e5e4
|
||||
timeCreated: 1639488877
|
@ -3,6 +3,7 @@ using CamControl;
|
||||
using Chars;
|
||||
using Data;
|
||||
using HexFiled;
|
||||
using Units;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Controller
|
||||
@ -14,27 +15,36 @@ namespace Controller
|
||||
var hexGrid = new HexGrid(data.FieldData);
|
||||
controllers.Add(hexGrid);
|
||||
hexGrid.OnHexPainted += DoSomething;
|
||||
|
||||
Player player = new Player(data.PlayerData, data.WeaponsData.WeaponsList[0], hexGrid);
|
||||
List<IUnit> units = new List<IUnit> { player };
|
||||
data.EnemyData.Enemies.ForEach(enemyInfo =>
|
||||
Unit player;
|
||||
|
||||
List<Unit> units = new List<Unit>();
|
||||
data.UnitData.Units.ForEach(unit =>
|
||||
{
|
||||
var enemy = new Enemy(enemyInfo, hexGrid);
|
||||
var enemyController = new EnemyController(enemyInfo, enemy);
|
||||
controllers.Add(enemyController);
|
||||
units.Add(enemy);
|
||||
if (unit.isPlayer)
|
||||
{
|
||||
player = new Unit(unit, data.WeaponsData.WeaponsList[0], hexGrid);
|
||||
PlayerControl playerControl = new PlayerControl(player, data.UIData);
|
||||
controllers.Add(playerControl);
|
||||
CameraControl cameraControl =
|
||||
new CameraControl(Camera.main, data.CameraData);
|
||||
controllers.Add(cameraControl);
|
||||
player.onPlayerSpawned += cameraControl.InitCameraControl;
|
||||
units.Add(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
var enemy = new Unit(unit,data.WeaponsData.WeaponsList[0], hexGrid);
|
||||
var enemyController = new EnemyController(unit, enemy);
|
||||
controllers.Add(enemyController);
|
||||
units.Add(enemy);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
var unitFactory = new UnitFactory(units);
|
||||
hexGrid.OnGridLoaded += unitFactory.Spawn;
|
||||
|
||||
PlayerControl playerControl = new PlayerControl(player, data.PlayerData);
|
||||
controllers.Add(playerControl);
|
||||
|
||||
CameraControl cameraControl =
|
||||
new CameraControl(Camera.main, data.CameraData);
|
||||
controllers.Add(cameraControl);
|
||||
player.onPlayerSpawned += cameraControl.InitCameraControl;
|
||||
|
||||
|
||||
}
|
||||
private void DoSomething(HexCell cell)
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.IO;
|
||||
using Chars;
|
||||
using DefaultNamespace.Weapons;
|
||||
using Runtime.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
@ -13,26 +12,29 @@ namespace Data
|
||||
private FieldData _fieldData;
|
||||
[SerializeField] private string cameraDataPath;
|
||||
private CameraData _cameraData;
|
||||
[SerializeField] private string playerDataPath;
|
||||
private PlayerData _playerData;
|
||||
[SerializeField] private string unitDataPath;
|
||||
private UnitData _unitData;
|
||||
[SerializeField] private string weaponDataPath;
|
||||
private WeaponsData _weaponData;
|
||||
[SerializeField] private string enemyDataPath;
|
||||
private EnemyData _enemyData;
|
||||
|
||||
[SerializeField] private string uiDataPath;
|
||||
private UIData _uiData;
|
||||
|
||||
public EnemyData EnemyData
|
||||
|
||||
public UIData UIData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_enemyData == null)
|
||||
if (_uiData == null)
|
||||
{
|
||||
_enemyData = Load<EnemyData>("Data/" + enemyDataPath);
|
||||
_uiData = Load<UIData>("Data/" + uiDataPath);
|
||||
}
|
||||
|
||||
return _enemyData;
|
||||
return _uiData;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WeaponsData WeaponsData
|
||||
{
|
||||
get
|
||||
@ -71,16 +73,16 @@ namespace Data
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerData PlayerData
|
||||
public UnitData UnitData
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_playerData == null)
|
||||
if (_unitData == null)
|
||||
{
|
||||
_playerData = Load<PlayerData>("Data/" + playerDataPath);
|
||||
_unitData = Load<UnitData>("Data/" + unitDataPath);
|
||||
}
|
||||
|
||||
return _playerData;
|
||||
return _unitData;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "EnemyData", menuName = "Data/EnemyData", order = 0)]
|
||||
public class EnemyData : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<EnemyInfo> _enemies;
|
||||
public List<EnemyInfo> Enemies => _enemies;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EnemyInfo
|
||||
{
|
||||
public HexCoordinates spawnPos;
|
||||
public GameObject playerPrefab;
|
||||
public UnitColor color;
|
||||
public int maxHP;
|
||||
public int maxMana;
|
||||
public int manaRegen;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a68fdab0e3dd421d93555195f3a2bd5b
|
||||
timeCreated: 1640183173
|
@ -2,23 +2,19 @@
|
||||
using HexFiled;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Runtime.Data
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "FieldData", menuName = "Data/Field Data")]
|
||||
public class FieldData : ScriptableObject
|
||||
{
|
||||
public int width = 6;
|
||||
public int height = 6;
|
||||
public Color defaultColor = Color.white;
|
||||
public Color touchedColor = Color.magenta;
|
||||
public int hexCaptureManaCost;
|
||||
|
||||
public GameObject cellPrefab;
|
||||
public TMP_Text cellLabelPrefab;
|
||||
public GameObject CoordinatesCanvas;
|
||||
public Texture DefaultTexture;
|
||||
public List<CellColor> colors;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using Chars;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "PlayerData", menuName = "Data/PlayerData", order = 0)]
|
||||
public class PlayerData : ScriptableObject
|
||||
{
|
||||
public HexCoordinates spawnPos;
|
||||
public GameObject playerPrefab;
|
||||
public PlayerControlView joystickView;
|
||||
public UnitColor color;
|
||||
public int manaRegen;
|
||||
public int maxMana;
|
||||
public int maxHP;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Data/UIData.cs
Normal file
11
Assets/Scripts/Data/UIData.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using Chars;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "UIData", menuName = "Data/UI Data", order = 0)]
|
||||
public class UIData : ScriptableObject
|
||||
{
|
||||
public PlayerControlView joystickView;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Data/UIData.cs.meta
Normal file
3
Assets/Scripts/Data/UIData.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d802c0065ac04effbd7685b3eddc7574
|
||||
timeCreated: 1640399053
|
28
Assets/Scripts/Data/UnitData.cs
Normal file
28
Assets/Scripts/Data/UnitData.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Chars;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Data
|
||||
{
|
||||
[CreateAssetMenu(fileName = "UnitData", menuName = "Data/UnitData", order = 0)]
|
||||
public class UnitData : ScriptableObject
|
||||
{
|
||||
[SerializeField] private List<UnitInfo> _units;
|
||||
|
||||
public List<UnitInfo> Units => _units;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct UnitInfo
|
||||
{
|
||||
public bool isPlayer;
|
||||
public HexCoordinates spawnPos;
|
||||
public GameObject unitPrefa;
|
||||
public UnitColor color;
|
||||
public int manaRegen;
|
||||
public int maxMana;
|
||||
public int maxHP;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
|
||||
namespace DefaultNamespace.Weapons
|
||||
{
|
||||
@ -13,17 +13,4 @@ namespace DefaultNamespace.Weapons
|
||||
|
||||
public List<Weapon> WeaponsList => _weapons;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct Weapon
|
||||
{
|
||||
public GameObject objectToThrow;
|
||||
public GameObject VFXGameObject;
|
||||
public int manaCost;
|
||||
public int damage;
|
||||
public float speed;
|
||||
public int disnatce;
|
||||
public float reloadTime;
|
||||
public int shots;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Data;
|
||||
using Runtime.Controller;
|
||||
using Runtime.Data;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
@ -5,6 +5,7 @@
|
||||
GREEN,
|
||||
RED,
|
||||
GREY,
|
||||
YELLOW
|
||||
YELLOW,
|
||||
BLUE
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
using Controller;
|
||||
using Data;
|
||||
using Runtime.Controller;
|
||||
using Units;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Chars
|
||||
{
|
||||
public class EnemyController : IFixedExecute, IExecute
|
||||
{
|
||||
private Enemy _enemy;
|
||||
private Unit _enemy;
|
||||
private Camera _camera;
|
||||
|
||||
public EnemyController(EnemyInfo enemyInfo, Enemy enemy)
|
||||
public EnemyController(UnitInfo enemyInfo, Unit enemy)
|
||||
{
|
||||
_enemy = enemy;
|
||||
_camera = Camera.main;
|
||||
@ -24,10 +25,10 @@ namespace Chars
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (_enemy.EnemyView != null)
|
||||
if (_enemy.UnitView != null)
|
||||
{
|
||||
_enemy.EnemyView.BarCanvas.transform.LookAt(
|
||||
_enemy.EnemyView.BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
||||
_enemy.UnitView.BarCanvas.transform.LookAt(
|
||||
_enemy.UnitView.BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
||||
_camera.transform.rotation * Vector3.up);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using Controller;
|
||||
using Data;
|
||||
using HexFiled;
|
||||
using Runtime.Controller;
|
||||
using Units;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@ -10,17 +11,17 @@ namespace Chars
|
||||
{
|
||||
public class PlayerControl : IFixedExecute, IExecute
|
||||
{
|
||||
private Player _player;
|
||||
private Unit _unit;
|
||||
private FloatingJoystick _moveJoystick;
|
||||
private FloatingJoystick _attackJoystick;
|
||||
private Camera _camera;
|
||||
private Vector2 _attackDircetion;
|
||||
|
||||
|
||||
public PlayerControl(Player player, PlayerData playerData)
|
||||
public PlayerControl(Unit unit, UIData uiData)
|
||||
{
|
||||
_player = player;
|
||||
var joyView = Object.Instantiate(playerData.joystickView);
|
||||
_unit = unit;
|
||||
var joyView = Object.Instantiate(uiData.joystickView);
|
||||
_moveJoystick = joyView.MoveJoystick;
|
||||
_attackJoystick = joyView.AttackJoystick;
|
||||
_camera = Camera.main;
|
||||
@ -30,26 +31,26 @@ namespace Chars
|
||||
|
||||
private void DoAttack()
|
||||
{
|
||||
_player.UnitView.AimCanvas.SetActive(false);
|
||||
_player.StartAttack(_attackDircetion);
|
||||
_unit.UnitView.AimCanvas.SetActive(false);
|
||||
_unit.StartAttack(_attackDircetion);
|
||||
}
|
||||
|
||||
private void AimCanvas()
|
||||
{
|
||||
_player.UnitView.AimCanvas.SetActive(true);
|
||||
_unit.UnitView.AimCanvas.SetActive(true);
|
||||
}
|
||||
|
||||
public void FixedExecute()
|
||||
{
|
||||
if (!_player.IsBusy && _moveJoystick.Direction != Vector2.zero)
|
||||
if (!_unit.IsBusy && _moveJoystick.Direction != Vector2.zero)
|
||||
{
|
||||
_player.Move(VectorToDirection(_moveJoystick.Direction.normalized));
|
||||
_unit.Move(VectorToDirection(_moveJoystick.Direction.normalized));
|
||||
}
|
||||
|
||||
if (!_player.IsBusy && _attackJoystick.isPressed)
|
||||
if (!_unit.IsBusy && _attackJoystick.isPressed)
|
||||
{
|
||||
_attackDircetion = _attackJoystick.Direction.normalized;
|
||||
_player.Aim(_attackDircetion);
|
||||
_unit.Aim(_attackDircetion);
|
||||
}
|
||||
|
||||
}
|
||||
@ -92,10 +93,10 @@ namespace Chars
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (_player.UnitView != null)
|
||||
if (_unit.UnitView != null)
|
||||
{
|
||||
_player.UnitView.BarCanvas.transform.LookAt(
|
||||
_player.UnitView.BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
||||
_unit.UnitView.BarCanvas.transform.LookAt(
|
||||
_unit.UnitView.BarCanvas.transform.position + _camera.transform.rotation * Vector3.back,
|
||||
_camera.transform.rotation * Vector3.up);
|
||||
}
|
||||
}
|
@ -1,17 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Chars;
|
||||
using Data;
|
||||
using DefaultNamespace.Weapons;
|
||||
using DG.Tweening;
|
||||
using HexFiled;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
|
||||
namespace Chars
|
||||
namespace Units
|
||||
{
|
||||
public class Player : IUnit
|
||||
public class Unit
|
||||
{
|
||||
private bool _isAlive;
|
||||
private GameObject _instance;
|
||||
@ -23,7 +22,7 @@ namespace Chars
|
||||
private Animator _animator;
|
||||
private UnitView _unitView;
|
||||
private bool _isBusy;
|
||||
private PlayerData _data;
|
||||
private UnitInfo _data;
|
||||
private int _hp;
|
||||
private int _mana;
|
||||
private Weapon _weapon;
|
||||
@ -35,10 +34,10 @@ namespace Chars
|
||||
public GameObject PlayerInstance => _instance;
|
||||
public UnitView UnitView => _unitView;
|
||||
|
||||
public Player(PlayerData playerData, Weapon weapon, HexGrid hexGrid)
|
||||
public Unit(UnitInfo unitData, Weapon weapon, HexGrid hexGrid)
|
||||
{
|
||||
_weapon = weapon;
|
||||
_data = playerData;
|
||||
_data = unitData;
|
||||
_isAlive = false;
|
||||
_hexGrid = hexGrid;
|
||||
_isBusy = false;
|
||||
@ -97,10 +96,10 @@ namespace Chars
|
||||
_cell.PaintHex(_data.color);
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
_cell.GetNeighbor((HexDirection)i).PaintHex(_data.color);
|
||||
_cell.GetNeighbor((HexDirection)i)?.PaintHex(_data.color);
|
||||
}
|
||||
|
||||
_instance = Object.Instantiate(_data.playerPrefab, _cell.transform.parent);
|
||||
_instance = Object.Instantiate(_data.unitPrefa, _cell.transform.parent);
|
||||
_instance.transform.localPosition = _cell.transform.localPosition;
|
||||
onPlayerSpawned?.Invoke(_instance);
|
||||
_isAlive = true;
|
||||
@ -171,9 +170,15 @@ namespace Chars
|
||||
_barCanvas.HealthBar.DOFillAmount(hp / maxHp, 0.5f).SetEase(Ease.InQuad);
|
||||
}
|
||||
|
||||
public void Death()
|
||||
private void Death()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_unitView.OnStep -= MoveEnd;
|
||||
_unitView.OnAttackEnd -= AttackEnd;
|
||||
_unitView.OnAttack -= Attacking;
|
||||
_unitView.OnHit -= Damage;
|
||||
_isAlive = false;
|
||||
_animator.SetTrigger("Death");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -192,7 +197,7 @@ namespace Chars
|
||||
_direction = direction;
|
||||
}
|
||||
|
||||
public void Damage(int dmg)
|
||||
private void Damage(int dmg)
|
||||
{
|
||||
if (_hp - dmg <= 0f)
|
||||
{
|
||||
@ -200,6 +205,7 @@ namespace Chars
|
||||
}
|
||||
|
||||
_hp -= dmg;
|
||||
UpdateBarCanvas();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using Units;
|
||||
|
||||
namespace Chars
|
||||
{
|
||||
public class UnitFactory
|
||||
{
|
||||
private List<IUnit> _units;
|
||||
private List<Unit> _units;
|
||||
|
||||
public UnitFactory(List<IUnit> units)
|
||||
public UnitFactory(List<Unit> units)
|
||||
{
|
||||
_units = units;
|
||||
}
|
3
Assets/Scripts/Units/Views.meta
Normal file
3
Assets/Scripts/Units/Views.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26981711fd264680885d637f6f9122bf
|
||||
timeCreated: 1640398702
|
@ -5,6 +5,7 @@ using DefaultNamespace.Weapons;
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
|
||||
public class UnitView : MonoBehaviour
|
||||
{
|
||||
@ -15,7 +16,7 @@ public class UnitView : MonoBehaviour
|
||||
[SerializeField] private GameObject barCanvas;
|
||||
[SerializeField] private GameObject aimCanvas;
|
||||
|
||||
private Stack<ShotUIView> _shotUIStack;
|
||||
private Stack<ShotUIView> _shootUIStack;
|
||||
private Stack<ShotUIView> _toReloadStack;
|
||||
private Weapon _weapon;
|
||||
private int _manaRegen;
|
||||
@ -29,7 +30,7 @@ public class UnitView : MonoBehaviour
|
||||
|
||||
public void SetUp(Stack<ShotUIView> shots, Weapon weapon, Action RegenMana, int manaRegen)
|
||||
{
|
||||
_shotUIStack = shots;
|
||||
_shootUIStack = shots;
|
||||
_weapon = weapon;
|
||||
_toReloadStack = new Stack<ShotUIView>();
|
||||
_startRegen = RegenMana;
|
||||
@ -38,8 +39,8 @@ public class UnitView : MonoBehaviour
|
||||
|
||||
public bool Shoot()
|
||||
{
|
||||
if (_shotUIStack.Count == 0) return false;
|
||||
var shot = _shotUIStack.Pop();
|
||||
if (_shootUIStack.Count == 0) return false;
|
||||
var shot = _shootUIStack.Pop();
|
||||
shot.Switch();
|
||||
_toReloadStack.Push(shot);
|
||||
if (_previosReload != null)
|
||||
@ -92,15 +93,12 @@ public class UnitView : MonoBehaviour
|
||||
|
||||
private IEnumerator Reload()
|
||||
{
|
||||
if (_toReloadStack.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (_toReloadStack.Count == 0) yield break; //TODO При частой стрльбе перезарядка работает некорректно
|
||||
yield return new WaitForSeconds(_weapon.reloadTime);
|
||||
if (_toReloadStack.Count == 0) yield break;
|
||||
var shot = _toReloadStack.Pop();
|
||||
shot.Switch();
|
||||
_shotUIStack.Push(shot);
|
||||
_shootUIStack.Push(shot);
|
||||
StartCoroutine(Reload());
|
||||
}
|
||||
|
18
Assets/Scripts/Weapons/Weapon.cs
Normal file
18
Assets/Scripts/Weapons/Weapon.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Weapons
|
||||
{
|
||||
[Serializable]
|
||||
public struct Weapon
|
||||
{
|
||||
public GameObject objectToThrow;
|
||||
public GameObject VFXGameObject;
|
||||
public int manaCost;
|
||||
public int damage;
|
||||
public float speed;
|
||||
public int disnatce;
|
||||
public float reloadTime;
|
||||
public int shots;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Weapons/Weapon.cs.meta
Normal file
3
Assets/Scripts/Weapons/Weapon.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d750b480071a4f939fc2f27e2017c24c
|
||||
timeCreated: 1640398807
|
@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DefaultNamespace.Weapons;
|
||||
using UnityEngine;
|
||||
using Weapons;
|
||||
|
||||
public class WeaponView : MonoBehaviour
|
||||
{
|
Loading…
x
Reference in New Issue
Block a user