Skip to content

Instantly share code, notes, and snippets.

@starikcetin
Last active October 22, 2019 01:31
Show Gist options
  • Save starikcetin/6977072a6134152eef5ca8cf891e1936 to your computer and use it in GitHub Desktop.
Save starikcetin/6977072a6134152eef5ca8cf891e1936 to your computer and use it in GitHub Desktop.
Unity Edtor-time Prefab Instantiator For Context Menu
using UnityEditor;
using UnityEngine;
internal class Instantiator : ScriptableObject
{
private static Instantiator _instance;
private static Instantiator Instance
{
get
{
if (_instance == null)
{
_instance = CreateInstance<Instantiator>();
}
return _instance;
}
}
[SerializeField] private GameObject _prefab;
[MenuItem("GameObject/Foo/Bar", false, 12)]
private static void Instantiate()
{
Selection.activeObject = PrefabUtility.InstantiatePrefab(Instance._prefab);
}
[MenuItem("GameObject/Foo/Bar", true, 12)]
private static bool ValidateInstantiate()
{
var go = Instance._prefab;
return go != null && PrefabUtility.IsPartOfPrefabAsset(go);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment