formatting

This commit is contained in:
klemek
2020-12-19 17:21:06 +01:00
parent 63e8f2c5f6
commit 205a663e07
56 changed files with 1690 additions and 1297 deletions
+91 -91
View File
@@ -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
}
}