Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Texture2D GetTexture2DFacePreset(FacePreset thisFacePreset, string generateIconHere, string iconName)
- {
- if (thisFacePreset != null)
- {
- if (customisablePerson != null)
- {
- customisablePerson.LoadPreset(thisFacePreset);
- Texture2D generatedTexture = GrabIconTexture();
- string assetPath = Path.GetDirectoryName(generateIconHere) + "/Icons/" + iconName + ".png";
- byte[] bytes = generatedTexture.EncodeToPNG();
- File.WriteAllBytes(assetPath, bytes);
- #if UNITY_EDITOR
- AssetDatabase.ImportAsset(assetPath);
- #endif
- return generatedTexture;
- }
- }
- return null;
- }
- public Texture2D GrabIconTexture()
- {
- if (cam == null)
- cam = transform.Find("IconCamera").GetComponent<Camera>();
- RenderTexture rt = new RenderTexture(width, height,24, RenderTextureFormat.ARGB32);
- cam.targetTexture = rt;
- _screenShot = new Texture2D(width, height, textureFormat, false);
- cam.Render();
- RenderTexture.active = rt;
- _screenShot.ReadPixels(new Rect(0, 0, width, height), 0, 0);
- _screenShot.Apply();
- cam.targetTexture = null;
- RenderTexture.active = null;
- if (Application.isPlaying)
- Destroy(rt);
- else
- DestroyImmediate(rt);
- return _screenShot;
- }
Advertisement
Add Comment
Please, Sign In to add comment