Skip to content

Commit

Permalink
Create SDK package
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed May 21, 2024
1 parent f689343 commit 0e612cf
Show file tree
Hide file tree
Showing 92 changed files with 857 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async UniTaskVoid Load()
Status.text = statusText.AsFormat(avatar.Path.Replace(@"\", @"\\"));
await UniTask.Delay(TimeSpan.FromSeconds(2));
var dir = Path.GetDirectoryName(avatar.Path);
var res = NativeFileDialogSharp.Dialog.FileOpen("vsfavatar,vrm", Directory.Exists(dir) ? dir : null);
var res = NativeFileDialogSharp.Dialog.FileOpen("ava,vsfavatar,vrm", Directory.Exists(dir) ? dir : null);
Status.text = "";

if (res.IsOk)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/UI/AvatarsPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void Awake()

public void AddAvatar()
{
var result = NativeFileDialogSharp.Dialog.FileOpen("vsfavatar,vrm");
var result = NativeFileDialogSharp.Dialog.FileOpen("ava,vsfavatar,vrm");
if (result.IsOk)
StartCoroutine(AddAvatar(result.Path));
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "AvatarViewer.SDK.Editor",
"rootNamespace": "",
"references": [
"GUID:45eb7e608532af94697dea786c597332",
"GUID:05dd262a0c0a2f841b8252c8c3815582"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
// Adapted from TWSDK
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEditor;
using VRM;
using UnityEngine;

namespace VSeeFace
{
public class ExportAvatar : MonoBehaviour
{
[MenuItem("VSF SDK/Export avatar bundle")]
[MenuItem("Avatar Viewer/Export bundle")]
public static void ExportAvatarBundle()
{
GameObject obj = Selection.activeGameObject;
string error;
if (!AvatarCheck.CheckAvatar(obj, out error)) {
if (!AvatarCheck.CheckAvatar(obj, out error))
{
EditorUtility.DisplayDialog("Export Avatar Bundle", error, "OK");
return;
}
string fullpath = EditorUtility.SaveFilePanel("Export Avatar Bundle", ".", obj.name, "vsfavatar");

string fullpath = EditorUtility.SaveFilePanel("Export Avatar Bundle", ".", obj.name, "ava");
if (fullpath == null || fullpath == "")
return;

string filename = Path.GetFileName(fullpath);

bool complete = false;
string prefabPath = "Assets/VSFAvatarTemporary.prefab";
try {
string prefabPath = "Assets/AvATemporary.prefab";
try
{
AssetDatabase.DeleteAsset(prefabPath);
if (File.Exists(prefabPath))
File.Delete(prefabPath);

bool succeededPack = false;
PrefabUtility.SaveAsPrefabAsset(obj, prefabPath, out succeededPack);
if (!succeededPack) {
if (!succeededPack)
{
Debug.Log("Prefab creation failed");
return;
}
Expand All @@ -46,26 +45,30 @@ public static void ExportAvatarBundle()
bundleBuild.assetNames = new string[] { prefabPath };
bundleBuild.addressableNames = new string[] { "VSFAvatar" };

BuildAssetBundleOptions options = BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.DeterministicAssetBundle | BuildAssetBundleOptions.StrictMode;
if (obj.GetComponentsInChildren<UnityEngine.Video.VideoPlayer>(true).Length > 0) {
BuildAssetBundleOptions options = BuildAssetBundleOptions.ForceRebuildAssetBundle | BuildAssetBundleOptions.StrictMode | BuildAssetBundleOptions.ChunkBasedCompression;
if (obj.GetComponentsInChildren<UnityEngine.Video.VideoPlayer>(true).Length > 0)
{
Debug.Log("VideoPlayer detected, using uncompressed asset bundle.");
options = options | BuildAssetBundleOptions.UncompressedAssetBundle;
}
BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { bundleBuild }, options, BuildTarget.StandaloneWindows);
BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { bundleBuild }, options, EditorUserBuildSettings.activeBuildTarget);
if (File.Exists(fullpath))
File.Delete(fullpath);
File.Move(Application.temporaryCachePath + "/" + filename, fullpath);

File.Move(Path.Combine(Application.temporaryCachePath, filename), fullpath);

EditorUtility.DisplayDialog("Export", "Export complete!", "OK");
complete = true;
}
finally
{
try {
try
{
AssetDatabase.DeleteAsset(prefabPath);
if (File.Exists(prefabPath))
File.Delete(prefabPath);
} catch {}
}
catch { }

if (!complete)
EditorUtility.DisplayDialog("Export", "Export failed! See the console for details.", "OK");
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Packages/net.guerra24.avatarviewer.sdk/Editor/VSF/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2019, Emiliana (https://twitter.com/Emiliana_vt / https://github.com/emilianavt/)

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e612cf

Please sign in to comment.