Initialer Upload neues Unity-Projekt

This commit is contained in:
Daniel Ocks
2025-07-21 09:11:14 +02:00
commit eeca72985b
14558 changed files with 1508140 additions and 0 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0e93701f7111c8343b48fc4a99b918d5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,269 @@
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
https://developer.oculus.com/licenses/oculussdk/
Unless required by applicable law or agreed to in writing, the Utilities 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 System;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace Oculus.Interaction.InterfaceSupport
{
/// <summary>
/// This property drawer is the meat of the interface support implementation. When
/// the value of field with this attribute is modified, the new value is tested
/// against the interface expected. If the component matches, the new value is
/// accepted. Otherwise, the old value is maintained.
/// </summary>
[CustomPropertyDrawer(typeof(InterfaceAttribute))]
public class InterfaceDrawer : PropertyDrawer
{
private int _filteredObjectPickerID;
private static readonly Type[] _singleMonoBehaviourType = new Type[1] { typeof(MonoBehaviour) };
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
_filteredObjectPickerID = GUIUtility.GetControlID(FocusType.Passive);
if (property.serializedObject.isEditingMultipleObjects) return;
if (property.propertyType != SerializedPropertyType.ObjectReference)
{
EditorGUI.LabelField(position, label.text, "InterfaceAttribute can only " +
"be used with Object Reference fields.");
return;
}
EditorGUI.BeginProperty(position, label, property);
Type[] attTypes = GetInterfaceTypes(property);
// Pick a specific component
UnityEngine.Object oldObject = property.objectReferenceValue;
GameObject temporaryGameObject = null;
string oldObjectName = "";
if (Event.current.type == EventType.Repaint)
{
string attTypesName = GetTypesName(attTypes);
if (oldObject == null)
{
temporaryGameObject = new GameObject("None" + " (" + attTypesName + ")");
temporaryGameObject.hideFlags = HideFlags.HideAndDontSave;
oldObject = temporaryGameObject;
}
else
{
oldObjectName = oldObject.name;
oldObject.name = oldObjectName + " (" + attTypesName + ")";
}
}
UnityEngine.Object candidateObject =
EditorGUI.ObjectField(position, label, oldObject, typeof(UnityEngine.Object), true);
int objectPickerID = GUIUtility.GetControlID(FocusType.Passive) - 1;
ReplaceObjectPickerForControl(attTypes, objectPickerID);
if (Event.current.commandName == "ObjectSelectorUpdated" &&
EditorGUIUtility.GetObjectPickerControlID() == _filteredObjectPickerID)
{
candidateObject = EditorGUIUtility.GetObjectPickerObject();
}
if (Event.current.type == EventType.Repaint)
{
if (temporaryGameObject != null)
GameObject.DestroyImmediate(temporaryGameObject);
else
oldObject.name = oldObjectName;
}
UnityEngine.Object matchingObject = null;
if (candidateObject != null)
{
// Make sure the assigned object it is the interface we are looking for.
if (IsAssignableFromTypes(candidateObject.GetType(), attTypes))
{
matchingObject = candidateObject;
}
else if (candidateObject is GameObject gameObject)
{
// If assigned component is a GameObject, find all matching components
// on it and if there are multiple, open the picker window.
List<MonoBehaviour> monos = new List<MonoBehaviour>();
monos.AddRange(gameObject.GetComponents<MonoBehaviour>().
Where((mono) => IsAssignableFromTypes(mono.GetType(), attTypes)));
if (monos.Count > 1)
{
EditorApplication.delayCall += () => InterfacePicker.Show(property, monos);
}
else
{
matchingObject = monos.Count == 1 ? monos[0] : null;
}
}
}
if (candidateObject == null || matchingObject != null)
{
property.objectReferenceValue = matchingObject;
}
EditorGUI.EndProperty();
}
private bool IsAssignableFromTypes(Type source, Type[] targets)
{
foreach (Type t in targets)
{
if (!IsAssignableTo(source, t))
{
return false;
}
}
return true;
}
private static string GetTypesName(Type[] attTypes)
{
if (attTypes.Length == 1)
{
return GetTypeName(attTypes[0]);
}
string typesString = "";
for (int i = 0; i < attTypes.Length; i++)
{
if (i > 0)
{
typesString += ", ";
}
typesString += GetTypeName(attTypes[i]);
}
return typesString;
}
private static string GetTypeName(Type attType)
{
if (!attType.IsGenericType)
{
return attType.Name;
}
var genericTypeNames = attType.GenericTypeArguments.Select(GetTypeName);
return $"{attType.Name}<{string.Join(", ", genericTypeNames)}>";
}
private Type[] GetInterfaceTypes(SerializedProperty property)
{
InterfaceAttribute att = (InterfaceAttribute)attribute;
Type[] t = att.Types;
if (!String.IsNullOrEmpty(att.TypeFromFieldName))
{
var thisType = property.serializedObject.targetObject.GetType();
while (thisType != null)
{
var referredFieldInfo = thisType.GetField(att.TypeFromFieldName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (referredFieldInfo != null)
{
t = new Type[1] { referredFieldInfo.FieldType };
break;
}
var referredPropertyInfo = thisType.GetProperty(att.TypeFromFieldName,
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
if (referredPropertyInfo != null)
{
t = new Type[1] { referredPropertyInfo.PropertyType };
break;
}
thisType = thisType.BaseType;
}
}
return t ?? _singleMonoBehaviourType;
}
void ReplaceObjectPickerForControl(Type[] attTypes, int replacePickerID)
{
var currentObjectPickerID = EditorGUIUtility.GetObjectPickerControlID();
if (currentObjectPickerID != replacePickerID)
{
return;
}
var derivedTypes = TypeCache.GetTypesDerivedFrom(attTypes[0]);
HashSet<Type> validTypes = new HashSet<Type>(derivedTypes);
for (int i = 1; i < attTypes.Length; i++)
{
var derivedTypesIntersect = TypeCache.GetTypesDerivedFrom(attTypes[i]);
validTypes.IntersectWith(derivedTypesIntersect);
}
//start filter with a long empty area to allow for easy clicking and typing
var filterBuilder = new System.Text.StringBuilder(" ");
foreach (Type type in validTypes)
{
if (type.IsGenericType)
{
continue;
}
filterBuilder.Append("t:" + type.FullName + " ");
}
string filter = filterBuilder.ToString();
EditorGUIUtility.ShowObjectPicker<Component>(null, true, filter, _filteredObjectPickerID);
}
private bool IsAssignableTo(Type fromType, Type toType)
{
// is open interface
if (toType.IsGenericType && toType.IsGenericTypeDefinition)
{
return IsAssignableToGenericType(fromType, toType);
}
return toType.IsAssignableFrom(fromType);
}
private bool IsAssignableToGenericType(Type fromType, Type toType)
{
var interfaceTypes = fromType.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == toType)
{
return true;
}
}
if (fromType.IsGenericType && fromType.GetGenericTypeDefinition() == toType)
{
return true;
}
Type baseType = fromType.BaseType;
if (baseType == null)
{
return false;
}
return IsAssignableToGenericType(baseType, toType);
}
}
}

View File

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

View File

@ -0,0 +1,160 @@
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
https://developer.oculus.com/licenses/oculussdk/
Unless required by applicable law or agreed to in writing, the Utilities 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 System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Oculus.Interaction.InterfaceSupport
{
public class InterfacePicker : EditorWindow
{
private class MonoInspector
{
public readonly MonoBehaviour Mono;
public readonly Editor Editor;
public MonoInspector(MonoBehaviour mono)
{
Mono = mono;
Editor = Editor.CreateEditor(mono);
}
public void Destroy()
{
DestroyImmediate(Editor);
}
}
private static class GUIStyles
{
public static readonly GUIStyle Default;
public static readonly GUIStyle Window;
public static readonly GUIStyle Inspector;
private static readonly RectOffset padding =
new RectOffset(EDGE_PADDING_PX,
EDGE_PADDING_PX,
EDGE_PADDING_PX,
EDGE_PADDING_PX);
static GUIStyles()
{
Default = new GUIStyle();
Window = new GUIStyle(Default);
Window.padding = padding;
Inspector = new GUIStyle(GUI.skin.window);
Inspector.padding = padding;
}
}
private const float SELECT_BUTTON_HEIGHT_PX = 32f;
private const float LABEL_COLUMN_RATIO = 0.4f;
private const int EDGE_PADDING_PX = 8;
public static bool AnyOpen => HasOpenInstances<InterfacePicker>();
private Object _target;
private string _propertyPath;
private List<MonoInspector> _monoInspectors;
private Vector2 _scrollPos = Vector2.zero;
public static void Show(SerializedProperty prop, List<MonoBehaviour> monos)
{
if (monos == null ||
monos.Count == 0 ||
prop == null)
{
return;
}
InterfacePicker picker = GetWindow<InterfacePicker>(true);
picker._propertyPath = prop.propertyPath;
picker._target = prop.serializedObject.targetObject;
picker._monoInspectors?.ForEach((mi) => mi.Destroy());
picker._monoInspectors = new List<MonoInspector>();
picker.titleContent = new GUIContent(monos[0].gameObject.name);
monos.ForEach((m) => picker._monoInspectors.Add(new MonoInspector(m)));
picker.ShowUtility();
}
private void OnGUI()
{
if (_target == null)
{
Close();
return;
}
Prune();
DrawAll();
}
private void OnDestroy()
{
_monoInspectors.ForEach((mi) => mi.Destroy());
}
private void Prune()
{
_monoInspectors.FindAll((m) => m.Mono == null).ForEach((mi) =>
{
_monoInspectors.Remove(mi);
mi.Destroy();
});
}
private void DrawAll()
{
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUIStyles.Window);
foreach (var monoInspector in _monoInspectors)
{
EditorGUILayout.Separator();
EditorGUILayout.BeginVertical(GUIStyles.Inspector);
DrawHeader(monoInspector);
EditorGUILayout.Separator();
DrawComponent(monoInspector);
EditorGUILayout.EndVertical();
}
GUILayout.FlexibleSpace();
EditorGUILayout.EndScrollView();
}
private void DrawHeader(MonoInspector monoInspector)
{
if (GUILayout.Button($"{monoInspector.Mono.GetType().Name}",
GUILayout.Height(SELECT_BUTTON_HEIGHT_PX)))
{
Apply(monoInspector.Mono);
Close();
}
}
private void DrawComponent(MonoInspector monoInspector)
{
GUI.enabled = false;
EditorGUIUtility.labelWidth = position.width * LABEL_COLUMN_RATIO;
monoInspector.Editor.OnInspectorGUI();
GUI.enabled = true;
}
private void Apply(MonoBehaviour mono)
{
SerializedProperty property =
new SerializedObject(_target).FindProperty(_propertyPath);
property.objectReferenceValue = mono;
property.serializedObject.ApplyModifiedProperties();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 13ee802452fb40949acff6a643c6d06a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,17 @@
{
"name": "Oculus.Interaction.InterfaceSupport",
"references": [
"GUID:2a230cb87a1d3ba4a98bdc0ddae76e6c"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 62f0806efa855234fa40d98ad397e1ca
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,52 @@
/************************************************************************************
Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved.
Your use of this SDK or tool is subject to the Oculus SDK License Agreement, available at
https://developer.oculus.com/licenses/oculussdk/
Unless required by applicable law or agreed to in writing, the Utilities 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 UnityEngine;
using System;
namespace Oculus.Interaction
{
/// <summary>
/// When this attribute is attached to a MonoBehaviour field within a
/// Unity Object, this allows an interface to be specified in to to
/// entire only a specific type of MonoBehaviour can be attached.
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
public class InterfaceAttribute : PropertyAttribute
{
public Type[] Types = null;
public string TypeFromFieldName;
/// <summary>
/// Creates a new Interface attribute.
/// </summary>
/// <param name="type">The type of interface which is allowed.</param>
/// <param name="types">Extra types of interface which is allowed.</param>
public InterfaceAttribute(Type type, params Type[] types)
{
Debug.Assert(type.IsInterface, $"{type.Name} needs to be an interface.");
Types = new Type[types.Length + 1];
Types[0] = type;
for (int i = 0; i < types.Length; i++)
{
Debug.Assert(types[i].IsInterface, $"{types[i].Name} needs to be an interface.");
Types[i+1] = types[i];
}
}
public InterfaceAttribute(string typeFromFieldName)
{
this.TypeFromFieldName = typeFromFieldName;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 548b4f28547edc44d95c20e74bcc8c70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
MIT License
Copyright (c) 2020 TheDudeFromCI
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
// Unity Interface Support based on
// https://github.com/TheDudeFromCI/Unity-Interface-Support/

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: b4104bbb012ef2b4b9e1d89fcb33b495
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: