public void ConnectWire() { Debug.Log("Connect wire: " + transform.parent.transform.parent.name + "." + name); // If no wire is currently being connected if (connectingWire == null) { //Create new wire wire = Instantiate(wirePrefab, wirePrefab.transform.position, Quaternion.identity).GetComponent <WireController>(); //Create a static reference to new wire connectingWire = wire.GetComponent <WireController>(); // Connect wire and reserve this pin from further connections wire = connectingWire.SetConnection(this); } // If a wire is being connected else if (connectingWire != null) { // Connect this wire to the second pin wire = connectingWire.SetConnection(this); // If connection was made if (wire != null) { // Remove static reference to wire, so a new wire can be created connectingWire = null; } } }
public void MoveWire() { if (wire.RemoveConnection(this)) { connectingWire = wire; wire = null; } }
void OnTriggerExit(Collider other) { WireController comp = other.gameObject.GetComponent <WireController>(); if (comp != null && touchedControls.Contains(comp)) { touchedControls.Remove(comp); } }
// Update is called once per frame void Update() { if (!Application.isPlaying) { if (wire == null) { wire = GetComponent <WireController>(); } wire.InitConnections(); wire.Updater(Camera.main.ScreenToWorldPoint(Input.mousePosition)); // wire.UpdatePosition(Camera.main.ScreenToWorldPoint(Input.mousePosition)); } }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Floor")) { return; } WireController comp = other.gameObject.GetComponent <WireController>(); if (comp != null) { touchedControls.Add(comp); CheckIsElectrified(); } }
protected override void onRemoveCallback(UnityEditorInternal.ReorderableList list) { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this pin? " + list.index, "Yes", "No")) { var data = _node.Weights[list.index]; var output = _node.PinCollection.Get(data.OutputName); if (output != null) { WireController.Disconnect(output); } _node.Variables.RemoveByName(data.VariableName); _node.PinCollection.Remove(data.OutputName); _node.Weights.Remove(data); _node.HasChanges = true; } }
protected override void onRemoveCallback(UnityEditorInternal.ReorderableList list) { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this answer?", "Yes", "No")) { var element = _node.Answers[list.index]; var input = _node.PinCollection.Get(element.InputName); var output = _node.PinCollection.Get(element.OutputName); if (input != null) { WireController.Disconnect(input); } if (output != null) { WireController.Disconnect(output); } _node.PinCollection.Remove(element.InputName); _node.PinCollection.Remove(element.OutputName); _node.Variables.RemoveByName(element.VariableName); ReorderableList.defaultBehaviours.DoRemoveButton(list); } }
private void Start() { wireController = this.transform.parent.GetComponent <WireController>(); }
void OnSceneGUI(SceneView scene) { if (Tools.current != oldTool) { toolEnabled = false; Repaint(); } oldTool = Tools.current; Event e = Event.current; if (toolEnabled && !Application.isPlaying) { ToolController.SelectedTool = ToolController.ToolType.WIRE; if (e.type == EventType.MouseDown && e.button == 0) { Debug.Log("Click"); LayerMask mask = LayerMask.GetMask("Connector"); Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); RaycastHit2D[] hit2d = Physics2D.RaycastAll(ray.origin, ray.direction, 10000, mask); foreach (var hit in hit2d) { Debug.Log("Ray hit: " + hit.collider.name); if (wire == null) { PinController pin = hit.collider.GetComponent <PinController>(); Undo.RecordObject(pin, "ConnectedWire"); pin.ConnectWire(); EditorUtility.SetDirty(pin); wire = PinController.connectingWire; Undo.FlushUndoRecordObjects(); // GameObject clone = PrefabUtility.InstantiatePrefab(wirePrefab as GameObject) as GameObject; // wire = clone.GetComponent<WireController>(); // PinController pin = hit.collider.GetComponent<PinController>(); // wire.SetConnection(pin); } else { PinController pin = hit.collider.GetComponent <PinController>(); Undo.RecordObject(pin, "ConnectedWire"); pin.ConnectWire(); EditorUtility.SetDirty(pin); wire = PinController.connectingWire; Undo.FlushUndoRecordObjects(); } } e.Use(); } if (wire != null) { wire.Updater(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin); } } else { if (wire != null) { DestroyImmediate(wire.gameObject); } } }