VRM10Object を作成するステップ

* VRM10Object が無いときにエラー表示
* VRM10Object が無ければ VRM10Instance を停止させる
This commit is contained in:
ousttrue
2022-10-21 15:20:57 +09:00
parent f33b8dbb46
commit b18e5cd63b
4 changed files with 47 additions and 11 deletions

View File

@@ -35,15 +35,15 @@ namespace UniGLTF
return path;
}
public static string GetDir(string title, string name)
public static string GetDir(string title, string dir = null)
{
string directory = m_lastExportDir;
string directory = string.IsNullOrEmpty(dir) ? m_lastExportDir : dir;
if (string.IsNullOrEmpty(directory))
{
directory = Directory.GetParent(Application.dataPath).ToString();
}
var path = EditorUtility.SaveFolderPanel(title, directory, name);
var path = EditorUtility.SaveFolderPanel(title, directory, null);
if (!string.IsNullOrEmpty(path))
{
m_lastExportDir = Path.GetDirectoryName(path).Replace("\\", "/");

View File

@@ -115,6 +115,21 @@ namespace UniVRM10
return loaded;
}
static string GetSaveName(Vrm10Instance instance)
{
if (instance == null)
{
return "Assets/vrm-1.0.assets";
}
if (VRMShaders.PathObject.TryGetFromAsset(instance, out var asset))
{
return (asset.Parent.Child(instance.name + ".asset")).UnityAssetPath;
}
return $"Assets/{instance.name}.assets";
}
void SetupVRM10Object(Vrm10Instance instance)
{
if (!CheckHumanoid(instance.gameObject))
@@ -124,10 +139,17 @@ namespace UniVRM10
}
EditorGUILayout.HelpBox("Humanoid OK.", MessageType.Info);
// VRM10Object
var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm));
if (prop.objectReferenceValue == null)
{
EditorGUILayout.HelpBox("No VRM10Object.", MessageType.Error);
}
if (GUILayout.Button("Create new VRM10Object"))
{
var saveName = (instance.name ?? "vrm-1.0");
var dir = SaveFileDialog.GetDir(SaveTitle, saveName);
var saveName = GetSaveName(instance);
var dir = SaveFileDialog.GetDir(SaveTitle, System.IO.Path.GetDirectoryName(saveName));
if (!string.IsNullOrEmpty(dir))
{
var expressions = new Dictionary<ExpressionPreset, VRM10Expression>();
@@ -146,7 +168,6 @@ namespace UniVRM10
{
// update editor
serializedObject.Update();
var prop = serializedObject.FindProperty(nameof(Vrm10Instance.Vrm));
prop.objectReferenceValue = asset;
serializedObject.ApplyModifiedProperties();
}

View File

@@ -92,6 +92,13 @@ namespace UniVRM10
void Start()
{
if (Vrm == null)
{
Debug.LogError("no VRM10Object");
enabled = false;
return;
}
// cause new Vrm10Runtime.
// init LookAt init rotation.
var runtime = Runtime;

View File

@@ -161,14 +161,22 @@ namespace VRMShaders
}
var assetPath = AssetDatabase.GetAssetPath(src);
if (string.IsNullOrEmpty(assetPath))
if (!string.IsNullOrEmpty(assetPath))
{
dst = default;
return false;
dst = FromUnityAssetPath(assetPath);
return true;
}
dst = FromUnityAssetPath(assetPath);
return true;
var prefab = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(src);
if (!string.IsNullOrEmpty(prefab))
{
dst = FromUnityAssetPath(prefab);
return true;
}
dst = default;
return false;
}
public void ImportAsset()