Class DropTable
Container for your drops and configurations of how to drop things
Fields
OnGlobalModified
Declaration
public static Action<ModifiedContext> OnGlobalModified
Field Value
Type | Description |
---|---|
System.Action<ModifiedContext> |
OnGlobalModify
Declaration
public static Action<ModifyContext> OnGlobalModify
Field Value
Type | Description |
---|---|
System.Action<ModifyContext> |
OnLocalModified
Declaration
public Action<ModifiedContext> OnLocalModified
Field Value
Type | Description |
---|---|
System.Action<ModifiedContext> |
OnLocalModify
Declaration
public Action<ModifyContext> OnLocalModify
Field Value
Type | Description |
---|---|
System.Action<ModifyContext> |
Properties
Description
Table description
Declaration
public string Description { get; set; }
Icon
Provide an icon to the table.
It`s normally used when you want to list the table as a drop in some list.
Declaration
public Sprite Icon { get; set; }
PercentageCalculation
This decides the method used to calculate the drops percentage.
You can get more info about different calculations methods on PercentageCalculation
Declaration
public PercentageCalculation PercentageCalculation { get; set; }
Methods
AddDrop(Drop)
Declaration
public void AddDrop(Drop drop)
AddFilter(Predicate<Drop>)
Declaration
[Obsolete("Use OnTableFilter instead")]
public void AddFilter(Predicate<Drop> filter)
AddFilterToDrops(Predicate<Drop>, Predicate<Drop>)
Declaration
public void AddFilterToDrops(Predicate<Drop> dropsGroup, Predicate<Drop> filter)
Clone()
Declaration
public DropTable Clone()
CustomDrop(Int32, Func<List<Drop>, Bag>, Action<DroppingContext>, Action<DroppedContext>)
Declaration
public Bag CustomDrop(int numberOfDrops = 1, Func<List<Drop>, Bag> customDropBehaviour = null, Action<DroppingContext> beforeDropCallback = null, Action<DroppedContext> afterDropCallback = null)
CustomEnumerator(Filter)
Here you can specify what kind of drops that you want to receive, take a look at Filter on documentation
Declaration
public IEnumerable<Drop> CustomEnumerator(Filter settings)
Drop(Int32)
API to request a drop
Declaration
public Bag Drop(int n = 1)
GetEnumerator()
Declaration
public IEnumerator<Drop> GetEnumerator()
Load(DropTableSaveData, LoadParams)
This overload will use deserialize callbacks passed via loadParams to find and clone your table and create your drops
Declaration
public static DropTable Load(DropTableSaveData data, LoadParams loadParams)
Parameters
Type | Name | Description |
---|---|---|
DropTableSaveData | data | Deserialized data |
Loot.Params.LoadParams | loadParams | Callbacks to recovery your table and drops |
Returns
Type | Description |
---|---|
DropTable | A clone of the table recovered by load params deserialize table |
Remarks
Note
Your table will be cloned inside this method, so just pass a way to recovery original table
Examples
Note
This example came from Save/Load demo scene with minor modification
public void Load()
{
// We will get our saved JSON from file and remove the possible pretty print
var savedJson = "";
using (var sr = new StreamReader(Application.persistentDataPath + "/save.json"))
{
var line = "";
while ((line = sr.ReadLine()) != null)
savedJson += line;
}
// Create our data var savedData = JsonUtility.FromJson<DropTableSaveData>(savedJson);
// Then we recovery our table // In this case our tables and items are being stored by resources tableOwner.runtimeTable = DropTable.Load(savedData, new LoadParams { deserializeTable = tableName => Resources .Load<DropTable>("Tables/" + tableName),
deserializeEntry = entryName => string.IsNullOrWhiteSpace(entryName)
? null
: Resources.Load<ScriptableObject>("Items/" + entryName)
}); }
Load(DropTable, DropTableSaveData)
This overload will load only values from your saved data, this means that addictive operations (drops that can't be recovered from your original table at runtime) will not be loaded
Declaration
public static void Load(DropTable runtimeTable, DropTableSaveData data)
Parameters
Type | Name | Description |
---|---|---|
DropTable | runtimeTable | Drop table that will receive the loaded values |
DropTableSaveData | data | Deserialized data |
Remarks
Warning
As remove drops isn't considered a destructive operation, this will compare entries in your data with drops in your runtime table and if their entry name does not match drop will be removed
Examples
Note
This example came from Save/Load demo scene with minor modification
public void Load()
{
// Get our saved string from file and remove the possible pretty print
var savedJson = "";
using (var sr = new StreamReader(Application.persistentDataPath + "/simplestSave.json"))
{
var line = "";
while ((line = sr.ReadLine()) != null)
savedJson += line;
}
// Load from json var loadedData = JsonUtility.FromJson<DropTableSaveData>(savedJson);
// Here we will pass recovered data for our runtime table DropTable.Load(runtimeTable, loadedData); }
Exceptions
Type | Condition |
---|---|
System.ComponentModel.WarningException | If you try to change values in a table that isn't a clone |
MultipleDrop(Int32)
Declaration
[Obsolete("Use Drop passing a parameter N instead")]
public Bag MultipleDrop(int n)
RawEnumerator()
This enumerator will provide you the original drops that you see in the inspector, including hidden drops without open the extensions and not applying any modify or filter. [WARNING] Be careful as this returns to you the actual drops list, so changes on it will be permanent.
Declaration
public IEnumerable<Drop> RawEnumerator()
RemoveAllTableFilters()
Clean filters from this table
Declaration
public void RemoveAllTableFilters()
RemoveDrop(Drop)
Declaration
public void RemoveDrop(Drop drop)
RemoveDrop(Predicate<Drop>)
Declaration
public void RemoveDrop(Predicate<Drop> predicate)
Save(DropTable)
Convert your table to a serializable structure that can be saved
Declaration
public static DropTableSaveData Save(DropTable tableToSerialize)
Parameters
Type | Name | Description |
---|---|---|
DropTable | tableToSerialize | Table that will be serialized |
Returns
Type | Description |
---|---|
DropTableSaveData | The structure ready to be saved in your disk |
Remarks
Warning
Your modifiers and filters will not be saved
Examples
Note
This example came from Save/Load demo scene with minor modification
public void Save()
{
// Convert our table to save data
var saveData = DropTable.Save(runtimeTable);
// Create JSON var saveJson = JsonUtility.ToJson(saveData, true);
// Then save it as you normally do when using things json using (var sw = new StreamWriter(Application.persistentDataPath + "/save.json")) { sw.Write(saveJson); } }
Save(DropTable, SaveParams)
This override will receive a SaveParams to allow you to inform how we should serialize your original table and/or drops, so you will be able to use this information to recovery table state in load methods
Declaration
public static DropTableSaveData Save(DropTable tableToSerialize, SaveParams saveParams)
Parameters
Type | Name | Description |
---|---|---|
DropTable | tableToSerialize | Table that will be serialized |
Loot.Params.SaveParams | saveParams | Class the contains your methods to transform table and drop into something serializable |
Returns
Type | Description |
---|---|
DropTableSaveData | The structure ready to be saved in your disk |
Remarks
Warning
Your modifiers and filters will not be saved
Note
Fields inside SaveParams are optional
Examples
Note
This example came from Save/Load demo scene with minor modification
public void Save()
{
// As this will suppose that destructive operations was done in our table, lets use a Save
// override that allow us to recover table (for modifiers) and new entries
var savedData = DropTable.Save(runtimeTable, new SaveParams
{
serializeTable = () => templateTable.name, // Serialize our base table by name
serializeEntry = drop => drop.Entry == null // Serialize each drop by name too
? string.Empty
: drop.Entry.name
});
// Convert it to JSON var savedJson = JsonUtility.ToJson(savedData, true);
// Then save it using (var sw = new StreamWriter(Application.persistentDataPath + "/save.json")) { sw.Write(savedJson); } }
SumOfWeights()
This will open extensions, remove hidden, remove duplications apply modifiers and filters and THEN give the sum of weight to you
Declaration
public int SumOfWeights()
Returns
Type | Description |
---|---|
System.Int32 | The sum of drop`s weight |
Events
OnDropped
Declaration
public event Action<DroppedContext> OnDropped
Event Type
Type | Description |
---|---|
System.Action<DroppedContext> |
OnDropping
Declaration
public event Action<DroppingContext> OnDropping
Event Type
Type | Description |
---|---|
System.Action<DroppingContext> |
OnTableFilter
This will be called when iterating over the list to filter it
Declaration
public event Predicate<Drop> OnTableFilter
Event Type
Type | Description |
---|---|
System.Predicate<Drop> |
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()