items finished

This commit is contained in:
dddushesss 2022-01-05 15:43:08 +03:00
parent 7421638a8d
commit c87a906d97
31 changed files with 625 additions and 80 deletions

8
Assets/Prefab/Items.meta Normal file
View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 89412f229cb2738409fadd58645601f8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,126 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &4774919592469818776
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 5262522953580885794}
- component: {fileID: 9126517344989362311}
- component: {fileID: 6432002706622696525}
- component: {fileID: 8015579614070857994}
- component: {fileID: 5879628246065515362}
m_Layer: 0
m_Name: Tower
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &5262522953580885794
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4774919592469818776}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0, y: 0, z: 0}
m_LocalScale: {x: 0.3, y: 0.3, z: 0.3}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &9126517344989362311
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4774919592469818776}
m_Mesh: {fileID: 688505742851261164, guid: a6c1d0254e365a4489cf81b74d608b43, type: 3}
--- !u!23 &6432002706622696525
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4774919592469818776}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8720b7cac4364f14f961a3b6968c9beb, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &8015579614070857994
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4774919592469818776}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5db196e1099b97246bde07a348189567, type: 3}
m_Name:
m_EditorClassIdentifier:
_weapon:
name: Tower
icon: {fileID: 4774919592469818776}
objectToThrow: {fileID: 4746165193704193263, guid: 4e7523811a052fd46acf941fc69c8c98,
type: 3}
VFXGameObject: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889,
type: 3}
manaCost: 0
damage: 10
speed: 10
disnatce: 10
reloadTime: 3
shots: 3
shotSound: {fileID: 8300000, guid: 9ea918c6c23577f4e885a8490d2f2046, type: 3}
hitSound: {fileID: 8300000, guid: 6c42231c18643dc4d9d8f8d15bc4735b, type: 3}
--- !u!136 &5879628246065515362
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4774919592469818776}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 31.906784
m_Height: 63.813572
m_Direction: 1
m_Center: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0dbed8f974ba44a42af9d8fcae504ce0
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:37ff580b2ac54350270f8fdd11d105d68b35b02b990899ad64863f566bed2e4d
size 182837

View File

@ -0,0 +1,102 @@
fileFormatVersion: 2
guid: a6c1d0254e365a4489cf81b74d608b43
ModelImporter:
serializedVersion: 20200
internalIDToNameTable: []
externalObjects: {}
materials:
materialImportMode: 2
materialName: 0
materialSearch: 1
materialLocation: 1
animations:
legacyGenerateAnimations: 4
bakeSimulation: 0
resampleCurves: 1
optimizeGameObjects: 0
motionNodeName:
rigImportErrors:
rigImportWarnings:
animationImportErrors:
animationImportWarnings:
animationRetargetingWarnings:
animationDoRetargetingWarnings: 0
importAnimatedCustomProperties: 0
importConstraints: 0
animationCompression: 1
animationRotationError: 0.5
animationPositionError: 0.5
animationScaleError: 0.5
animationWrapMode: 0
extraExposedTransformPaths: []
extraUserProperties: []
clipAnimations: []
isReadable: 0
meshes:
lODScreenPercentages: []
globalScale: 1
meshCompression: 0
addColliders: 0
useSRGBMaterialColor: 1
sortHierarchyByName: 1
importVisibility: 1
importBlendShapes: 1
importCameras: 1
importLights: 1
fileIdsGeneration: 2
swapUVChannels: 0
generateSecondaryUV: 0
useFileUnits: 1
keepQuads: 0
weldVertices: 1
bakeAxisConversion: 0
preserveHierarchy: 0
skinWeightsMode: 0
maxBonesPerVertex: 4
minBoneWeight: 0.001
meshOptimizationFlags: -1
indexFormat: 0
secondaryUVAngleDistortion: 8
secondaryUVAreaDistortion: 15.000001
secondaryUVHardAngle: 88
secondaryUVMarginMethod: 1
secondaryUVMinLightmapResolution: 40
secondaryUVMinObjectScale: 1
secondaryUVPackMargin: 4
useFileScale: 1
tangentSpace:
normalSmoothAngle: 60
normalImportMode: 0
tangentImportMode: 3
normalCalculationMode: 4
legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0
blendShapeNormalImportMode: 1
normalSmoothingSource: 0
referencedClips: []
importAnimation: 1
humanDescription:
serializedVersion: 3
human: []
skeleton: []
armTwist: 0.5
foreArmTwist: 0.5
upperLegTwist: 0.5
legTwist: 0.5
armStretch: 0.05
legStretch: 0.05
feetSpacing: 0
globalScale: 1
rootMotionBoneName:
hasTranslationDoF: 0
hasExtraRoot: 0
skeletonHasParents: 1
lastHumanDescriptionAvatarSource: {instanceID: 0}
autoGenerateAvatarMappingIfUnspecified: 1
animationType: 2
humanoidOversampling: 1
avatarSetup: 0
addHumanoidExtraRootOnlyWhenUsingAvatar: 1
additionalBone: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -14,8 +14,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
width: 25
height: 50
defaultColor: {r: 1, g: 1, b: 1, a: 1}
touchedColor: {r: 1, g: 0, b: 1, a: 1}
hexCaptureManaCost: 10
cellPrefab: {fileID: 1661242500252451528, guid: bcea5b4a96735bd4b936f8f3fefcc688,
type: 3}
@ -23,24 +21,28 @@ MonoBehaviour:
type: 3}
CoordinatesCanvas: {fileID: 4726489279989878083, guid: f31e0880dd078104bb31dc0fd7ef9f19,
type: 3}
DefaultTexture: {fileID: 2800000, guid: 983242f4b4db7a841af48234cf0021b8, type: 3}
colors:
- _unitColor: 2
_texture: {fileID: 2800000, guid: 983242f4b4db7a841af48234cf0021b8, type: 3}
_vfxPrefab: {fileID: 0}
_buildinTexture: {fileID: 0}
- _unitColor: 0
_texture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3}
_vfxPrefab: {fileID: 8021195855904498788, guid: 2f6d0540c8fd7bb46b356ff86962379c,
type: 3}
_buildinTexture: {fileID: 2800000, guid: 0298dfcb0756f534a9a125d510461c7a, type: 3}
- _unitColor: 1
_texture: {fileID: 2800000, guid: 3b75368df991b164583e8cede390e24e, type: 3}
_vfxPrefab: {fileID: 442387583353148024, guid: 53959bc898e9a644daad0282881d596a,
type: 3}
_buildinTexture: {fileID: 2800000, guid: 3b75368df991b164583e8cede390e24e, type: 3}
- _unitColor: 3
_texture: {fileID: 2800000, guid: 1a76a79d5a83143479c76f4f37c4b896, type: 3}
_vfxPrefab: {fileID: 5732852186060375560, guid: 54d847a18c62f57479c53469d4398ceb,
type: 3}
_buildinTexture: {fileID: 2800000, guid: 1a76a79d5a83143479c76f4f37c4b896, type: 3}
- _unitColor: 4
_texture: {fileID: 2800000, guid: 779719648deedb4478ddebb3b81751ef, type: 3}
_vfxPrefab: {fileID: 1651852338557341938, guid: fa6c1fc3da7c8d24c85a88b00cf598d4,
type: 3}
_buildinTexture: {fileID: 2800000, guid: 779719648deedb4478ddebb3b81751ef, type: 3}

View File

@ -13,12 +13,26 @@ MonoBehaviour:
m_Name: ItemData
m_EditorClassIdentifier:
itemInfos:
- prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
type: 3}
- prefab: {fileID: 919132149155446097, guid: 4166c606d638610418dc9ead794d697b, type: 3}
isInstantUse: 0
type: Tower
icon: {fileID: 21300000, guid: 543c4732bd2d47a41bdbbf2156eb358c, type: 3}
spawnablePrefab: {fileID: 1175122412763585952, guid: ca39954219550f949aeeecf95f25f3d1,
spawnablePrefab: {fileID: 4774919592469818776, guid: 0dbed8f974ba44a42af9d8fcae504ce0,
type: 3}
values:
- prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
type: 3}
isInstantUse: 1
type: AttackBonus
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
spawnablePrefab: {fileID: 0}
values: 030000000f000000
- prefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
type: 3}
isInstantUse: 1
type: DefenceBonus
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
spawnablePrefab: {fileID: 0}
values: 0a0000001e000000
fromTimeSpawn: 3
toTimeSpawn: 10

View File

@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
using System.Timers;
using CamControl;
using Chars;
using DefaultNamespace;
using GameUI;
using HexFiled;
using Items;
using Units;
using UnityEngine;
using Weapons;
using Object = UnityEngine.Object;
using Random = UnityEngine.Random;
namespace Controller
@ -16,16 +19,18 @@ namespace Controller
{
public GameInit(Controllers controllers, Data.Data data)
{
new GameObject("Timer").AddComponent<TimerHelper>();
var hexGrid = new HexGrid(data.FieldData);
new MusicController();
MusicController.Instance.SetMusicData(data.MusicData);
controllers.Add(hexGrid);
List<Type> types =
new List<Type>() { typeof(Tower) };
ItemFabric itemFabric = new ItemFabric(data.ItemsData, types);
ItemFabric itemFabric = new ItemFabric(data.ItemsData, SetUpItems());
controllers.Add(itemFabric);
UIController uiController = new UIController(data.UIData);
uiController.Spawn(); //TODO при паузе Dotween ругается
Unit player;
@ -35,7 +40,8 @@ namespace Controller
if (unit.isPlayer)
{
player = new Unit(unit, JsonUtility.FromJson<Weapon>(data.ChosenWeapon), hexGrid);
PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView, uiController.PlayerInventoryView);
PlayerControl playerControl = new PlayerControl(player, uiController.PlayerControlView,
uiController.PlayerInventoryView);
controllers.Add(playerControl);
CameraControl cameraControl =
new CameraControl(Camera.main, data.CameraData);
@ -46,7 +52,8 @@ namespace Controller
}
else
{
var enemy = new Unit(unit, data.WeaponsData.WeaponsList[Random.Range(0,data.WeaponsData.WeaponsList.Count - 1)], hexGrid);
var enemy = new Unit(unit,
data.WeaponsData.WeaponsList[Random.Range(0, data.WeaponsData.WeaponsList.Count - 1)], hexGrid);
var enemyController = new EnemyController(unit, enemy);
controllers.Add(enemyController);
units.Add(enemy);
@ -62,9 +69,11 @@ namespace Controller
hexGrid.OnHexPainted += paintedController.SetHexColors;
hexGrid.OnHexPainted += itemFabric.UpdateCellToOpenList;
}
private List<Type> SetUpItems()
{
return new List<Type>() { typeof(Tower), typeof(AttackBonus), typeof(DefenceBonus) };
}
}
}

View File

@ -27,6 +27,8 @@ namespace Data
[SerializeField] private string type;
[SerializeField] private Sprite icon;
[SerializeField] private GameObject spawnablePrefab;
[SerializeField] private int[] values;
[SerializeField][Range(0,1)] private float spawnChance;
public GameObject Prefab => prefab;
public string Type => type;
@ -35,5 +37,7 @@ namespace Data
public GameObject SpawnablePrefab => spawnablePrefab;
public bool IsInstanceUse => isInstantUse;
public int[] Values => values;
public float SpawnChance => spawnChance;
}
}

View File

@ -0,0 +1,50 @@
using System;
using HexFiled;
using UnityEngine;
namespace DefaultNamespace
{
public static class DirectionHelper
{
public static Vector3 DirectionTo(Vector3 a, Vector3 b)
{
return (b - a).normalized;
}
public static HexDirection VectorToDirection(Vector2 dir)
{
if (dir.x >= 0 && dir.y <= 1 && dir.x <= 1 && dir.y >= 0.5)
{
return HexDirection.NE;
}
if (Math.Abs(dir.x - 1f) < 0.2 && dir.y <= 0.5 && dir.y >= -0.5)
{
return HexDirection.E;
}
if (dir.x <= 1 && dir.y <= -0.5 && dir.x >= 0 && dir.y >= -1)
{
return HexDirection.SE;
}
if (dir.x <= 0 && dir.y >= -1 && dir.x >= -1 && dir.y <= -0.5)
{
return HexDirection.SW;
}
if (Math.Abs(dir.x - (-1f)) < 0.2 && dir.y >= -0.5 && dir.y <= 0.5)
{
return HexDirection.W;
}
if (dir.x >= -1 && dir.y >= 0.5 && dir.x <= 0 && dir.y <= 1)
{
return HexDirection.NW;
}
return HexDirection.W;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fc19bb5576de42c89aa7aae62e2c3552
timeCreated: 1641323470

View File

@ -32,12 +32,14 @@ public class GameMenuView : MonoBehaviour
private void ShowMenu()
{
DOTween.PauseAll();
menu.SetActive(true);
Time.timeScale = 0f;
}
private void HideMenu()
{
DOTween.PlayAll();
Time.timeScale = 1f;
menu.SetActive(false);
}

View File

@ -46,6 +46,7 @@ public class PlayerInventoryView : MonoBehaviour
var button = _freeButtons.Dequeue();
_dictionary.Add(item, button);
button.gameObject.SetActive(true);
button.image.sprite = item.Icon;
button.onClick.AddListener(() =>
{
if (item.IsInstantUse)
@ -59,6 +60,7 @@ public class PlayerInventoryView : MonoBehaviour
item.Invoke(SwitchButton);
OnItemInvoked?.Invoke(item);
}
});

View File

@ -9,10 +9,14 @@ namespace HexFiled
[SerializeField] private UnitColor _unitColor;
[SerializeField] private Texture _texture;
[SerializeField] private GameObject _vfxPrefab;
[SerializeField] private Texture _buildinTexture;
public UnitColor UnitColor => _unitColor;
public Texture Texture => _texture;
public Texture BuildingTexture => _buildinTexture;
public GameObject VFXPrefab => _vfxPrefab;
public bool Equals(CellColor obj)
{

View File

@ -16,7 +16,6 @@ namespace HexFiled
private Item _item;
private UnitColor _color;
private MeshRenderer _renderer;
private Dictionary<UnitColor, CellColor> _cellColor;
public UnitColor Color => _color;
@ -39,11 +38,7 @@ namespace HexFiled
{
return neighbors.ToList();
}
public void SetDictionary(Dictionary<UnitColor, CellColor> colors)
{
_cellColor = colors;
}
public HexCell GetNeighbor(HexDirection direction)
{
@ -61,15 +56,15 @@ namespace HexFiled
if (color == _color) return;
if (color == UnitColor.GREY)
{
_renderer.material.mainTexture = _cellColor[color].Texture;
_renderer.material.mainTexture = HexGrid.Colors[color].Texture;
_color = color;
return;
}
_renderer.material.mainTexture = _cellColor[color].Texture;
_renderer.material.mainTexture = HexGrid.Colors[color].Texture;
_color = color;
Instantiate(_cellColor[color].VFXPrefab, transform);
Instantiate(HexGrid.Colors[color].VFXPrefab, transform);
onHexPainted?.Invoke(this);
}
}

View File

@ -17,15 +17,17 @@ namespace HexFiled
private HexCell[] _cells;
private Canvas _gridCanvas;
private GameObject _baseGameObject;
private Dictionary<UnitColor, CellColor> _colors;
private float _hexDistance;
private static Dictionary<UnitColor, CellColor> _colors;
private static float _hexDistance;
private int _hexCaptureCost;
public float HexDistance => _hexDistance;
public static float HexDistance => _hexDistance;
public Action<HexCell> OnHexPainted;
public Action OnGridLoaded;
public int HexCaptureCost => _hexCaptureCost;
public static Dictionary<UnitColor, CellColor> Colors => _colors;
public HexGrid(FieldData fieldData)
{
_hexCaptureCost = fieldData.hexCaptureManaCost;
@ -63,7 +65,6 @@ namespace HexFiled
position.z = z * (HexMetrics.outerRadius * 1.5f);
var cellGO = Object.Instantiate(_cellPrefab);
HexCell cell = _cells[i] = cellGO.GetComponent<HexCell>();
cell.SetDictionary(_colors);
cell.PaintHex(UnitColor.GREY);
cell.transform.SetParent(_baseGameObject.transform, false);
cell.transform.localPosition = position;

View File

@ -0,0 +1,28 @@
using System;
using Data;
using HexFiled;
namespace Items
{
public class AttackBonus : Item
{
public AttackBonus(ItemInfo data) : base(data)
{
}
public override void Invoke(Action<Item> item)
{
throw new NotImplementedException();
}
public override void InstanceInvoke()
{
Unit.SetAttackBonus(Data.Values[0], Data.Values[1]);
}
public override void PlaceItem(HexCell cell)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2b016eba27de41629261b965b3e2be0c
timeCreated: 1641382290

View File

@ -0,0 +1,28 @@
using System;
using Data;
using HexFiled;
namespace Items
{
public class DefenceBonus : Item
{
public DefenceBonus(ItemInfo data) : base(data)
{
}
public override void Invoke(Action<Item> item)
{
throw new NotImplementedException();
}
public override void InstanceInvoke()
{
Unit.SetDefenceBonus(Data.Values[0], Data.Values[1]);
}
public override void PlaceItem(HexCell cell)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c518da097b3645c491c6a4cc61b3d493
timeCreated: 1641382317

View File

@ -15,6 +15,7 @@ namespace Items
protected Action<Item> OnItemUsed;
public bool IsInstantUse => Data.IsInstanceUse;
public Sprite Icon => Data.Icon;
protected Item(ItemInfo data)
{
Data = data;

View File

@ -49,13 +49,17 @@ namespace Items
.ToList();
time = Time.time;
var cell = _openList[Random.Range(0, _openList.Count - 1)];
while (closedList.Contains(cell) || cell.Item != null)
{
cell = _openList[Random.Range(0, _openList.Count - 1)];
}
var type = _itemTypes[Random.Range(0, _itemTypes.Count - 1)];
var type = GetWeightedType();
while (type == null)
{
type = GetWeightedType();
}
var info = _itemInfos[type.ToString().Replace("Items.", "")];
var obj = (Item)Activator.CreateInstance(type, info);
@ -67,5 +71,20 @@ namespace Items
_spawnTime = Random.Range(_data.SpawnTime.from, _data.SpawnTime.to);
}
}
private Type GetWeightedType()
{
float randomNum = Random.Range(1, 101)/100f;
List<Type> possibleTypes = new List<Type>();
_itemTypes.ForEach(type =>
{
if (_itemInfos[type.ToString().Replace("Items.", "")].SpawnChance >= randomNum)
{
possibleTypes.Add(type);
}
});
return possibleTypes.Count > 0 ? possibleTypes[Random.Range(0, possibleTypes.Count - 1)] : null;
}
}
}

View File

@ -22,12 +22,14 @@ namespace Items
public override void InstanceInvoke()
{
throw new System.NotImplementedException();
Unit.UseItem(this);
}
public override void PlaceItem(HexCell cell)
{
Object.Instantiate(Data.SpawnablePrefab, cell.transform.position, Quaternion.identity);
Unit.UseItem(this);
var obj = Object.Instantiate(Data.SpawnablePrefab, cell.transform.position, Quaternion.identity);
obj.AddComponent<TowerView>().SetUp(Unit.Color);
OnItemUsed?.Invoke(this);
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections;
using UnityEngine;
namespace DefaultNamespace
{
public class TimerHelper : MonoBehaviour
{
private static TimerHelper _instance;
public static TimerHelper Instance => _instance;
private void Start()
{
if (_instance == null)
_instance = this;
else
{
Destroy(this);
}
}
public void StartTimer(Action action, int time)
{
StartCoroutine(Timer(action, time));
}
IEnumerator Timer(Action action, int time)
{
yield return new WaitForSeconds(time);
action.Invoke();
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 031d061e6f684c0d992624e679d1a311
timeCreated: 1641383305

View File

@ -1,6 +1,7 @@
using System;
using Controller;
using Data;
using DefaultNamespace;
using DG.Tweening;
using HexFiled;
using Items;
@ -85,8 +86,8 @@ namespace Chars
if (!_unit.IsBusy && _moveJoystick.Direction != Vector2.zero)
{
_unit.Move(VectorToDirection(_moveJoystick.Direction.normalized));
_placeJoystick.gameObject.SetActive(false);
_unit.Move(DirectionHelper.VectorToDirection(_moveJoystick.Direction.normalized));
}
if (!_unit.IsBusy && _attackJoystick.isPressed)
@ -97,46 +98,12 @@ namespace Chars
if (!_unit.IsBusy && _placeJoystick.isPressed)
{
_placeDirection = VectorToDirection(_placeJoystick.Direction.normalized);
_placeDirection = DirectionHelper.VectorToDirection(_placeJoystick.Direction.normalized);
_cellToPlace = _unit.PlaceItemAim(_placeDirection);
}
}
private static HexDirection VectorToDirection(Vector2 dir)
{
if (dir.x >= 0 && dir.y <= 1 && dir.x <= 1 && dir.y >= 0.5)
{
return HexDirection.NE;
}
if (Math.Abs(dir.x - 1f) < 0.2 && dir.y <= 0.5 && dir.y >= -0.5)
{
return HexDirection.E;
}
if (dir.x <= 1 && dir.y <= -0.5 && dir.x >= 0 && dir.y >= -1)
{
return HexDirection.SE;
}
if (dir.x <= 0 && dir.y >= -1 && dir.x >= -1 && dir.y <= -0.5)
{
return HexDirection.SW;
}
if (Math.Abs(dir.x - (-1f)) < 0.2 && dir.y >= -0.5 && dir.y <= 0.5)
{
return HexDirection.W;
}
if (dir.x >= -1 && dir.y >= 0.5 && dir.x <= 0 && dir.y <= 1)
{
return HexDirection.NW;
}
return HexDirection.W;
}
public void Execute()
{

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using Chars;
using Data;
using DefaultNamespace;
using DG.Tweening;
using HexFiled;
using Items;
@ -33,12 +34,14 @@ namespace Units
private BarCanvas _barCanvas;
private bool _isHardToCapture;
private bool _isCapturing;
private int _attackBonus;
private int _defenceBonus;
public bool IsBusy => _isBusy;
public GameObject PlayerInstance => _instance;
public UnitView UnitView => _unitView;
public bool IsAlive => _isAlive;
public UnitColor Color => _data.color;
public int InventoryCapacity => _data.inventoryCapacity;
public Action<Item> OnItemPickUp;
@ -53,6 +56,28 @@ namespace Units
_isCapturing = false;
}
public void SetAttackBonus(int duration, int value)
{
TimerHelper.Instance.StartTimer(StopAttackBonus, duration);
_weapon.SetModifiedDamage(value);
}
private void StopAttackBonus()
{
_weapon.SetModifiedDamage(0);
}
public void SetDefenceBonus(int duration, int value)
{
TimerHelper.Instance.StartTimer(StopDefenceBonus, duration);
_defenceBonus = value;
}
private void StopDefenceBonus()
{
_defenceBonus = 0;
}
public void Move(HexDirection direction)
{
if (!_cell.GetNeighbor(direction) || _isBusy) return;
@ -159,13 +184,22 @@ namespace Units
UpdateBarCanvas();
}
public void PickUpItem(Item item)
public bool PickUpItem(ItemView itemView)
{
if (_inventory.Count < _data.inventoryCapacity)
{
var item = itemView.PickUp(this);
_inventory.Add(item);
OnItemPickUp.Invoke(item);
return true;
}
return false;
}
public void UseItem(Item item)
{
_inventory.Remove(item);
}
private void MoveEnd()
{
@ -213,7 +247,7 @@ namespace Units
ball.AddComponent<WeaponView>().SetWeapon(_weapon);
ball.transform.DOMove(
new Vector3(_direction.normalized.x,
0, _direction.normalized.y) * _weapon.disnatce * _hexGrid.HexDistance +
0, _direction.normalized.y) * _weapon.disnatce * HexGrid.HexDistance +
_instance.transform.position + new Vector3(0, 2, 0),
_weapon.speed)
.SetEase(Ease.Linear)
@ -290,12 +324,21 @@ namespace Units
private void Damage(int dmg)
{
if (_hp - dmg <= 0f)
if (_defenceBonus == 0 && _hp - dmg <= 0f)
{
Death();
}
_hp -= dmg;
if (_defenceBonus > 0)
{
_defenceBonus -= dmg;
}
else
{
_hp -= dmg;
}
UpdateBarCanvas();
}
}

View File

@ -39,6 +39,7 @@ public class UnitView : MonoBehaviour
public GameObject BarCanvas => barCanvas;
public GameObject AimCanvas => aimCanvas;
public UnitColor Color => _unit.Color;
public void SetUp(Stack<ShotUIView> shots, Weapon weapon, Action regenMana, int manaRegen, Action captureHex,
Unit unit)
@ -126,16 +127,15 @@ public class UnitView : MonoBehaviour
WeaponView weaponView = other.GetComponent<WeaponView>();
if (weaponView != null)
{
OnHit?.Invoke(weaponView.Weapon.damage);
OnHit?.Invoke(weaponView.Weapon.modifiedDamage);
other.transform.DOKill();
Destroy(other.gameObject);
}
ItemView itemView = other.GetComponent<ItemView>();
if (itemView != null)
if (itemView != null && _unit.PickUpItem(itemView))
{
_unit.PickUpItem(itemView.PickUp(_unit));
Destroy(itemView.gameObject);
}
}

View File

@ -10,7 +10,7 @@ namespace Weapons
public GameObject icon;
public GameObject objectToThrow;
public GameObject VFXGameObject;
public int manaCost;
public int modifiedDamage;
public int damage;
public float speed;
public int disnatce;
@ -18,5 +18,10 @@ namespace Weapons
public int shots;
public AudioClip shotSound;
public AudioClip hitSound;
public void SetModifiedDamage(int bonus)
{
modifiedDamage = damage + bonus;
}
}
}

66
Assets/TowerView.cs Normal file
View File

@ -0,0 +1,66 @@
using System;
using System.Collections;
using System.Collections.Generic;
using DefaultNamespace;
using DG.Tweening;
using HexFiled;
using Units;
using UnityEngine;
using Weapons;
public class TowerView : MonoBehaviour
{
private UnitColor _color;
private GameObject _target;
[SerializeField] private Weapon weapon;
public void SetUp(UnitColor unitColor)
{
_color = unitColor;
GetComponent<MeshRenderer>().material.mainTexture = HexGrid.Colors[unitColor].BuildingTexture;
}
private void OnCollisionEnter(Collision collision)
{
var unit = collision.gameObject.GetComponent<UnitView>();
if (unit != null && unit.Color != _color)
{
_target = unit.gameObject;
StartCoroutine(Shot());
}
}
private void OnCollisionExit(Collision other)
{
if (_target == other.gameObject)
{
_target = null;
}
}
private IEnumerator Shot()
{
while (_target != null)
{
yield return new WaitForSecondsRealtime(weapon.reloadTime);
var direction = DirectionHelper.DirectionTo(transform.position, _target.transform.position);
var ball = Instantiate(weapon.objectToThrow,
transform.forward + transform.position + new Vector3(0, 2),
Quaternion.FromToRotation(transform.position, _target.transform.position));
MusicController.Instance.AddAudioSource(ball);
MusicController.Instance.PlayAudioClip(weapon.shotSound, ball);
ball.AddComponent<WeaponView>().SetWeapon(weapon);
ball.transform.DOMove(
new Vector3(direction.x,
0, direction.z) * weapon.disnatce * HexGrid.HexDistance +
transform.position + new Vector3(0, 2, 0),
weapon.speed)
.SetEase(Ease.Linear)
.OnComplete(() => Destroy(ball));
}
}
}

11
Assets/TowerView.cs.meta Normal file
View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5db196e1099b97246bde07a348189567
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: