protected override void Start() { base.Start(); this.m_ResultStorageContainer = WidgetUtility.Find <ItemContainer>(this.m_ResultStorageWindow); this.m_RequiredIngredientsContainer = WidgetUtility.Find <ItemContainer>(this.m_RequiredIngredientsWindow); this.m_Progressbar = WidgetUtility.Find <Progressbar>(this.m_CraftingProgressbar); }
private void Start() { if (transform.root != transform) { EquipmentHandler handler = transform.root.gameObject.GetComponent <EquipmentHandler>(); if (handler == null) { handler = transform.root.gameObject.AddComponent <EquipmentHandler>(); } handler.m_VisibleItems = m_VisibleItems; Destroy(this); return; } this.m_EquipmentContainer = WidgetUtility.Find <ItemContainer>(this.m_WindowName); if (this.m_EquipmentContainer != null) { for (int i = 0; i < this.m_VisibleItems.Count; i++) { this.m_VisibleItems[i].enabled = false; } this.m_EquipmentContainer.OnAddItem += OnAddItem; this.m_EquipmentContainer.OnRemoveItem += OnRemoveItem; UpdateEquipment(); if (InventoryManager.current != null) { InventoryManager.current.onSceneLoaded.AddListener(UpdateEquipment); } } }
private void Start() { this.m_EquipmentContainer = WidgetUtility.Find <ItemContainer>(this.m_WindowName); if (this.m_EquipmentContainer != null) { this.m_EquipmentContainer.OnAddItem += OnAddItem; this.m_EquipmentContainer.OnRemoveItem += OnRemoveItem; UpdateEquipment(); } }
public override ActionStatus OnUpdate() { Notification widget = WidgetUtility.Find <Notification>(this.m_WidgetName); if (widget == null) { Debug.LogWarning("Missing notification widget " + this.m_WidgetName + " in scene!"); return(ActionStatus.Failure); } return(widget.AddItem(this.m_Notification)?ActionStatus.Success:ActionStatus.Failure); }
public override void OnStart() { this.m_Time = 0f; this.m_Widget = WidgetUtility.Find <Progressbar>(this.m_WidgetName); if (this.m_Widget == null) { Debug.LogWarning("Missing progressbar widget " + this.m_WidgetName + " in scene!"); return; } this.m_Widget.Show(); }
public override ActionStatus OnUpdate() { UIWidget widget = WidgetUtility.Find <UIWidget>(this.m_WidgetName); if (widget == null) { Debug.LogWarning("Missing notification widget " + this.m_WidgetName + " in scene!"); return(ActionStatus.Failure); } widget.Close(); return(ActionStatus.Success); }
public override void OnStart() { this.m_DialogBox = WidgetUtility.Find <DialogBox>(this.m_WidgetName); if (this.m_DialogBox == null) { Debug.LogWarning("Missing dialog box widget " + this.m_WidgetName + " in scene!"); return; } this.m_DialogBox.RegisterListener("OnClose", OnClose); this.m_Status = ActionStatus.Running; this.m_DialogBox.Show(this.m_Title, this.m_Text, this.m_Icon, OnResponse, "Yes", "No"); }
private IEnumerator CraftItem(Item item) { this.m_ProgressDuration = item.CraftingDuration; this.m_ProgressInitTime = Time.time; yield return(new WaitForSeconds(item.CraftingDuration)); if (item.UseCraftingSkill) { ItemContainer skills = WidgetUtility.Find <ItemContainer>(item.SkillWindow); Skill skill = (Skill)skills.GetItems(item.CraftingSkill.Id).FirstOrDefault(); if (skill == null) { Debug.LogWarning("Skill not found in " + item.SkillWindow + "."); } if (!skill.CheckSkill()) { InventoryManager.Notifications.failedToCraft.Show(item.DisplayName); if (item.RemoveIngredientsWhenFailed) { for (int i = 0; i < item.ingredients.Count; i++) { this.m_RequiredIngredientsContainer.RemoveItem(item.ingredients[i].item, item.ingredients[i].amount); } } yield break; } } Item craftedItem = Instantiate(item); craftedItem.Stack = 1; craftedItem.CraftingModifier.Modify(craftedItem); if (this.m_ResultStorageContainer.StackOrAdd(craftedItem)) { for (int i = 0; i < item.ingredients.Count; i++) { this.m_RequiredIngredientsContainer.RemoveItem(item.ingredients[i].item, item.ingredients[i].amount); } InventoryManager.Notifications.craftedItem.Show(UnityTools.ColorString(craftedItem.Name, craftedItem.Rarity.Color)); ExecuteEvent <ITriggerCraftItem>(Execute, craftedItem); } else { InventoryManager.Notifications.containerFull.Show(this.m_ResultStorageContainer.Name); ExecuteEvent <ITriggerFailedToCraftItem>(Execute, item, FailureCause.ContainerFull); StopCrafting(item); } }
protected override void Start() { base.Start(); this.m_ResultStorageContainer = WidgetUtility.Find <ItemContainer>(this.m_StorageWindow); this.m_RequiredIngredientsContainer = WidgetUtility.Find <ItemContainer>(this.m_IngredientsWindow); this.m_Progressbar = WidgetUtility.Find <Progressbar>(this.m_CraftingProgressbar); ItemContainer container = GetComponent <ItemContainer>(); if (container != null) { container.RegisterListener("OnShow", (CallbackEventData ev) => { InUse = true; }); container.RegisterListener("OnClose", (CallbackEventData ev) => { InUse = false; }); } }
public virtual void SetObjectData(Dictionary <string, object> data) { this.Stack = System.Convert.ToInt32(data["Stack"]); if (data.ContainsKey("RarityIndex")) { int rarityIndex = System.Convert.ToInt32(data["RarityIndex"]); if (rarityIndex > -1 && rarityIndex < InventoryManager.Database.raritys.Count) { this.m_Rarity = InventoryManager.Database.raritys[rarityIndex]; } } if (data.ContainsKey("Properties")) { List <object> objectProperties = data["Properties"] as List <object>; for (int i = 0; i < objectProperties.Count; i++) { Dictionary <string, object> propertyData = objectProperties[i] as Dictionary <string, object>; string propertyName = (string)propertyData["Name"]; object propertyValue = propertyData["Value"]; ObjectProperty property = FindProperty(propertyName); if (property == null) { property = new ObjectProperty(); property.Name = propertyName; properties.Add(property); } property.SetValue(propertyValue); } } if (data.ContainsKey("Reference")) { List <object> references = data["Reference"] as List <object>; for (int i = 0; i < references.Count; i++) { Dictionary <string, object> referenceData = references[i] as Dictionary <string, object>; string container = (string)referenceData["Container"]; int slot = System.Convert.ToInt32(referenceData["Slot"]); ItemContainer referenceContainer = WidgetUtility.Find <ItemContainer>(container); if (referenceContainer != null) { referenceContainer.ReplaceItem(slot, this); } } } }
protected override void Start() { base.Start(); this.m_BuySellDialog = WidgetUtility.Find <DialogBox>(this.m_BuySellDialogName); if (this.m_BuySellDialog != null) { this.m_AmountSpinner = this.m_BuySellDialog.GetComponentInChildren <Spinner>(); this.m_PriceInfo = this.m_BuySellDialog.GetComponentInChildren <ItemContainer>(); } this.m_PurchasedStorageContainer = WidgetUtility.Find <ItemContainer>(this.m_PurchasedStorageWindow); this.m_PaymentContainer = WidgetUtility.Find <ItemContainer>(this.m_PaymentWindow); /* ItemCollection collection = GetComponent<ItemCollection>(); * for (int i = 0; i < collection.Count; i++) { * collection[i].BuyPrice = Mathf.RoundToInt(m_BuyPriceFactor*collection[i].BuyPrice); * }*/ }
/// <summary> /// Try to move item by move conditions set in inspector /// </summary> /// <returns>True if item was moved.</returns> public virtual bool MoveItem() { if (Container.MoveUsedItem) { for (int i = 0; i < Container.moveItemConditions.Count; i++) { ItemContainer.MoveItemCondition condition = Container.moveItemConditions[i]; ItemContainer moveToContainer = WidgetUtility.Find <ItemContainer>(condition.window); if (moveToContainer == null || (condition.requiresVisibility && !moveToContainer.IsVisible)) { continue; } if (moveToContainer.IsLocked) { InventoryManager.Notifications.inUse.Show(); continue; } if (moveToContainer.CanAddItem(ObservedItem) && moveToContainer.StackOrAdd(ObservedItem)) { if (!moveToContainer.UseReferences || !Container.CanReferenceItems) { // Debug.Log("Move Item from "+Container.Name+" to "+moveToContainer.Name); if (!moveToContainer.CanReferenceItems) { ItemContainer.RemoveItemReferences(ObservedItem); } Container.RemoveItem(Index); } return(true); } for (int j = 0; j < moveToContainer.Slots.Count; j++) { if (moveToContainer.CanSwapItems(moveToContainer.Slots[j], this) && moveToContainer.SwapItems(moveToContainer.Slots[j], this)) { return(true); } } } } return(false); }
protected virtual void Start() { if (!InventoryManager.HasSavedData()) { for (int i = 0; i < this.m_Entries.Count; i++) { ItemContainer container = WidgetUtility.Find <ItemContainer>(this.m_Entries[i].name); if (container != null) { Item[] groupItems = InventoryManager.CreateInstances(this.m_Entries[i].group); for (int j = 0; j < groupItems.Length; j++) { container.StackOrAdd(groupItems[j]); } } } } }
private void Start() { this.m_EquipmentContainer = WidgetUtility.Find <ItemContainer>(this.m_WindowName); if (this.m_EquipmentContainer != null) { for (int i = 0; i < this.m_VisibleItems.Count; i++) { this.m_VisibleItems[i].enabled = false; } this.m_EquipmentContainer.OnAddItem += OnAddItem; this.m_EquipmentContainer.OnRemoveItem += OnRemoveItem; UpdateEquipment(); if (InventoryManager.current != null) { InventoryManager.current.onDataLoaded.AddListener(UpdateEquipment); } } }
public override void OnSequenceStart() { this.m_WindowStatus = ActionStatus.Inactive; this.m_ItemContainer = WidgetUtility.Find <ItemContainer>(this.m_WindowName); if (this.m_ItemContainer != null) { this.m_ItemContainer.RegisterListener("OnClose", (CallbackEventData eventData) => { this.m_WindowStatus = ActionStatus.Success; }); } this.m_ItemCollection = gameObject.GetComponent <ItemCollection>(); if (this.m_ItemCollection != null) { this.m_ItemCollection.onChange.AddListener(delegate() { if (this.m_ItemCollection.IsEmpty && this.m_DestroyWhenEmpty) { InventoryManager.Destroy(gameObject); } }); } }
private static void LoadUI(string json) { if (string.IsNullOrEmpty(json)) { return; } List <object> list = MiniJSON.Deserialize(json) as List <object>; for (int i = 0; i < list.Count; i++) { Dictionary <string, object> mData = list[i] as Dictionary <string, object>; string prefab = (string)mData["Prefab"]; List <object> positionData = mData["Position"] as List <object>; List <object> rotationData = mData["Rotation"] as List <object>; string type = (string)mData["Type"]; Vector3 position = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2])); Quaternion rotation = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2]))); ItemCollection itemCollection = null; if (type == "UI") { UIWidget container = WidgetUtility.Find <UIWidget>(prefab); if (container != null) { itemCollection = container.GetComponent <ItemCollection>(); } } if (itemCollection != null) { itemCollection.SetObjectData(mData); } } if (InventoryManager.DefaultSettings.debugMessages) { Debug.Log("[Inventory System] UI Loaded: " + json); } }
public void SetObjectData(Dictionary <string, object> data) { this.Stack = System.Convert.ToInt32(data["Stack"]); if (data.ContainsKey("RarityIndex")) { int rarityIndex = System.Convert.ToInt32(data["RarityIndex"]); if (rarityIndex > -1 && rarityIndex < InventoryManager.Database.raritys.Count) { this.m_Rarity = InventoryManager.Database.raritys[rarityIndex]; } } foreach (ObjectProperty property in this.properties) { if (data.ContainsKey(property.Name)) { object obj = data[property.Name]; property.SetValue(obj); } } if (data.ContainsKey("Reference")) { List <object> references = data["Reference"] as List <object>; for (int i = 0; i < references.Count; i++) { Dictionary <string, object> referenceData = references[i] as Dictionary <string, object>; string container = (string)referenceData["Container"]; int slot = System.Convert.ToInt32(referenceData["Slot"]); ItemContainer referenceContainer = WidgetUtility.Find <ItemContainer>(container); if (referenceContainer != null) { referenceContainer.ReplaceItem(slot, this); } } } }
public static void Load(string key, bool includePersistent = true) { key += "InventorySystem"; key += " [" + UnityEngine.SceneManagement.SceneManager.GetActiveScene().name + "]"; string data = PlayerPrefs.GetString(key); if (string.IsNullOrEmpty(data)) { return; } ItemCollection[] itemCollections = FindObjectsOfType <ItemCollection>(); for (int i = 0; i < itemCollections.Length; i++) { if (InventoryManager.GetPrefab(itemCollections[i].name.Replace("(Clone)", "")) == null) { continue; } Destroy(itemCollections[i].gameObject); } List <object> list = MiniJSON.Deserialize(data) as List <object>; for (int i = 0; i < list.Count; i++) { Dictionary <string, object> mData = list[i] as Dictionary <string, object>; string prefab = (string)mData["Prefab"]; List <object> positionData = mData["Position"] as List <object>; List <object> rotationData = mData["Rotation"] as List <object>; string type = (string)mData["Type"]; Vector3 position = new Vector3(System.Convert.ToSingle(positionData[0]), System.Convert.ToSingle(positionData[1]), System.Convert.ToSingle(positionData[2])); Quaternion rotation = Quaternion.Euler(new Vector3(System.Convert.ToSingle(rotationData[0]), System.Convert.ToSingle(rotationData[1]), System.Convert.ToSingle(rotationData[2]))); ItemCollection itemCollection = null; if (type == "UI") { UIWidget container = WidgetUtility.Find <UIWidget>(prefab); if (container != null && (includePersistent || container.gameObject.scene == UnityEngine.SceneManagement.SceneManager.GetActiveScene())) { itemCollection = container.GetComponent <ItemCollection>(); } } else { GameObject collectionGameObject = CreateCollection(prefab, position, rotation); if (collectionGameObject != null) { IGenerator[] generators = collectionGameObject.GetComponents <IGenerator>(); for (int j = 0; j < generators.Length; j++) { generators[j].enabled = false; } itemCollection = collectionGameObject.GetComponent <ItemCollection>(); } } if (itemCollection != null) { itemCollection.SetObjectData(mData); } } if (InventoryManager.current != null && InventoryManager.current.onSceneLoaded != null) { InventoryManager.current.onSceneLoaded.Invoke(); } if (InventoryManager.DefaultSettings.debugMessages) { Debug.Log("[Inventory System] Data loaded: " + data); } }
// Start is called before the first frame update private void Start() { this.m_RadialMenu = WidgetUtility.Find <RadialMenu>("RadialMenu"); }
private void Start() { //Find the reference to the MessageContainer this.m_Notification = WidgetUtility.Find <Notification> ("Notification"); }
// Start is called before the first frame update private void Start() { this.m_ContextMenu = WidgetUtility.Find <ContextMenu>("ContextMenu"); }
//Detects the release of the mouse button public virtual void OnPointerUp(PointerEventData eventData) { EventSystem.current.SetSelectedGameObject(null); if (!eventData.dragging) { Stack stack = InventoryManager.UI.stack; bool isUnstacking = stack != null && stack.item != null; if (!isUnstacking && InventoryManager.Input.unstackEvent.HasFlag <Configuration.Input.UnstackInput>(Configuration.Input.UnstackInput.OnClick) && Input.GetKey(InventoryManager.Input.unstackKeyCode) && ObservedItem.Stack > 1) { Unstack(); return; } //Check if we are currently unstacking the item if (isUnstacking && Container.StackOrAdd(this, stack.item)) { stack.item = null; UICursor.Clear(); } if (isUnstacking) { return; } if (ObservedItem == null) { return; } if (Container.useButton.HasFlag((InputButton)Mathf.Clamp(((int)eventData.button * 2), 1, int.MaxValue))) { Use(); } else if (Container.UseContextMenu && Container.ContextMenuButton.HasFlag((InputButton)Mathf.Clamp(((int)eventData.button * 2), 1, int.MaxValue))) { UIWidgets.ContextMenu menu = InventoryManager.UI.contextMenu; if (menu == null) { return; } menu.Clear(); if (Trigger.currentUsedTrigger != null && Trigger.currentUsedTrigger is VendorTrigger && Container.CanSellItems) { menu.AddMenuItem("Sell", Use); } else if (ObservedItem is UsableItem) { menu.AddMenuItem("Use", Use); } if (ObservedItem.MaxStack > 1 || ObservedItem.MaxStack == 0) { menu.AddMenuItem("Unstack", Unstack); } menu.AddMenuItem("Drop", DropItem); if (ObservedItem.EnchantingRecipe != null) { menu.AddMenuItem("Enchant", delegate() { ItemContainer container = WidgetUtility.Find <ItemContainer>("Enchanting"); container.Show(); container.ReplaceItem(0, ObservedItem); }); } if (ObservedItem.CanDestroy) { menu.AddMenuItem("Destroy", DestroyItem); } for (int i = 0; i < Container.ContextMenuFunctions.Count; i++) { int cnt = i; if (!string.IsNullOrEmpty(Container.ContextMenuFunctions[cnt])) { menu.AddMenuItem(Container.ContextMenuFunctions[cnt], () => { Container.gameObject.SendMessage(Container.ContextMenuFunctions[cnt], ObservedItem, SendMessageOptions.DontRequireReceiver); }); } } menu.Show(); } } }
public override void OnStart() { this.m_ItemContainer = WidgetUtility.Find <ItemContainer>(this.m_WindowName); }
private void Start() { m_Trigger = GetComponentInChildren <BaseTrigger>(true); this.m_Tooltip = WidgetUtility.Find <TriggerTooltip>("Trigger Tooltip"); }
public override void OnStart() { this.m_TalkQuestWindow = WidgetUtility.Find <QuestTalkWindow>(this.m_WindowName); }
public void StartCrafting(Item item, int amount) { if (item == null) { InventoryManager.Notifications.selectItem.Show(); ExecuteEvent <ITriggerFailedCraftStart>(Execute, item, FailureCause.FurtherAction); return; } if (this.m_IsCrafting) { InventoryManager.Notifications.alreadyCrafting.Show(); ExecuteEvent <ITriggerFailedCraftStart>(Execute, item, FailureCause.InUse); return; } if (item.UseCraftingSkill) { ItemContainer skills = WidgetUtility.Find <ItemContainer>(item.SkillWindow); if (skills != null) { Skill skill = (Skill)skills.GetItems(item.CraftingSkill.Id).FirstOrDefault(); if (skill == null) { InventoryManager.Notifications.missingSkillToCraft.Show(item.DisplayName); return; } if (skill.CurrentValue < item.MinCraftingSkillValue) { InventoryManager.Notifications.requiresHigherSkill.Show(item.DisplayName, skill.DisplayName); return; } } else { Debug.LogWarning("Item is set to use a skill but no skill window with name " + item.SkillWindow + " found!"); } } if (!HasIngredients(this.m_RequiredIngredientsContainer, item)) { InventoryManager.Notifications.missingIngredient.Show(); ExecuteEvent <ITriggerFailedCraftStart>(Execute, item, FailureCause.Requirement); return; } GameObject user = InventoryManager.current.PlayerInfo.gameObject; if (user != null) { //user.transform.LookAt(new Vector3(Trigger.currentUsedTrigger.transform.position.x, user.transform.position.y, Trigger.currentUsedTrigger.transform.position.z)); user.SendMessage("SetControllerActive", false, SendMessageOptions.DontRequireReceiver); Animator animator = InventoryManager.current.PlayerInfo.animator; if (animator != null) { animator.CrossFadeInFixedTime(Animator.StringToHash(item.CraftingAnimatorState), 0.2f); } } //this.m_RequiredIngredientsContainer.Lock(true); StartCoroutine(CraftItems(item, amount)); ExecuteEvent <ITriggerCraftStart>(Execute, item); }