-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAvatarImageEncoderWindow.cs
93 lines (77 loc) · 3.24 KB
/
AvatarImageEncoderWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#if VRCHAT_API_TOOLS_IMPORTED
using BocuD.VRChatApiTools;
using System.IO;
using AvatarImageReader.Enums;
using UnityEditor;
using UnityEngine;
using VRC.Core;
namespace AvatarImageReader.Editor
{
public class AvatarImageEncoderWindow : EditorWindow
{
private string text;
private Texture2D output;
private ApiAvatar selectedAvatar;
private EditorCoroutine ImageUploader;
[MenuItem("Tools/Avatar Image Encoder")]
private static void ShowWindow()
{
AvatarImageEncoderWindow encoderWindow = GetWindow<AvatarImageEncoderWindow>();
}
private void OnGUI()
{
EditorGUILayout.LabelField("Text to encode");
text = EditorGUILayout.TextArea(text);
if (GUILayout.Button("Encode Image"))
{
Texture2D[] outputImages = AvatarImageEncoder.EncodeText(text, new string[1] { selectedAvatar.id }, 128, 96, DataMode.UTF8);
output = outputImages[0];
}
if (output != null)
{
GUIContent texturePreview = new GUIContent(output);
GUILayout.Box(texturePreview);
if (GUILayout.Button("Save"))
{
string path = EditorUtility.SaveFilePanel(
"Save texture as PNG",
Application.dataPath,
"output.png",
"png");
if (path.Length != 0)
{
var pngData = output.EncodeToPNG();
if (pngData != null)
File.WriteAllBytes(path, pngData);
path = "Assets" + path.Substring(Application.dataPath.Length);
AssetDatabase.WriteImportSettingsIfDirty(path);
AssetDatabase.ImportAsset(path);
TextureImporter importer = (TextureImporter) AssetImporter.GetAtPath(path);
importer.npotScale = TextureImporterNPOTScale.None;
importer.textureCompression = TextureImporterCompression.Uncompressed;
importer.maxTextureSize = 2048;
EditorUtility.SetDirty(importer);
AssetDatabase.WriteImportSettingsIfDirty(path);
AssetDatabase.ImportAsset(path);
}
}
if (GUILayout.Button("Select avatar"))
{
BlueprintPicker.BlueprintSelector<ApiAvatar>(avatar => selectedAvatar = avatar);
}
if (selectedAvatar != null)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.TextField("Selected Avatar:", selectedAvatar.name);
EditorGUI.EndDisabledGroup();
if (GUILayout.Button("Upload Image"))
{
VRChatApiUploaderAsync vrChatApiUploaderAsync = new VRChatApiUploaderAsync();
vrChatApiUploaderAsync.UpdateBlueprintImage(selectedAvatar, output);
}
}
}
}
}
}
#endif