InvManager.cs

using UnityEngine; using System.Collections.Generic; using AC; [AddComponentMenu("Adventure Creator/Hotspots/Inventory Action Manager")] [ExecuteInEditMode] [RequireComponent(typeof(Hotspot))] //[RequireComponent(typeof(InvItem))] public class InvManager : MonoBehaviour { public List<ItemOverride> itemOverrides = new List<ItemOverride>(); private Hotspot thisHotspot; public List<string> invButtons = new List<string>(); private bool buttonFound; private bool hotSpotMatch; private InventoryManager inventoryManager; private void OnEnable() { EventManager.OnHotspotSelect += OnHotspotSelect; EventManager.OnHotspotDeselect += OnHotspotDeselect; } private void OnDisable() { EventManager.OnHotspotSelect -= OnHotspotSelect; EventManager.OnHotspotDeselect -= OnHotspotDeselect; } private void OnHotspotSelect(Hotspot hotspot) { hotSpotMatch = false; foreach (ItemOverride itemOverride in itemOverrides) { if (hotspot.name == itemOverride.hotspot) { hotSpotMatch = true; } } if (hotSpotMatch==true) { if (KickStarter.runtimeInventory.SelectedItem != null) { foreach (ItemOverride itemOverride in itemOverrides) { if (itemOverride.invitem == KickStarter.runtimeInventory.SelectedItem.label) { KickStarter.cursorManager.hotspotPrefix2.label = itemOverride.overrideSyntax; // Use this to set an ID value for the Editor } } } } hotSpotMatch = false; } private void OnHotspotDeselect(Hotspot hotspot) { KickStarter.cursorManager.hotspotPrefix2.label = "on"; } private void Update() { GameObject g = GameObject.Find(this.name); Hotspot thisHotspot = g.GetComponent<Hotspot>(); inventoryManager = AdvGame.GetReferences().inventoryManager; foreach (Button invButton in thisHotspot.invButtons) { bool invFound = false; var j = 0; foreach (ItemOverride itemOverride in itemOverrides) { if (inventoryManager.items[invButton.invID].label.ToString() == itemOverride.invitem) invFound = true; j++; } if (invFound == false) { itemOverrides.Add(new ItemOverride(inventoryManager.items[invButton.invID].label.ToString(), "on", thisHotspot.name)); } } for (int j = 0; j < itemOverrides.Count; j++) { buttonFound = false; foreach (Button invButton in thisHotspot.invButtons) { if (inventoryManager.items[invButton.invID].label.ToString() == itemOverrides[j].invitem.ToString()) { buttonFound = true; } } if (buttonFound == false) { itemOverrides.RemoveAt(j); } } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.