Add ultimate xr

This commit is contained in:
2024-08-06 21:58:35 +02:00
parent 864033bf10
commit 7165bacd9d
3952 changed files with 2162037 additions and 35 deletions

View File

@@ -0,0 +1,83 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AlignWindow.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Extensions.Unity;
using UnityEditor;
using UnityEngine;
namespace UltimateXR.Editor.Utilities.TransformUtils
{
/// <summary>
/// Custom tool window that will reposition/reorient an object so that the source transform would match the target
/// transform.
/// </summary>
public class AlignWindow : EditorWindow
{
#region Unity
/// <summary>
/// Draws the inspector and gathers user input.
/// </summary>
private void OnGUI()
{
EditorGUILayout.HelpBox("This utility will reposition/reorient an object in a way so that it would make source match target", MessageType.Info);
EditorGUI.BeginChangeCheck();
Transform objectToAlign = _objectToAlign;
_objectToAlign = EditorGUILayout.ObjectField(new GUIContent("Object To Align", ""), _objectToAlign, typeof(Transform), true) as Transform;
if (EditorGUI.EndChangeCheck())
{
if (EditorUtility.IsPersistent(_objectToAlign))
{
_objectToAlign = objectToAlign;
EditorUtility.DisplayDialog(UxrConstants.Editor.Error, "The object to align needs to be in the scene", UxrConstants.Editor.Ok);
}
}
_referenceSource = EditorGUILayout.ObjectField(new GUIContent("Reference Source", ""), _referenceSource, typeof(Transform), true) as Transform;
_referenceTarget = EditorGUILayout.ObjectField(new GUIContent("Reference Target", ""), _referenceTarget, typeof(Transform), true) as Transform;
_reposition = EditorGUILayout.Toggle(new GUIContent("Reposition", ""), _reposition);
_reorient = EditorGUILayout.Toggle(new GUIContent("Reorient", ""), _reorient);
GUI.enabled = _objectToAlign && _referenceSource && _referenceTarget;
if (UxrEditorUtils.CenteredButton(new GUIContent("Align")))
{
Undo.RegisterCompleteObjectUndo(_objectToAlign.transform, "Align object");
_objectToAlign.ApplyAlignment(_referenceSource, _referenceTarget, UxrUtils.BuildTransformations(_reposition, _reorient));
}
GUI.enabled = true;
}
#endregion
#region Private Methods
/// <summary>
/// Menu entry that invokes the tool.
/// </summary>
[MenuItem(UxrConstants.Editor.MenuPathUtils + "Align Object", priority = UxrConstants.Editor.PriorityMenuPathUtils + 1)]
private static void Init()
{
AlignWindow window = (AlignWindow)GetWindow(typeof(AlignWindow), true, "Align Object");
window.Show();
}
#endregion
#region Private Types & Data
private Transform _objectToAlign;
private Transform _referenceSource;
private Transform _referenceTarget;
private bool _reposition = true;
private bool _reorient = true;
#endregion
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: ae6cd2a1c2ad2aa49adb72d0073c05d3
timeCreated: 1516916387
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LookAtWindow.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UnityEditor;
using UnityEngine;
namespace UltimateXR.Editor.Utilities.TransformUtils
{
/// <summary>
/// Custom tool window to implement a LookAt on an object transform.
/// </summary>
public class LookAtWindow : EditorWindow
{
#region Unity
/// <summary>
/// Draws the inspector and gathers user input.
/// </summary>
private void OnGUI()
{
EditorGUILayout.HelpBox("This utility will make an object face a target. The look-at direction will be applied to the object's forward vector", MessageType.Info);
EditorGUI.BeginChangeCheck();
Transform objectToLookAt = _object;
_object = EditorGUILayout.ObjectField(new GUIContent("Object", ""), _object, typeof(Transform), true) as Transform;
if (EditorGUI.EndChangeCheck())
{
if (EditorUtility.IsPersistent(_object))
{
_object = objectToLookAt;
EditorUtility.DisplayDialog(UxrConstants.Editor.Error, "The object to process needs to be in the scene", UxrConstants.Editor.Ok);
}
}
_target = EditorGUILayout.ObjectField(new GUIContent("Target", ""), _target, typeof(Transform), true) as Transform;
_invertForward = EditorGUILayout.Toggle(new GUIContent("Invert Forward"), _invertForward);
GUI.enabled = _object && _target;
if (UxrEditorUtils.CenteredButton(new GUIContent("Look At")))
{
Undo.RegisterCompleteObjectUndo(_object.transform, "Look at object");
Vector3 forward = _target.position - _object.position;
_object.rotation = Quaternion.LookRotation(_invertForward ? -forward : forward);
}
GUI.enabled = true;
}
#endregion
#region Private Methods
/// <summary>
/// Menu entry that invokes the tool.
/// </summary>
[MenuItem(UxrConstants.Editor.MenuPathUtils + "LookAt Object", priority = UxrConstants.Editor.PriorityMenuPathUtils + 2)]
private static void Init()
{
LookAtWindow window = (LookAtWindow)GetWindow(typeof(LookAtWindow), true, "LookAt Object");
window.Show();
}
#endregion
#region Private Types & Data
private Transform _object;
private Transform _target;
private bool _invertForward;
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c9d5baecadf7402fa7b9ea82b71ec6fe
timeCreated: 1628846735

View File

@@ -0,0 +1,104 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MirrorWindow.cs" company="VRMADA">
// Copyright (c) VRMADA, All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
using UltimateXR.Core;
using UltimateXR.Core.Math;
using UltimateXR.Editor.Core.Math;
using UltimateXR.Extensions.Unity;
using UnityEditor;
using UnityEngine;
namespace UltimateXR.Editor.Utilities.TransformUtils
{
/// <summary>
/// Custom tool window that will mirror an object's position/orientation with reference to another.
/// </summary>
public class MirrorWindow : EditorWindow
{
#region Unity
/// <summary>
/// Draws the inspector and gathers user input.
/// </summary>
private void OnGUI()
{
EditorGUILayout.HelpBox("This utility will mirror an object. The mirror position is defined by a transform and the mirror plane by the transform's forward vector.\nThe Mirror Type option controls which vectors from the object will be mirrored, the remaining one being computed using the cross-product of the other two.",
MessageType.Info);
EditorGUI.BeginChangeCheck();
UnityEngine.Transform objectToAlign = _objectToMirror;
_objectToMirror = EditorGUILayout.ObjectField(new GUIContent("Object to Mirror", "The object that will be mirrored"), _objectToMirror, typeof(UnityEngine.Transform), true) as UnityEngine.Transform;
if (EditorGUI.EndChangeCheck())
{
if (EditorUtility.IsPersistent(_objectToMirror))
{
_objectToMirror = objectToAlign;
EditorUtility.DisplayDialog(UxrConstants.Editor.Error, "The object to mirror needs to be in the scene", UxrConstants.Editor.Ok);
}
}
_useSelfSourceTransform = EditorGUILayout.Toggle(new GUIContent("Use Object As Source", "Whether to use the object to be mirrored as the source position/orientation"), _useSelfSourceTransform);
if (!_useSelfSourceTransform)
{
_sourceTransform = EditorGUILayout.ObjectField(new GUIContent("Source Reference", "The transform that will be used as reference for the start position/orientation"), _sourceTransform, typeof(UnityEngine.Transform), true) as UnityEngine.Transform;
}
_mirrorPlane = EditorGUILayout.ObjectField(new GUIContent("Mirror Plane", "A point where the mirror plane lies"), _mirrorPlane, typeof(UnityEngine.Transform), true) as UnityEngine.Transform;
_mirrorAxis = UxrAxisPropertyDrawer.EditorGuiLayout(new GUIContent("Mirror Axis", "The normal of the axis plane"), _mirrorAxis);
_reposition = EditorGUILayout.Toggle(new GUIContent("Reposition", "Change position?"), _reposition);
_reorient = EditorGUILayout.Toggle(new GUIContent("Reorient", "Change orientation?"), _reorient);
GUI.enabled = _reorient;
_mirrorType = (TransformExt.MirrorType)EditorGUILayout.EnumPopup("Mirror Type", _mirrorType);
GUI.enabled = _objectToMirror != null && _mirrorPlane != null;
if (UxrEditorUtils.CenteredButton(new GUIContent("Mirror")))
{
Undo.RegisterCompleteObjectUndo(_objectToMirror.transform, "Mirror object");
if (!_useSelfSourceTransform && _sourceTransform)
{
_objectToMirror.SetPositionAndRotation(_sourceTransform);
}
_objectToMirror.ApplyMirroring(_mirrorPlane, _mirrorAxis, _mirrorType, _reorient, _reposition);
}
GUI.enabled = true;
}
#endregion
#region Private Methods
/// <summary>
/// Menu entry that invokes the tool.
/// </summary>
[MenuItem(UxrConstants.Editor.MenuPathUtils + "Mirror Object", priority = UxrConstants.Editor.PriorityMenuPathUtils + 3)]
private static void Init()
{
MirrorWindow window = (MirrorWindow)GetWindow(typeof(MirrorWindow), true, "Mirror Object");
window.Show();
}
#endregion
#region Private Types & Data
private UnityEngine.Transform _objectToMirror;
private bool _useSelfSourceTransform = true;
private UnityEngine.Transform _sourceTransform;
private UnityEngine.Transform _mirrorPlane;
private UxrAxis _mirrorAxis = UxrAxis.Z;
private TransformExt.MirrorType _mirrorType = TransformExt.MirrorType.MirrorYZ;
private bool _reposition = true;
private bool _reorient = true;
#endregion
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 5cf17205ae70ea045bcfca2fefd80085
timeCreated: 1516916387
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: