formatting
This commit is contained in:
@@ -4,77 +4,77 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame
|
||||
{
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
[Header("Zooming")]
|
||||
public int MinSize;
|
||||
public int MaxSize;
|
||||
public float ScrollSensitivity;
|
||||
[Header("Zooming")]
|
||||
public int MinSize;
|
||||
public int MaxSize;
|
||||
public float ScrollSensitivity;
|
||||
|
||||
[Header("Moving")]
|
||||
public Camera Camera101;
|
||||
[Header("Moving")]
|
||||
public Camera Camera101;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Vector3 _startDragMousePos;
|
||||
private Vector3? _startDragPos;
|
||||
private Vector3 _startDragMousePos;
|
||||
private Vector3? _startDragPos;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateZoom();
|
||||
UpdateDrag();
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateZoom();
|
||||
UpdateDrag();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateZoom()
|
||||
{
|
||||
var size = Camera.main.orthographicSize;
|
||||
size -= Input.GetAxis("Mouse ScrollWheel") * ScrollSensitivity;
|
||||
size = Mathf.Clamp(size, MinSize, MaxSize);
|
||||
Camera.main.orthographicSize = size;
|
||||
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -size);
|
||||
}
|
||||
private void UpdateZoom()
|
||||
{
|
||||
var size = Camera.main.orthographicSize;
|
||||
size -= Input.GetAxis("Mouse ScrollWheel") * ScrollSensitivity;
|
||||
size = Mathf.Clamp(size, MinSize, MaxSize);
|
||||
Camera.main.orthographicSize = size;
|
||||
Camera.main.transform.position = new Vector3(Camera.main.transform.position.x, Camera.main.transform.position.y, -size);
|
||||
}
|
||||
|
||||
private void UpdateDrag()
|
||||
{
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
var mousePos = Camera101.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePos.z = 0f;
|
||||
private void UpdateDrag()
|
||||
{
|
||||
if (Input.GetMouseButton(2))
|
||||
{
|
||||
var mousePos = Camera101.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePos.z = 0f;
|
||||
|
||||
if (_startDragPos == null)
|
||||
{
|
||||
_startDragMousePos = mousePos;
|
||||
_startDragPos = Camera.main.transform.position;
|
||||
}
|
||||
if (_startDragPos == null)
|
||||
{
|
||||
_startDragMousePos = mousePos;
|
||||
_startDragPos = Camera.main.transform.position;
|
||||
}
|
||||
|
||||
Camera.main.transform.position = _startDragPos.Value - (mousePos - _startDragMousePos) * Camera.main.orthographicSize;
|
||||
}
|
||||
else if (_startDragPos != null)
|
||||
{
|
||||
_startDragPos = null;
|
||||
}
|
||||
}
|
||||
Camera.main.transform.position = _startDragPos.Value - (mousePos - _startDragMousePos) * Camera.main.orthographicSize;
|
||||
}
|
||||
else if (_startDragPos != null)
|
||||
{
|
||||
_startDragPos = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,31 +5,31 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame
|
||||
{
|
||||
//public class TODO : MonoBehaviour
|
||||
//{
|
||||
// #region Unity Properties
|
||||
//public class TODO : MonoBehaviour
|
||||
//{
|
||||
// #region Unity Properties
|
||||
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
// #region Public Properties
|
||||
// #region Public Properties
|
||||
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
// #region Private Properties
|
||||
// #region Private Properties
|
||||
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
// #region Unity Methods
|
||||
// #region Unity Methods
|
||||
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
// #region Public Methods
|
||||
// #region Public Methods
|
||||
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
// #region Private Methods
|
||||
// #region Private Methods
|
||||
|
||||
// #endregion
|
||||
//}
|
||||
// #endregion
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,80 +6,80 @@ using UntitledLogicGame.Workspace;
|
||||
|
||||
namespace UntitledLogicGame
|
||||
{
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
#region Static Properties
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
#region Static Properties
|
||||
|
||||
public static GameManager Instance {
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = FindObjectOfType<GameManager>();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
private static GameManager _instance;
|
||||
public static GameManager Instance {
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = FindObjectOfType<GameManager>();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
private static GameManager _instance;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Properties
|
||||
#region Unity Properties
|
||||
|
||||
[Header("Prefabs")]
|
||||
public Cable CablePrefab;
|
||||
[Header("Prefabs")]
|
||||
public Cable CablePrefab;
|
||||
|
||||
[Header("Groups")]
|
||||
public Transform GatesGroup;
|
||||
public Transform CablesGroup;
|
||||
[Header("Groups")]
|
||||
public Transform GatesGroup;
|
||||
public Transform CablesGroup;
|
||||
|
||||
[Header("Colors")]
|
||||
public Color DeadColor;
|
||||
public Color ActivatedColor;
|
||||
[Header("Colors")]
|
||||
public Color DeadColor;
|
||||
public Color ActivatedColor;
|
||||
|
||||
[Header("Gates")]
|
||||
public List<Gate> GatePrefabs;
|
||||
[Header("Gates")]
|
||||
public List<Gate> GatePrefabs;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public Anchor CurrentAnchor { get; set; }
|
||||
public Gate CurrentGate { get; set; }
|
||||
public PointerManager PointerManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pointerManager == null)
|
||||
_pointerManager = GetComponent<PointerManager>();
|
||||
return _pointerManager;
|
||||
}
|
||||
}
|
||||
public Anchor CurrentAnchor { get; set; }
|
||||
public Gate CurrentGate { get; set; }
|
||||
public PointerManager PointerManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_pointerManager == null)
|
||||
_pointerManager = GetComponent<PointerManager>();
|
||||
return _pointerManager;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private PointerManager _pointerManager;
|
||||
private PointerManager _pointerManager;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public void CreateGate(Gate gatePrefab)
|
||||
{
|
||||
var gate = Instantiate(gatePrefab, GatesGroup);
|
||||
gate.transform.position = PointerManager.MousePos - gate.Box.transform.position;
|
||||
PointerManager.DragGate(gate, true);
|
||||
}
|
||||
public void CreateGate(Gate gatePrefab)
|
||||
{
|
||||
var gate = Instantiate(gatePrefab, GatesGroup);
|
||||
gate.transform.position = PointerManager.MousePos - gate.Box.transform.position;
|
||||
PointerManager.DragGate(gate, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
+191
-191
@@ -7,226 +7,226 @@ using UntitledLogicGame.Workspace;
|
||||
|
||||
namespace UntitledLogicGame
|
||||
{
|
||||
public class PointerManager : MonoBehaviour
|
||||
{
|
||||
#region Static Properties
|
||||
public class PointerManager : MonoBehaviour
|
||||
{
|
||||
#region Static Properties
|
||||
|
||||
public static PointerManager Instance => GameManager.Instance.PointerManager;
|
||||
public static PointerManager Instance => GameManager.Instance.PointerManager;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Properties
|
||||
#region Unity Properties
|
||||
|
||||
[Header("Click")]
|
||||
public float DoubleClickThreshold;
|
||||
public float DoubleClickDelay;
|
||||
[Header("Click")]
|
||||
public float DoubleClickThreshold;
|
||||
public float DoubleClickDelay;
|
||||
|
||||
[Header("Cursor")]
|
||||
public Texture2D DefaultCursor;
|
||||
public Texture2D PointerCursor;
|
||||
public Texture2D MoveCursor;
|
||||
[Header("Cursor")]
|
||||
public Texture2D DefaultCursor;
|
||||
public Texture2D PointerCursor;
|
||||
public Texture2D MoveCursor;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public static Vector3 MousePos { get; set; }
|
||||
public bool Interacting => _currentCable != null || _currentGate != null;
|
||||
public bool MovingObject => _currentGate != null;
|
||||
public bool Clicking => Input.GetButton("Fire1");
|
||||
public bool DeleteOnRelease { get; set; }
|
||||
public static Vector3 MousePos { get; set; }
|
||||
public bool Interacting => _currentCable != null || _currentGate != null;
|
||||
public bool MovingObject => _currentGate != null;
|
||||
public bool Clicking => Input.GetButton("Fire1");
|
||||
public bool DeleteOnRelease { get; set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Cable _currentCable;
|
||||
private Gate _currentGate;
|
||||
private Vector3? _currentGateInitialPos;
|
||||
private Vector3 _currentGateDelta;
|
||||
private Texture2D _currentCursor;
|
||||
private float _clicked = 0f;
|
||||
private float _clicktime = 0f;
|
||||
private Cable _currentCable;
|
||||
private Gate _currentGate;
|
||||
private Vector3? _currentGateInitialPos;
|
||||
private Vector3 _currentGateDelta;
|
||||
private Texture2D _currentCursor;
|
||||
private float _clicked = 0f;
|
||||
private float _clicktime = 0f;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateMousePos();
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateMousePos();
|
||||
|
||||
if (Clicking)
|
||||
{
|
||||
UpdateDrag();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateDrop();
|
||||
}
|
||||
if (Clicking)
|
||||
{
|
||||
UpdateDrag();
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateDrop();
|
||||
}
|
||||
|
||||
UpdateCursor();
|
||||
}
|
||||
UpdateCursor();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public void DragGate(Gate gate, bool created)
|
||||
{
|
||||
_currentGate = gate;
|
||||
_currentGateDelta = MousePos - _currentGate.transform.position;
|
||||
_currentGateInitialPos = created ? (Vector3?)null : _currentGate.transform.position;
|
||||
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
renderer.sortingLayerName = "moving";
|
||||
}
|
||||
}
|
||||
public void DragGate(Gate gate, bool created)
|
||||
{
|
||||
_currentGate = gate;
|
||||
_currentGateDelta = MousePos - _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;
|
||||
}
|
||||
}
|
||||
public void RequestDelete()
|
||||
{
|
||||
if (_currentGate != null)
|
||||
{
|
||||
Destroy(_currentGate.gameObject);
|
||||
_currentGate = null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DoubleClick()
|
||||
{
|
||||
|
||||
if (Clicking)
|
||||
{
|
||||
_clicked += Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_clicked >= DoubleClickThreshold)
|
||||
{
|
||||
if(Time.time - _clicktime < DoubleClickDelay)
|
||||
{
|
||||
_clicked = 0f;
|
||||
_clicktime = 0f;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_clicktime = Time.time;
|
||||
}
|
||||
}
|
||||
_clicked = 0f;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool DoubleClick()
|
||||
{
|
||||
|
||||
if (Clicking)
|
||||
{
|
||||
_clicked += Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_clicked >= DoubleClickThreshold)
|
||||
{
|
||||
if(Time.time - _clicktime < DoubleClickDelay)
|
||||
{
|
||||
_clicked = 0f;
|
||||
_clicktime = 0f;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_clicktime = Time.time;
|
||||
}
|
||||
}
|
||||
_clicked = 0f;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private static void UpdateMousePos()
|
||||
{
|
||||
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePos.z = 0f;
|
||||
MousePos = mousePos;
|
||||
}
|
||||
private static void UpdateMousePos()
|
||||
{
|
||||
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
mousePos.z = 0f;
|
||||
MousePos = mousePos;
|
||||
}
|
||||
|
||||
private void UpdateCursor()
|
||||
{
|
||||
var cursor = DefaultCursor;
|
||||
var position = Vector2.zero;
|
||||
private void UpdateCursor()
|
||||
{
|
||||
var cursor = DefaultCursor;
|
||||
var 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 (!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)
|
||||
{
|
||||
//TODO Invalid texture used for cursor - check importer settings or texture creation. Texture must be RGBA32, readable, have alphaIsTransparency enabled and have no mip chain.
|
||||
Cursor.SetCursor(cursor, position, CursorMode.Auto);
|
||||
_currentCursor = cursor;
|
||||
}
|
||||
}
|
||||
if(_currentCursor != cursor)
|
||||
{
|
||||
//TODO Invalid texture used for cursor - check importer settings or texture creation. Texture must be RGBA32, readable, have alphaIsTransparency enabled and have no mip chain.
|
||||
Cursor.SetCursor(cursor, position, CursorMode.Auto);
|
||||
_currentCursor = cursor;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDrag()
|
||||
{
|
||||
if (_currentCable != null) // Dragging cable
|
||||
{
|
||||
_currentCable.FallbackEndPos = MousePos;
|
||||
}
|
||||
else if (_currentGate != null) // Dragging gate
|
||||
{
|
||||
_currentGate.transform.position = MousePos - _currentGateDelta;
|
||||
}
|
||||
else if (GameManager.Instance.CurrentAnchor != null) // Dragging new cable
|
||||
{
|
||||
_currentCable = Instantiate(GameManager.Instance.CablePrefab, GameManager.Instance.CablesGroup, true);
|
||||
_currentCable.StartAnchor = GameManager.Instance.CurrentAnchor;
|
||||
_currentCable.FallbackEndPos = MousePos;
|
||||
}
|
||||
else if (GameManager.Instance.CurrentGate != null) // Dragging new gate
|
||||
{
|
||||
DragGate(GameManager.Instance.CurrentGate, false);
|
||||
}
|
||||
}
|
||||
private void UpdateDrag()
|
||||
{
|
||||
if (_currentCable != null) // Dragging cable
|
||||
{
|
||||
_currentCable.FallbackEndPos = MousePos;
|
||||
}
|
||||
else if (_currentGate != null) // Dragging gate
|
||||
{
|
||||
_currentGate.transform.position = MousePos - _currentGateDelta;
|
||||
}
|
||||
else if (GameManager.Instance.CurrentAnchor != null) // Dragging new cable
|
||||
{
|
||||
_currentCable = Instantiate(GameManager.Instance.CablePrefab, GameManager.Instance.CablesGroup, true);
|
||||
_currentCable.StartAnchor = GameManager.Instance.CurrentAnchor;
|
||||
_currentCable.FallbackEndPos = MousePos;
|
||||
}
|
||||
else if (GameManager.Instance.CurrentGate != null) // Dragging new gate
|
||||
{
|
||||
DragGate(GameManager.Instance.CurrentGate, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDrop()
|
||||
{
|
||||
if (_currentCable != null) // Dropping cable
|
||||
{
|
||||
if (GameManager.Instance.CurrentAnchor == null || _currentCable.StartAnchor.IsInput == GameManager.Instance.CurrentAnchor.IsInput)
|
||||
{
|
||||
Destroy(_currentCable.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentCable.EndAnchor = GameManager.Instance.CurrentAnchor;
|
||||
}
|
||||
_currentCable = null;
|
||||
}
|
||||
else if (_currentGate != null) // Dropping gate
|
||||
{
|
||||
if (DeleteOnRelease)
|
||||
{
|
||||
Destroy(_currentGate.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
renderer.sortingLayerName = "default";
|
||||
}
|
||||
_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)))
|
||||
{
|
||||
// Collision with another gate
|
||||
if (_currentGateInitialPos == null)
|
||||
{
|
||||
Destroy(_currentGate.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentGate.transform.position = _currentGateInitialPos.Value; // Reset pos
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentGate = null;
|
||||
DeleteOnRelease = false;
|
||||
}
|
||||
}
|
||||
private void UpdateDrop()
|
||||
{
|
||||
if (_currentCable != null) // Dropping cable
|
||||
{
|
||||
if (GameManager.Instance.CurrentAnchor == null || _currentCable.StartAnchor.IsInput == GameManager.Instance.CurrentAnchor.IsInput)
|
||||
{
|
||||
Destroy(_currentCable.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentCable.EndAnchor = GameManager.Instance.CurrentAnchor;
|
||||
}
|
||||
_currentCable = null;
|
||||
}
|
||||
else if (_currentGate != null) // Dropping gate
|
||||
{
|
||||
if (DeleteOnRelease)
|
||||
{
|
||||
Destroy(_currentGate.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
renderer.sortingLayerName = "default";
|
||||
}
|
||||
_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)))
|
||||
{
|
||||
// Collision with another gate
|
||||
if (_currentGateInitialPos == null)
|
||||
{
|
||||
Destroy(_currentGate.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
_currentGate.transform.position = _currentGateInitialPos.Value; // Reset pos
|
||||
}
|
||||
}
|
||||
}
|
||||
_currentGate = null;
|
||||
DeleteOnRelease = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -6,20 +6,20 @@ using UnityEngine.EventSystems;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
public class UIDelete : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
public SVGImage closedImage;
|
||||
public SVGImage openImage;
|
||||
public SVGImage openImage;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private SVGImage Image
|
||||
{
|
||||
@@ -31,23 +31,23 @@ namespace UntitledLogicGame.UI
|
||||
}
|
||||
}
|
||||
|
||||
private SVGImage _image;
|
||||
private SVGImage _image;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
Image.sprite = openImage.sprite;
|
||||
PointerManager.Instance.DeleteOnRelease = true;
|
||||
}
|
||||
PointerManager.Instance.DeleteOnRelease = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
Image.sprite = closedImage.sprite;
|
||||
PointerManager.Instance.DeleteOnRelease = false;
|
||||
}
|
||||
PointerManager.Instance.DeleteOnRelease = false;
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
|
||||
@@ -34,18 +34,18 @@ namespace UntitledLogicGame.UI
|
||||
|
||||
#region Private Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,16 @@ using UntitledLogicGame.Workspace.Gates;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
[Header("Components")]
|
||||
public GameObject GateBar;
|
||||
public GameObject MovingBar;
|
||||
[Header("Components")]
|
||||
public GameObject GateBar;
|
||||
public GameObject MovingBar;
|
||||
|
||||
[Header("Prefabs")]
|
||||
public UIGate UIGatePrefab;
|
||||
[Header("Prefabs")]
|
||||
public UIGate UIGatePrefab;
|
||||
public UIFolder UIFolderPrefab;
|
||||
|
||||
#endregion
|
||||
@@ -33,11 +33,11 @@ namespace UntitledLogicGame.UI
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private bool _lastMouseInteracting;
|
||||
private bool _lastMouseInteracting;
|
||||
private GateCategory _gateBarState;
|
||||
private Dictionary<GateCategory, GameObject> _gateBarSateList;
|
||||
|
||||
@@ -46,35 +46,35 @@ namespace UntitledLogicGame.UI
|
||||
#region Unity Methods
|
||||
|
||||
private IEnumerator Start()
|
||||
{
|
||||
yield return new WaitUntil(() => GameManager.Instance != null);
|
||||
{
|
||||
yield return new WaitUntil(() => GameManager.Instance != null);
|
||||
CreateGateBar();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateUI();
|
||||
private void FixedUpdate()
|
||||
{
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
if (PointerManager.Instance.Interacting != _lastMouseInteracting)
|
||||
{
|
||||
//TODO animate go down
|
||||
GateBar.SetActive(!PointerManager.Instance.Interacting);
|
||||
MovingBar.SetActive(PointerManager.Instance.MovingObject);
|
||||
_lastMouseInteracting = PointerManager.Instance.Interacting;
|
||||
}
|
||||
}
|
||||
private void UpdateUI()
|
||||
{
|
||||
if (PointerManager.Instance.Interacting != _lastMouseInteracting)
|
||||
{
|
||||
//TODO animate go down
|
||||
GateBar.SetActive(!PointerManager.Instance.Interacting);
|
||||
MovingBar.SetActive(PointerManager.Instance.MovingObject);
|
||||
_lastMouseInteracting = PointerManager.Instance.Interacting;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateGateBar()
|
||||
{
|
||||
@@ -144,6 +144,6 @@ namespace UntitledLogicGame.UI
|
||||
_gateBarSateList[category].SetActive(category == GateBarState);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using UnityEngine.EventSystems;
|
||||
|
||||
namespace UntitledLogicGame.UI
|
||||
{
|
||||
public class UIToolbarButton : MonoBehaviour, IPointerDownHandler
|
||||
public class UIToolbarButton : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
|
||||
+40
-40
@@ -6,57 +6,57 @@ using Random = UnityEngine.Random;
|
||||
|
||||
namespace UntitledLogicGame
|
||||
{
|
||||
public static class Utils
|
||||
{
|
||||
#region String Utils
|
||||
public static class Utils
|
||||
{
|
||||
#region String Utils
|
||||
|
||||
public static string RandomString(int length)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[Random.Range(0, s.Length)]).ToArray());
|
||||
}
|
||||
public static string RandomString(int length)
|
||||
{
|
||||
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
return new string(Enumerable.Repeat(chars, length)
|
||||
.Select(s => s[Random.Range(0, s.Length)]).ToArray());
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Bool Utils
|
||||
#region Bool Utils
|
||||
|
||||
public static bool[][] AllBoolArrayValues(int length)
|
||||
{
|
||||
public static bool[][] AllBoolArrayValues(int length)
|
||||
{
|
||||
if (length == 0)
|
||||
return new bool[0][];
|
||||
var count = (int)Math.Pow(2, length);
|
||||
return new ArrayList[count].Select((v, i) => i.ToBoolArray(length)).ToArray();
|
||||
}
|
||||
var count = (int)Math.Pow(2, length);
|
||||
return new ArrayList[count].Select((v, i) => i.ToBoolArray(length)).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Utils
|
||||
#region Unity Utils
|
||||
|
||||
public static void RandomName(string prefix, GameObject obj)
|
||||
{
|
||||
obj.name = $"{prefix}_{RandomString(5)}";
|
||||
}
|
||||
public static void RandomName(string prefix, GameObject obj)
|
||||
{
|
||||
obj.name = $"{prefix}_{RandomString(5)}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static bool[] ToBoolArray(this int value, int length)
|
||||
{
|
||||
var str = Convert.ToString(value, 2).PadLeft(length, '0');
|
||||
return str.Select((x) => x == '1').ToArray();
|
||||
}
|
||||
public static class Extensions
|
||||
{
|
||||
public static bool[] ToBoolArray(this int value, int length)
|
||||
{
|
||||
var str = Convert.ToString(value, 2).PadLeft(length, '0');
|
||||
return str.Select((x) => x == '1').ToArray();
|
||||
}
|
||||
|
||||
public static int ToInt(this bool[] array)
|
||||
{
|
||||
return array.Select((v, i) => (v ? 1 : 0) << (array.Length - i - 1)).Sum();
|
||||
}
|
||||
public static int ToInt(this bool[] array)
|
||||
{
|
||||
return array.Select((v, i) => (v ? 1 : 0) << (array.Length - i - 1)).Sum();
|
||||
}
|
||||
|
||||
public static Vector3 Round(this Vector3 v)
|
||||
{
|
||||
return new Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z));
|
||||
}
|
||||
}
|
||||
public static Vector3 Round(this Vector3 v)
|
||||
{
|
||||
return new Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,116 +5,116 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class Anchor : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class Anchor : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
public string Name;
|
||||
public bool IsInput;
|
||||
public float ScaleIncrease;
|
||||
public Vector2 Orientation;
|
||||
public string Name;
|
||||
public bool IsInput;
|
||||
public float ScaleIncrease;
|
||||
public Vector2 Orientation;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public List<Cable> Cables { get; set; }
|
||||
public Gate Gate { get; set; }
|
||||
public bool Activated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsInput)
|
||||
return Cables.Count > 0 && Cables.First().Activated;
|
||||
else
|
||||
return _activated;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!IsInput)
|
||||
_activated = value;
|
||||
}
|
||||
}
|
||||
public bool Hovering { get; internal set; }
|
||||
public List<Cable> Cables { get; set; }
|
||||
public Gate Gate { get; set; }
|
||||
public bool Activated
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsInput)
|
||||
return Cables.Count > 0 && Cables.First().Activated;
|
||||
else
|
||||
return _activated;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!IsInput)
|
||||
_activated = value;
|
||||
}
|
||||
}
|
||||
public bool Hovering { get; internal set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Vector3 _scale;
|
||||
private SpriteRenderer _sprite;
|
||||
private bool _activated;
|
||||
private bool? _lastActivated;
|
||||
private Vector3 _scale;
|
||||
private SpriteRenderer _sprite;
|
||||
private bool _activated;
|
||||
private bool? _lastActivated;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
Gate = GetComponentInParent<Gate>();
|
||||
Utils.RandomName($"{Gate.GateType}_{Name}", gameObject);
|
||||
_scale = transform.localScale;
|
||||
_sprite = GetComponent<SpriteRenderer>();
|
||||
Cables = new List<Cable>();
|
||||
Orientation = Orientation.normalized;
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
Gate = GetComponentInParent<Gate>();
|
||||
Utils.RandomName($"{Gate.GateType}_{Name}", gameObject);
|
||||
_scale = transform.localScale;
|
||||
_sprite = GetComponent<SpriteRenderer>();
|
||||
Cables = new List<Cable>();
|
||||
Orientation = Orientation.normalized;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
transform.localScale = _scale * ScaleIncrease;
|
||||
GameManager.Instance.CurrentAnchor = this;
|
||||
Hovering = true;
|
||||
}
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
transform.localScale = _scale * ScaleIncrease;
|
||||
GameManager.Instance.CurrentAnchor = this;
|
||||
Hovering = true;
|
||||
}
|
||||
|
||||
private void OnMouseExit()
|
||||
{
|
||||
transform.localScale = _scale;
|
||||
if (Equals(GameManager.Instance.CurrentAnchor))
|
||||
GameManager.Instance.CurrentAnchor = null;
|
||||
Hovering = false;
|
||||
}
|
||||
private void OnMouseExit()
|
||||
{
|
||||
transform.localScale = _scale;
|
||||
if (Equals(GameManager.Instance.CurrentAnchor))
|
||||
GameManager.Instance.CurrentAnchor = null;
|
||||
Hovering = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach(var cable in Cables)
|
||||
{
|
||||
Destroy(cable.gameObject);
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach(var cable in Cables)
|
||||
{
|
||||
Destroy(cable.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
if (IsInput)
|
||||
return Cables.Any(c => c.HasInputAnchor(target));
|
||||
else
|
||||
return Gate.HasInputAnchor(target);
|
||||
}
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
if (IsInput)
|
||||
return Cables.Any(c => c.HasInputAnchor(target));
|
||||
else
|
||||
return Gate.HasInputAnchor(target);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateState()
|
||||
{
|
||||
if (_lastActivated == null || _lastActivated != Activated)
|
||||
{
|
||||
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
}
|
||||
}
|
||||
private void UpdateState()
|
||||
{
|
||||
if (_lastActivated == null || _lastActivated != Activated)
|
||||
{
|
||||
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+153
-153
@@ -5,183 +5,183 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class Cable : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class Cable : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public Anchor StartAnchor
|
||||
{
|
||||
get => _startAnchor;
|
||||
set
|
||||
{
|
||||
_startAnchor = value;
|
||||
if (value.IsInput)
|
||||
{
|
||||
if (value.Cables.Count > 0)
|
||||
Destroy(value.Cables.First().gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Anchor EndAnchor
|
||||
{
|
||||
get => _endAnchor;
|
||||
set
|
||||
{
|
||||
if (!value.IsInput)
|
||||
{
|
||||
_endAnchor = StartAnchor;
|
||||
StartAnchor = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endAnchor = value;
|
||||
}
|
||||
public Anchor StartAnchor
|
||||
{
|
||||
get => _startAnchor;
|
||||
set
|
||||
{
|
||||
_startAnchor = value;
|
||||
if (value.IsInput)
|
||||
{
|
||||
if (value.Cables.Count > 0)
|
||||
Destroy(value.Cables.First().gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Anchor EndAnchor
|
||||
{
|
||||
get => _endAnchor;
|
||||
set
|
||||
{
|
||||
if (!value.IsInput)
|
||||
{
|
||||
_endAnchor = StartAnchor;
|
||||
StartAnchor = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_endAnchor = value;
|
||||
}
|
||||
|
||||
if (StartAnchor.HasInputAnchor(EndAnchor))
|
||||
{
|
||||
// Loop detected
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartAnchor.Cables.Add(this);
|
||||
if (EndAnchor.Cables.Count > 0)
|
||||
Destroy(EndAnchor.Cables.First().gameObject);
|
||||
EndAnchor.Cables = new List<Cable> { this };
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool Activated => StartAnchor != null && !StartAnchor.IsInput && StartAnchor.Activated;
|
||||
public Vector3 FallbackEndPos { get; set; }
|
||||
if (StartAnchor.HasInputAnchor(EndAnchor))
|
||||
{
|
||||
// Loop detected
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
StartAnchor.Cables.Add(this);
|
||||
if (EndAnchor.Cables.Count > 0)
|
||||
Destroy(EndAnchor.Cables.First().gameObject);
|
||||
EndAnchor.Cables = new List<Cable> { this };
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool Activated => StartAnchor != null && !StartAnchor.IsInput && StartAnchor.Activated;
|
||||
public Vector3 FallbackEndPos { get; set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Vector3 _lastStartPos;
|
||||
private Vector3 _lastEndPos;
|
||||
private Anchor _startAnchor;
|
||||
private Anchor _endAnchor;
|
||||
private LineRenderer _line;
|
||||
private bool? _lastActivated;
|
||||
private Vector3 _lastStartPos;
|
||||
private Vector3 _lastEndPos;
|
||||
private Anchor _startAnchor;
|
||||
private Anchor _endAnchor;
|
||||
private LineRenderer _line;
|
||||
private bool? _lastActivated;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
_line = GetComponent<LineRenderer>();
|
||||
Utils.RandomName("Cable", gameObject);
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
_line = GetComponent<LineRenderer>();
|
||||
Utils.RandomName("Cable", gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateColor();
|
||||
UpdateLine();
|
||||
}
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateColor();
|
||||
UpdateLine();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if(StartAnchor != null)
|
||||
StartAnchor.Cables.Remove(this);
|
||||
if (EndAnchor != null)
|
||||
EndAnchor.Cables.Remove(this);
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
if(StartAnchor != null)
|
||||
StartAnchor.Cables.Remove(this);
|
||||
if (EndAnchor != null)
|
||||
EndAnchor.Cables.Remove(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
return StartAnchor.HasInputAnchor(target);
|
||||
}
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
return StartAnchor.HasInputAnchor(target);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateColor()
|
||||
{
|
||||
if (_lastActivated == null || _lastActivated != Activated)
|
||||
{
|
||||
_line.startColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_line.endColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
}
|
||||
}
|
||||
private void UpdateColor()
|
||||
{
|
||||
if (_lastActivated == null || _lastActivated != Activated)
|
||||
{
|
||||
_line.startColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_line.endColor = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLine()
|
||||
{
|
||||
if (StartAnchor != null)
|
||||
{
|
||||
var startPos = StartAnchor.transform.position;
|
||||
var endPos = EndAnchor == null ? FallbackEndPos : EndAnchor.transform.position;
|
||||
private void UpdateLine()
|
||||
{
|
||||
if (StartAnchor != null)
|
||||
{
|
||||
var startPos = StartAnchor.transform.position;
|
||||
var endPos = EndAnchor == null ? FallbackEndPos : EndAnchor.transform.position;
|
||||
|
||||
if (startPos != _lastStartPos || endPos != _lastEndPos)
|
||||
{
|
||||
if (EndAnchor == null)
|
||||
{
|
||||
_line.positionCount = 2;
|
||||
_line.SetPosition(0, startPos);
|
||||
_line.SetPosition(1, endPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
var startOr = StartAnchor.Orientation;
|
||||
var endOr = StartAnchor.Orientation;
|
||||
if (startPos != _lastStartPos || endPos != _lastEndPos)
|
||||
{
|
||||
if (EndAnchor == null)
|
||||
{
|
||||
_line.positionCount = 2;
|
||||
_line.SetPosition(0, startPos);
|
||||
_line.SetPosition(1, endPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
var startOr = StartAnchor.Orientation;
|
||||
var endOr = StartAnchor.Orientation;
|
||||
|
||||
_line.positionCount = 4;
|
||||
_line.SetPosition(0, startPos);
|
||||
_line.positionCount = 4;
|
||||
_line.SetPosition(0, startPos);
|
||||
|
||||
if (Mathf.Abs(startOr.x) > 0)
|
||||
{
|
||||
if (Mathf.Abs(endOr.x) > 0)
|
||||
{
|
||||
var middle = (startPos.x + endPos.x) / 2;
|
||||
_line.SetPosition(1, new Vector3(middle, startPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(middle, endPos.y, startPos.z));
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mathf.Abs(endOr.x) > 0)
|
||||
{
|
||||
var middle = (startPos.y + endPos.y) / 2;
|
||||
_line.SetPosition(1, new Vector3(startPos.x, middle, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(endPos.x, middle, startPos.z));
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z));
|
||||
}
|
||||
}
|
||||
if (Mathf.Abs(startOr.x) > 0)
|
||||
{
|
||||
if (Mathf.Abs(endOr.x) > 0)
|
||||
{
|
||||
var middle = (startPos.x + endPos.x) / 2;
|
||||
_line.SetPosition(1, new Vector3(middle, startPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(middle, endPos.y, startPos.z));
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.SetPosition(1, new Vector3(startPos.x, endPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(startPos.x, endPos.y, startPos.z));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mathf.Abs(endOr.x) > 0)
|
||||
{
|
||||
var middle = (startPos.y + endPos.y) / 2;
|
||||
_line.SetPosition(1, new Vector3(startPos.x, middle, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(endPos.x, middle, startPos.z));
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.SetPosition(1, new Vector3(endPos.x, startPos.y, startPos.z));
|
||||
_line.SetPosition(2, new Vector3(endPos.x, startPos.y, startPos.z));
|
||||
}
|
||||
}
|
||||
|
||||
_line.SetPosition(3, endPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.positionCount = 0;
|
||||
}
|
||||
}
|
||||
_line.SetPosition(3, endPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_line.positionCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,106 +6,106 @@ using UntitledLogicGame.Workspace.Gates;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class Gate : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class Gate : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
public GateType GateType;
|
||||
public GateType GateType;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public IEnumerable<Anchor> Anchors
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_anchors == null)
|
||||
_anchors = GetComponentsInChildren<Anchor>().ToList();
|
||||
return _anchors;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Anchor> InputAnchors => Anchors.Where(a => a.IsInput);
|
||||
public IEnumerable<Anchor> OutputAnchors => Anchors.Where(a => !a.IsInput);
|
||||
public BoxCollider2D Box {
|
||||
get
|
||||
{
|
||||
if (_box == null)
|
||||
_box = GetComponentInChildren<BoxCollider2D>();
|
||||
return _box;
|
||||
}
|
||||
}
|
||||
public GateSprite Sprite
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_sprite == null)
|
||||
_sprite = GetComponentInChildren<GateSprite>();
|
||||
return _sprite;
|
||||
}
|
||||
}
|
||||
public GateDefinition Definition
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_definition == null)
|
||||
_definition = GateDefinition.Get(GateType, this);
|
||||
return _definition;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Anchor> Anchors
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_anchors == null)
|
||||
_anchors = GetComponentsInChildren<Anchor>().ToList();
|
||||
return _anchors;
|
||||
}
|
||||
}
|
||||
public IEnumerable<Anchor> InputAnchors => Anchors.Where(a => a.IsInput);
|
||||
public IEnumerable<Anchor> OutputAnchors => Anchors.Where(a => !a.IsInput);
|
||||
public BoxCollider2D Box {
|
||||
get
|
||||
{
|
||||
if (_box == null)
|
||||
_box = GetComponentInChildren<BoxCollider2D>();
|
||||
return _box;
|
||||
}
|
||||
}
|
||||
public GateSprite Sprite
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_sprite == null)
|
||||
_sprite = GetComponentInChildren<GateSprite>();
|
||||
return _sprite;
|
||||
}
|
||||
}
|
||||
public GateDefinition Definition
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_definition == null)
|
||||
_definition = GateDefinition.Get(GateType, this);
|
||||
return _definition;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private IEnumerable<Anchor> _anchors;
|
||||
private GateDefinition _definition;
|
||||
private int _lastState = -1;
|
||||
private BoxCollider2D _box;
|
||||
private GateSprite _sprite;
|
||||
private IEnumerable<Anchor> _anchors;
|
||||
private GateDefinition _definition;
|
||||
private int _lastState = -1;
|
||||
private BoxCollider2D _box;
|
||||
private GateSprite _sprite;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName(Definition.Name, gameObject);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName(Definition.Name, gameObject);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
return !Definition.HasState && (
|
||||
InputAnchors.Contains(target) ||
|
||||
InputAnchors.Any(a => a.HasInputAnchor(target))
|
||||
);
|
||||
}
|
||||
public bool HasInputAnchor(Anchor target)
|
||||
{
|
||||
return !Definition.HasState && (
|
||||
InputAnchors.Contains(target) ||
|
||||
InputAnchors.Any(a => a.HasInputAnchor(target))
|
||||
);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateState()
|
||||
{
|
||||
var state = Definition.GetState(this).ToInt();
|
||||
if (state != _lastState)
|
||||
{
|
||||
Definition.Compute(this);
|
||||
_lastState = state;
|
||||
}
|
||||
}
|
||||
private void UpdateState()
|
||||
{
|
||||
var state = Definition.GetState(this).ToInt();
|
||||
if (state != _lastState)
|
||||
{
|
||||
Definition.Compute(this);
|
||||
_lastState = state;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,53 +6,53 @@ using UntitledLogicGame.Workspace.Gates;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class GateSprite : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
public class GateSprite : MonoBehaviour
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public bool Hovering { get; internal set; }
|
||||
public bool Hovering { get; internal set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Gate _gate;
|
||||
private Gate _gate;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_gate = GetComponentInParent<Gate>();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
_gate = GetComponentInParent<Gate>();
|
||||
}
|
||||
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
GameManager.Instance.CurrentGate = _gate;
|
||||
Hovering = true;
|
||||
}
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
GameManager.Instance.CurrentGate = _gate;
|
||||
Hovering = true;
|
||||
}
|
||||
|
||||
private void OnMouseExit()
|
||||
{
|
||||
if (_gate.Equals(GameManager.Instance.CurrentGate))
|
||||
GameManager.Instance.CurrentGate = null;
|
||||
Hovering = false;
|
||||
}
|
||||
private void OnMouseExit()
|
||||
{
|
||||
if (_gate.Equals(GameManager.Instance.CurrentGate))
|
||||
GameManager.Instance.CurrentGate = null;
|
||||
Hovering = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +1,35 @@
|
||||
namespace UntitledLogicGame.Workspace.Gates
|
||||
{
|
||||
public enum GateType
|
||||
{
|
||||
// 000 - Technical
|
||||
None = 000,
|
||||
// 100 - I/O
|
||||
IN = 100,
|
||||
OUT = 110,
|
||||
// 200 - Basic
|
||||
BUF = 200,
|
||||
AND = 210,
|
||||
OR = 220,
|
||||
XOR = 230,
|
||||
public enum GateType
|
||||
{
|
||||
// 000 - Technical
|
||||
None = 000,
|
||||
// 100 - I/O
|
||||
IN = 100,
|
||||
OUT = 110,
|
||||
// 200 - Basic
|
||||
BUF = 200,
|
||||
AND = 210,
|
||||
OR = 220,
|
||||
XOR = 230,
|
||||
NOT = 240,
|
||||
NAND = 250,
|
||||
NOR = 260,
|
||||
XNOR = 270,
|
||||
// 300 - Latches
|
||||
SRLatch = 300,
|
||||
JKLatch = 310,
|
||||
DLatch = 320,
|
||||
// 500 - Flip-Flops
|
||||
SRFlipFlop = 400,
|
||||
JKFlipFlop = 410,
|
||||
DFlipFlop = 420,
|
||||
TFlipFlop = 430,
|
||||
// 500 - Arithmetic
|
||||
HalfAdd = 500,
|
||||
FullAdd = 510,
|
||||
HalfSub = 520,
|
||||
FullSub = 530,
|
||||
JKLatch = 310,
|
||||
DLatch = 320,
|
||||
// 500 - Flip-Flops
|
||||
SRFlipFlop = 400,
|
||||
JKFlipFlop = 410,
|
||||
DFlipFlop = 420,
|
||||
TFlipFlop = 430,
|
||||
// 500 - Arithmetic
|
||||
HalfAdd = 500,
|
||||
FullAdd = 510,
|
||||
HalfSub = 520,
|
||||
FullSub = 530,
|
||||
// 600 - Data
|
||||
Mux = 610,
|
||||
Demux = 620,
|
||||
|
||||
@@ -3,77 +3,77 @@ using System.Linq;
|
||||
|
||||
namespace UntitledLogicGame.Workspace.Gates
|
||||
{
|
||||
public class InputState : State
|
||||
{
|
||||
public InputState(IEnumerable<bool> args) : base(args) { }
|
||||
public class InputState : State
|
||||
{
|
||||
public InputState(IEnumerable<bool> args) : base(args) { }
|
||||
|
||||
public InputState(params bool[] args) : base(args) { }
|
||||
public InputState(params bool[] args) : base(args) { }
|
||||
|
||||
public InputState(int len) : base(len) { }
|
||||
}
|
||||
public InputState(int len) : base(len) { }
|
||||
}
|
||||
|
||||
public class OutputState : State
|
||||
{
|
||||
public OutputState(IEnumerable<bool> args) : base(args) { }
|
||||
{
|
||||
public OutputState(IEnumerable<bool> args) : base(args) { }
|
||||
|
||||
public OutputState(params bool[] args) : base(args) { }
|
||||
public OutputState(params bool[] args) : base(args) { }
|
||||
|
||||
public OutputState(int len) : base(len) { }
|
||||
}
|
||||
public OutputState(int len) : base(len) { }
|
||||
}
|
||||
|
||||
public abstract class State
|
||||
{
|
||||
internal int Length => values.Length;
|
||||
{
|
||||
internal int Length => values.Length;
|
||||
|
||||
internal bool[] values;
|
||||
internal bool[] values;
|
||||
|
||||
public State(IEnumerable<bool> args)
|
||||
{
|
||||
values = args.ToArray();
|
||||
}
|
||||
public State(IEnumerable<bool> args)
|
||||
{
|
||||
values = args.ToArray();
|
||||
}
|
||||
|
||||
public State(params bool[] args)
|
||||
{
|
||||
values = args;
|
||||
}
|
||||
public State(params bool[] args)
|
||||
{
|
||||
values = args;
|
||||
}
|
||||
|
||||
public State(int len)
|
||||
{
|
||||
values = new bool[len];
|
||||
}
|
||||
public State(int len)
|
||||
{
|
||||
values = new bool[len];
|
||||
}
|
||||
|
||||
public bool this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= values.Length)
|
||||
return false;
|
||||
return values[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index >= 0 && index < values.Length)
|
||||
values[index] = value;
|
||||
}
|
||||
}
|
||||
public bool this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= values.Length)
|
||||
return false;
|
||||
return values[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index >= 0 && index < values.Length)
|
||||
values[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is State state && Enumerable.SequenceEqual(values, state.values);
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is State state && Enumerable.SequenceEqual(values, state.values);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//https://stackoverflow.com/questions/6832139/gethashcode-from-booleans-only
|
||||
int hash = 17;
|
||||
for (int index = 0; index < values.Length; index++)
|
||||
hash = hash * 23 + values[index].GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
//https://stackoverflow.com/questions/6832139/gethashcode-from-booleans-only
|
||||
int hash = 17;
|
||||
for (int index = 0; index < values.Length; index++)
|
||||
hash = hash * 23 + values[index].GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Join(",", values);
|
||||
}
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Join(",", values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,62 +5,62 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class InputGate : Gate
|
||||
{
|
||||
#region Unity Properties
|
||||
public class InputGate : Gate
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public bool State { get; set; }
|
||||
public bool State { get; set; }
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Anchor OutputAnchor {
|
||||
get
|
||||
{
|
||||
if (_outputAnchor == null)
|
||||
_outputAnchor = Anchors.First(g => g.Name == "Q");
|
||||
return _outputAnchor;
|
||||
}
|
||||
}
|
||||
private Anchor _outputAnchor;
|
||||
private Anchor OutputAnchor {
|
||||
get
|
||||
{
|
||||
if (_outputAnchor == null)
|
||||
_outputAnchor = Anchors.First(g => g.Name == "Q");
|
||||
return _outputAnchor;
|
||||
}
|
||||
}
|
||||
private Anchor _outputAnchor;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName("Input", gameObject);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName("Input", gameObject);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
private void UpdateState()
|
||||
{
|
||||
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
|
||||
{
|
||||
State = !State;
|
||||
OutputAnchor.Activated = State;
|
||||
}
|
||||
}
|
||||
private void UpdateState()
|
||||
{
|
||||
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
|
||||
{
|
||||
State = !State;
|
||||
OutputAnchor.Activated = State;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,53 +5,53 @@ using UnityEngine;
|
||||
|
||||
namespace UntitledLogicGame.Workspace
|
||||
{
|
||||
public class OutputGate : Gate
|
||||
{
|
||||
#region Unity Properties
|
||||
public class OutputGate : Gate
|
||||
{
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
#region Public Properties
|
||||
|
||||
public bool State {
|
||||
get
|
||||
{
|
||||
return InputAnchor.Activated;
|
||||
}
|
||||
}
|
||||
public bool State {
|
||||
get
|
||||
{
|
||||
return InputAnchor.Activated;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
#region Private Properties
|
||||
|
||||
private Anchor InputAnchor {
|
||||
get
|
||||
{
|
||||
if (_inputAnchor == null)
|
||||
_inputAnchor = Anchors.First(g => g.Name == "A");
|
||||
return _inputAnchor;
|
||||
}
|
||||
}
|
||||
private Anchor _inputAnchor;
|
||||
private Anchor InputAnchor {
|
||||
get
|
||||
{
|
||||
if (_inputAnchor == null)
|
||||
_inputAnchor = Anchors.First(g => g.Name == "A");
|
||||
return _inputAnchor;
|
||||
}
|
||||
}
|
||||
private Anchor _inputAnchor;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
#region Unity Methods
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName("Output", gameObject);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
Utils.RandomName("Output", gameObject);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user