private void MakeConnection(ClickableObject aOb, ClickableObject bOb) { Debug.Assert(newCable.objectFrom == aOb.transform, "MakeConnection: start connector doesn't match"); newCable.objectTo = bOb.transform; newCable.UpdateConnection(); bool shortCircuit = false, madeConnection = false; if (int.TryParse(aOb.transform.parent.name, out int idA) && int.TryParse(bOb.transform.parent.name, out int idB)) { bool isP1 = (aOb.name == "TerminalPositive"); bool isP2 = (bOb.name == "TerminalPositive"); madeConnection = true; if (idA != idB) { Connected newCon = new Connected(idA, isP1, idB, isP2, newCable); if (!connectedList.Contains(newCon)) { connectedList.Add(newCon); } // Otherwise let it dangle } else { shortCircuit = true; // Same battery means short shortCircuitFx.SetActive(true); Destroy(newCable); } connectedList.Sort(); } else { Debug.LogError("Evaluating connectors without valid parent IDs convertable to integers"); } if (madeConnection) // only if connection made, otherwise continue to look for endpoint { newCable = null; } if (shortCircuit) { ShortCircuit(idA); } }
private void Select(ClickableObject obj) { ClickableObject prevSelected = selected; selected = obj; if (selected) { if (prevSelected) { if (prevSelected == selected) { Destroy(newCable); newCable = null; } else { MakeConnection(prevSelected, selected); } prevSelected = selected = null; } else { // Start of connection newCable = Instantiate(cableTemplate, connections) as Cable; newCable.gameObject.SetActive(true); newCable.objectFrom = obj.transform; beamLengthAtTerminal = Vector3.Distance(obj.transform.position, ControllerInput.Instance.ControllerPosition); } } foreach (ClickableObject s in selectables) { s.Select(s == selected); } }
private void OnTerminalPointerExit(ClickableObject c) { }