Initial Commit

This commit is contained in:
2025-07-04 20:33:06 +03:00
commit 8f09347ae0
9219 changed files with 2447903 additions and 0 deletions
@@ -0,0 +1,321 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Oculus.Interaction.Editor;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Oculus.Interaction.Grab.GrabSurfaces.Editor
{
[CustomEditor(typeof(BezierGrabSurface))]
[CanEditMultipleObjects]
public class BezierGrabSurfaceEditor : UnityEditor.Editor
{
private BezierGrabSurface _surface;
private SerializedProperty _relativeToProperty;
private Transform _relativeTo;
private bool IsSelectedIndexValid => _selectedIndex >= 0
&& _selectedIndex < _surface.ControlPoints.Count;
private int _selectedIndex = -1;
private const float PICK_SIZE = 0.1f;
private const float AXIS_SIZE = 0.5f;
private const int CURVE_STEPS = 50;
private const float SEPARATION = 0.1f;
private void OnEnable()
{
_surface = (target as BezierGrabSurface);
_relativeToProperty = serializedObject.FindProperty("_relativeTo");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_relativeTo = _relativeToProperty.objectReferenceValue as Transform;
if (_relativeTo == null)
{
return;
}
if (GUILayout.Button("Add ControlPoint At Start"))
{
AddControlPoint(true, _relativeTo);
}
if (GUILayout.Button("Add ControlPoint At End"))
{
AddControlPoint(false, _relativeTo);
}
if (!IsSelectedIndexValid)
{
_selectedIndex = -1;
GUILayout.Label($"No Selected Point");
}
else
{
GUILayout.Label($"Selected Point: {_selectedIndex}");
if (GUILayout.Button("Align Selected Tangent"))
{
AlignTangent(_selectedIndex, _relativeTo);
}
if (GUILayout.Button("Smooth Selected Tangent"))
{
SmoothTangent(_selectedIndex, _relativeTo);
}
}
serializedObject.ApplyModifiedProperties();
}
public void OnSceneGUI()
{
if (_relativeTo == null)
{
return;
}
Handles.color = EditorConstants.PRIMARY_COLOR;
DrawEndsCaps(_surface.ControlPoints, _relativeTo);
if (Event.current.type == EventType.Repaint)
{
DrawCurve(_surface.ControlPoints, _relativeTo);
}
}
private void AddControlPoint(bool addFirst, Transform relativeTo)
{
BezierControlPoint controlPoint = new BezierControlPoint();
if (_surface.ControlPoints.Count == 0)
{
Pose pose = _surface.transform.GetPose();
controlPoint.SetPose(pose, relativeTo);
_surface.ControlPoints.Add(controlPoint);
_selectedIndex = 0;
return;
}
else if (_surface.ControlPoints.Count == 1)
{
controlPoint = _surface.ControlPoints[0];
Pose pose = controlPoint.GetPose(relativeTo);
pose.position += relativeTo.forward * SEPARATION;
controlPoint.SetPose(pose, relativeTo);
}
else if (_surface.ControlPoints.Count > 1)
{
BezierControlPoint firstControlPoint;
BezierControlPoint secondControlPoint;
if (addFirst)
{
firstControlPoint = _surface.ControlPoints[1];
secondControlPoint = _surface.ControlPoints[0];
}
else
{
firstControlPoint = _surface.ControlPoints[_surface.ControlPoints.Count - 2];
secondControlPoint = _surface.ControlPoints[_surface.ControlPoints.Count - 1];
}
Pose firstPose = firstControlPoint.GetPose(relativeTo);
Pose secondPose = secondControlPoint.GetPose(relativeTo);
Pose controlPointPose;
controlPointPose.position = 2 * secondPose.position - firstPose.position;
controlPointPose.rotation = secondPose.rotation;
controlPoint.SetPose(controlPointPose, relativeTo);
}
if (addFirst)
{
_surface.ControlPoints.Insert(0, controlPoint);
_selectedIndex = 0;
AlignTangent(0, relativeTo);
}
else
{
_surface.ControlPoints.Add(controlPoint);
_selectedIndex = _surface.ControlPoints.Count - 1;
AlignTangent(_selectedIndex - 1, relativeTo);
}
}
private void AlignTangent(int index, Transform relativeTo)
{
BezierControlPoint controlPoint = _surface.ControlPoints[index];
BezierControlPoint nextControlPoint = _surface.ControlPoints[(index + 1) % _surface.ControlPoints.Count];
Vector3 tangent = (nextControlPoint.GetPose(relativeTo).position + controlPoint.GetPose(relativeTo).position) * 0.5f;
controlPoint.SetTangent(tangent, relativeTo);
_surface.ControlPoints[index] = controlPoint;
}
private void SmoothTangent(int index, Transform relativeTo)
{
BezierControlPoint controlPoint = _surface.ControlPoints[index];
BezierControlPoint prevControlPoint = _surface.ControlPoints[(index + _surface.ControlPoints.Count - 1) % _surface.ControlPoints.Count];
Vector3 tangent = prevControlPoint.GetTangent(relativeTo);
tangent = (controlPoint.GetPose(relativeTo).position - tangent) * 0.5f;
controlPoint.SetTangent(tangent, relativeTo);
_surface.ControlPoints[index] = controlPoint;
}
private void DrawEndsCaps(List<BezierControlPoint> controlPoints, Transform relativeTo)
{
Handles.color = EditorConstants.PRIMARY_COLOR;
for (int i = 0; i < controlPoints.Count; i++)
{
DrawControlPoint(i, relativeTo);
}
Handles.color = EditorConstants.PRIMARY_COLOR_DISABLED;
if (IsSelectedIndexValid)
{
DrawControlPointHandles(_selectedIndex, relativeTo);
DrawTangentLine(_selectedIndex, relativeTo);
}
}
private void DrawCurve(List<BezierControlPoint> controlPoints, Transform relativeTo)
{
Handles.color = EditorConstants.PRIMARY_COLOR;
for (int i = 0; i < controlPoints.Count && controlPoints.Count > 1; i++)
{
BezierControlPoint fromControlPoint = _surface.ControlPoints[i];
Pose from = fromControlPoint.GetPose(relativeTo);
BezierControlPoint toControlPoint = _surface.ControlPoints[(i + 1) % controlPoints.Count];
if (toControlPoint.Disconnected)
{
continue;
}
Pose to = toControlPoint.GetPose(relativeTo);
Vector3 tangent = fromControlPoint.GetTangent(relativeTo);
DrawBezier(from.position, tangent, to.position, CURVE_STEPS);
}
}
private void DrawBezier(Vector3 start, Vector3 middle, Vector3 end, int steps)
{
Vector3 from = start;
Vector3 to;
float t;
for (int i = 1; i < steps; i++)
{
t = i / (steps - 1f);
to = BezierGrabSurface.EvaluateBezier(start, middle, end, t);
#if UNITY_2020_2_OR_NEWER
Handles.DrawLine(from, to, EditorConstants.LINE_THICKNESS);
#else
Handles.DrawLine(from, to);
#endif
from = to;
}
}
private void DrawTangentLine(int index, Transform relativeTo)
{
BezierControlPoint controlPoint = _surface.ControlPoints[index];
Pose pose = controlPoint.GetPose(relativeTo);
Vector3 center = pose.position;
Vector3 tangent = controlPoint.GetTangent(relativeTo);
#if UNITY_2020_2_OR_NEWER
Handles.DrawLine(center, tangent, EditorConstants.LINE_THICKNESS);
#else
Handles.DrawLine(center, tangent);
#endif
}
private void DrawControlPoint(int index, Transform relativeTo)
{
BezierControlPoint controlPoint = _surface.ControlPoints[index];
Pose pose = controlPoint.GetPose(relativeTo);
float handleSize = HandleUtility.GetHandleSize(pose.position);
Handles.color = EditorConstants.PRIMARY_COLOR;
if (Handles.Button(pose.position, pose.rotation, handleSize * PICK_SIZE, handleSize * PICK_SIZE, Handles.DotHandleCap))
{
_selectedIndex = index;
}
Handles.color = Color.red;
Handles.DrawLine(pose.position, pose.position + pose.right * handleSize * AXIS_SIZE);
Handles.color = Color.green;
Handles.DrawLine(pose.position, pose.position + pose.up * handleSize * AXIS_SIZE);
Handles.color = Color.blue;
Handles.DrawLine(pose.position, pose.position + pose.forward * handleSize * AXIS_SIZE);
}
private void DrawControlPointHandles(int index, Transform relativeTo)
{
BezierControlPoint controlPoint = _surface.ControlPoints[index];
Pose pose = controlPoint.GetPose(relativeTo);
if (Tools.current == Tool.Move)
{
EditorGUI.BeginChangeCheck();
Quaternion pointRotation = Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : pose.rotation;
pose.position = Handles.PositionHandle(pose.position, pointRotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(_surface, "Change ControlPoint Position");
controlPoint.SetPose(pose, relativeTo);
_surface.ControlPoints[index] = controlPoint;
}
}
else if (Tools.current == Tool.Rotate)
{
Quaternion originalRotation = pose.rotation;
if (Tools.pivotRotation == PivotRotation.Global)
{
Quaternion offset = Handles.RotationHandle(Quaternion.identity, pose.position);
pose.rotation = offset * pose.rotation;
}
else
{
pose.rotation = Handles.RotationHandle(pose.rotation, pose.position);
}
pose.rotation.Normalize();
if (originalRotation != pose.rotation)
{
Undo.RecordObject(_surface, "Change ControlPoint Rotation");
controlPoint.SetPose(pose, relativeTo);
_surface.ControlPoints[index] = controlPoint;
}
}
Vector3 tangent = controlPoint.GetTangent(relativeTo);
Quaternion tangentRotation = Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : pose.rotation;
EditorGUI.BeginChangeCheck();
tangent = Handles.PositionHandle(tangent, tangentRotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(_surface, "Change ControlPoint Tangent");
controlPoint.SetTangent(tangent, relativeTo);
_surface.ControlPoints[index] = controlPoint;
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 718688abdc60caa4984fe98623ff42dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,193 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Oculus.Interaction.Editor;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Oculus.Interaction.Grab.GrabSurfaces.Editor
{
[CustomEditor(typeof(BoxGrabSurface))]
[CanEditMultipleObjects]
public class BoxGrabSurfaceEditor : UnityEditor.Editor
{
private BoxBoundsHandle _boxHandle = new BoxBoundsHandle();
private BoxGrabSurface _surface;
private Transform _relativeTo;
private SerializedProperty _relativeToProperty;
private void OnEnable()
{
_boxHandle.handleColor = EditorConstants.PRIMARY_COLOR;
_boxHandle.wireframeColor = EditorConstants.PRIMARY_COLOR_DISABLED;
_boxHandle.axes = PrimitiveBoundsHandle.Axes.X | PrimitiveBoundsHandle.Axes.Z;
_surface = (target as BoxGrabSurface);
_relativeToProperty = serializedObject.FindProperty("_relativeTo");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_relativeTo = _relativeToProperty.objectReferenceValue as Transform;
}
public void OnSceneGUI()
{
if (_relativeTo == null)
{
return;
}
DrawRotator(_surface, _relativeTo);
DrawBoxEditor(_surface, _relativeTo);
DrawSlider(_surface, _relativeTo);
if (Event.current.type == EventType.Repaint)
{
DrawSnapLines(_surface, _relativeTo);
}
}
private void DrawSnapLines(BoxGrabSurface surface, Transform relativeTo)
{
Handles.color = EditorConstants.PRIMARY_COLOR;
Vector3 size = surface.GetSize(relativeTo);
Quaternion rotation = surface.GetRotation(relativeTo);
Vector3 surfacePosition = surface.GetReferencePose(relativeTo).position;
float widthOffset = surface.GetWidthOffset(relativeTo);
Vector4 snapOffset = surface.GetSnapOffset(relativeTo);
Vector3 rightAxis = rotation * Vector3.right;
Vector3 forwardAxis = rotation * Vector3.forward;
Vector3 forwardOffset = forwardAxis * size.z;
Vector3 bottomLeft = surfacePosition - rightAxis * size.x * (1f - widthOffset);
Vector3 bottomRight = surfacePosition + rightAxis * size.x * (widthOffset);
Vector3 topLeft = bottomLeft + forwardOffset;
Vector3 topRight = bottomRight + forwardOffset;
Handles.DrawLine(bottomLeft + rightAxis * snapOffset.y, bottomRight + rightAxis * snapOffset.x);
Handles.DrawLine(topLeft - rightAxis * snapOffset.x, topRight - rightAxis * snapOffset.y);
Handles.DrawLine(bottomLeft - forwardAxis * snapOffset.z, topLeft - forwardAxis * snapOffset.w);
Handles.DrawLine(bottomRight + forwardAxis * snapOffset.w, topRight + forwardAxis * snapOffset.z);
}
private void DrawSlider(BoxGrabSurface surface, Transform relativeTo)
{
Handles.color = EditorConstants.PRIMARY_COLOR;
Vector3 size = surface.GetSize(relativeTo);
Quaternion rotation = surface.GetRotation(relativeTo);
Vector3 surfacePosition = surface.GetReferencePose(relativeTo).position;
float widthOffset = surface.GetWidthOffset(relativeTo);
Vector4 snapOffset = surface.GetSnapOffset(relativeTo);
EditorGUI.BeginChangeCheck();
Vector3 rightDir = rotation * Vector3.right;
Vector3 forwardDir = rotation * Vector3.forward;
Vector3 bottomRight = surfacePosition
+ rightDir * size.x * (widthOffset);
Vector3 bottomLeft = surfacePosition
- rightDir * size.x * (1f - widthOffset);
Vector3 topRight = bottomRight + forwardDir * size.z;
Vector3 rightHandle = DrawOffsetHandle(bottomRight + rightDir * snapOffset.x, rightDir);
Vector3 leftHandle = DrawOffsetHandle(bottomLeft + rightDir * snapOffset.y, -rightDir);
Vector3 topHandle = DrawOffsetHandle(topRight + forwardDir * snapOffset.z, forwardDir);
Vector3 bottomHandle = DrawOffsetHandle(bottomRight + forwardDir * snapOffset.w, -forwardDir);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Offset Box");
Vector4 offset = snapOffset;
offset.x = DistanceToHandle(bottomRight, rightHandle, rightDir);
offset.y = DistanceToHandle(bottomLeft, leftHandle, rightDir);
offset.z = DistanceToHandle(topRight, topHandle, forwardDir);
offset.w = DistanceToHandle(bottomRight, bottomHandle, forwardDir);
surface.SetSnapOffset(offset, relativeTo);
}
}
private Vector3 DrawOffsetHandle(Vector3 point, Vector3 dir)
{
float size = HandleUtility.GetHandleSize(point) * 0.2f;
return Handles.Slider(point, dir, size, Handles.ConeHandleCap, 0f);
}
private float DistanceToHandle(Vector3 origin, Vector3 handlePoint, Vector3 dir)
{
float distance = Vector3.Distance(origin, handlePoint);
if (Vector3.Dot(handlePoint - origin, dir) < 0f)
{
distance = -distance;
}
return distance;
}
private void DrawRotator(BoxGrabSurface surface, Transform relativeTo)
{
EditorGUI.BeginChangeCheck();
Quaternion rotation = Handles.RotationHandle(
surface.GetRotation(relativeTo),
surface.GetReferencePose(relativeTo).position);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Rotation Box");
surface.SetRotation(rotation, relativeTo);
}
}
private void DrawBoxEditor(BoxGrabSurface surface, Transform relativeTo)
{
Quaternion rot = surface.GetRotation(relativeTo);
Vector3 size = surface.GetSize(relativeTo);
float widthOffset = surface.GetWidthOffset(relativeTo);
Vector3 snapP = surface.GetReferencePose(relativeTo).position;
_boxHandle.size = size;
float widthPos = Mathf.Lerp(-size.x * 0.5f, size.x * 0.5f, widthOffset);
_boxHandle.center = new Vector3(widthPos, 0f, size.z * 0.5f);
Matrix4x4 handleMatrix = Matrix4x4.TRS(
snapP,
rot,
Vector3.one
);
using (new Handles.DrawingScope(handleMatrix))
{
EditorGUI.BeginChangeCheck();
_boxHandle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Box Properties");
surface.SetSize(_boxHandle.size, relativeTo);
float width = _boxHandle.size.x;
if (width != 0f)
{
width = (_boxHandle.center.x + width * 0.5f) / width;
}
surface.SetWidthOffset(width, relativeTo);
}
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: baf3d860debef0947b62cdebdd94cb74
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,172 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Oculus.Interaction.Editor;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Oculus.Interaction.Grab.GrabSurfaces.Editor
{
[CustomEditor(typeof(CylinderGrabSurface))]
[CanEditMultipleObjects]
public class CylinderGrabSurfaceEditor : UnityEditor.Editor
{
private const float DRAW_SURFACE_ANGULAR_RESOLUTION = 5f;
private ArcHandle _arcEndHandle = new ArcHandle();
private ArcHandle _arcStartHandle = new ArcHandle();
private Vector3[] _surfaceEdges;
private CylinderGrabSurface _surface;
private SerializedProperty _relativeToProperty;
private Transform _relativeTo;
private void OnEnable()
{
_arcStartHandle.SetColorWithRadiusHandle(EditorConstants.PRIMARY_COLOR_DISABLED, 0f);
_arcEndHandle.SetColorWithRadiusHandle(EditorConstants.PRIMARY_COLOR, 0f);
_surface = target as CylinderGrabSurface;
_relativeToProperty = serializedObject.FindProperty("_relativeTo");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_relativeTo = _relativeToProperty.objectReferenceValue as Transform;
}
public void OnSceneGUI()
{
if (_relativeTo == null)
{
return;
}
DrawEndsCaps(_surface, _relativeTo);
float oldArcStart = _surface.ArcOffset;
Quaternion look = Quaternion.LookRotation(_surface.GetPerpendicularDir(_relativeTo), _surface.GetDirection(_relativeTo));
float newArcStart = DrawArcEditor(_surface, _arcStartHandle, _relativeTo,
oldArcStart,_surface.GetStartPoint(_relativeTo),
look);
_surface.ArcOffset = newArcStart;
_surface.ArcLength -= newArcStart - oldArcStart;
_surface.ArcLength = DrawArcEditor(_surface, _arcEndHandle, _relativeTo,
_surface.ArcLength,
_surface.GetStartPoint(_relativeTo),
Quaternion.LookRotation(_surface.GetStartArcDir(_relativeTo), _surface.GetDirection(_relativeTo)));
if (Event.current.type == EventType.Repaint)
{
DrawSurfaceVolume(_surface, _relativeTo);
}
}
private void DrawEndsCaps(CylinderGrabSurface surface, Transform relativeTo)
{
EditorGUI.BeginChangeCheck();
Quaternion handleRotation = relativeTo.rotation;
Vector3 startPosition = Handles.PositionHandle(surface.GetStartPoint(relativeTo), handleRotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Start Cylinder Position");
surface.SetStartPoint(startPosition, relativeTo);
}
EditorGUI.BeginChangeCheck();
Vector3 endPosition = Handles.PositionHandle(surface.GetEndPoint(relativeTo), handleRotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Start Cylinder Position");
surface.SetEndPoint(endPosition, relativeTo);
}
}
private void DrawSurfaceVolume(CylinderGrabSurface surface, Transform relativeTo)
{
Vector3 start = surface.GetStartPoint(relativeTo);
Vector3 end = surface.GetEndPoint(relativeTo);
Vector3 startArc = surface.GetStartArcDir(relativeTo);
Vector3 endArc = surface.GetEndArcDir(relativeTo);
Vector3 direction = surface.GetDirection(relativeTo);
float radius = surface.GetRadius(relativeTo);
Handles.color = EditorConstants.PRIMARY_COLOR;
Handles.DrawWireArc(end,
direction,
startArc,
surface.ArcLength,
radius);
Handles.DrawLine(start, end);
Handles.DrawLine(start, start + startArc * radius);
Handles.DrawLine(start, start + endArc * radius);
Handles.DrawLine(end, end + startArc * radius);
Handles.DrawLine(end, end + endArc * radius);
int edgePoints = Mathf.CeilToInt((2 * surface.ArcLength) / DRAW_SURFACE_ANGULAR_RESOLUTION) + 3;
if (_surfaceEdges == null
|| _surfaceEdges.Length != edgePoints)
{
_surfaceEdges = new Vector3[edgePoints];
}
Handles.color = EditorConstants.PRIMARY_COLOR_DISABLED;
int i = 0;
for (float angle = 0f; angle < surface.ArcLength; angle += DRAW_SURFACE_ANGULAR_RESOLUTION)
{
Vector3 dir = Quaternion.AngleAxis(angle, direction) * startArc;
_surfaceEdges[i++] = start + dir * radius;
_surfaceEdges[i++] = end + dir * radius;
}
_surfaceEdges[i++] = start + endArc * radius;
_surfaceEdges[i++] = end + endArc * radius;
Handles.DrawPolyLine(_surfaceEdges);
}
private float DrawArcEditor(CylinderGrabSurface surface, ArcHandle handle, Transform relativeTo,
float inputAngle, Vector3 position, Quaternion rotation)
{
handle.radius = surface.GetRadius(relativeTo);
handle.angle = inputAngle;
Matrix4x4 handleMatrix = Matrix4x4.TRS(
position,
rotation,
Vector3.one
);
using (new Handles.DrawingScope(handleMatrix))
{
EditorGUI.BeginChangeCheck();
handle.DrawHandle();
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Cylinder Properties");
return handle.angle;
}
}
return inputAngle;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 69099ed7427360a4ab3734573c188647
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,97 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* Licensed under the Oculus SDK License Agreement (the "License");
* you may not use the Oculus SDK except in compliance with the License,
* which is provided at the time of installation or download, or which
* otherwise accompanies this software in either electronic or hard copy form.
*
* You may obtain a copy of the License at
*
* https://developer.oculus.com/licenses/oculussdk/
*
* Unless required by applicable law or agreed to in writing, the Oculus SDK
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Oculus.Interaction.Editor;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Oculus.Interaction.Grab.GrabSurfaces.Editor
{
[CustomEditor(typeof(SphereGrabSurface))]
[CanEditMultipleObjects]
public class SphereGrabSurfaceEditor : UnityEditor.Editor
{
private SphereBoundsHandle _sphereHandle = new SphereBoundsHandle();
private SphereGrabSurface _surface;
private SerializedProperty _relativeToProperty;
private Transform _relativeTo;
private void OnEnable()
{
_sphereHandle.SetColor(EditorConstants.PRIMARY_COLOR);
_sphereHandle.midpointHandleDrawFunction = null;
_surface = target as SphereGrabSurface;
_relativeToProperty = serializedObject.FindProperty("_relativeTo");
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
_relativeTo = _relativeToProperty.objectReferenceValue as Transform;
}
public void OnSceneGUI()
{
if (_relativeTo == null)
{
return;
}
DrawCentre(_surface, _relativeTo);
Handles.color = Color.white;
DrawSphereEditor(_surface, _relativeTo);
if (Event.current.type == EventType.Repaint)
{
DrawSurfaceVolume(_surface, _relativeTo);
}
}
private void DrawCentre(SphereGrabSurface surface, Transform relativeTo)
{
EditorGUI.BeginChangeCheck();
Quaternion handleRotation = relativeTo.rotation;
Vector3 centrePosition = Handles.PositionHandle(surface.GetCentre(relativeTo), handleRotation);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(surface, "Change Centre Sphere Position");
surface.SetCentre(centrePosition, relativeTo);
}
}
private void DrawSurfaceVolume(SphereGrabSurface surface, Transform relativeTo)
{
Handles.color = EditorConstants.PRIMARY_COLOR;
Vector3 startLine = surface.GetCentre(relativeTo);
Vector3 endLine = startLine + surface.GetDirection(relativeTo) * surface.GetRadius(relativeTo);
Handles.DrawDottedLine(startLine, endLine, 5);
}
private void DrawSphereEditor(SphereGrabSurface surface, Transform relativeTo)
{
_sphereHandle.radius = surface.GetRadius(relativeTo);
_sphereHandle.center = surface.GetCentre(relativeTo);
EditorGUI.BeginChangeCheck();
_sphereHandle.DrawHandle();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ee7657a153e652d448fa1b7775ca7f8c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: