weapon fixes

This commit is contained in:
dddushesss 2022-01-05 21:33:46 +03:00
parent 6ccb4723cb
commit 95f941abb8
13 changed files with 92 additions and 103 deletions

View File

@ -1,6 +0,0 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}

View File

@ -95,19 +95,19 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 5db196e1099b97246bde07a348189567, type: 3}
m_Name:
m_EditorClassIdentifier:
_weapon:
weapon:
name: Tower
icon: {fileID: 4774919592469818776}
icon: {fileID: 0}
objectToThrow: {fileID: 4746165193704193263, guid: 4e7523811a052fd46acf941fc69c8c98,
type: 3}
VFXGameObject: {fileID: 2957420090356197408, guid: 5d1244f7b80cadd428a70173a01ce889,
type: 3}
manaCost: 0
damage: 10
modifiedDamage: 0
damage: 15
speed: 10
disnatce: 10
reloadTime: 3
shots: 3
disnatce: 6
reloadTime: 6
shots: 4
shotSound: {fileID: 8300000, guid: 9ea918c6c23577f4e885a8490d2f2046, type: 3}
hitSound: {fileID: 8300000, guid: 6c42231c18643dc4d9d8f8d15bc4735b, type: 3}
--- !u!136 &5879628246065515362

View File

@ -20,19 +20,22 @@ MonoBehaviour:
spawnablePrefab: {fileID: 4774919592469818776, guid: 0dbed8f974ba44a42af9d8fcae504ce0,
type: 3}
values:
spawnChance: 0.23
- prefab: {fileID: 3197816592181874056, guid: 2704c4f795b0d7748a3e3fa53be4d893,
type: 3}
isInstantUse: 1
type: AttackBonus
icon: {fileID: 21300000, guid: caf8bc0311dd2fc4ca1528a82a063754, type: 3}
spawnablePrefab: {fileID: 0}
values: 030000000f000000
values: 0500000064000000
spawnChance: 0.62
- prefab: {fileID: 8639522512577941448, guid: 7b6a7f64e52da514d88aa97ad8f863df,
type: 3}
isInstantUse: 1
type: DefenceBonus
icon: {fileID: 21300000, guid: 35be128594dcdce48b5d8e5317b38ed9, type: 3}
spawnablePrefab: {fileID: 0}
values: 0a0000001e000000
values: 1e0000001e000000
spawnChance: 0.77
fromTimeSpawn: 3
toTimeSpawn: 10

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Chars;
using GameUI;
using UnityEngine;
namespace Data

View File

@ -1,19 +1,20 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Items;
using UnityEngine;
using UnityEngine.UI;
public class PlayerInventoryView : MonoBehaviour
namespace GameUI
{
public class PlayerInventoryView : MonoBehaviour
{
[SerializeField] private GameObject item;
[SerializeField] private GameObject grid;
public Action<Item> OnItemInvoked;
private List<Button> _buttons;
private Queue<Button> _freeButtons;
private Button[] _freeButtons;
private Dictionary<Item, Button> _dictionary;
@ -21,7 +22,7 @@ public class PlayerInventoryView : MonoBehaviour
{
_buttons = new List<Button>();
_dictionary = new Dictionary<Item, Button>();
_freeButtons = new Queue<Button>();
_freeButtons = new Button[inventoryCapacity];
for (int i = 0; i < inventoryCapacity; i++)
{
var itemGo = Instantiate(item, grid.transform);
@ -30,7 +31,8 @@ public class PlayerInventoryView : MonoBehaviour
button.gameObject.SetActive(false);
}
_buttons.ForEach(button => _freeButtons.Enqueue(button));
var j = 0;
_buttons.ForEach(button => _freeButtons[j++] = button);
}
private void SwitchButton(Item item)
@ -38,12 +40,27 @@ public class PlayerInventoryView : MonoBehaviour
var button = _dictionary[item];
_dictionary.Remove(item);
button.gameObject.SetActive(false);
_freeButtons.Enqueue(button);
for (int i = 0; i < _freeButtons.Length; i++)
{
if (_freeButtons[i] != null) continue;
_freeButtons[i] = button;
break;
}
}
public void PickUpItem(Item item)
{
var button = _freeButtons.Dequeue();
Button button = null;
for (int i = 0; i < _freeButtons.Length; i++)
{
if (_freeButtons[i] == null) continue;
button = _freeButtons[i];
_freeButtons[i] = null;
break;
}
if (button == null)
return;
_dictionary.Add(item, button);
button.gameObject.SetActive(true);
button.image.sprite = item.Icon;
@ -51,8 +68,15 @@ public class PlayerInventoryView : MonoBehaviour
{
if (item.IsInstantUse)
{
button.onClick.RemoveAllListeners();
item.InstanceInvoke();
_freeButtons.Enqueue(button);
for (int i = 0; i < _freeButtons.Length; i++)
{
if (_freeButtons[i] != null) continue;
_freeButtons[i] = button;
break;
}
button.gameObject.SetActive(false);
}
else
@ -60,9 +84,7 @@ public class PlayerInventoryView : MonoBehaviour
item.Invoke(SwitchButton);
OnItemInvoked?.Invoke(item);
}
});
}
}
}

View File

@ -18,6 +18,7 @@ namespace Items
public override void InstanceInvoke()
{
Unit.SetAttackBonus(Data.Values[0], Data.Values[1]);
Unit.UseItem(this);
}
public override void PlaceItem(HexCell cell)

View File

@ -18,6 +18,7 @@ namespace Items
public override void InstanceInvoke()
{
Unit.SetDefenceBonus(Data.Values[0], Data.Values[1]);
Unit.UseItem(this);
}
public override void PlaceItem(HexCell cell)

View File

@ -3,6 +3,7 @@ using Controller;
using Data;
using DefaultNamespace;
using DG.Tweening;
using GameUI;
using HexFiled;
using Items;
using Runtime.Controller;

View File

@ -24,8 +24,9 @@ public class TowerView : MonoBehaviour
private void OnCollisionEnter(Collision collision)
{
var unit = collision.gameObject.GetComponent<UnitView>();
if (unit != null && unit.Color != _color)
if (unit != null && unit.Color != _color) //TODO какие-то проблемы с задием цвета
{
weapon.SetModifiedDamage(0);
_target = unit.gameObject;
StartCoroutine(Shot());
}
@ -48,7 +49,7 @@ public class TowerView : MonoBehaviour
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));
Quaternion.LookRotation(direction));
MusicController.Instance.AddAudioSource(ball);
MusicController.Instance.PlayAudioClip(weapon.shotSound, ball);

View File

@ -1 +0,0 @@
{"icon":{"instanceID":17620},"objectToThrow":{"instanceID":17622},"VFXGameObject":{"instanceID":17624},"manaCost":15,"damage":30,"speed":0.5,"disnatce":3,"reloadTime":3.0,"shots":5,"shotSound":{"instanceID":17616},"hitSound":{"instanceID":17618}}

View File

@ -1,12 +1,9 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.collab-proxy": "1.7.1",
"com.unity.ide.rider": "2.0.7",
"com.unity.ide.visualstudio": "2.0.11",
"com.unity.ide.vscode": "1.2.3",
"com.unity.postprocessing": "3.1.1",
"com.unity.recorder": "2.5.5",
"com.unity.test-framework": "1.1.27",
"com.unity.textmeshpro": "3.0.6",
"com.unity.timeline": "1.4.8",

View File

@ -1,11 +1,5 @@
{
"dependencies": {
"com.unity.2d.sprite": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.collab-proxy": {
"version": "1.7.1",
"depth": 0,
@ -54,24 +48,6 @@
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.postprocessing": {
"version": "3.1.1",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.physics": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.recorder": {
"version": "2.5.5",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.timeline": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.test-framework": {
"version": "1.1.27",
"depth": 0,

View File

@ -1,7 +0,0 @@
Точка входа — GameController.cs. Чтобы проект запустился надо создать на сцене пустой объект и добавить туда GameController, и указать ему путь до ScriptableObject Data (по умолчанию — Assets/Resources/Data)
В GameInit Инициализация основных классов и добавление контроллеров, которые выполняются в цикле в GameController
Информация для объектов берётся из ScriptableObject, названия к которым прописываются в ScriptableObject Data по пути Assets/Resources/Data.
Чтобы выполнить метод в Start, Update и тд надо реализовать соответствующий интерфейс (IInitialization, IExecute и тд)