Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by danny_appel · Jan 18, 2021 at 10:55 AM · randominventorysave datascriptable objectequipment

What is the best way for saving Scriptable Objects (With random stats when created)?

Hi all,

Im hitting a roadblock, I got a player and enemies working that drop loot when they die, got the inventory finally working althought now I cannot save my inventory. All the vidoes that im trying to watch are hard to understand and develop in my project. And I fear that creating random stats on the item when instantiated wasnt a good idea, since nobody does that.

Does any one know a good way to do it do I have to redo all the items a different way? I will show what I mean with random stats with instantiating. (Line 163)

 using UnityEngine;
 
 namespace Items
 {
     //Enum of item types
     public enum ItemType
     {
         Weapon,
         Armor,
         Consumable,
         Misc
     }
 
     //Enum of equip types
     public enum EquipType
     {
         Weapon,
         Armor,
         Ammo
     }
     public enum RarityType
     {
         Common,
         Uncommon,
         Rare,
         Epic,
         Legendary
     }
 
 
     [CreateAssetMenu(fileName = "New Item", menuName = "Items/Base Item")]
     [System.Serializable]
     public class ItemData : ScriptableObject
     {
         PlayerStats playerStats;
         private float _ItemLevel;
 
 
 
         string[] commonNamePrefix = new string[] { "Old ", "Damaged ", "Battered ", "Rusty " };                                            
 
         string[] uncommonNamePrefix = new string[] { "Used ", "Battered ", "Dirty ", "Bloody " };                                      
 
         string[] rareNamePrefix = new string[] { "Balanced ", "Fine  ", "Repaired " };                                         
         string[] rareNameEnd = new string[] { " of the Warrior", " of the Soldier", " of Clans", " of Raiders", " of the Backstabber" };
 
         string[] epicNamePrefix = new string[] { "Fine ", "Ferocious ", "Massive ", "Perfect "};                                
         string[] epicNameEnd = new string[] { " of the Claw", " of the Master", " of the Falcon", " of Sovereignty", " of the Graverobber", " of Scavangers"};
 
         string[] legendaryNamePrefix = new string[] { "Shiny ", "Golden ", "Brutal ", "Deadly "};                   
         string[] legendaryNameEnd = new string[] { " of the Grandmaster", " of the Fallen Hero", " of the Living Legend", " of Greatness"};
 
         string[] legendaryStatTitle = new string[] { " of Swiftness", " of Fortune", " of Bloodthirst" };
 
 
 
         [SerializeField]
         private float maxStamina, maxEndurance, maxLuck, maxCool;
         private float minStamina, minEndurance, minLuck, minCool;
 
         private string randomPrefix, randomNameEnd;
 
         private string _itemTitle;
         public string ItemTitle { get { return _itemTitle; } set { _itemTitle = value; } }
 
         private float _powerLevel;
         public float PowerLevel { get { return _powerLevel; } set { _powerLevel = value; } }
 
         private float _stamina;
         public float Stamina { get { return _stamina; } set { _stamina = value; } }
 
         private float _endurance;
         public float Endurance { get { return _endurance; } set { _endurance = value; } }
 
         private float _luck;
         public float Luck { get { return _luck; } set { _luck = value; } }
 
         private float _cool;
         public float Cool { get { return _cool; } set { _cool = value; } }
 
         public float Level { get { return _ItemLevel; } set { _ItemLevel = value; } }
 
         [SerializeField]
         private float minDamage, maxDamage;
 
         private float _damage;
         public float Damage { get { return _damage; } set { _damage = value; } }
 
         [Space(10)] // 10 pixels of spacing here.
 
         [SerializeField]
         private float minDefence;
 
         [SerializeField]
         private float maxDefence;
 
         private float characterMinLevel, characterMaxLevel;
 
         private float _defence;
         public float Defence { get { return _defence; } set { _defence = value; } }
 
         [Space(10)] // 10 pixels of spacing here.
 
         //Rarity reference for the items
         [SerializeField]
         private RarityType _rarityType;
         public RarityType RarityType { get { return _rarityType; } set { _rarityType = value; } }
 
         [SerializeField]
         private WeaponType _weaponType;
         public WeaponType WeaponType { get { return _weaponType; } set { _weaponType = value; } }
 
         private WeaponItemData _weaponItemData;
         public WeaponItemData WeaponItemData { get { return _weaponItemData; } set { _weaponItemData = value; } }
 
         //Item ID for easy referencing
         [SerializeField]
         private int _id;
         public int ItemID { get { return _id; } set { _id = value; } }
 
         //Bool for stackable items
         [SerializeField]
         private bool _stackable;
         public bool Stackable { get { return _stackable; } protected set { _stackable = value; } }
 
         //Item type reference
         [SerializeField]
         private ItemType _itemType;
         public ItemType ItemType { get { return _itemType; } protected set { _itemType = value; } }
 
         //String for display name
         [SerializeField]
         private string _itemName;
         public string ItemName { get { return _itemName; } }
 
         //Sprite for display image
         [SerializeField]
         private Sprite _itemImage;
         public Sprite ItemImage { get { return _itemImage; } set { _itemImage = value; } }
 
         //Float for item weight
         [SerializeField]
         private float _itemWeight;
         public float ItemWeight { get { return _itemWeight; } }
 
         //String for item display description
         [SerializeField]
         private string _itemDescription;
         public string ItemDescription { get { return _itemDescription; } }
 
         //GameObject prefab to spawn when item is dropped
         [SerializeField]
         private GameObject _itemPrefab;
         public GameObject ItemPrefab { get { return _itemPrefab; } }
 
         private float legendaryExtraBonus = 1.4f;
         private float epicExtraBonus = 1.3f;
         private float rareExtraBonus = 1.2f;
         private float uncommonExtraBonus = 1.1f;
 
 
         //Create and return a new item from the existing data
         public Item CreateItem()
         {
 
             playerStats = GameObject.FindObjectOfType<PlayerStats>();
 
             Item item = new Item(this);
 
             Damage = Random.Range(minDamage, maxDamage * _ItemLevel);
             Defence = Random.Range(minDefence, maxDefence * _ItemLevel);
 
             Stamina = Random.Range(minStamina, maxStamina * _ItemLevel);
             Endurance = Random.Range(minEndurance, maxEndurance * _ItemLevel);
             Luck = Random.Range(minLuck, maxLuck * _ItemLevel);
             Cool = Random.Range(minCool, maxCool * _ItemLevel);
 
 
             characterMinLevel = playerStats.playerLevel - 1;
             characterMaxLevel = playerStats.playerLevel + 2;
             _ItemLevel = Random.Range(characterMinLevel, characterMaxLevel);
 
            
             if (_rarityType == RarityType.Legendary)
             {
                 Damage = Damage * legendaryExtraBonus;
                 randomPrefix = legendaryNamePrefix[Random.Range(0, legendaryNamePrefix.Length)];
                 randomNameEnd = legendaryNameEnd[Random.Range(0, legendaryNameEnd.Length)];
             }
 
             else if (_rarityType == RarityType.Epic)
             {
                 Damage = Damage * epicExtraBonus;
                 randomPrefix = epicNamePrefix[Random.Range(0, epicNamePrefix.Length)];
                 randomNameEnd = epicNameEnd[Random.Range(0, epicNameEnd.Length)];
             }
 
             else if (_rarityType == RarityType.Rare)
             {
                 Damage = Damage * rareExtraBonus;
                 randomPrefix = rareNamePrefix[Random.Range(0, rareNamePrefix.Length)];
                 randomNameEnd = rareNameEnd[Random.Range(0, rareNameEnd.Length)];
             }
 
             else if (_rarityType == RarityType.Uncommon)
             {
                 Damage = Damage * uncommonExtraBonus;
                 randomPrefix = uncommonNamePrefix[Random.Range(0, uncommonNamePrefix.Length)];
                 randomNameEnd = "";
             }
 
             else if(_rarityType == RarityType.Common)
             {
                 randomPrefix = commonNamePrefix[Random.Range(0, commonNamePrefix.Length)];
                 randomNameEnd = "";
             }
 
             PowerLevel = Stamina + Endurance + Luck + Cool + Damage + Defence;
 
             ItemTitle = randomPrefix + _itemName + randomNameEnd;
        
 
             return item;
         }
     }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
     public class EquipItemData : ItemData
     {
         //Reference for the equip type of the item
         [SerializeField]
         private EquipType _equipType;
         public EquipType EquipType { get { return _equipType; } set { _equipType = value; } }
 
         //Create and return a new equippable item from the existing data
         public EquippableItem CreateEquippableItem()
         {
             EquippableItem item = new EquippableItem(this);
             return item;
         }
     }
 
 
     //Item Class
     //Variables match the variables from ItemData
     [System.Serializable]
     public class Item
     {
             
         public string Name;
         public int ID;
         public bool Stackable;
         public float Weight;
         public Sprite Icon;
         public float Damage;
         public float Defence;
         public float ItemLevel;
         public string ItemTitle;
 
         public float Stamina;
         public float Endurance;
         public float Luck;
         public float Cool;
         public float PowerLevel;
 
         public float BaseCritChance;
         public float BaseItemFindChance;
         public float BaseMovementSpeed;
 
         public ItemType ItemType;
         public RarityType RarityType;
         public WeaponType WeaponType;
 
 
 
         
 
         public Item(ItemData item)
         {
 
             Name = item.ItemName;
             ID = item.ItemID;
             Stackable = item.Stackable;
             Weight = item.ItemWeight;
             Icon = item.ItemImage;
             ItemLevel = item.Level;
 
             Defence = item.Defence;
             Damage = item.Damage;
             RarityType = item.RarityType;
             ItemType = item.ItemType;
             Stamina = item.Stamina;
             Endurance = item.Endurance;
             Luck = item.Luck;
             Cool = item.Cool;
             PowerLevel = item.PowerLevel;
             WeaponType = item.WeaponType;
 
             ItemTitle = item.ItemTitle;
 
         }
     }
 
 
     //Equippable Item Class
     //Variables match those from EquippableItemData
     [System.Serializable]
     public class EquippableItem : Item
     {
         public EquipType EquipType;
 
         public EquippableItem(EquipItemData item) : base(item as ItemData)
         {
             EquipType = item.EquipType;
         }
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

119 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RPG ability database - Scriptable Object vs XML vs Prefab? 0 Answers

Save and load an inventory 0 Answers

How can i save the games inventory? 1 Answer

I need to find inventory and item system, and to save them 0 Answers

How do I program in an interactive journal? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges