示例#1
0
        public virtual object GetSaveData()
        {
            InventorySaveData inventorySaveData = new InventorySaveData();

            if (DatabaseInventory.Load().inventorySettings.saveInventory&&
                this.playerInventory != null)
            {
                if (this.playerInventory.items != null && this.playerInventory.items.Count > 0)
                {
                    int playerInventoryItemsCount = this.playerInventory.items.Count;
                    inventorySaveData.playerItemsUUIDS = new int[playerInventoryItemsCount];
                    inventorySaveData.playerItemsStack = new int[playerInventoryItemsCount];

                    int itemIndex = 0;
                    foreach (KeyValuePair <int, int> entry in this.playerInventory.items)
                    {
                        inventorySaveData.playerItemsUUIDS[itemIndex] = entry.Key;
                        inventorySaveData.playerItemsStack[itemIndex] = entry.Value;
                        ++itemIndex;
                    }
                }

                inventorySaveData.playerCurrencyAmount = this.playerInventory.currencyAmount;
            }

            return(inventorySaveData);
        }
示例#2
0
        // INITIALIZE: ----------------------------------------------------------------------------

        protected override void OnCreate()
        {
            DatabaseInventory dbInventory = DatabaseInventory.LoadDatabase <DatabaseInventory>();

            this.eventChangePlayerInventory = new UnityEvent();
            this.eventChangePlayerCurrency  = new UnityEvent();

            this.itemsCatalogue = new Dictionary <int, Item>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.items.Length; ++i)
            {
                this.itemsCatalogue.Add(
                    dbInventory.inventoryCatalogue.items[i].uuid,
                    dbInventory.inventoryCatalogue.items[i]
                    );
            }

            this.recipes = new Dictionary <Recipe.Key, Recipe>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.recipes.Length; ++i)
            {
                this.recipes.Add(
                    new Recipe.Key(
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineA.item.uuid,
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineB.item.uuid
                        ),
                    dbInventory.inventoryCatalogue.recipes[i]
                    );
            }

            this.playerInventory = new PlayerInventory();
            SaveLoadManager.Instance.Initialize(this);
        }
示例#3
0
        private static void RequireInstance(Merchant merchant)
        {
            if (DATABASE_INVENTORY == null)
            {
                DATABASE_INVENTORY = DatabaseInventory.Load();
            }
            if (MerchantUIManager.Instance == null)
            {
                EventSystemManager.Instance.Wakeup();
                if (DATABASE_INVENTORY.inventorySettings == null)
                {
                    Debug.LogError("No inventory database found");
                    return;
                }

                GameObject prefab = merchant.merchantUI;
                if (prefab == null)
                {
                    prefab = DATABASE_INVENTORY.inventorySettings.merchantUIPrefab;
                }
                if (prefab == null)
                {
                    prefab = Resources.Load <GameObject>(DEFAULT_UI_PATH);
                }

                Instantiate(prefab, Vector3.zero, Quaternion.identity);
            }
        }
示例#4
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void Start()
        {
            if (DATABASE_INVENTORY == null)
            {
                DATABASE_INVENTORY = DatabaseInventory.Load();
            }
            this.SetupEvents(EventTriggerType.PointerClick, this.OnClick);
        }
        // INITIALIZERS: --------------------------------------------------------------------------

        private void OnEnable()
        {
            if (target == null || serializedObject == null)
            {
                return;
            }
            if (DATABASE_INVENTORY == null)
            {
                DATABASE_INVENTORY = DatabaseInventory.Load();
            }
            this.equipment = (CharacterEquipment)this.target;
        }
示例#6
0
        // PRIVATE METHODS: -----------------------------------------------------------------------

        private void OnUpdate()
        {
            float      curWeight = InventoryManager.Instance.GetCurrentWeight();
            GameObject player    = HookPlayer.Instance == null ? null : HookPlayer.Instance.gameObject;

            float maxWeight = DatabaseInventory
                              .Load()
                              .inventorySettings
                              .maxInventoryWeight
                              .GetValue(player);

            this.text.text = string.Format(this.format, curWeight, maxWeight);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (INVENTORY == null)
            {
                INVENTORY = DatabaseInventory.Load();
            }

            property.intValue = EditorGUI.MaskField(
                position,
                label,
                property.intValue,
                INVENTORY.GetItemTypesIDs()
                );
        }
        // PUBLIC METHODS: ---------------------------------------------------------------------------------------------

        public ItemHolderPropertyDrawerWindow(Rect activatorRect, SerializedProperty property)
        {
            this.windowRect = new Rect(
                activatorRect.x,
                activatorRect.y + activatorRect.height,
                activatorRect.width,
                WIN_HEIGHT
                );

            this.inputfieldFocus = true;
            this.scroll          = Vector2.zero;
            this.property        = property;

            if (DATABASE_INVENTORY == null)
            {
                DATABASE_INVENTORY = DatabaseInventory.LoadDatabase <DatabaseInventory>();
            }
        }
示例#9
0
        // CONSTRUCTOR & UPDATER: -----------------------------------------------------------------

        public virtual void Setup(Item item, int amount)
        {
            this.UpdateUI(item, amount);
            this.button = gameObject.GetComponentInChildren <Button>();

            if (DATABASE_INVENTORY == null)
            {
                DATABASE_INVENTORY = DatabaseInventory.Load();
            }
            if (DATABASE_INVENTORY.inventorySettings.onDragGrabItem)
            {
                this.SetupEvents(EventTriggerType.BeginDrag, this.OnDragBegin);
                this.SetupEvents(EventTriggerType.EndDrag, this.OnDragEnd);
                this.SetupEvents(EventTriggerType.Drag, this.OnDragMove);
            }

            this.SetupEvents(EventTriggerType.PointerEnter, this.OnPointerEnter);
            this.SetupEvents(EventTriggerType.PointerExit, this.OnPointerExit);
        }
示例#10
0
        // CONSTRUCTOR: ------------------------------------------------------------------------------------------------

                #if UNITY_EDITOR
        public static Recipe CreateRecipeInstance()
        {
            Recipe recipe = ScriptableObject.CreateInstance <Recipe>();
            Guid   guid   = Guid.NewGuid();

            recipe.itemToCombineA     = new ItemHolder();
            recipe.itemToCombineB     = new ItemHolder();
            recipe.removeItemsOnCraft = true;

            recipe.name      = "recipe." + Mathf.Abs(guid.GetHashCode());
            recipe.hideFlags = HideFlags.HideInHierarchy;

            DatabaseInventory databaseInventory = DatabaseInventory.Load();

            AssetDatabase.AddObjectToAsset(recipe, databaseInventory);

            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(recipe));
            return(recipe);
        }
示例#11
0
        // CONSTRUCTOR: ------------------------------------------------------------------------------------------------

                #if UNITY_EDITOR
        public static Item CreateItemInstance()
        {
            Item item = ScriptableObject.CreateInstance <Item>();
            Guid guid = Guid.NewGuid();

            item.name = "item." + Mathf.Abs(guid.GetHashCode());
            item.uuid = Mathf.Abs(guid.GetHashCode());

            item.itemName        = new LocString();
            item.itemDescription = new LocString();
            item.price           = 1;
            item.maxStack        = 99;
            item.hideFlags       = HideFlags.HideInHierarchy;

            DatabaseInventory databaseInventory = DatabaseInventory.Load();

            AssetDatabase.AddObjectToAsset(item, databaseInventory);
            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(item));
            return(item);
        }
示例#12
0
        public virtual void OnLoad(object generic)
        {
            InventorySaveData inventorySaveData = generic as InventorySaveData;

            this.playerInventory = new PlayerInventory();
            if (!DatabaseInventory.Load().inventorySettings.saveInventory ||
                inventorySaveData == null)
            {
                return;
            }

            this.SetCurrency(inventorySaveData.playerCurrencyAmount);
            int playerInventoryItemsCount = inventorySaveData.playerItemsUUIDS.Length;

            for (int i = 0; i < playerInventoryItemsCount; ++i)
            {
                this.playerInventory.items.Add(
                    inventorySaveData.playerItemsUUIDS[i],
                    inventorySaveData.playerItemsStack[i]
                    );
            }
        }
示例#13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (INVENTORY == null)
            {
                INVENTORY = DatabaseInventory.Load();
            }

            string[] ids    = INVENTORY.GetItemTypesIDs();
            int[]    values = new int[ids.Length];
            for (int i = 0; i < values.Length; ++i)
            {
                values[i] = i;
            }

            property.intValue = EditorGUI.IntPopup(
                position,
                label.text,
                property.intValue,
                ids,
                values
                );
        }
示例#14
0
        // INITIALIZE: ----------------------------------------------------------------------------

        protected override void OnCreate()
        {
            DatabaseInventory dbInventory = DatabaseInventory.Load();

            if (INVENTORY == null)
            {
                INVENTORY = dbInventory;
            }

            this.eventChangePlayerInventory = new InventoryEvent();
            this.eventChangePlayerCurrency  = new InventoryEvent();

            this.itemsCatalogue = new Dictionary <int, Item>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.items.Length; ++i)
            {
                this.itemsCatalogue.Add(
                    dbInventory.inventoryCatalogue.items[i].uuid,
                    dbInventory.inventoryCatalogue.items[i]
                    );
            }

            this.recipes = new Dictionary <Recipe.Key, Recipe>();
            for (int i = 0; i < dbInventory.inventoryCatalogue.recipes.Length; ++i)
            {
                this.recipes.Add(
                    new Recipe.Key(
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineA.item.uuid,
                        dbInventory.inventoryCatalogue.recipes[i].itemToCombineB.item.uuid
                        ),
                    dbInventory.inventoryCatalogue.recipes[i]
                    );
            }

            this.playerInventory = new PlayerInventory();
            SaveLoadManager.Instance.Initialize(this, 25);

            SaveLoadManager.Instance.eventOnChangeProfile.AddListener(this.OnChangeProfile);
        }