refactoring again
This commit is contained in:
@@ -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
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user