Skip to content

Instantly share code, notes, and snippets.

@suakig
Created April 17, 2015 13:19
Show Gist options
  • Save suakig/bea0eafdb67773ed07eb to your computer and use it in GitHub Desktop.
Save suakig/bea0eafdb67773ed07eb to your computer and use it in GitHub Desktop.
RatePickerSample.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RatePickerSample : MonoBehaviour {
public enum ColorKey : int{
Red,
Blue,
Green,
None,
}
RatePicker<ColorKey> ratePicker;
Dictionary<ColorKey, int> itemMap = new Dictionary<ColorKey, int>();
[Range(0, 100)] public int redRate;
[Range(0, 100)] public int blueRate;
[Range(0, 100)] public int greenRate;
[Range(0, 100)] public int noneRate;
public int maxCreateCount = 1000;
void Start ()
{
itemMap.Add (ColorKey.Red, redRate);
itemMap.Add (ColorKey.Blue, blueRate);
itemMap.Add (ColorKey.Green,greenRate);
itemMap.Add (ColorKey.None, noneRate);
ratePicker = new RatePicker<ColorKey> (itemMap);
DebugTest ();
}
void DebugTest()
{
int[] result = new int[4];
if (!ratePicker.PickeAble ()) {
Debug.Log (
"ColorKey.Red___:" + result [0].ToString().PadLeft(15)+ "\n" +
"ColorKey.Blue__:" + result [1].ToString().PadLeft(15)+ "\n" +
"ColorKey.Green_:" + result [2].ToString().PadLeft(15)+ "\n" +
"ColorKey.None__:" + result [3].ToString().PadLeft(15)+ "\n"
);
return;
}
for (int i = 0; i < maxCreateCount; i++) {
switch (ratePicker.PickeRate ()) {
case ColorKey.Red: result [0]++; break;
case ColorKey.Blue: result [1]++; break;
case ColorKey.Green: result [2]++; break;
case ColorKey.None: result [3]++; break;
}
}
Debug.Log (
"ColorKey.Red___:" + result [0].ToString().PadLeft(15)+ "\n" +
"ColorKey.Blue__:" + result [1].ToString().PadLeft(15)+ "\n" +
"ColorKey.Green_:" + result [2].ToString().PadLeft(15)+ "\n" +
"ColorKey.None__:" + result [3].ToString().PadLeft(15)+ "\n"
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment