/// <summary> /// Check if there all dice have stopped rolling /// </summary> public static bool IsRolling() { bool Die1roll = true; bool Die2roll = true; RollingDie rDie1 = null; RollingDie rDie2 = null; //verifico se uno dei 2 dadi si è fermato if (rollingDice.Count > 0) { rDie1 = (RollingDie)rollingDice[0]; rDie2 = (RollingDie)rollingDice[1]; if (!rDie1.rolling && Die1roll == true) { Die1roll = false; } if (!rDie2.rolling && Die2roll == true) { Die2roll = false; } } //se entrambi i dadi si sono fermati, svuoto l'array if (Die1roll == false && Die2roll == false) { rollingDice.Remove(rDie2); rollingDice.Remove(rDie1); } return(rollingDice.Count > 0); }
public string GetResultsString() { if (allDice.Count == 0) { return(string.Empty); } sb.Length = 0; sb.Append("Results: "); // assemble status of specific dieType bool hasValue = false; for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; if (hasValue) { sb.Append(" + "); } // if the value of the die is 0 , no value could be determined // this could be because the die is rolling or is in a invalid position sb.Append(rDie.die.value == 0 ? "?" : rDie.die.value.ToString()); hasValue = true; } sb.Append(" = "); sb.Append(Value()); return(sb.ToString()); }
// Update is called once per frame void Update() { // we want to update thrownDice once per throw, otherwise we will get new references to the dice each frame: if (Dice.rolling && !newThrow) { newThrow = true; } if (!Dice.rolling && newThrow) { thrownDice = Dice.GetAllDice(); newThrow = false; } scoreController.UpdateSelectedScore(thrownDice); scoreController.UpdateSelectable(thrownDice); // Handle input from dice being clicked: if (Input.GetMouseButtonDown(0) && !Dice.rolling && !Parameters.AIPlaying) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 1000.0f)) { if (hit.transform && hit.transform.gameObject.tag == "Dice") { RollingDie die = GetRollingDie(hit.transform.gameObject); dieSelector.OnClick(die, thrownDice, scoreController.NumberOfDuplicates(die.value, thrownDice)); } } } // update number of selected dice: noOfSelected = 0; if (!firstThrow) { foreach (RollingDie die in thrownDice) { if (die.selected) { noOfSelected++; } } } if (!CanPlay() && !Dice.rolling) { SetFail(); } // If we have marked a fail wrongly, redeem it: else if (failedThrow) { ResetFail(); } // Sometimes there is a bug that markes a single die throw as fail before it has time to start rolling, this should stop that: if (Dice.rolling && failedThrow) { ResetFail(); } }
/// <summary> /// Roll one or more dice with a specific material from a spawnPoint and give it a specific force. /// format dice : ({count}){die type} , exmpl. d6, 4d4, 12d8 , 1d20 /// possible die types : d4, d6, d8 , d10, d12, d20 /// </summary> public static void Roll(string dice, string mat, Vector3 spawnPoint, Vector3 force) { rolling = true; // sotring dice to lowercase for comparing purposes dice = dice.ToLower(); int count = 1; string dieType = "d6"; // 'd' must be present for a valid 'dice' specification int p = dice.IndexOf("d"); if (p >= 0) { // check if dice starts with d, if true a single die is rolled. // dice must have a count because dice does not start with 'd' if (p > 0) { // extract count string[] a = dice.Split('d'); count = System.Convert.ToInt32(a[0]); // get die type if (a.Length > 1) { dieType = "d" + a[1]; } else { dieType = "d6"; } } else { dieType = dice; } // instantiate the dice for (int d = 0; d < count; d++) { // randomize spawnPoint variation spawnPoint.x = spawnPoint.x - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; // create the die prefab/gameObject GameObject die = prefab(dieType, spawnPoint, Vector3.zero, Vector3.one, mat); // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die, dieType, mat, spawnPoint, force); allDice.Add(rDie); die.SetActive(true); // apply the force impuls die.GetComponent <Rigidbody>().AddForce((Vector3)rDie.force, ForceMode.Impulse); // apply a random torque die.GetComponent <Rigidbody>().AddTorque(new Vector3(-50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude), ForceMode.Impulse); } } }
/// <summary> /// Roll one or more dice with a specific material from a spawnPoint and give it a specific force. /// format dice : ({count}){die type} , exmpl. d6, 4d4, 12d8 , 1d20 /// possible die types : d4, d6, d8 , d10, d12, d20 /// </summary> public static int Roll(string dice, string mat, Vector3 spawnPoint, Vector3 force) { rolling = true; // sotring dice to lowercase for comparing purposes dice = dice.ToLower(); int count = 1; string dieType = "d6"; // 'd' must be present for a valid 'dice' specification int p = dice.IndexOf("d"); if (p >= 0) { // check if dice starts with d, if true a single die is rolled. // dice must have a count because dice does not start with 'd' if (p > 0) { // extract count string[] a = dice.Split('d'); count = System.Convert.ToInt32(a[0]); // get die type if (a.Length > 1) { dieType = "d" + a[1]; } else { dieType = "d6"; } } else { dieType = dice; } throwCounter++; // instantiate the dice for (int d = 0; d < count; d++) { // randomize spawnPoint variation spawnPoint.x = spawnPoint.x - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; // create the die prefab/gameObject GameObject die = prefab(dieType, spawnPoint, Vector3.zero, new Vector3(0.2f, 0.2f, 0.2f), mat, throwCounter); // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // inactivate this gameObject because activating it will be handeled using the rollQueue and at the apropriate time die.SetActive(false); // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die, dieType, mat, spawnPoint, force); // add RollingDie to allDices allDice.Add(rDie); // add RollingDie to the rolling queue rollQueue.Add(rDie); } return(throwCounter); } return(0); }
/// <summary> /// Get rolling status of all ( dieType = "" ) dice or dieType specific dice. /// </summary> public static string AsString(string dieType, int throwId) { // count the dice string v = "" + Count(dieType, throwId); if (v == "0") { //Debug.Log("B³¹d"); } if (dieType == "") { v += " dice | "; } else { v += dieType + " : "; } if (dieType == "") { // no dieType specified to cumulate values per dieType ( if they are available ) if (Count("d6", throwId) > 0) { v += AsString("d6", throwId) + " | "; } if (Count("d10", throwId) > 0) { v += AsString("d10", throwId) + " | "; } } else { // assemble status of specific dieType bool hasValue = false; for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; // check type if ((rDie.name == dieType || dieType == "") && rDie.die.throwId == throwId) { if (hasValue) { v += " + "; } // if the value of the die is 0 , no value could be determined // this could be because the die is rolling or is in a invalid position v += "" + ((rDie.die.value == 0) ? "?" : "" + rDie.die.value); hasValue = true; } } v += " = " + Value(dieType); } return(v); }
public static int getSomma() { int ritorno = 0; for (int d = 0; d < allDice.Count; d++) { RollingDie dado = (RollingDie)allDice[d]; ritorno += dado.die.value; } return(ritorno); }
/// <summary> /// Get value of all ( dieType = "" ) dice or dieType specific dice. /// </summary> public static int Value() { int v = 0; // loop all dice for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; v += rDie.die.value; } return(v); }
public void OnClick(RollingDie die, ArrayList thrownDice, int duplicates) { if (die.selectable) { if (die.selected) { DeselectDie(die, thrownDice); } else { SelectDie(die, duplicates, thrownDice); } } }
public static string AsString_edit(string dieType) { // count the dice string v = ""; // assemble status of specific dieType for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; v += "" + ((rDie.die.value == 0) ? "?" : "" + rDie.die.value); } //v += " = " + Value(dieType); return(v); }
// Количество всех выброшенных кубиков или количество выброшенных кубиков определенного типа public static int Count(string dieType) { int v = 0; for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; if (rDie.name == dieType || dieType == "") { v++; } } return(v); }
/// <summary> /// Get rolling status of all ( dieType = "" ) dice or dieType specific dice. /// </summary> public static string AsString(string dieType) { // count the dice string v = "" + Count(dieType); //주사위의 총 갯수 if (dieType == "") //빈간으로 들어왔으면 그냥 주사위의 갯수를 출력할 문자열에 추가 { v += " dice | "; } else { v += dieType + " : "; //아니면 특정 이름, 주사위의 정보를 문자열에 추가 } if (dieType == "") //재귀로 자기 자신을 다시 부름 { // no dieType specified to cumulate values per dieType ( if they are available ) if (Count("d6") > 0) { v += AsString("d6") + " | "; } if (Count("d10") > 0) { v += AsString("d10") + " | "; //이렇게 해서 d6, d10의 총합을 알 수 있음 해당 로직은 아래 else문에 있는듯 } } else { // assemble status of specific dieType bool hasValue = false; for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; // check type if (rDie.name == dieType || dieType == "") { if (hasValue) { v += " + "; } // if the value of the die is 0 , no value could be determined // this could be because the die is rolling or is in a invalid position v += "" + ((rDie.die.value == 0) ? "?" : "" + rDie.die.value); hasValue = true; } } v += " = " + Value(dieType); } return(v); }
public static bool Valid() { bool valido = false; // loop rollingDice for (int d = 0; d < allDice.Count; d++) { RollingDie dado = (RollingDie)allDice[d]; if (dado.die.value == 0) { valido = false; break; } } return(valido); }
/// <summary> /// Get number of all ( dieType = "" ) dice or dieType specific dice. /// </summary> public static int Count(string dieType, int throwId) { int v = 0; // loop all dice for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; // check the type if ((rDie.name == dieType || dieType == "") && throwId == rDie.die.throwId) { v++; } } return(v); }
/// <summary> /// Get value of all ( dieType = "" ) dice or dieType specific dice. /// </summary> public static int Value(string dieType) { int v = 0; // loop all dice for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; // check the type if (rDie.name == dieType || dieType == "") { v += rDie.die.value; } } return(v); }
// Определяет для всех кубиков или кубиков определенного типа, остановились ли они и имеют ли допустимое значение public static bool IsStopped(string dieType) { if (allDice.Count == 0) { return(false); } for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; if ((!rDie.onGround || rDie.value == 0 || rDie.rolling) && (rDie.name == dieType || dieType == "")) { return(false); } } return(true); }
public void SelectDie(RollingDie die, int duplicates, ArrayList thrownDice) { // Select the clicked die: Highlight(die); die.selected = true; // See if it is a triple and not a 1 or 5: if (die.value != 1 && die.value != 5 && duplicates >= 3) { SelectTriple(die, thrownDice); } // See if it is a straight and not a 1 or 5: if (die.value != 1 && die.value != 5 && die.straight) { SelectStraight(thrownDice); } }
/*public void SelectDie(RollingDie die) { * // Select the clicked die: * if (die.selectable) * { * Highlight(die); * die.selected = true; * } * }//*/ private void DeselectDie(RollingDie die, ArrayList thrownDice) { DeHighlight(die); die.selected = false; // See if it is a triple and not a one or a five: if (die.value != 1 && die.value != 5 && die.triple) { DeselectTriple(die.value, thrownDice); } // See if it is a straight: (Even if it is a one or a five we must //deselect the entire straight, since the other values cannot be //selected without all being selected) if (die.straight) { DeselectStraight(thrownDice); } }
/// <summary> /// Update is called once per frame /// </summary> void Update() { if (rolling) { // there are dice rolling so increment rolling time rollTime += Time.deltaTime; // check rollTime against rollSpeed to determine if a die should be activated ( if one available in the rolling queue ) if (rollQueue.Count > 0 && rollTime > rollSpeed) { // get die from rolling queue RollingDie rDie = (RollingDie)rollQueue[0]; GameObject die = rDie.gameObject; // activate the gameObject die.active = true; // apply the force impuls die.rigidbody.AddForce((Vector3)rDie.force, ForceMode.Impulse); // apply a random torque die.rigidbody.AddTorque(new Vector3(-50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude), ForceMode.Impulse); // add die to rollingDice rollingDice.Add(rDie); // remove the die from the queue rollQueue.RemoveAt(0); canc = true; // reset rollTime so we can check when the next die has to be rolled rollTime = 0; } else if (rollQueue.Count == 0) { //if (canc) //{ // canc = false; //} // roll queue is empty so if no dice are rolling we can set the rolling attribute to false if (!IsRolling()) { rolling = false; GameObject.Find("app").GetComponent <AppDemo>().roll = true; } } } }
public static void RollDie(Die die, Vector3 spawnPoint, Vector3 force) { string dieType = "d6"; rolling = true; // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // inactivate this gameObject because activating it will be handeled using the rollQueue and at the apropriate time die.gameObject.SetActive(false); Vector3 spawnRnd = new Vector3(Random.value * 2.0f - 1.0f, Random.value * 2.0f - 1.0f, Random.value * 2.0f - 1.0f); die.transform.position = spawnPoint + spawnRnd; // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die.gameObject, dieType, "d6-red", spawnPoint, force); // add RollingDie to allDices allDice.Add(rDie); // add RollingDie to the rolling queue rollQueue.Add(rDie); }
// Определяет для всех кубиков или кубиков определенного типа, движутся ли они public static bool IsRolling(string dieType) { int d = 0; while (d < rollingDice.Count) { // Если кубик не движется, то удалим его из rollingDice RollingDie rDie = (RollingDie)rollingDice[d]; if (!rDie.rolling) { rollingDice.Remove(rDie); } else if (rDie.name == dieType || dieType == "") { d++; } } return(rollingDice.Count > 0); }
private void SelectTriple(RollingDie clickedDie, ArrayList thrownDice) { // mark the clicked die as a part if the triple: clickedDie.triple = true; // There is one die selected already: int selected = 1; foreach (RollingDie die in thrownDice) { // Select the die if we have less than 3 selected, it is not the already selected one, and the die is of the same value: if (selected < 3 && die != clickedDie && die.value == clickedDie.value) { // This is not done using the SelectDie(RollingDie die) function since that would cause an inf loop. Highlight(die); die.selected = true; die.triple = true; selected++; } } }
/// <summary> /// Update is called once per frame /// </summary> void Update() { if (rolling) { // there are dice rolling so increment rolling time rollTime += Time.deltaTime; // check rollTime against rollSpeed to determine if a die should be activated ( if one available in the rolling queue ) DetermineRollQueueValues(); // what were the values of each die after rolling? if (rollQueue.Count > 0 && rollTime > rollSpeed) { // get die from rolling queue RollingDie rDie = (RollingDie)rollQueue[0]; GameObject die = rDie.gameObject; // activate the gameObject die.SetActive(true); // apply the force impuls die.GetComponent <Rigidbody>().AddForce((Vector3)rDie.force, ForceMode.Impulse); // apply a random torque die.GetComponent <Rigidbody>().AddTorque(new Vector3(-50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude), ForceMode.Impulse); // add die to rollingDice rollingDice.Add(rDie); // remove the die from the queue rollQueue.RemoveAt(0); // reset rollTime so we can check when the next die has to be rolled rollTime = 0; } else if (rollQueue.Count == 0) { // roll queue is empty so if no dice are rolling we can set the rolling attribute to false if (!IsRolling()) { rolling = false; if (allDice.Count > 0) { DiceCup.StopRolling(); } } } } }
public static bool Equals() { bool ritorno = false; for (int d = 1; d < allDice.Count; d++) { RollingDie dado1 = (RollingDie)allDice[d]; RollingDie dado2 = (RollingDie)allDice[d - 1]; if (dado1.die.value == dado2.die.value) { ritorno = true; } else { ritorno = false; } } return(ritorno); }
/// <summary> /// Check if there all dice have stopped rolling /// </summary> private bool IsRolling() { int d = 0; // loop rollingDice while (d < rollingDice.Count) { // if rolling die no longer rolling , remove it from rollingDice RollingDie rDie = (RollingDie)rollingDice[d]; if (!rDie.rolling) { rollingDice.Remove(rDie); } else { d++; } } // return false if we have no rolling dice return(rollingDice.Count > 0); }
/// <summary> /// Get value of all ( dieType = "" ) dice or dieType specific dice. /// </summary> /// 1 public static int Value(string dieType) { int v = 0; // loop all dice for (int d = 0; d < allDice.Count; d++) { RollingDie rDie = (RollingDie)allDice[d]; RollingDie compare2dices1 = (RollingDie)allDice[0]; RollingDie compare2dices2 = (RollingDie)allDice[1]; AppDemo.dice1Value = compare2dices1.die.value; AppDemo.dice2Value = compare2dices2.die.value; // check the type if (rDie.name == dieType || dieType == "") { v += rDie.die.value; } } // AppDemo.PlayerTileNumber= AppDemo.PlayerTileNumber+v; return(v); }
// Бросает кубик из точки spawnPoint c силой force public static void Roll(string dice, Vector3 spawnPoint, Vector3 force) { rolling = true; // Случайная точка создания кубика, +-1 юнит от spawnPoint spawnPoint.x = spawnPoint.x - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; spawnPoint.z = spawnPoint.z - 1 + Random.value * 2; // Создаем кубик из префаба GameObject die = prefab(dice, spawnPoint, Vector3.zero, Vector3.one /*, mat*/); // Случайный вектор вращения die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // Деактивируем объект. Но будет активорован после задержки, когда наступит его очередь die.SetActive(false); // Создаем экземпляр вспомогательного класса, который содержит всю информацию о данном кубике RollingDie rDie = new RollingDie(die, dice, spawnPoint, force); // Добавляем его в allDice allDice.Add(rDie); // И в очередь перед броском rollQueue rollQueue.Add(rDie); }
public static bool Movimento() { int d = 0; bool movimento = false; // loop rollingDice while (d < rollingDice.Count) { // if rolling die no longer rolling , remove it from rollingDice RollingDie rDie = (RollingDie)rollingDice[d]; if (rDie.rolling) { movimento = true; break; } else { d++; } } // return false if we have no rolling dice return(movimento); }
public void Roll(Material mat, Vector3 spawnPoint, Vector3 force) { rolling = true; // randomize spawnPoint variation spawnPoint.x = spawnPoint.x - (1 + Random.value * 2) * 0.01f; spawnPoint.y = spawnPoint.y - (1 + Random.value * 2) * 0.01f; spawnPoint.y = spawnPoint.y - (1 + Random.value * 2) * 0.01f; // create the die prefab/gameObject GameObject die = prefab(spawnPoint, Vector3.zero, Vector3.one, mat); // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // inactivate this gameObject because activating it will be handeled using the rollQueue and at the apropriate time die.SetActive(false); // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die, mat, spawnPoint, force); // add RollingDie to allDices allDice.Add(rDie); // add RollingDie to the rolling queue rollQueue.Add(rDie); }
void Update() { if (rolling) { // Считаем задержку перед броском rollTime += Time.deltaTime; // Если в очереди есть кубики и задержка перед броском прошла if (rollQueue.Count > 0 && rollTime > rollSpeed) { // Берем первый кубик из очереди RollingDie rDie = (RollingDie)rollQueue[0]; GameObject die = rDie.gameObject; // Активируем его die.SetActive(true); // Применяем силу die.GetComponent <Rigidbody>().AddForce((Vector3)rDie.force, ForceMode.Impulse); // Применяем случайный крутящий момент die.GetComponent <Rigidbody>().AddTorque(new Vector3(-50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude, -50 * Random.value * die.transform.localScale.magnitude), ForceMode.Impulse); // Добавляем кубик в rollingDice rollingDice.Add(rDie); // Удаляем кубик из очереди rollQueue.RemoveAt(0); // Обнуляем счетчик задержки для следующего кубика rollTime = 0; } else if (rollQueue.Count == 0) { // Если очередь пуста и движущихся кубиков нет, то rolling = false if (!IsRolling("")) { rolling = false; } } } }
public static void RollDie(Die die, Vector3 spawnPoint, Vector3 force) { string dieType = "d6"; rolling = true; // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // inactivate this gameObject because activating it will be handeled using the rollQueue and at the apropriate time die.gameObject.SetActive(false); Vector3 spawnRnd = new Vector3 (Random.value * 2.0f - 1.0f, Random.value * 2.0f - 1.0f, Random.value * 2.0f - 1.0f); die.transform.position = spawnPoint + spawnRnd; // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die.gameObject, dieType, "d6-red", spawnPoint, force); // add RollingDie to allDices allDice.Add(rDie); // add RollingDie to the rolling queue rollQueue.Add(rDie); }
//добавляем кубик на текущий игровой стол public string addDie( string dieType ) { // dice2 = gameObject.AddComponent("Dice2") as D; string[] a = dieType.Split('-'); die = dice2.createDie( a[0], Vector3.zero, Vector3.zero, demo.dieSize, a[1] ); die.name = "die" + Random.Range(diceList.Count, 65535); die.tag = "die"; rDie = new RollingDie( die, a[0] ); diceList.Add( die.name, rDie ); rDie.tableNum = demo.table; rDie.grp = addorCreateGroup( dieType ) ; rDie.transparency = gallery.trValue; rDie.color = a[1]; return die.name; }
/* public static void cleanUnsuccessful(){ for (int d = 0; d < unsuccessfulDice.Count; d++){ RollingDie rDie = (RollingDie) unsuccessfulDice[d]; if( rDie.tableNum == demo.table ){ GameObject die = rDie.gameObject; die.renderer.material.SetColor( "_Color", new Vector4(rDie.clr.r, rDie.clr.g, rDie.clr.b, 1f) ); unsuccessfulDice.Remove( rDie ); } } } */ public static string addDie( string dieType ) { string[] a = dieType.Split('-'); /* Object prefab = Resources.Load("dice_prefabs/" + dieType); GameObject die = (GameObject) GameObject.Instantiate( prefab, Vector3.zero, Quaternion.identity); */ GameObject die = createDie( a[0], Vector3.zero, Vector3.zero, demo.dieSize*Vector3.one, a[1] ); die.name = "die" + Random.Range(allDice.Count, 65535); RollingDie rDie = new RollingDie( die, a[0] ); allDice.Add( rDie ); rDie.tableNum = demo.table; rDie.transparency = gallery.trValue; rDie.color = a[1]; return die.name; }
/// <summary> /// Roll one or more dice with a specific material from a spawnPoint and give it a specific force. /// format dice : ({count}){die type} , exmpl. d6, 4d4, 12d8 , 1d20 /// possible die types : d4, d6, d8 , d10, d12, d20 /// </summary> public static void Roll(string dice, string mat, Vector3 spawnPoint, Vector3 force) { rolling = true; // sotring dice to lowercase for comparing purposes dice = dice.ToLower(); int count = 1; string dieType = "d6"; // 'd' must be present for a valid 'dice' specification int p = dice.IndexOf("d"); if (p>=0) { // check if dice starts with d, if true a single die is rolled. // dice must have a count because dice does not start with 'd' if (p>0) { // extract count string[] a = dice.Split('d'); count = System.Convert.ToInt32(a[0]); // get die type if (a.Length>1) dieType = "d"+a[1]; else dieType = "d6"; } else dieType = dice; // instantiate the dice for (int d=0; d<count; d++) { // randomize spawnPoint variation spawnPoint.x = spawnPoint.x - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; spawnPoint.y = spawnPoint.y - 1 + Random.value * 2; // create the die prefab/gameObject GameObject die = prefab(dieType, spawnPoint, Vector3.zero, Vector3.one, mat); // give it a random rotation die.transform.Rotate(new Vector3(Random.value * 360, Random.value * 360, Random.value * 360)); // inactivate this gameObject because activating it will be handeled using the rollQueue and at the apropriate time die.active = false; // create RollingDie class that will hold things like spawnpoint and force, to be used when activating the die at a later stage RollingDie rDie = new RollingDie(die, dieType, mat, spawnPoint, force); // add RollingDie to allDices allDice.Add(rDie); // add RollingDie to the rolling queue rollQueue.Add(rDie); } } }
//перезапускаем конкретный кубик до тех пор, пока он не остановится с определенным значением IEnumerator Reroll( RollingDie rDie ) { do{ rDie.die.kickDie(); yield return new WaitForSeconds(.2f); while( dice.isRolling( table ) ){ yield return new WaitForSeconds(.1f); } }while( rDie.die.getVal < 0 ); }
public static void preaddDie( string dieType ) { string[] a = dieType.Split('-'); /* Object prefab = Resources.Load("dice_prefabs/" + dieType); GameObject die = (GameObject) GameObject.Instantiate( prefab, Vector3.zero, Quaternion.identity); */ Vector3 position = new Vector3( Random.value, 1+Random.value, Random.value ); GameObject die = createDie( a[0], position, Vector3.zero, new Vector3(5,5,5), a[1] ); die.name = "die" + allDice.Count; RollingDie rDie = new RollingDie( die, a[0] ); allDice.Add(rDie ); rDie.tableNum = demo.table; die.rigidbody.isKinematic = true; rDie.size = die.transform.localScale; die.transform.localScale = die.transform.localScale * 0.25f;//new Vector3(3F, 3f, 3f); rDie.spawnPoint = die.rigidbody.position; rDie.slot = getFreeSlot; // Debug.Log( rDie.slot ); GameObject g = GameObject.Find("platform-2"); die.rigidbody.MovePosition( g.transform.position + new Vector3( -3.3f ,5, -2.9f +rDie.slot*0.95f) ); rDie.frozen = true; diceSlots[ rDie.slot ] = 1; }