Post by Chronicman on Nov 3, 2016 22:40:50 GMT
This is a small item loot system that you attach to vItemCollection game objects. It will allow you to randomize the loot within the vItemCollection. You can generate the loot at start or on open using the new event system with 2.0 .
Set up:
#1 Copy and past this into a new scripted called vItemPercentContainer save and let unity compile.
#2 Add this component to any vItemCollection.
#3 Set up the items list you wish to drop.
#4 Either enable generate at start or using the new event system
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Invector.ItemManager;
namespace Invector.ItemManager
{
public class vItemPercentContainer : MonoBehaviour
{
public vItemCollection collection;
public bool GenerateOnStart;
[Header("You can search the vItemListData for all your Id's.")]
public List<vPercent> items = new List<vPercent>();
void Start()
{
gameObject.GetComponent<vItemCollection>();
if (GenerateOnStart)
{
GenerateLoot();
}
}
public void GenerateLoot()
{
for (int o = 0; o < items.Count; o++)
{
if (Random.Range(0, 1f) <= items[o].percent)
{
var itemRef = new ItemReference(items[o].id);
collection.items.Add(itemRef);
collection.items.Find(_item => _item.id == items[o].id).amount = items[o].amount;
}
}
}
[System.Serializable]
public class vPercent
{
[Tooltip("The name of the item, this will just clean up the element names.This does not need to filled in.")]
public string title;
[Tooltip("The id of the item you wish to give.")]
public int id;
[Tooltip("The amount of the item you wish to give.")]
[Range(1,100)]
public int amount;
[Range(0, 1f)]
public float percent;
}
}
}
Set up:
#1 Copy and past this into a new scripted called vItemPercentContainer save and let unity compile.
#2 Add this component to any vItemCollection.
#3 Set up the items list you wish to drop.
#4 Either enable generate at start or using the new event system
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Invector.ItemManager;
namespace Invector.ItemManager
{
public class vItemPercentContainer : MonoBehaviour
{
public vItemCollection collection;
public bool GenerateOnStart;
[Header("You can search the vItemListData for all your Id's.")]
public List<vPercent> items = new List<vPercent>();
void Start()
{
gameObject.GetComponent<vItemCollection>();
if (GenerateOnStart)
{
GenerateLoot();
}
}
public void GenerateLoot()
{
for (int o = 0; o < items.Count; o++)
{
if (Random.Range(0, 1f) <= items[o].percent)
{
var itemRef = new ItemReference(items[o].id);
collection.items.Add(itemRef);
collection.items.Find(_item => _item.id == items[o].id).amount = items[o].amount;
}
}
}
[System.Serializable]
public class vPercent
{
[Tooltip("The name of the item, this will just clean up the element names.This does not need to filled in.")]
public string title;
[Tooltip("The id of the item you wish to give.")]
public int id;
[Tooltip("The amount of the item you wish to give.")]
[Range(1,100)]
public int amount;
[Range(0, 1f)]
public float percent;
}
}
}