trash tool

This commit is contained in:
klemek
2020-12-16 15:45:44 +01:00
parent 78fe021014
commit a7c2f5bc4f
40 changed files with 662 additions and 34 deletions
+1 -1
View File
@@ -94,7 +94,7 @@ namespace UntitledLogicGame
{
_line.positionCount = 2;
_line.SetPosition(0, StartAnchor.transform.position);
_line.SetPosition(1, MouseManager.MousePos);
_line.SetPosition(1, PointerManager.MousePos);
}
else
{
+31
View File
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UntitledLogicGame
{
//public class TODO : MonoBehaviour
//{
// #region Unity Properties
// #endregion
// #region Public Properties
// #endregion
// #region Unity Methods
// #endregion
// #region Public Methods
// #endregion
// #region Private Methods
// #endregion
//}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c4ef9ac47ea5c04ca839d0f92831e52
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+3 -3
View File
@@ -38,7 +38,7 @@ namespace UntitledLogicGame
public Gate CurrentGate { get; set; }
public MouseManager MouseManager { get; private set; }
public PointerManager MouseManager { get; private set; }
#endregion
@@ -54,7 +54,7 @@ namespace UntitledLogicGame
if (Instance != null)
throw new InvalidOperationException("More than one GameManager in scene");
Instance = this;
MouseManager = GetComponent<MouseManager>();
MouseManager = GetComponent<PointerManager>();
}
// Update is called once per frame
@@ -70,7 +70,7 @@ namespace UntitledLogicGame
public void CreateGate(Gate gatePrefab, Vector3 position)
{
var gate = Instantiate(gatePrefab, GatesGroup);
gate.transform.position = MouseManager.MousePos - gate.Box.transform.position;
gate.transform.position = PointerManager.MousePos - gate.Box.transform.position;
MouseManager.DragGate(gate, true);
}
@@ -1,20 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VectorGraphics;
using UnityEngine;
namespace UntitledLogicGame
{
public class MouseManager : MonoBehaviour
public class PointerManager : MonoBehaviour
{
#region Static Properties
public static MouseManager Instance => GameManager.Instance.MouseManager;
public static PointerManager Instance => GameManager.Instance.MouseManager;
#endregion
#region Unity Properties
public Texture2D DefaultCursor;
public Texture2D PointerCursor;
public Texture2D MoveCursor;
#endregion
#region Public Properties
@@ -23,26 +28,26 @@ namespace UntitledLogicGame
public bool Interacting => _currentCable != null || _currentGate != null;
public bool MovingObject => _currentGate != null;
public static bool Clicking => Input.GetButton("Fire1");
public bool DeleteOnRelease { get; set; }
#endregion
#region Private Properties
private Cable _currentCable;
private Gate _currentGate;
private Vector3 _currentGateInitialPos;
private Vector3? _currentGateInitialPos;
private Vector3 _currentGateDelta;
private Texture2D _currentCursor;
#endregion
#region Unity Methods
private void Start()
{
}
private void FixedUpdate()
{
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
@@ -82,29 +87,39 @@ namespace UntitledLogicGame
}
else if(_currentGate != null)
{
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
if (DeleteOnRelease)
{
renderer.sortingLayerName = "default";
Destroy(_currentGate.gameObject);
}
_currentGate.transform.position = _currentGate.transform.position.Round();
var currentBox = _currentGate.Box;
if (FindObjectsOfType<Gate>()
.Where(g => !g.Equals(_currentGate))
.Select(g => g.Box)
.Any(b => currentBox.IsTouching(b)))
else
{
// Collision with another gate
if(_currentGateInitialPos == null)
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
{
Destroy(_currentGate.gameObject);
renderer.sortingLayerName = "default";
}
else
_currentGate.transform.position = _currentGate.transform.position.Round();
var currentBox = _currentGate.Box;
if (FindObjectsOfType<Gate>()
.Where(g => !g.Equals(_currentGate))
.Select(g => g.Box)
.Any(b => currentBox.IsTouching(b)))
{
_currentGate.transform.position = _currentGateInitialPos; // Reset pos
// Collision with another gate
if (_currentGateInitialPos == null)
{
Destroy(_currentGate.gameObject);
}
else
{
_currentGate.transform.position = _currentGateInitialPos.Value; // Reset pos
}
}
}
_currentGate = null;
DeleteOnRelease = false;
}
SetCursor();
}
#endregion
@@ -115,18 +130,49 @@ namespace UntitledLogicGame
{
_currentGate = gate;
_currentGateDelta = MousePos - _currentGate.transform.position;
if(!created)
_currentGateInitialPos = _currentGate.transform.position;
_currentGateInitialPos = created ? (Vector3?)null : _currentGate.transform.position;
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
{
renderer.sortingLayerName = "moving";
}
}
public void RequestDelete()
{
if (_currentGate != null)
{
Destroy(_currentGate.gameObject);
_currentGate = null;
}
}
#endregion
#region Private Methods
private void SetCursor()
{
Texture2D cursor = DefaultCursor;
Vector2 position = Vector2.zero;
if(!Interacting && GameManager.Instance.CurrentAnchor != null || Interacting && _currentCable != null)
{
cursor = PointerCursor;
position = new Vector2(cursor.width / 2f, 0f);
}
else if (!Interacting && GameManager.Instance.CurrentGate != null || Interacting && _currentGate != null)
{
cursor = MoveCursor;
position = new Vector2(cursor.width / 2f, cursor.height / 2f);
}
if(_currentCursor != cursor)
{
Cursor.SetCursor(cursor, position, CursorMode.Auto);
_currentCursor = cursor;
}
}
#endregion
}
}
+58
View File
@@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using Unity.VectorGraphics;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UntitledLogicGame.UI
{
public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
#region Unity Properties
public SVGImage openImage;
#endregion
#region Public Properties
#endregion
#region Private Properties
private SVGImage _image;
private Sprite _closedSprite;
#endregion
#region Unity Methods
private void Start()
{
_image = GetComponent<SVGImage>();
_closedSprite = _image.sprite;
}
public void OnPointerEnter(PointerEventData eventData)
{
_image.sprite = openImage.sprite;
PointerManager.Instance.DeleteOnRelease = true;
}
public void OnPointerExit(PointerEventData eventData)
{
_image.sprite = _closedSprite;
PointerManager.Instance.DeleteOnRelease = false;
}
#endregion
#region Public Methods
#endregion
#region Private Methods
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 07b6ed78fbbf4124794530c3e8451329
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+7 -4
View File
@@ -11,6 +11,7 @@ namespace UntitledLogicGame.UI
[Header("Components")]
public GameObject GateBar;
public GameObject MovingBar;
[Header("Prefabs")]
public UIGate UIGatePrefab;
@@ -41,16 +42,18 @@ namespace UntitledLogicGame.UI
uiGate.RectTransform.anchoredPosition = new Vector2(currentPos, 0);
currentPos += uiGate.RectTransform.sizeDelta.x;
}
MovingBar.SetActive(false);
}
private void FixedUpdate()
{
if(MouseManager.Instance.Interacting != _lastMouseInteracting)
if(PointerManager.Instance.Interacting != _lastMouseInteracting)
{
//TODO animate go down
GateBar.SetActive(!MouseManager.Instance.Interacting);
_lastMouseInteracting = MouseManager.Instance.Interacting;
GateBar.SetActive(!PointerManager.Instance.Interacting);
MovingBar.SetActive(PointerManager.Instance.MovingObject);
_lastMouseInteracting = PointerManager.Instance.Interacting;
}
}