Created
April 17, 2015 13:19
-
-
Save suakig/bea0eafdb67773ed07eb to your computer and use it in GitHub Desktop.
RatePickerSample.cs
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
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