mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-09 12:29:23 -05:00
fix humanoid asset path
This commit is contained in:
@@ -202,9 +202,23 @@ namespace UniHumanoid
|
||||
var prefab = PrefabUtility.GetCorrespondingObjectFromSource(obj);
|
||||
if (prefab == null)
|
||||
{
|
||||
return null;
|
||||
return "Assets";
|
||||
}
|
||||
return UnityPath.FromAsset(prefab).FullPath;
|
||||
return Path.GetDirectoryName(AssetDatabase.GetAssetPath(prefab));
|
||||
}
|
||||
|
||||
static bool TryGetAssetPath(string fullpath, out string AssetPath)
|
||||
{
|
||||
fullpath = fullpath.Replace("\\", "/");
|
||||
var basePath = Application.dataPath + "/";
|
||||
if (!fullpath.StartsWith(basePath))
|
||||
{
|
||||
AssetPath = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
AssetPath = "Assets/" + fullpath.Substring(basePath.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
@@ -274,16 +288,15 @@ namespace UniHumanoid
|
||||
GetDialogDir(m_target),
|
||||
string.Format("{0}.avatar.asset", serializedObject.targetObject.name),
|
||||
"asset");
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
if (TryGetAssetPath(path, out string unityPath))
|
||||
{
|
||||
var avatar = m_target.CreateAvatar();
|
||||
if (avatar != null)
|
||||
{
|
||||
var unityPath = UnityPath.FromFullpath(path);
|
||||
avatar.name = "avatar";
|
||||
Debug.LogFormat("Create avatar {0}", unityPath);
|
||||
AssetDatabase.CreateAsset(avatar, unityPath.Value);
|
||||
AssetDatabase.ImportAsset(unityPath.Value);
|
||||
AssetDatabase.CreateAsset(avatar, unityPath);
|
||||
AssetDatabase.ImportAsset(unityPath);
|
||||
|
||||
// replace
|
||||
var animator = m_target.GetComponent<Animator>();
|
||||
@@ -296,6 +309,10 @@ namespace UniHumanoid
|
||||
Selection.activeObject = avatar;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"cannot create {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user