// Update is called once per frame void Update() { //if ton tour de jouer + canva qui dit lancer le des RollDice(); if (_throwingDice == true && Dice.rolling == false) { _time += Time.deltaTime; if (_time > 4f) { _time = 0f; _throwingDice = false; if (Dice.AsString("d6").IndexOf("?") == -1) { _retry = true; } Debug.Log(Dice.AsString("d6")); Debug.Log("Value : " + Dice.Value("d6")); Dice.Clear(); } } }
// handle GUI void OnGUI() { // Make mode selection box var menuW = Screen.width / 4; var menuH = Screen.height / 10; var ptMenu1 = new Vector4(20, 35, menuW, menuH); var ptMenu2 = new Vector4(ptMenu1.x, ptMenu1.y + ptMenu1.w + 5, ptMenu1.z, ptMenu1.w); if (!hideGui) { var name = "Wuerfi"; if (Application.platform == RuntimePlatform.Android) { name = "Wuerfi Android"; } GUI.Box(rectModeSelect, name); /* * if (GUI.Button (new Rect (ptMenu1.x, ptMenu1.y, ptMenu1.z, ptMenu1.w), "Dice Gallery")) { * SetMode(MODE_GALLERY); * } * if (GUI.Button (new Rect (ptMenu2.x, ptMenu2.y, ptMenu2.z, ptMenu2.w), "Roll Dice")) { * SetMode(MODE_ROLL); * } */ } switch (mode) { case MODE_GALLERY: if (nextCameraPosition == null) { // camera is not moving so display dice selector GUI.Box(rectGallerySelectBox, "Dice Selector"); if (txSelector == null) { // determine dieType dependent selection texture string add = ""; if (galleryDie.IndexOf("-dots") >= 0) { // dice with dots found so we have to append -dots when loading material add = "-dots"; } // we have to load our selector texture txSelector = (Texture)Resources.Load("Textures/GUI-selector/select-" + galleryDie.Split('-')[0] + add); } if (txSelector != null) { // draw our selector texture GUI.DrawTexture(rectGallerySelect, txSelector, ScaleMode.ScaleToFit, true, 0f); } // check current mouseposition against selector string status = CheckSelection(rectGallerySelect); if (status == "") { status = "[select your dice and color]"; } // display status label GUI.Label(new Rect(Screen.width - 245, 145, 230, 20), status); } GUI.Box(new Rect((Screen.width - 350) / 2, Screen.height - 40, 350, 25), ""); GUI.Label(new Rect(((Screen.width - 350) / 2) + 10, Screen.height - 38, 350, 22), "You can rotate the die by dragging it with the mouse."); break; case MODE_ROLL: // Display button to roll dice //var ptRoll = new Vector4(ptMenu2.x, ptMenu2.y + ptMenu2.w + 5, ptMenu2.z, ptMenu2.w); var ptRoll = new Vector4(ptMenu2.x, 35, ptMenu2.z, ptMenu2.w); if (!hideGui) { if (GUI.Button(new Rect(ptRoll.x, ptRoll.y, ptRoll.z, ptRoll.w), "Roll dice!") && allowRoll) { var f = Force(); ThrowForGame(f); } GUI.Box(new Rect((Screen.width - 350) / 2, Screen.height - 40, 350, 25), ""); string fps = "FPS: " + ((int)(1.0f / Time.deltaTime)).ToString(); GUI.Label(new Rect(((Screen.width - 350) / 2) + 10, Screen.height - 38, 350, 22), fps); } // Display last force applied //GUI.Box(new Rect(10, Screen.height - 125, Screen.width - 20, 30), ""); //GUI.Label(new Rect(20, Screen.height - 120, Screen.width, 20), "Last force: " + lastForceApplied.ToString()); // display rolling message on bottom var rectInstructions = new Rect(((Screen.width - 520) / 2) + 10, Screen.height - 38, 520, 22); if (!hideGui && Dice.Count("") > 0) { // we have rolling dice so display rolling status GUI.Box(new Rect(10, Screen.height - 75, Screen.width - 20, 30), ""); var strDice = Dice.AsString(""); GUI.Label(new Rect(20, Screen.height - 70, Screen.width, 20), strDice); } if (Dice.rolling && !allowRollPrevious) { Debug.Log("Rolling"); allowRoll = false; allowRollPrevious = true; } else if (!Dice.rolling && allowRollPrevious) { Debug.Log("Not rolling anymore"); // allow roll allowRoll = true; allowRollPrevious = false; } break; } }
// handle GUI void OnGUI() { // Make mode selection box GUI.Box(rectModeSelect, "Dice Demo"); if (GUI.Button(new Rect(20, 35, 160, 20), "Dice Gallery")) { SetMode(MODE_GALLERY); } if (GUI.Button(new Rect(20, 60, 160, 20), "Roll Dice")) { SetMode(MODE_ROLL); } switch (mode) { case MODE_GALLERY: if (nextCameraPosition == null) { // camera is not moving so display dice selector GUI.Box(rectGallerySelectBox, "Dice Selector"); if (txSelector == null) { // determine dieType dependent selection texture string add = ""; if (galleryDie.IndexOf("-dots") >= 0) { // dice with dots found so we have to append -dots when loading material add = "-dots"; } // we have to load our selector texture txSelector = (Texture)Resources.Load("Textures/GUI-selector/select-" + galleryDie.Split('-')[0] + add); } if (txSelector != null) { // draw our selector texture GUI.DrawTexture(rectGallerySelect, txSelector, ScaleMode.ScaleToFit, true, 0f); } // check current mouseposition against selector string status = CheckSelection(rectGallerySelect); if (status == "") { status = "[select your dice and color]"; } // display status label GUI.Label(new Rect(Screen.width - 245, 145, 230, 20), status); } GUI.Box(new Rect((Screen.width - 350) / 2, Screen.height - 40, 350, 25), ""); GUI.Label(new Rect(((Screen.width - 350) / 2) + 10, Screen.height - 38, 350, 22), "You can rotate the die by dragging it with the mouse."); break; case MODE_ROLL: // display rolling message on bottom GUI.Box(new Rect((Screen.width - 520) / 2, Screen.height - 40, 520, 25), ""); GUI.Label(new Rect(((Screen.width - 520) / 2) + 10, Screen.height - 38, 520, 22), "Click with the left (all die types) or right (gallery die) mouse button in the center to roll."); if (Dice.Count("") > 0) { // we have rolling dice so display rolling status GUI.Box(new Rect(10, Screen.height - 75, Screen.width - 20, 30), ""); GUI.Label(new Rect(20, Screen.height - 70, Screen.width, 20), Dice.AsString("")); } break; } }