Added Feel plugin
This commit is contained in:
47
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLoot.cs
vendored
Normal file
47
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLoot.cs
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using MoreMountains.Tools;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A class defining the contents of a MMLootTable
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class MMLoot<T>
|
||||
{
|
||||
/// the object to return
|
||||
public T Loot;
|
||||
/// the weight attributed to this specific object in the table
|
||||
public float Weight = 1f;
|
||||
/// the chance percentage to display for this object to be looted. ChancePercentages are meant to be computed by the MMLootTable class
|
||||
[MMReadOnly]
|
||||
public float ChancePercentage;
|
||||
|
||||
/// the computed low bound of this object's range
|
||||
public virtual float RangeFrom { get; set; }
|
||||
/// the computed high bound of this object's range
|
||||
public virtual float RangeTo { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// a MMLoot implementation for gameobjects
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootGameObject : MMLoot<GameObject> { }
|
||||
|
||||
/// <summary>
|
||||
/// a MMLoot implementation for strings
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootString : MMLoot<string> { }
|
||||
|
||||
/// <summary>
|
||||
/// a MMLoot implementation for floats
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootFloat : MMLoot<float> { }
|
||||
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLoot.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLoot.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae83134bbe174934c889c5969a608e7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMLoot/MMLoot.cs
|
||||
uploadId: 830868
|
||||
126
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTable.cs
vendored
Normal file
126
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTable.cs
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A loot table helper that can be used to randomly pick objects out of a weighted list
|
||||
/// This design pattern was described in more details by Daniel Cook in 2014 in his blog :
|
||||
/// https://lostgarden.home.blog/2014/12/08/loot-drop-tables/
|
||||
///
|
||||
/// This generic LootTable defines a list of objects to loot, each of them weighted.
|
||||
/// The weights don't have to add to a certain number, they're relative to each other.
|
||||
/// The ComputeWeights method determines, based on these weights, the chance percentage of each object to be picked
|
||||
/// The GetLoot method returns one object, picked randomly from the table
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="V"></typeparam>
|
||||
public class MMLootTable<T,V> where T:MMLoot<V>
|
||||
{
|
||||
/// the list of objects that have a chance of being returned by the table
|
||||
[SerializeField]
|
||||
public List<T> ObjectsToLoot;
|
||||
|
||||
/// the total amount of weights, for debug purposes only
|
||||
[Header("Debug")]
|
||||
[MMReadOnly]
|
||||
public float WeightsTotal;
|
||||
|
||||
protected float _maximumWeightSoFar = 0f;
|
||||
protected bool _weightsComputed = false;
|
||||
|
||||
/// <summary>
|
||||
/// Determines, for each object in the table, its chance percentage, based on the specified weights
|
||||
/// </summary>
|
||||
public virtual void ComputeWeights()
|
||||
{
|
||||
if (ObjectsToLoot == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ObjectsToLoot.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_maximumWeightSoFar = 0f;
|
||||
|
||||
foreach(T lootDropItem in ObjectsToLoot)
|
||||
{
|
||||
if(lootDropItem.Weight >= 0f)
|
||||
{
|
||||
lootDropItem.RangeFrom = _maximumWeightSoFar;
|
||||
_maximumWeightSoFar += lootDropItem.Weight;
|
||||
lootDropItem.RangeTo = _maximumWeightSoFar;
|
||||
}
|
||||
else
|
||||
{
|
||||
lootDropItem.Weight = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
WeightsTotal = _maximumWeightSoFar;
|
||||
|
||||
foreach(T lootDropItem in ObjectsToLoot)
|
||||
{
|
||||
lootDropItem.ChancePercentage = ((lootDropItem.Weight) / WeightsTotal) * 100;
|
||||
}
|
||||
|
||||
_weightsComputed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns one object from the table, picked randomly
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual T GetLoot()
|
||||
{
|
||||
if (ObjectsToLoot == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ObjectsToLoot.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!_weightsComputed)
|
||||
{
|
||||
ComputeWeights();
|
||||
}
|
||||
|
||||
float index = Random.Range(0, WeightsTotal);
|
||||
|
||||
foreach (T lootDropItem in ObjectsToLoot)
|
||||
{
|
||||
if ((index > lootDropItem.RangeFrom) && (index < lootDropItem.RangeTo))
|
||||
{
|
||||
return lootDropItem;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A MMLootTable implementation for GameObjects
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootTableGameObject : MMLootTable<MMLootGameObject, GameObject> { }
|
||||
|
||||
/// <summary>
|
||||
/// A MMLootTable implementation for floats
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootTableFloat : MMLootTable<MMLootFloat, float> { }
|
||||
|
||||
/// <summary>
|
||||
/// A MMLootTable implementation for strings
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class MMLootTableString : MMLootTable<MMLootString, string> { }
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTable.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTable.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e6301cb44b6ff94f98077ceb3446fe2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMLoot/MMLootTable.cs
|
||||
uploadId: 830868
|
||||
33
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTableGameObjectSO.cs
vendored
Normal file
33
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTableGameObjectSO.cs
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// A scriptable object containing a MMLootTable definition for game objects
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName="LootDefinition",menuName="MoreMountains/Loot Definition")]
|
||||
public class MMLootTableGameObjectSO : ScriptableObject
|
||||
{
|
||||
/// the loot table
|
||||
public MMLootTableGameObject LootTable;
|
||||
|
||||
/// returns an object from the loot table
|
||||
public virtual GameObject GetLoot()
|
||||
{
|
||||
return LootTable.GetLoot()?.Loot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// computes the loot table's weights
|
||||
/// </summary>
|
||||
public virtual void ComputeWeights()
|
||||
{
|
||||
LootTable.ComputeWeights();
|
||||
}
|
||||
|
||||
protected virtual void OnValidate()
|
||||
{
|
||||
ComputeWeights();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTableGameObjectSO.cs.meta
vendored
Normal file
18
Assets/External/Feel/MMTools/Foundation/MMLoot/MMLootTableGameObjectSO.cs.meta
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4627644fa4929f64a92e4d63b3a1a95e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 183370
|
||||
packageName: Feel
|
||||
packageVersion: 5.9.1
|
||||
assetPath: Assets/Feel/MMTools/Foundation/MMLoot/MMLootTableGameObjectSO.cs
|
||||
uploadId: 830868
|
||||
Reference in New Issue
Block a user