public static GenericMenu GetMenu(object o, ECSContext inspectedECSContext) { var menu = new GenericMenu(); if (TypeUtility.IsNull(o)) { return(menu); } if (o is MonoScript monoScript) { Type classType = monoScript.GetClass(); if (classType != null) { if (classType.IsSubclassOf(typeof(ScriptableObject))) { menu.AddItem(new GUIContent("Instantiate Asset"), false, InstantiateScript, classType); } else if (classType.IsSubclassOf(typeof(Component))) { menu.AddItem(new GUIContent("Instantiate In Scene"), false, InstantiateScript, classType); } } } if (o is GameObject gameObject) { menu.AddItem(new GUIContent("Set Name From First Script"), false, SetNameFromFirstScript, gameObject); } if (o is Object unityObject) { menu.AddItem(new GUIContent("Set Name From Type"), false, () => unityObject.name = o.GetType().Name); } if (o is Texture2D) { menu.AddItem(new GUIContent("Export Texture"), false, ExportTexture, o); } if (o is Component component) { menu.AddItem(new GUIContent("Remove Component"), false, () => { Undo.DestroyObjectImmediate(component); }); } #if ECS_EXISTS if (inspectedECSContext != null && o.GetType().GetInterfaces().Contains(typeof(IComponentData))) { menu.AddItem(new GUIContent("Remove Component"), false, () => { inspectedECSContext.EntityManager.RemoveComponent(inspectedECSContext.Entity, new ComponentType(o.GetType())); }); } if (o is Translation translation) { menu.AddItem(new GUIContent("Focus In Scene View"), false, () => { SceneView sceneView = SceneView.lastActiveSceneView; if (sceneView == null) { sceneView = EditorWindow.GetWindow <SceneView>(); } sceneView.pivot = translation.Value; sceneView.Show(); }); } if (o is LocalToWorld localToWorld) { menu.AddItem(new GUIContent("Focus In Scene View"), false, () => { SceneView sceneView = SceneView.lastActiveSceneView; if (sceneView == null) { sceneView = EditorWindow.GetWindow <SceneView>(); } sceneView.pivot = localToWorld.Position; sceneView.Show(); }); } #endif MonoScript targetMonoScript = GetMonoScriptForType(o.GetType()); if (targetMonoScript != null) { menu.AddItem(new GUIContent("Select Script"), false, _ => Selection.activeObject = targetMonoScript, targetMonoScript); menu.AddItem(new GUIContent("Edit Script"), false, _ => AssetDatabase.OpenAsset(targetMonoScript), targetMonoScript); } menu.AddItem(new GUIContent("Copy As JSON (Unity JsonUtility)"), false, CopyAsJSON, o); return(menu); }