refactor placement buttons to accomodate delete
This commit is contained in:
parent
637fec1410
commit
795d6751ec
@ -708,6 +708,7 @@ GameObject:
|
|||||||
- component: {fileID: 179679301}
|
- component: {fileID: 179679301}
|
||||||
- component: {fileID: 179679300}
|
- component: {fileID: 179679300}
|
||||||
- component: {fileID: 179679299}
|
- component: {fileID: 179679299}
|
||||||
|
- component: {fileID: 179679302}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: Remove
|
m_Name: Remove
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -817,6 +818,18 @@ CanvasRenderer:
|
|||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 179679297}
|
m_GameObject: {fileID: 179679297}
|
||||||
m_CullTransparentMesh: 1
|
m_CullTransparentMesh: 1
|
||||||
|
--- !u!114 &179679302
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 179679297}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bd64ba32c0dc69d40a067bbeb7f1b8f0, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
--- !u!114 &180485348 stripped
|
--- !u!114 &180485348 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_CorrespondingSourceObject: {fileID: 217791848456698108, guid: 5497dc5adfbe67341980c9d946816424, type: 3}
|
m_CorrespondingSourceObject: {fileID: 217791848456698108, guid: 5497dc5adfbe67341980c9d946816424, type: 3}
|
||||||
|
|||||||
5
Assets/Scripts/CardInfo.cs
Normal file
5
Assets/Scripts/CardInfo.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class CardInfo : ScriptableObject
|
||||||
|
{
|
||||||
|
}
|
||||||
11
Assets/Scripts/CardInfo.cs.meta
Normal file
11
Assets/Scripts/CardInfo.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a23104b82dc1384aa1f7fa6f263a41c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
12
Assets/Scripts/DeleteButton.cs
Normal file
12
Assets/Scripts/DeleteButton.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
public class DeleteButton : PlacementButton
|
||||||
|
{
|
||||||
|
protected override DraggablePlaceholder Place()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/DeleteButton.cs.meta
Normal file
11
Assets/Scripts/DeleteButton.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bd64ba32c0dc69d40a067bbeb7f1b8f0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -13,7 +13,7 @@ public class GameObjectPlacementButton : UnitPlacementButton
|
|||||||
var hasEnoughPopulation = isBuilding || ResourceManager.Instance.EnoughPopulationFor(defaultPopCost);
|
var hasEnoughPopulation = isBuilding || ResourceManager.Instance.EnoughPopulationFor(defaultPopCost);
|
||||||
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food)
|
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food)
|
||||||
&& hasEnoughPopulation
|
&& hasEnoughPopulation
|
||||||
&& _button.enabled && _canSpawn;
|
&& base.CanPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DraggablePlaceholder Place()
|
protected override DraggablePlaceholder Place()
|
||||||
@ -44,7 +44,7 @@ public class GameObjectPlacementButton : UnitPlacementButton
|
|||||||
color.a = 0.6f;
|
color.a = 0.6f;
|
||||||
rend.color = color;
|
rend.color = color;
|
||||||
|
|
||||||
rend.material = _outlineMaterial;
|
rend.material = OutlineMaterial;
|
||||||
placeholder.OutlineRenderers.Add(rend);
|
placeholder.OutlineRenderers.Add(rend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
53
Assets/Scripts/Drag&Drop/PlacementButton.cs
Normal file
53
Assets/Scripts/Drag&Drop/PlacementButton.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using GatherAndDefend.Events;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
[RequireComponent(typeof(Button))]
|
||||||
|
public abstract class PlacementButton : MonoBehaviour, IPointerDownHandler
|
||||||
|
{
|
||||||
|
private bool _canUse = false;
|
||||||
|
private Button _button;
|
||||||
|
private DraggablePlaceholder placeholder;
|
||||||
|
[SerializeField]
|
||||||
|
private Material _outlineMaterial;
|
||||||
|
|
||||||
|
public bool CanUse => _canUse;
|
||||||
|
public Button Button => _button;
|
||||||
|
public DraggablePlaceholder Placeholder => placeholder;
|
||||||
|
public Material OutlineMaterial => _outlineMaterial;
|
||||||
|
protected virtual void Start()
|
||||||
|
{
|
||||||
|
_button = GetComponent<Button>();
|
||||||
|
_button.enabled = false;
|
||||||
|
EventAggregator.Instance.GetEvent<LevelLoadedEvent>().Attach(OnLevelLoaded);
|
||||||
|
EventAggregator.Instance.GetEvent<ExitingLevelEvent>().Attach(DeactivateButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void Update()
|
||||||
|
{
|
||||||
|
_button.interactable = CanPlace();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLevelLoaded(GatherAndDefend.LevelEditor.Level level)
|
||||||
|
{
|
||||||
|
_canUse = true;
|
||||||
|
EventAggregator.Instance.GetEvent<LevelLoadedEvent>().Detach(OnLevelLoaded);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeactivateButton()
|
||||||
|
{
|
||||||
|
EventAggregator.Instance.GetEvent<ExitingLevelEvent>().Detach(DeactivateButton);
|
||||||
|
_canUse = false;
|
||||||
|
}
|
||||||
|
public virtual void OnPointerDown(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (!_button.interactable) return;
|
||||||
|
placeholder = Place();
|
||||||
|
}
|
||||||
|
protected abstract DraggablePlaceholder Place();
|
||||||
|
protected virtual bool CanPlace()
|
||||||
|
{
|
||||||
|
return Button.enabled && CanUse;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/Drag&Drop/PlacementButton.cs.meta
Normal file
11
Assets/Scripts/Drag&Drop/PlacementButton.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ecad147c112b0c14d8e6705756ea170e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -8,7 +8,7 @@ public class TilePlacementButton : UnitPlacementButton
|
|||||||
|
|
||||||
protected override bool CanPlace()
|
protected override bool CanPlace()
|
||||||
{
|
{
|
||||||
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food) && _button.enabled && _canSpawn;
|
return ResourceManager.Instance.EnoughFor(_rock, _wood, _food) && base.CanPlace();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DraggablePlaceholder Place()
|
protected override DraggablePlaceholder Place()
|
||||||
@ -19,7 +19,7 @@ public class TilePlacementButton : UnitPlacementButton
|
|||||||
var rend = instance.AddComponent<SpriteRenderer>();
|
var rend = instance.AddComponent<SpriteRenderer>();
|
||||||
rend.sprite = tile.Sprite;
|
rend.sprite = tile.Sprite;
|
||||||
rend.sortingLayerName = "Character";
|
rend.sortingLayerName = "Character";
|
||||||
rend.material = _outlineMaterial;
|
rend.material = OutlineMaterial;
|
||||||
rend.sortingOrder = 2;
|
rend.sortingOrder = 2;
|
||||||
return placeholder;
|
return placeholder;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,10 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using GatherAndDefend.Events;
|
|
||||||
|
|
||||||
[RequireComponent(typeof(Button))]
|
public abstract class UnitPlacementButton : PlacementButton
|
||||||
public abstract class UnitPlacementButton : MonoBehaviour, IPointerDownHandler
|
|
||||||
{
|
{
|
||||||
[SerializeField]
|
|
||||||
protected Material _outlineMaterial;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected Sprite _detectionRangeSprite;
|
protected Sprite _detectionRangeSprite;
|
||||||
|
|
||||||
@ -21,7 +15,6 @@ public abstract class UnitPlacementButton : MonoBehaviour, IPointerDownHandler
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
protected int _food;
|
protected int _food;
|
||||||
|
|
||||||
protected Button _button;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private TMP_Text _foodLabel;
|
private TMP_Text _foodLabel;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -29,30 +22,10 @@ public abstract class UnitPlacementButton : MonoBehaviour, IPointerDownHandler
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private TMP_Text _rockLabel;
|
private TMP_Text _rockLabel;
|
||||||
|
|
||||||
protected bool _canSpawn = false;
|
|
||||||
|
protected override void Update()
|
||||||
protected virtual void Start()
|
|
||||||
{
|
{
|
||||||
_button = GetComponent<Button>();
|
base.Update();
|
||||||
|
|
||||||
_button.enabled = false;
|
|
||||||
EventAggregator.Instance.GetEvent<LevelLoadedEvent>().Attach(OnLevelLoaded);
|
|
||||||
EventAggregator.Instance.GetEvent<ExitingLevelEvent>().Attach(DeactivateButton);
|
|
||||||
}
|
|
||||||
private void OnLevelLoaded(GatherAndDefend.LevelEditor.Level level)
|
|
||||||
{
|
|
||||||
_canSpawn = true;
|
|
||||||
EventAggregator.Instance.GetEvent<LevelLoadedEvent>().Detach(OnLevelLoaded);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeactivateButton()
|
|
||||||
{
|
|
||||||
EventAggregator.Instance.GetEvent<ExitingLevelEvent>().Detach(DeactivateButton);
|
|
||||||
_canSpawn = false;
|
|
||||||
}
|
|
||||||
protected virtual void Update()
|
|
||||||
{
|
|
||||||
_button.interactable = CanPlace();
|
|
||||||
|
|
||||||
SetTextFor(_foodLabel, _food);
|
SetTextFor(_foodLabel, _food);
|
||||||
SetTextFor(_rockLabel, _rock);
|
SetTextFor(_rockLabel, _rock);
|
||||||
@ -63,15 +36,11 @@ public abstract class UnitPlacementButton : MonoBehaviour, IPointerDownHandler
|
|||||||
label.transform.parent.gameObject.SetActive(value > 0);
|
label.transform.parent.gameObject.SetActive(value > 0);
|
||||||
label.text = "" + value;
|
label.text = "" + value;
|
||||||
}
|
}
|
||||||
public void OnPointerDown(PointerEventData eventData)
|
public override void OnPointerDown(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (!_button.interactable) return;
|
base.OnPointerDown(eventData);
|
||||||
|
Placeholder.Rock = _rock;
|
||||||
var placeholder = Place();
|
Placeholder.Wood = _wood;
|
||||||
placeholder.Rock = _rock;
|
Placeholder.Food = _food;
|
||||||
placeholder.Wood = _wood;
|
|
||||||
placeholder.Food = _food;
|
|
||||||
}
|
}
|
||||||
protected abstract DraggablePlaceholder Place();
|
|
||||||
protected abstract bool CanPlace();
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user