Created
April 15, 2020 03:56
-
-
Save ellisgeek/5ecec00e536aa38dcf0d800c68ad434c to your computer and use it in GitHub Desktop.
Custom Avatar Exporter fix for 5.0.0 beta 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using UnityEngine; | |
using CustomAvatar; | |
public class CompileAvatarWindow : EditorWindow | |
{ | |
private AvatarDescriptor[] avatars; | |
[MenuItem("Window/Avatar Exporter")] | |
public static void ShowWindow() | |
{ | |
EditorWindow.GetWindow(typeof(CompileAvatarWindow),false , "Avatar Exporter"); | |
} | |
void OnGUI() | |
{ | |
GUILayout.Label("Avatars", EditorStyles.boldLabel); | |
GUILayout.Space(20); | |
foreach (AvatarDescriptor avatar in avatars) | |
{ | |
if (avatar == null) | |
{ | |
return; | |
} | |
GUILayout.Label ("GameObject : " + avatar.gameObject.name, EditorStyles.boldLabel); | |
avatar.author = EditorGUILayout.TextField("Author Name", avatar.author); | |
avatar.name = EditorGUILayout.TextField("Avatar Name", avatar.name); | |
EditorGUI.BeginDisabledGroup (avatar.transform.Find("LeftHand") == null || avatar.transform.Find("RightHand") == null || avatar.transform.Find("Body") == null || avatar.transform.Find("Head") == null); | |
if(GUILayout.Button("Export " + avatar.name)) | |
{ | |
GameObject avatarObject = avatar.gameObject; | |
if (avatarObject != null && avatar != null) | |
{ | |
string path = EditorUtility.SaveFilePanel("Save .avatar file", "", avatar.name + ".avatar", "avatar"); | |
Debug.Log(path == ""); | |
if (path != "") { | |
string fileName = Path.GetFileName (path); | |
string folderPath = Path.GetDirectoryName (path); | |
Selection.activeObject = avatarObject; | |
EditorUtility.SetDirty (avatar); | |
EditorSceneManager.MarkSceneDirty (avatarObject.scene); | |
EditorSceneManager.SaveScene (avatarObject.scene); | |
PrefabUtility.CreatePrefab ("Assets/_CustomAvatar.prefab", Selection.activeObject as GameObject); | |
AssetBundleBuild assetBundleBuild = default(AssetBundleBuild); | |
assetBundleBuild.assetNames = new string[] { | |
"Assets/_CustomAvatar.prefab" | |
}; | |
assetBundleBuild.assetBundleName = fileName; | |
BuildTargetGroup selectedBuildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup; | |
BuildTarget activeBuildTarget = EditorUserBuildSettings.activeBuildTarget; | |
BuildPipeline.BuildAssetBundles (Application.temporaryCachePath, new AssetBundleBuild[]{ assetBundleBuild }, 0, EditorUserBuildSettings.activeBuildTarget); | |
EditorPrefs.SetString ("currentBuildingAssetBundlePath", folderPath); | |
EditorUserBuildSettings.SwitchActiveBuildTarget (selectedBuildTargetGroup, activeBuildTarget); | |
AssetDatabase.DeleteAsset ("Assets/_CustomAvatar.prefab"); | |
File.Move (Application.temporaryCachePath + "/" + fileName, path); | |
AssetDatabase.Refresh (); | |
EditorUtility.DisplayDialog ("Export Successful!", "Export Successful!", "OK"); | |
} else { | |
EditorUtility.DisplayDialog ("Export Failed!", "Path is invalid.", "OK"); | |
} | |
} | |
else | |
{ | |
EditorUtility.DisplayDialog ("Export Failed!", "Saber GameObject is missing.", "OK"); | |
} | |
} | |
EditorGUI.EndDisabledGroup (); | |
if (avatar.transform.Find("LeftHand") == null) { | |
GUILayout.Label ("LeftHand gameObject is missing", EditorStyles.boldLabel); | |
} | |
if (avatar.transform.Find("RightHand") == null) { | |
GUILayout.Label ("RightHand gameObject is missing", EditorStyles.boldLabel); | |
} | |
if (avatar.transform.Find("Body") == null) { | |
GUILayout.Label ("Body gameObject is missing", EditorStyles.boldLabel); | |
} | |
if (avatar.transform.Find("Head") == null) { | |
GUILayout.Label ("Head gameObject is missing", EditorStyles.boldLabel); | |
} | |
GUILayout.Space(20); | |
} | |
} | |
private void OnFocus() | |
{ | |
avatars = GameObject.FindObjectsOfType<AvatarDescriptor>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment