internal void DoDuplicateNode(string id, Vector3 position) { var old = GameObject.Find(id); var oldNode = (old.GetComponent(typeof(NodePhysX)) as NodePhysX); var links = GameObject.FindGameObjectsWithTag("link").Select(p => p.GetComponent <Link>()); links = links.Where(p => p.source == old || p.target == old).ToArray(); var createAction = new CreateNode() { name = oldNode.Text, position = SVector3.FromVector3(position) }; DoAction(createAction); foreach (var l in links) { DoAction(new CreateLink() { SourceId = l.target == old ? l.source.name : createAction.nodeId, TargetId = l.target == old ? createAction.nodeId : l.source.name }); } DoAction(new CreateLink() { SourceId = old.name, TargetId = createAction.nodeId }); }
void Update() { //animation if (curves[0] != null) { transform.position = new Vector3(curves[0].Evaluate(Time.time), curves[1].Evaluate(Time.time), curves[2].Evaluate(Time.time)); transform.rotation = Quaternion.Euler(new Vector3(curves[3].Evaluate(Time.time), curves[4].Evaluate(Time.time), curves[5].Evaluate(Time.time))); CoordControl.text = "Pos: " + transform.position.ToString() + "\nRot: " + transform.rotation.eulerAngles.ToString(); } //input Vector3 move = new Vector3(); Vector3 rotate = new Vector3(); if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { rotate.y = Input.GetAxis("Horizontal") * speed * Time.deltaTime; move.y = Input.GetAxis("Vertical") * speed * Time.deltaTime; } else { move.x = Input.GetAxis("Horizontal") * speed * Time.deltaTime; move.z = Input.GetAxis("Vertical") * speed * Time.deltaTime; } //adjust speed with mouse wheel move.z += Input.GetAxis("Mouse ScrollWheel") * 15; if (speed < 5) { speed = 5; } movementSpeed.text = "Flyspeed: " + speed; move = transform.TransformDirection(move); var oldRot = transform.rotation.eulerAngles; var newRot = (transform.rotation * Quaternion.Euler(rotate)).eulerAngles; if (oldRot.Equals(newRot) && move.Equals(Vector3.zero)) { return; } graphController.DoAction(new MoveCamera() { newPos = SVector3.FromVector3(transform.position + move), oldPos = SVector3.FromVector3(transform.position), newRot = SVector3.FromVector3(newRot), oldRot = SVector3.FromVector3(oldRot), duration = 0 }); }
public void PaintModeController() { if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && Input.GetKeyDown(KeyCode.Z)) { graphControl.UndoAction(); } if (Input.GetKeyDown(KeyCode.F2)) { if (graphControl.SelectedNode != null) { graphControl.Select(graphControl.SelectedNode, true); } } if (Input.GetKeyDown(KeyCode.F3)) { if (graphControl.SelectedNode != null) { //delete node graphControl.DoAction(new DeleteNode() { nodeId = graphControl.SelectedNode.name }); } } if (Input.GetKeyDown(KeyCode.F1)) { if (graphControl.SelectedNode != null) { var worldpos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, lazyZ)); graphControl.DoDuplicateNode(graphControl.SelectedNode.name, worldpos); } } // Paint only if not over Panel if (!gameCtrlUI.PanelIsPointeroverPanel(Input.mousePosition)) { // Check what was clicked on when MouseButtonDown if (Input.GetMouseButtonDown(0)) { btnDownPointerPos = Input.mousePosition; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Detected MouseButtonDown. mousePosition: x: " + btnDownPointerPos.x + " y: " + btnDownPointerPos.y + " z: " + btnDownPointerPos.z); } if (graphControl.IsRecording()) { //Ray ray = Camera.main.ScreenPointToRay(btnDownPointerPos); //hitObjBtnDown = null; //if (Physics.Raycast(ray, out hitInfoBtnDown)) btnDownHitGo = null; btnDownHitGo = gameCtrlHelper.ScreenPointToRaySingleHitWrapper(Camera.main, btnDownPointerPos); if (btnDownHitGo != null) { //hitObjBtnDown = hitInfoBtnDown.collider.gameObject; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonDown: Ray did hit. On Object: " + btnDownHitGo); } paintedLinkObject = Instantiate(paintedLinkPrefab, new Vector3(0, 0, 0), Quaternion.identity) as paintedLink; paintedLinkObject.name = "paintedLink"; //paintedLinkObject.sourceObj = hitObjBtnDown; //paintedLinkObject.targetVector = hitObjBtnDown.transform.position; paintedLinkObject.sourceObj = btnDownHitGo; paintedLinkObject.targetVector = btnDownHitGo.transform.position; } } } if (Input.GetMouseButton(0) && paintedLinkObject != null && graphControl.IsRecording()) { if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Entered GetMouseButton, about to start paintlink()"); } Vector3 mousePosWorld = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, lazyZ)); if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Painting Link. Current mousePosition is: (" + Input.mousePosition.x + ", " + Input.mousePosition.y + ", " + lazyZ + "). Converted worldPosition is: " + mousePosWorld); } paintedLinkObject.targetVector = mousePosWorld; } if (Input.GetMouseButtonUp(0)) { btnUpPointerPos = Input.mousePosition; if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": Detected MouseButtonUp. mousePosition: x: " + btnUpPointerPos.x + " y: " + btnUpPointerPos.y + " z: " + btnUpPointerPos.z); } if (graphControl.PaintMode) { // Ray ray = Camera.main.ScreenPointToRay(btnUpPointerPos); // hitObjBtnUp = null; // if (Physics.Raycast(ray, out hitInfoBtnUp)) btnUpHitGo = null; btnUpHitGo = gameCtrlHelper.ScreenPointToRaySingleHitWrapper(Camera.main, btnUpPointerPos); string newNodeId = null; if (btnUpHitGo == null && graphControl.IsRecording()) { //create new node if release on empty space Vector3 clickPosWorld = Camera.main.ScreenToWorldPoint(new Vector3(btnUpPointerPos.x, btnUpPointerPos.y, lazyZ)); newNodeId = "node_" + graphControl.NextId; graphControl.DoAction(new CreateNode() { nodeId = newNodeId, position = SVector3.FromVector3(clickPosWorld) }); btnUpHitGo = GameObject.Find(newNodeId); graphControl.SelectById(newNodeId, true); } if (btnUpHitGo != null) { // If on ButtonDown a node was rayhit, and on ButtonUp a different nodes, we just want to link these nodes together if (btnDownHitGo != null) { if (btnDownHitGo != btnUpHitGo && graphControl.IsRecording()) { if (verbose) { Debug.Log(this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + ": GetMouseButtonUp: ButtonDown node and a differing ButtonUp was selected. This linking the ButtonDown node: " + btnDownHitGo + " with the ButtonUp node: " + btnUpHitGo); } graphControl.DoAction(new CreateLink() { SourceId = btnDownHitGo.name, TargetId = btnUpHitGo.name }); } else { //select node graphControl.Select(btnUpHitGo.GetComponent(typeof(NodePhysX)) as NodePhysX); } } } if (paintedLinkObject != null) { GameObject.Destroy(paintedLinkObject.gameObject); } } } } }