static GameObject GetExistingTilePrefabInstance(tk2dTileMap tileMap, int tileX, int tileY, int tileLayer) { int n = tileMap.GetTilePrefabsListCount(); for (int i = 0; i < n; ++i) { int x, y, layer; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layer, out instance); if (x == tileX && y == tileY && layer == tileLayer) return instance; } return null; }
static GameObject GetExistingTilePrefabInstance(tk2dTileMap tileMap, int tileX, int tileY, int tileLayer) { int n = tileMap.GetTilePrefabsListCount(); for (int i = 0; i < n; ++i) { int x, y, layer; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layer, out instance); if (x == tileX && y == tileY && layer == tileLayer) { return(instance); } } return(null); }
/// <summary> /// Moves the chunk's gameobject's children to the prefab root /// </summary> public static void HideTileMapPrefabs(tk2dTileMap tileMap) { if (tileMap.renderData == null || tileMap.Layers == null) { // No Render Data to parent Prefab Root to return; } if (tileMap.PrefabsRoot == null) { var go = tileMap.PrefabsRoot = tk2dUtil.CreateGameObject("Prefabs"); go.transform.parent = tileMap.renderData.transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; } int instListCount = tileMap.GetTilePrefabsListCount(); bool[] instExists = new bool[instListCount]; for (int i = 0; i < tileMap.Layers.Length; ++i) { var layer = tileMap.Layers[i]; for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j) { var chunk = layer.spriteChannel.chunks[j]; if (chunk.gameObject == null) continue; var t = chunk.gameObject.transform; int childCount = t.childCount; for (int k = 0; k < childCount; ++k) { GameObject go = t.GetChild(k).gameObject; for (int q = 0; q < instListCount; ++q) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance); if (instance == go) { instExists[q] = true; break; } } } } } Object[] prefabs = tileMap.data.tilePrefabs; List<int> tileX = new List<int>(); List<int> tileY = new List<int>(); List<int> tileLayer = new List<int>(); List<GameObject> tileInst = new List<GameObject>(); for (int i = 0; i < instListCount; ++i) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance); // Is it already IN the list for some reason? if (!instExists[i]) { int tileId = (x >= 0 && x < tileMap.width && y >= 0 && y < tileMap.height) ? tileMap.GetTile(x, y, layerIdx) : -1; if (tileId >= 0 && tileId < prefabs.Length && prefabs[tileId] != null) { instExists[i] = true; } } if (instExists[i]) { tileX.Add(x); tileY.Add(y); tileLayer.Add(layerIdx); tileInst.Add(instance); tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform); } } tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst); }
/// <summary> /// Moves the chunk's gameobject's children to the prefab root /// </summary> public static void HideTileMapPrefabs(tk2dTileMap tileMap) { if (tileMap.renderData == null) { // No Render Data to parent Prefab Root to return; } else { if (tileMap.PrefabsRoot == null) { var go = tileMap.PrefabsRoot = new GameObject("Prefabs"); go.transform.parent = tileMap.renderData.transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; } } if (tileMap.Layers == null) { return; } int instListCount = tileMap.GetTilePrefabsListCount(); bool[] instExists = new bool[instListCount]; for (int i = 0; i < tileMap.Layers.Length; ++i) { var layer = tileMap.Layers[i]; for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j) { var chunk = layer.spriteChannel.chunks[j]; if (chunk.gameObject == null) { continue; } var t = chunk.gameObject.transform; int childCount = t.childCount; for (int k = 0; k < childCount; ++k) { GameObject go = t.GetChild(k).gameObject; for (int q = 0; q < instListCount; ++q) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance); if (instance == go) { instExists[q] = true; break; } } } } } List <int> tileX = new List <int>(); List <int> tileY = new List <int>(); List <int> tileLayer = new List <int>(); List <GameObject> tileInst = new List <GameObject>(); for (int i = 0; i < instListCount; ++i) { if (instExists[i]) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance); tileX.Add(x); tileY.Add(y); tileLayer.Add(layerIdx); tileInst.Add(instance); instance.transform.parent = tileMap.PrefabsRoot.transform; } } tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst); }
/// <summary> /// Moves the chunk's gameobject's children to the prefab root /// </summary> public static void HideTileMapPrefabs(tk2dTileMap tileMap) { if (tileMap.renderData == null || tileMap.Layers == null) { // No Render Data to parent Prefab Root to return; } if (tileMap.PrefabsRoot == null) { var go = tileMap.PrefabsRoot = tk2dUtil.CreateGameObject("Prefabs"); go.transform.parent = tileMap.renderData.transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; } int instListCount = tileMap.GetTilePrefabsListCount(); bool[] instExists = new bool[instListCount]; for (int i = 0; i < tileMap.Layers.Length; ++i) { var layer = tileMap.Layers[i]; for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j) { var chunk = layer.spriteChannel.chunks[j]; if (chunk.gameObject == null) { continue; } var t = chunk.gameObject.transform; int childCount = t.childCount; for (int k = 0; k < childCount; ++k) { GameObject go = t.GetChild(k).gameObject; for (int q = 0; q < instListCount; ++q) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance); if (instance == go) { instExists[q] = true; break; } } } } } Object[] prefabs = tileMap.data.tilePrefabs; List <int> tileX = new List <int>(); List <int> tileY = new List <int>(); List <int> tileLayer = new List <int>(); List <GameObject> tileInst = new List <GameObject>(); for (int i = 0; i < instListCount; ++i) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance); // Is it already IN the list for some reason? if (!instExists[i]) { int tileId = (x >= 0 && x < tileMap.width && y >= 0 && y < tileMap.height) ? tileMap.GetTile(x, y, layerIdx) : -1; if (tileId >= 0 && tileId < prefabs.Length && prefabs[tileId] != null) { instExists[i] = true; } } if (instExists[i]) { tileX.Add(x); tileY.Add(y); tileLayer.Add(layerIdx); tileInst.Add(instance); tk2dUtil.SetTransformParent(instance.transform, tileMap.PrefabsRoot.transform); } } tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst); }
public static void HideTileMapPrefabs(tk2dTileMap tileMap) { if ((tileMap.renderData != null) && (tileMap.Layers != null)) { if (tileMap.PrefabsRoot == null) { GameObject obj6 = tk2dUtil.CreateGameObject("Prefabs"); tileMap.PrefabsRoot = obj6; GameObject obj2 = obj6; obj2.transform.parent = tileMap.renderData.transform; obj2.transform.localPosition = Vector3.zero; obj2.transform.localRotation = Quaternion.identity; obj2.transform.localScale = Vector3.one; } int tilePrefabsListCount = tileMap.GetTilePrefabsListCount(); bool[] flagArray = new bool[tilePrefabsListCount]; for (int i = 0; i < tileMap.Layers.Length; i++) { Layer layer = tileMap.Layers[i]; for (int k = 0; k < layer.spriteChannel.chunks.Length; k++) { SpriteChunk chunk = layer.spriteChannel.chunks[k]; if (chunk.gameObject != null) { Transform transform = chunk.gameObject.transform; int childCount = transform.childCount; for (int m = 0; m < childCount; m++) { GameObject gameObject = transform.GetChild(m).gameObject; for (int n = 0; n < tilePrefabsListCount; n++) { int num7; int num8; int num9; GameObject obj4; tileMap.GetTilePrefabsListItem(n, out num7, out num8, out num9, out obj4); if (obj4 == gameObject) { flagArray[n] = true; break; } } } } } } UnityEngine.Object[] tilePrefabs = tileMap.data.tilePrefabs; List<int> xs = new List<int>(); List<int> ys = new List<int>(); List<int> layers = new List<int>(); List<GameObject> instances = new List<GameObject>(); for (int j = 0; j < tilePrefabsListCount; j++) { int num11; int num12; int num13; GameObject obj5; tileMap.GetTilePrefabsListItem(j, out num11, out num12, out num13, out obj5); if (!flagArray[j]) { int index = (((num11 < 0) || (num11 >= tileMap.width)) || ((num12 < 0) || (num12 >= tileMap.height))) ? -1 : tileMap.GetTile(num11, num12, num13); if (((index >= 0) && (index < tilePrefabs.Length)) && (tilePrefabs[index] != null)) { flagArray[j] = true; } } if (flagArray[j]) { xs.Add(num11); ys.Add(num12); layers.Add(num13); instances.Add(obj5); tk2dUtil.SetTransformParent(obj5.transform, tileMap.PrefabsRoot.transform); } } tileMap.SetTilePrefabsList(xs, ys, layers, instances); } }
private static GameObject GetExistingTilePrefabInstance(tk2dTileMap tileMap, int tileX, int tileY, int tileLayer) { int tilePrefabsListCount = tileMap.GetTilePrefabsListCount(); for (int i = 0; i < tilePrefabsListCount; i++) { int num3; int num4; int num5; GameObject obj2; tileMap.GetTilePrefabsListItem(i, out num3, out num4, out num5, out obj2); if (((num3 == tileX) && (num4 == tileY)) && (num5 == tileLayer)) { return obj2; } } return null; }
/// <summary> /// Moves the chunk's gameobject's children to the prefab root /// </summary> public static void HideTileMapPrefabs(tk2dTileMap tileMap) { if (tileMap.renderData == null) { // No Render Data to parent Prefab Root to return; } else { if (tileMap.PrefabsRoot == null) { var go = tileMap.PrefabsRoot = new GameObject("Prefabs"); go.transform.parent = tileMap.renderData.transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; } } if (tileMap.Layers == null) return; int instListCount = tileMap.GetTilePrefabsListCount(); bool[] instExists = new bool[instListCount]; for (int i = 0; i < tileMap.Layers.Length; ++i) { var layer = tileMap.Layers[i]; for (int j = 0; j < layer.spriteChannel.chunks.Length; ++j) { var chunk = layer.spriteChannel.chunks[j]; if (chunk.gameObject == null) continue; var t = chunk.gameObject.transform; int childCount = t.childCount; for (int k = 0; k < childCount; ++k) { GameObject go = t.GetChild(k).gameObject; for (int q = 0; q < instListCount; ++q) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(q, out x, out y, out layerIdx, out instance); if (instance == go) { instExists[q] = true; break; } } } } } List<int> tileX = new List<int>(); List<int> tileY = new List<int>(); List<int> tileLayer = new List<int>(); List<GameObject> tileInst = new List<GameObject>(); for (int i = 0; i < instListCount; ++i) { if (instExists[i]) { int x, y, layerIdx; GameObject instance; tileMap.GetTilePrefabsListItem(i, out x, out y, out layerIdx, out instance); tileX.Add(x); tileY.Add(y); tileLayer.Add(layerIdx); tileInst.Add(instance); instance.transform.parent = tileMap.PrefabsRoot.transform; } } tileMap.SetTilePrefabsList(tileX, tileY, tileLayer, tileInst); }