-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
270 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//using Bolt.Community.Addons.Utility; | ||
//using Ludiq; | ||
//using System; | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
//using System.Text; | ||
|
||
//namespace Bolt.Addons.Community.Fundamentals.Units.Documenting | ||
//{ | ||
// [UnitCategory("Community\\Documentation")] | ||
// [UnitShortTitle("Make Game")] | ||
// [UnitTitle("Make Game")] | ||
// public class MakeGame : Unit | ||
// { | ||
|
||
// [UnitHeaderInspectable] | ||
// [UnitButton("TriggerButton")] | ||
// public UnitButton go; | ||
|
||
|
||
// /// <summary> | ||
// /// The action to execute if the condition is true. | ||
// /// </summary> | ||
// [DoNotSerialize] | ||
// [PortLabel("Success!")] | ||
// public ControlOutput success { get; private set; } | ||
|
||
|
||
|
||
// /// <summary> | ||
// /// The action to execute if the condition is true. | ||
// /// </summary> | ||
// [DoNotSerialize] | ||
// [PortLabel("Give Up")] | ||
// public ControlOutput giveUp { get; private set; } | ||
|
||
|
||
|
||
// /// <summary> | ||
// /// The action to execute if the condition is true. | ||
// /// </summary> | ||
// [DoNotSerialize] | ||
// [PortLabel("Why is this so hard?")] | ||
// public ControlOutput hard { get; private set; } | ||
|
||
|
||
// /// <summary> | ||
// /// The action to execute if the condition is true. | ||
// /// </summary> | ||
// [DoNotSerialize] | ||
// [PortLabel("There's a button for this?")] | ||
// public ControlOutput button { get; private set; } | ||
|
||
|
||
// /// <summary> | ||
// /// The action to execute if the condition is true. | ||
// /// </summary> | ||
// [DoNotSerialize] | ||
// [PortLabel("I can haz MMORPG?")] | ||
// public ControlOutput mmorpg { get; private set; } | ||
|
||
// protected override void Definition() | ||
// { | ||
// success = ControlOutput(nameof(success)); | ||
// giveUp = ControlOutput(nameof(giveUp)); | ||
// hard = ControlOutput(nameof(hard)); | ||
// button = ControlOutput(nameof(button)); | ||
// mmorpg = ControlOutput(nameof(mmorpg)); | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
using Ludiq; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace Bolt.Addons.Community.Fundamentals | ||
{ | ||
/// <summary> | ||
/// Returns a list of random numbers from the specified range. | ||
/// </summary> | ||
[UnitCategory("Community\\Collections\\Lists")] | ||
[UnitTitle("Random Numbers")] | ||
[TypeIcon(typeof(IList))] | ||
[UnitOrder(20)] | ||
public class RandomNumbersv2 : Unit | ||
{ | ||
public RandomNumbersv2() : base() { } | ||
|
||
/// <summary> | ||
/// Flow In | ||
/// </summary> | ||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ControlInput input { get; private set; } | ||
|
||
[DoNotSerialize] | ||
public ValueInput count { get; private set; } | ||
|
||
[DoNotSerialize] | ||
public ValueInput minimum { get; private set; } | ||
|
||
[DoNotSerialize] | ||
public ValueInput maximum { get; private set; } | ||
|
||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ValueOutput output { get; private set; } | ||
|
||
|
||
//Flow Out | ||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ControlOutput exit { get; private set; } | ||
|
||
/// <summary> | ||
/// Whether the compared inputs are numbers. | ||
/// </summary> | ||
[Serialize] | ||
[Inspectable] | ||
[InspectorToggleLeft] | ||
public bool integer { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Whether the compared inputs are numbers. | ||
/// </summary> | ||
[Serialize] | ||
[Inspectable] | ||
[InspectorToggleLeft] | ||
public bool aotList { get; set; } = false; | ||
|
||
|
||
/// <summary> | ||
/// Whether the compared inputs are numbers. | ||
/// </summary> | ||
[Serialize] | ||
[Inspectable] | ||
[InspectorToggleLeft] | ||
public bool unique { get; set; } = true; | ||
|
||
|
||
// IList _list = new List<object>(); | ||
IList _list; | ||
|
||
protected override void Definition() | ||
{ | ||
input = ControlInput(nameof(input), x => Enter(x)); | ||
count = ValueInput<int>(nameof(count), 10); | ||
exit = ControlOutput(nameof(exit)); | ||
|
||
if (integer) | ||
{ | ||
minimum = ValueInput<int>(nameof(minimum), 0); | ||
maximum = ValueInput<int>(nameof(maximum), 100); | ||
output = ValueOutput<IList>(nameof(output), (x) => { if (_list == null) BuildList(x); return _list; }); | ||
} | ||
else | ||
{ | ||
minimum = ValueInput<float>(nameof(minimum), 0); | ||
maximum = ValueInput<float>(nameof(maximum), 100); | ||
output = ValueOutput<IList>(nameof(output), (x) => { if (_list == null) BuildList(x); return _list; }); | ||
} | ||
|
||
Succession(input, exit); | ||
|
||
Requirement(count, input); | ||
Requirement(minimum, input); | ||
|
||
Requirement(count, output); | ||
Requirement(minimum, output); | ||
} | ||
|
||
private void BuildList(Flow flow) | ||
{ | ||
int num = flow.GetValue<int>(count); | ||
|
||
ManageList(num); | ||
|
||
if (integer) | ||
{ | ||
int min = flow.GetValue<int>(minimum); | ||
int max = flow.GetValue<int>(maximum); | ||
|
||
//If we need unique integers, we have to ensure there are enough choices | ||
if (unique) | ||
if (max - min < num) | ||
{ | ||
throw new ArgumentException("Random Number generation failed. Unique range is too small for the number of elements specified."); | ||
} | ||
|
||
PopulateList(unique, num, _list, () => { return UnityEngine.Random.Range(min, max); }); | ||
} | ||
else | ||
{ | ||
|
||
float min = flow.GetValue<float>(minimum); | ||
float max = flow.GetValue<float>(maximum); | ||
PopulateList(unique, num, _list, () => { return UnityEngine.Random.Range(min, max); }); | ||
} | ||
|
||
} | ||
|
||
private void ManageList(int num) | ||
{ | ||
if (_list == null) | ||
{ | ||
if (aotList) | ||
{ | ||
_list = new AotList(num); | ||
} | ||
else | ||
{ | ||
if (integer) | ||
_list = new List<object>(num); | ||
} | ||
} | ||
|
||
_list.Clear(); | ||
} | ||
|
||
private void PopulateList<T>(bool unique, int count, IList list, Func<T> p) | ||
{ | ||
HashSet<T> uniqueNumbers = new HashSet<T>(); | ||
|
||
while (list.Count < count) | ||
{ | ||
T newNumber = p(); | ||
if (unique) | ||
{ | ||
if (!uniqueNumbers.Contains(newNumber)) | ||
{ | ||
uniqueNumbers.Add(newNumber); | ||
list.Add(newNumber); | ||
} | ||
} | ||
else | ||
list.Add(newNumber); | ||
} | ||
} | ||
|
||
private ControlOutput Enter(Flow flow) | ||
{ | ||
BuildList(flow); | ||
return exit; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters