named anchors
This commit is contained in:
@@ -81,10 +81,7 @@ namespace CompuLogic
|
||||
_currentGate = gate;
|
||||
_currentGateDelta = MousePos - _currentGate.transform.position;
|
||||
_currentGateInitialPos = created ? (Vector3?)null : _currentGate.transform.position;
|
||||
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
renderer.sortingLayerName = "moving";
|
||||
}
|
||||
_currentGate.SetSortingLayerRecursive("moving");
|
||||
}
|
||||
|
||||
public void RequestDelete()
|
||||
@@ -203,10 +200,7 @@ namespace CompuLogic
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var renderer in _currentGate.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
renderer.sortingLayerName = "default";
|
||||
}
|
||||
_currentGate.SetSortingLayerRecursive("default");
|
||||
_currentGate.transform.position = _currentGate.transform.position.Round();
|
||||
var currentBox = _currentGate.Box;
|
||||
if (FindObjectsOfType<Gate>()
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace CompuLogic.UI
|
||||
get
|
||||
{
|
||||
if(_maxSize == null)
|
||||
_maxSize = GameManager.Instance.GateSprites.Select(s => Math.Max(s.rect.width, s.rect.height)).Max();
|
||||
_maxSize = GameManager.Instance.GateSprites.Select(s => Mathf.Max(s.rect.width, s.rect.height)).Max();
|
||||
return _maxSize.Value;
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace CompuLogic.UI
|
||||
{
|
||||
var sprite = value.GetComponentInChildren<SpriteRenderer>().sprite;
|
||||
Image.sprite = sprite;
|
||||
Image.GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 100 * Math.Max(sprite.rect.width, sprite.rect.height) / MaxSize);
|
||||
Image.GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 100 * Mathf.Max(sprite.rect.width, sprite.rect.height) / MaxSize);
|
||||
gameObject.name = "UI_" + value.GateType.ToString();
|
||||
Text.text = value.UIName;
|
||||
}
|
||||
|
||||
@@ -58,5 +58,32 @@ namespace CompuLogic
|
||||
{
|
||||
return new Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z));
|
||||
}
|
||||
|
||||
public static void SetSortingLayerRecursive(this UnityEngine.Component obj, string sortingLayer)
|
||||
{
|
||||
if(obj.TryGetComponent<SpriteRenderer>(out var renderer))
|
||||
{
|
||||
renderer.SetSortingLayerRecursive(sortingLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var subrenderer in obj.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
subrenderer.SetSortingLayerRecursive(sortingLayer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void SetSortingLayerRecursive(this SpriteRenderer renderer, string sortingLayer)
|
||||
{
|
||||
foreach (var subrenderer in renderer.GetComponentsInChildren<SpriteRenderer>())
|
||||
{
|
||||
if(subrenderer != renderer)
|
||||
{
|
||||
subrenderer.SetSortingLayerRecursive(sortingLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CompuLogic.Workspace
|
||||
@@ -13,6 +14,8 @@ namespace CompuLogic.Workspace
|
||||
public bool IsInput;
|
||||
public float ScaleIncrease;
|
||||
public Vector2 Orientation;
|
||||
public float TextSpace;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -24,25 +27,60 @@ namespace CompuLogic.Workspace
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsInput)
|
||||
return Cables.Count > 0 && Cables.First().Activated;
|
||||
else
|
||||
return _activated;
|
||||
if (IsInput)
|
||||
return Cables.Count > 0 && Cables.First().Activated;
|
||||
else
|
||||
return _activated;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!IsInput)
|
||||
_activated = value;
|
||||
if (!IsInput)
|
||||
_activated = value;
|
||||
}
|
||||
}
|
||||
public bool Hovering { get; internal set; }
|
||||
public bool ShowName
|
||||
{
|
||||
set
|
||||
{
|
||||
Text.gameObject.SetActive(value);
|
||||
if (value)
|
||||
{
|
||||
Text.text = Name;
|
||||
var rect = Text.GetComponent<RectTransform>();
|
||||
rect.localRotation = (Mathf.Abs(Orientation.y) > Mathf.Epsilon) ? Quaternion.AngleAxis(90f, Vector3.forward) : Quaternion.identity;
|
||||
rect.localPosition = new Vector3(Orientation.x, Orientation.y, 0f) * TextSpace;
|
||||
Text.alignment = (Orientation.x < -Mathf.Epsilon || Orientation.y < -Mathf.Epsilon) ? TextAlignmentOptions.MidlineRight : TextAlignmentOptions.MidlineLeft;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public TextMeshPro Text
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_text == null)
|
||||
_text = GetComponentInChildren<TextMeshPro>(true);
|
||||
return _text;
|
||||
}
|
||||
}
|
||||
public SpriteRenderer Sprite
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_sprite == null)
|
||||
_sprite = GetComponentInChildren<SpriteRenderer>();
|
||||
return _sprite;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private Vector3 _scale;
|
||||
private SpriteRenderer _sprite;
|
||||
private TextMeshPro _text;
|
||||
private Vector3 _scale;
|
||||
private bool _activated;
|
||||
private bool? _lastActivated;
|
||||
|
||||
@@ -55,8 +93,7 @@ namespace CompuLogic.Workspace
|
||||
{
|
||||
Gate = GetComponentInParent<Gate>();
|
||||
Utils.RandomName($"{Gate.GateType}_{Name}", gameObject);
|
||||
_scale = transform.localScale;
|
||||
_sprite = GetComponent<SpriteRenderer>();
|
||||
_scale = Sprite.transform.localScale;
|
||||
Cables = new List<Cable>();
|
||||
Orientation = Orientation.normalized;
|
||||
}
|
||||
@@ -69,16 +106,16 @@ namespace CompuLogic.Workspace
|
||||
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
transform.localScale = _scale * ScaleIncrease;
|
||||
Sprite.transform.localScale = _scale * ScaleIncrease;
|
||||
GameManager.Instance.CurrentAnchor = this;
|
||||
Hovering = true;
|
||||
}
|
||||
|
||||
private void OnMouseExit()
|
||||
{
|
||||
transform.localScale = _scale;
|
||||
Sprite.transform.localScale = _scale;
|
||||
if (Equals(GameManager.Instance.CurrentAnchor))
|
||||
GameManager.Instance.CurrentAnchor = null;
|
||||
GameManager.Instance.CurrentAnchor = null;
|
||||
Hovering = false;
|
||||
}
|
||||
|
||||
@@ -88,7 +125,7 @@ namespace CompuLogic.Workspace
|
||||
{
|
||||
foreach(var cable in Cables)
|
||||
{
|
||||
Destroy(cable.gameObject);
|
||||
Destroy(cable.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,8 +151,8 @@ namespace CompuLogic.Workspace
|
||||
{
|
||||
if (_lastActivated == null || _lastActivated != Activated)
|
||||
{
|
||||
_sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
Sprite.color = Activated ? GameManager.Instance.ActivatedColor : GameManager.Instance.DeadColor;
|
||||
_lastActivated = Activated;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +66,15 @@ namespace CompuLogic.Workspace
|
||||
gate.GateType = (GateType)key;
|
||||
|
||||
gate.UIName = string.IsNullOrEmpty(item.Name) ? gate.GateType.ToString() : item.Name;
|
||||
|
||||
|
||||
var showAnchorNames = false;
|
||||
|
||||
if (string.IsNullOrEmpty(item.Skin))
|
||||
{
|
||||
gate.Sprite.Renderer.sprite = _defaultSprite;
|
||||
gate.Sprite.Renderer.drawMode = SpriteDrawMode.Sliced;
|
||||
gate.Sprite.Renderer.size = new Vector2(item.Width, item.Height);
|
||||
showAnchorNames = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -87,6 +90,7 @@ namespace CompuLogic.Workspace
|
||||
var anchor = Instantiate(inputAnchor.Big ? _bigAnchorPrefab : _anchorPrefab);
|
||||
anchor.transform.parent = prefab.transform;
|
||||
inputAnchor.ConfigAnchor(anchor);
|
||||
anchor.ShowName = showAnchorNames;
|
||||
anchor.IsInput = true;
|
||||
}
|
||||
}
|
||||
@@ -98,6 +102,7 @@ namespace CompuLogic.Workspace
|
||||
var anchor = Instantiate(outputAnchor.Big ? _bigAnchorPrefab : _anchorPrefab);
|
||||
anchor.transform.parent = prefab.transform;
|
||||
outputAnchor.ConfigAnchor(anchor);
|
||||
anchor.ShowName = showAnchorNames;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
#region 300 - Latches
|
||||
|
||||
internal class SRLatchGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "SR Latch";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "S", "R" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -114,8 +113,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class JKLatchGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "JK Latch";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "J", "K" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -136,8 +134,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class DLatchGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "D Latch";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "D", "E" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -158,8 +155,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
#region 400 - Flip-Flops
|
||||
|
||||
internal class SRFlipFlopGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "SR Flip-Flop";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "S", "R" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -182,8 +178,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class JKFlipFlopGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "JK Flip-Flop";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "J", "K" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -208,8 +203,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class DFlipFlopGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "D Flip-Flop";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "D" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -228,8 +222,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class TFlipFlopGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "T Flip-Flop";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "T" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q", "Q̅" };
|
||||
|
||||
@@ -253,8 +246,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
#region 500 - Arithmetic
|
||||
|
||||
internal class HalfAddGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "Half Add.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "A", "B" };
|
||||
public override string[] Outputs { get; } = new string[] { "S", "C" };
|
||||
|
||||
@@ -271,8 +263,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class FullAddGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "Full Add.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "A", "B", "Cɪ" };
|
||||
public override string[] Outputs { get; } = new string[] { "S", "Cᴏ" };
|
||||
|
||||
@@ -290,8 +281,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class HalfSubGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "Half Sub.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "A", "B" };
|
||||
public override string[] Outputs { get; } = new string[] { "S", "C" };
|
||||
|
||||
@@ -309,8 +299,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class FullSubGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "Full Add.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "A", "B", "Cɪ" };
|
||||
public override string[] Outputs { get; } = new string[] { "S", "Cᴏ" };
|
||||
|
||||
@@ -369,8 +358,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class Mux2bGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "2bits Mux";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "E", "S₀", "S₁", "D₀", "D₁", "D₂", "D₃" };
|
||||
public override string[] Outputs { get; } = new string[] { "Y" };
|
||||
|
||||
@@ -396,8 +384,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class Demux2bGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "2bits Demux";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "E", "S₀", "S₁", "D" };
|
||||
public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁", "Y₂", "Y₃" };
|
||||
|
||||
@@ -418,8 +405,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class Enc2b4bGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "2b/4b Enc.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "D₀", "D₁" };
|
||||
public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁", "Y₂", "Y₃" };
|
||||
|
||||
@@ -438,8 +424,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class Dec4b2bGate : StatelessGateDefinition
|
||||
{
|
||||
public new string Name => "4b/2b Dec.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "D₀", "D₁", "D₂", "D₃"};
|
||||
public override string[] Outputs { get; } = new string[] { "Y₀", "Y₁" };
|
||||
|
||||
@@ -462,8 +447,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
#region 700 - Registers
|
||||
|
||||
internal class SISO4bGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "4bits SISO";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "D" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q" };
|
||||
|
||||
@@ -490,8 +474,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class SIPO4bGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "4bits SIPO";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "D" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁", "Q₂", "Q₃" };
|
||||
|
||||
@@ -518,8 +501,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class PIPO4bGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "4bits PIPO";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "D₀", "D₁", "D₂", "D₃" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁", "Q₂", "Q₃" };
|
||||
|
||||
@@ -553,8 +535,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
#region 800 - Counters
|
||||
|
||||
internal class Counter2bGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "2bits Count.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "RST" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁" };
|
||||
|
||||
@@ -585,8 +566,7 @@ namespace CompuLogic.Workspace.Gates
|
||||
}
|
||||
|
||||
internal class Counter4bGate : StatefulGateDefinition
|
||||
{
|
||||
public new string Name => "4bits Count.";
|
||||
{
|
||||
public override string[] Inputs { get; } = new string[] { "CLK", "RST" };
|
||||
public override string[] Outputs { get; } = new string[] { "Q₀", "Q₁", "Q₂", "Q₃" };
|
||||
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace CompuLogic
|
||||
{
|
||||
public class OverlineCorrector : MonoBehaviour
|
||||
{
|
||||
public Vector3 SubTextOffset;
|
||||
|
||||
#region Unity Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
#endregion
|
||||
|
||||
#region Unity Methods
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
var subText = GetComponentInChildren<TMP_SubMesh>();
|
||||
if(subText != null && Mathf.Abs(subText.transform.localPosition.magnitude) < Mathf.Epsilon)
|
||||
subText.transform.localPosition = SubTextOffset;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 644a8320ad8f9c54db2cf3119c482ab8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user