added item editor in item settings

This commit is contained in:
dddushesss 2022-02-12 23:44:05 +03:00
parent 919d7c8726
commit eb2fd931ff
25 changed files with 100 additions and 410 deletions

View File

@ -1,62 +0,0 @@
%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: 09939b8f9dce4b858d34f89d66c453e6, type: 3}
m_Name: Defaults
m_EditorClassIdentifier:
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects:
- {fileID: 1175122412763585952, guid: ca39954219550f949aeeecf95f25f3d1, type: 3}
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: buildings
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[Data.BuildingKeys, Assembly-CSharp],[UnityEngine.GameObject,
UnityEngine.CoreModule]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.EnumEqualityComparer`1[[Data.BuildingKeys,
Assembly-CSharp]], mscorlib
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 3
Data: 2
- Name: $v
Entry: 10
Data: 0
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: dd5ca1c9dc36b944a96cd347a3fe6b0d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -19,7 +19,7 @@ MonoBehaviour:
icon: {fileID: 0}
objectToThrow: {fileID: 662838864788327244, guid: 4ae54c1263fd76148b1888c9e05f1d48, type: 3}
VFXGameObject: {fileID: 8032726150168125150, guid: 65c8920b6d1553a4d885992e8f7dff6a, type: 3}
modifiedDamage: 0
modifiedDamage: 100
damage: 100
speed: 1
disnatce: 10
@ -28,3 +28,4 @@ MonoBehaviour:
shotSound: {fileID: 0}
hitSound: {fileID: 0}
_aimGameObject: {fileID: 2273039178377770117, guid: 09a0317cbdff9fa479a18c9e20743a8e, type: 3}
lifeTime: 3

View File

@ -25,7 +25,7 @@ MonoBehaviour:
maxHP: 100
inventoryCapacity: 4
- isPlayer: 0
isAI: 1
isAI: 0
spawnPos:
x: 3
z: 4
@ -36,7 +36,7 @@ MonoBehaviour:
maxHP: 100
inventoryCapacity: 4
- isPlayer: 0
isAI: 1
isAI: 0
spawnPos:
x: -1
z: 42
@ -47,7 +47,7 @@ MonoBehaviour:
maxHP: 100
inventoryCapacity: 4
- isPlayer: 0
isAI: 1
isAI: 0
spawnPos:
x: -17
z: 40

View File

@ -64,7 +64,7 @@ public class AdsMob : MonoBehaviour
var randomCell = Random.Range(0, cells.Count);
Vector3 respawnPosition = cells[randomCell].transform.position;
player = FindObjectOfType<ExtraLife>().gameObject;
player.transform.position = respawnPosition;
if (player.transform.position == respawnPosition)

View File

@ -1,22 +0,0 @@
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
namespace Data
{
[CreateAssetMenu(fileName = "Defaults", menuName = "Data/Defaults", order = 0)]
public class DefaultLists : SerializedScriptableObject
{
[OdinSerialize] private Dictionary<BuildingKeys, GameObject> buildings;
public Dictionary<BuildingKeys, GameObject> Buildings => buildings;
}
public enum BuildingKeys
{
None,
Tree,
Bomb
}
}

View File

@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 09939b8f9dce4b858d34f89d66c453e6
timeCreated: 1644417891

View File

@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Data;
using Items;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Sirenix.Serialization;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using UnityEditor;
@ -61,9 +65,11 @@ namespace Editor
protected override OdinMenuTree BuildMenuTree()
{
_createNewLevel = new CreateNewLevel();
var tree = new OdinMenuTree();
tree.Add("New Level", _createNewLevel);
tree.Add("Default Lists",new Defaults());
var tree = new OdinMenuTree
{
{ "New Level", _createNewLevel },
{ "Items", new ItemList() }
};
var pathes = Resources.LoadAll<Data.Data>("Data/");
pathes.ForEach(x =>
{
@ -74,39 +80,74 @@ namespace Editor
return tree;
}
private class Defaults
private class ItemList
{
public Defaults()
public ItemList()
{
def = Resources.Load<DefaultLists>("Data/Defaults");
if (def == null)
{
def = CreateInstance<DefaultLists>();
AssetDatabase.CreateAsset(def, "Assets/Resources/Data/Defaults.asset");
AssetDatabase.SaveAssets();
}
items = Resources.LoadAll<Item>("Data/Items").ToList();
}
[OdinSerialize] public NewItem Type;
[InlineEditor(Expanded = true), ListDrawerSettings(HideAddButton = true, CustomRemoveElementFunction = "RemoveItem")] public List<Item> items;
private void RemoveItem(Item item)
{
var path = AssetDatabase.GetAssetPath(item);
var metaPath = path.Replace(".asset", ".asset.meta");
File.Delete(path);
File.Delete(metaPath);
AssetDatabase.Refresh();
}
[InlineEditor(ObjectFieldMode = InlineEditorObjectFieldModes.Boxed, Expanded = true, DrawHeader = false)]
public DefaultLists def;
internal enum ItemType
{
Bonus,
Building,
CaptureAbility,
SpecialWeapon
}
[Serializable]
internal class NewItem
{
public ItemType Type;
public string ItemName;
[Button("Add Item")]
private void AddItem()
{
Item item = Type switch
{
ItemType.Bonus => CreateInstance<Bonus>(),
ItemType.Building => CreateInstance<Building>(),
ItemType.CaptureAbility => CreateInstance<CaptureAbility>(),
ItemType.SpecialWeapon => CreateInstance<SpecialWeapon>(),
_ => throw new ArgumentOutOfRangeException(nameof(Type), Type, null)
};
AssetDatabase.CreateAsset(item,$"Assets/Resources/Data/Items/{ItemName}.asset");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
}
}
private class CreateNewLevel
{
public CreateNewLevel()
{
data = ScriptableObject.CreateInstance<Data.Data>();
datas = new List<ScriptableObject>();
datas.Add(ScriptableObject.CreateInstance<AIData>());
datas.Add(ScriptableObject.CreateInstance<CameraData>());
datas.Add(ScriptableObject.CreateInstance<FieldData>());
datas.Add(ScriptableObject.CreateInstance<ItemsData>());
datas.Add(ScriptableObject.CreateInstance<MusicData>());
datas.Add(ScriptableObject.CreateInstance<UIData>());
datas.Add(ScriptableObject.CreateInstance<UnitData>());
datas.Add(ScriptableObject.CreateInstance<WeaponsData>());
datas = new List<ScriptableObject>
{
ScriptableObject.CreateInstance<AIData>(),
ScriptableObject.CreateInstance<CameraData>(),
ScriptableObject.CreateInstance<FieldData>(),
ScriptableObject.CreateInstance<ItemsData>(),
ScriptableObject.CreateInstance<MusicData>(),
ScriptableObject.CreateInstance<UIData>(),
ScriptableObject.CreateInstance<UnitData>(),
ScriptableObject.CreateInstance<WeaponsData>()
};
}

View File

@ -23,8 +23,6 @@ namespace HexFiled
[SerializeField, AssetsOnly] public GameObject Building;
private Dictionary<BuildingKeys, GameObject> buildings =>
Resources.Load<DefaultLists>(Path.ChangeExtension("Data/Defaults.asset", null)).Buildings;
private UnitColor _color;
private MeshRenderer _renderer;
@ -51,7 +49,7 @@ namespace HexFiled
{
if (BuildingInstance != null)
{
DestroyImmediate(Building);
DestroyImmediate(BuildingInstance);
}
if (Building != null)
@ -61,6 +59,7 @@ namespace HexFiled
}
private void Awake()
{
_renderer = GetComponent<MeshRenderer>();

View File

@ -31,7 +31,9 @@ namespace HexFiled
foreach (var neighbour in neighbours)
{
if (hexByColorDict.TryGetValue(neighbour.Color, out var value) &&
value.Count >= 2 && value.Count < 6)
hexByColorDict.TryGetValue(cell.Color, out var hexCells) &&
hexCells.Count >= 2 &&
value.Count < 6)
{
foreach (var hex in value)
{
@ -48,7 +50,7 @@ namespace HexFiled
if (neighbour.Color != UnitColor.Grey
&& HexManager.UnitCurrentCell.TryGetValue(neighbour.Color, out var unit)
&& hexByColorDict.TryGetValue(neighbour.Color, out var cells)
&& cells.Count >= 2 && cells.Count < 5)
&& cells.Count >= 2 && cells.Count < 6)
{
var path = await HasPath(neighbour, unit.cell);
if (!path.hasPath)
@ -128,7 +130,7 @@ namespace HexFiled
private async Task<(bool hasPath, List<HexCell> field)> HasPath(HexCell start, HexCell end)
{
if (start.Color == _cell.Color || end.Color == _cell.Color)
if (start.Color == _cell.Color)
{
await Task.CompletedTask;
return (true, null);

View File

@ -26,7 +26,8 @@ namespace Items
cell.transform.position + buildingPrefab.transform.position, Quaternion.identity);
obj.GetComponent<ISetUp>().SetUp(Unit);
cell.Building = obj;
cell.Building = buildingPrefab;
cell.BuildingInstance = obj;
OnItemUsed.Invoke();
OnItemUsed = _action;
}

View File

@ -42,6 +42,8 @@ namespace Items
public void Fire()
{
OnItemUsed?.Invoke();
Unit.UseItem(this);
var cell = HexManager.UnitCurrentCell[Unit.Color].cell.GetNeighbor(_direction);
Unit.RotateUnit(new Vector2((cell.transform.position - Unit.Instance.transform.position).normalized.x,
(cell.transform.position - Unit.Instance.transform.position).normalized.z));
@ -54,7 +56,7 @@ namespace Items
{
_weapon.DestroyBall();
}, lifeTime);
OnItemUsed?.Invoke();
}
}
}

View File

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

View File

@ -1,72 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HexFiled;
public class ExtraLife : MonoBehaviour
{
[SerializeField] private GameObject canvasgroupe;
[SerializeField] private AdsMob canvasPref;
public static int lifeCount = 1;
public int health = 1;
private void Start() {
canvasPref = FindObjectOfType<AdsMob>();
canvasPref.gameObject.SetActive(false);
}
private void Update() {
if(health <= 0)
{
lifeCount -= 1;
canvasPref.gameObject.SetActive(true);
Time.timeScale = 0f;
//canvasPref.ShowAd();
//Instantiate(canvasPref);//.GetComponent<add>().ShowAd();
if(lifeCount < 0)
{
lifeCount = 0;
}
}
if(lifeCount > 0)
{
canvasPref.gameObject.SetActive(false);
//Respawn();
Time.timeScale = 1f;
}
}
// public void Respawn()
// {
// List<HexCell> cells = new List<HexCell>(FindObjectsOfType<HexCell>());
// // for (int i = 0; i < cells.Count; i++)
// // {
// // }
// foreach (var cell in cells)
// {
// if(cell.Color == UnitColor.GREY)
// {
// var randomCell = Random.Range(0, cells.Count);
// Vector3 respawnPosition = cells[randomCell].transform.position;
// GameObject player = FindObjectOfType<ExtraLife>().gameObject;
// player.transform.position = respawnPosition;
// }
// }
// }
// public void AddLIfe(int count)
// {
// lifeCount = count;
// if(count < 1)
// {
// //add reward = new add();
// count++;
// }
// }
}

View File

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

View File

@ -1,65 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gamelogic : MonoBehaviour
{
Mana manaSystem;
private void Start() {
manaSystem = new Mana();
}
private void Update() {
Debug.Log("HP: " + manaSystem.Current_MP);
manaSystem.Update();
}
}
public class Mana
{
public float Max_MP = 100;
public float Current_MP = 1;
List<ManaRegen> regenList;
public Mana()
{
regenList = new List<ManaRegen>();
}
public Mana(float max, float current)
{
Max_MP = max;
Current_MP = current;
regenList = new List<ManaRegen>();
}
public void Update() {
foreach (var regen in regenList.ToArray())
{
if(Current_MP < Max_MP && regen.fDuraton > 0)
{
Current_MP += regen.fManaPerSecond * Time.deltaTime;
}
regen.fDuraton -= 1f *Time.deltaTime;
if(regen.fDuraton < 0)
{
regenList.RemoveAt(regenList.IndexOf(regen));
}
}
}
}
public class ManaRegen
{
public float fDuraton;
public float fManaPerSecond;
public ManaRegen()
{
}
public ManaRegen(float duration, float manaPerSecond)
{
fDuraton = duration;
fManaPerSecond = manaPerSecond;
}
}

View File

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

View File

@ -1,60 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ManaBar : MonoBehaviour
{
public Slider manaBar;
private int maxMana = 100;
private int currentMana;
private WaitForSeconds regenTick = new WaitForSeconds(0.5f);
private Coroutine regen;
public static ManaBar instance;
private void Awake() {
instance = this;
}
private void Start() {
currentMana = maxMana;
manaBar.maxValue = maxMana;
manaBar.value = maxMana;
}
public void UseMana(int amount)
{
if(currentMana - amount >= 0 )
{
currentMana -= amount;
manaBar.value = currentMana;
if(regen != null)
StopCoroutine(regen);
regen = StartCoroutine(RegenMana());
}
else
{
Debug.Log("Not enough mana");
}
}
private IEnumerator RegenMana()
{
yield return new WaitForSeconds(0.1f);
while(currentMana < maxMana)
{
currentMana += maxMana / 10;
manaBar.value = currentMana;
yield return regenTick;
}
regen = null;
}
}

View File

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

View File

@ -1,13 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private void Update() {
if(Input.GetKeyDown(KeyCode.Space))
{
ManaBar.instance.UseMana(15);
}
}
}

View File

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

View File

@ -117,10 +117,10 @@ namespace Units
public void Move(HexDirection direction)
{
if (_cell.GetNeighbor(direction) == null || _isBusy || _isHardToCapture ||
if ( _cell.GetNeighbor(direction) == null || _cell.GetNeighbor(direction).BuildingInstance !=null || _isBusy || _isHardToCapture ||
(_cell.GetNeighbor(direction).Color != Color
&& HexManager.UnitCurrentCell.TryGetValue(_cell.GetNeighbor(direction).Color, out var value)
&& value.cell.coordinates.Equals(_cell.GetNeighbor(direction).coordinates))) return;
&& value.cell.Equals(_cell.GetNeighbor(direction)))) return;
if (_cell.GetNeighbor(direction).Color == _data.color)
@ -383,13 +383,15 @@ namespace Units
_unitView.OnHit -= Damage;
_isAlive = false;
_isBusy = true;
HexManager.PaintHexList(HexManager.CellByColor[Color], UnitColor.Grey);
HexManager.UnitCurrentCell.Remove(Color);
var hexToPaint = HexManager.CellByColor[Color];
_animator.SetTrigger("Death");
var vfx = VFXController.Instance.PlayEffect(HexGrid.Colors[Color].VFXDeathPrefab,
_instance.transform.position);
TimerHelper.Instance.StartTimer(() =>
{
HexManager.PaintHexList(hexToPaint, UnitColor.Grey);
Object.Destroy(_instance);
OnDeath?.Invoke(this);
}, _animLength.Death);

View File

@ -33,7 +33,6 @@ public class UnitView : MonoBehaviour
private Dictionary<string, Action> animActionDic;
private int _mana;
private event Action CaptureHex;
private Sequence _sequence;
private AudioSource _audioSource;
private Unit _unit;
private float _hardCaptureTime;
@ -78,8 +77,8 @@ public class UnitView : MonoBehaviour
{
_unit.BarCanvas.CaptureBar.DOFillAmount(0f, 0);
_barCanvas.CaptureBack.SetActive(true);
_sequence = DOTween.Sequence();
_sequence.Append(_unit.BarCanvas.CaptureBar.DOFillAmount(1f, _hardCaptureTime).SetEase(Ease.Linear).OnComplete(
_unit.BarCanvas.CaptureBar.DOFillAmount(1f, _hardCaptureTime).SetEase(Ease.Linear).OnComplete(
() =>
{
CaptureHex?.Invoke();
@ -87,14 +86,14 @@ public class UnitView : MonoBehaviour
MusicController.Instance.PlayRandomClip(MusicController.Instance.MusicData.SfxMusic.Captures,
cell.gameObject);
}));
_sequence.Play();
});
}
public void StopHardCapture()
{
_sequence.Kill();
_barCanvas.CaptureBar.DOKill();
_barCanvas.CaptureBar.DOFillAmount(0f, 0f).SetEase(Ease.Linear);
_unit.BarCanvas.CaptureBack.SetActive(false);

View File

@ -46,15 +46,14 @@ namespace Weapons
.SetEase(Ease.Linear)
.OnComplete(() =>
{
var vfx = VFXController.Instance.PlayEffect(tmpThis.VFXGameObject, localBall.transform.position, localBall.transform.rotation);
MusicController.Instance.AddAudioSource(vfx);
MusicController.Instance.PlayAudioClip(tmpThis.hitSound, vfx);
Object.Destroy(localBall);
tmpThis.DestroyBall();
});
}
public void DestroyBall()
{
if(ball == null)
return;
var vfx = VFXController.Instance.PlayEffect(VFXGameObject, ball.transform.position, ball.transform.rotation);
MusicController.Instance.AddAudioSource(vfx);
MusicController.Instance.PlayAudioClip(hitSound, vfx);

File diff suppressed because one or more lines are too long