void OnSceneGUI() { Usable obj = target as Usable; Handles.color = Color.yellow; obj.range = Handles.RadiusHandle(Quaternion.identity, obj.transform.position, obj.range); }
/// <summary>Activates the specified usable.</summary> /// <param name="usable">The usable.</param> public void Use(Usable <TAction> usable) { if (usable.Enabled) { Activate(usable.Response, usable.Entity); } }
public static Task <ExitCode> CreateReport(ExcelReportOptions opts, TextWriter stdErr) { if (!File.Exists(opts.PathToHealthExportFile)) { return(Task.FromResult(ExitCode.ExportFileNotFound(opts.PathToHealthExportFile))); } if (File.Exists(opts.OutputFilename)) { return(Task.FromResult(ExitCode.ExportFileExists(opts.OutputFilename))); } var loader = Usable.Using(new StreamReader(opts.PathToHealthExportFile), reader => ZipUtilities.ReadArchive( reader.BaseStream, entry => entry.FullName == "apple_health_export/export.xml", entry => new XmlReaderExportLoader(entry.Open())) .FirstOrDefault()); var settings = GetSettings(opts, stdErr); var(package, customSheets) = GetCustomSheets(opts, stdErr); using (var excelFile = new ExcelPackage()) using (package) { var timeZone = DateTimeZone.ForOffset(Offset.FromHours(-5)); ExcelReport.BuildReport(loader.Records, loader.Workouts, excelFile.Workbook, settings, timeZone, customSheets); excelFile.SaveAs(new FileInfo(opts.OutputFilename)); } return(Task.FromResult(ExitCode.Success)); }
public Usable GetFocusedUsable(ArrayList unavailable = null) { var player = TankCharacterController.Instance; var minDistance = Mathf.Infinity; Usable minUsable = null; foreach (var usable in this.Usables) { if (usable == null || usable.gameObject == null || !usable.gameObject.activeInHierarchy) { continue; } if (usable.IsDisabled()) { continue; } if (unavailable != null && unavailable.Contains(usable)) { continue; } var distance = Vector3.Distance(usable.transform.position, player.transform.position); if (distance < usable.UseDistance && distance < minDistance) { minDistance = distance; minUsable = usable; } } return(minUsable); }
private void Update() { if (usable != null) { if (usable.active == false) { usable = null; } } //hold usable if (usable != null && usable.hold == false && Input.GetKeyDown(KeyCode.E)) { usable.Use(); } //not hold usable if (usable != null && usable.hold == true && Input.GetKey(KeyCode.E)) { usable.Use(); } if (usable == null) { useText.SetActive(false); } }
void ResetAbilities() { _boostAvailable = MAX_BOOST_SPEED; _boostCurrentCooldown = 0; _shockWaveCurrentCooldown = 0; storedItem = null; }
private void OnTriggerEnter(Collider other) { if (other.GetComponent <Usable>() != false) { if (other.GetComponent <Usable>().active == false) { return; } if (usable != null) { //is closer than current usable? if (Vector3.Distance(other.transform.position, transform.position) < Vector3.Distance(usable.transform.position, transform.position)) { usable = other.GetComponent <Usable>(); } } else { usable = other.GetComponent <Usable>(); } } useText.SetActive(true); }
void DropWeapon(Usable item) { currentWeapon = item.GetComponent <Weapon>(); WeaponImage.gameObject.SetActive(true); WeaponImage.sprite = item.icon; WeaponRemaining.fillAmount = 1; }
// Use this for initialization void Start() { if (isServer) { realUsable = gameObject.AddComponent <UsableServer>(); } }
private void AttemptToUse(Collider other) { Usable usable = other.gameObject.GetComponent <Usable>(); if (usable) { usable.Use(); } }
public static async Task <Usable> GetOne(int usableId) { Webservice webservice = new Webservice(BASE_URL); String methodRoute = "/"; Usable usable = new Usable(); usable = await webservice.HttpClientCaller <Usable>(USABLE_URL + methodRoute + usableId, usable); return(usable); }
public void ReleaseItem() { if (OnItemRelease != null) { OnItemRelease(storedItem); } storedItem.OnUsed -= ReleaseItem; storedItem = null; }
public void Test1() { int number = 0; var usable = Usable.Begin(() => number = 414, () => number = 416); using (usable) { Assert.Equal(414, number); } Assert.Equal(416, number); }
public void Start() { Usable usable = Tools.GetComponentAnywhere <Usable>(gameObject); if ((usable != null) && (nameText != null)) { nameText.text = usable.GetName(); } if (canvas != null) { canvas.enabled = false; } }
private void OnDeselectedUsable(Usable usable) { if (usableUnityUI != null) { usableUnityUI.Hide(); usableUnityUI = null; } else { HideControls(); } this.usable = null; }
private void OnSelectedUsable(Usable usable) { this.usable = usable; usableUnityUI = (usable != null) ? usable.GetComponentInChildren <UsableUnityUI>() : null; if (usableUnityUI != null) { usableUnityUI.Show(GetUseMessage()); } else { ShowControls(); } lastInRange = !IsUsableInRange(); UpdateDisplay(!lastInRange); }
public void WhenTraceSourceScopeCreatedWithUsableCreate_ThenItIsLazy() { using (var trace = new TraceListenerScope()) { var usable = from outer in Usable.Create(() => new TraceSourceScope("outer"), s => s.Dispose()) from inner in new TraceSourceScope($"{outer.Operation}/inner") select $"{inner.Operation}/value".Trace(); Assert.Equal(new string[] { }, trace.ToLines()); var value = usable.Value(); } Assert.Equal(0, Trace.IndentLevel); }
public void GetItem(GameObject droppedItem) { GameObject Item = Instantiate(droppedItem, transform.position, Quaternion.identity); Item.transform.parent = transform; Usable ItemUsable = Item.GetComponent <Usable>(); if (ItemUsable.AUTOMATIC_USE) { InstantActivateItem(ItemUsable); } else { StoreItem(ItemUsable); } }
void StoreItem(Usable ItemUsable) { if (storedItem) { storedItem.Used(); } if (OnItemDrop != null) { OnItemDrop(ItemUsable); } ItemUsable.launcher = _player; ItemUsable.OnUsed += ReleaseItem; storedItem = ItemUsable; }
void OnSelectedUsable(Usable usable) { NGUITools.SetActive(mainControl.gameObject, true); if(usable!=null) { string actionText = usable.defaultActionText; // iTween.FadeTo(mainControl.gameObject,1.0f,0.25f); _trigger = usable.GetComponent<ConversationTrigger>(); #if UNITY_IPHONE || UNITY_ANDROID string output = "Press chat icon "+actionText+" "+usable.GetName(); label.text = output.ToUpper(); #else string output = "Press Space "+actionText +" "+ usable.GetName(); label.text = output.ToUpper(); #endif } }
// Update is called once per frame void Update() { //use button is E if (Input.GetButtonDown("Use")) { if (PickUp.IsHoldingObject()) { Usable usable = PickUp.HeldObject().GetComponent <Usable>(); if (usable != null) { usable.Use(); Debug.Log("use Pressed"); } } } }
void UpdateUse(float dT) { bool checkUse = controls.IsUse(); if (checkUse) { if (liftTarget) { Tool tool = liftTarget.GetComponent <Tool>() as Tool; if (tool) { tool.user = this; tool.Use(); return; } } if (useTarget != null) { if ( DistanceSquaredTo(useTarget.transform.position) < useDistanceSquared && IsFacing(useTarget.transform.position, useAngle) ) { useTarget.Use(dT); UpdateLookAtPosition(useTarget.transform.position, dT, turnSpeed); } else { useTarget = null; } } if (useTarget == null) { Usable curTarget = GetClosestUsable(useDistanceSquared); if (curTarget) { useTarget = curTarget; } } } else { useTarget = null; } }
private bool DrawTargetingOnUse() { EditorWindowTools.DrawHorizontalLine(); EditorGUILayout.LabelField("Collider", EditorStyles.boldLabel); Collider nontriggerCollider = null; foreach (var collider in npcObject.GetComponentsInChildren <Collider>()) { if (!collider.isTrigger) { nontriggerCollider = collider; } } Usable usable = npcObject.GetComponent <Usable>(); if ((nontriggerCollider != null) && (usable != null)) { EditorGUILayout.HelpBox("The NPC has a collider and a Usable component. The player's Selector component will be able to target it to send OnUse messages.", MessageType.None); EditorGUILayout.LabelField("'Usable' Customization", EditorStyles.boldLabel); EditorWindowTools.StartIndentedSection(); usable.maxUseDistance = EditorGUILayout.FloatField("Max Usable Distance", usable.maxUseDistance); usable.overrideName = EditorGUILayout.TextField("Override Actor Name (leave blank to use main override)", usable.overrideName); usable.overrideUseMessage = EditorGUILayout.TextField("Override Use Message", usable.overrideUseMessage); EditorWindowTools.EndIndentedSection(); } else { if (nontriggerCollider == null) { EditorGUILayout.HelpBox("The NPC is configured to listen for OnUse messages. If these messages will be coming from the player's Selector component, the NPC needs a collider that the Selector can target. Click Add Collider to add a CharacterController. If OnUse will come from another source, you don't necessarily need a collider.", MessageType.Info); if (GUILayout.Button("Add Collider", GUILayout.Width(160))) { npcObject.AddComponent <CharacterController>(); } } if (usable == null) { EditorGUILayout.HelpBox("The NPC is configured to listen for OnUse messages. If these messages will be coming from the player's Selector component, the NPC needs a Usable component to tell the Selector that it's usable. Click Add Usable to add one.", MessageType.Info); if (GUILayout.Button("Add Usable", GUILayout.Width(160))) { npcObject.AddComponent <Usable>(); } } } return(true); }
/// <summary> /// Creates AmmoMod Usables more conveniently (easier to use) than chaining constructors. /// </summary> /// <param name="name">item name shown in the inventory</param> /// <param name="damage">amount of damage changed</param> /// <param name="accuracy">amount of accuracy changed</param> /// <param name="range">amount of range changed</param> /// <param name="penetration">amount of penetration changed</param> /// <param name="type">new damage type</param> /// <param name="list">Parameter that allows to add additional custom ITraitBehaviours, default or empty list results in nothing being added to the Usable Behaviour</param> public Usable Create(string name, int damage = 0, float accuracy = 0, float range = 0, float penetration = 0, string type = "default", List <ITraitBehaviour> list = null) { Usable ammo = new Usable(); Trait temp = new Trait(); List <ITraitBehaviour> tempB = new List <ITraitBehaviour>(); list = new List <ITraitBehaviour>(); if (damage != 0) { tempB.Add(new DamageTrait(damage)); } if (accuracy != 0) { tempB.Add(new AccuracyTrait(accuracy)); } if (range != 0) { tempB.Add(new RangeTrait(range)); } if (penetration != 0) { tempB.Add(new PenetrationTrait(penetration)); } if (type != "default") { tempB.Add(new DamageTypeTrait(type)); } temp.duration = -1; temp.name = "ammo_mod"; temp.behaviour = tempB; if (list.Count > 0) { temp.behaviour.AddRange(list); } ammo.name = name; ammo.type = "use"; ammo.behaviour = new List <Trait> { temp }; return(ammo); }
// Update is called once per frame void FixedUpdate() { RaycastHit hit; Vector3 direction = transform.TransformDirection(Vector3.forward); Debug.DrawRay(transform.position, direction, Color.red); if (Input.GetKey(KeyCode.F) && Physics.Raycast(transform.position, direction, out hit, 10)) { Usable usable = hit.transform.GetComponent <Usable>(); if (usable != null) { usable.beingUsed(); } } }
private void UseItem() { Item item = data.inventory.content[data.currentItem].item; if (item is Weapon) { data.player.EquipWeapon((Weapon)item); } if (item is Armor) { data.player.EquipArmor((Armor)item); } if (item is Throwable) { Throwable t = (Throwable)item; data.inventory.content[data.currentItem].count -= 1; // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items bool temp = t.Use(); if (data.inventory.content[data.currentItem].count == 0 && temp) { data.inventory.content.RemoveAt(data.currentItem); data.currentItem = -1; } data.player.actions--; QuitInventory(); } if (item is Usable) { Usable u = (Usable)item; data.inventory.content[data.currentItem].count -= 1; // == 0 for potential abuse with items that have a count of < 0 to allow easier unlimited use items if (data.inventory.content[data.currentItem].count == 0) { data.inventory.content.RemoveAt(data.currentItem); data.currentItem = -1; } u.Use(); data.player.actions--; QuitInventory(); } }
void UseItem() { if (PlayerManager.Instance.playerDisabled) { return; } itemUsing = PlayerManager.Instance.PlayerUsableList[PlayerManager.Instance.usableSelected]; if (itemUsing == null) { return; } if (itemUsing.ammount <= 0) { Debug.Log("Cantidad: " + itemUsing.ammount); return; } itemUsing.Use(); Debug.Log("Ha sido usado el item: " + itemUsing.itemName + ". En la posiciĆ³n: " + PlayerManager.Instance.usableSelected + " del array"); }
public void UseButtonClicked() { Usable u = (Usable)currentItem; u.Use(); cooldown[u.GetType()] = u.cooldown + 1; availability[u.GetType()] = false; if (typeof(Consumable).IsInstanceOfType(currentItem)) { Consumable c = (Consumable)currentItem; if (c.amount == 0) { Remove(c); ClearSelection(); } amountText.GetComponent <TextMeshProUGUI>().text = c.amount.ToString(); } }
private void OnTriggerEnter(Collider other) { if (other.GetComponent <Usable>() != null) { if (usable != null) { //is closer than current usable? if (Vector3.Distance(other.transform.position, transform.position) < Vector3.Distance(usable.transform.position, transform.position)) { usable = other.GetComponent <Usable>(); } } else { usable = other.GetComponent <Usable>(); } } }
private void OnTriggerStay(Collider other) { if (other.GetComponent <Usable>() != null) { if (usable != null) { //compare usables in area if (Vector3.Distance(other.transform.position, transform.position) < Vector3.Distance(usable.transform.position, transform.position)) { usable = other.gameObject.GetComponent <Usable>(); } } else { usable = other.GetComponent <Usable>(); } } }
public override void Select(Item item, ItemBox itemBox) { base.Select(item, itemBox); detailImage.sprite = item.image; detailName.text = item.itemName; detailDescription.text = item.description; currentItem = item; currentItemBox = itemBox; if (typeof(Usable).IsInstanceOfType(currentItem)) { Usable u = (Usable)currentItem; if (!availability.ContainsKey(u.GetType())) { availability[u.GetType()] = true; } if (!useButton.activeSelf) { useButton.SetActive(true); } amountText.SetActive(false); if (availability[u.GetType()] == false) { useButton.GetComponent <Button>().interactable = true; useButton.GetComponent <Button>().enabled = false; useButton.GetComponent <Button>().interactable = false; } else { useButton.GetComponent <Button>().enabled = true; useButton.GetComponent <Button>().interactable = true; } if (typeof(Consumable).IsInstanceOfType(currentItem)) { Consumable c = (Consumable)currentItem; amountText.SetActive(true); amountText.GetComponent <TextMeshProUGUI>().text = c.amount.ToString(); } } else { useButton.SetActive(false); amountText.SetActive(false); } }
void OnDeselectedUsable(Usable usable) { // Debug.Log ("OnDeselectedUsable: "+usable.gameObject.name); if((mainControl!=null)&&(mainControl.gameObject!=null)) NGUITools.SetActive(mainControl.gameObject, false); // iTween.FadeTo(mainControl.gameObject,0.0f,0.25f); }
void Update() { // Raycast every frame for items lookAt = null; Ray ray = new Ray(Cam.transform.position, Cam.transform.TransformDirection(0f, 0f, 1f)); Debug.DrawRay(ray.origin, ray.direction, Color.yellow, 1.5f); RaycastHit[] hits = Physics.RaycastAll(ray, 1.5f); foreach (RaycastHit hit in hits) { Usable u = hit.collider.GetComponent<Usable>(); if (u != null) { lookAt = u; break; } } // Activate stuff while looking at stuff if (lookAt != null) { if ((usableActivated != null) && (usableActivated != lookAt.ActivateWhileLookAt)) usableActivated.SetActive(false); if (lookAt.ActivateWhileLookAt != null) { usableActivated = lookAt.ActivateWhileLookAt; usableActivated.SetActive(true); } } // Disable stuff while not looking at stuff if ((lookAt == null) && (usableActivated != null)) usableActivated.SetActive(false); // UI icon HandIcon.SetActive(lookAt != null); // Left hand if (Input.GetMouseButtonDown(0)) { // Pick up stuff if ((lookAt != null) && (lookAt.Item != null)) { if ((leftHand == null) && (lookAt != null) && (lookAt.Item != null)) { Audio.PlayOneShot(PickupSound); leftHand = lookAt.Item; leftOriginalScale = lookAt.Item.transform.localScale; Rigidbody rb = lookAt.Item.GetComponent<Rigidbody>(); if (rb != null) rb.isKinematic = true; lookAt.Item.transform.SetParent(LeftHandContainer); lookAt.Item.transform.localPosition = Vector3.zero; lookAt.Item.transform.localRotation = Quaternion.identity; } } // Activate trigger if ((lookAt != null) && (lookAt.Trigger != null)) { if (!string.IsNullOrEmpty(lookAt.NeedsItem)) { if ((leftHand != null) && (string.Compare(leftHand.Item, lookAt.NeedsItem) == 0)) { lookAt.Trigger.Invoke(); if (lookAt.ConsumesItem) Destroy(leftHand.gameObject); if (lookAt.OneTime) { Destroy(lookAt); lookAt = null; } } else if (lookAt.NoItemTrigger != null) { lookAt.NoItemTrigger.Invoke(); } } else { lookAt.Trigger.Invoke(); if (lookAt.OneTime) { Destroy(lookAt); lookAt = null; } } } // Throw what's in out hands if ((leftHand != null) && (lookAt == null)) { leftHand.transform.SetParent(null); leftHand.transform.localScale = leftOriginalScale; Rigidbody rb = leftHand.GetComponent<Rigidbody>(); if (rb != null) { rb.isKinematic = false; rb.velocity = GetComponentInParent<Rigidbody>().velocity; } leftHand = null; } } // Right hand if (Input.GetMouseButtonDown(1)) { // Pick up stuff if ((lookAt != null) && (lookAt.Item != null)) { if ((rightHand == null) && (lookAt != null) && (lookAt.Item != null)) { Audio.PlayOneShot(PickupSound); rightHand = lookAt.Item; rightOriginalScale = lookAt.Item.transform.localScale; Rigidbody rb = lookAt.Item.GetComponent<Rigidbody>(); if (rb != null) rb.isKinematic = true; lookAt.Item.transform.SetParent(RightHandContainer); lookAt.Item.transform.localPosition = Vector3.zero; lookAt.Item.transform.localRotation = Quaternion.identity; } } // Activate trigger if ((lookAt != null) && (lookAt.Trigger != null)) { if (string.IsNullOrEmpty(lookAt.NeedsItem) || ((rightHand != null) && (string.Compare(rightHand.Item, lookAt.NeedsItem) == 0))) { lookAt.Trigger.Invoke(); if (lookAt.ConsumesItem) Destroy(rightHand.gameObject); if (lookAt.OneTime) { Destroy(lookAt); lookAt = null; } } } // Throw what's in out hands if ((rightHand != null) && (lookAt == null)) { rightHand.transform.SetParent(null); rightHand.transform.localScale = rightOriginalScale; Rigidbody rb = rightHand.GetComponent<Rigidbody>(); if (rb != null) { rb.isKinematic = false; rb.velocity = GetComponentInParent<Rigidbody>().velocity; } rightHand = null; } } // Combine if (Input.GetMouseButtonDown(2)) { if ((leftHand != null) && (rightHand != null)) { GameObject result = Crafting.Instance.GetCraftResult(leftHand.Item, rightHand.Item); if (result != null) { Audio.PlayOneShot(CombineSound); Destroy(leftHand.gameObject); Destroy(rightHand.gameObject); Vector3 pos = Camera.main.transform.TransformPoint(new Vector3(0f, 0f, 3f)); GameObject go = (GameObject)Instantiate(result, pos, Quaternion.identity); go.SetActive(true); } } } }