private void RollDiceOfPrefab(ref Vector3 position, ToolboxDice diceVars, ref int count, string prefab) { DiceWithCam dCam; for (int i = 0; i < diceVars.dsaDiceChosen[prefab]; i++) { //Erzeuge jeweils neue Kamera mit Würfel dCam = new DiceWithCam(WürfelTyp.w20); position.y += count; SetParentGameObject(dCam); dCam.dice = PhotonNetwork.Instantiate(prefab, position, Quaternion.identity, 0); //Beschleunige und rotiere den Würfel RotateAndAccelerate(dCam.dice); //Positioniere die Kamera auf Würfel PositionCam(dCam); //füge den Würfel mit Kamera der UpdateListe hinzu createdDiceWithCam.Add(dCam); //Zähle aktuelle Wüfel nach oben countAllDice++; //aktueller counter count++; } }
/// <summary> /// Positioniert Rect-Port-Kamera über Würfel und gibt das Bild am unteren Bildschirmrand aus /// Bei vielen Würfeln: verschiebt immer um 1/8 der Bildschirmbreite (aktueller Würfel: countAllDice) /// </summary> /// <param name="dCam"></param> protected void PositionCam(DiceWithCam dCam) { float broadOffset = 8.0f; //Hole Kamera dCam.cam.AddComponent <Camera>(); Camera WCam = dCam.cam.GetComponent <Camera>(); //Positionierung folgt in LateUpdate, Rotation hier WCam.transform.rotation = Quaternion.FromToRotation(Vector3.forward, Vector3.down); WCam.rect = new Rect(countAllDice / broadOffset, 0, 0.15f, 0.15f); }
/// <summary> /// Setzt das Parent-GameObject für Kamera und Würfel (s.o.) /// </summary> /// <param name="dCam"></param> protected void SetParentGameObject(DiceWithCam dCam) { //Setze gleiche Parents dCam.dice.transform.parent = wuerfelGO.transform; dCam.cam.transform.parent = wuerfelGO.transform; }
/// <summary> /// Instanzieert die Würfel und speichert sie inklusive eigener Kamera in dcam-Liste ab /// </summary> /// <param name="typ"></param> /// <param name="position"></param> /// <param name="anzahl"></param> protected virtual void InstantiateDice(WürfelTyp typ, Vector3 position, int anzahl) { if (anzahl > 0) { DiceWithCam dCam; CreateParentGameObject(); for (int count = 0; count < anzahl; count++) { //Erzeuge jeweils neue Kamera mit Würfel dCam = new DiceWithCam(typ); position.y += count; SetParentGameObject(dCam); switch (typ) { case WürfelTyp.w6: if (count % 2 == 0) { dCam.dice = Instantiate(W6preFabBlack, position, Quaternion.identity) as GameObject; } else { dCam.dice = Instantiate(W6preFabBlue, position, Quaternion.identity) as GameObject; } dCam.dice.name = "W6_" + count; break; case WürfelTyp.w10: if (count % 2 == 0) { dCam.dice = Instantiate(W10preFabBlack, position, Quaternion.identity) as GameObject; } else { dCam.dice = Instantiate(W10preFabBlue, position, Quaternion.identity) as GameObject; } dCam.dice.name = "W10_" + count; break; case WürfelTyp.w20: if (count % 2 == 0) { dCam.dice = Instantiate(W20preFabBlack, position, Quaternion.identity) as GameObject; } else { dCam.dice = Instantiate(W20preFabBlue, position, Quaternion.identity) as GameObject; } dCam.dice.name = "W20_" + count; break; default: break; } //Beschleunige und rotiere den Würfel RotateAndAccelerate(dCam.dice); //Positioniere die Kamera auf Würfel PositionCam(dCam); //füge den Würfel mit Kamera der UpdateListe hinzu createdDiceWithCam.Add(dCam); //Zähle aktuelle Wüfel nach oben countAllDice++; } } }
override protected void InstantiateDice(WürfelTyp typ, Vector3 position, int anzahl) { ToolboxDice diceVars = ToolboxDice.Instance; if (anzahl > 0) { DiceWithCam dCam; CreateParentGameObject(); for (int count = 0; count < anzahl; count++) { //Erzeuge jeweils neue Kamera mit Würfel dCam = new DiceWithCam(typ); position.y += count; SetParentGameObject(dCam); switch (typ) { case WürfelTyp.w6: if (count % 2 == 0) { dCam.dice = PhotonNetwork.Instantiate(diceVars.colorDice_d6, position, Quaternion.identity, 0); } else { dCam.dice = PhotonNetwork.Instantiate("d6black", position, Quaternion.identity, 0); } dCam.dice.name = "W6_" + count; break; case WürfelTyp.w10: if (count % 2 == 0) { dCam.dice = PhotonNetwork.Instantiate(diceVars.colorDice_d10, position, Quaternion.identity, 0); } else { dCam.dice = PhotonNetwork.Instantiate("d10black", position, Quaternion.identity, 0); } dCam.dice.name = "W10_" + count; break; case WürfelTyp.w20: if (count % 2 == 0) { dCam.dice = PhotonNetwork.Instantiate(diceVars.colorDice_d20, position, Quaternion.identity, 0); } else { dCam.dice = PhotonNetwork.Instantiate("d20black", position, Quaternion.identity, 0); } dCam.dice.name = "W20_" + count; break; default: break; } //Beschleunige und rotiere den Würfel RotateAndAccelerate(dCam.dice); //Positioniere die Kamera auf Würfel PositionCam(dCam); //füge den Würfel mit Kamera der UpdateListe hinzu createdDiceWithCam.Add(dCam); //Zähle aktuelle Wüfel nach oben countAllDice++; } } }