refactoring again

This commit is contained in:
klemek
2020-12-17 13:47:47 +01:00
parent 8a6a1b0465
commit 947e847d3b
8 changed files with 227 additions and 167 deletions
+10 -5
View File
@@ -64,11 +64,7 @@ namespace UntitledLogicGame.Workspace
// Update is called once per frame
private void Update()
{
if (_lastActivated == null || _lastActivated != Activated)
{
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
_lastActivated = Activated;
}
UpdateState();
}
private void OnMouseEnter()
@@ -110,6 +106,15 @@ namespace UntitledLogicGame.Workspace
#region Private Methods
private void UpdateState()
{
if (_lastActivated == null || _lastActivated != Activated)
{
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
_lastActivated = Activated;
}
}
#endregion
}
}
+77 -61
View File
@@ -56,11 +56,14 @@ namespace UntitledLogicGame.Workspace
}
}
public bool Activated => StartAnchor != null && !StartAnchor.IsInput && StartAnchor.Activated;
public Vector3 FallbackEndPos { get; set; }
#endregion
#region Private Properties
private Vector3 _lastStartPos;
private Vector3 _lastEndPos;
private Anchor _startAnchor;
private Anchor _endAnchor;
private LineRenderer _line;
@@ -81,67 +84,8 @@ namespace UntitledLogicGame.Workspace
// Update is called once per frame
private void Update()
{
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;
}
if(StartAnchor != null)
{
if (EndAnchor == null)
{
_line.positionCount = 2;
_line.SetPosition(0, StartAnchor.transform.position);
_line.SetPosition(1, PointerManager.MousePos);
}
else
{
var startPos = StartAnchor.transform.position;
var startOr = StartAnchor.Orientation;
var endPos = EndAnchor.transform.position;
var endOr = StartAnchor.Orientation;
_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));
}
}
_line.SetPosition(3, endPos);
}
}
else
{
_line.positionCount = 0;
}
UpdateColor();
UpdateLine();
}
private void OnDestroy()
@@ -165,6 +109,78 @@ namespace UntitledLogicGame.Workspace
#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 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;
_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));
}
}
_line.SetPosition(3, endPos);
}
}
}
else
{
_line.positionCount = 0;
}
}
#endregion
}
+11 -6
View File
@@ -76,12 +76,7 @@ namespace UntitledLogicGame.Workspace
// Update is called once per frame
private void Update()
{
var state = Definition.GetState(this).ToInt();
if(state != _lastState)
{
Definition.Compute(this);
_lastState = state;
}
UpdateState();
}
#endregion
@@ -100,6 +95,16 @@ namespace UntitledLogicGame.Workspace
#region Private Methods
private void UpdateState()
{
var state = Definition.GetState(this).ToInt();
if (state != _lastState)
{
Definition.Compute(this);
_lastState = state;
}
}
#endregion
}
-6
View File
@@ -31,12 +31,6 @@ namespace UntitledLogicGame.Workspace
_gate = GetComponentInParent<Gate>();
}
// Update is called once per frame
private void Update()
{
}
private void OnMouseEnter()
{
GameManager.Instance.CurrentGate = _gate;
+11 -6
View File
@@ -38,13 +38,9 @@ namespace UntitledLogicGame.Workspace
Utils.RandomName("Input", gameObject);
}
private void FixedUpdate()
private void Update()
{
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
{
State = !State;
OutputAnchor.Activated = State;
}
UpdateState();
}
#endregion
@@ -55,6 +51,15 @@ namespace UntitledLogicGame.Workspace
#region Private Methods
private void UpdateState()
{
if ((Sprite.Hovering || OutputAnchor.Hovering) && PointerManager.Instance.DoubleClick())
{
State = !State;
OutputAnchor.Activated = State;
}
}
#endregion
}