public DialogGraphGUI() { menuDict.Add("New Statement", delegate { DialogStatement statement = ScriptableObject.CreateInstance <DialogStatement>(); statement.Id = idGenerator; statement.NodeRect = new Rect(lastMousePos, new Vector2(160, 50)); statement.name = "New Statement " + statement.Id; Nodes().Add(statement); AssetDatabase.AddObjectToAsset(statement, host.ActiveContainer); statement.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(host.ActiveContainer)); }); nodeDict.Add("Add Transition", delegate(object data) { startNode = Nodes().First(n => n.Id == (int)data); controllMode = ControllMode.DRAWEDGE; }); nodeDict.Add("Mark as Starting Node", delegate(object data) { host.ActiveContainer.StartingPoint = Nodes().First(n => n.Id == (int)data); }); nodeDict.Add("Delete Node", delegate(object data) { Edges().RemoveAll(e => e.From.Id == (int)data || e.To.Id == (int)data); Nodes().RemoveAll(n => n.Id == (int)data); }); edgeDict.Add("Delete Edge", delegate(object data) { var ed = Edges().First(e => e.Id == (int)data); ed.From.Answers.Remove(ed); }); }
public void ChangeControllMode() { //It's just a temp solution,We should change it in PanelManager. if (controllMode == ControllMode.Button) { controllMode = ControllMode.OneFinger; SetVisible(GUIControls, false); } else { controllMode = ControllMode.Button; SetVisible(GUIControls, true); } }
private void OnNodeEvent(DialogStatement node) { var rect = node.NodeRect; if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.ContextClick) { EditorContextMenu(nodeDict, node.Id); Event.current.Use(); } if (Event.current.type == EventType.MouseDown) { if (controllMode == ControllMode.DRAWEDGE && startNode != node) { DialogAnswer answer = ScriptableObject.CreateInstance <DialogAnswer>(); answer.From = startNode; answer.To = node; answer.Id = idGenerator; startNode.Answers.Add(answer); AssetDatabase.AddObjectToAsset(answer, host.ActiveContainer); answer.hideFlags = HideFlags.HideInHierarchy; answer.parent = host.ActiveContainer; AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(host.ActiveContainer)); controllMode = ControllMode.SELECTION; } else { selectedNode = node; Selection.activeObject = node; } Event.current.Use(); } } if (selectedNode != node) { return; } if (Event.current.type == EventType.MouseDrag) { node.NodeRect.position += Event.current.delta; EditorUtility.SetDirty(node); Event.current.Use(); } }
private void HandleMouseActions() { Vector2 v = Event.current.mousePosition; if (Event.current.button == 0 && Event.current.type == EventType.mouseDrag && selectedNode == null && selectedEdge == null) { if (Vector2.Distance(lastMousePos, v) < 50) { ScrollPosition -= Event.current.delta; Event.current.Use(); } lastMousePos = v; } if (Event.current.type != EventType.MouseDown) { return; } selectedNode = null; selectedEdge = null; foreach (var edge in Edges()) { if (Vector2.Distance(v, ((edge.BoundingRect.size + edge.BoundingRect.position) * 0.5f)) > (edge.BoundingRect.position - edge.BoundingRect.size).magnitude * 0.5f || !(PointdistanceToLine(Event.current.mousePosition, edge.BoundingRect.position, edge.BoundingRect.size) < 6)) { continue; } selectedEdge = edge; Selection.activeObject = edge; Event.current.Use(); if (Event.current.button == 1) { // rightclick: EditorContextMenu(edgeDict, edge.Id); } return; } if (Event.current.button > 1) { return; } Selection.activeObject = null; if (Event.current.button == 1) { // rightclick: if (controllMode == ControllMode.DRAWEDGE) { controllMode = ControllMode.SELECTION; } else { EditorContextMenu(menuDict); } } Event.current.Use(); }
void FixedUpdate() { if (!isLocalPlayer) { return; } #region Movement and camera controlling Vector3 pos = gameObject.transform.position; if (playerHuman == null) { Debug.LogWarning("PlayerController class not attached"); return; } if (Input.GetButtonDown("Change Mode")) { if (CurrentMode == ControllMode.Shooting) { CurrentMode = ControllMode.Interaction; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; prevOffset = Vector3.zero; } else { CurrentMode = ControllMode.Shooting; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; } } if (CurrentMode == ControllMode.Interaction) { float forward = Input.GetAxis("Vertical"); float turn = Input.GetAxis("Horizontal"); rig.velocity = rig.gameObject.transform.up * playerHuman.WalkSpeed * forward; rig.angularVelocity = -turn * playerHuman.RotationSpeed; } if (CurrentMode == ControllMode.Shooting) { float forward = Input.GetAxis("Vertical"); float turn = Input.GetAxis("Horizontal"); Ray ray = cameraObject.GetComponent <Camera>() .ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0)); var point = ray.GetPoint(-CameraRelativePosition.z); if (Vector3.Distance(gameObject.transform.position, point) >= ShootingModeMovementThresold) { rig.velocity = rig.gameObject.transform.up * playerHuman.WalkSpeed * forward; } else { rig.velocity = Vector2.zero; } float angle = Mathf.Atan2(point.y - pos.y, point.x - pos.x); rig.gameObject.transform.rotation = Quaternion.Euler(0, 0, angle * Mathf.Rad2Deg - 90); } if (CurrentMode == ControllMode.Interaction) { cameraObject.transform.position = pos + CameraRelativePosition; } if (CurrentMode == ControllMode.Shooting) { float move_x = Input.GetAxis("Mouse X"); float move_y = Input.GetAxis("Mouse Y"); prevOffset += new Vector3(move_x, move_y, 0) * AimSensitivity; cameraObject.transform.position = new Vector3(pos.x, pos.y, CameraRelativePosition.z) + prevOffset; } #endregion if (CurrentMode == ControllMode.Interaction) { #region Picking and puting items if (Ui != null && !Ui.IsCursorUponUi() && Ui.UnderCursor("Items") != null && Ui.UnderCursor("Items").layer != LayerMask.NameToLayer("Hidden")) { ManipulatedItem = Ui.UnderCursor("Items"); } else { ManipulatedItem = null; } if (Input.GetMouseButtonDown(0) && ManipulatedItem != null && !Ui.IsCursorUponUi()) { PickItem(ManipulatedItem); } if (Input.GetMouseButtonDown(0) && ManipulatedItem == null && Ui.IsCursorUponUi() == false) { if (ActiveHand == HandSide.Left && playerHuman.Equipment[Equipment.EquipmentSlot.LeftHand] != null) { PutItem(ActiveHand); } if (ActiveHand == HandSide.Right && playerHuman.Equipment[Equipment.EquipmentSlot.RightHand] != null) { PutItem(ActiveHand); } } #endregion ShowMovablesGui(); } #region Shooting // Getting a weapon instance if (CurrentMode == ControllMode.Shooting) { Weapon weapon = null; switch (ActiveHand) { case HandSide.Left: if (playerHuman.Equipment[0] == null) { // TODO Weapon-free behavior break; } weapon = playerHuman.Equipment[0].GetComponent <Weapon>(); if (weapon == null) { // TODO Item is not a weapon issue break; } weapon = playerHuman.Equipment[0].GetComponent <Weapon>(); break; case HandSide.Right: if (playerHuman.Equipment[1] == null) { // TODO Weapon-free behavior break; } weapon = playerHuman.Equipment[1].GetComponent <Weapon>(); if (weapon == null) { // TODO Item is not a weapon issue break; } weapon = playerHuman.Equipment[1].GetComponent <Weapon>(); break; default: throw new ArgumentOutOfRangeException(); } // TODO Shooting if (weapon != null) { if (weapon.ReadyToShoot && Input.GetAxis("Fire and usage") == 1f) { weapon.CmdUse(gameObject); } } } #endregion }