/// <summary> /// Fügt alle WorldObjects aus der übergebenen Gruppe zu dieser Gruppe hinzu und löscht die andere Gruppe. /// </summary> /// <param name="other"></param> public void MergeGroups(WorldObjectGroup other) { foreach (WorldObject obj in other.objects) { obj.myGroup = null; AddObjectToGroup(obj); } other.objects.Clear(); Destroy(other.gameObject); }
/// <summary> /// Initialisiert das WorldObject mit den übergebenen Parametern. /// </summary> /// <param name="dir"></param> /// <param name="x"></param> /// <param name="y"></param> public void InitializeWorldObject(Vector2 dir, int x = 0, int y = 0) { myInteractiveObject = GetComponent <InteractiveObject>(); myInteractiveObject.ChangeStartingPosition(x, y); myInteractiveObject.ChangeStartingDirection(dir); connectedWorldObjects = new WorldObject[] { null, null, null, null }; connectionSprites = new GameObject[4]; for (int i = 0; i < 4; i++) { connectionSprites[i] = transform.GetChild(i).gameObject; connectionSprites[i].SetActive(false); } InitializeActionDictionary(); InitializeScript(); myGroup = null; connective = false; }
/// <summary> /// Verbindet die beiden übergebenen WorldObjects, falls möglich /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void ConnectWorldObjects(WorldObject a, WorldObject b) { if (Vector3.Distance(a.transform.position, b.transform.position) > 1.1f) { Debug.Log("Die WorldObjects '" + a.gameObject.name + "' und '" + b.gameObject.name + "' sind zu weit auseinander, um verbunden zu werden."); return; } if (a.myGroup == null && b.myGroup == null) { WorldObjectGroup group = Instantiate(groupObjectPrefab).GetComponent <WorldObjectGroup>(); group.transform.SetParent(this.transform); group.GetComponent <InteractiveObject>().SetStartingPositionAndRotation(a.GetComponent <InteractiveObject>().posX, a.GetComponent <InteractiveObject>().posY, new Vector2(0, -1)); group.transform.position = new Vector3(a.GetComponent <InteractiveObject>().posX + 0.5f, a.GetComponent <InteractiveObject>().posY + 0.5f); worldObjectGroups.Add(group.gameObject); group.AddObjectToGroup(a); } a.AttemptToConnectWorldObject(b); b.AttemptToConnectWorldObject(a); }
/// <summary> /// Entfernt die übergebene WorldObjectGroup aus worldObjectGroups und zerstört sie. /// </summary> /// <param name="group"></param> public void RemoveWorldObjectGroup(WorldObjectGroup group) { worldObjectGroups.Remove(group.gameObject); Destroy(group.gameObject); }