Skip to content

Commit

Permalink
Merge pull request #568 from ousttrue/fix_prefabutility_warning
Browse files Browse the repository at this point in the history
fix warnings
  • Loading branch information
ousttrue committed Sep 29, 2020
2 parents fbfae2c + 0c10e5f commit b4f4a4a
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions Assets/VRM/UniVRM/Editor/SkinnedMeshUtility/SkinnedMeshUtility.cs
Expand Up @@ -9,7 +9,7 @@ public static class SkinnedMeshUtility
{
public const string MENU_KEY = "GameObject/UnityEditorScripts/";
public const int MENU_PRIORITY = 11;

public static Object GetPrefab(GameObject instance)
{
#if UNITY_2018_2_OR_NEWER
Expand All @@ -21,22 +21,39 @@ public static Object GetPrefab(GameObject instance)

public static bool IsPrefab(Object instance)
{
return instance != null && PrefabUtility.GetPrefabType(instance) == PrefabType.Prefab;
if (instance == null)
{
return false;
}
if (PrefabUtility.GetPrefabAssetType(instance) != PrefabAssetType.Regular)
{
return false;
}
return true;
}

public static void ApplyChangesToPrefab(GameObject instance)
{
var prefab = GetPrefab(instance);
if (prefab == null) return;
if (prefab == null)
{
return;
}

var path = AssetDatabase.GetAssetPath(prefab);
if (string.IsNullOrEmpty(path))
{
return;
}

PrefabUtility.ReplacePrefab(instance, prefab, ReplacePrefabOptions.ConnectToPrefab);
PrefabUtility.SaveAsPrefabAssetAndConnect(instance, path, InteractionMode.AutomatedAction);
}

public static GameObject InstantiatePrefab(GameObject prefab)
{
if (!IsPrefab(prefab)) return null;

return (GameObject) PrefabUtility.InstantiatePrefab(prefab);
return (GameObject)PrefabUtility.InstantiatePrefab(prefab);
}
}
}

0 comments on commit b4f4a4a

Please sign in to comment.