/// <summary> /// Function to generate sprites for every vehicle in the game. /// It generates the sprite for the first prefab in the list. /// </summary> private void GenerateVehicleSprites() { foreach (VehiclePrefab vehiclePrefab in _assetBundleSettingsSettings.Vehicles) { // Generate a texture of the prefab Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(GetPrefab(vehiclePrefab.PrefabNames.First()) .transform); // Add the sprite to the caching dictionary _spriteCacheDictionary.Add(vehiclePrefab.Name, texture.GenerateSprite()); } Texture2D planeTexture = RuntimePreviewGenerator.GenerateModelPreview( GetPrefab(SettingsManager.Instance.Settings.AssetBundle.Chaos.PlanePrefab) .transform); _spriteCacheDictionary.Add(SettingsManager.Instance.Settings.AssetBundle.Chaos.PlanePrefab, planeTexture.GenerateSprite()); Texture2D tankTexture = RuntimePreviewGenerator.GenerateModelPreview( GetPrefab(SettingsManager.Instance.Settings.AssetBundle.Chaos.TankPrefab) .transform); _spriteCacheDictionary.Add(SettingsManager.Instance.Settings.AssetBundle.Chaos.TankPrefab, tankTexture.GenerateSprite()); }
public void Populate() { UIManager manager = GameObject.Find("Canvas").GetComponent <UIManager>(); Kategorie = manager.KategorieClicked; Debug.Log("Populate Kategorie" + Kategorie.Name); GameObject newObj; Debug.Log(Kategorie.gameObjects.Length); for (int i = 0; i < Kategorie.gameObjects.Length; i++) { newObj = Instantiate(prefab, transform); newObj.GetComponent <Eintrag>().Name = (Kategorie.gameObjects[i] as GameObject).name; newObj.GetComponent <Eintrag>().Width = (Kategorie.gameObjects[i] as GameObject).transform.localScale.x; newObj.GetComponent <Eintrag>().Heigth = (Kategorie.gameObjects[i] as GameObject).transform.localScale.y; newObj.GetComponent <Eintrag>().Depth = (Kategorie.gameObjects[i] as GameObject).transform.localScale.z; newObj.GetComponent <Eintrag>().GameObject = Kategorie.gameObjects[i] as GameObject; InstantiatedObjects.Add(newObj); GameObject go = Kategorie.gameObjects[i] as GameObject; Sprite mySprite = Sprite.Create(RuntimePreviewGenerator.GenerateModelPreview(go.transform, 128, 128), new Rect(.0f, .0f, 128, 128), new Vector2(.5f, .5f), 100.0f); newObj.GetComponent <Eintrag>().Image.sprite = mySprite; } }
/// <summary> /// Rafraichis la palette selont une liste des Rails modèles /// </summary> /// <param name="rails"></param> /// <param name="buttonCallback"></param> public void RefreshPalette(List <Rail> rails, System.Action <int> buttonCallback) { // Clear foreach (Transform child in paletteContent) { Destroy(child.gameObject); } Rail rail; for (int i = 0; i < rails.Count; i++) { rail = rails[i]; Texture2D preview = RuntimePreviewGenerator.GenerateModelPreview(rail.transform, _iconsSize, _iconsSize); Button button = Instantiate(railIconPrefab, paletteContent); button.image.sprite = Sprite.Create(preview, new Rect(0, 0, _iconsSize, _iconsSize), new Vector2(0.5f, 0.5f)); // local copy int buttonId = i; button.onClick.AddListener(() => buttonCallback(buttonId)); } }
public void Initialize(Prop prop) { Prop = prop; _nameText.text = prop.Name; if (prop.Object is GameObject gameObj && _previewImage) { _previewImage.color = Color.white; _propCamera.gameObject.SetActive(true); var previewObject = GameObject.Instantiate <GameObject>(gameObj); foreach (var rb in previewObject.GetComponentsInChildren <Rigidbody>()) { rb.isKinematic = true; } RuntimePreviewGenerator.PreviewRenderCamera = _propCamera; RuntimePreviewGenerator.OrthographicMode = true; _previewImage.texture = RuntimePreviewGenerator.GenerateModelPreview(previewObject.transform, 1024, 1024); GameObject.Destroy(previewObject); _propCamera.gameObject.SetActive(false); } _button.onClick.AddListener(() => { OnClicked.Invoke(); }); if (!string.IsNullOrEmpty(prop.Tags)) { Tags = prop.Tags.Split(',').ToList(); } else { Tags = new List <string>(); } }
IEnumerator Gen() { RuntimePreviewGenerator.PreviewDirection = new Vector3(50, -35, -40); RuntimePreviewGenerator.BackgroundColor = new Color(0, 0, 0, 0); RuntimePreviewGenerator.Padding = -0.05f; yield return(null); mapDisplay.sprites = new Texture2D[MapStorage.CurrentMaps.Length]; BoardManager b = Instantiate(GameManager.gameManager.boardPrefab, new Vector3(10000, 10000, 10000), Quaternion.identity).GetComponent <BoardManager>(); for (int i = 0; i < MapStorage.CurrentMaps.Length; i++) { b.GenerateBoard(MapStorage.CurrentMaps[i]); yield return(null); mapDisplay.sprites[i] = RuntimePreviewGenerator.GenerateModelPreview(b.transform, 1000, 1000, false); } b.ClearBoard(); Destroy(b.gameObject); #if UNITY_EDITOR mapDisplay.InitDisplay(); #endif for (int i = 0; i < displayRack.displays.Length; i++) { if (displayRack.displays[i].prefab != null) { displayRack.displays[i].sprite = RuntimePreviewGenerator.GenerateModelPreview(displayRack.displays[i].prefab.transform, 1000, 1000); } yield return(null); } done = true; Destroy(gameObject); }
/// <summary> /// Uses RuntimePreviewGenerator to generate thumbnails for the avatar selecter UI. /// </summary> /// <param name="_gameObject"></param> /// <returns>Returns a Texture2D.</returns> Texture2D GenerateAvatarThumbnail(GameObject _gameObject) { RuntimePreviewGenerator.PreviewRenderCamera = m_ThumbnailCamera; RuntimePreviewGenerator.BackgroundColor = m_ThumbnailBackColor; Texture2D tex = RuntimePreviewGenerator.GenerateModelPreview(_gameObject.transform, 256, 256, true); return(tex); }
public static Sprite Generate(Transform transform) { //RuntimePreviewGenerator.BackgroundColor = Color.white; RuntimePreviewGenerator.Padding = 0.25f; RuntimePreviewGenerator.OrthographicMode = true; Texture2D thumbnail = RuntimePreviewGenerator.GenerateModelPreview(transform, 512, 512, false); return(Sprite.Create(thumbnail, new Rect(0, 0, thumbnail.width, thumbnail.height), new Vector2(0.5f, 0.5f))); }
private void GenerateTexture(GameObject thumbnailTarget, string outputPath, bool compress) { var texture = RuntimePreviewGenerator.GenerateModelPreview(thumbnailTarget.transform, 128, 128, true); if (texture == null) { return; } ProcessTexture(texture, outputPath, compress); }
public void GenerateNewIcon() { RuntimePreviewGenerator.BackgroundColor = new Color(0, 0, 0, 0); RuntimePreviewGenerator.OrthographicMode = true; Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(this.transform, 128, 128, false); sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f), 100); sprite.name = transform.name; }
private void CreateGridElement(GameObject elementGrid, string elementName, string path) { //Create button gameobject GameObject go = new GameObject(elementName); go.transform.SetParent(elementGrid.transform, false); //Add interaction component BDDElementHandler bddElementHandler = go.AddComponent <BDDElementHandler>(); bddElementHandler.SetPath(path); bddElementHandler.SetElementPositioningPanel(ElementPositioningPanel); //Add image Image img = go.AddComponent <Image>() as Image; img.type = Image.Type.Sliced; //Create temporary instance to get thumb image GameObject thumbTransform = new GameObject(elementName); //Material MeshRenderer mr = thumbTransform.AddComponent <MeshRenderer>(); mr.material = Resources.Load <Material>("Materials/BenchMat"); //Mesh MeshFilter mf = thumbTransform.AddComponent <MeshFilter>(); FileStream lStream = new FileStream(path, FileMode.Open); OBJData lOBJData = OBJLoader.LoadOBJ(lStream); lStream.Close(); mf.mesh.LoadOBJ(lOBJData); mf.mesh.RecalculateNormals(); //Generate thumb Texture2D image = RuntimePreviewGenerator.GenerateModelPreview(thumbTransform.transform, 128, 128, false); img.sprite = Sprite.Create(image, new Rect(0, 0, image.width, image.height), new Vector2(0.5f, 0.5f)); //Destroy temporary instance Destroy(thumbTransform); //Text under button GameObject txGO = new GameObject(); Text tx = txGO.AddComponent <Text>() as Text; tx.text = elementName; tx.color = Color.black; tx.alignment = TextAnchor.UpperCenter; tx.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; tx.fontStyle = FontStyle.Bold; tx.fontSize = 14; //tx.resizeTextForBestFit = true; //tx.resizeTextMaxSize = 25; txGO.transform.position = new Vector3(0, -63, 0); txGO.transform.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 25); txGO.transform.SetParent(go.transform, false); }
// Create sprites for the assests menu void SetPanelSprite(GameObject obj, GameObject asset, Color BackgroundColor) { Image img = obj.GetComponent <Image>(); if (img != null) { RuntimePreviewGenerator.BackgroundColor = BackgroundColor; Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(asset.transform, 100, 100, true); Rect rect = new Rect(0, 0, texture.width, texture.height); Vector2 pivot = new Vector2(1, 1); Sprite preview = Sprite.Create(texture, rect, pivot); img.sprite = preview; } }
public static Sprite GetSprite(ViewTypeId typeId, int width = 48, int height = 48) { var dictKey = new ViewKey(typeId, width, height); if (Sprites.TryGetValue(dictKey, out var sprite)) { return(sprite); } ViewObject viewObject = ViewObjectsBase.Instance.GetViewObject(typeId); if (viewObject is SpriteObject spriteObject) { return(Sprites[dictKey] = spriteObject.sprite); } Texture2D texture; if (viewObject is AbstractLineObject lineObject) { texture = (Texture2D)lineObject.material.mainTexture; if (texture == null) { texture = new Texture2D(1, 1, TextureFormat.ARGB32, false); texture.SetPixel(0, 0, lineObject.material.color); texture.Apply(); } } else { RuntimePreviewGenerator.PreviewDirection = Vector3.forward; RuntimePreviewGenerator.BackgroundColor = Color.clear; RuntimePreviewGenerator.OrthographicMode = true; var prefabObject = (PrefabObject)viewObject; var withoutParticles = Object.Instantiate(prefabObject.gameObject); var particleSystems = withoutParticles.GetComponentsInChildren <ParticleSystem>(); foreach (var particleSystem in particleSystems) { Object.DestroyImmediate(particleSystem); } texture = RuntimePreviewGenerator.GenerateModelPreview(withoutParticles.transform, width, height); Object.DestroyImmediate(withoutParticles); } Rect rect = new Rect(0, 0, texture.width, texture.height); return(Sprites[dictKey] = Sprite.Create(texture, rect, Vector2.zero, 100)); }
/// <summary> /// Function to generate sprites for every vehicle in the game. /// It generates the sprite for the first prefab in the list. /// </summary> private void GenerateBuildingSprites() { foreach (BuildingPrefab buildingPrefab in _assetBundleSettingsSettings.Buildings) { // Generate a texture of the prefab Prefab firstBuildingPrefab = buildingPrefab.Prefabs.First(); GameObject buildingGameObject = GetPrefab(firstBuildingPrefab.Name); buildingGameObject.transform.rotation = Quaternion.Euler(0f, firstBuildingPrefab.Rotation, 0f); Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(buildingGameObject.transform); // Add the sprite to the caching dictionary _spriteCacheDictionary.Add(buildingPrefab.Name, texture.GenerateSprite()); } }
public void Populate() { GameObject newObj; foreach (KeyValuePair <string, Object[]> pair in Kategories) { newObj = Instantiate(prefab, transform); newObj.GetComponent <Kategorie>().Name = pair.Key; newObj.GetComponent <Kategorie>().gameObjects = pair.Value; GameObject go = newObj.GetComponent <Kategorie>().gameObjects[0] as GameObject; Sprite mySprite = Sprite.Create(RuntimePreviewGenerator.GenerateModelPreview(go.transform, 128, 128), new Rect(.0f, .0f, 128, 128), new Vector2(.5f, .5f), 100.0f); newObj.GetComponent <Kategorie>().Image.sprite = mySprite; } }
void CreateWeaponPanel() { if (Setup.LA[0] == 0) { string L = PlayerPrefs.GetString(string.Format("LA{0}", Setup.IdActiveRobot)); if (!PlayerPrefs.HasKey(string.Format("LA{0}", Setup.IdActiveRobot))) { L = "-1,-1,-1"; } Setup.LA = L.Split(',').Select(Int32.Parse).ToArray(); } if (Setup.LA[0] > -1) { WeaponIndex = 0; } else if (Setup.LA[1] > -1) { WeaponIndex = 1; } else if (Setup.LA[2] > -1) { WeaponIndex = 2; } GameObject i = GameObject.Find("WeaponPanel").transform.Find("Item").gameObject; RuntimePreviewGenerator.PreviewDirection = new Vector3(-0.7f, -0.4f, -1f); RuntimePreviewGenerator.Padding = 0.1f; RuntimePreviewGenerator.OrthographicMode = true; for (int x = 0; x < 3; x++) { if (Setup.LA[x] > -1) { GameObject item = Instantiate(i, GameObject.Find("WeaponPanel").transform); item.name = "Item" + x.ToString(); item.transform.Find("Weapon/Text").gameObject.GetComponent <Text>().text = (x + 1).ToString(); RuntimePreviewGenerator.BackgroundColor = new Color(0, 0, 0, 0); Texture prev = RuntimePreviewGenerator.GenerateModelPreview(Setup.Figures[Setup.LA[x]].GO.transform, 100, 100, false) as Texture; Image Im = item.transform.Find("Weapon").gameObject.GetComponent <Image>(); Im.sprite = Sprite.Create((Texture2D)prev, new Rect(0, 0, 100, 100), new Vector2(0.5f, 0.5f)); Im.color = new Color32(255, 255, 255, 255); } } Destroy(i); WeaponPanelUpdate(); }
public Sprite GenerateThumbnail() { if (thumbnail) { return(thumbnail); } //TODO: Change GenerateThumbnail to handmaded thumbnails. //This method is generating separate textures and sprites for every instance and every canvas updates! //RuntimePreviewGenerator.BackgroundColor = Color.white; RuntimePreviewGenerator.Padding = 0.25f; RuntimePreviewGenerator.OrthographicMode = true; thumbnailTexture = RuntimePreviewGenerator.GenerateModelPreview(model.transform, 512, 512, false); thumbnail = Sprite.Create(thumbnailTexture, new Rect(0, 0, thumbnailTexture.width, thumbnailTexture.height), new Vector2(0.5f, 0.5f)); return(thumbnail); }
void Start() { contentRectTransform = this.GetComponent <RectTransform> (); RuntimePreviewGenerator.BackgroundColor = Color.clear; // Define the path to the "Objects" mod folder. string objectsDir = Path.Combine(Application.streamingAssetsPath + "/Objects"); // Get a list of AssetBundles in the "Objects" mod folder. string [] objectsDirFileList = Directory.GetFiles(objectsDir, "*.object"); int objectsCounter = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 6; j++) { if (objectsCounter != objectsDirFileList.Length) { GameObject objectPrefab = LoadObjectFromAssetBundle(objectsDirFileList [objectsCounter]); if (objectPrefab != null) { RectTransform currentTile = Instantiate(listItemPrefab, contentRectTransform); currentTile.GetComponent <ListItemController> ().objectPrefab = objectPrefab; currentTile.anchoredPosition = new Vector2(listPosX, listPosY); Texture2D objectPreview = RuntimePreviewGenerator.GenerateModelPreview(objectPrefab.transform, 64, 64, false); Sprite objectPreviewSprite = Sprite.Create(objectPreview, new Rect(0, 0, 64, 64), new Vector2(0.5f, 0.5f)); currentTile.GetComponent <Image> ().overrideSprite = objectPreviewSprite; string objectName = Path.GetFileNameWithoutExtension(objectsDirFileList [objectsCounter]); currentTile.GetComponentInChildren <TextMeshProUGUI> ().SetText(objectName); listPosX += 4.25F + 20; } else { j--; } objectsCounter++; } else { break; } } listPosY += -7.25F - 20; listPosX = 14.25F; } }
public Sprite GetPreview() { IHaveInputs haveInputs = null; IHaveOutputs haveOutputs = null; if (this is IHaveInputs) { haveInputs = (IHaveInputs)this; foreach (var input in haveInputs.Inputs) { input.GetComponent <LineRenderer>().enabled = false; } } if (this is IHaveOutputs) { haveOutputs = (IHaveOutputs)this; foreach (var output in haveOutputs.Outputs) { output.GetComponent <LineRenderer>().enabled = false; } } var preview = RuntimePreviewGenerator.GenerateModelPreview(transform, 512, 512, true); #if UNITY_EDITOR var image = preview.EncodeToPNG(); System.IO.File.WriteAllBytes($@"D:\Install\Projects\UnityProjects\Logires\Assets\Sprites\Temp\{name}.png", image); #endif if (this is IHaveInputs) { foreach (var input in haveInputs.Inputs) { input.GetComponent <LineRenderer>().enabled = true; } } if (this is IHaveOutputs) { foreach (var output in haveOutputs.Outputs) { output.GetComponent <LineRenderer>().enabled = true; } } return(Sprite.Create(preview, new Rect(0, 0, 512, 512), new Vector2(0.5f, 0.5f))); }
private static GameObject createItem(GameObject obj) { GameObject btn = Instantiate(Resources.Load("Prefabs/BtnSample")) as GameObject; //set the obj btn.GetComponent <ItemListener>().setCurrGameObject(obj); ((RectTransform)btn.transform).sizeDelta = new Vector2(110, 110); //#if UNITY_EDITOR // Texture2D texture = UnityEditor.AssetPreview.GetAssetPreview(obj); Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(obj.transform, 110, 110, false); btn.GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(0, 0, 110, 110), new Vector2(0, 0)); //#endif return(btn); }
public void GenerateThumbnail(Blueprint blueprint) { // Generate Ship foreach (var block in blueprint.Blocks) { var blockGO = block.CreateInactiveInertBlockInGrid(transform); blockGO.SetActive(true); } RuntimePreviewGenerator.PreviewDirection = transform.forward; var tex = RuntimePreviewGenerator.GenerateModelPreview(transform, 512, 512, false); blueprint.Thumbnail = tex; // Cleaup Ship transform.SetActiveChildren(false); }
public static void SaveBlocks() { //получаем число блоков на сцене int i = GameObject.Find("Figures").transform.childCount; string saveStr = ""; //берем каждый блок for (int x = 0; x < i; x++) //foreach (GameObject g in allBlocks) { GameObject g = GameObject.Find("Figures").transform.GetChild(x).gameObject; //позиция блока Vector3 pos = g.transform.position; //Поворот блока Vector3 rot = g.transform.localEulerAngles; //Цвет блока Color color = g.GetComponent <MeshRenderer>().material.color; //Тип блока int id = Setup.NameToInt(g.name); if (id == -1) { continue; } //записываем информацию о блоке в строку. saveStr += string.Format("{0}#{1}#{2}#{3}#{4}#{5}#{6}#{7};", fround(pos.x), fround(pos.y), fround(pos.z), Setup.ColorToInt(color), id, rot.x, rot.y, rot.z); } //добавляем строку с блоками в хронилище PlayerPrefs.SetString(string.Format("robot{0}", Setup.IdActiveRobot), saveStr); PlayerPrefs.Save(); //Debug.Log(string.Format("Сохранено {0} блоков", i)); //Сохроняем превью Texture2D t = new Texture2D(200, 170); RuntimePreviewGenerator.BackgroundColor = new Color(34f / 255, 39f / 255, 48f / 255, 1f); RuntimePreviewGenerator.PreviewDirection = new Vector3(8, -8, -8); RuntimePreviewGenerator.OrthographicMode = true; t = (Texture2D)RuntimePreviewGenerator.GenerateModelPreview(GameObject.Find("Figures").transform, 200, 170, false); Setup.WriteTextureToPlayerPrefs(string.Format("preview{0}", Setup.IdActiveRobot), t); string L = string.Join(",", LA); //Debug.Log(L); PlayerPrefs.SetString(string.Format("LA{0}", Setup.IdActiveRobot), L); }
protected void populateArt(GameObject prefab /*, int retry =0*/) { //if (retry > 3) //{ // return; //} Texture2D art = RuntimePreviewGenerator.GenerateModelPreview(prefab.transform, 120, 80); //Texture2D art = AssetPreview.GetAssetPreview(prefab); try { Rect rec = new Rect(0, 0, art.width, art.height); cardArt.sprite = Sprite.Create(art, rec, new Vector2(0.5f, 0.5f), 100); } catch { Debug.Log("Sprite load error"); //StartCoroutine(ArtCoRou(prefab,retry+1)); } }
void populate() { clear(); print(isDesk); string[] inventory = isDesk ? deskPrefab : furniturePrefab; int page2Offset = isPage2 ? 15 : 0; for (int i = 0; i < 15 && i < inventory.Length; i++) { GameObject go = GameObject.Find("i" + i); //print("GO: " + go.name); if (go != null) { GameObject prefab = (GameObject)Instantiate(Resources .Load("3DAssets/PolygonOffice/Prefabs/Props/" + (isDesk ? "Desk Props/" : "Furniture/") + inventory[i + page2Offset])); RuntimePreviewGenerator.BackgroundColor = new Color(0, 0, 0, 0); Texture2D texture = RuntimePreviewGenerator.GenerateModelPreview(prefab.transform); toDelete.Add(texture); go.GetComponent <Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); } } }
/// <summary> /// Generates a thumbnail for the planet /// </summary> public static Texture2D GetPlanetThumbnail(CelestialBody body) { // Config RuntimePreviewGenerator.TransparentBackground = true; RuntimePreviewGenerator.BackgroundColor = Color.clear; RuntimePreviewGenerator.PreviewDirection = Vector3.forward; RuntimePreviewGenerator.Padding = -0.15f; ScaledSpaceOnDemand od = body.scaledBody.GetComponent <ScaledSpaceOnDemand>(); Boolean isLoaded = true; if (od != null) { isLoaded = od.isLoaded; if (!isLoaded) { od.LoadTextures(); } } GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); sphere.GetComponentInChildren <MeshFilter>().sharedMesh = body.scaledBody.GetComponent <MeshFilter>().sharedMesh; sphere.GetComponentInChildren <MeshRenderer>().sharedMaterial = body.scaledBody.GetComponent <MeshRenderer>().sharedMaterial; Texture2D finalTexture = RuntimePreviewGenerator.GenerateModelPreview(sphere.transform, 256, 256); Object.DestroyImmediate(sphere); if (!isLoaded) { od.UnloadTextures(); } return(finalTexture); }
private void OnGUI() { _target = (GameObject)EditorGUILayout.ObjectField("", _target, typeof(GameObject), false); _size = EditorGUILayout.Vector2IntField("", _size); if (GUILayout.Button("Make preview")) { if (_target != null) { //_target = Resources.Load("temp.prefab"); //var preview = AssetPreview.GetMiniThumbnail(_target); RuntimePreviewGenerator.PreviewDirection = new Vector3(0, 0, 1); RuntimePreviewGenerator.OrthographicMode = true; RuntimePreviewGenerator.BackgroundColor = new Color(0, 0, 0, 0); RuntimePreviewGenerator.MarkTextureNonReadable = false; var preview = RuntimePreviewGenerator.GenerateModelPreview(_target.transform, _size.x, _size.y, true); var image = preview.EncodeToPNG(); System.IO.File.WriteAllBytes(@"D:\Install\Projects\UnityProjects\Logires\Assets\Sprites\Temp.png", image); } } }
public void SetSelectedElement(GameObject go) { //Change color of the element to red this.SelectedElement = new SelectedElement(go); foreach (Material mat in SelectedElement.GetMaterials()) { mat.color = Color.red; } //Set image Texture2D image = RuntimePreviewGenerator.GenerateModelPreview(go.transform, 128, 128, false); ElementImage.sprite = Sprite.Create(image, new Rect(0, 0, image.width, image.height), new Vector2(0.5f, 0.5f)); //Active UI InteractionsCanvasController.instance.RightPanel.SetActive(true); MapCanvasController.instance.SetVisible(true); //Check if is alterable cutButton.interactable = go.GetComponent <SelectableElementController>().IsAlterable() ? true : false; //Update UI HistoryPanelManager.instance.Refresh(); }
public void PopulateList() { foreach (GameObject terrainTile in terrainTiles) { GameObject newTileItem = gameobjectItem; GameobjectListItem listItemScript = newTileItem.GetComponent <GameobjectListItem>(); Texture2D objectThumbnail = RuntimePreviewGenerator.GenerateModelPreview(terrainTile.transform); if (objectThumbnail != null) { listItemScript.ObjectThumbnail.sprite = Sprite.Create(objectThumbnail, new Rect(0.0f, 0.0f, objectThumbnail.width, objectThumbnail.height), new Vector2(), 100.0f); } listItemScript.ObjectName.text = terrainTile.name; listItemScript.Object = terrainTile; newTileItem = Instantiate(newTileItem) as GameObject; newTileItem.transform.SetParent(contentPanel); newTileItem.SetActive(true); items.Add(newTileItem); } }
public void SetUIForItem(Item item, Inventory Inv, Equipment EQ) { int count = 0; if (item && Inv) { count = Inv.HasItem(item); } gameObject.SetActive(count > 0); if (gameObject.activeSelf) { Item = item; Inventory = Inv; if (ItemImage) { ItemImage.sprite = Sprite.Create(RuntimePreviewGenerator.GenerateModelPreview(item.WorldModel.transform, _TextureSize, _TextureSize), new Rect(0, 0, _TextureSize, _TextureSize), 0.5f * Vector2.one); ItemImage.color = Color.white; } if (ItemName) { ItemName.text = item.name; } if (ItemCount) { ItemCount.gameObject.SetActive(count > 1); if (ItemCount.gameObject.activeSelf) { ItemCount.text = $"({count})"; } } EquippedMarker.SetActive(EquippedMarker && EQ && item is EquipableItem e && EQ.IsEquipped(e)); } }
public override void HandleDescriptionUI(ItemDescriptionUI UI) { if (UI) { if (UI.TitleText) { Instantiate(UI.TitleText, UI.TitleText.transform.parent).text = name; } if (UI.Image) { Instantiate(UI.Image, UI.Image.transform.parent).sprite = Sprite.Create(RuntimePreviewGenerator.GenerateModelPreview(WorldModel.transform, _TextureSize, _TextureSize), new Rect(0, 0, _TextureSize, _TextureSize), 0.5f * Vector2.one); } if (UI.GenericText) { for (int i = 0; i < Effects.Length; i++) { var D = Effects[i].GetEffectDescription(); if (!string.IsNullOrWhiteSpace(D)) { Instantiate(UI.GenericText, UI.GenericText.transform.parent).text = D; } } } if (UI.GenericText && !string.IsNullOrWhiteSpace(Description)) { Instantiate(UI.GenericText, UI.GenericText.transform.parent).text = Description; } } }
public virtual void HandleDescriptionUI(ItemDescriptionUI UI) { if (UI) { if (UI.TitleText) { Instantiate(UI.TitleText, UI.TitleText.transform.parent).text = name; } if (UI.Image) { Instantiate(UI.Image, UI.Image.transform.parent).sprite = Sprite.Create(RuntimePreviewGenerator.GenerateModelPreview(WorldModel.transform, _TextureSize, _TextureSize), new Rect(0, 0, _TextureSize, _TextureSize), 0.5f * Vector2.one); } if (UI.GenericText && !string.IsNullOrWhiteSpace(Description)) { Instantiate(UI.GenericText, UI.GenericText.transform.parent).text = Description; } } }