/// <summary> /// Instantiate the buttons for display in the content holder /// </summary> /// <param name="tileObject"></param> //private void InstantiateObject(GameObject tileObject, int id) private void InstantiateObject(BaseTileObject baseTileObject, int id) { print("InstantiateObject :" + baseTileObject + " id :" + id); GameObject tileObject = baseTileObject.getPrefab().gameObject; if (tileObject == null) { Debug.LogWarning("Warning given tileObject is null"); } GameObject f = Instantiate(tileObject.transform.Find("IconButton").gameObject); //GameObject mesh = tileObject.GetComponentInChildren<MeshFilter>().gameObject; //print("mesh object :" + mesh.name); //Image image = f.GetComponent<Image>(); //Texture2D texture = AssetPreview.GetMiniThumbnail(TileObjectManger.instance.prefabsThisArrayWillBeReplacedWithAnAutomaticWay[2]); //image.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); f.transform.SetParent(GameObject.Find("Content").gameObject.transform); f.transform.localScale = new Vector3(1, 1, 1); f.transform.rotation = new Quaternion(0, 0, 0, 0); //f.transform.localPosition = new Vector3(f.transform.position.x, f.transform.position.y, 0); f.transform.localPosition = new Vector3(); f.GetComponent <BoxCollider>().size = new Vector3(50, 50); //Give the object the name of the id f.name = standartKeyName + id; //Add an click listener for when the button is clicked //Button b = f.GetComponent<Button>(); // f.transform.GetChild(0).gameObject.GetComponent<Indexer>().index = prefabs.Count - 1; // b.onClick.AddListener(delegate { this.SelectTileObject(f); }); //spawn mesh for preview GameObject mesh = Instantiate(tileObject.GetComponentInChildren <MeshFilter>().gameObject); Renderer meshRenderer = mesh.GetComponent <Renderer>(); Vector3 size = meshRenderer.bounds.size; Vector3 scale = transform.localScale; if (size.x > size.y) { if (size.x > size.z) { scale /= size.x; } else { scale /= size.z; } } else if (size.z > size.y) { if (size.z > size.x) { scale /= size.z; } else { scale /= size.x; } } else { scale /= size.y; } scale.Scale(new Vector3(1, 1, 0.1f)); //mesh.transform.localScale = scale*40; scale.Scale(new Vector3(0.02f, 0.0007f, 1f)); mesh.transform.localScale = scale; mesh.transform.parent = f.transform; //mesh.transform.localPosition = new Vector3(f.transform.position.x, f.transform.position.y-30f, -10); mesh.transform.localPosition = new Vector3(); mesh.transform.localEulerAngles = new Vector3(); }
//Add a prefab to the gridview public void AddPrefab(BaseTileObject prefab) { prefabs.Add(prefab); InstantiateObject(prefab.getPrefab().gameObject); }