// Update is called once per frame void Update() { Ray myray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(myray, out hit)) { if (hit.distance < 2f && hit.transform.GetComponent <Item>()) { Item item = hit.transform.GetComponent <Item>(); UIManager.Instance.SetPickUpTextInfo(item.ItemInfo.nameItem + "\n lewy przycisk myszy!"); if (Input.GetMouseButtonDown(0)) { if (items.Count == 0 && item.ItemInfo.currentItem == Equipment.Outfit || items.Count > 0 && items.Peek().currentItem == item.ItemInfo.previousItem) { item.Action(); items.Push(item.ItemInfo); UIManager.Instance.SetErrorPickUpMessage(""); } else { UIManager.Instance.SetErrorPickUpMessage(item.ItemInfo.errorMessage); } } } else { UIManager.Instance.SetPickUpTextInfo(""); } } }
/// <summary> /// Uses the item in the left hand if something is equipped. /// </summary> public void UseItemInSlot(EquipSlot slot) { Item Item = Drive.GetSlot(slot); if (Item != null && Item.Action != null && Character != null) { Item.Action(Character); } }
private void Interact() { if (_itemBeingInteracted != null) { _itemBeingInteracted.Action(); } else Debug.Log("INTERACTION FAILED"); }
public override bool ProcessKeyboard(Keyboard info) { MenuOption CurrentlySelectedOption = new MenuOption() { Id = 0 }; if (Menu.Any(x => x.Selected)) { CurrentlySelectedOption = Menu.Where(x => x.Selected).FirstOrDefault(); } if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) || info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.W)) { if (Menu.Any(x => x.Id == CurrentlySelectedOption.Id - 1)) { Menu.Where(x => x.Id == CurrentlySelectedOption.Id - 1).FirstOrDefault().Selected = true; CurrentlySelectedOption.Selected = false; } } if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Down) || info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.S)) { if (Menu.Any(x => x.Id == CurrentlySelectedOption.Id + 1)) { Menu.Where(x => x.Id == CurrentlySelectedOption.Id + 1).FirstOrDefault().Selected = true; CurrentlySelectedOption.Selected = false; } } if (info.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter) && Menu.Any(x => x.Selected)) { CurrentlySelectedOption.Action(); return(true); } foreach (var Item in Menu) { if (info.IsKeyPressed(Item.Key)) { Item.Action(); CurrentlySelectedOption.Selected = false; Item.Selected = true; return(true); } } if (CurrentlySelectedOption != Menu.Where(x => x.Selected).FirstOrDefault()) { RenderMenuOptions(); return(true); } return(false); }
public static void DoWork(Func <object, object> action, Action <object> completed, object state, string title, string text) { Application.Current.MainWindow.Cursor = Cursors.Wait; ((UIElement)(Application.Current.MainWindow.Content)).IsEnabled = false; lock (queueLock) { queue.Enqueue(new Item() { Action = action, Completed = completed, State = state, Title = title, Text = text, }); if (queue.Count > 1) { return; } finishedTasks = 0; } shownLock.WaitOne(); window = null; taskCompleted = false; shownLock.ReleaseMutex(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (s, e) => { bool empty = false; do { Item item = null; double?progress = null; lock (queueLock) { if (queue.Count <= 0) { break; } item = queue.Peek(); if (!(queue.Count == 1 && finishedTasks == 0)) { progress = 1.0 * (finishedTasks + 1) / (queue.Count + finishedTasks); } } Application.Current.Dispatcher.BeginInvoke((Action <string, string, double?>) UpdateUI, item.Title, item.Text, progress); var result = item.Action(item.State); Application.Current.Dispatcher.BeginInvoke(item.Completed, result); lock (queueLock) { queue.Dequeue(); empty = (queue.Count <= 0); finishedTasks++; } }while (!empty); }; worker.RunWorkerCompleted += (s, e) => { Application.Current.Dispatcher.BeginInvoke((Action)HideWaitWindow); Application.Current.MainWindow.Cursor = Cursors.Arrow; ((UIElement)(Application.Current.MainWindow.Content)).IsEnabled = true; }; worker.RunWorkerAsync(); BackgroundWorker timer = new BackgroundWorker(); timer.DoWork += (s, e) => { Thread.Sleep(TimeSpan.FromSeconds(1)); shownLock.WaitOne(); Application.Current.Dispatcher.BeginInvoke((Action)ShowWaitWindow); shownLock.ReleaseMutex(); }; timer.RunWorkerAsync(); }
// Helper methods void useItem() { equippedItem.Action(equipPoint); }
private void OnClick() { Item.Action(); }
/// <summary> /// This function run the action of the item /// </summary> public void UseItem() { item.Action(); }