void Start() { if (!skipSetup) { skipSetup = true; int maxTotalPortCount = Mathf.Max(TotalInPortCount, TotalOutPortCount); bool useCompactFormat = false; if (maxTotalPortCount >= 4) { useCompactFormat = true; rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, ((3 * maxTotalPortCount - 1) * in0.RectTransform.sizeDelta.y) / 2); } SetupPorts(InPortCount, Chip.inputPorts, useCompactFormat, ref in0, ref inR, ref inPorts); SetupPorts(OutPortCount, Chip.outputPorts, useCompactFormat, ref out0, ref outR, ref outPorts); PortUi nullPort = null; SetupPorts(Chip.statePort != null ? 1 : 0, new Port[] { Chip.statePort }, false, ref state, ref nullPort, ref statePorts); Sprite sprite = GetSprite(); if (sprite != null) { icon.sprite = sprite; } } }
private void SetupPorts(int portCount, Port[] ports, ref PortUi port0Ui, ref PortUi[] portUis) { DebugUtils.Assert(ports != null); DebugUtils.Assert(portUis == null); portUis = new PortUi[ports.Length]; if (portCount <= 0) { Destroy(port0Ui.gameObject); } else { portUis[0] = port0Ui; port0Ui.nodeUi = this; port0Ui.Port = ports[0]; RectTransform tr0 = port0Ui.RectTransform; Vector2 offset = new Vector2(0, tr0.sizeDelta.y * -3 / 2); for (int i = 1; i < portCount; i++) { PortUi portUi = Instantiate <PortUi>(port0Ui, transform); portUis[i] = portUi; portUi.nodeUi = this; portUi.Port = ports[i]; portUi.RectTransform.anchoredPosition = tr0.anchoredPosition + i * offset; portUi.PortIndex = i; } } port0Ui = null; }
public void OnEndDrag(PointerEventData eventData) { if (draggingLine == null) { return; } RRCSManager.Instance.selectionManager.SelectionEnabled = true; PortUi dstPort = null; foreach (GameObject go in eventData.hovered) { dstPort = go.GetComponent <PortUi>(); if (dstPort != null) { break; } } PortUi srcPort = draggingLine.sourcePortUi ?? this; draggingLine.Disconnect(); draggingLine = null; if (dstPort != null && (dstPort.nodeUi == null || !dstPort.nodeUi.IsSidebarNode)) { srcPort.port.Connect(dstPort.port); } }
protected override void OnMovedToWorld() { if (!skipSetup) { return; } DebugUtils.Assert(inPorts == null); inPorts = new PortUi[TotalInPortCount]; outPorts = new PortUi[0]; statePorts = new PortUi[0]; int inPortIndex = 0; foreach (Transform child in transform) { PortUi port = child.GetComponent <PortUi>(); if (port == null) { continue; } port.nodeUi = this; if (port.isInput) { int index = port.IsReset ? InPortCount : (inPortIndex++); DebugUtils.Assert(inPorts[index] == null); inPorts[index] = port; port.Port = Node.inputPorts[index]; } } DebugUtils.Assert(!Array.Exists(inPorts, element => element == null)); }
void Start() { DebugUtils.Assert(inPorts == null); DebugUtils.Assert(outPorts == null); inPorts = new PortUi[0]; outPorts = new PortUi[3]; statePorts = new PortUi[0]; int portIndex = 0; foreach (Transform child in transform) { if (centerUi == null) { centerUi = child.GetComponent <RRButtonCenterUi>(); } PortUi port = child.GetComponent <PortUi>(); if (port == null) { continue; } port.nodeUi = this; port.Port = button.outputPorts[portIndex]; port.PortIndex = portIndex; outPorts[portIndex] = port; portIndex++; } DebugUtils.Assert(portIndex == 3); button.ButtonTextChanged += Button_ButtonTextChanged; Button_ButtonTextChanged(button, button.ButtonText); }
public void OnBeginDrag(PointerEventData eventData) { if (eventData.button != 0) { return; } if (draggingLine != null) { return; } if (nodeUi && nodeUi.IsSidebarNode) { return; } PortUi srcPort = this; if (isInput && HasLines) { //connectedLines should contain exactly 1 entry. ConnectionUi entry = connectedLines[0]; entry.Disconnect(); srcPort = entry.sourcePortUi; } draggingLine = Instantiate(connectionPrefab, linesContainer).GetComponent <ConnectionUi>(); DebugUtils.Assert(draggingLine != null); draggingLine.sourcePortUi = srcPort; draggingLine.SetVirtualTargetPosition(Center); draggingLine.UpdateColors(); RRCSManager.Instance.selectionManager.SelectionEnabled = false; }
private static void Port_Disconnected(Connection connection) { PortUi senderUi = GetUi(connection.SourcePort); PortUi otherUi = GetUi(connection.TargetPort); bool destroy = senderUi.RemoveConnection(GetUi(connection), false); otherUi.RemoveConnection(GetUi(connection), destroy); }
private static void Port_Connected(Connection connection) { PortUi sourceUi = GetUi(connection.SourcePort); PortUi targetUi = GetUi(connection.TargetPort); ConnectionUi connectionUi = sourceUi.AddConnection(sourceUi, targetUi, connection, null); targetUi.AddConnection(sourceUi, targetUi, connection, connectionUi); }
private void SetupPorts(int portCount, Port[] ports, bool useCompactFormat, ref PortUi port0UI, ref PortUi resetPortUi, ref PortUi[] portUIs) { DebugUtils.Assert(ports != null); DebugUtils.Assert(portUIs == null); portUIs = new PortUi[ports.Length]; if (portCount <= 0) { Destroy(port0UI.gameObject); } else { portUIs[0] = port0UI; port0UI.nodeUi = this; port0UI.Port = ports[0]; RectTransform tr0 = port0UI.RectTransform; if (useCompactFormat) { tr0.anchoredPosition = new Vector2(tr0.anchoredPosition.x, -tr0.sizeDelta.y / 2); if (resetPortUi != null) { ((RectTransform)resetPortUi.transform).anchoredPosition = new Vector2(0, tr0.sizeDelta.y / 2); } } Vector2 offset = new Vector2(0, tr0.sizeDelta.y * -3 / 2); for (int i = 1; i < portCount; i++) { PortUi portUi = Instantiate <PortUi>(port0UI, transform); portUIs[i] = portUi; portUi.nodeUi = this; portUi.Port = ports[i]; portUi.RectTransform.anchoredPosition = tr0.anchoredPosition + i * offset; portUi.PortIndex = i; } } if (resetPortUi != null) { if (HasReset) { portUIs[portCount] = resetPortUi; resetPortUi.nodeUi = this; resetPortUi.Port = ports[portCount]; } else { Destroy(resetPortUi.gameObject); } } port0UI = null; resetPortUi = null; }
internal ConnectionUi AddConnection(PortUi sourceUi, PortUi targetUi, Connection connection, ConnectionUi connectionUi) { if (connectionUi == null) { connectionUi = Instantiate(connectionPrefab, linesContainer).GetComponent <ConnectionUi>(); connectionUi.sourcePortUi = sourceUi; connectionUi.targetPortUi = targetUi; connectionUi.Connection = connection; } connectedLines.Add(connectionUi); connectionUi.UpdatePositions(); connectionUi.UpdateColors(); return(connectionUi); }
void Start() { DebugUtils.Assert(inPorts == null); DebugUtils.Assert(outPorts == null); inPorts = new PortUi[3]; outPorts = new PortUi[0]; statePorts = new PortUi[0]; int portIndex = 0; foreach (Transform child in transform) { Image img = child.GetComponent <Image>(); if (img != null) { if (lightCone == null) { lightCone = img; continue; } else if (lamp == null) { lamp = img; continue; } } PortUi port = child.GetComponent <PortUi>(); if (port == null) { continue; } port.nodeUi = this; port.Port = stageLight.inputPorts[portIndex]; port.PortIndex = portIndex; inPorts[portIndex] = port; portIndex++; } DebugUtils.Assert(lightCone != null); DebugUtils.Assert(lamp != null); DebugUtils.Assert(portIndex == 3); stageLight.ColorChanged += StageLight_ColorChanged; StageLight_ColorChanged(stageLight, stageLight.color); }
void Start() { inPorts = new PortUi[4]; outPorts = new PortUi[0]; statePorts = new PortUi[0]; for (int i = 0; i < portsUis.Length; ++i) { PortUi portUi = portsUis[i]; portUi.nodeUi = this; portUi.Port = Node.inputPorts[i]; portUi.PortIndex = i; inPorts[i] = portUi; } sign.DisplayTextChanged += Sign_DisplayTextChanged; Sign_DisplayTextChanged(sign.DisplayText, sign.DisplayTextIsLimited); }
public static void Unregister(PortUi portUi) { if (portUi.nodeUi == null || portUi.nodeUi.IsSidebarNode) { return; } portUi.Port.Connected -= Port_Connected; portUi.Port.Disconnected -= Port_Disconnected; foreach (Connection c in portUi.Port.connections) { if (ports.ContainsKey(c.SourcePort) && ports.ContainsKey(c.TargetPort)) { Port_Disconnected(c); } } ports.Remove(portUi.Port); }
public static void Register(PortUi portUi) { if (portUi.nodeUi != null && portUi.nodeUi.IsSidebarNode) { return; } if (ports.ContainsKey(portUi.Port)) { return; } ports.Add(portUi.Port, portUi); portUi.Port.Connected += Port_Connected; portUi.Port.Disconnected += Port_Disconnected; portUi.TextActive = showPortLabels; foreach (Connection c in portUi.Port.connections) { if (ports.ContainsKey(c.SourcePort) && ports.ContainsKey(c.TargetPort)) { Port_Connected(c); } } }