working toolbar
This commit is contained in:
Executable
+67
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VectorGraphics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIGate : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Gate GatePrefab {
|
||||
set
|
||||
{
|
||||
_gatePrefab = value;
|
||||
var sprite = _gatePrefab.GetComponentInChildren<SpriteRenderer>().sprite;
|
||||
GetComponent<SVGImage>().sprite = sprite;
|
||||
RectTransform.sizeDelta = new Vector2(100 * sprite.rect.width / 700f, 100); // TODO get max width from UIManager
|
||||
gameObject.name = "UI_" + _gatePrefab.GateType.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public RectTransform RectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rectTransform == null)
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
return _rectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private Gate _gatePrefab;
|
||||
private RectTransform _rectTransform;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
var position = Camera.main.ScreenToWorldPoint(transform.position);
|
||||
position.z = 0f;
|
||||
GameManager.Instance.CreateGate(_gatePrefab, position);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a451c18bcd06994d8ac3b549cff313d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
[Header("Components")]
|
||||
public GameObject GateBar;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public UIGate UIGatePrefab;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private bool _lastMouseInteracting;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
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.RectTransform.anchoredPosition = new Vector2(currentPos, 0);
|
||||
currentPos += uiGate.RectTransform.sizeDelta.x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if(MouseManager.Instance.Interacting != _lastMouseInteracting)
|
||||
{
|
||||
//TODO animate go down
|
||||
GateBar.SetActive(!MouseManager.Instance.Interacting);
|
||||
_lastMouseInteracting = MouseManager.Instance.Interacting;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3124eabb2ea5e3547bf503bdcc463cb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user