add catalog as prefab

This commit is contained in:
Legonzaur 2023-01-16 13:15:59 +01:00
parent 8aac7c382a
commit 12a77cd53d
6 changed files with 2094 additions and 0 deletions

View File

@ -0,0 +1,245 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1527984575184472642
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1527984575184472644}
- component: {fileID: 1527984575184472645}
m_Layer: 0
m_Name: Catalog
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1527984575184472644
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1527984575184472642}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.0397532, y: 1.6641229, z: -1.5216272}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6652929519105104434}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1527984575184472645
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1527984575184472642}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e448cbb02ada1545b6c4c79341232fc, type: 3}
m_Name:
m_EditorClassIdentifier:
maxShownObjects: 6
angle: 130
distance: 0.17
objectScale: 0.04
--- !u!1 &6275806258134515848
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6652929519105104434}
- component: {fileID: 3102087200456469538}
- component: {fileID: 3086371222807627863}
- component: {fileID: 7945404223398940130}
- component: {fileID: 5004594542533833549}
- component: {fileID: 1321968106976948543}
- component: {fileID: 3556194868201819980}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6652929519105104434
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.04, y: 0.04, z: 0.04}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 1527984575184472644}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3102087200456469538
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b93b6a877adcbf94c89a9d6e0c0e844d, type: 3}
m_Name:
m_EditorClassIdentifier:
activateActionSetOnAttach:
actionSetPath:
hideHandOnAttach: 1
hideSkeletonOnAttach: 0
hideControllerOnAttach: 0
handAnimationOnPickup: 0
setRangeOfMotionOnPickup: -1
useHandObjectAttachmentPoint: 1
attachEaseIn: 0
snapAttachEaseInCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
snapAttachEaseInTime: 0.15
snapAttachEaseInCompleted: 0
skeletonPoser: {fileID: 0}
handFollowTransform: 1
highlightOnHover: 1
hideHighlight: []
hoverPriority: 0
--- !u!114 &3086371222807627863
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 783750eec4c41da428b7651515146d14, type: 3}
m_Name:
m_EditorClassIdentifier:
velocityAverageFrames: 5
angularVelocityAverageFrames: 11
estimateOnAwake: 0
--- !u!114 &7945404223398940130
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e7418c7dd8f977d4e969202d3fa7e926, type: 3}
m_Name:
m_EditorClassIdentifier:
poseEditorExpanded: 1
blendEditorExpanded: 1
poseNames:
- sphereSmallPose (MAIN)
overridePreviewLeftHandPrefab: {fileID: 1000013348574242, guid: 638779290bce1af49b356f33dcc6fccf, type: 3}
overridePreviewRightHandPrefab: {fileID: 1000010304998954, guid: 6def53d002137b747aec0b29551e0e25, type: 3}
skeletonMainPose: {fileID: 11400000, guid: ccd16738d1f943640aa2aed1071a3897, type: 2}
skeletonAdditionalPoses: []
showLeftPreview: 0
showRightPreview: 0
previewLeftInstance: {fileID: 0}
previewRightInstance: {fileID: 0}
previewPoseSelection: 0
blendingBehaviours: []
scale: 1
--- !u!33 &5004594542533833549
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1321968106976948543
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!135 &3556194868201819980
SphereCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6275806258134515848}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1805c511e7b7f0e49afb0651e27725b4
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,470 @@
#if (UNITY_EDITOR && UNITY_2019_1_OR_NEWER)
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.XR.OpenVR.SimpleJSON;
using UnityEditor;
using UnityEditor.PackageManager;
using UnityEditor.PackageManager.Requests;
using UnityEditor.PackageManager.UI;
using UnityEngine;
using UnityEngine.Networking;
namespace Unity.XR.OpenVR
{
[InitializeOnLoad]
public class OpenVRPackageInstaller : ScriptableObject
{
private const string valveOpenVRPackageString = "com.valvesoftware.unity.openvr";
private static ListRequest listRequest;
private static AddRequest addRequest;
private static System.Diagnostics.Stopwatch packageTime = new System.Diagnostics.Stopwatch();
private const float estimatedTimeToInstall = 90; // in seconds
private const string updaterKeyTemplate = "com.valvesoftware.unity.openvr.updateState.{0}";
private static string updaterKey
{
get { return string.Format(updaterKeyTemplate, Application.productName); }
}
private static UpdateStates updateState
{
get { return _updateState; }
set
{
#if VALVE_DEBUG
Debug.Log("[DEBUG] Update State: " + value.ToString());
#endif
_updateState = value;
EditorPrefs.SetInt(updaterKey, (int)value);
}
}
private static UpdateStates _updateState = UpdateStates.Idle;
private static double runningSeconds
{
get
{
if (packageTime.IsRunning == false)
packageTime.Start();
return packageTime.Elapsed.TotalSeconds;
}
}
private static bool forced = false;
public static void Start(bool force = false)
{
EditorApplication.update -= Update;
EditorApplication.update += Update;
if (force)
{
RemoveScopedRegistry();
}
}
static OpenVRPackageInstaller()
{
#if OPENVR_XR_API //if we're updating, go ahead and just start
Start();
#endif
}
/// <summary>
/// State Machine
/// Idle: Start from last known state. If none is known, ask user if they want to install, if yes goto remove scoped registry step
/// WaitingOnExistingCheck:
/// RemoveScopedRegistry: Remove the scoped registry entry if it exists
/// WaitingForAdd: if the add request has been nulled or completed successfully, request a list of packages for confirmation
/// WaitingForAddConfirmation: enumerate the packages and verify the add succeeded. If it failed, try again.
/// If it succeeded request removal of this script
/// RemoveSelf: delete the key that we've been using to maintain state. Delete this script and the containing folder if it's empty.
/// </summary>
private static void Update()
{
switch (updateState)
{
case UpdateStates.Idle:
if (EditorPrefs.HasKey(updaterKey))
{
_updateState = (UpdateStates)EditorPrefs.GetInt(updaterKey);
packageTime.Start();
}
else
{
RequestExisting();
}
break;
case UpdateStates.WaitingOnExistingCheck:
if (listRequest == null)
{
//the list request got nulled for some reason. Request it again.
RequestExisting();
}
else if (listRequest != null && listRequest.IsCompleted)
{
if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
{
DisplayErrorAndStop("Error while checking for an existing OpenVR package.", listRequest);
}
else
{
if (listRequest.Result.Any(package => package.name == valveOpenVRPackageString))
{
var existingPackage = listRequest.Result.FirstOrDefault(package => package.name == valveOpenVRPackageString);
string latestTarball = GetLatestTarballVersion();
if (latestTarball != null && latestTarball.CompareTo(existingPackage.version) == 1)
{
//we have a tarball higher than the currently installed version
string upgradeString = string.Format("This SteamVR Unity Plugin has a newer version of the Unity XR OpenVR package than you have installed. Would you like to upgrade?\n\nCurrent: {0}\nUpgrade: {1} (recommended)", existingPackage.version, latestTarball);
bool upgrade = UnityEditor.EditorUtility.DisplayDialog("OpenVR XR Updater", upgradeString, "Upgrade", "Cancel");
if (upgrade)
RemoveScopedRegistry();
else
{
bool delete = UnityEditor.EditorUtility.DisplayDialog("OpenVR XR Updater", "Would you like to remove this updater script so we don't ask again?", "Remove updater", "Keep");
if (delete)
{
Stop();
return;
}
else
{
GentleStop();
return;
}
}
}
}
else
{
#if UNITY_2020_1_OR_NEWER
RemoveScopedRegistry(); //just install if we're on 2020 and they don't have the package
return;
#else
//they don't have the package yet. Ask if they want to install (only for 2019)
bool blankInstall = UnityEditor.EditorUtility.DisplayDialog("OpenVR XR Installer", "The SteamVR Unity Plugin can be used with the legacy Unity VR API (Unity 5.4 - 2019) or with the Unity XR API (2019+). Would you like to install OpenVR for Unity XR?", "Install", "Cancel");
if (blankInstall)
RemoveScopedRegistry();
else
{
bool delete = UnityEditor.EditorUtility.DisplayDialog("OpenVR XR Installer", "Would you like to remove this installer script so we don't ask again?", "Remove installer", "Keep");
if (delete)
{
Stop();
return;
}
else
{
GentleStop();
return;
}
}
#endif
}
}
}
break;
case UpdateStates.WaitingForAdd:
if (addRequest == null)
{
//the add request got nulled for some reason. Request an add confirmation
RequestAddConfirmation();
}
else if (addRequest != null && addRequest.IsCompleted)
{
if (addRequest.Error != null || addRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
{
DisplayErrorAndStop("Error adding new version of OpenVR package.", addRequest);
}
else
{
//verify that the package has been added (then stop)
RequestAddConfirmation();
}
}
else
{
if (packageTime.Elapsed.TotalSeconds > estimatedTimeToInstall)
DisplayErrorAndStop("Error while trying to add package.", addRequest);
else
DisplayProgressBar();
}
break;
case UpdateStates.WaitingForAddConfirmation:
if (listRequest == null)
{
//the list request got nulled for some reason. Request it again.
RequestAddConfirmation();
}
else if (listRequest != null && listRequest.IsCompleted)
{
if (listRequest.Error != null || listRequest.Status == UnityEditor.PackageManager.StatusCode.Failure)
{
DisplayErrorAndStop("Error while confirming the OpenVR package has been added.", listRequest);
}
else
{
if (listRequest.Result.Any(package => package.name == valveOpenVRPackageString))
{
updateState = UpdateStates.RemoveSelf;
UnityEditor.EditorUtility.DisplayDialog("OpenVR Unity XR Installer", "OpenVR Unity XR successfully installed.\n\nA restart of the Unity Editor may be necessary.", "Ok");
}
else
{
//try to add again if it's not there and we don't know why
RequestAdd();
}
}
}
else
{
if (runningSeconds > estimatedTimeToInstall)
{
DisplayErrorAndStop("Error while confirming the OpenVR package has been added.", listRequest);
}
else
DisplayProgressBar();
}
break;
case UpdateStates.RemoveSelf:
EditorPrefs.DeleteKey(updaterKey);
EditorUtility.ClearProgressBar();
EditorApplication.update -= Update;
#if VALVE_SKIP_DELETE
Debug.Log("[DEBUG] skipping script deletion. Complete.");
return;
#endif
var script = MonoScript.FromScriptableObject(OpenVRPackageInstaller.CreateInstance<OpenVRPackageInstaller>());
var path = AssetDatabase.GetAssetPath(script);
FileInfo updaterScript = new FileInfo(path); updaterScript.IsReadOnly = false;
FileInfo updaterScriptMeta = new FileInfo(path + ".meta");
FileInfo simpleJSONScript = new FileInfo(Path.Combine(updaterScript.Directory.FullName, "OpenVRSimpleJSON.cs"));
FileInfo simpleJSONScriptMeta = new FileInfo(Path.Combine(updaterScript.Directory.FullName, "OpenVRSimpleJSON.cs.meta"));
updaterScript.IsReadOnly = false;
updaterScriptMeta.IsReadOnly = false;
simpleJSONScript.IsReadOnly = false;
simpleJSONScriptMeta.IsReadOnly = false;
updaterScriptMeta.Delete();
if (updaterScriptMeta.Exists)
{
DisplayErrorAndStop("Error while removing package installer script. Please delete manually.", listRequest);
return;
}
simpleJSONScript.Delete();
simpleJSONScriptMeta.Delete();
updaterScript.Delete();
AssetDatabase.Refresh();
break;
}
}
private static string GetLatestTarballVersion()
{
FileInfo[] files;
FileInfo latest = GetAvailableTarballs(out files);
if (latest == null)
return null;
return GetTarballVersion(latest);
}
private static FileInfo GetAvailableTarballs(out FileInfo[] packages)
{
var installerScript = MonoScript.FromScriptableObject(OpenVRPackageInstaller.CreateInstance<OpenVRPackageInstaller>());
var scriptPath = AssetDatabase.GetAssetPath(installerScript);
FileInfo thisScript = new FileInfo(scriptPath);
packages = thisScript.Directory.GetFiles("*.tgz");
if (packages.Length > 0)
{
if (packages.Length > 1)
{
var descending = packages.OrderByDescending(file => file.Name);
var latest = descending.First();
packages = descending.Where(file => file != latest).ToArray();
return latest;
}
var onlyPackage = packages[0];
packages = new FileInfo[0];
return onlyPackage;
}
else
return null;
}
private static string GetTarballVersion(FileInfo file)
{
int startIndex = file.Name.IndexOf('-') + 1;
int endIndex = file.Name.IndexOf(".tgz");
int len = endIndex - startIndex;
return file.Name.Substring(startIndex, len);
}
private const string packageManifestPath = "Packages/manifest.json";
private const string scopedRegistryKey = "scopedRegistries";
private const string npmRegistryName = "Valve";
//load packages.json
//check for existing scoped registries
//check for our scoped registry
//if no to either then add it
//save file
//reload
private static void RemoveScopedRegistry()
{
updateState = UpdateStates.RemoveOldRegistry;
packageTime.Start();
if (File.Exists(packageManifestPath) == false)
{
Debug.LogWarning("[OpenVR Installer] Could not find package manifest at: " + packageManifestPath);
RequestAdd();
return;
}
string jsonText = File.ReadAllText(packageManifestPath);
JSONNode manifest = JSON.Parse(jsonText);
if (manifest.HasKey(scopedRegistryKey) == true)
{
if (manifest[scopedRegistryKey].HasKey(npmRegistryName))
{
manifest[scopedRegistryKey].Remove(npmRegistryName);
File.WriteAllText(packageManifestPath, manifest.ToString(2));
Debug.Log("[OpenVR Installer] Removed Valve entry from scoped registry.");
}
}
RequestAdd();
}
private static void RequestAdd()
{
updateState = UpdateStates.WaitingForAdd;
FileInfo[] oldFiles;
FileInfo latest = GetAvailableTarballs(out oldFiles);
if (latest != null)
{
if (oldFiles.Length > 0)
{
var oldFilesNames = oldFiles.Select(file => file.Name);
string oldFilesString = string.Join("\n", oldFilesNames);
bool delete = UnityEditor.EditorUtility.DisplayDialog("OpenVR XR Installer", "Would you like to delete the old OpenVR packages?\n\n" + oldFilesString, "Delete old files", "Keep");
if (delete)
{
foreach (FileInfo file in oldFiles)
{
FileInfo meta = new FileInfo(file.FullName + ".meta");
if (meta.Exists)
{
meta.IsReadOnly = false;
meta.Delete();
}
if (file.Exists)
{
file.IsReadOnly = false;
file.Delete();
}
}
}
}
string packagePath = latest.FullName;
if (packagePath != null)
{
string packageAbsolute = packagePath.Replace("\\", "/");
string packageRelative = packageAbsolute.Substring(packageAbsolute.IndexOf("/Assets/"));
string packageURI = System.Uri.EscapeUriString(packageRelative);
addRequest = UnityEditor.PackageManager.Client.Add("file:.." + packageURI);
}
else
{
updateState = UpdateStates.RemoveSelf;
}
}
}
private static void RequestAddConfirmation()
{
updateState = UpdateStates.WaitingForAddConfirmation;
listRequest = Client.List(true, true);
}
private static void RequestExisting()
{
updateState = UpdateStates.WaitingOnExistingCheck;
listRequest = Client.List(true, true);
}
private static string dialogText = "Installing OpenVR Unity XR package from local storage using Unity Package Manager...";
private static void DisplayProgressBar()
{
bool cancel = UnityEditor.EditorUtility.DisplayCancelableProgressBar("SteamVR", dialogText, (float)packageTime.Elapsed.TotalSeconds / estimatedTimeToInstall);
if (cancel)
Stop();
}
private static void DisplayErrorAndStop(string stepInfo, Request request)
{
string error = "";
if (request != null)
error = request.Error.message;
string errorMessage = string.Format("{0}:\n\t{1}\n\nPlease manually reinstall the package through the package manager.", stepInfo, error);
UnityEngine.Debug.LogError(errorMessage);
Stop();
UnityEditor.EditorUtility.DisplayDialog("OpenVR Error", errorMessage, "Ok");
}
private static void Stop()
{
updateState = UpdateStates.RemoveSelf;
}
private static void GentleStop()
{
EditorApplication.update -= Update;
}
private enum UpdateStates
{
Idle,
WaitingOnExistingCheck,
RemoveOldRegistry,
WaitingForAdd,
WaitingForAddConfirmation,
RemoveSelf,
}
}
}
#endif

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 538300977557ee34892368a50c97bdd6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ca02308d9febaa442a742ecaaaa06d2c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: