Jump to content
Unity Insider Forum

(Unity) Karten in Hand anordnen - mathematische Lösung?


Maurice94

Recommended Posts

Ja, es ist bei uns halt so, dass wir sogut wie keine Themen löschen.
Der Sinn eines Forums ist ja, dass sich Informationen anhäufen und somit anderen Leuten helfen können.
Es wäre schön gewesen, wenn du uns deine selbst gefundene Lösung mitgeteilt hättest um eben anderen Leuten, die später vielleicht ein ähnliches Problem haben, helfen zu können.
Jetzt ist es egal, denn die Fragestellung sieht ja auch keiner mehr.

Trotzdem löschen wir nicht. ;)

Link zu diesem Kommentar
Auf anderen Seiten teilen

Okay, das kann ich natürlich nachvollziehen. Da alles so schnell ging und ich innerhalb kürzester Zeit das Problem beheben konnte, dachte ich, dass es womöglich einfach am besten wäre, den Beitrag zu löschen um anderen Leuten nicht den Platz, bzw. die Aufmerksamkeit für Ihre Probleme wegzunehmen. Ich kann das Problem nochmal aufgreifen. Es ging darum, dass ich versucht habe, die Karten in meiner Hand je nach Anzahl flexibel und dynamisch anzupassen. Wenn ich also 2 Karten in der Hand habe, ist Karte 1 an Position Vector(-1, 0, 0) und Karte 2 z.B an Position Vector(0, 0, 0). Sollte nun aber Karte 2 aus meiner Hand verschwinden, möchte ich, dass die andere Karte automatisch ein Stück nach rechts rückt. Und sollte meiner Hand dann wieder eine weitere Karte hinzugefügt werden, möchte ich halt immer wieder die automatische Veränderung der Position erreichen, so dass auch bei einer größeren Anzahl von Karten, alle Karten ihre Positionen anpassen. Da ich diese Logik an iTween knüpfen wollte, musste ich kurz überlegen. Die Lösung dafür hat dann wie folgt ausgesehen. Unter dem Code gehe ich nochmal spezifisch auf den Code ein.

 

public void DrawCardFromDeck()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (Master_Hand.childCount == 0)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 1)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if(Master_Hand.childCount == 2)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if(Master_Hand.childCount == 3)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 4)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_Neutral, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(3).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 5)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_minus1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_Neutral, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(3).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(4).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 6)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_minus2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_minus1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_Neutral, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(3).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(4).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(5).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 7)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_minus3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_minus2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_minus1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(3).gameObject, iTween.Hash("position", Position_Neutral, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(4).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(5).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(6).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
            }
            else if (Master_Hand.childCount == 8)
            {
                Temp = PhotonNetwork.Instantiate("Network_Card_Prefab", Deck_Childs[Deck_Childs.Count - 1].transform.position + new Vector3(0, 1, 0), Quaternion.identity);
                iTween.MoveTo(Master_Hand.GetChild(0).gameObject, iTween.Hash("position", Position_minus4, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(1).gameObject, iTween.Hash("position", Position_minus3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(2).gameObject, iTween.Hash("position", Position_minus2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(3).gameObject, iTween.Hash("position", Position_minus1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(4).gameObject, iTween.Hash("position", Position_Neutral, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(5).gameObject, iTween.Hash("position", Position_1, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(6).gameObject, iTween.Hash("position", Position_2, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Master_Hand.GetChild(7).gameObject, iTween.Hash("position", Position_3, "time", 1f, "easeType", iTween.EaseType.easeInOutSine));
                iTween.MoveTo(Temp, iTween.Hash("position", Position_4, "time", 2f, "easeType", iTween.EaseType.easeInOutSine));
                //Vector3 Temp_Position = Master_Hand.position + new Vector3(8, 0, 0);
                //iTween.MoveTo(Master_Hand.gameObject, iTween.Hash("position", Temp_Position, "time", 1f, "easeType", iTween.EaseType.easeOutSine));
                Temp.transform.SetParent(Master_Hand);
                
            }
            else if (Master_Hand.childCount == 9)
            {
                return;
            }

        }    
    }

Ich habe zunächst einmal 9 individuelle Transforms in der Szene positioniert. Dann instantiate ich eine Karte, die sich zur Position des besagten Transforms bewegt. Bevor all das passiert, wird immer geprüft, wie viele Childs aktuell in der Hand sind. Je nachdem, wie das Resultat ausgeht, werden all die Childobjekte im gleichen Zug ein Stück nach links bewegt. Es kommt also eine neue Karte dazu und die anderen wandern im gleichen Atemzug zur nächstgelegenen Position. Ich weiß, dass diese Methode etwas grob ist - aber sie hat für den Moment das erfüllt, was ich bewirken wollte. Demnach kann es ja gar nicht so schlecht gewesen sein. Entschuldige nochmal, dass ich den Beitrag gelöscht habe. Ich hoffe, dass ich nachträglich erklären konnte, was mein Anliegen gewesen ist.

Liebe Grüße,
Maurice

Link zu diesem Kommentar
Auf anderen Seiten teilen

Archiviert

Dieses Thema ist jetzt archiviert und für weitere Antworten gesperrt.

×
×
  • Neu erstellen...