First commit

This commit is contained in:
Pascal Serrarens 2022-01-12 10:50:57 +01:00
commit 17741d862a
1528 changed files with 470041 additions and 0 deletions

8
Editor.meta Normal file
View File

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

8
Editor/HumanoidFree.meta Normal file
View File

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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0e21e875c1037294faff6e238111315b
timeCreated: 1534854189
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,73 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
namespace Passer.Humanoid {
public class PoseEvent_Editor : Event_Editor {
public static void EventInspector(
SerializedProperty eventSourceProp, PoseEventList eventSource,
ref int selectedEventSourceIx, ref int selectedEventIx) {
//UnityEventBase unityEventBase = eventSource.events[selectedEventIx].GetUnityEventBase();
EventInspector(eventSourceProp, ref selectedEventSourceIx, ref selectedEventIx,
PoseMethodCheck, InitPoseEvent);
}
protected static void InitPoseEvent(SerializedProperty eventProp) {
}
protected static bool PoseMethodCheck(MethodInfo method, out string label) {
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0 && method.ReturnType == typeof(void)) {
label = method.Name + " ()";
return true;
}
else if (parameters.Length == 1 && (
parameters[0].ParameterType == typeof(bool) ||
parameters[0].ParameterType == typeof(Pose)
)) {
label = method.Name + " (" + parameters[0].ParameterType.Name + ")";
return true;
}
label = "";
return false;
}
public static void DetailsInspector(SerializedProperty eventProp, string label) {
if (eventProp == null)
return;
DetailsTypeInspector(eventProp);
PoseDetailsInspector(eventProp, label);
}
protected static SerializedProperty DetailsTypeInspector(SerializedProperty eventProp) {
GUIContent text = new GUIContent(
"Event Type",
"Never: the function is never called\n" +
"OnStart: when the Pose becomes non-null\n" +
"OnEnd: when the Pose becomes null\n" +
"WhileActive: while Pose is non-null\n" +
"WhileInactive: while Pose is null\n" +
"OnChange: when the Pose changes\n" +
"Continuous: the function is called for every frame"
);
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
eventTypeProp.intValue = (int)(EventHandler.Type)EditorGUILayout.EnumPopup(text, (EventHandler.Type)eventTypeProp.intValue);
return eventTypeProp;
}
protected static void PoseDetailsInspector(SerializedProperty eventProp, string label) {
SerializedProperty poseEventProp = eventProp.FindPropertyRelative("poseEvent");
EditorGUILayout.PropertyField(poseEventProp, new GUIContent("Pose"));
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 38cd88a9439142a4da4900d6fad80ee6
timeCreated: 1551348784
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,39 @@
using UnityEngine;
using UnityEditor;
namespace Passer.Humanoid {
using Passer.Tracking;
[CustomEditor(typeof(RealWorldConfiguration))]
public class RealWorldConfiguration_Editor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();
SerializedProperty trackerList = serializedObject.FindProperty("trackers");
for (int i = 0; i < trackerList.arraySize; i++) {
SerializedProperty trackerProp = trackerList.GetArrayElementAtIndex(i);
TrackingSpaceInspector(trackerProp);
}
serializedObject.ApplyModifiedProperties();
}
bool foldout = true;
protected virtual void TrackingSpaceInspector(SerializedProperty trackerProp) {
SerializedProperty trackerIdProp = trackerProp.FindPropertyRelative("trackerId");
TrackerId trackerId = (TrackerId) trackerIdProp.intValue;
foldout = EditorGUILayout.Foldout(foldout, trackerId.ToString());
if (foldout) {
EditorGUI.indentLevel++;
SerializedProperty positionProp = trackerProp.FindPropertyRelative("position");
positionProp.vector3Value = EditorGUILayout.Vector3Field("Position", positionProp.vector3Value);
SerializedProperty rotationProp = trackerProp.FindPropertyRelative("rotation");
Vector3 angles = rotationProp.quaternionValue.eulerAngles;
angles = EditorGUILayout.Vector3Field("Rotation", angles);
rotationProp.quaternionValue = Quaternion.Euler(angles);
EditorGUI.indentLevel--;
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fec146cec5c169f44bb2a27991f924b3
timeCreated: 1562138586
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,184 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
using Passer.Tracking;
public class UnityXR_Editor : Tracker_Editor {
#if pUNITYXR
#region Tracker
public class TrackerProps : HumanoidControl_Editor.HumanoidTrackerProps {
#if hOCHAND
readonly private SerializedProperty oculusHandTrackingProp;
#endif
#if hVIVEHAND
readonly private SerializedProperty viveHandTrackingProp;
#endif
public TrackerProps(SerializedObject serializedObject, HumanoidControl_Editor.HumanoidTargetObjs targetObjs, UnityXRTracker _unityXR)
: base(serializedObject, targetObjs, _unityXR, nameof(HumanoidControl.unityXR)) {
tracker = _unityXR;
#if hOCHAND
oculusHandTrackingProp = serializedObject.FindProperty("unityXR.oculusHandTracking");
CheckQuestManifest();
#endif
#if hVIVEHAND
viveHandTrackingProp = serializedObject.FindProperty("unityXR.viveHandTracking");
#endif
}
public override void Inspector(HumanoidControl humanoid) {
Inspector(humanoid, "Unity XR");
if (enabledProp.boolValue) {
EditorGUI.indentLevel++;
TrackerInspector(humanoid, humanoid.unityXR);
HandTrackingInspector(humanoid);
EditorGUI.indentLevel--;
}
}
protected void HandTrackingInspector(HumanoidControl humanoid) {
OculusHandTrackingInspector();
ViveHandTrackingInspector(humanoid);
}
protected void OculusHandTrackingInspector() {
#if hOCHAND
GUIContent labelText = new GUIContent(
"Oculus Hand Tracking",
"Enables hand tracking on the Oculus Quest"
);
oculusHandTrackingProp.boolValue = EditorGUILayout.ToggleLeft(labelText, oculusHandTrackingProp.boolValue);
#endif
}
protected virtual void CheckQuestManifest() {
string manifestPath = Application.dataPath + "/Plugins/Android/AndroidManifest.xml";
FileInfo fileInfo = new FileInfo(manifestPath);
fileInfo.Directory.Create();
bool manifestAvailable = File.Exists(manifestPath);
if (manifestAvailable)
return;
string humanoidPath = Configuration_Editor.FindHumanoidFolder();
string questManifestPath = Application.dataPath + humanoidPath + "Extensions/Oculus/QuestManifest.xml";
File.Copy(questManifestPath, manifestPath);
}
protected void ViveHandTrackingInspector(HumanoidControl humanoid) {
#if hVIVEHAND
GUIContent labelText = new GUIContent(
"Vive Hand Tracking",
"Enables hand tracking on the HTC Vive"
);
viveHandTrackingProp.boolValue = EditorGUILayout.ToggleLeft(labelText, viveHandTrackingProp.boolValue);
// When using vive hand tracking, the GestureProvider should be added to the UnityXR component
// before the scene starts. So we need to add it in the edito
// and we need to have the unityXR component in the scene
if (viveHandTrackingProp.boolValue == true) {
humanoid.unityXR.CheckTracker(humanoid, UnityXR.Get);
ViveHandSkeleton.CheckGestureProvider(humanoid.unityXR.trackerComponent);
}
#endif
}
}
#endregion
#region Head
public class HeadTargetProps : HeadTarget_Editor.TargetProps {
readonly SerializedProperty hmdProp;
public HeadTargetProps(SerializedObject serializedObject, HeadTarget headTarget)
: base(serializedObject, headTarget.unityXR, headTarget, nameof(HeadTarget.unityXR)) {
hmdProp = serializedObject.FindProperty(nameof(HeadTarget.unityXR) + ".hmd");
}
public override void Inspector() {
if (!headTarget.humanoid.unityXR.enabled)
return;
enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(headTarget.unityXR, headTarget);
headTarget.unityXR.enabled = enabledProp.boolValue;
if (enabledProp.boolValue) {
EditorGUI.indentLevel++;
if (headTarget.unityXR.hmd == null) {
// Hmd does not exist
using (new EditorGUILayout.HorizontalScope()) {
EditorGUILayout.LabelField("Hmd", GUILayout.Width(120));
if (GUILayout.Button("Show")) {
headTarget.unityXR.CheckSensor(headTarget);
}
}
}
else
hmdProp.objectReferenceValue = (UnityXRHmd)EditorGUILayout.ObjectField("Hmd", headTarget.unityXR.hmd, typeof(UnityXRHmd), true);
EditorGUI.indentLevel--;
}
else
headTarget.unityXR.CheckSensor(headTarget);
}
}
#endregion
#region Hand
public class HandTargetProps : HandTarget_Editor.TargetProps {
SerializedProperty controllerProp;
public HandTargetProps(SerializedObject serializedObject, HandTarget handTarget)
: base(serializedObject, handTarget.unityXR, handTarget, "unityXR") {
controllerProp = serializedObject.FindProperty("unityXR.controller");
}
public override void Inspector() {
if (!handTarget.humanoid.unityXR.enabled)
return;
enabledProp.boolValue = HumanoidTarget_Editor.ControllerInspector(handTarget.unityXR, handTarget);
handTarget.unityXR.enabled = enabledProp.boolValue;
if (enabledProp.boolValue) {
EditorGUI.indentLevel++;
if (handTarget.unityXR.controller == null) {
// Controller does not exist
using (new EditorGUILayout.HorizontalScope()) {
EditorGUILayout.LabelField("Controller", GUILayout.Width(120));
if (GUILayout.Button("Show")) {
handTarget.unityXR.CheckSensor(handTarget);
}
}
}
else
controllerProp.objectReferenceValue = (UnityXRController)EditorGUILayout.ObjectField("Controller", controllerProp.objectReferenceValue, typeof(UnityXRController), true);
EditorGUI.indentLevel--;
}
else
handTarget.unityXR.CheckSensor(handTarget);
}
}
#endregion
#endif
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9c0bc4a64527a146baf617108518151
MonoImporter:
externalObjects: {}
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,12 @@
fileFormatVersion: 2
guid: 7b268ac19ecf09444b33a5c00674eec9
timeCreated: 1453541563
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,158 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
/// <summary>
/// Sets preferences for \ref Humanoid "Humanoid Control"
/// </summary>
///
/// The preferences can be accessed by the Edit->Preferences... menu.
///
/// \image html HumanoidPreferences.png
///
/// * SteamVR Support, enables support for SteamVR devices beyound Unity XR (VR, Plus, Pro)
/// * Vive Tracker Support, enables support for Vive Trackers (Plus, Pro)
/// * Leap Motion Support, enables support for Leap Motion (Plus, Pro)
/// * Kinect 1 Support, enables support for Microsoft Kinect 360/Kinect for Windows (Plus, Pro)
/// * Kinect 2 Support, enables support for Microsoft Kinect 2 (Plus, Pro)
/// * Azure Kinect Support, enables support for Azure Kinect (Plus, Pro)
/// * Orbbec Astra Support, enables support for Orbbec Astra (Plus, Pro)
/// * Hydra Support, enables support for Razer Hydra (Pro)
/// * Tobii Support, enables support for Tobii desktop eye tracking (Pro)
/// * Perception Neuron Support, enables support for Perception Neuron (Pro)
/// * OptiTrack Support, enables support for OptiTrack (Pro)
/// * Antilatency Support, enables support for Antilatency (Pro)
///
/// * The Testing Visitor selects which Visitor Scene will be used when a Site is started in Play mode.
///
[System.Serializable]
public class HumanoidPreferences : ScriptableObject {
public static bool help = false;
public const string settingsPath = "Assets/Passer/Humanoid/HumanoidPreferences.asset";
public Configuration configuration;
internal static HumanoidPreferences GetOrCreateSettings() {
string humanoidPath = Configuration_Editor.FindHumanoidFolder();
humanoidPath = humanoidPath.Substring(0, humanoidPath.Length - 1); // strip last /
humanoidPath = humanoidPath.Substring(0, humanoidPath.LastIndexOf('/') + 1); // strip Scripts;
string settingsPath = "Assets" + humanoidPath + "HumanoidPreferences.asset";
HumanoidPreferences settings = AssetDatabase.LoadAssetAtPath<HumanoidPreferences>(settingsPath);
SerializedObject serializedSettings = new SerializedObject(settings);
if (settings == null) {
settings = CreateInstance<HumanoidPreferences>();
AssetDatabase.CreateAsset(settings, settingsPath);
}
if (settings.configuration == null) {
string configurationString = EditorPrefs.GetString("HumanoidConfigurationKey", "DefaultConfiguration");
Configuration configuration = Configuration_Editor.LoadConfiguration(configurationString);
if (configuration == null) {
configurationString = "DefaultConfiguration";
Configuration_Editor.LoadConfiguration(configurationString);
if (configuration == null) {
Debug.Log("Created new Default Configuration");
// Create new Default Configuration
configuration = CreateInstance<Configuration>();
string path = "Assets" + humanoidPath + configurationString + ".asset";
AssetDatabase.CreateAsset(configuration, path);
AssetDatabase.SaveAssets();
}
}
SerializedProperty configurationProp = serializedSettings.FindProperty("configuration");
configurationProp.objectReferenceValue = configuration;
EditorUtility.SetDirty(settings);
}
serializedSettings.ApplyModifiedProperties();
return (HumanoidPreferences)serializedSettings.targetObject;//settings;
}
internal static SerializedObject GetOrCreateSerializedSettings() {
string humanoidPath = Configuration_Editor.FindHumanoidFolder();
humanoidPath = humanoidPath.Substring(0, humanoidPath.Length - 1); // strip last /
humanoidPath = humanoidPath.Substring(0, humanoidPath.LastIndexOf('/') + 1); // strip Scripts;
string settingsPath = "Assets" + humanoidPath + "HumanoidPreferences.asset";
HumanoidPreferences settings = AssetDatabase.LoadAssetAtPath<HumanoidPreferences>(settingsPath);
if (settings == null) {
Debug.Log("Created new Settings");
settings = CreateInstance<HumanoidPreferences>();
AssetDatabase.CreateAsset(settings, settingsPath);
}
if (settings.configuration == null) {
Debug.Log("Settings Configuration is not set");
string configurationString = "DefaultConfiguration";
Configuration configuration = Configuration_Editor.LoadConfiguration(configurationString);
if (configuration == null) {
configurationString = "DefaultConfiguration";
Configuration_Editor.LoadConfiguration(configurationString);
if (configuration == null) {
Debug.Log("Created new Default Configuration");
// Create new Default Configuration
configuration = CreateInstance<Configuration>();
string path = "Assets" + humanoidPath + configurationString + ".asset";
AssetDatabase.CreateAsset(configuration, path);
AssetDatabase.SaveAssets();
}
}
settings.configuration = configuration;
}
SerializedObject serializedSettings = new SerializedObject(settings);
return serializedSettings;
}
}
static class HumanoidPreferencesIMGUIRegister {
public static bool reload;
[SettingsProvider]
public static SettingsProvider CreateHumanoidSettingsProvider() {
var provider = new SettingsProvider("Preferences/HumanoidControlSettings", SettingsScope.User) {
label = "Humanoid Control",
guiHandler = (searchContext) => {
SerializedObject serializedSettings = HumanoidPreferences.GetOrCreateSerializedSettings();
SerializedProperty configurationProp = serializedSettings.FindProperty("configuration");
Configuration oldConfiguration = (Configuration)configurationProp.objectReferenceValue;
configurationProp.objectReferenceValue = EditorGUILayout.ObjectField("Configuration", configurationProp.objectReferenceValue, typeof(Configuration), false);
SerializedObject serializedConfiguration = new SerializedObject(configurationProp.objectReferenceValue);
bool anyChanged = false;
anyChanged |= (configurationProp.objectReferenceValue != oldConfiguration);
anyChanged |= Configuration_Editor.ConfigurationGUI(serializedConfiguration);
serializedConfiguration.ApplyModifiedProperties();
serializedSettings.ApplyModifiedProperties();
Configuration_Editor.CheckExtensions((Configuration)configurationProp.objectReferenceValue);
if (reload) {
reload = false;
#if hUNET
OnLoadHumanoidPlayerUnet.CheckHumanoidPlayer();
#endif
#if hPHOTON1 || hPHOTON2
OnLoadHumanoidPlayerPun.CheckHumanoidPlayer();
#endif
#if hBOLT
OnLoadHumanoidPlayerBolt.CheckHumanoidPlayer();
#endif
#if hMIRROR
OnLoadHumanoidPlayerMirror.CheckHumanoidPlayer();
#endif
}
},
keywords = new HashSet<string>(
new[] { "Humanoid", "Oculus", "SteamVR" }
)
};
return provider;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6021fe10956d4fe4e847551130851c03
timeCreated: 1559823791
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 505c20d3b5eb39c44b642561b71057c2
folderAsset: yes
DefaultImporter:
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: e541a1c70a1d7c3439b0071a59508460
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

View File

@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: b9f0c4cc30a3a8e459af3607eba66591
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 1024
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:

View File

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

View File

@ -0,0 +1,20 @@
using UnityEditor;
namespace Passer.Humanoid {
using Pawn;
public class HumanoidNetworking_Editor : Editor {
protected virtual void SyncFingerSwingInspector() {
SerializedProperty syncFingerSwingProp = serializedObject.FindProperty("_syncFingerSwing");
syncFingerSwingProp.boolValue = EditorGUILayout.Toggle("Sync Finger Swing", syncFingerSwingProp.boolValue);
}
protected virtual void SyncTrackingInspector() {
SerializedProperty syncTrackingProp = serializedObject.FindProperty("_syncTracking");
syncTrackingProp.boolValue = EditorGUILayout.Toggle("Sync Tracking Space", syncTrackingProp.boolValue);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 534ed79b66bde8d459759734a5d468f7
timeCreated: 1504014208
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,83 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
#if !UNITY_2019_1_OR_NEWER
using UnityEngine.Networking;
#endif
namespace Passer.Humanoid {
[InitializeOnLoad]
public class OnLoadHumanoidPlayer {
static OnLoadHumanoidPlayer() {
HumanoidPreferencesIMGUIRegister.reload = true;
}
public static string GetHumanoidPlayerPrefabPath() {
string humanoidPath = Configuration_Editor.FindHumanoidFolder();
string prefabPathWithoutScripts = humanoidPath.Substring(0, humanoidPath.Length - 8);
string prefabPath = "Assets" + prefabPathWithoutScripts + "Prefabs/Networking/Resources/HumanoidPlayer.prefab";
return prefabPath;
}
public static GameObject GetHumanoidPlayerPrefab(string prefabPath) {
GameObject prefab = PrefabUtility.LoadPrefabContents(prefabPath);
return prefab;
}
public static void UpdateHumanoidPrefab(GameObject prefab, string prefabPath) {
if (!Application.isPlaying) {
Debug.Log("UpdateHumanoidPrefab " + Application.isFocused + " " + Application.isBatchMode + " " + Application.isEditor);
if (Application.isFocused && !Application.isBatchMode && Application.isEditor) {
Debug.Log("delaying save " + prefab);
HumanoidPlayer_Editor.prefabsToSave.Push(prefab);
HumanoidPlayer_Editor.prefabPaths.Push(prefabPath);
EditorApplication.delayCall += HumanoidPlayer_Editor.DelayedSave;
}
else {
Debug.Log("updating " + prefab);
PrefabUtility.SaveAsPrefabAsset(prefab, prefabPath);
PrefabUtility.UnloadPrefabContents(prefab);
}
}
}
[CustomEditor(typeof(HumanoidPlayer))]
public class HumanoidPlayer_Editor : HumanoidNetworking_Editor {
#if hNW_UNET
public override void OnInspectorGUI() {
serializedObject.Update();
SendRateInspector();
DebugLevelInspector();
SmoothingInspector();
SyncFingerSwingInspector();
CreateLocalRemotesInspector();
SyncTrackingInspector();
serializedObject.ApplyModifiedProperties();
}
#endif
public static Stack<GameObject> prefabsToSave = new Stack<GameObject>();
public static Stack<string> prefabPaths = new Stack<string>();
//private void OnSceneGUI() {
public static void DelayedSave() {
if (Application.isPlaying)
return;
if (prefabsToSave.Count > 0) {
GameObject prefab = prefabsToSave.Pop();
Debug.Log("Delayed save of prefab " + prefab);
string path = prefabPaths.Pop();
PrefabUtility.SaveAsPrefabAsset(prefab, path);
PrefabUtility.UnloadPrefabContents(prefab);
}
}
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ff6f5bfdd54b0a84da3fa2464feaf06e
timeCreated: 1563434259
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,46 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Networking;
namespace Passer.Humanoid {
[CustomEditor(typeof(NetworkingSpawner))]
public class NetworkingSpawner_Editor : NetworkingStarter_Editor {
private SerializedProperty humanoidPrefabProp;
private SerializedProperty spawnPointsProp;
private SerializedProperty spawnMethodProp;
public override void OnEnable() {
base.OnEnable();
humanoidPrefabProp = serializedObject.FindProperty("humanoidPrefab");
spawnPointsProp = serializedObject.FindProperty("spawnPoints");
spawnMethodProp = serializedObject.FindProperty("spawnMethod");
}
public override void OnInspectorGUI() {
base.OnInspectorGUI();
GUIContent label;
label = new GUIContent(
"Humanoid Prefab",
"The Humanoid Prefab that will be spawned when networking has started"
);
EditorGUILayout.PropertyField(humanoidPrefabProp, label);
label = new GUIContent(
"Spawn Points",
"The possible spawning points for the Humanoid"
);
EditorGUILayout.PropertyField(spawnPointsProp, label, true);
label = new GUIContent(
"Spawn Mode",
"The order in which the spawn points are chosen"
);
EditorGUILayout.PropertyField(spawnMethodProp, label);
serializedObject.ApplyModifiedProperties();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a432ba4f8b031e84ebae8a3ad39724f3
timeCreated: 1519718995
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,118 @@
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
using Passer.Tracking;
[HelpURL("http://passervr.com/documentation/humanoid-control/object-tracker/")]
[CustomEditor(typeof(ObjectTracker))]
public class ObjectTracker_Editor : Editor {
public enum Side {
Left,
Right
}
protected ObjectTracker objectTracker;
#region Enable
public void OnEnable() {
objectTracker = (ObjectTracker)target;
//if (objectTracker.targetTransform == null)
// objectTracker.targetTransform = objectTracker.transform;
// HumanoidControl humanoid = objectTracker.humanoid;
// if (humanoid != null) {
//#if hOCULUS
// objectTracker.oculusTouch.tracker = humanoid.oculus;
//#endif
// }
//#if hOCULUS
// if (objectTracker.oculusTouch.target == null)
// objectTracker.oculusTouch.target = objectTracker;
//#endif
}
#endregion
#region Disable
public void OnDisable() {
if (!Application.isPlaying) {
serializedObject.Update();
SetSensor2Object();
serializedObject.ApplyModifiedProperties();
}
}
protected void SetSensor2Object() {
SensorComponent sensorComponent = objectTracker.sensorComponent;
if (sensorComponent == null)
return;
SerializedProperty sensor2ObjectRotationProp = serializedObject.FindProperty("sensor2ObjectRotation");
sensor2ObjectRotationProp.quaternionValue = Quaternion.Inverse(sensorComponent.transform.rotation) * objectTracker.transform.rotation;
SerializedProperty sensor2ObjectPositionProp = serializedObject.FindProperty("sensor2ObjectPosition");
sensor2ObjectPositionProp.vector3Value = -InverseTransformPointUnscaled(objectTracker.transform, sensorComponent.transform.position);
}
private static Vector3 InverseTransformPointUnscaled(Transform transform, Vector3 position) {
var worldToLocalMatrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse;
return worldToLocalMatrix.MultiplyPoint3x4(position);
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
ObjectTracker objectTracker = (ObjectTracker)target;
serializedObject.Update();
SerializedProperty sensorComponentProp = serializedObject.FindProperty("sensorComponent");
sensorComponentProp.objectReferenceValue = (SensorComponent)EditorGUILayout.ObjectField("Sensor Component", sensorComponentProp.objectReferenceValue, typeof(SensorComponent), true);
Settings(objectTracker);
serializedObject.ApplyModifiedProperties();
}
#region Settings
private static bool showSettings = false;
public static void Settings(ObjectTracker objectTracker) {
showSettings = EditorGUILayout.Foldout(showSettings, "Settings", true);
if (showSettings) {
EditorGUI.indentLevel++;
objectTracker.showRealObjects = EditorGUILayout.Toggle("Show Real Objects", objectTracker.showRealObjects);
ShowTrackers(objectTracker, objectTracker.showRealObjects);
// Work in progress
//objectTracker.physics = EditorGUILayout.Toggle("Physics", objectTracker.physics);
EditorGUI.indentLevel--;
}
}
private static void ShowTrackers(ObjectTracker objectTracker, bool shown) {
objectTracker.ShowTrackers(shown);
}
#endregion
#endregion
#region Scene
//private Vector3 objectPosition;
//private Quaternion objectLocalRotation;
public void OnSceneGUI() {
ObjectTracker objectTracker = (ObjectTracker)target;
//if (!Application.isPlaying)
// objectTracker.UpdateSensorsFromTarget();
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 81fa75314925347479e90858692406b5
timeCreated: 1470140284
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,14 @@
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(BallHandle))]
public class BallHandle_Editor : Handle_Editor {
public override void OnInspectorGUI() {
EditorGUILayout.HelpBox("BallHandle is depreciated, use Handle with Grab Type=Ball Grab instead.", MessageType.Warning);
base.OnInspectorGUI();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5377376e3bb6b534499b7acdc84ea2b0
timeCreated: 1547654508
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,14 @@
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(BarHandle))]
public class BarHandle_Editor : Handle_Editor {
public override void OnInspectorGUI() {
EditorGUILayout.HelpBox("BarHandle is depreciated, use Handle with Grab Type=Bar Grab instead.", MessageType.Warning);
base.OnInspectorGUI();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6f72951144d0b36449e65bbd06fc6ed4
timeCreated: 1506938796
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1 @@
// This file is intentionally empty

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 61ac78e296f28ed4895d68008f395045
timeCreated: 1515774271
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,322 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Passer;
using Passer.Humanoid.Tracking;
namespace Passer.Humanoid {
[CustomEditor(typeof(Pose))]
public class Pose_Editor : Editor {
private Pose pose;
#region Enable
public void OnEnable() {
pose = (Pose)target;
if (pose.bonePoses == null)
pose.bonePoses = new List<BonePose>();
}
#endregion
#region Disable
public void OnDisable() {
pose.Cleanup();
}
#endregion
private enum Reference {
HumanoidLocal,
BoneLocal
}
#region Inspector
public override void OnInspectorGUI() {
for (int i = 0; i < pose.bonePoses.Count; i++) {
BonePose bonePoses = pose.bonePoses[i];
if (bonePoses == null)
continue;
if (bonePoses.boneRef.type == BoneType.SideBones && bonePoses.boneRef.side == Side.AnySide) {
EditorGUILayout.HelpBox("Configure AnySide like Left Side", MessageType.Info);
}
EditorGUILayout.BeginHorizontal();
bonePoses.boneRef.type = (BoneType)EditorGUILayout.EnumPopup(bonePoses.boneRef.type, GUILayout.Width(159));
Bone oldBoneId = bonePoses.boneRef.boneId;
SideBone oldSideBoneId = bonePoses.boneRef.sideBoneId;
BoneSelector(ref bonePoses.boneRef);
EditorGUILayout.EndHorizontal();
if (bonePoses.boneRef.boneId != oldBoneId || bonePoses.boneRef.sideBoneId != oldSideBoneId)
PresetReferenceBone(bonePoses.boneRef, ref bonePoses.referenceBoneRef);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Reference", GUILayout.MaxWidth(65));
bonePoses.referenceBoneRef.type = (BoneType)EditorGUILayout.EnumPopup(bonePoses.referenceBoneRef.type, GUILayout.Width(90));
BoneSelector(ref bonePoses.referenceBoneRef); EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
bonePoses.setTranslation = EditorGUILayout.ToggleLeft("Translation", bonePoses.setTranslation, GUILayout.MaxWidth(131));
if (bonePoses.setTranslation)
bonePoses.translation = EditorGUILayout.Vector3Field("", bonePoses.translation);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
bonePoses.setRotation = EditorGUILayout.ToggleLeft("Rotation", bonePoses.setRotation, GUILayout.MaxWidth(131));
if (bonePoses.setRotation) {
Vector3 eulerAngles = EditorGUILayout.Vector3Field("", bonePoses.rotation.eulerAngles);
if (eulerAngles != bonePoses.rotation.eulerAngles)
bonePoses.rotation.eulerAngles = eulerAngles;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
bonePoses.setScale = EditorGUILayout.ToggleLeft("Scale", bonePoses.setScale, GUILayout.MaxWidth(131));
if (bonePoses.setScale)
bonePoses.scale = EditorGUILayout.Vector3Field("", bonePoses.scale);
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
Buttons();
EditorUtility.SetDirty(pose);
}
private void PresetReferenceBone(BoneReference bone, ref BoneReference referenceBone) {
if (referenceBone.boneId != Bone.None)
return;
if (bone.isFacialBone)
referenceBone.centerBoneId = CenterBone.Head;
if (bone.isHandBone) {
referenceBone.sideBoneId = SideBone.Hand;
referenceBone.type = BoneType.SideBones;
}
}
private void BoneSelector(ref BoneReference bone) {
switch (bone.type) {
case BoneType.AllBones:
bone.boneId = (Bone)EditorGUILayout.EnumPopup(bone.boneId);
return;
case BoneType.CenterBones:
CenterBone centerBone = (CenterBone)EditorGUILayout.EnumPopup(bone.centerBoneId);
if (centerBone != CenterBone.Unknown)
bone.centerBoneId = centerBone;
return;
case BoneType.SideBones:
if (bone.boneId == Bone.None) {
SideBone sideBoneId = bone.sideBoneId;
bone.sideBoneId = (SideBone)EditorGUILayout.EnumPopup(sideBoneId);
}
else {
bone.sideBoneId = (SideBone)EditorGUILayout.EnumPopup(bone.sideBoneId);
}
bone.side = (Side)EditorGUILayout.EnumPopup(bone.side, GUILayout.Width(80));
return;
case BoneType.FaceBones:
bone.faceBoneId = (FacialBone)EditorGUILayout.EnumPopup(bone.faceBoneId);
return;
default:
return;
}
}
#region Buttons
private void Buttons() {
EditorGUILayout.BeginHorizontal();
AddBoneButton();
ClearAllButton();
EditorGUILayout.EndHorizontal();
}
private void AddBoneButton() {
if (GUILayout.Button("Add Bone")) {
//PoseBone newBone = new PoseBone();
//PoseBone newBone = ScriptableObject.CreateInstance<PoseBone>();
//pose.bones.Add(newBone);
pose.AddBone(Bone.None);
}
}
private void ClearAllButton() {
if (GUILayout.Button("Clear All")) {
pose.bonePoses = new List<BonePose>();
//pose.boneArray = new BonePose[0];
}
}
#endregion
#endregion
public static void PoseMixerInspector(PoseMixer poseMixer, HumanoidControl humanoid, Side side = Side.AnySide) {
int i = 0;
foreach (MixedPose pose in poseMixer.mixedPoses) {
Pose oldPose = pose.pose;
HumanoidPoseInspector(poseMixer, pose, i, humanoid, side);
if (pose.pose != oldPose && pose.pose == null) {
// We deleted a pose, let's undo it's effect
pose.value = 0;
pose.pose = oldPose;
poseMixer.ShowPose(humanoid);
pose.pose = null;
}
i++;
}
EditorGUILayout.BeginHorizontal();
Pose addPose = (Pose)EditorGUILayout.ObjectField(null, typeof(Pose), false, GUILayout.Width(200));
if (addPose != null) {
MixedPose newPose = poseMixer.Add();
newPose.pose = addPose;
}
EditorGUILayout.EndHorizontal();
}
public static MixedPose HumanoidPoseInspector(PoseMixer poseMixer, MixedPose mixedPose, int poseIx, HumanoidControl humanoid, Side side = Side.AnySide) {
EditorGUILayout.BeginHorizontal();
if (poseMixer.poseMode == PoseMixer.PoseMode.Set)
mixedPose.pose = (Pose)EditorGUILayout.ObjectField(mixedPose.pose, typeof(Pose), false, GUILayout.Width(200));
else
mixedPose.pose = (Pose)EditorGUILayout.ObjectField(mixedPose.pose, typeof(Pose), false);
if (mixedPose.pose != null) {
if (mixedPose.isEdited) {
EditorGUILayout.Slider(mixedPose.value, 0, 1);
poseMixer.SetPoseValue(poseIx, 1);
}
else if (poseMixer.poseMode == PoseMixer.PoseMode.Set)
{
float value = EditorGUILayout.Slider(mixedPose.value, 0, 1);
if (value != mixedPose.value) {
poseMixer.SetPoseValue(poseIx, value);
}
}
if (!Application.isPlaying || side == Side.AnySide) {
bool isEdited = EditorGUILayout.Toggle(mixedPose.isEdited, "button", GUILayout.Width(19));
if (mixedPose.isEdited != isEdited)
SceneView.RepaintAll();
mixedPose.isEdited = isEdited;
}
else {
EditorGUILayout.FloatField(mixedPose.score);
}
}
EditorGUILayout.EndHorizontal();
if (mixedPose.isEdited) {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(" ", GUILayout.Width(200));
mixedPose.additive = EditorGUILayout.ToggleLeft("Additive", mixedPose.additive);
EditorGUILayout.EndHorizontal();
}
return mixedPose;
}
#region Scene
static int boneIndex = -1;
public static void UpdateScene(HumanoidControl humanoid, ITarget target, PoseMixer poseMixer, ref BonePose selectedBone, Side side = Side.AnySide) {
//if (!Application.isPlaying)
// poseMixer.ShowPose(humanoid);
MixedPose currentPose = poseMixer.GetEditedPose();
if (currentPose == null || !currentPose.isEdited) {
UnityEditor.Tools.hidden = false;
return;
}
UnityEditor.Tools.hidden = true;
HumanoidTarget.TargetedBone[] bones = target.GetBones();
int[] controlIds = new int[bones.Length];
Bone[] boneIds = new Bone[bones.Length];
for (int i = 0; i < bones.Length; i++) {
if (bones[i] == null || bones[i].bone == null || bones[i].bone.transform == null)
continue;
Handles.FreeMoveHandle(bones[i].bone.transform.position, bones[i].bone.transform.rotation, 0.002F, Vector3.zero, DotHandleCapSaveID);
controlIds[i] = lastControlID;
boneIds[i] = bones[i].boneId;
}
FindSelectedHandle(controlIds, boneIds, ref boneIndex);
if (boneIndex == -1)
return;
HumanoidTarget.TargetedBone targetedBone = FindTargetedBone(bones, boneIds[boneIndex]);
if (targetedBone == null || targetedBone.bone.transform == null)
return;
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.yellow;
Handles.Label(targetedBone.bone.transform.position + Vector3.up * 0.01F, targetedBone.name, style);
Handles.color = Color.white;
switch (UnityEditor.Tools.current) {
case Tool.Move:
selectedBone = currentPose.pose.CheckBone(boneIds[boneIndex], true);
Vector3 handlePosition = Handles.PositionHandle(targetedBone.target.transform.position, targetedBone.bone.transform.rotation);
targetedBone.target.transform.position = handlePosition;
selectedBone.setTranslation = true;
selectedBone.SetReferenceLocal(humanoid, side);
selectedBone.UpdateTranslation(humanoid, side);
break;
case Tool.Rotate:
selectedBone = currentPose.pose.CheckBone(boneIds[boneIndex], true);
Quaternion handleRotation = Handles.RotationHandle(targetedBone.target.transform.rotation, targetedBone.bone.transform.position);
targetedBone.target.transform.rotation = handleRotation;
selectedBone.setRotation = true;
selectedBone.SetReferenceLocal(humanoid, side);
selectedBone.UpdateRotation(humanoid, side);
break;
case Tool.Scale:
//Handles.ScaleHandle(selectedBone.transform.localScale, selectedBone.transform.position, selectedBone.transform.rotation, HandleUtility.GetHandleSize(selectedBone.transform.position));
// need to all morphScale first...
break;
}
Handles.BeginGUI();
ResetBoneButton(selectedBone, humanoid);
Handles.EndGUI();
}
private static void ResetBoneButton(BonePose selectedBone, HumanoidControl humanoid) {
if (GUILayout.Button("Reset Bone", GUILayout.Width(100))) {
Debug.Log("Got it to work.");
selectedBone.setRotation = false;
selectedBone.rotation = Quaternion.identity;
HumanoidTarget.TargetedBone targetedBone = humanoid.GetBone(selectedBone.boneRef.boneId);
targetedBone.target.transform.localRotation = selectedBone.rotation;
}
}
private static HumanoidTarget.TargetedBone FindTargetedBone(HumanoidTarget.TargetedBone[] bones, Tracking.Bone boneId) {
foreach (HumanoidTarget.TargetedBone bone in bones) {
if (bone.boneId == boneId)
return bone;
}
return null;
}
static int lastControlID;
public static void DotHandleCapSaveID(int controlID, Vector3 position, Quaternion rotation, float size, EventType et) {
lastControlID = controlID;
Handles.DotHandleCap(controlID, position, rotation, size, et);
}
private static void FindSelectedHandle(int[] controlIds, Tracking.Bone[] boneIds, ref int boneIndex) {
for (int i = 0; i < controlIds.Length; i++) {
if (controlIds[i] != 0 && controlIds[i] == GUIUtility.hotControl) {
boneIndex = i;
return;
}
}
return;
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5ff8acba029085e498aca5aa403685d5
timeCreated: 1515774608
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,35 @@
#if UNITY_EDITOR
using System;
using System.Runtime.InteropServices;
using UnityEditor;
using UnityEngine;
namespace Passer {
using Humanoid;
using Humanoid.Tracking;
using Passer.Tracking;
[InitializeOnLoad]
public class HumanoidConfiguration : MonoBehaviour {
static HumanoidConfiguration() {
//Configuration_Editor.GlobalDefine("pHUMANOID");
#if hLEAP
LeapDevice.LoadDlls();
#endif
#if hORBBEC
AstraDevice.LoadDlls();
#endif
#if hNEURON
NeuronDevice.LoadDlls();
#endif
}
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string dllToLoad);
// Have we loaded the prefs yet
public static Configuration configuration;
}
}
#endif

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 336932db5f7f6174ea2950adf102b57b
timeCreated: 1534854134
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,605 @@
using UnityEditor;
using UnityEngine;
namespace Passer {
using Humanoid;
[CanEditMultipleObjects]
[CustomEditor(typeof(FootTarget), true)]
public class FootTarget_Editor : Editor {
private FootTarget footTarget;
private HumanoidControl humanoid;
private TargetProps[] allProps;
#region Enable
public void OnEnable() {
footTarget = (FootTarget)target;
if (footTarget.humanoid == null)
footTarget.humanoid = GetHumanoid(footTarget);
humanoid = footTarget.humanoid;
if (humanoid == null)
return;
InitEditors();
footTarget.InitSensors();
InitConfiguration(footTarget);
InitSettings();
InitEvents();
}
private void InitEditors() {
allProps = new TargetProps[] {
#if hOPENVR && hVIVETRACKER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
new ViveTracker_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hKINECT1
new Kinect1_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hKINECT2
new Kinect2_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hKINECT4
new Kinect4_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hORBBEC
new Astra_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hNEURON
new Neuron_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hOPTITRACK
new Optitrack_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hANTILATENCY
new Antilatency_Editor.FootTargetProps(serializedObject, footTarget),
#endif
#if hCUSTOM
new Custom_Editor.FootTargetProps(serializedObject, footTarget),
#endif
};
}
#endregion
#region Disable
public void OnDisable() {
if (humanoid == null) {
// This target is not connected to a humanoid, so we delete it
DestroyImmediate(footTarget, true);
return;
}
if (!Application.isPlaying) {
SetSensor2Target();
}
}
private void SetSensor2Target() {
foreach (TargetProps props in allProps)
props.SetSensor2Target();
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
if (footTarget == null || humanoid == null)
return;
serializedObject.Update();
ControllerInspectors(footTarget);
ConfigurationInspector(footTarget);
SettingsInspector(footTarget);
EventsInspector();
serializedObject.ApplyModifiedProperties();
UpdateBones(footTarget);
}
public static FootTarget Inspector(FootTarget footTarget, string name) {
if (footTarget == null)
return footTarget;
EditorGUILayout.BeginHorizontal();
Transform defaultTargetTransform = footTarget.GetDefaultTarget(footTarget.humanoid);
Transform targetTransform = footTarget.transform ?? defaultTargetTransform;
GUIContent text = new GUIContent(
name,
"The transform controlling the " + name
);
targetTransform = (Transform)EditorGUILayout.ObjectField(text, targetTransform, typeof(Transform), true);
if (!Application.isPlaying) {
if (targetTransform == defaultTargetTransform && GUILayout.Button("Show", GUILayout.MaxWidth(60))) {
// Call static method CreateTarget on target
footTarget = (FootTarget)footTarget.GetType().GetMethod("CreateTarget").Invoke(null, new object[] { footTarget });
}
else if (targetTransform != footTarget.transform) {
footTarget = (FootTarget)footTarget.GetType().GetMethod("SetTarget").Invoke(null, new object[] { footTarget.humanoid, targetTransform, footTarget.isLeft });
}
}
EditorGUILayout.EndHorizontal();
return footTarget;
}
public static HumanoidControl GetHumanoid(HumanoidTarget target) {
HumanoidControl foundHumanoid = target.transform.GetComponentInParent<HumanoidControl>();
if (foundHumanoid != null)
return foundHumanoid;
HumanoidControl[] humanoids = GameObject.FindObjectsOfType<HumanoidControl>();
for (int i = 0; i < humanoids.Length; i++)
if (humanoids[i].leftFootTarget.transform == target.transform ||
humanoids[i].rightFootTarget.transform == target.transform)
foundHumanoid = humanoids[i];
return foundHumanoid;
}
#region Sensors
private static bool showControllers = true;
private void ControllerInspectors(FootTarget footTarget) {
showControllers = EditorGUILayout.Foldout(showControllers, "Controllers", true);
if (showControllers) {
EditorGUI.indentLevel++;
foreach (TargetProps props in allProps)
props.Inspector();
if (humanoid.animatorEnabled)
footTarget.legAnimator.enabled = EditorGUILayout.ToggleLeft("Procedural Animation", footTarget.legAnimator.enabled, GUILayout.MinWidth(80));
EditorGUI.indentLevel--;
}
}
#endregion
#region Configuration
private void InitConfiguration(FootTarget footTarget) {
if (footTarget.humanoid.avatarRig == null)
return;
InitUpperLegConfiguration(footTarget.upperLeg);
InitLowerLegConfiguration(footTarget.lowerLeg);
InitFootConfiguration(footTarget.foot);
InitToesConfiguration(footTarget.toes);
}
private static bool showConfiguration;
private void ConfigurationInspector(FootTarget footTarget) {
//if (!target.jointLimitations)
// return;
footTarget.RetrieveBones();
showConfiguration = EditorGUILayout.Foldout(showConfiguration, "Configuration", true);
if (showConfiguration) {
EditorGUI.indentLevel++;
UpperLegConfigurationInspector(ref footTarget.upperLeg, footTarget.isLeft);
LowerLegConfigurationInspector(ref footTarget.lowerLeg, footTarget.isLeft);
FootConfigurationInspector(ref footTarget.foot, footTarget.isLeft);
ToesConfigurationInspector(ref footTarget.toes, footTarget.isLeft);
EditorGUI.indentLevel--;
}
}
private void UpdateBones(FootTarget target) {
if (target.humanoid.avatarRig == null)
return;
UpdateUpperLegBones(target.upperLeg);
UpdateLowerLegBones(target.lowerLeg);
UpdateFootBones(target.foot);
UpdateToesBones(target.toes);
}
#region UpperLeg
//private string upperLegXname;
//private SerializedProperty upperLegMinX;
//private SerializedProperty upperLegMaxX;
//private string upperLegYname;
//private SerializedProperty upperLegMinY;
//private SerializedProperty upperLegMaxY;
//private string upperLegZname;
//private SerializedProperty upperLegMinZ;
//private SerializedProperty upperLegMaxZ;
private void InitUpperLegConfiguration(FootTarget.TargetedUpperLegBone upperLeg) {
//if (upperLeg.bone.transform == null)
// return;
//upperLegXname = upperLeg.bone.transform.name + "X";
//upperLegMinX = serializedObject.FindProperty("upperLeg.bone.minAngles.x");
//upperLegMaxX = serializedObject.FindProperty("upperLeg.bone.maxAngles.x");
//upperLegYname = upperLeg.bone.transform.name + "Y";
//upperLegMinY = serializedObject.FindProperty("upperLeg.bone.minAngles.y");
//upperLegMaxY = serializedObject.FindProperty("upperLeg.bone.maxAngles.y");
//upperLegZname = upperLeg.bone.transform.name + "Z";
//upperLegMinZ = serializedObject.FindProperty("upperLeg.bone.minAngles.z");
//upperLegMaxZ = serializedObject.FindProperty("upperLeg.bone.maxAngles.z");
}
private void UpperLegConfigurationInspector(ref FootTarget.TargetedUpperLegBone upperLeg, bool isLeft) {
if (upperLeg.bone.transform != null)
GUI.SetNextControlName(upperLeg.bone.transform.name + "00");
upperLeg.bone.transform = (Transform)EditorGUILayout.ObjectField("Upper Leg Bone", upperLeg.bone.transform, typeof(Transform), true);
if (upperLeg.bone.transform != null) {
EditorGUI.indentLevel++;
upperLeg.bone.jointLimitations = EditorGUILayout.Toggle("Joint Limitations", upperLeg.bone.jointLimitations);
if (upperLeg.bone.jointLimitations) {
upperLeg.bone.maxAngle = EditorGUILayout.Slider("Max Angle", upperLeg.bone.maxAngle, 0, 180);
}
//EditorGUILayout.BeginHorizontal();
//upperLeg.bone.maxAngle = EditorGUILayout.Slider("Max Angle", upperLeg.bone.maxAngle, 0, 180);
//if (GUILayout.Button("R", GUILayout.Width(20))) {
// upperLeg.bone.maxAngle = FootTarget.maxUpperLegAngle;
//}
//EditorGUILayout.EndHorizontal();
//if (isLeft) {
// Target_Editor.BoneAngleInspector(upperLegMinX, upperLegMaxX, FootTarget.minLeftUpperLegAngles.x, FootTarget.maxLeftUpperLegAngles.x, upperLegXname, "X Limits");
// Target_Editor.BoneAngleInspector(upperLegMinY, upperLegMaxY, FootTarget.minLeftUpperLegAngles.y, FootTarget.maxLeftUpperLegAngles.y, upperLegYname, "Y Limits");
// Target_Editor.BoneAngleInspector(upperLegMinZ, upperLegMaxZ, FootTarget.minLeftUpperLegAngles.z, FootTarget.maxLeftUpperLegAngles.z, upperLegZname, "Z Limits");
//} else {
// Target_Editor.BoneAngleInspector(upperLegMinX, upperLegMaxX, FootTarget.minRightUpperLegAngles.x, FootTarget.maxRightUpperLegAngles.x, upperLegXname, "X Limits");
// Target_Editor.BoneAngleInspector(upperLegMinY, upperLegMaxY, FootTarget.minRightUpperLegAngles.y, FootTarget.maxRightUpperLegAngles.y, upperLegYname, "Y Limits");
// Target_Editor.BoneAngleInspector(upperLegMinZ, upperLegMaxZ, FootTarget.minRightUpperLegAngles.z, FootTarget.maxRightUpperLegAngles.z, upperLegZname, "Z Limits");
//}
EditorGUI.indentLevel--;
}
}
private void UpdateUpperLegBones(FootTarget.TargetedUpperLegBone upperLeg) {
//if (upperLeg.bone.transform == null)
// return;
//upperLeg.bone.minAngles.x = upperLegMinX.floatValue;
//upperLeg.bone.maxAngles.x = upperLegMaxX.floatValue;
//upperLeg.bone.minAngles.y = upperLegMinY.floatValue;
//upperLeg.bone.maxAngles.y = upperLegMaxY.floatValue;
//upperLeg.bone.minAngles.z = upperLegMinZ.floatValue;
//upperLeg.bone.maxAngles.z = upperLegMaxZ.floatValue;
}
#endregion
#region LowerLeg
//private string lowerLegYname;
//private SerializedProperty lowerLegMinX;
//private SerializedProperty lowerLegMaxX;
private void InitLowerLegConfiguration(FootTarget.TargetedLowerLegBone lowerLeg) {
//if (lowerLeg.bone.transform == null)
// return;
//lowerLegYname = lowerLeg.bone.transform.name + "X";
//lowerLegMinX = serializedObject.FindProperty("lowerLeg.bone.minAngles.x");
//lowerLegMaxX = serializedObject.FindProperty("lowerLeg.bone.maxAngles.x");
}
private void LowerLegConfigurationInspector(ref FootTarget.TargetedLowerLegBone lowerLeg, bool isLeft) {
if (lowerLeg.bone.transform != null)
GUI.SetNextControlName(lowerLeg.bone.transform.name + "00");
lowerLeg.bone.transform = (Transform)EditorGUILayout.ObjectField("Lower Leg Bone", lowerLeg.bone.transform, typeof(Transform), true);
if (lowerLeg.bone.transform != null) {
EditorGUI.indentLevel++;
lowerLeg.bone.jointLimitations = EditorGUILayout.Toggle("Joint Limitations", lowerLeg.bone.jointLimitations);
if (lowerLeg.bone.jointLimitations) {
lowerLeg.bone.maxAngle = EditorGUILayout.Slider("Max Angle", lowerLeg.bone.maxAngle, 0, 180);
}
//EditorGUILayout.BeginHorizontal();
//lowerLeg.bone.maxAngle = EditorGUILayout.Slider("Max Angle", lowerLeg.bone.maxAngle, 0, 180);
//if (GUILayout.Button("R", GUILayout.Width(20))) {
// lowerLeg.bone.maxAngle = FootTarget.maxLowerLegAngle;
//}
//EditorGUILayout.EndHorizontal();
//if (isLeft)
// Target_Editor.BoneAngleInspector(lowerLegMinX, lowerLegMaxX, FootTarget.minLeftLowerLegAngles.x, FootTarget.maxLeftLowerLegAngles.x, lowerLegYname, "X Limits");
//else
// Target_Editor.BoneAngleInspector(lowerLegMinX, lowerLegMaxX, FootTarget.minRightLowerLegAngles.x, FootTarget.maxRightLowerLegAngles.x, lowerLegYname, "X Limits");
EditorGUI.indentLevel--;
}
}
private void UpdateLowerLegBones(FootTarget.TargetedLowerLegBone lowerLeg) {
//if (lowerLeg.bone.transform == null)
// return;
//lowerLeg.bone.minAngles.x = lowerLegMinX.floatValue;
//lowerLeg.bone.maxAngles.x = lowerLegMaxX.floatValue;
}
#endregion
#region Foot
//private string footXname;
//private SerializedProperty footMinX;
//private SerializedProperty footMaxX;
//private string footZname;
//private SerializedProperty footMinZ;
//private SerializedProperty footMaxZ;
private void InitFootConfiguration(FootTarget.TargetedFootBone foot) {
//if (foot.bone.transform == null)
// return;
//footXname = foot.bone.transform.name + "X";
//footMinX = serializedObject.FindProperty("foot.bone.minAngles.x");
//footMaxX = serializedObject.FindProperty("foot.bone.maxAngles.x");
//footZname = foot.bone.transform.name + "Z";
//footMinZ = serializedObject.FindProperty("foot.bone.minAngles.z");
//footMaxZ = serializedObject.FindProperty("foot.bone.maxAngles.z");
}
private void FootConfigurationInspector(ref FootTarget.TargetedFootBone foot, bool isLeft) {
if (foot.bone.transform != null)
GUI.SetNextControlName(foot.bone.transform.name + "00");
foot.bone.transform = (Transform)EditorGUILayout.ObjectField("Foot Bone", foot.bone.transform, typeof(Transform), true);
if (foot.bone.transform != null) {
EditorGUI.indentLevel++;
foot.bone.jointLimitations = EditorGUILayout.Toggle("Joint Limitations", foot.bone.jointLimitations);
if (foot.bone.jointLimitations) {
foot.bone.maxAngle = EditorGUILayout.Slider("Max Angle", foot.bone.maxAngle, 0, 180);
}
//EditorGUILayout.BeginHorizontal();
//foot.bone.maxAngle = EditorGUILayout.Slider("Max Angle", foot.bone.maxAngle, 0, 180);
//if (GUILayout.Button("R", GUILayout.Width(20))) {
// foot.bone.maxAngle = FootTarget.maxFootAngle;
//}
//EditorGUILayout.EndHorizontal();
//if (isLeft) {
// Target_Editor.BoneAngleInspector(footMinX, footMaxX, FootTarget.minLeftFootAngles.x, FootTarget.maxLeftFootAngles.x, footXname, "X Limits");
// Target_Editor.BoneAngleInspector(footMinZ, footMaxZ, FootTarget.minLeftFootAngles.z, FootTarget.maxLeftFootAngles.z, footZname, "Z Limits");
//} else {
// Target_Editor.BoneAngleInspector(footMinX, footMaxX, FootTarget.minRightFootAngles.x, FootTarget.maxRightFootAngles.x, footXname, "X Limits");
// Target_Editor.BoneAngleInspector(footMinZ, footMaxZ, FootTarget.minRightFootAngles.z, FootTarget.maxRightFootAngles.z, footZname, "Z Limtis");
//}
EditorGUI.indentLevel--;
}
}
private void UpdateFootBones(FootTarget.TargetedFootBone foot) {
//if (foot.bone.transform == null)
// return;
//foot.bone.minAngles.x = footMinX.floatValue;
//foot.bone.maxAngles.x = footMaxX.floatValue;
//foot.bone.minAngles.z = footMinZ.floatValue;
//foot.bone.maxAngles.z = footMaxZ.floatValue;
}
#endregion
#region Toes
//private string toesXname;
//private SerializedProperty toesMinX;
//private SerializedProperty toesMaxX;
private void InitToesConfiguration(FootTarget.TargetedToesBone toes) {
//if (toes.bone.transform == null)
// return;
//toesXname = toes.bone.transform.name + "X";
//toesMinX = serializedObject.FindProperty("toes.bone.minAngles.x");
//toesMaxX = serializedObject.FindProperty("toes.bone.maxAngles.x");
}
private void ToesConfigurationInspector(ref FootTarget.TargetedToesBone toes, bool isLeft) {
if (toes.bone.transform != null)
GUI.SetNextControlName(toes.bone.transform.name + "00");
toes.bone.transform = (Transform)EditorGUILayout.ObjectField("Toes Bone", toes.bone.transform, typeof(Transform), true);
if (toes.bone.transform != null) {
EditorGUI.indentLevel++;
toes.bone.jointLimitations = EditorGUILayout.Toggle("Joint Limitations", toes.bone.jointLimitations);
if (toes.bone.jointLimitations) {
toes.bone.maxAngle = EditorGUILayout.Slider("Max Angle", toes.bone.maxAngle, 0, 180);
}
//EditorGUILayout.BeginHorizontal();
//toes.bone.maxAngle = EditorGUILayout.Slider("Max Angle", toes.bone.maxAngle, 0, 180);
//if (GUILayout.Button("R", GUILayout.Width(20))) {
// toes.bone.maxAngle = FootTarget.maxToesAngle;
//}
//EditorGUILayout.EndHorizontal();
//if (isLeft)
// Target_Editor.BoneAngleInspector(toesMinX, toesMaxX, FootTarget.minLeftToesAngles.x, FootTarget.maxLeftToesAngles.x, toesXname, "X Limits");
//else
// Target_Editor.BoneAngleInspector(toesMinX, toesMaxX, FootTarget.minRightToesAngles.x, FootTarget.maxRightToesAngles.x, toesXname, "X Limits");
EditorGUI.indentLevel--;
}
}
private void UpdateToesBones(FootTarget.TargetedToesBone toes) {
//if (toes.bone.transform == null)
// return;
//toes.bone.minAngles.x = toesMinX.floatValue;
//toes.bone.maxAngles.x = toesMaxX.floatValue;
}
#endregion
#endregion
#region Settings
private SerializedProperty rotationSpeedLimitationProp;
private SerializedProperty slidePreventionProp;
private void InitSettings() {
rotationSpeedLimitationProp = serializedObject.FindProperty("rotationSpeedLimitation");
slidePreventionProp = serializedObject.FindProperty("slidePrevention");
}
private static bool showSettings;
private void SettingsInspector(FootTarget footTarget) {
showSettings = EditorGUILayout.Foldout(showSettings, "Settings", true);
if (showSettings) {
EditorGUI.indentLevel++;
//footTarget.jointLimitations = EditorGUILayout.Toggle("Joint Limitations", footTarget.jointLimitations);
bool showRealObjects = EditorGUILayout.Toggle("Show Real Objects", footTarget.showRealObjects);
if (showRealObjects != footTarget.showRealObjects) {
footTarget.ShowControllers(showRealObjects);
footTarget.showRealObjects = showRealObjects;
}
rotationSpeedLimitationProp.boolValue = EditorGUILayout.Toggle("Rotation Speed Limitation", rotationSpeedLimitationProp.boolValue);
slidePreventionProp.boolValue = EditorGUILayout.Toggle("Slide Prevention", slidePreventionProp.boolValue);
EditorGUI.indentLevel--;
}
}
#endregion
#region Events
protected SerializedProperty groundEventProp;
protected virtual void InitEvents() {
groundEventProp = serializedObject.FindProperty("groundEvent");
}
protected int selectedEventSource = -1;
protected int selectedEvent;
protected bool showEvents;
protected virtual void EventsInspector() {
showEvents = EditorGUILayout.Foldout(showEvents, "Events", true);
if (showEvents) {
EditorGUI.indentLevel++;
GameObjectEvent_Editor.EventInspector(groundEventProp, footTarget.groundEvent, ref selectedEventSource, ref selectedEvent);
//EditorGUILayout.BeginHorizontal();
////Labels
//EditorGUILayout.BeginVertical(GUILayout.MinWidth(110));
//GUILayout.Space(3);
//EditorGUILayout.LabelField("Ground", GUILayout.Width(110));
//EditorGUILayout.EndVertical();
//// Buttons
//string[] buttonTexts = new string[1];
//buttonTexts[0] = Event.GetInputButtonLabel(footTarget.groundEvent.gameObjectEvent);
//int oldFontSize = GUI.skin.button.fontSize;
//GUI.skin.button.fontSize = 9;
//selectedEventSource = GUILayout.SelectionGrid(selectedEventSource, buttonTexts, 1);
//GUI.skin.button.fontSize = oldFontSize;
//EditorGUILayout.EndHorizontal();
//// Details
//GUIStyle style = new GUIStyle(GUI.skin.label) {
// fontStyle = FontStyle.Bold
//};
//EditorGUILayout.LabelField("Details", style, GUILayout.ExpandWidth(true));
//EditorGUI.indentLevel++;
//EventDetails(selectedEventSource);
//EditorGUI.indentLevel--;
EditorGUI.indentLevel--;
}
}
//protected void EventDetails(int selectedInputEvent) {
// switch (selectedInputEvent) {
// case 0:
// GameObjectEvent_Editor.DetailsInspector(groundEventProp, "Ground");
// break;
// }
//}
#endregion
#endregion
#region Scene
public void OnSceneGUI() {
if (footTarget == null || humanoid == null)
return;
if (Application.isPlaying)
return;
if (humanoid.pose != null) {
if (humanoid.editPose)
humanoid.pose.UpdatePose(humanoid);
else {
humanoid.pose.Show(humanoid);
footTarget.CopyRigToTarget();
}
}
// update the target rig from the current foot target
footTarget.CopyTargetToRig();
// update the avatar bones from the target rig
humanoid.UpdateMovements();
// match the target rig with the new avatar pose
humanoid.MatchTargetsToAvatar();
// and update all target to match the target rig
humanoid.CopyRigToTargets();
// Update the sensors to match the updated targets
humanoid.UpdateSensorsFromTargets();
}
#endregion
public abstract class TargetProps {
public SerializedProperty enabledProp;
public SerializedProperty sensorTransformProp;
public SerializedProperty sensor2TargetPositionProp;
public SerializedProperty sensor2TargetRotationProp;
public FootTarget footTarget;
public LegSensor sensor;
public TargetProps(SerializedObject serializedObject, LegSensor _sensor, FootTarget _footTarget, string unitySensorName) {
enabledProp = serializedObject.FindProperty(unitySensorName + ".enabled");
sensorTransformProp = serializedObject.FindProperty(unitySensorName + ".sensorTransform");
sensor2TargetPositionProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetPosition");
sensor2TargetRotationProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetRotation");
footTarget = _footTarget;
sensor = _sensor;
sensor.Init(footTarget);
}
public virtual void SetSensor2Target() {
if (sensor.sensorTransform == null)
return;
sensor2TargetRotationProp.quaternionValue = Quaternion.Inverse(sensor.sensorTransform.rotation) * footTarget.foot.target.transform.rotation;
sensor2TargetPositionProp.vector3Value = -footTarget.foot.target.transform.InverseTransformPoint(sensor.sensorTransform.position);
}
public abstract void Inspector();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0874824509b87a747a5b7fc51126d0e1
timeCreated: 1462298140
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,759 @@
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
using Tracking;
[CanEditMultipleObjects]
[CustomEditor(typeof(HandTarget), true)]
public class HandTarget_Editor : Editor {
private HandTarget handTarget;
private Passer.Humanoid.HumanoidControl humanoid;
private TargetProps[] allProps;
#region Enable
public void OnEnable() {
handTarget = (HandTarget)target;
if (handTarget.humanoid == null)
handTarget.humanoid = GetHumanoid(handTarget);
humanoid = handTarget.humanoid;
if (humanoid == null)
return;
humanoid.InitTargets();
InitEditors();
handTarget.InitTarget();
InitConfiguration(handTarget);
InitSettings();
InitEvents();
InitHandPose(handTarget);
if (!Application.isPlaying)
SetSensor2Target();
}
private void InitEditors() {
allProps = new TargetProps[] {
#if pUNITYXR
new UnityXR_Editor.HandTargetProps(serializedObject, handTarget),
#endif
//#if hOPENVR && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
// new OpenVR_Editor.HandTargetProps(serializedObject, handTarget),
//#if hVIVETRACKER
// new ViveTracker_Editor.HandTargetProps(serializedObject, handTarget),
//#endif
//#endif
#if hSTEAMVR && UNITY_STANDALONE_WIN
//new SteamVR_Editor.HandTargetProps(serializedObject, handTarget),
#if hVIVETRACKER
//new ViveTracker_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#endif
//#if hOCULUS && (UNITY_STANDALONE_WIN || UNITY_ANDROID)
// new Oculus_Editor.HandTargetProps(serializedObject, handTarget),
//#endif
#if hWINDOWSMR && UNITY_WSA_10_0
new WindowsMR_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hWAVEVR
new WaveVR_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hVRTK
new Vrtk_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hLEAP
new LeapMotion_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hHYDRA
new Hydra_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hKINECT1
new Kinect1_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hKINECT2
new Kinect2_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hKINECT4
new Kinect4_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hORBBEC
new Astra_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hNEURON
new Neuron_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hOPTITRACK
new Optitrack_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hANTILATENCY
new Antilatency_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hHI5
new Hi5_Editor.HandTargetProps(serializedObject, handTarget),
#endif
#if hCUSTOM
new Custom_Editor.HandTargetProps(serializedObject, handTarget),
#endif
};
}
#endregion
#region Disable
public void OnDisable() {
if (humanoid == null) {
// This target is not connected to a humanoid, so we delete it
DestroyImmediate(handTarget, true);
return;
}
if (!Application.isPlaying) {
SetSensor2Target();
}
handTarget.poseMixer.Cleanup();
if (!Application.isPlaying)
handTarget.poseMixer.ShowPose(humanoid, handTarget.isLeft ? Side.Left : Side.Right);
handTarget.UpdateMovements(humanoid);
}
private void SetSensor2Target() {
foreach (TargetProps props in allProps)
props.SetSensor2Target();
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
if (handTarget == null || humanoid == null)
return;
serializedObject.Update();
ControllerInspectors(handTarget);
if (humanoid != null) {
SubTargetsInspector(handTarget);
ConfigurationInspector(handTarget);
serializedObject.ApplyModifiedProperties();
HandPoseInspector(handTarget);
serializedObject.Update();
}
SettingsInspector(handTarget);
TouchedObjectInspector(handTarget);
GrabbedObjectInspector(handTarget);
EventsInspector();
InteractionPointerButton(handTarget);
serializedObject.ApplyModifiedProperties();
//serializedObject.Update();
//serializedObject.ApplyModifiedProperties();
}
public static HandTarget Inspector(HandTarget handTarget, string name) {
if (handTarget == null)
return handTarget;
EditorGUILayout.BeginHorizontal();
Transform defaultTargetTransform = handTarget.GetDefaultTarget(handTarget.humanoid);
Transform targetTransform = handTarget.transform ?? defaultTargetTransform;
GUIContent text = new GUIContent(
name,
"The transform controlling the " + name
);
targetTransform = (Transform)EditorGUILayout.ObjectField(text, targetTransform, typeof(Transform), true);
if (!Application.isPlaying) {
if (targetTransform == defaultTargetTransform && GUILayout.Button("Show", GUILayout.MaxWidth(60))) {
// Call static method CreateTarget on target
handTarget = (HandTarget)handTarget.GetType().GetMethod("CreateTarget").Invoke(null, new object[] { handTarget });
}
else if (targetTransform != handTarget.transform) {
handTarget = (HandTarget)handTarget.GetType().GetMethod("SetTarget").Invoke(null, new object[] { handTarget.humanoid, targetTransform, handTarget.isLeft });
}
}
EditorGUILayout.EndHorizontal();
return handTarget;
}
public static HumanoidControl GetHumanoid(HumanoidTarget target) {
HumanoidControl foundHumanoid = target.transform.GetComponentInParent<HumanoidControl>();
if (foundHumanoid != null)
return foundHumanoid;
HumanoidControl[] humanoids = GameObject.FindObjectsOfType<HumanoidControl>();
for (int i = 0; i < humanoids.Length; i++)
if (humanoids[i].leftHandTarget.transform == target.transform ||
humanoids[i].rightHandTarget.transform == target.transform)
foundHumanoid = humanoids[i];
return foundHumanoid;
}
#region Sensors
public bool showControllers = true;
private void ControllerInspectors(HandTarget handTarget) {
showControllers = EditorGUILayout.Foldout(showControllers, "Sensors/Controllers", true);
if (showControllers) {
EditorGUI.indentLevel++;
foreach (TargetProps props in allProps)
props.Inspector();
if (humanoid != null && humanoid.animatorEnabled)
handTarget.armAnimator.enabled = EditorGUILayout.ToggleLeft("Procedural animation", handTarget.armAnimator.enabled, GUILayout.MinWidth(80));
EditorGUI.indentLevel--;
}
}
#endregion
#region Morph Targets
//float thumbCurl = 0;
private bool showSubTargets;
private void SubTargetsInspector(HandTarget handTarget) {
showSubTargets = EditorGUILayout.Foldout(showSubTargets, "Sub Targets", true);
if (showSubTargets) {
EditorGUI.indentLevel++;
EditorGUI.BeginDisabledGroup(true);
float thumbCurl = handTarget.fingers.thumb.CalculateCurl();
EditorGUILayout.Slider("Thumb Curl", thumbCurl, -0.5F, 1);
float indexCurl = handTarget.fingers.index.CalculateCurl();
EditorGUILayout.Slider("Index Finger Curl", indexCurl, -0.1F, 1);
float middleCurl = handTarget.fingers.middle.CalculateCurl();
EditorGUILayout.Slider("Middle Finger Curl", middleCurl, -0.1F, 1);
float ringCurl = handTarget.fingers.ring.CalculateCurl();
EditorGUILayout.Slider("Ring Finger Curl", ringCurl, -0.1F, 1);
float littleCurl = handTarget.fingers.little.CalculateCurl();
EditorGUILayout.Slider("Little Finger Curl", littleCurl, -0.1F, 1);
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel--;
}
}
#endregion
#region Configuration
private void InitConfiguration(HandTarget handTarget) {
InitShoulderConfiguration(handTarget.shoulder);
InitUpperArmConfiguration(handTarget.upperArm);
InitForearmConfiguration(handTarget.forearm);
InitHandConfiguration(handTarget.hand);
}
private bool showConfiguration;
private bool showFingerConfiguration;
private void ConfigurationInspector(HandTarget handTarget) {
//if (!target.jointLimitations)
//return;
//handTarget.RetrieveBones();
showConfiguration = EditorGUILayout.Foldout(showConfiguration, "Configuration", true);
if (showConfiguration) {
EditorGUI.indentLevel++;
ShoulderConfigurationInspector(ref handTarget.shoulder, handTarget.isLeft);
UpperArmConfigurationInspector(ref handTarget.upperArm, handTarget.isLeft);
ForearmConfigurationInspector(ref handTarget.forearm, handTarget.isLeft);
HandConfigurationInspector(ref handTarget.hand, handTarget.isLeft);
showFingerConfiguration = EditorGUILayout.Foldout(showFingerConfiguration, "Fingers", true);
if (showFingerConfiguration) {
EditorGUI.indentLevel++;
FingersConfigurationInspector(handTarget);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
}
#region Shoulder
private SerializedProperty shoulderArmJointLimitations;
private SerializedProperty shoulderArmLimitationAngle;
private void InitShoulderConfiguration(HandTarget.TargetedShoulderBone shoulder) {
shoulderArmJointLimitations = serializedObject.FindProperty("shoulder.bone.jointLimitations");
shoulderArmLimitationAngle = serializedObject.FindProperty("shoulder.bone.maxAngle");
}
private void ShoulderConfigurationInspector(ref HandTarget.TargetedShoulderBone shoulder, bool isLeft) {
if (shoulder.bone.transform != null)
GUI.SetNextControlName(shoulder.bone.transform.name + "00");
shoulder.bone.transform = (Transform)EditorGUILayout.ObjectField("Shoulder Bone", shoulder.bone.transform, typeof(Transform), true);
if (shoulder.bone.transform != null) {
EditorGUI.indentLevel++;
shoulderArmJointLimitations.boolValue = EditorGUILayout.Toggle("Joint Limitations", shoulder.bone.jointLimitations);
if (shoulder.bone.jointLimitations) {
shoulderArmLimitationAngle.floatValue = EditorGUILayout.Slider("Max Angle", shoulder.bone.maxAngle, 0, 180);
}
EditorGUI.indentLevel--;
}
}
private void UpdateShoulderBones(HandTarget.TargetedShoulderBone shoulder) {
}
#endregion
#region UpperArm
private SerializedProperty upperArmJointLimitations;
private SerializedProperty upperArmLimitationAngle;
private void InitUpperArmConfiguration(HandTarget.TargetedUpperArmBone upperArm) {
upperArmJointLimitations = serializedObject.FindProperty("upperArm.bone.jointLimitations");
upperArmLimitationAngle = serializedObject.FindProperty("upperArm.bone.maxAngle");
}
private void UpperArmConfigurationInspector(ref HandTarget.TargetedUpperArmBone upperArm, bool isLeft) {
if (upperArm.bone.transform != null)
GUI.SetNextControlName(upperArm.bone.transform.name + "00");
upperArm.bone.transform = (Transform)EditorGUILayout.ObjectField("Upper Arm Bone", upperArm.bone.transform, typeof(Transform), true);
if (upperArm.bone.transform != null) {
EditorGUI.indentLevel++;
upperArmJointLimitations.boolValue = EditorGUILayout.Toggle("Joint Limitations", upperArm.bone.jointLimitations);
if (upperArm.bone.jointLimitations) {
upperArmLimitationAngle.floatValue = EditorGUILayout.Slider("Max Angle", upperArm.bone.maxAngle, 0, 180);
}
EditorGUI.indentLevel--;
}
}
private void UpdateUpperArmBones(HandTarget.TargetedUpperArmBone upperArm) {
}
#endregion
#region Forearm
private SerializedProperty forearmJointLimitations;
private SerializedProperty forearmLimitationAngle;
private void InitForearmConfiguration(HandTarget.TargetedForearmBone forearm) {
forearmJointLimitations = serializedObject.FindProperty("forearm.bone.jointLimitations");
forearmLimitationAngle = serializedObject.FindProperty("forearm.bone.maxAngle");
}
private void ForearmConfigurationInspector(ref HandTarget.TargetedForearmBone forearm, bool isLeft) {
if (forearm.bone.transform != null)
GUI.SetNextControlName(forearm.bone.transform.name + "00");
forearm.bone.transform = (Transform)EditorGUILayout.ObjectField("Forearm Bone", forearm.bone.transform, typeof(Transform), true);
if (forearm.bone.transform != null) {
EditorGUI.indentLevel++;
forearmJointLimitations.boolValue = EditorGUILayout.Toggle("Joint Limitations", forearm.bone.jointLimitations);
if (forearm.bone.jointLimitations) {
forearmLimitationAngle.floatValue = EditorGUILayout.Slider("Max Angle", forearm.bone.maxAngle, 0, 180);
}
EditorGUI.indentLevel--;
}
}
private void UpdateForearmBones(HandTarget.TargetedForearmBone forearm) {
}
#endregion
#region Hand
private SerializedProperty handJointLimitations;
private SerializedProperty handLimitationAngle;
private void InitHandConfiguration(HandTarget.TargetedHandBone hand) {
handJointLimitations = serializedObject.FindProperty("hand.bone.jointLimitations");
handLimitationAngle = serializedObject.FindProperty("hand.bone.maxAngle");
}
private void HandConfigurationInspector(ref HandTarget.TargetedHandBone hand, bool isLeft) {
hand.bone.transform = (Transform)EditorGUILayout.ObjectField("Hand Bone", hand.bone.transform, typeof(Transform), true);
if (hand.bone.transform != null) {
EditorGUI.indentLevel++;
handJointLimitations.boolValue = EditorGUILayout.Toggle("Joint Limitations", hand.bone.jointLimitations);
if (hand.bone.jointLimitations) {
handLimitationAngle.floatValue = EditorGUILayout.Slider("Max Angle", hand.bone.maxAngle, 0, 180);
}
EditorGUI.indentLevel--;
}
}
#endregion
#region Fingers
SerializedProperty proximalMinX;
SerializedProperty proximalMaxX;
private void InitFingerConfiguration(FingersTarget fingers) {
}
private void FingersConfigurationInspector(HandTarget handTarget) {
FingerConfigurationInspector(handTarget, handTarget.fingers.thumb, 0, "Proximal Thumb Bone");
FingerConfigurationInspector(handTarget, handTarget.fingers.index, 1, "Proximal Index Bone");
FingerConfigurationInspector(handTarget, handTarget.fingers.middle, 2, "Proximal Middle Bone");
FingerConfigurationInspector(handTarget, handTarget.fingers.ring, 3, "Proximal Ring Bone");
FingerConfigurationInspector(handTarget, handTarget.fingers.little, 4, "Proximal Little Bone");
}
private void FingerConfigurationInspector(HandTarget handTarget, FingersTarget.TargetedFinger digit, int fingerIndex, string label) {
Transform proximalBone = (Transform)EditorGUILayout.ObjectField(label, digit.proximal.bone.transform, typeof(Transform), true);
if (proximalBone == null || proximalBone != digit.proximal.bone.transform) {
if (proximalBone == null)
proximalBone = FingersTarget.GetFingerBone(handTarget, (Finger)fingerIndex, Humanoid.Tracking.FingerBones.Proximal);
if (proximalBone != null && proximalBone.childCount == 1) {
digit.intermediate.bone.transform = proximalBone.GetChild(0);
if (digit.intermediate.bone.transform != null && digit.intermediate.bone.transform.childCount == 1)
digit.distal.bone.transform = digit.intermediate.bone.transform.GetChild(0);
else
digit.distal.bone.transform = null;
}
else
digit.intermediate.bone.transform = null;
}
digit.proximal.bone.transform = proximalBone;
}
#endregion
#endregion
#region Settings
private SerializedProperty physicsProp;
private SerializedProperty rotationSpeedLimitationProp;
private SerializedProperty touchInteractionProp;
private void InitSettings() {
// Cannot use serializedPropery because showRealObjects is a getter/setter
//showRealObjectsProp = serializedObject.FindProperty("showRealObjects");
physicsProp = serializedObject.FindProperty("physics");
rotationSpeedLimitationProp = serializedObject.FindProperty("rotationSpeedLimitation");
touchInteractionProp = serializedObject.FindProperty("touchInteraction");
}
public bool showSettings;
private void SettingsInspector(HandTarget handTarget) {
showSettings = EditorGUILayout.Foldout(showSettings, "Settings", true);
if (showSettings) {
EditorGUI.indentLevel++;
// Cannot use serializedPropery because showRealObjects is a getter/setter
bool showRealObjects = EditorGUILayout.Toggle("Show Real Objects", handTarget.showRealObjects);
if (showRealObjects != handTarget.showRealObjects) {
handTarget.showRealObjects = showRealObjects;
handTarget.ShowSensors(showRealObjects, true);
}
rotationSpeedLimitationProp.boolValue = EditorGUILayout.Toggle("Rotation Speed Limitation", rotationSpeedLimitationProp.boolValue);
handTarget.rotationSpeedLimitation = rotationSpeedLimitationProp.boolValue;
touchInteractionProp.boolValue = EditorGUILayout.Toggle("Touch Interaction", touchInteractionProp.boolValue);
handTarget.touchInteraction = touchInteractionProp.boolValue;
physicsProp.boolValue = EditorGUILayout.Toggle("Physics", physicsProp.boolValue);
handTarget.physics = physicsProp.boolValue;
if (handTarget.humanoid.physics) {
handTarget.strength = EditorGUILayout.FloatField("Strength", handTarget.strength);
}
EditorGUI.indentLevel--;
}
}
#endregion
#region HandPose
public static BonePose selectedBone = null;
private string[] poseNames;
private void InitHandPose(HandTarget handTarget) {
}
private bool showHandPoses = false;
private void HandPoseInspector(HandTarget handTarget) {
EditorGUILayout.BeginHorizontal();
showHandPoses = EditorGUILayout.Foldout(showHandPoses, "Hand Pose", true);
GetPoseNames();
EditorGUILayout.BeginHorizontal(GUILayout.Width(300));
if (handTarget.poseMixer.poseMode == PoseMixer.PoseMode.Set) {
handTarget.poseMixer.poseMode = (PoseMixer.PoseMode)EditorGUILayout.EnumPopup(handTarget.poseMixer.poseMode, GUILayout.Width(100));
int poseIx = EditorGUILayout.Popup(handTarget.poseMixer.currentPoseIx, poseNames);
if (poseIx != handTarget.poseMixer.currentPoseIx) {
handTarget.poseMixer.currentPoseIx = poseIx;
handTarget.poseMixer.SetPoseValue(poseIx);
}
}
else if (Application.isPlaying) {
handTarget.poseMixer.poseMode = (PoseMixer.PoseMode)EditorGUILayout.EnumPopup(handTarget.poseMixer.poseMode, GUILayout.Width(100));
EditorGUILayout.ObjectField(handTarget.poseMixer.detectedPose, typeof(Pose), true);
}
else
handTarget.poseMixer.poseMode = (PoseMixer.PoseMode)EditorGUILayout.EnumPopup(handTarget.poseMixer.poseMode, GUILayout.MinWidth(100));
EditorGUILayout.EndHorizontal();
EditorGUILayout.EndHorizontal();
if (showHandPoses) {
EditorGUI.indentLevel++;
Pose_Editor.PoseMixerInspector(handTarget.poseMixer, humanoid, handTarget.side);
EditorGUI.indentLevel--;
}
if (!Application.isPlaying) {
handTarget.poseMixer.ShowPose(humanoid, handTarget.isLeft ? Side.Left : Side.Right);
handTarget.UpdateMovements(humanoid);
SceneView.RepaintAll();
}
}
private void GetPoseNames() {
poseNames = new string[handTarget.poseMixer.mixedPoses.Count];//.Length];
for (int i = 0; i < poseNames.Length; i++) {
if (handTarget.poseMixer.mixedPoses[i].pose == null)
poseNames[i] = "";
else
poseNames[i] = handTarget.poseMixer.mixedPoses[i].pose.name;
}
}
#endregion
#region Other
private void TouchedObjectInspector(HandTarget handTarget) {
handTarget.touchedObject = (GameObject)EditorGUILayout.ObjectField("Touched Object", handTarget.touchedObject, typeof(GameObject), true);
}
private void GrabbedObjectInspector(HandTarget handTarget) {
SerializedProperty grabbedObjectProp = serializedObject.FindProperty("grabbedObject");
if (Application.isPlaying) {
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Grabbed Object", grabbedObjectProp.objectReferenceValue, typeof(GameObject), false);
EditorGUI.EndDisabledGroup();
}
else {
SerializedProperty grabbedPrefabProp = serializedObject.FindProperty("grabbedPrefab");
GameObject grabbedPrefab = (GameObject)EditorGUILayout.ObjectField("Grabbed Prefab", grabbedPrefabProp.objectReferenceValue, typeof(GameObject), false);
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField("Grabbed Object", grabbedObjectProp.objectReferenceValue, typeof(GameObject), false);
EditorGUI.EndDisabledGroup();
if (grabbedPrefab != grabbedPrefabProp.objectReferenceValue) {
if (grabbedPrefab != null)
GrabPrefab(handTarget, grabbedObjectProp, grabbedPrefab);
else {
LetGoObject(handTarget, grabbedObjectProp);
}
}
serializedObject.Update();
grabbedPrefabProp.objectReferenceValue = grabbedPrefab;
}
}
private void GrabPrefab(HandTarget handTarget, SerializedProperty grabbedObjectProp, GameObject prefab) {
if (grabbedObjectProp.objectReferenceValue != null)
LetGoObject(handTarget, grabbedObjectProp);
GameObject obj = Instantiate(prefab, handTarget.transform.position, handTarget.transform.rotation);
//HandInteraction.NetworkedGrab(handTarget, obj, false);
handTarget.Grab(obj, false);
if (handTarget.grabbedObject == null)
Debug.LogWarning("Could not grab object");
else {
grabbedObjectProp.objectReferenceValue = obj;
Handle handle = handTarget.grabbedHandle;
if (handle == null) {
Handle.Create(obj, handTarget);
}
}
}
private void LetGoObject(HandTarget handTarget, SerializedProperty grabbedObjectProp) {
GameObject grabbedObject = (GameObject)grabbedObjectProp.objectReferenceValue;
handTarget.LetGo();
DestroyImmediate(grabbedObject, true);
grabbedObjectProp.objectReferenceValue = null;
}
#endregion
#region Events
protected SerializedProperty touchEventProp;
protected SerializedProperty grabEventProp;
protected SerializedProperty poseEventProp;
protected virtual void InitEvents() {
touchEventProp = serializedObject.FindProperty("touchEvent");
grabEventProp = serializedObject.FindProperty("grabEvent");
poseEventProp = serializedObject.FindProperty("poseEvent");
}
protected int selectedEvent = -1;
protected int selectedSubEvent;
protected bool showEvents;
protected virtual void EventsInspector() {
showEvents = EditorGUILayout.Foldout(showEvents, "Events", true);
if (showEvents) {
EditorGUI.indentLevel++;
IntEvent_Editor.EventInspector(poseEventProp, handTarget.poseEvent, ref selectedEvent, ref selectedSubEvent);
GameObjectEvent_Editor.EventInspector(touchEventProp, handTarget.touchEvent, ref selectedEvent, ref selectedSubEvent);
GameObjectEvent_Editor.EventInspector(grabEventProp, handTarget.grabEvent, ref selectedEvent, ref selectedSubEvent);
EditorGUI.indentLevel--;
}
}
#endregion
#region Buttons
private void InteractionPointerButton(HandTarget handTarget) {
InteractionPointer interactionPointer = handTarget.transform.GetComponentInChildren<InteractionPointer>();
if (interactionPointer != null)
return;
GUILayout.BeginHorizontal();
if (GUILayout.Button("Add Interaction Pointer"))
AddInteractionPointer();
if (GUILayout.Button("Add Teleporter"))
AddTeleporter();
GUILayout.EndHorizontal();
}
private void AddInteractionPointer() {
InteractionPointer pointer = InteractionPointer.Add(handTarget.transform, InteractionPointer.PointerType.Ray);
if (handTarget.isLeft) {
pointer.transform.localPosition = new Vector3(-0.21F, -0.02F, 0.01F);
pointer.transform.localRotation = Quaternion.Euler(-180, 90, 180);
}
else {
pointer.transform.localPosition = new Vector3(0.21F, -0.02F, 0.01F);
pointer.transform.localRotation = Quaternion.Euler(-180, -90, -180);
}
pointer.active = false;
ControllerInput controllerInput = humanoid.GetComponent<ControllerInput>();
if (controllerInput != null) {
controllerInput.SetEventHandler(handTarget.isLeft, ControllerInput.SideButton.Button1, pointer.Activation);
controllerInput.SetEventHandler(handTarget.isLeft, ControllerInput.SideButton.Trigger1, pointer.Click);
}
}
private void AddTeleporter() {
Teleporter teleporter = Teleporter.Add(handTarget.transform);
if (handTarget.isLeft) {
teleporter.transform.localPosition = new Vector3(-0.21F, -0.02F, 0.01F);
teleporter.transform.localRotation = Quaternion.Euler(-180, 90, 180);
}
else {
teleporter.transform.localPosition = new Vector3(0.21F, -0.02F, 0.01F);
teleporter.transform.localRotation = Quaternion.Euler(-180, -90, -180);
}
ControllerInput controllerInput = humanoid.GetComponent<ControllerInput>();
if (controllerInput != null) {
//ControllerEventHandlers button1Input = controllerInput.GetInputEvent(handTarget.isLeft, ControllerInput.SideButton.Button1);
//ControllerEvent_Editor.SetBoolMethod(controllerInput.gameObject, button1Input, EventHandler.Type.OnChange, teleporter.Activation);
//ControllerEvent_Editor.SetEventHandlerBool(button1Input, EventHandler.Type.OnChange, teleporter, "Activation");
controllerInput.SetEventHandler(handTarget.isLeft, ControllerInput.SideButton.Button1, teleporter.Activation);
//ControllerEventHandlers trigger1Input = controllerInput.GetInputEvent(handTarget.isLeft, ControllerInput.SideButton.Trigger1);
//ControllerEvent_Editor.SetBoolMethod(controllerInput.gameObject, trigger1Input, EventHandler.Type.OnChange, teleporter.Click);
//ControllerEvent_Editor.SetEventHandlerBool(trigger1Input, EventHandler.Type.OnChange, teleporter, "Click");
controllerInput.SetEventHandler(handTarget.isLeft, ControllerInput.SideButton.Trigger1, teleporter.Click);
}
}
#endregion
#endregion
#region Scene
protected void OnSceneGUI() {
HandTarget handTarget = (HandTarget)target;
if (humanoid == null)
return;
if (Application.isPlaying)
return;
Pose_Editor.UpdateScene(humanoid, handTarget.fingers, handTarget.poseMixer, ref selectedBone, handTarget.isLeft ? Side.Left : Side.Right);
handTarget.poseMixer.ShowPose(humanoid, handTarget.side);
if (humanoid.pose != null) {
if (humanoid.editPose)
humanoid.pose.UpdatePose(humanoid);
else {
humanoid.pose.Show(humanoid);
handTarget.CopyRigToTarget();
}
}
// update the target rig from the current hand target
handTarget.CopyTargetToRig();
// update the avatar bones from the target rig
humanoid.UpdateMovements();
// match the target rig with the new avatar pose
humanoid.MatchTargetsToAvatar();
// and update all targets to match the target rig
humanoid.CopyRigToTargets();
// Update the sensors to match the updated targets
humanoid.UpdateSensorsFromTargets();
}
#endregion
public abstract class TargetProps {
public SerializedProperty enabledProp;
public SerializedProperty sensorTransformProp;
public SerializedProperty sensor2TargetPositionProp;
public SerializedProperty sensor2TargetRotationProp;
public HandTarget handTarget;
public Humanoid.ArmSensor sensor;
public TargetProps(SerializedObject serializedObject, Humanoid.ArmSensor _sensor, HandTarget _handTarget, string unitySensorName) {
enabledProp = serializedObject.FindProperty(unitySensorName + ".enabled");
sensorTransformProp = serializedObject.FindProperty(unitySensorName + ".sensorTransform");
sensor2TargetPositionProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetPosition");
sensor2TargetRotationProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetRotation");
handTarget = _handTarget;
sensor = _sensor;
sensor.Init(handTarget);
}
public virtual void SetSensor2Target() {
sensor.SetSensor2Target();
}
public abstract void Inspector();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 0dd34aad8039ffd41b5585e0da454192
timeCreated: 1459000174
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,536 @@
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
[CanEditMultipleObjects]
[CustomEditor(typeof(HeadTarget), true)]
public class HeadTarget_Editor : Editor {
private HeadTarget headTarget;
private HumanoidControl humanoid;
private TargetProps[] allProps;
#region Enable
public void OnEnable() {
headTarget = (HeadTarget)target;
if (headTarget.humanoid == null)
headTarget.humanoid = GetHumanoid(headTarget);
humanoid = headTarget.humanoid;
InitEditors();
headTarget.InitSensors();
InitSensors();
#if hFACE
FaceTarget_Editor.OnEnable(serializedObject, headTarget);
#endif
}
private void InitEditors() {
allProps = new TargetProps[] {
#if pUNITYXR
new UnityXR_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hSTEAMVR && UNITY_STANDALONE_WIN
#if hVIVETRACKER
//new ViveTracker_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#endif
#if hWINDOWSMR && UNITY_WSA_10_0
new WindowsMR_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hWAVEVR
new WaveVR_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hVRTK
new Vrtk_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hREALSENSE
new Realsense_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hKINECT1
new Kinect1_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hKINECT2
new Kinect2_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hKINECT4
new Kinect4_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hORBBEC
new Astra_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hOPTITRACK
new Optitrack_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hNEURON
new Neuron_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hTOBII
new Tobii_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hARKIT
new ArKit_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hDLIB
new Dlib_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hPUPIL
new Tracking.Pupil.Pupil_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hANTILATENCY
new Antilatency_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
#if hCUSTOM
new Custom_Editor.HeadTargetProps(serializedObject, headTarget),
#endif
};
}
#endregion
#region Disable
public void OnDisable() {
if (humanoid == null) {
// This target is not connected to a humanoid, so we delete it
DestroyImmediate(headTarget, true);
return;
}
if (!Application.isPlaying) {
SetSensor2Target();
}
#if hFACE
FaceTarget_Editor.OnDisable(serializedObject, headTarget);
#endif
}
private void SetSensor2Target() {
if (allProps != null)
foreach (TargetProps props in allProps)
props.SetSensor2Target();
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
if (headTarget == null || humanoid == null)
return;
serializedObject.Update();
SensorInspectors(headTarget);
if (headTarget.humanoid != null) {
#if hFACE
SerializedProperty faceTargetProp = serializedObject.FindProperty("face");
FaceTarget_Editor.OnInspectorGUI(faceTargetProp, headTarget);
#endif
ConfigurationInspector(headTarget);
#if hFACE
FaceTarget_Editor.ExpressionsInspector(headTarget.face);
#endif
}
PoseInspector();
SettingsInspector(headTarget);
#if hFACE
FaceTarget_Editor.FocusObjectInspector(headTarget.face);
#endif
EventsInspector();
GazeInteractionButton(headTarget);
serializedObject.ApplyModifiedProperties();
}
private static HumanoidControl GetHumanoid(HumanoidTarget target) {
HumanoidControl foundHumanoid = target.transform.GetComponentInParent<HumanoidControl>();
if (foundHumanoid != null)
return foundHumanoid;
HumanoidControl[] humanoids = GameObject.FindObjectsOfType<HumanoidControl>();
for (int i = 0; i < humanoids.Length; i++)
if (humanoids[i].headTarget.transform == target.transform)
foundHumanoid = humanoids[i];
return foundHumanoid;
}
#region Sensors
#if hFACE
private SerializedProperty microphoneEnabledProp;
#endif
private void InitSensors() {
#if hFACE
microphoneEnabledProp = serializedObject.FindProperty("microphone.enabled");
#endif
}
private bool showControllers = true;
private void SensorInspectors(HeadTarget headTarget) {
showControllers = EditorGUILayout.Foldout(showControllers, "Controllers", true);
if (showControllers) {
EditorGUI.indentLevel++;
FirstPersonCameraInspector(headTarget);
ScreenInspector(headTarget);
foreach (TargetProps props in allProps)
props.Inspector();
AnimatorInspector(headTarget);
EditorGUI.indentLevel--;
}
}
private void FirstPersonCameraInspector(HeadTarget headTarget) {
#if pUNITYXR || hLEGACYXR
if (headTarget.unityXR == null)
return;
#endif
#if hOPENVR && hVIVETRACKER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
EditorGUI.BeginDisabledGroup(headTarget.humanoid.openVR.enabled && headTarget.viveTracker.enabled);
#endif
#if pUNITYXR || hLEGACYXR
bool wasEnabled
= headTarget.unityXR.enabled;
#endif
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
#if hLEGACYXR
#if hOPENVR && hVIVETRACKER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
if (headTarget.humanoid.openVR.enabled && headTarget.viveTracker.enabled)
headTarget.unity.enabled = false;
#endif
#endif
#pragma warning disable 219
bool enabled
#if pUNITYXR || hLEGACYXR
= EditorGUILayout.ToggleLeft(headTarget.unityXR.name, headTarget.unityXR.enabled, GUILayout.MinWidth(80));
if (EditorGUI.EndChangeCheck()) {
Undo.RecordObject(headTarget, enabled ? "Enabled " : "Disabled " + headTarget.unityXR.name);
headTarget.unityXR.enabled = enabled;
}
#else
= false;
#endif
#pragma warning restore 219
EditorGUILayout.EndHorizontal();
#if hFACE
if (enabled) { // && microphoneEnabledProp != null) {
EditorGUI.indentLevel++;
microphoneEnabledProp.boolValue = EditorGUILayout.ToggleLeft("Microphone", microphoneEnabledProp.boolValue);
EditorGUI.indentLevel--;
}
#endif
#if pUNITYXR
//if (!Application.isPlaying) {
// //Passer.Tracking.UnityXRHmd.CheckCamera(headTarget);
// if (!wasEnabled && headTarget.unity.enabled) {
// Passer.Tracking.UnityXRHmd.AddCamera(headTarget.unity);
// }
// else if (wasEnabled && !headTarget.unity.enabled) {
// Passer.Tracking.UnityXRHmd.RemoveCamera(headTarget.unity);
// }
//}
#endif
#if hOPENVR && hVIVETRACKER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
EditorGUI.EndDisabledGroup();
#endif
}
private void ScreenInspector(HeadTarget headTarget) {
if (headTarget.virtual3d && headTarget.humanoid.showRealObjects) {
if (headTarget.screenTransform == null)
CreateScreen(headTarget);
headTarget.screenTransform.gameObject.SetActive(true);
}
else if (headTarget.screenTransform != null)
headTarget.screenTransform.gameObject.SetActive(false);
}
private void CreateScreen(HeadTarget headTarget) {
GameObject realWorld = HumanoidControl.GetRealWorld(headTarget.humanoid.transform);
headTarget.screenTransform = realWorld.transform.Find("Screen");
if (headTarget.screenTransform == null) {
GameObject screenObj = GameObject.CreatePrimitive(PrimitiveType.Cube); //new GameObject("Screen");
screenObj.name = "Screen";
headTarget.screenTransform = screenObj.transform;
headTarget.screenTransform.parent = realWorld.transform;
headTarget.screenTransform.localPosition = headTarget.transform.position + headTarget.transform.forward;
headTarget.screenTransform.rotation = headTarget.transform.rotation * Quaternion.AngleAxis(180, Vector3.up);
headTarget.screenTransform.localScale = new Vector3(0.476F, 0.2677F, 0.02F); // 21.5 inch 16:9 screen size
}
}
private void AnimatorInspector(HeadTarget headTarget) {
if (headTarget.humanoid == null)
return;
if (headTarget.humanoid.animatorEnabled) {
headTarget.headAnimator.enabled = EditorGUILayout.ToggleLeft("Procedural Animation", headTarget.headAnimator.enabled, GUILayout.MinWidth(80));
if (headTarget.headAnimator.enabled) {
EditorGUI.indentLevel++;
//headTarget.headAnimator.headAnimation = EditorGUILayout.ToggleLeft("Head Animation", headTarget.headAnimator.headAnimation);
#if hFACE
headTarget.face.behaviour.enabled = EditorGUILayout.ToggleLeft("Eye Behaviour", headTarget.face.behaviour.enabled);
#endif
EditorGUI.indentLevel--;
}
}
}
#endregion
#region Configuration
private bool showConfiguration;
private bool showLeftEye;
private bool showRightEye;
private void ConfigurationInspector(HeadTarget headTarget) {
if (headTarget.humanoid == null)
return;
showConfiguration = EditorGUILayout.Foldout(showConfiguration, "Configuration", true);
if (showConfiguration) {
EditorGUI.indentLevel++;
#if hFACE
SerializedProperty faceProp = serializedObject.FindProperty("face");
FaceTarget_Editor.ConfigurationInspector(faceProp, headTarget.face);
#endif
HeadConfigurationInspector(ref headTarget.head);
NeckConfigurationInspector(ref headTarget.neck);
EditorGUI.indentLevel--;
}
}
private void HeadConfigurationInspector(ref HeadTarget.TargetedHeadBone head) {
head.bone.transform = (Transform)EditorGUILayout.ObjectField("Head", head.bone.transform, typeof(Transform), true);
if (head.bone.transform != null) {
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
head.bone.maxAngle = EditorGUILayout.Slider("Max Angle", head.bone.maxAngle, 0, 180);
if (GUILayout.Button("R", GUILayout.Width(20))) {
head.bone.maxAngle = HeadTarget.maxHeadAngle;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
private void NeckConfigurationInspector(ref HeadTarget.TargetedNeckBone neck) {
neck.bone.transform = (Transform)EditorGUILayout.ObjectField("Neck", neck.bone.transform, typeof(Transform), true);
if (neck.bone.transform != null) {
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
neck.bone.maxAngle = EditorGUILayout.Slider("Max Angle", neck.bone.maxAngle, 0, 180);
if (GUILayout.Button("R", GUILayout.Width(20))) {
neck.bone.maxAngle = HeadTarget.maxNeckAngle;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
#endregion
#region Pose
private void PoseInspector() {
if (!Application.isPlaying && humanoid.pose != null && humanoid.editPose)
humanoid.pose.UpdatePose(humanoid);
}
#endregion
#region Settings
private bool showSettings;
private void SettingsInspector(HeadTarget headTarget) {
showSettings = EditorGUILayout.Foldout(showSettings, "Settings", true);
if (showSettings) {
EditorGUI.indentLevel++;
CollisionFaderInspector();
EditorGUI.indentLevel--;
}
}
private void CollisionFaderInspector() {
SerializedProperty collisionFaderProp = serializedObject.FindProperty("collisionFader");
collisionFaderProp.boolValue = EditorGUILayout.Toggle("Collision Fader", collisionFaderProp.boolValue);
}
#endregion
#region Events
protected int selectedEventSource = -1;
protected int selectedEvent;
protected bool showEvents;
protected virtual void EventsInspector() {
showEvents = EditorGUILayout.Foldout(showEvents, "Events", true);
if (showEvents) {
EditorGUI.indentLevel++;
TrackingEventInspector();
AudioEventInspector();
#if hFACE
FocusEventInspector();
BlinkEventInspector();
#endif
InsideColliderInspector();
EditorGUI.indentLevel--;
}
}
protected void TrackingEventInspector() {
SerializedProperty trackingEventProp = serializedObject.FindProperty("trackingEvent");
BoolEvent_Editor.EventInspector(trackingEventProp, headTarget.trackingEvent, ref selectedEventSource, ref selectedEvent);
}
protected void AudioEventInspector() {
SerializedProperty audioEventProp = serializedObject.FindProperty("audioEvent");
FloatEvent_Editor.EventInspector(audioEventProp, headTarget.audioEvent, ref selectedEventSource, ref selectedEvent);
}
#if hFACE
protected void FocusEventInspector() {
SerializedProperty focusEventProp = serializedObject.FindProperty("focusEvent");
GameObjectEvent_Editor.EventInspector(focusEventProp, headTarget.focusEvent, ref selectedEventSource, ref selectedEvent);
}
protected void BlinkEventInspector() {
SerializedProperty blinkEventProp = serializedObject.FindProperty("blinkEvent");
BoolEvent_Editor.EventInspector(blinkEventProp, headTarget.blinkEvent, ref selectedEventSource, ref selectedEvent);
}
#endif
protected void InsideColliderInspector() {
SerializedProperty insideColliderEventProp = serializedObject.FindProperty("insideColliderEvent");
BoolEvent_Editor.EventInspector(insideColliderEventProp, headTarget.insideColliderEvent, ref selectedEventSource, ref selectedEvent);
}
// protected void EventDetails(int selectedEvent) {
// switch (selectedEvent) {
// case 0:
// FloatEvent_Editor.DetailsInspector(headTarget.audioEvent, audioEventProp, "Audio");
// break;
//#if hFACE
// case 1:
// GameObjectEvent_Editor.DetailsInspector(focusEventProp, "Focus");
// break;
// case 2:
// BoolEvent_Editor.DetailsInspector(blinkEventProp, "Blink");
// break;
//#endif
// }
// }
#endregion
#region Buttons
private void GazeInteractionButton(HeadTarget headTarget) {
InteractionPointer interactionPointer = headTarget.transform.GetComponentInChildren<InteractionPointer>();
if (interactionPointer != null)
return;
GUILayout.BeginHorizontal();
if (GUILayout.Button("Add Interaction Pointer"))
AddInteractionPointer();
if (GUILayout.Button("Add Teleporter"))
AddTeleporter();
GUILayout.EndHorizontal();
}
private void AddInteractionPointer() {
}
private void AddTeleporter() {
}
#endregion
#endregion
#region Scene
public void OnSceneGUI() {
if (Application.isPlaying)
return;
if (headTarget == null || headTarget.humanoid == null)
return;
#if hFACE
FaceTarget_Editor.UpdateScene(headTarget.face);
#endif
if (humanoid.pose != null) {
if (humanoid.editPose)
humanoid.pose.UpdatePose(humanoid);
else {
humanoid.pose.Show(humanoid);
headTarget.CopyRigToTarget();
}
}
// update the target rig from the current head target
headTarget.CopyTargetToRig();
// update the avatar bones from the target rig
humanoid.UpdateMovements();
// match the target rig with the new avatar pose
humanoid.MatchTargetsToAvatar();
// and update all targets to match the target rig
humanoid.CopyRigToTargets();
// Update the sensors to match the updated targets
humanoid.UpdateSensorsFromTargets();
}
#endregion
public abstract class TargetProps {
public SerializedProperty enabledProp;
public SerializedProperty sensorTransformProp;
public SerializedProperty sensor2TargetPositionProp;
public SerializedProperty sensor2TargetRotationProp;
public HeadTarget headTarget;
public HeadSensor sensor;
public TargetProps(SerializedObject serializedObject, HeadSensor _sensor, HeadTarget _headTarget, string unitySensorName) {
enabledProp = serializedObject.FindProperty(unitySensorName + ".enabled");
sensorTransformProp = serializedObject.FindProperty(unitySensorName + ".sensorTransform");
sensor2TargetPositionProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetPosition");
sensor2TargetRotationProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetRotation");
headTarget = _headTarget;
sensor = _sensor;
sensor.Init(headTarget);
}
public virtual void SetSensor2Target() {
if (sensor.sensorTransform == null)
return;
sensor2TargetRotationProp.quaternionValue = Quaternion.Inverse(sensor.sensorTransform.rotation) * headTarget.head.target.transform.rotation;
sensor2TargetPositionProp.vector3Value = -headTarget.head.target.transform.InverseTransformPoint(sensor.sensorTransform.position);
}
public abstract void Inspector();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 363b5edd875938247a1df60350426519
timeCreated: 1455896583
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,316 @@
using UnityEditor;
using UnityEngine;
namespace Passer {
using Humanoid;
[CanEditMultipleObjects]
[CustomEditor(typeof(HipsTarget), true)]
public class HipsTarget_Editor : Editor {
private HipsTarget hipsTarget;
private HumanoidControl humanoid;
private TargetProps[] allProps;
#region Enable
public void OnEnable() {
hipsTarget = (HipsTarget)target;
if (hipsTarget.humanoid == null)
hipsTarget.humanoid = GetHumanoid(hipsTarget);
humanoid = hipsTarget.humanoid;
if (humanoid == null)
return;
InitEditors();
hipsTarget.InitSensors();
InitConfiguration(hipsTarget);
InitSettings();
}
private void InitEditors() {
allProps = new TargetProps[] {
#if hOPENVR && hVIVETRACKER && (UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX)
new ViveTracker_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hKINECT1
new Kinect1_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hKINECT2
new Kinect2_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hKINECT4
new Kinect4_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hORBBEC
new Astra_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hNEURON
new Neuron_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hOPTITRACK
new Optitrack_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
#if hCUSTOM
new Custom_Editor.HipsTargetProps(serializedObject, hipsTarget),
#endif
};
}
#endregion
#region Disable
public void OnDisable() {
if (humanoid == null) {
// This target is not connected to a humanoid, so we delete it
DestroyImmediate(hipsTarget, true);
return;
}
if (!Application.isPlaying) {
SetSensor2Target();
}
}
private void SetSensor2Target() {
foreach (TargetProps props in allProps)
props.SetSensor2Target();
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
if (hipsTarget == null || humanoid == null)
return;
serializedObject.Update();
SensorInspectors(hipsTarget);
ConfigurationInspector(hipsTarget);
SettingsInspector();
serializedObject.ApplyModifiedProperties();
}
public static HumanoidControl GetHumanoid(HumanoidTarget target) {
HumanoidControl foundHumanoid = target.transform.GetComponentInParent<HumanoidControl>();
if (foundHumanoid != null)
return foundHumanoid;
HumanoidControl[] humanoids = GameObject.FindObjectsOfType<HumanoidControl>();
for (int i = 0; i < humanoids.Length; i++)
if (humanoids[i].hipsTarget.transform == target.transform)
foundHumanoid = humanoids[i];
return foundHumanoid;
}
#region Sensors
public bool showSensors = true;
private void SensorInspectors(HipsTarget hipsTarget) {
showSensors = EditorGUILayout.Foldout(showSensors, "Controllers", true);
if (showSensors) {
EditorGUI.indentLevel++;
foreach (TargetProps props in allProps)
props.Inspector();
if (humanoid.animatorEnabled)
hipsTarget.torsoAnimator.enabled = EditorGUILayout.ToggleLeft("Procedural Animation", hipsTarget.torsoAnimator.enabled, GUILayout.MinWidth(80));
EditorGUI.indentLevel--;
}
}
#endregion
#region Configuration
private void InitConfiguration(HipsTarget target) {
if (target.humanoid.avatarRig == null)
return;
InitChestConfiguration(target.chest);
InitSpineConfiguration(target.spine);
InitHipsConfiguration(target.hips);
}
private bool showConfiguration;
private void ConfigurationInspector(HipsTarget hipsTarget) {
hipsTarget.RetrieveBones();
showConfiguration = EditorGUILayout.Foldout(showConfiguration, "Configuration", true);
if (showConfiguration) {
EditorGUI.indentLevel++;
ChestConfigurationInspector(ref hipsTarget.chest);
SpineConfigurationInspector(ref hipsTarget.spine);
HipsConfigurationInspector(ref hipsTarget.hips);
EditorGUI.indentLevel--;
}
}
private void UpdateBones(HipsTarget target) {
if (target.humanoid.avatarRig == null)
return;
UpdateHipsBones(target.hips);
UpdateSpineBones(target.spine);
UpdateChestBones(target.chest);
}
#region Chest
private void InitChestConfiguration(HipsTarget.TargetedChestBone upperLeg) {
}
private void ChestConfigurationInspector(ref HipsTarget.TargetedChestBone chest) {
chest.bone.transform = (Transform)EditorGUILayout.ObjectField("Chest", chest.bone.transform, typeof(Transform), true);
if (chest.bone.transform != null) {
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
chest.bone.maxAngle = EditorGUILayout.Slider("Max Angle", chest.bone.maxAngle, 0, 180);
if (GUILayout.Button("R", GUILayout.Width(20))) {
chest.bone.maxAngle = HipsTarget.maxChestAngle;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
private void UpdateChestBones(HipsTarget.TargetedChestBone chest) {
}
#endregion
#region Spine
private void InitSpineConfiguration(HipsTarget.TargetedSpineBone spine) {
}
private void SpineConfigurationInspector(ref HipsTarget.TargetedSpineBone spine) {
spine.bone.transform = (Transform)EditorGUILayout.ObjectField("Spine", spine.bone.transform, typeof(Transform), true);
if (spine.bone.transform != null) {
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
spine.bone.maxAngle = EditorGUILayout.Slider("Max Angle", spine.bone.maxAngle, 0, 180);
if (GUILayout.Button("R", GUILayout.Width(20))) {
spine.bone.maxAngle = HipsTarget.maxSpineAngle;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
private void UpdateSpineBones(HipsTarget.TargetedSpineBone spine) {
}
#endregion
#region Hips
private void InitHipsConfiguration(HipsTarget.TargetedHipsBone hips) {
}
private void HipsConfigurationInspector(ref HipsTarget.TargetedHipsBone hips) {
hips.bone.transform = (Transform)EditorGUILayout.ObjectField("Hips", hips.bone.transform, typeof(Transform), true);
}
private void UpdateHipsBones(HipsTarget.TargetedHipsBone hips) {
}
#endregion
#endregion
#region Settings
protected SerializedProperty bodyRotationProp;
protected void InitSettings() {
SerializedProperty animatorProp = serializedObject.FindProperty("torsoAnimator");
bodyRotationProp = animatorProp.FindPropertyRelative("bodyRotation");
}
public bool showSettings;
protected void SettingsInspector() {
showSettings = EditorGUILayout.Foldout(showSettings, "Settings", true);
if (showSettings) {
EditorGUI.indentLevel++;
bodyRotationProp.intValue = (int)(TorsoAnimator.BodyRotation)EditorGUILayout.EnumPopup("Body Rotation", (TorsoAnimator.BodyRotation)bodyRotationProp.intValue);
EditorGUI.indentLevel--;
}
}
#endregion
#endregion
#region Scene
public void OnSceneGUI() {
if (Application.isPlaying)
return;
if (hipsTarget == null || humanoid == null)
return;
if (humanoid.pose != null) {
if (humanoid.editPose)
humanoid.pose.UpdatePose(humanoid);
else {
humanoid.pose.Show(humanoid);
hipsTarget.CopyRigToTarget();
}
}
// update the target rig from the current hips target
hipsTarget.CopyTargetToRig();
// update the avatar bones to match the target rig
humanoid.UpdateMovements();
// match the target rig with the new avatar pose
humanoid.MatchTargetsToAvatar();
// and update all targets to match the target rig
humanoid.CopyRigToTargets();
// Update the sensors to match the updated targets
humanoid.UpdateSensorsFromTargets();
}
#endregion
public abstract class TargetProps {
public SerializedProperty enabledProp;
public SerializedProperty sensorTransformProp;
public SerializedProperty sensor2TargetPositionProp;
public SerializedProperty sensor2TargetRotationProp;
public HipsTarget hipsTarget;
public TorsoSensor sensor;
public TargetProps(SerializedObject serializedObject, TorsoSensor _sensor, HipsTarget _hipsTarget, string unitySensorName) {
enabledProp = serializedObject.FindProperty(unitySensorName + ".enabled");
sensorTransformProp = serializedObject.FindProperty(unitySensorName + ".sensorTransform");
sensor2TargetPositionProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetPosition");
sensor2TargetRotationProp = serializedObject.FindProperty(unitySensorName + ".sensor2TargetRotation");
hipsTarget = _hipsTarget;
sensor = _sensor;
sensor.Init(hipsTarget);
}
public virtual void SetSensor2Target() {
if (sensor.sensorTransform == null)
return;
sensor2TargetRotationProp.quaternionValue = Quaternion.Inverse(sensor.sensorTransform.rotation) * hipsTarget.hips.target.transform.rotation;
sensor2TargetPositionProp.vector3Value = -hipsTarget.hips.target.transform.InverseTransformPoint(sensor.sensorTransform.position);
}
public abstract void Inspector();
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bfaf25c142fe67b49969e7693e8db940
timeCreated: 1462300882
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,389 @@
using UnityEditor;
using UnityEngine;
namespace Passer.Humanoid {
public static class HumanoidTarget_Editor {
public static Target Inspector(Target target, string name) {
if (target == null)
return target;
EditorGUILayout.BeginHorizontal();
Transform defaultTargetTransform = null; // target.GetDefaultTarget(target.humanoid);
Transform targetTransform = target.transform ?? defaultTargetTransform;
targetTransform = (Transform)EditorGUILayout.ObjectField(name, targetTransform, typeof(Transform), true);
if (!Application.isPlaying) {
if (targetTransform == defaultTargetTransform && GUILayout.Button("Show", GUILayout.MaxWidth(60))) {
// Call static method CreateTarget on target
target = (HumanoidTarget)target.GetType().GetMethod("CreateTarget").Invoke(null, new object[] { target });
//} else if (targetTransform != target.transform) {
// target = (HumanoidTarget)target.GetType().GetMethod("SetTarget").Invoke(null, new object[] { target.humanoid, targetTransform });
}
}
EditorGUILayout.EndHorizontal();
return target;
}
public static HumanoidTarget Inspector(HumanoidTarget target, string name) {
if (target == null)
return target;
EditorGUILayout.BeginHorizontal();
Transform defaultTargetTransform = target.GetDefaultTarget(target.humanoid);
Transform targetTransform = target.transform ?? defaultTargetTransform;
GUIContent text = new GUIContent(
name,
"The transform controlling the " + name
);
targetTransform = (Transform)EditorGUILayout.ObjectField(text, targetTransform, typeof(Transform), true);
if (!Application.isPlaying) {
if (targetTransform == defaultTargetTransform && GUILayout.Button("Show", GUILayout.MaxWidth(60))) {
// Call static method CreateTarget on target
target = (HumanoidTarget)target.GetType().GetMethod("CreateTarget").Invoke(null, new object[] { target });
} else if (targetTransform != target.transform) {
target = (HumanoidTarget)target.GetType().GetMethod("SetTarget").Invoke(null, new object[] { target.humanoid, targetTransform });
}
}
EditorGUILayout.EndHorizontal();
return target;
}
public static bool ControllerInspector(HumanoidSensor controller) {
EditorGUILayout.BeginHorizontal();
controller.enabled = EditorGUILayout.ToggleLeft(controller.name, controller.enabled, GUILayout.MinWidth(80));
if (controller.enabled && Application.isPlaying)
EditorGUILayout.EnumPopup(controller.status);
EditorGUILayout.EndHorizontal();
return controller.enabled;
}
public static bool ControllerInspector(HumanoidSensor controller, Target target) {
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
GUIContent text = new GUIContent(
controller.name,
"Activate " + controller.name + " support for this humanoid"
);
bool enabled = EditorGUILayout.ToggleLeft(text, controller.enabled, GUILayout.MinWidth(80));
if (EditorGUI.EndChangeCheck()) {
Undo.RecordObject(target, enabled ? "Enabled " : "Disabled " + controller.name);
controller.enabled = enabled;
}
if (Application.isPlaying && enabled)
EditorGUILayout.EnumPopup(controller.status);
EditorGUILayout.EndHorizontal();
return enabled;
}
public static void BoneAngleInspector(SerializedProperty minProperty, SerializedProperty maxProperty, float defaultMin, float defaultMax, string boneAxisName, string label) {
float min = minProperty.floatValue;
float max = maxProperty.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label, GUILayout.MinWidth(70));
min = EditorGUILayout.FloatField(min, GUILayout.Width(65));
GUI.SetNextControlName(boneAxisName + "1");
EditorGUILayout.MinMaxSlider(ref min, ref max, -180, 180);
GUI.SetNextControlName(boneAxisName + "2");
max = EditorGUILayout.FloatField(max, GUILayout.Width(65));
if (GUILayout.Button("R")) {
min = defaultMin;
max = defaultMax;
GUI.FocusControl(boneAxisName + "1");
}
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck()) {
minProperty.floatValue = min;
maxProperty.floatValue = max;
}
SceneView.RepaintAll();
}
public static void BoneXAngleInspector(HumanoidTarget.TargetedBone bone, float defaultMin, float defaultMax) {
float oldMin = bone.bone.minAngles.x;
float oldMax = bone.bone.maxAngles.x;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("X Limits", GUILayout.MinWidth(70));
GUI.SetNextControlName(bone.bone.transform.name + "X1");
bone.bone.minAngles.x = EditorGUILayout.FloatField(bone.bone.minAngles.x, GUILayout.Width(65));
EditorGUILayout.MinMaxSlider(ref bone.bone.minAngles.x, ref bone.bone.maxAngles.x, -180, 180);
GUI.SetNextControlName(bone.bone.transform.name + "X2");
bone.bone.maxAngles.x = EditorGUILayout.FloatField(bone.bone.maxAngles.x, GUILayout.Width(65));
if (GUILayout.Button("R")) {
bone.bone.minAngles.x = defaultMin;
bone.bone.maxAngles.x = defaultMax;
GUI.FocusControl(bone.bone.transform.name + "X1");
}
EditorGUILayout.EndHorizontal();
if (bone.bone.maxAngles.x != oldMax || bone.bone.minAngles.x != oldMin)
SceneView.RepaintAll();
}
public static void BoneYAngleInspector(HumanoidTarget.TargetedBone bone, float defaultMin, float defaultMax) {
float oldMin = bone.bone.minAngles.y;
float oldMax = bone.bone.maxAngles.y;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Y Limits", GUILayout.MinWidth(70));
GUI.SetNextControlName(bone.bone.transform.name + "Y1");
bone.bone.minAngles.y = EditorGUILayout.FloatField(bone.bone.minAngles.y, GUILayout.Width(65));
EditorGUILayout.MinMaxSlider(ref bone.bone.minAngles.y, ref bone.bone.maxAngles.y, -180, 180);
GUI.SetNextControlName(bone.bone.transform.name + "Y2");
bone.bone.maxAngles.y = EditorGUILayout.FloatField(bone.bone.maxAngles.y, GUILayout.Width(65));
if (GUILayout.Button("R")) {
bone.bone.minAngles.y = defaultMin;
bone.bone.maxAngles.y = defaultMax;
GUI.FocusControl(bone.bone.transform.name + "Y1");
}
EditorGUILayout.EndHorizontal();
if (bone.bone.maxAngles.y != oldMax || bone.bone.minAngles.y != oldMin)
SceneView.RepaintAll();
}
public static void BoneYAngleInspector(HumanoidTarget.TargetedBone bone, SerializedProperty minProperty, SerializedProperty maxProperty, float defaultMin, float defaultMax) {
float min = minProperty.floatValue;
float max = maxProperty.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Limits Y", GUILayout.MinWidth(70));
min = EditorGUILayout.FloatField(min, GUILayout.Width(65));
GUI.SetNextControlName(bone.bone.transform.name + "Y1");
EditorGUILayout.MinMaxSlider(ref min, ref max, -180, 180);
GUI.SetNextControlName(bone.bone.transform.name + "Y2");
max = EditorGUILayout.FloatField(max, GUILayout.Width(65));
if (GUILayout.Button("R")) {
min = defaultMin;
max = defaultMax;
GUI.FocusControl(bone.bone.transform.name + "Y1");
}
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck()) {
minProperty.floatValue = min;
maxProperty.floatValue = max;
SceneView.RepaintAll();
}
}
public static void BoneZAngleInspector(HumanoidTarget.TargetedBone bone, float defaultMin, float defaultMax) {
float oldMin = bone.bone.minAngles.z;
float oldMax = bone.bone.maxAngles.z;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Z Limits", GUILayout.MinWidth(70));
GUI.SetNextControlName(bone.bone.transform.name + "Z1");
bone.bone.minAngles.z = EditorGUILayout.FloatField(bone.bone.minAngles.z, GUILayout.Width(65));
EditorGUILayout.MinMaxSlider(ref bone.bone.minAngles.z, ref bone.bone.maxAngles.z, -180, 180);
GUI.SetNextControlName(bone.bone.transform.name + "Z2");
bone.bone.maxAngles.z = EditorGUILayout.FloatField(bone.bone.maxAngles.z, GUILayout.Width(65));
if (GUILayout.Button("R")) {
bone.bone.minAngles.z = defaultMin;
bone.bone.maxAngles.z = defaultMax;
GUI.FocusControl(bone.bone.transform.name + "Z1");
}
EditorGUILayout.EndHorizontal();
if (bone.bone.maxAngles.y != oldMax || bone.bone.minAngles.y != oldMin)
SceneView.RepaintAll();
}
public static void BoneZAngleInspector(HumanoidTarget.TargetedBone bone, SerializedProperty minProperty, SerializedProperty maxProperty, float defaultMin, float defaultMax) {
float min = minProperty.floatValue;
float max = maxProperty.floatValue;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Limits Z", GUILayout.MinWidth(70));
min = EditorGUILayout.FloatField(min, GUILayout.Width(65));
GUI.SetNextControlName(bone.bone.transform.name + "Z1");
EditorGUILayout.MinMaxSlider(ref min, ref max, -180, 180);
GUI.SetNextControlName(bone.bone.transform.name + "Z2");
max = EditorGUILayout.FloatField(max, GUILayout.Width(65));
if (GUILayout.Button("R")) {
min = defaultMin;
max = defaultMax;
GUI.FocusControl(bone.bone.transform.name + "Z1");
}
EditorGUILayout.EndHorizontal();
if (EditorGUI.EndChangeCheck()) {
minProperty.floatValue = min;
maxProperty.floatValue = max;
SceneView.RepaintAll();
}
}
//public static void DrawTargetBone(HumanoidTarget.TargetedBone bone) {
// if (bone.target.transform != null) {
// Handles.color = Color.white;
// Handles.DrawLine(bone.target.transform.position, bone.target.transform.position + bone.target.transform.rotation * bone.target.normalDirection * bone.bone.length);
// }
//}
#region xArcs
public static void DrawXArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle) {
DrawXArcs(position, rotation, minAngle, maxAngle, rotation * Vector3.down);
}
public static void DrawXArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 zeroDirection) {
Vector3 planeNormal = rotation * Vector3.right;
DrawXArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection);
}
public static void DrawXArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 planeNormal, Vector3 zeroDirection) {
DrawArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection, Color.red);
}
#endregion
#region yArcs
public static void DrawYArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle) {
DrawYArcs(position, rotation, minAngle, maxAngle, rotation * Vector3.forward);
}
public static void DrawYArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 zeroDirection) {
Vector3 planeNormal = rotation * Vector3.up;
DrawYArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection);
}
public static void DrawYArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 planeNormal, Vector3 zeroDirection) {
DrawArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection, Color.green);
}
#endregion
#region zArcs
public static void DrawZArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle) {
DrawZArcs(position, rotation, minAngle, maxAngle, rotation * Vector3.down);
}
public static void DrawZArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 zeroDirection) {
Vector3 planeNormal = rotation * Vector3.forward;
DrawZArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection);
}
public static void DrawZArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 planeNormal, Vector3 zeroDirection) {
DrawArcs(position, rotation, minAngle, maxAngle, planeNormal, zeroDirection, Color.blue);
}
#endregion
public static void DrawArcs(Vector3 position, Quaternion rotation, float minAngle, float maxAngle, Vector3 planeNormal, Vector3 zeroDirection, Color color) {
color.a = 0.1F;
Handles.color = color;
Handles.DrawSolidArc(position, planeNormal, zeroDirection, minAngle, HandleUtility.GetHandleSize(position));
Handles.DrawSolidArc(position, planeNormal, zeroDirection, maxAngle, HandleUtility.GetHandleSize(position));
color.a = 1;
Handles.color = color;
Handles.DrawWireArc(position, planeNormal, zeroDirection, minAngle, HandleUtility.GetHandleSize(position));
Handles.DrawWireArc(position, planeNormal, zeroDirection, maxAngle, HandleUtility.GetHandleSize(position));
Handles.DrawLine(position, position + zeroDirection * HandleUtility.GetHandleSize(position));
}
#region MinMaxSlider
}
public class MinMaxSliderAttribute : PropertyAttribute {
public readonly string name;
public readonly float defaultMin;
public readonly float defaultMax;
public readonly float minLimit;
public readonly float maxLimit;
public MinMaxSliderAttribute(string _name, float _defaultMin, float _defaultMax, float _minLimit, float _maxLimit) {
name = _name;
defaultMin = _defaultMin;
defaultMax = _defaultMax;
minLimit = _minLimit;
maxLimit = _maxLimit;
}
}
[CustomPropertyDrawer(typeof(MinMaxSliderAttribute))]
class MinMaxSliderDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if (property.propertyType == SerializedPropertyType.Vector2) {
Vector2 range = property.vector2Value;
float min = range.x;
float max = range.y;
MinMaxSliderAttribute attr = attribute as MinMaxSliderAttribute;
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(label, GUILayout.MinWidth(70));
min = EditorGUILayout.FloatField(min, GUILayout.Width(65));
GUI.SetNextControlName(attr.name + "1");
EditorGUI.MinMaxSlider(position, label, ref min, ref max, attr.minLimit, attr.maxLimit);
GUI.SetNextControlName(attr.name + "2");
max = EditorGUILayout.FloatField(max, GUILayout.Width(65));
if (GUILayout.Button("R")) {
min = attr.defaultMin;
max = attr.defaultMax;
GUI.FocusControl(attr.name + "Y1");
}
if (EditorGUI.EndChangeCheck()) {
range.x = min;
range.y = max;
property.vector2Value = range;
}
EditorGUILayout.EndHorizontal();
} else {
EditorGUI.LabelField(position, label, "Use only with Vector2");
}
}
}
#endregion
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dfaa18de9efae9e4692a96305b21d4e3
timeCreated: 1485418477
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,29 @@
using UnityEditor;
using UnityEngine;
namespace Passer {
public static class Target_Editor {
public static Target Inspector(Target target, string name) {
if (target == null)
return target;
EditorGUILayout.BeginHorizontal();
Transform defaultTargetTransform = null; // target.GetDefaultTarget(target.humanoid);
Transform targetTransform = target.transform ?? defaultTargetTransform;
targetTransform = (Transform)EditorGUILayout.ObjectField(name, targetTransform, typeof(Transform), true);
if (!Application.isPlaying) {
if (targetTransform == defaultTargetTransform && GUILayout.Button("Show", GUILayout.MaxWidth(60))) {
// Call static method CreateTarget on target
target = (Target)target.GetType().GetMethod("CreateTarget").Invoke(null, new object[] { target });
//} else if (targetTransform != target.transform) {
// target = (HumanoidTarget)target.GetType().GetMethod("SetTarget").Invoke(null, new object[] { target.humanoid, targetTransform });
}
}
EditorGUILayout.EndHorizontal();
return target;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f51402f87211d494abb18fefb102f23b
timeCreated: 1553075920
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

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

View File

@ -0,0 +1,90 @@
using UnityEngine;
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(AvatarManager))]
public class AvatarManager_Editor : Editor {
public void OnDisable() {
AvatarManager avatarManager = (AvatarManager)target;
Cleanup(avatarManager);
}
public override void OnInspectorGUI() {
AvatarManager avatarManager = (AvatarManager)target;
CurrentAvatarInspector(avatarManager);
if (avatarManager.fpAvatars.Length == 0 || avatarManager.fpAvatars[avatarManager.fpAvatars.Length - 1] != null)
avatarManager.fpAvatars = Extend(avatarManager.fpAvatars, avatarManager.fpAvatars.Length + 1);
if (avatarManager.tpAvatars.Length < avatarManager.fpAvatars.Length)
avatarManager.tpAvatars = Extend(avatarManager.tpAvatars, avatarManager.fpAvatars.Length);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("#", GUILayout.Width(20));
EditorGUILayout.LabelField("First Person", GUILayout.MinWidth(100));
#if hNW_UNET || hNW_PHOTON || hNW_BOLT || hNW_MIRROR
EditorGUILayout.LabelField("Third Person", GUILayout.MinWidth(100));
#endif
EditorGUILayout.EndHorizontal();
for (int i = 0; i < avatarManager.fpAvatars.Length; i++)
AvatarInspector(avatarManager, i);
//if (GUILayout.Button("Add Avatar"))
// AddAvatar(avatarManager);
}
private void CurrentAvatarInspector(AvatarManager avatarManager) {
int lastAvatarIndex = avatarManager.currentAvatarIndex;
avatarManager.currentAvatarIndex = EditorGUILayout.IntField("Current Avatar Index", avatarManager.currentAvatarIndex);
if (Application.isPlaying && avatarManager.currentAvatarIndex != lastAvatarIndex)
avatarManager.SetAvatar(avatarManager.currentAvatarIndex);
}
private void AvatarInspector(AvatarManager avatarManager, int i) {
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(i.ToString(), GUILayout.Width(20));
avatarManager.fpAvatars[i] = (Animator)EditorGUILayout.ObjectField(avatarManager.fpAvatars[i], typeof(Animator), false);
#if hNW_UNET || hNW_PHOTON || hNW_BOLT || hNW_MIRROR
avatarManager.tpAvatars[i] = (Animator) EditorGUILayout.ObjectField(avatarManager.tpAvatars[i], typeof(Animator), false);
#endif
EditorGUILayout.EndHorizontal();
}
private void AddAvatar(AvatarManager avatarManager) {
avatarManager.fpAvatars = Extend(avatarManager.fpAvatars, avatarManager.fpAvatars.Length + 1);
}
private Animator[] Extend(Animator[] animators, int n) {
Animator[] newAnimators = new Animator[n];
for (int i = 0; i < animators.Length; i++)
newAnimators[i] = animators[i];
return newAnimators;
}
private void Cleanup(AvatarManager avatarManager) {
int nNonNullEntries = 0;
foreach (Animator animator in avatarManager.fpAvatars) {
if (animator != null)
nNonNullEntries++;
}
if (nNonNullEntries == avatarManager.fpAvatars.Length)
return;
Animator[] newFpAvatars = new Animator[nNonNullEntries];
int j = 0;
for (int i = 0; i < avatarManager.fpAvatars.Length; i++) {
if (avatarManager.fpAvatars[i] != null) {
newFpAvatars[j] = avatarManager.fpAvatars[i];
j++;
}
}
avatarManager.fpAvatars = newFpAvatars;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 43744b1e9fbbc154da0167e2af1c5fd5
timeCreated: 1513776933
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,24 @@
using UnityEngine;
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(ColoringInteractionPointer), true)]
public class ColoringInteractionPointer_Editor : InteractionPointer_Editor {
#region Inspector
public override void OnInspectorGUI() {
base.OnInspectorGUI();
SerializedProperty validMaterialProp = serializedObject.FindProperty("validMaterial");
SerializedProperty invalidMaterialProp = serializedObject.FindProperty("invalidMaterial");
validMaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Valid Material", validMaterialProp.objectReferenceValue, typeof(Material), false);
invalidMaterialProp.objectReferenceValue = EditorGUILayout.ObjectField("Invalid Material", invalidMaterialProp.objectReferenceValue, typeof(Material), false);
serializedObject.ApplyModifiedProperties();
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d02dc353189558b4ea8595963c421445
timeCreated: 1575542779
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
/*
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(HumanoidInteractionPointer), true)]
public class HumanoidInteractionPointer_Editor : InteractionPointer_Editor { }
}
*/

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9960a3766953271488d78fb0a36223a6
timeCreated: 1520436447
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,6 @@
using UnityEditor;
namespace Passer.Humanoid {
[CustomEditor(typeof(Telegrabber))]
public class Telegrabber_Editor : InteractionPointer_Editor { }
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f20a7e0a71465de4bab00c177aa6af18
timeCreated: 1536833107
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,56 @@
using UnityEditor;
using UnityEngine;
namespace Passer {
using Passer.Tracking;
[CustomEditor(typeof(TrackedRigidbody))]
public class TrackedRigidbody_Editor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();
SensorInspector();
HybridPhysics.PhysicsMode physicsMode = PhysicsModeInspector();
if (physicsMode != HybridPhysics.PhysicsMode.Kinematic) {
StrengthInspector();
if (physicsMode == HybridPhysics.PhysicsMode.HybridKinematic)
KinematicMass();
}
serializedObject.ApplyModifiedProperties();
}
protected virtual void SensorInspector() {
SerializedProperty sensorComponentProp = serializedObject.FindProperty("target");
Transform sensorTransform = (Transform)sensorComponentProp.objectReferenceValue;
SensorComponent sensorComponent =
sensorTransform != null ?
sensorTransform.GetComponent<SensorComponent>() :
null;
sensorComponent = (SensorComponent)EditorGUILayout.ObjectField("Sensor", sensorComponent, typeof(SensorComponent), true);
sensorComponentProp.objectReferenceValue =
sensorComponent != null ?
sensorComponent.transform :
null;
}
protected virtual HybridPhysics.PhysicsMode PhysicsModeInspector() {
SerializedProperty modeProp = serializedObject.FindProperty("mode");
HybridPhysics.PhysicsMode physicsMode = (HybridPhysics.PhysicsMode)EditorGUILayout.EnumPopup("Physics Mode", (HybridPhysics.PhysicsMode)modeProp.intValue);
modeProp.intValue = (int)physicsMode;
return physicsMode;
}
protected virtual void StrengthInspector() {
SerializedProperty strengthProp = serializedObject.FindProperty("strength");
strengthProp.floatValue = EditorGUILayout.FloatField("Strength", strengthProp.floatValue);
}
protected virtual void KinematicMass() {
SerializedProperty kinematicMassProp = serializedObject.FindProperty("kinematicMass");
kinematicMassProp.floatValue = EditorGUILayout.FloatField("Kinematic Mass", kinematicMassProp.floatValue);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f7c0372c48e713242be42a6c0b6332ba
timeCreated: 1569481259
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,55 @@
using UnityEngine;
using UnityEditor;
namespace Passer.Humanoid {
public class Tracker_Editor : Editor {
public static void Inspector(HumanoidControl humanoid, HumanoidTracker tracker, SerializedProperty enabledProp, string resourceName) {
EditorGUILayout.BeginHorizontal();
//EditorGUI.BeginChangeCheck();
bool wasEnabled = enabledProp.boolValue;
enabledProp.boolValue = EditorGUILayout.ToggleLeft(tracker.name, enabledProp.boolValue, GUILayout.MinWidth(80));
if (Application.isPlaying && enabledProp.boolValue)
EditorGUILayout.EnumPopup(tracker.status);
EditorGUILayout.EndHorizontal();
PrefabAssetType prefabType = PrefabUtility.GetPrefabAssetType(humanoid);
if (prefabType != PrefabAssetType.NotAPrefab)
return;
if (tracker.humanoid == null)
tracker.humanoid = humanoid;
//if (enabledProp.boolValue && resourceName != null)
// tracker.AddTracker(humanoid, resourceName);
//else if (wasEnabled) {
// RemoveTracker(tracker);
//}
//tracker.ShowTracker(humanoid.showRealObjects && enabledProp.boolValue);
}
public static void Inspector(HumanoidTracker tracker, SerializedProperty enabledProp) {
EditorGUILayout.BeginHorizontal();
//EditorGUI.BeginChangeCheck();
enabledProp.boolValue = EditorGUILayout.ToggleLeft(tracker.name, enabledProp.boolValue, GUILayout.MinWidth(80));
if (Application.isPlaying && enabledProp.boolValue)
EditorGUILayout.EnumPopup(tracker.status);
EditorGUILayout.EndHorizontal();
}
protected static void RemoveTracker(HumanoidTracker tracker) {
if (tracker.trackerComponent == null)
return;
DestroyImmediate(tracker.trackerComponent.gameObject, true);
}
public static Transform RemoveTransform(Transform trackerTransform) {
if (trackerTransform != null) {
DestroyImmediate(trackerTransform.gameObject, true);
}
return null;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ab47a0583b3b8d947ab63aef8be18bdb
timeCreated: 1487856438
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,23 @@
{
"name": "PasserVR.HumanoidControl.Editor",
"references": [
"PasserVR.HumanoidControl",
"Passer.Visitors.Editor",
"PhotonUnityNetworking",
"PhotonVoice",
"PhotonVoice.PUN",
"PhotonRealtime",
"PhotonVoice.API"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

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

8
Editor/Sites.meta Normal file
View File

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

View File

@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(HumanoidAttachments))]
public class HumanoidAttachments_Editor : Editor {
}
}

View File

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

View File

@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(VisitorPossessions))]
public class PawnPossessions_Editor : Editor {
private VisitorPossessions humanoidPossessions;
private void OnEnable() {
humanoidPossessions = (VisitorPossessions)target;
}
public override void OnInspectorGUI() {
ClearOnAwakeInspector();
DefaultPossessionsInspector();
serializedObject.ApplyModifiedProperties();
if (Application.isPlaying) {
CurrentPossessions();
} else {
ScenePossessions();
}
}
protected virtual void ClearOnAwakeInspector() {
SerializedProperty clearOnAwakeProp = serializedObject.FindProperty("clearOnAwake");
EditorGUILayout.PropertyField(clearOnAwakeProp);
}
protected virtual void DefaultPossessionsInspector() {
SerializedProperty defaultPossessionsProp = serializedObject.FindProperty("defaultPossessions");
EditorGUILayout.PropertyField(defaultPossessionsProp, true);
}
protected void CurrentPossessions() {
EditorGUILayout.LabelField("Current Possessions");
EditorGUI.indentLevel++;
if (humanoidPossessions.possessions != null) {
List<VisitorPossessions.Possession> possessionList = humanoidPossessions.possessions;
foreach (VisitorPossessions.Possession possession in possessionList) {
EditorGUILayout.TextField(possession.name);
}
}
EditorGUI.indentLevel--;
}
protected void ScenePossessions() {
EditorGUILayout.LabelField("Possessions in this Scene");
EditorGUI.indentLevel++;
using (new EditorGUI.DisabledScope(true)) {
Possessable[] sitePossessions = FindObjectsOfType<Possessable>();
foreach (Possessable possession in sitePossessions) {
EditorGUILayout.ObjectField(possession, typeof(Possessable), true);
}
}
EditorGUI.indentLevel--;
}
}
}

View File

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

View File

@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
#if UNITY_2021_2_OR_NEWER
using UnityEditor.SceneManagement;
#else
using UnityEditor.Experimental.SceneManagement;
#endif
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(Possessable))]
public class Possession_Editor : Editor {
protected Possessable possession;
#region Enable
// should execute after compile...?
private void OnEnable() {
possession = (Possessable)target;
DeterminePossessionType();
AddToAssetBundle();
}
private void DeterminePossessionType() {
Animator animator = possession.GetComponent<Animator>();
if (animator != null && animator.isHuman) {
possession.possessionType = Possessable.Type.Avatar;
// Avatar are always unique
possession.isUnique = true;
return;
}
possession.possessionType = Possessable.Type.Generic;
}
private void AddToAssetBundle() {
Scene activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
if (IsPrefab(possession.gameObject)) {
Debug.Log("is prefab");
possession.assetPath = AssetDatabase.GetAssetPath(possession.gameObject);
string scenePath = activeScene.path;
AssetImporter assetImporter = AssetImporter.GetAtPath(possession.assetPath);
if (assetImporter != null)
assetImporter.assetBundleName = "possessions"; //activeScene.name + "_possessions";
return;
}
Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(possession.gameObject);
if (prefab != null) {
possession.assetPath = AssetDatabase.GetAssetPath(prefab);
string scenePath = activeScene.path;
AssetImporter assetImporter = AssetImporter.GetAtPath(possession.assetPath);
assetImporter.assetBundleName = "possessions"; //activeScene.name + "_possessions";
//Debug.Log(possession.gameObject + ": Set AssetBundleName to " + assetImporter.assetBundleName);
}
}
public static bool IsPrefab(GameObject gameObject) {
PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(gameObject);
if (prefabStage == null)
return false;
else
return true;
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
serializedObject.Update();
PossessionTypeInspector();
CrossSitePossession();
IsUniqueInspector();
serializedObject.ApplyModifiedProperties();
}
protected void PossessionTypeInspector() {
SerializedProperty possessionTypeProp = serializedObject.FindProperty("possessionType");
possessionTypeProp.intValue = (int)(Possessable.Type)EditorGUILayout.EnumPopup("Possession Type", (Possessable.Type)possessionTypeProp.intValue);
}
protected void CrossSitePossession() {
SerializedProperty crossSiteProp = serializedObject.FindProperty("crossSite");
crossSiteProp.boolValue = EditorGUILayout.Toggle("Cross Site Allowed", crossSiteProp.boolValue);
}
protected void IsUniqueInspector() {
SerializedProperty isUniqueProp = serializedObject.FindProperty("crossSite");
isUniqueProp.boolValue = EditorGUILayout.Toggle("Is Unique", isUniqueProp.boolValue);
}
#endregion
}
}

View File

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

287
Editor/Sites/SiteBuilder.cs Normal file
View File

@ -0,0 +1,287 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using System.IO;
namespace Passer {
/// <summary>
/// A component for building \ref Site "Humanoid Sites"
/// </summary>
///
/// Sites can be built by selecting the _File->Build Sites_ menu.
/// After this you will be able to select which sites will be built
/// by selecting the appropriate sites in the dialog:
///
/// \image html BuildSitesDialog.png
///
/// When the Build button is pressed, all sites will be build and become available in the Assets/SiteBuilds folder
/// with a submap for each platform (like Windows, Android...)
///
/// When the Build to Folder is pressed, the built sites will additionally be copied to the selected target folder.
/// This enables you to directly publish to a web site for instance.
///
/// \version 4 and higher
[InitializeOnLoad]
public class SiteBuilder {
static SiteBuilder() {
if (siteBuilds == null) {
siteBuilds = AssetDatabase.LoadAssetAtPath<Sites>("Assets/HumanoidControl/Runtime/Sites/SiteList.asset");
if (siteBuilds == null) {
siteBuilds = (Sites)ScriptableObject.CreateInstance(typeof(Sites));
AssetDatabase.CreateAsset(siteBuilds, "Assets/HumanoidControl/Runtime/Sites/SiteList.asset");
}
}
bool hasChanged = false;
string[] assetbundles = AssetDatabase.GetAllAssetBundleNames();
for (int i = 0; i < assetbundles.Length; i++) {
Sites.SiteBuild siteBuild = siteBuilds.list.Find(sb => sb.siteName == assetbundles[i]);
if (siteBuild == null) {
siteBuild = new Sites.SiteBuild() {
siteName = assetbundles[i],
enabled = true,
};
siteBuilds.list.Add(siteBuild);
hasChanged = true;
}
}
if (hasChanged)
AssetDatabase.SaveAssets();
}
public static Sites siteBuilds;
private class SiteBuilderWindow : EditorWindow {
[MenuItem("File/Build Sites", false, 100)] // somehow priority does not work in File Menu?
public static void OpenWindow() {
SiteBuilderWindow window = (SiteBuilderWindow)EditorWindow.GetWindow(typeof(SiteBuilderWindow), true, "Build Sites");
window.ShowUtility();
}
private Vector2 scrollPos;
private void OnGUI() {
//GUI.contentColor = Color.red;
EditorGUILayout.LabelField("Sites in Build", EditorStyles.boldLabel);
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(true));
for (int i = 0; i < siteBuilds.list.Count; i++) {
siteBuilds.list[i].enabled = EditorGUILayout.ToggleLeft(siteBuilds.list[i].siteName, siteBuilds.list[i].enabled);
}
EditorGUILayout.EndScrollView();
bool buildSites = false;
bool buildToFolder = false;
using (new GUILayout.HorizontalScope()) {
GUILayout.FlexibleSpace();
buildSites = GUILayout.Button("Build", GUILayout.Width(110));
buildToFolder = GUILayout.Button("Build to Folder", GUILayout.Width(110));
}
if (buildSites) BuildSites("");
if (buildToFolder) StartBuildToFolder();
}
}
private static void StartBuildToFolder() {
string savePath = EditorUtility.SaveFolderPanel("Target folder", "", "");
BuildSites(savePath);
}
/// <summary>
/// Build all sites in this project and save them in the indicated location
/// </summary>
/// Currently this function will build all sites for Windows and Android platforms only.
/// <param name="savePath">The full path to the folder in which the sites should be saved</param>
public static void BuildSites(string savePath) {
BuildWindowsSites(savePath);
BuildAndroidSites(savePath);
BuildWebGLSites(savePath);
}
/// <summary>
/// Build all sites for the Windows Standalone platform in this project and save them in the indicated location
/// </summary>
/// <param name="savePath">The full path to the folder in which the sites should be saved</param>
public static void BuildWindowsSites(string savePath) {
Debug.Log("[SiteBuilder] Building Windows Sites");
System.Console.WriteLine("[SiteBuilder] Building Windows Sites");
string assetBundleDirectory = "Assets/SiteBuilds/Windows";
if (Directory.Exists(assetBundleDirectory))
Directory.Delete(assetBundleDirectory, true);
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);
AssetBundleBuild[] buildMap = GetBuildmap();
BuildPipeline.BuildAssetBundles(assetBundleDirectory, buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
string[] filePaths = Directory.GetFiles(assetBundleDirectory);
foreach (string filePath in filePaths) {
if (!filePath.Contains(".")) {
if (filePath.Substring(filePath.Length - 8) == "\\Windows" ||
filePath.Substring(filePath.Length - 17) == "\\Windows.manifest") {
File.Delete(filePath);
File.Delete(filePath + ".meta");
continue;
}
Debug.Log("Built " + filePath);
// Rename assetbundles to include platform
string newFilePath = filePath + ".windows.site";
if (File.Exists(newFilePath))
File.Delete(newFilePath);
File.Move(filePath, newFilePath);
// Rename .meta
string newMetaPath = newFilePath + ".meta";
string metaPath = filePath + ".meta";
if (File.Exists(newMetaPath))
File.Delete(newMetaPath);
if (File.Exists(metaPath))
File.Move(metaPath, newMetaPath);
if (savePath != "") {
int slashPos = newFilePath.LastIndexOf("\\");
string fileName = newFilePath.Substring(slashPos + 1);
string saveFilePath = savePath + "/" + fileName;
System.Console.WriteLine("[SiteBuilder] Copy " + newFilePath + " to " + saveFilePath);
File.Copy(newFilePath, saveFilePath, true);
}
}
}
}
/// <summary>
/// Build all sites for the Android platform in this project and save them in the indicated location
/// </summary>
/// <param name="savePath">The full path to the folder in which the sites should be saved</param>
public static void BuildAndroidSites(string savePath) {
Debug.Log("[SiteBuilder] Building Android Sites");
System.Console.WriteLine("[SiteBuilder] Building Android Sites");
string assetBundleDirectory = "Assets/SiteBuilds/Android";
if (Directory.Exists(assetBundleDirectory))
Directory.Delete(assetBundleDirectory, true);
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);
AssetBundleBuild[] buildMap = GetBuildmap();
BuildPipeline.BuildAssetBundles(assetBundleDirectory, buildMap, BuildAssetBundleOptions.None, BuildTarget.Android);
string[] filePaths = Directory.GetFiles(assetBundleDirectory);
foreach (string filePath in filePaths) {
if (!filePath.Contains(".")) {
if (filePath.Substring(filePath.Length - 8) == "\\Android" ||
filePath.Substring(filePath.Length - 17) == "\\Android.manifest") {
File.Delete(filePath);
File.Delete(filePath + ".meta");
continue;
}
Debug.Log("Built " + filePath);
string newFilePath = filePath + ".android.site";
if (File.Exists(newFilePath))
File.Delete(newFilePath);
File.Move(filePath, newFilePath);
// Rename .meta
string newMetaPath = newFilePath + ".meta";
string metaPath = filePath + ".meta";
if (File.Exists(newMetaPath))
File.Delete(newMetaPath);
if (File.Exists(metaPath))
File.Move(metaPath, newMetaPath);
if (savePath != "") {
int slashPos = newFilePath.LastIndexOf("\\");
string fileName = newFilePath.Substring(slashPos + 1);
string saveFilePath = savePath + "/" + fileName;
System.Console.WriteLine("[SiteBuilder] Copy " + newFilePath + " to " + saveFilePath);
File.Copy(newFilePath, saveFilePath, true);
}
}
}
}
/// <summary>
/// Build all sites for the WebGL platform in this project and save them in the indicated location
/// </summary>
/// <param name="savePath">The full path to the folder in which the sites should be saved</param>
public static void BuildWebGLSites(string savePath) {
Debug.Log("[SiteBuilder] Building WebGL Sites");
System.Console.WriteLine("[SiteBuilder] Building WebGL Sites");
string assetBundleDirectory = "Assets/SiteBuilds/WebGL";
if (Directory.Exists(assetBundleDirectory))
Directory.Delete(assetBundleDirectory, true);
if (!Directory.Exists(assetBundleDirectory))
Directory.CreateDirectory(assetBundleDirectory);
AssetBundleBuild[] buildMap = GetBuildmap();
BuildPipeline.BuildAssetBundles(assetBundleDirectory, buildMap, BuildAssetBundleOptions.None, BuildTarget.WebGL);
string[] filePaths = Directory.GetFiles(assetBundleDirectory);
foreach (string filePath in filePaths) {
if (!filePath.Contains(".")) {
if (filePath.Substring(filePath.Length - 6) == "\\WebGL" ||
filePath.Substring(filePath.Length - 15) == "\\WebGL.manifest") {
File.Delete(filePath);
File.Delete(filePath + ".meta");
continue;
}
Debug.Log("Built " + filePath);
string newFilePath = filePath + ".webgl.site";
if (File.Exists(newFilePath))
File.Delete(newFilePath);
File.Move(filePath, newFilePath);
// Rename .meta
string newMetaPath = newFilePath + ".meta";
string metaPath = filePath + ".meta";
if (File.Exists(newMetaPath))
File.Delete(newMetaPath);
if (File.Exists(metaPath))
File.Move(metaPath, newMetaPath);
if (savePath != "") {
int slashPos = newFilePath.LastIndexOf("\\");
string fileName = newFilePath.Substring(slashPos + 1);
string saveFilePath = savePath + "/" + fileName;
System.Console.WriteLine("[SiteBuilder] Copy " + newFilePath + " to " + saveFilePath);
File.Copy(newFilePath, saveFilePath, true);
}
}
}
}
protected static AssetBundleBuild[] GetBuildmap() {
List<AssetBundleBuild> buildList = new List<AssetBundleBuild>();
for (int i = 0; i < siteBuilds.list.Count; i++) {
if (siteBuilds.list[i].enabled == false)
continue;
AssetBundleBuild build = new AssetBundleBuild();
build.assetBundleName = siteBuilds.list[i].siteName;
string[] AssetsInBundle = AssetDatabase.GetAssetPathsFromAssetBundle(build.assetBundleName);
build.assetNames = AssetsInBundle;
buildList.Add(build);
}
AssetBundleBuild[] buildMap = buildList.ToArray();
return buildMap;
}
}
}

View File

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

View File

@ -0,0 +1,117 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace Passer {
using Humanoid;
[CustomEditor(typeof(SiteNavigator))]
public class SiteNavigator_Editor : Editor {
protected SiteNavigator siteNavigator;
protected string[] siteNames;
#region Enable
protected virtual void OnEnable() {
siteNavigator = (SiteNavigator)target;
InitializeSiteNames();
}
protected virtual void InitializeSiteNames() {
EditorBuildSettingsScene[] editorBuildSettingsScenes = EditorBuildSettings.scenes;
int siteCount = editorBuildSettingsScenes.Length - HumanoidVisitors.visitors.Count;
List<string> siteList = new List<string>();
siteList.Add("-none-");
int j = 0;
for (int i = 0; i < siteCount; i++) {
if (!editorBuildSettingsScenes[j].enabled) {
j++;
continue;
}
string sceneName = editorBuildSettingsScenes[j].path;
int lastSlash = sceneName.LastIndexOf('/');
sceneName = sceneName.Substring(lastSlash + 1);
sceneName = sceneName.Substring(0, sceneName.Length - 6); // remove .unity
bool isVisitor = HumanoidVisitors.visitors.Contains(sceneName);
if (!isVisitor) {
//siteNames[i] = sceneName;
siteList.Add(sceneName);
j++;
}
}
siteNames = siteList.ToArray();//new string[siteCount];
}
#endregion Enable
#region Inspector
public override void OnInspectorGUI() {
serializedObject.Update();
LoadSiteAtStartInspector();
StartSiteInspector();
StartSceneInspector();
serializedObject.ApplyModifiedProperties();
}
protected void LoadSiteAtStartInspector() {
GUIContent text = new GUIContent(
"Load Site at Start",
""
);
SerializedProperty loadSiteAtStartProp = serializedObject.FindProperty(nameof(siteNavigator.loadSiteAtStart));
loadSiteAtStartProp.boolValue = EditorGUILayout.Toggle(text, loadSiteAtStartProp.boolValue);
}
protected void StartSiteInspector() {
GUIContent text = new GUIContent(
"Start Site",
""
);
SerializedProperty startSiteProp = serializedObject.FindProperty(nameof(siteNavigator.startSite));
startSiteProp.stringValue = EditorGUILayout.TextField(text, startSiteProp.stringValue);
}
protected void StartSceneInspector() {
GUIContent text = new GUIContent(
"Start Scene",
""
);
SerializedProperty startSceneProp = serializedObject.FindProperty(nameof(siteNavigator.startScene));
if (siteNames == null || siteNames.Length == 0) {
startSceneProp.stringValue = "";
return;
}
int ix = 0;
for (; ix < siteNames.Length; ix++) {
if (siteNames[ix] == startSceneProp.stringValue)
break;
}
if (ix == siteNames.Length) ix = 0;
if (Application.isPlaying) {
using (new EditorGUI.DisabledScope(true)) {
EditorGUILayout.Popup(text, ix, siteNames);
}
}
else {
ix = EditorGUILayout.Popup(text, ix, siteNames);
startSceneProp.stringValue = siteNames[ix];
}
}
#endregion Inspector
}
}

View File

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

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(Site))]
public class Site_Editor : Editor {
protected Site site;
private Humanoid.Configuration configuration;
private string[] personalHumanoidNames;
#region Enable
private void OnEnable() {
site = (Site)target;
Scene activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
string scenePath = activeScene.path;
AssetImporter assetImporter = AssetImporter.GetAtPath(scenePath);
assetImporter.assetBundleName = activeScene.name;
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
serializedObject.ApplyModifiedProperties();
}
#endregion Inspector
}
}

View File

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

8
Editor/Tools.meta Normal file
View File

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

View File

@ -0,0 +1,63 @@
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(CollisionEventHandler))]
public class CollisionEventHandler_Editor : Editor {
protected CollisionEventHandler eventHandler;
#region Enable
protected virtual void OnEnable() {
eventHandler = (CollisionEventHandler)target;
InitEvents();
}
#endregion
#region Disable
protected virtual void OnDisable() {
CleanupEvents();
}
#endregion
#region Inspector
public override void OnInspectorGUI() {
serializedObject.Update();
EventsInspector();
serializedObject.ApplyModifiedProperties();
}
#region Events
protected GameObjectEventHandlers[] eventLists;
protected SerializedProperty[] eventListProps;
protected SerializedProperty collisionEventProp;
protected void InitEvents() {
eventLists = new GameObjectEventHandlers[] {
eventHandler.collisionHandlers,
};
collisionEventProp = serializedObject.FindProperty("collisionHandlers");
}
protected int selectedEvent = -1;
protected int selectedSub = -1;
protected void EventsInspector() {
GameObjectEvent_Editor.EventInspector(collisionEventProp, eventHandler.collisionHandlers, ref selectedEvent, ref selectedSub);
}
protected void CleanupEvents() {
foreach (GameObjectEventHandlers eventList in eventLists)
GameObjectEvent_Editor.Cleanup(eventList);
}
#endregion
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bf8f19f53465b6a42a45d554263dae88
timeCreated: 1551351700
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(Comment))]
public class Comment_Editor : Editor {
public override void OnInspectorGUI() {
serializedObject.Update();
EditorStyles.textField.wordWrap = true;
SerializedProperty textProp = serializedObject.FindProperty("text");
textProp.stringValue = EditorGUILayout.TextArea(textProp.stringValue);
serializedObject.ApplyModifiedProperties();
}
}
}

View File

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

View File

@ -0,0 +1,243 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Passer {
public class Condition_Editor {
public static string GetConditionLabel(SerializedProperty conditionProp) {
SerializedProperty targetProp = conditionProp.FindPropertyRelative("targetGameObject");
if (targetProp.objectReferenceValue == null)
return "";
string targetName = targetProp.objectReferenceValue.ToString();
int braceIndex = targetName.IndexOf('(');
if (braceIndex > 0)
targetName = targetName.Substring(0, braceIndex - 1);
string label = "[" + targetName + "]";
SerializedProperty propertyNameProp = conditionProp.FindPropertyRelative("fullPropertyName");
string propertyName = propertyNameProp.stringValue;
label += propertyNameProp.stringValue;
SerializedProperty propertyTypeProp = conditionProp.FindPropertyRelative("propertyType");
Condition.PropertyType propertyType = (Condition.PropertyType)propertyTypeProp.intValue;
SerializedProperty operandIndexProp = conditionProp.FindPropertyRelative("operandIndex");
int operandIndex = operandIndexProp.intValue;
switch (propertyType) {
case Condition.PropertyType.Bool:
label += " " + Condition.boolOperands[operandIndex];
break;
case Condition.PropertyType.Int:
label += " " + Condition.intOperands[operandIndex];
SerializedProperty intConstantProp = conditionProp.FindPropertyRelative("intConstant");
label += " " + intConstantProp.intValue;
break;
case Condition.PropertyType.Float:
label += " " + Condition.floatOperands[operandIndex];
SerializedProperty floatConstantProp = conditionProp.FindPropertyRelative("floatConstant");
label += " " + floatConstantProp.floatValue;
break;
case Condition.PropertyType.Object:
label += " " + Condition.objectOperands[operandIndex];
break;
}
return label;
}
public static void ConditionInspector(SerializedProperty conditionProp) {
if (conditionProp == null)
return;
GUIStyle style = new GUIStyle(GUI.skin.box) {
margin = new RectOffset(0, 0, 0, 0)
};
Rect rect = EditorGUILayout.BeginVertical(style);
GUI.Box(rect, "", style);
int indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 1;
SerializedProperty targetProp = ConditionTargetInspector(conditionProp);
ConditionPropertyInspector(conditionProp, targetProp);
EditorGUILayout.BeginHorizontal();
ConditionOperandInspector(conditionProp);
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel = indentLevel;
EditorGUILayout.EndVertical();
}
public static void AppendNewCondition(SerializedProperty conditionsProp) {
int conditionsCount = conditionsProp.arraySize;
conditionsProp.InsertArrayElementAtIndex(conditionsCount);
SerializedProperty functionCallProp = conditionsProp.GetArrayElementAtIndex(conditionsCount);
SerializedProperty targetProp = functionCallProp.FindPropertyRelative("targetGameObject");
targetProp.objectReferenceValue = null;
}
#region Target
protected static SerializedProperty ConditionTargetInspector(SerializedProperty conditionProp) {
SerializedProperty targetProp = conditionProp.FindPropertyRelative("targetGameObject");
GUIContent text = new GUIContent(
"Target",
"The Object on which the method is called"
);
EditorGUILayout.ObjectField(targetProp, text);
return targetProp;
}
#endregion
#region Property
private static System.Type ConditionPropertyInspector(SerializedProperty conditionProp, SerializedProperty targetProp) {
string componentType = "";
Object callTarget = targetProp.objectReferenceValue;
if (callTarget != null && callTarget.GetType() != typeof(GameObject))
componentType = callTarget.GetType().Name;
List<Condition.PropertyType> propertyTypes;
string[] propertyNames = GetPropertyNames(targetProp, out propertyTypes);
SerializedProperty fullPropertyNameProp = conditionProp.FindPropertyRelative("fullPropertyName");
//SerializedProperty propertyNameProp = conditionProp.FindPropertyRelative("propertyName");
int propertyNameIndex = GetPropertyIndex(/*componentType,*/ fullPropertyNameProp.stringValue, propertyNames);
propertyNameIndex = EditorGUILayout.Popup("Property", propertyNameIndex, propertyNames);
if (propertyNameIndex >= 0 && propertyNameIndex < propertyNames.Length) {
string fullPropertyName = propertyNames[propertyNameIndex];
SetProperty(conditionProp, targetProp, fullPropertyName, propertyTypes[propertyNameIndex]);
}
return null;
}
private static string[] GetPropertyNames(SerializedProperty targetProp, out List<Condition.PropertyType> propertyTypes) {
GameObject targetObject = (GameObject)targetProp.objectReferenceValue;
if (targetObject == null) {
propertyTypes = new List<Condition.PropertyType>();
return new string[0];
}
// Get all components for the targetObejct
Component[] components = targetObject.GetComponents<Component>();
// For each component, add the properties
List<string> nameList = new List<string>();
propertyTypes = new List<Condition.PropertyType>();
AddPropertyNames(ref nameList, ref propertyTypes, targetObject);
foreach (Component component in components) {
AddPropertyNames(ref nameList, ref propertyTypes, component);
}
string[] names = new string[nameList.Count];
for (int i = 0; i < nameList.Count; i++) {
names[i] = nameList[i];
}
return names;
}
private static void AddPropertyNames(ref List<string> names, ref List<Condition.PropertyType> types, Object component) {
if (component == null)
return;
System.Type componentType = component.GetType();
PropertyInfo[] properties = componentType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < properties.Length; i++) {
if (BlackListed(properties[i].Name))
continue;
if (properties[i].PropertyType == typeof(float) ||
properties[i].PropertyType == typeof(int) ||
properties[i].PropertyType == typeof(bool) ||
properties[i].PropertyType == typeof(Object)
) {
names.Add(componentType.Name + "/" + properties[i].Name);
types.Add(Condition.GetFromType(properties[i].PropertyType));
}
}
}
private static string[] blackList = {
};
private static bool BlackListed(string propertyName) {
foreach (string blackListEntry in blackList) {
if (propertyName == blackListEntry)
return true;
}
return false;
}
private static int GetPropertyIndex(/*string componentType,*/ string propertyName, string[] propertyNames) {
for (int i = 0; i < propertyNames.Length; i++) {
if (propertyName == propertyNames[i])
return i;
}
return -1;
}
private static void SetProperty(
SerializedProperty conditionProp, SerializedProperty targetProp,
string fullPropertyName, Condition.PropertyType propertyType) {
//int slashPos = fullPropertyName.LastIndexOf("/");
GameObject callTargetObject = Event_Editor.GetTargetGameObject(targetProp);
if (callTargetObject != null) {
//string componentType = fullPropertyName.Substring(0, slashPos);
targetProp.objectReferenceValue = callTargetObject;
}
SerializedProperty fullPropertyNameProp = conditionProp.FindPropertyRelative("fullPropertyName");
fullPropertyNameProp.stringValue = fullPropertyName;
SerializedProperty propertyTypeProp = conditionProp.FindPropertyRelative("propertyType");
propertyTypeProp.intValue = (int)propertyType;
}
#endregion
#region Operand
private static void ConditionOperandInspector(SerializedProperty conditionProp) {
SerializedProperty propertyTypeProp = conditionProp.FindPropertyRelative("propertyType");
SerializedProperty operandIndexProp = conditionProp.FindPropertyRelative("operandIndex");
Condition.PropertyType propertyType = (Condition.PropertyType)propertyTypeProp.intValue;
switch (propertyType) {
case Condition.PropertyType.Bool:
operandIndexProp.intValue = EditorGUILayout.Popup(" ", operandIndexProp.intValue, Condition.boolOperands);
break;
case Condition.PropertyType.Int:
operandIndexProp.intValue = EditorGUILayout.Popup(operandIndexProp.intValue, Condition.intOperands, GUILayout.MaxWidth(120));
SerializedProperty intConstantProp = conditionProp.FindPropertyRelative("intConstant");
intConstantProp.intValue = EditorGUILayout.IntField(intConstantProp.intValue);
break;
case Condition.PropertyType.Float:
operandIndexProp.intValue = EditorGUILayout.Popup(operandIndexProp.intValue, Condition.floatOperands, GUILayout.MaxWidth(120));
SerializedProperty floatConstantProp = conditionProp.FindPropertyRelative("floatConstant");
floatConstantProp.floatValue = EditorGUILayout.FloatField(floatConstantProp.floatValue);
break;
case Condition.PropertyType.Object:
operandIndexProp.intValue = EditorGUILayout.Popup(operandIndexProp.intValue, Condition.objectOperands);
break;
default:
return;
}
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 59c8435b1c2081c40aaff93023a634da
timeCreated: 1564304070
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,111 @@
using UnityEngine;
using UnityEditor;
namespace Passer {
[CustomEditor(typeof(Counter), true)]
public class Counter_Editor : Editor {
protected Counter counter;
#region Enable
protected virtual void OnEnable() {
counter = (Counter)target;
}
#endregion Enable
#region Inspector
public override void OnInspectorGUI() {
serializedObject.Update();
ValueInspector();
MinInspector();
MaxInspector();
TimerInspector();
NetworkingInspector();
EventsInspector(counter);
if (Application.isPlaying)
Buttons();
serializedObject.ApplyModifiedProperties();
}
protected void ValueInspector() {
SerializedProperty valueProp = serializedObject.FindProperty("_value");
valueProp.intValue = EditorGUILayout.IntField("Value", valueProp.intValue);
}
protected void MinInspector() {
SerializedProperty minProp = serializedObject.FindProperty("min");
minProp.intValue = EditorGUILayout.IntField("Minimum", minProp.intValue);
}
protected void MaxInspector() {
SerializedProperty maxProp = serializedObject.FindProperty("max");
maxProp.intValue = EditorGUILayout.IntField("Maximum", maxProp.intValue);
}
protected void TimerInspector() {
SerializedProperty timerProp = serializedObject.FindProperty("timer");
timerProp.floatValue = EditorGUILayout.FloatField("Timer", timerProp.floatValue);
}
protected virtual void NetworkingInspector() {
#if hNW_PHOTON
SerializedProperty networkingProp = serializedObject.FindProperty(nameof(Counter.networking));
networkingProp.boolValue = EditorGUILayout.Toggle("Network Sync", networkingProp.boolValue);
if (networkingProp.boolValue) {
Photon.Pun.PhotonView photonView = counter.GetComponent<Photon.Pun.PhotonView>();
if (photonView == null) {
counter.gameObject.AddComponent<Photon.Pun.PhotonView>();
}
}
#endif
}
protected virtual void Buttons() {
EditorGUILayout.BeginHorizontal();
DecrementButton();
IncrementButton();
EditorGUILayout.EndHorizontal();
}
protected virtual void DecrementButton() {
if (GUILayout.Button("Decrement"))
counter.Decrement();
}
protected virtual void IncrementButton() {
if (GUILayout.Button("Increment"))
counter.Increment();
}
#endregion Inspector
#region Events
protected bool showEvents;
protected int selectedEventSource = -1;
protected int selectedEvent;
protected virtual void EventsInspector(Counter counter) {
showEvents = EditorGUILayout.Foldout(showEvents, "Events", true);
if (showEvents) {
EditorGUI.indentLevel++;
SerializedProperty counterEventProp = serializedObject.FindProperty("counterEvent");
IntEvent_Editor.EventInspector(counterEventProp, counter.counterEvent, ref selectedEventSource, ref selectedEvent);
}
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9ed53a946a9ce95459817ea0b3b11863
timeCreated: 1564565060
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
Editor/Tools/Events.meta Normal file
View File

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

View File

@ -0,0 +1,59 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
namespace Passer {
public class BoolEvent_Editor : Event_Editor {
public static void EventInspector(
SerializedProperty eventSourceProp, BoolEventHandlers eventSource,
ref int selectedEventSourceIx, ref int selectedEventIx) {
EventInspector(eventSourceProp, ref selectedEventSourceIx, ref selectedEventIx,
BoolMethodCheck, InitBoolEvent);
}
protected static void InitBoolEvent(SerializedProperty eventProp) {
}
protected static bool BoolMethodCheck(MethodInfo method, out string label) {
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0 && method.ReturnType == typeof(void)) {
label = method.Name + " ()";
return true;
}
else if (parameters.Length == 1 && (
parameters[0].ParameterType == typeof(bool)
)) {
label = method.Name + " (" + parameters[0].ParameterType.Name + ")";
return true;
}
label = "";
return false;
}
protected static SerializedProperty DetailsTypeInspector(SerializedProperty eventProp) {
GUIContent text = new GUIContent(
"Event Type",
"Never: the function is never called\n" +
"OnStart: when the boolean becomes true\n" +
"OnEnd: when the boolean becomes false\n" +
"WhileActive: while the bool is true\n" +
"WhileInactive: while the bool is false\n" +
"OnChange: when the bool value changes\n" +
"Continuous: the function is called for every frame"
);
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
eventTypeProp.intValue = (int)(EventHandler.Type)EditorGUILayout.EnumPopup(text, (EventHandler.Type)eventTypeProp.intValue);
return eventTypeProp;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bdbc48da826150e47b4c7993401149a7
timeCreated: 1551346543
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,60 @@
using UnityEditor;
using UnityEngine.Events;
namespace Passer {
public class ControllerEvent_Editor : FloatEvent_Editor {
public static void EventInspector(
SerializedProperty eventHandlerProp,
ref int selectedEventIx, ref int selectedEventHandlerIx, bool showOverrideMode = false) {
EventInspector(eventHandlerProp, ref selectedEventIx, ref selectedEventHandlerIx,
EventMethodCheck, InitControllerEvent, null, showOverrideMode) ;
SetParameterOnEvents(eventHandlerProp);
}
public static void SetParameterOnEvents(SerializedProperty eventHandlersProp) {
SerializedProperty defaultParameterPropertyProp = eventHandlersProp.FindPropertyRelative("defaultParameterProperty");
string defaultParameterProperty = defaultParameterPropertyProp.stringValue;
SerializedProperty eventsProp = eventHandlersProp.FindPropertyRelative("events");
int eventCount = eventsProp.arraySize;
for (int i = 0; i < eventCount; i++) {
SerializedProperty eventHandlerProp = eventsProp.GetArrayElementAtIndex(i);
SetParameterOnEvent(eventHandlerProp, defaultParameterProperty);
}
}
protected static void SetParameterOnEvent(SerializedProperty eventHandlerProp, string defaultParameterProperty) {
SerializedProperty parametersProp = eventHandlerProp.FindPropertyRelative("functionCall.parameters");
int parameterCount = parametersProp.arraySize;
if (parameterCount != 1)
return; // no support for more than 1 parameter yet, 0 parameters: nothing to do
SerializedProperty parameterProp = parametersProp.GetArrayElementAtIndex(0);
SerializedProperty parameterTypeProp = parameterProp.FindPropertyRelative("type");
SerializedProperty propertyNameProp = parameterProp.FindPropertyRelative("localProperty");
if (propertyNameProp.stringValue == "") {
switch ((FunctionCall.ParameterType)parameterTypeProp.intValue) {
case FunctionCall.ParameterType.Float:
propertyNameProp.stringValue = defaultParameterProperty;
break;
}
}
}
public static void InitControllerEvent(SerializedProperty eventProp) {
SerializedProperty functionParametersProp = eventProp.FindPropertyRelative("functionCall.parameters");
if (functionParametersProp.arraySize == 0)
functionParametersProp.InsertArrayElementAtIndex(0);
SerializedProperty parameter0Prop = functionParametersProp.GetArrayElementAtIndex(0);
parameter0Prop.FindPropertyRelative("fromEvent").boolValue = true;
parameter0Prop.FindPropertyRelative("localProperty").stringValue = "From Event";
InitFloatEvent(eventProp);
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ddcf94c88c8845e40a1b201ac9f20c81
timeCreated: 1550151605
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,686 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Passer {
public class Event_Editor {
public static bool showParameterSettings = false;
public delegate bool MethodCheck(MethodInfo method, out string label);
public delegate void InitEvent(SerializedProperty eventProp);
public delegate void LabelField(SerializedProperty eventHandlerProp);
public static void EventInspector(
SerializedProperty eventHandlerProp,
ref int selectedEventSourceIx, ref int selectedEventIx,
MethodCheck methodCheck,
InitEvent InitEvent,
LabelField LabelField = null,
bool showOverrideMode = false
) {
if (!Application.isPlaying)
CheckEmptySlot(eventHandlerProp, InitEvent);
SerializedProperty eventsProp = eventHandlerProp.FindPropertyRelative("events");
int eventCount = eventsProp.arraySize;
string[] eventTypeLabels = GetEventTypeLabels(eventHandlerProp);
SerializedProperty eventIdProp = eventHandlerProp.FindPropertyRelative("id");
bool selected = eventIdProp.intValue == selectedEventSourceIx;
for (int i = 0; i < eventCount; i++) {
EditorGUILayout.BeginHorizontal();
if (i == 0) {
if (LabelField == null) {
SerializedProperty eventLabel = eventHandlerProp.FindPropertyRelative("label");
EditorGUILayout.LabelField(eventLabel.stringValue, GUILayout.Width(140));
}
else
LabelField(eventHandlerProp);
}
else
EditorGUILayout.LabelField(" ", GUILayout.Width(140));
SerializedProperty selectedButton = eventsProp.GetArrayElementAtIndex(i);
if (selected && selectedEventIx == i) {
EventDetails(eventHandlerProp, selectedButton, methodCheck, eventTypeLabels, InitEvent, showOverrideMode);
}
else {
string label = GetButtonLabel(selectedButton, eventTypeLabels);
if (GUILayout.Button(label)) {
selectedEventSourceIx = eventIdProp.intValue;
selectedEventIx = i;
}
}
EditorGUILayout.EndHorizontal();
}
if (eventCount > 1)
EditorGUILayout.Space();
}
protected static void CheckEmptySlot(
SerializedProperty eventHandlerProp,
InitEvent InitEvent) {
SerializedProperty eventsProp = eventHandlerProp.FindPropertyRelative("events");
int eventCount = eventsProp.arraySize;
if (eventCount == 0) {
eventsProp.InsertArrayElementAtIndex(0);
SerializedProperty eventProp = eventsProp.GetArrayElementAtIndex(0);
InitEvent(eventProp);
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
eventTypeProp.intValue = 0;
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty eventTargetGameObjectProp = functionCallProp.FindPropertyRelative("targetGameObject");
eventTargetGameObjectProp.objectReferenceValue = null;
}
else {
SerializedProperty lastEventProp = eventsProp.GetArrayElementAtIndex(eventCount - 1);
SerializedProperty lastEventTypeProp = lastEventProp.FindPropertyRelative("eventType");
if (lastEventTypeProp.intValue != 0) {
eventsProp.InsertArrayElementAtIndex(eventCount);
SerializedProperty eventProp = eventsProp.GetArrayElementAtIndex(eventCount);
InitEvent(eventProp);
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
eventTypeProp.intValue = 0;
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty eventTargetGameObjectProp = functionCallProp.FindPropertyRelative("targetGameObject");
eventTargetGameObjectProp.objectReferenceValue = null;
}
}
}
public static string GetButtonLabel(SerializedProperty eventProp, string[] eventTypeLabels) {
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
EventHandler.Type eventType = (EventHandler.Type)eventTypeProp.intValue;
//if (eventType == EventHandler.Type.Never)
// return "";
string eventTypeLabel = eventTypeLabels[eventTypeProp.intValue];
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty eventTargetGameObjectProp = functionCallProp.FindPropertyRelative("targetGameObject");
if (eventTargetGameObjectProp.objectReferenceValue == null)
return "";
string targetName = eventTargetGameObjectProp.objectReferenceValue.ToString();
int braceIndex = targetName.IndexOf('(');
if (braceIndex > 0)
targetName = targetName.Substring(0, braceIndex - 1);
string methodName = GetTargetMethodName(eventProp);
methodName = methodName.Replace('/', '.');
string label = eventTypeLabel + ": [" + targetName + "]" + methodName;
SerializedProperty parametersProp = functionCallProp.FindPropertyRelative("parameters");
if (parametersProp.arraySize == 0) {
label += "()";
return label;
}
SerializedProperty parameterProp = parametersProp.GetArrayElementAtIndex(0);
SerializedProperty fromEventProp = parameterProp.FindPropertyRelative("fromEvent");
if (fromEventProp.boolValue) {
label += "(...)";
return label;
}
SerializedProperty parameterTypeProp = parameterProp.FindPropertyRelative("type");
switch ((FunctionCall.ParameterType)parameterTypeProp.intValue) {
case FunctionCall.ParameterType.Void:
label += "()";
break;
case FunctionCall.ParameterType.Float:
SerializedProperty floatValueProp = parameterProp.FindPropertyRelative("floatConstant");
label += "(" + floatValueProp.floatValue + ")";
break;
case FunctionCall.ParameterType.Bool:
SerializedProperty boolValueProp = parameterProp.FindPropertyRelative("boolConstant");
label += "(" + boolValueProp.boolValue + ")";
break;
case FunctionCall.ParameterType.Int:
SerializedProperty intValueProp = parameterProp.FindPropertyRelative("intConstant");
label += "(" + intValueProp.intValue + ")";
break;
case FunctionCall.ParameterType.String:
SerializedProperty stringValueProp = parameterProp.FindPropertyRelative("stringConstant");
label += "(" + stringValueProp.stringValue + ")";
break;
default:
label += "(...)";
break;
}
return label;
}
protected static string GetTargetMethodName(SerializedProperty eventProp) {
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty methodNameProp = functionCallProp.FindPropertyRelative("methodName");
string methodName = methodNameProp.stringValue;
if (methodName == "Execute") {
// user Custom Script Name
SerializedProperty eventTargetProp = functionCallProp.FindPropertyRelative("target");
Object eventTarget = eventTargetProp.objectReferenceValue;
if (eventTarget is Script) {
Script script = (Script)eventTarget;
return script.scriptName;
}
}
int ix = methodName.LastIndexOf('.');
if (ix > -1) {
methodName = methodName.Substring(ix + 1);
}
return methodName;
}
#region Details
protected static void EventDetails(
SerializedProperty eventHandlerProp, SerializedProperty eventSourceProp,
MethodCheck methodCheck, string[] eventTypeLabels, InitEvent InitEvent, bool showOverrideMode) {
if (eventSourceProp == null)
return;
GUIStyle style = new GUIStyle(GUI.skin.box) {
margin = new RectOffset(0, 0, 4, 10)
};
Rect rect = EditorGUILayout.BeginVertical(style);
GUI.Box(rect, "", style);
int indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 1;
EventTypeInspector(eventSourceProp, eventTypeLabels);
EventTargetInspector(eventHandlerProp, eventSourceProp, methodCheck, InitEvent);
#if hNW_PHOTON
EventNetworkingInspector(eventSourceProp);
#endif
ParameterOptionsInspector(eventSourceProp);
if (showOverrideMode)
OverrideModeInspector(eventSourceProp);
EditorGUI.indentLevel = indentLevel;
EditorGUILayout.EndVertical();
}
private static string[] GetEventTypeLabels(SerializedProperty eventSourceProp) {
SerializedProperty eventTypeLabelsProp = eventSourceProp.FindPropertyRelative("eventTypeLabels");
string[] eventTypeLabels = new string[7];
if (eventTypeLabelsProp.arraySize == 7) {
for (int i = 0; i < eventTypeLabelsProp.arraySize; i++) {
SerializedProperty eventTypeLabelProp = eventTypeLabelsProp.GetArrayElementAtIndex(i);
eventTypeLabels[i] = eventTypeLabelProp.stringValue;
}
}
else {
for (int i = 0; i < 7; i++) {
eventTypeLabels[i] = ((EventHandler.Type)i).ToString();
}
}
return eventTypeLabels;
}
public static SerializedProperty EventTypeInspector(SerializedProperty eventProp, string[] eventTypeLabels) {
SerializedProperty eventTypeProp = eventProp.FindPropertyRelative("eventType");
using (new EditorGUILayout.HorizontalScope()) {
GUIContent text = new GUIContent(
"Event Type",
"Never: the function is never called\n" +
"OnStart: when the button is pressed\n" +
"OnEnd: when the button is released\n" +
"WhileActive: while the button is pressed\n" +
"WhileInactive: while the button is released\n" +
"OnChange: when the button press changes\n" +
"Continuous: the function is called for every frame"
);
EditorGUILayout.LabelField(text.text, GUILayout.Width(90));
eventTypeProp.intValue = EditorGUILayout.Popup(eventTypeProp.intValue, eventTypeLabels);
}
return eventTypeProp;
}
protected static void OverrideModeInspector(SerializedProperty eventProp) {
SerializedProperty overrideModeProp = eventProp.FindPropertyRelative("overrideMode");
using (new EditorGUILayout.HorizontalScope()) {
GUIContent text = new GUIContent(
"Add by",
"How will this handler interact with existing handlers?"
);
EditorGUILayout.LabelField(text.text, GUILayout.Width(90));
overrideModeProp.intValue = (int)(EventHandler.OverrideMode)EditorGUILayout.EnumPopup((EventHandler.OverrideMode)overrideModeProp.intValue);
}
}
#region Event Target
protected static void EventTargetInspector(
SerializedProperty eventHandlerProp, SerializedProperty eventProp,
MethodCheck methodCheck, InitEvent InitEvent) {
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty functionParametersProp = eventProp.FindPropertyRelative("functionCall.parameters");
if (functionParametersProp.arraySize == 0)
InitEvent(eventProp);
SerializedProperty eventTargetGameObjectProp = functionCallProp.FindPropertyRelative("targetGameObject");
GUIContent text = new GUIContent(
"Target",
"The Object on which the method is called"
);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(text, GUILayout.Width(90));
eventTargetGameObjectProp.objectReferenceValue = EditorGUILayout.ObjectField(eventTargetGameObjectProp.objectReferenceValue, typeof(GameObject), true);
EditorGUILayout.EndHorizontal();
SerializedProperty parametersProp = functionCallProp.FindPropertyRelative("parameters");
if (parametersProp.arraySize > 0) {
SerializedProperty parameterProp = parametersProp.GetArrayElementAtIndex(0);
if (!parameterProp.FindPropertyRelative("fromEvent").boolValue) {
methodCheck = ConstantCheck;
}
}
// Component / Method
string[] methodNames = GetMethodNames(eventTargetGameObjectProp, methodCheck);
SerializedProperty methodNameProp = functionCallProp.FindPropertyRelative("methodName");
int methodNameIndex = GetMethodIndex(methodNameProp.stringValue, methodNames);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Method", GUILayout.Width(90));
methodNameIndex = EditorGUILayout.Popup(methodNameIndex, methodNames);
EditorGUILayout.EndHorizontal();
if (methodNameIndex >= 0 && methodNameIndex < methodNames.Length) {
string fullMethodName = methodNames[methodNameIndex];
SetMethod(functionCallProp, fullMethodName);
SerializedProperty newFunctionCallProp = eventProp.FindPropertyRelative("functionCallFloat");
if (newFunctionCallProp != null) {
SerializedProperty newEventTargetGameObjectProp = newFunctionCallProp.FindPropertyRelative("targetGameObject");
SerializedProperty newMethodNameProp = newFunctionCallProp.FindPropertyRelative("methodName");
newEventTargetGameObjectProp.objectReferenceValue = eventTargetGameObjectProp.objectReferenceValue;
newMethodNameProp.stringValue = methodNameProp.stringValue;
}
MethodParametersInspector(eventProp, eventHandlerProp);
}
}
private static bool ConstantCheck(MethodInfo method, out string label) {
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0 && method.ReturnType == typeof(void)) {
label = method.Name + " ()";
return true;
}
else if (parameters.Length == 1) {
label = method.Name + " (" + parameters[0].ParameterType.Name + ")";
return true;
}
label = "";
return false;
}
#endregion
#region Method
public static int GetMethodIndex(string methodName, string[] methodNames) {
for (int i = 0; i < methodNames.Length; i++) {
int brace1Pos = methodNames[i].LastIndexOf("(");
if (methodName == methodNames[i].Substring(0, brace1Pos - 1))
return i;
}
return -1;
}
public static string[] GetMethodNames(SerializedProperty targetGameObjectProp, MethodCheck methodCheck) {
GameObject callTargetObject = (GameObject)targetGameObjectProp.objectReferenceValue;
if (callTargetObject == null)
return new string[0];
Component[] components = callTargetObject.GetComponents<Component>();
List<string> nameList = new List<string>();
AddMethodNames(ref nameList, callTargetObject, methodCheck);
foreach (Component component in components) {
AddMethodNames(ref nameList, component, methodCheck);
}
string[] names = new string[nameList.Count];
for (int i = 0; i < nameList.Count; i++) {
names[i] = nameList[i];
}
return names;
}
public static GameObject GetTargetGameObject(SerializedProperty callTargetProp) {
Object callTarget = callTargetProp.objectReferenceValue;
if (callTarget == null)
return null;
if (callTarget.GetType() == typeof(GameObject))
return (GameObject)callTarget;
else
return ((Component)callTarget).gameObject;
}
protected static void AddMethodNames(ref List<string> names, Object component, MethodCheck methodCheck) {
if (component == null)
return;
System.Type componentType = component.GetType();
MethodInfo[] methods = componentType.GetMethods(BindingFlags.Public | BindingFlags.Instance);
for (int i = 0; i < methods.Length; i++) {
if (BlackListed(methods[i].Name))
continue;
if (methods[i].ReturnType != typeof(void))
continue;
if (componentType == typeof(Script) && component is Script) {
Script script = (Script)component;
names.Add("Script/" + script.scriptName + " ()");
}
else {
string methodLabel;
if (methodCheck(methods[i], out methodLabel)) {
names.Add(componentType.FullName + "/" + methodLabel);
}
}
}
if (componentType == typeof(Humanoid.HumanoidControl)) {
AddAnimatorParameterMethods(ref names, component);
}
}
protected static void AddAnimatorParameterMethods(ref List<string> names, Object component) {
Humanoid.HumanoidControl humanoid = component as Humanoid.HumanoidControl;
if (humanoid == null || humanoid.targetsRig.runtimeAnimatorController == null)
return;
AnimatorControllerParameter[] animatorParameters = humanoid.targetsRig.parameters;
for (int i = 0; i < animatorParameters.Length; i++) {
string fullMethodName = "SetAnimatorParameter/" + animatorParameters[i].name;
switch (animatorParameters[i].type) {
case AnimatorControllerParameterType.Bool:
fullMethodName += " (Boolean)";
break;
case AnimatorControllerParameterType.Float:
fullMethodName += " (Single)";
break;
case AnimatorControllerParameterType.Int:
fullMethodName += " (Int32)";
break;
case AnimatorControllerParameterType.Trigger:
default:
break;
}
names.Add(fullMethodName);
}
}
protected static string[] blackList = {
"GetComponentInChildren",
"GetComponentsInChildren",
"GetComponentsInParent",
"SetSiblingIndex",
"set_hasChanged",
"set_active",
"GetChild",
"set_hierarchyCapacity",
"set_useGUILayout",
"set_runInEditMode",
"CancelInvoke",
"StopAllCoroutines",
"Awake",
"Start",
"Update",
"FixedUpdate",
"OnApplicationQuit",
"DetachChildren",
"SetAsFirstSibling",
"SetAsLastSibling",
"IsInvoking",
"StopCoroutine",
"SetAnimationParameterTrigger" // is done via SetAnimationParamater construction
};
public static bool BlackListed(string methodName) {
foreach (string blackListEntry in blackList) {
if (methodName == blackListEntry)
return true;
}
return false;
}
public static void SetMethod(SerializedProperty functionCallProp, string fullMethodName) {
int brace1Pos = fullMethodName.LastIndexOf("(");
int brace2Pos = fullMethodName.LastIndexOf(")");
string methodName = fullMethodName.Substring(0, brace1Pos - 1);
SerializedProperty methodNameProp = functionCallProp.FindPropertyRelative("methodName");
methodNameProp.stringValue = methodName;
string parameterTypeName = fullMethodName.Substring(brace1Pos + 1, brace2Pos - brace1Pos - 1);
SerializedProperty parametersProp = functionCallProp.FindPropertyRelative("parameters");
SerializedProperty parameterProp;
if (parametersProp.arraySize <= 0) {
parametersProp.InsertArrayElementAtIndex(0);
parameterProp = parametersProp.GetArrayElementAtIndex(0);
InitParameter(parameterProp);
}
else {
parameterProp = parametersProp.GetArrayElementAtIndex(0);
}
SerializedProperty parameterTypeProp = parameterProp.FindPropertyRelative("type");
switch (parameterTypeName) {
case "Single":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Float;
break;
case "Int32":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Int;
break;
case "Boolean":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Bool;
break;
case "String":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.String;
break;
case "Vector3":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Vector3;
break;
case "GameObject":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.GameObject;
break;
case "Rigidbody":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Rigidbody;
break;
case "Object":
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Void;
break;
default:
parameterTypeProp.intValue = (int)FunctionCall.ParameterType.Void;
break;
}
}
protected static void InitParameter(SerializedProperty parameterProp) {
parameterProp.FindPropertyRelative("fromEvent").boolValue = true;
}
public static bool EventMethodCheck(MethodInfo method, out string label) {
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length == 0 && method.ReturnType == typeof(void)) {
label = method.Name + " ()";
return true;
}
else if (parameters.Length == 1 && (
parameters[0].ParameterType == typeof(float) ||
parameters[0].ParameterType == typeof(int) ||
parameters[0].ParameterType == typeof(bool) ||
parameters[0].ParameterType == typeof(string) ||
parameters[0].ParameterType == typeof(Vector3) ||
parameters[0].ParameterType == typeof(GameObject) ||
parameters[0].ParameterType == typeof(Rigidbody) ||
parameters[0].ParameterType.IsEnum
)) {
label = method.Name + " (" + parameters[0].ParameterType.Name + ")";
return true;
}
else if (parameters.Length == 1 && parameters[0].ParameterType.IsSubclassOf(typeof(Object))) {
label = method.Name + " (Object)";
return true;
}
label = "";
return false;
}
#endregion
#region Parameters
public static void MethodParametersInspector(SerializedProperty eventProp, SerializedProperty eventHandlerProp) {
SerializedProperty functionCallProp = eventProp.FindPropertyRelative("functionCall");
SerializedProperty parametersProp = functionCallProp.FindPropertyRelative("parameters");
if (parametersProp.arraySize == 0)
return;
SerializedProperty parameterProp = parametersProp.GetArrayElementAtIndex(0);
SerializedProperty parameterTypeProp = parameterProp.FindPropertyRelative("type");
FunctionCall.ParameterType parameterType = (FunctionCall.ParameterType)parameterTypeProp.intValue;
if (parameterType == FunctionCall.ParameterType.Void)
return;
System.Type parameterSystemType = FunctionCall.ToSystemType(parameterType);
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Parameter", GUILayout.Width(120));
int indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
FunctionCall_Editor.PropertyParameterInspector(parameterProp.serializedObject, parameterProp, parameterSystemType);
EditorGUI.indentLevel = indentLevel;
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
#endregion
protected static void EventNetworkingInspector(SerializedProperty eventProp) {
GUIContent text = new GUIContent(
"Networking",
"When enabled, the event will be synchronized across the network"
);
SerializedProperty eventNetworkingProp = eventProp.FindPropertyRelative("eventNetworking");
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(text, GUILayout.Width(90));
eventNetworkingProp.boolValue = EditorGUILayout.Toggle(eventNetworkingProp.boolValue);
EditorGUILayout.EndHorizontal();
}
public static void ParameterOptionsInspector(SerializedProperty eventSourceProp) {
SerializedProperty functionCallProp = eventSourceProp.FindPropertyRelative("functionCall");
SerializedProperty parametersProp = functionCallProp.FindPropertyRelative("parameters");
if (parametersProp.arraySize == 0)
return;
SerializedProperty parameterProp = parametersProp.GetArrayElementAtIndex(0);
SerializedProperty parameterTypeProp = parameterProp.FindPropertyRelative("type");
FunctionCall.ParameterType parameterType = (FunctionCall.ParameterType)parameterTypeProp.intValue;
showParameterSettings = EditorGUILayout.Foldout(showParameterSettings, "Options", true);
if (showParameterSettings) {
EditorGUI.indentLevel++;
switch (parameterType) {
case FunctionCall.ParameterType.Float:
MultiplicationInspector(eventSourceProp);
TriggerLevelInspector(eventSourceProp);
break;
case FunctionCall.ParameterType.Int:
MultiplicationInspector(eventSourceProp);
TriggerLevelInspector(eventSourceProp);
break;
case FunctionCall.ParameterType.Bool:
TriggerLevelInspector(eventSourceProp);
InverseInspector(eventSourceProp);
break;
default:
TriggerLevelInspector(eventSourceProp);
break;
}
EditorGUI.indentLevel--;
}
}
protected static SerializedProperty MultiplicationInspector(SerializedProperty eventProp) {
GUIContent text = new GUIContent(
"Multiplication",
"Multiply the value before calling event trigger"
);
SerializedProperty multiplicationProp = eventProp.FindPropertyRelative("multiplicationFactor");
multiplicationProp.floatValue = EditorGUILayout.FloatField(text, multiplicationProp.floatValue);
return multiplicationProp;
}
protected static void TriggerLevelInspector(SerializedProperty eventProp) {
SerializedProperty floatTriggerLowProp = eventProp.FindPropertyRelative("floatTriggerLow");
SerializedProperty floatTriggerHighProp = eventProp.FindPropertyRelative("floatTriggerHigh");
float floatTriggerLow = floatTriggerLowProp.floatValue;
float floatTriggerHigh = floatTriggerHighProp.floatValue;
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Trigger Level", GUILayout.MinWidth(115));
int indentLevel = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
floatTriggerLow = EditorGUILayout.FloatField(floatTriggerLow, GUILayout.Width(40));
EditorGUILayout.MinMaxSlider(ref floatTriggerLow, ref floatTriggerHigh, -1, 1);
floatTriggerHigh = EditorGUILayout.FloatField(floatTriggerHigh, GUILayout.Width(40));
EditorGUI.indentLevel = indentLevel;
EditorGUILayout.EndHorizontal();
floatTriggerLowProp.floatValue = floatTriggerLow;
floatTriggerHighProp.floatValue = floatTriggerHigh;
}
protected static SerializedProperty InverseInspector(SerializedProperty eventProp) {
GUIContent text = new GUIContent(
"Inverse",
"Negate the boolean state before calling event trigger"
);
SerializedProperty boolInverseProp = eventProp.FindPropertyRelative("boolInverse");
boolInverseProp.boolValue = EditorGUILayout.Toggle(text, boolInverseProp.boolValue);
return boolInverseProp;
}
#endregion
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6f789752f3d51344fad00118ef8c1e81
timeCreated: 1555502438
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More