gate sub-categories
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UntitledLogicGame.Workspace.Gates;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
@@ -15,41 +17,45 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
[Header("Prefabs")]
|
||||
public UIGate UIGatePrefab;
|
||||
public UIFolder UIFolderPrefab;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public GateCategory GateBarState
|
||||
{
|
||||
get => _gateBarState;
|
||||
set
|
||||
{
|
||||
_gateBarState = value;
|
||||
UpdateGateBar();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private bool _lastMouseInteracting;
|
||||
private GateCategory _gateBarState;
|
||||
private Dictionary<GateCategory, GameObject> _gateBarSateList;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private IEnumerator Start()
|
||||
private IEnumerator Start()
|
||||
{
|
||||
yield return new WaitUntil(() => GameManager.Instance != null);
|
||||
// TODO calculate max width
|
||||
var currentPos = 0f;
|
||||
foreach(var gatePrefab in GameManager.Instance.GatePrefabs)
|
||||
{
|
||||
var uiGate = Instantiate(UIGatePrefab, GateBar.transform);
|
||||
uiGate.GatePrefab = gatePrefab;
|
||||
uiGate.GetComponent<RectTransform>().anchoredPosition = new Vector2(currentPos, 0);
|
||||
currentPos += 100f;
|
||||
}
|
||||
|
||||
MovingBar.SetActive(false);
|
||||
}
|
||||
CreateGateBar();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateUI();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -70,6 +76,74 @@ namespace UntitledLogicGame.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateGateBar()
|
||||
{
|
||||
_gateBarSateList = new Dictionary<GateCategory, GameObject>();
|
||||
|
||||
var allCategories = Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>();
|
||||
|
||||
foreach (var category in allCategories)
|
||||
{
|
||||
var parent = new GameObject(category.ToString(), typeof(RectTransform));
|
||||
parent.transform.parent = GateBar.transform;
|
||||
var rect = parent.GetComponent<RectTransform>();
|
||||
rect.anchorMin = Vector2.zero;
|
||||
rect.anchorMax = new Vector2(1, 1);
|
||||
rect.position = Vector2.zero;
|
||||
rect.offsetMin = Vector2.zero;
|
||||
parent.SetActive(false);
|
||||
if(category == GateCategory.None)
|
||||
{
|
||||
var currentPos = 0f;
|
||||
foreach (var subCategory in allCategories)
|
||||
{
|
||||
if(subCategory != GateCategory.None)
|
||||
{
|
||||
var uiFolder = Instantiate(UIFolderPrefab, parent.transform);
|
||||
uiFolder.Rect.anchoredPosition = new Vector2(currentPos, 0);
|
||||
uiFolder.Name = subCategory.ToString();
|
||||
uiFolder.OnClick = () =>
|
||||
{
|
||||
GateBarState = subCategory;
|
||||
};
|
||||
currentPos += 100f;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var uiFolder = Instantiate(UIFolderPrefab, parent.transform);
|
||||
uiFolder.Name = "Back";
|
||||
uiFolder.IsBack = true;
|
||||
uiFolder.OnClick = () =>
|
||||
{
|
||||
GateBarState = GateCategory.None;
|
||||
};
|
||||
var currentPos = 100f;
|
||||
var possibleGateTypes = GateDefinition.TypeCategoryList[category];
|
||||
foreach (var gatePrefab in GameManager.Instance.GatePrefabs.Where(g => possibleGateTypes.Contains(g.GateType)))
|
||||
{
|
||||
var uiGate = Instantiate(UIGatePrefab, parent.transform);
|
||||
uiGate.GatePrefab = gatePrefab;
|
||||
uiGate.Rect.anchoredPosition = new Vector2(currentPos, 0);
|
||||
uiGate.OnClick = () => {
|
||||
GameManager.Instance.CreateGate(gatePrefab);
|
||||
};
|
||||
currentPos += 100f;
|
||||
}
|
||||
}
|
||||
_gateBarSateList[category] = parent;
|
||||
}
|
||||
UpdateGateBar();
|
||||
}
|
||||
|
||||
private void UpdateGateBar()
|
||||
{
|
||||
//TODO animate ?
|
||||
foreach (var category in Enum.GetValues(typeof(GateCategory)).Cast<GateCategory>())
|
||||
_gateBarSateList[category].SetActive(category == GateBarState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user