add package files
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.OpenXR;
|
||||
using UnityEngine.XR.OpenXR.Samples.MeshingFeature;
|
||||
using UnityEditor.XR.OpenXR.Features;
|
||||
|
||||
namespace UnityEditor.XR.OpenXR.Samples.MeshingFeature
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom editor for meshing behaviour that ensures the meshing feature plugin can be loaded.
|
||||
///
|
||||
/// For the SceneUnderstanding sample to be loaded the sample folder must be an immediate child of the 'Assets' folder and
|
||||
/// must be there on Unity startup. This script will copy the sample folder to the required destination and attempt
|
||||
/// to force a restart after.
|
||||
///
|
||||
/// Note that this script will self destruct after running by deleting the script asset to ensure it only ever runs once.
|
||||
///
|
||||
/// Note that when developing samples this copying functionality may not be desired. To disable this
|
||||
/// functionality add the UNITY_SAMPLE_DEV define to your project.
|
||||
/// </summary>
|
||||
[InitializeOnLoad]
|
||||
public class MeshingFeatureInstaller : Editor
|
||||
{
|
||||
#if !UNITY_SAMPLE_DEV
|
||||
private const string k_MeshingFeaturePath = "SceneUnderstanding Example/MeshingFeaturePlugin/UnitySubsystemsManifest.json";
|
||||
|
||||
private const string k_ErrorMessage = "The SceneUnderstanding Example requires the `MeshingFeaturePlugin' folder be moved to the root 'Assets` folder to run properly. An attempt was made to automatically move these files to the correct location but failed, please move these files manaually before running the sample.";
|
||||
|
||||
private const string k_DialogText = "The SceneUnderstanding Example requires that the MeshingFeature subsystem be registered, which will require Unity editor to be restarted.\n\nDo you want to *RESTART* the editor now?";
|
||||
|
||||
static MeshingFeatureInstaller()
|
||||
{
|
||||
// Automatically enable the feature
|
||||
FeatureHelpers.RefreshFeatures(BuildTargetGroup.Standalone);
|
||||
var feature = OpenXRSettings.Instance.GetFeature<MeshingTeapotFeature>();
|
||||
if (feature != null)
|
||||
feature.enabled = true;
|
||||
|
||||
// Find the subsystem manifest to figure out where the sample was installed
|
||||
var source = AssetDatabase
|
||||
.FindAssets(Path.GetFileNameWithoutExtension(k_MeshingFeaturePath))
|
||||
.Select(AssetDatabase.GUIDToAssetPath)
|
||||
.FirstOrDefault(r => r.Contains(k_MeshingFeaturePath));
|
||||
|
||||
if (string.IsNullOrEmpty(source))
|
||||
{
|
||||
Debug.LogError(k_ErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract the `UnitySubsystemsManifest.json` from the path
|
||||
source = Path.GetDirectoryName(source);
|
||||
|
||||
// Target path is 'Assets/<sample folder name>`
|
||||
var target = Path.Combine("Assets", Path.GetFileNameWithoutExtension(source));
|
||||
|
||||
// Attempt to move the entire folder
|
||||
var moveResult = AssetDatabase.MoveAsset(source, target);
|
||||
if (!string.IsNullOrWhiteSpace(moveResult))
|
||||
{
|
||||
Debug.LogError(moveResult);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"Moved '{source}' to '{target}");
|
||||
|
||||
if (EditorUtility.DisplayDialog("Warning", k_DialogText, "Yes", "No"))
|
||||
{
|
||||
// Restart editor.
|
||||
var editorApplicationType = typeof(EditorApplication);
|
||||
var requestCloseAndRelaunchWithCurrentArgumentsMethod =
|
||||
editorApplicationType.GetMethod("RequestCloseAndRelaunchWithCurrentArguments",
|
||||
BindingFlags.NonPublic | BindingFlags.Static);
|
||||
|
||||
if (requestCloseAndRelaunchWithCurrentArgumentsMethod == null)
|
||||
throw new MissingMethodException(editorApplicationType.FullName, "RequestCloseAndRelaunchWithCurrentArguments");
|
||||
|
||||
requestCloseAndRelaunchWithCurrentArgumentsMethod.Invoke(null, null);
|
||||
}
|
||||
|
||||
// Self destruct
|
||||
AssetDatabase.DeleteAsset(Path.Combine(Path.GetDirectoryName(source), "Editor"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 889289a1c4a096340aede480e53f0e7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user