mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-11 21:14:19 -05:00
Merge pull request #145 from dwango/fix_asset_assign_for_avoid_overwrite
Fix asset assign for avoid overwrite
This commit is contained in:
commit
077a6d8ddb
|
|
@ -802,14 +802,31 @@ namespace UniGLTF
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool IsOverwrite(UnityEngine.Object o)
|
||||
public virtual bool AvoidOverwriteAndLoad(UnityPath assetPath, UnityEngine.Object o)
|
||||
{
|
||||
if(o is Material)
|
||||
if (o is Material)
|
||||
{
|
||||
return false;
|
||||
var loaded = assetPath.LoadAsset<Material>();
|
||||
|
||||
// replace component reference
|
||||
foreach(var mesh in Meshes)
|
||||
{
|
||||
foreach(var r in mesh.Renderers)
|
||||
{
|
||||
for(int i=0; i<r.sharedMaterials.Length; ++i)
|
||||
{
|
||||
if (r.sharedMaterials.Contains(o))
|
||||
{
|
||||
r.sharedMaterials = r.sharedMaterials.Select(x => x == o ? loaded : x).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SaveAsAsset(UnityPath prefabPath)
|
||||
|
|
@ -841,13 +858,14 @@ namespace UniGLTF
|
|||
{
|
||||
if (assetPath.IsFileExists)
|
||||
{
|
||||
if (!IsOverwrite(o))
|
||||
if (AvoidOverwriteAndLoad(assetPath, o))
|
||||
{
|
||||
// 上書きしない
|
||||
Debug.LogWarningFormat("already exists. skip {0}", assetPath);
|
||||
// 上書きせずに既存のアセットからロードして置き換えた
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// アセットとして書き込む
|
||||
assetPath.Parent.EnsureFolder();
|
||||
assetPath.CreateAsset(o);
|
||||
paths.Add(assetPath);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ namespace UniGLTF
|
|||
{
|
||||
public Mesh Mesh;
|
||||
public Material[] Materials;
|
||||
|
||||
// 複数のノードから参照されうる
|
||||
public List<Renderer> Renderers=new List<Renderer>(); // SkinnedMeshRenderer or MeshRenderer
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -341,18 +341,23 @@ namespace VRM
|
|||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public override bool IsOverwrite(UnityEngine.Object o)
|
||||
public override bool AvoidOverwriteAndLoad(UnityPath assetPath, UnityEngine.Object o)
|
||||
{
|
||||
if (o is BlendShapeAvatar)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (o is BlendShapeClip)
|
||||
{
|
||||
return false;
|
||||
var loaded = assetPath.LoadAsset<BlendShapeAvatar>();
|
||||
var proxy = Root.GetComponent<VRMBlendShapeProxy>();
|
||||
proxy.BlendShapeAvatar = loaded;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.IsOverwrite(o);
|
||||
if (o is BlendShapeClip)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.AvoidOverwriteAndLoad(assetPath, o);
|
||||
}
|
||||
|
||||
protected override UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user