Skip to content

Commit 00d6008

Browse files
author
Andrei Borodin
committed
Revert "Removing dead code"
This reverts commit 54c806c.
1 parent 70b6428 commit 00d6008

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.MixedReality.Toolkit.Utilities;
5+
using Microsoft.MixedReality.Toolkit.Utilities.Solvers;
6+
using UnityEngine;
7+
8+
namespace Microsoft.MixedReality.Toolkit.UI.Utilities.Solvers
9+
{
10+
/// <summary>
11+
/// Waits for a controller to be instantiated, then attaches itself to a specified element
12+
/// </summary>
13+
public class AttachToController : ControllerFinder
14+
{
15+
public bool SetChildrenInactiveWhenDetached = true;
16+
17+
[SerializeField]
18+
protected Vector3 PositionOffset = Vector3.zero;
19+
20+
[SerializeField]
21+
protected Vector3 RotationOffset = Vector3.zero;
22+
23+
[SerializeField]
24+
protected Vector3 ScaleOffset = Vector3.one;
25+
26+
[SerializeField]
27+
protected bool SetScaleOnAttach = false;
28+
29+
public bool IsAttached { get { return transform.parent == null; } }
30+
31+
protected virtual void OnAttachToController() { }
32+
protected virtual void OnDetachFromController() { }
33+
34+
// TODO: Implement ControllerFinder properly on vNext.
35+
36+
//protected override void OnEnable()
37+
//{
38+
// SetChildrenActive(false);
39+
40+
// base.OnEnable();
41+
//}
42+
43+
//protected override void OnControllerFound()
44+
//{
45+
// // Parent ourselves under the element and set our offsets
46+
// transform.parent = ElementTransform;
47+
// transform.localPosition = PositionOffset;
48+
// transform.localEulerAngles = RotationOffset;
49+
50+
// if (SetScaleOnAttach)
51+
// {
52+
// transform.localScale = ScaleOffset;
53+
// }
54+
55+
// SetChildrenActive(true);
56+
57+
// // Announce that we're attached
58+
// OnAttachToController();
59+
//}
60+
61+
//protected override void OnControllerLost()
62+
//{
63+
// OnDetachFromController();
64+
65+
// SetChildrenActive(false);
66+
67+
// transform.parent = null;
68+
//}
69+
70+
//private void SetChildrenActive(bool isActive)
71+
//{
72+
// if (SetChildrenInactiveWhenDetached)
73+
// {
74+
// foreach (Transform child in transform)
75+
// {
76+
// child.gameObject.SetActive(isActive);
77+
// }
78+
// }
79+
//}
80+
81+
protected void Reset()
82+
{
83+
// We want the default value of Handedness of Controller finders to be Unknown so it doesn't attach to random object.
84+
// But we also want the Editor to start with a useful default, so we set a Left handedness on inspector reset.
85+
Handedness = Handedness.Left;
86+
}
87+
}
88+
}

Assets/MixedRealityToolkit.SDK/Features/Utilities/Solvers/AttachToController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.MixedReality.Toolkit.UI.Utilities.Solvers;
5+
using Microsoft.MixedReality.Toolkit.Utilities.Editor.Solvers;
6+
using UnityEditor;
7+
using UnityEngine;
8+
9+
namespace Microsoft.MixedReality.Toolkit.UI.Editor.Solvers
10+
{
11+
[CustomEditor(typeof(AttachToController))]
12+
public class AttachToControllerInspector : ControllerFinderInspector
13+
{
14+
private SerializedProperty positionOffsetProperty;
15+
private SerializedProperty rotationOffsetProperty;
16+
private SerializedProperty scaleOffsetProperty;
17+
private SerializedProperty setScaleOnAttachProperty;
18+
private SerializedProperty setChildrenInactiveWhenDetachedProperty;
19+
20+
protected override void OnEnable()
21+
{
22+
base.OnEnable();
23+
24+
positionOffsetProperty = serializedObject.FindProperty("PositionOffset");
25+
rotationOffsetProperty = serializedObject.FindProperty("RotationOffset");
26+
scaleOffsetProperty = serializedObject.FindProperty("ScaleOffset");
27+
setScaleOnAttachProperty = serializedObject.FindProperty("SetScaleOnAttach");
28+
setChildrenInactiveWhenDetachedProperty = serializedObject.FindProperty("SetChildrenInactiveWhenDetached");
29+
}
30+
31+
public override void OnInspectorGUI()
32+
{
33+
base.OnInspectorGUI();
34+
serializedObject.Update();
35+
36+
EditorGUILayout.Space();
37+
EditorGUILayout.LabelField("Attachment Options", new GUIStyle("Label") { fontStyle = FontStyle.Bold });
38+
EditorGUILayout.Space();
39+
EditorGUI.indentLevel++;
40+
41+
EditorGUILayout.PropertyField(positionOffsetProperty);
42+
EditorGUILayout.PropertyField(rotationOffsetProperty);
43+
EditorGUILayout.PropertyField(scaleOffsetProperty);
44+
EditorGUILayout.PropertyField(setScaleOnAttachProperty);
45+
EditorGUILayout.PropertyField(setChildrenInactiveWhenDetachedProperty);
46+
47+
EditorGUI.indentLevel--;
48+
serializedObject.ApplyModifiedProperties();
49+
}
50+
}
51+
}

Assets/MixedRealityToolkit.SDK/Inspectors/Utilities/Solvers/AttachToControllerInspector.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)