Skip to content

Commit

Permalink
1.1.0 (#2)
Browse files Browse the repository at this point in the history
* fix vector3 value diff in property output

* fix sending vector3.xz in property output

* add support for fields to property output

* fix monitor window state

* re-serialize property sender scene

* move member variable in receiver inspector

* remove public memberinfo accesor

* add sorting to properties and fields

* remove unused editor using
  • Loading branch information
Stella Cannefax authored Feb 25, 2020
1 parent 0402b85 commit d133d19
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 113 deletions.
24 changes: 16 additions & 8 deletions Editor/Scripts/Inspectors/Input/OscReceiverInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class OscReceiverInspector : Editor
SerializedProperty m_PortProp;

bool m_ShowAddressFoldout;
bool m_PreviouslyRunning;

void OnEnable()
{
Expand All @@ -28,21 +29,28 @@ void OnEnable()
public override void OnInspectorGUI()
{
var running = m_Target != null && m_Target.Running;
if (running != m_PreviouslyRunning)
SortAddresses();

m_PreviouslyRunning = running;

EditorGUI.BeginDisabledGroup(running && Application.IsPlaying(this));
EditorGUILayout.PropertyField(m_PortProp);
EditorGUI.EndDisabledGroup();

var count = CountHandlers();
var prefix = m_ShowAddressFoldout ? "Hide" : "Show";
m_ShowAddressFoldout = EditorGUILayout.Foldout(m_ShowAddressFoldout, $"{prefix} {count} Listening Addresses", true);

if (m_ShowAddressFoldout)
using (new EditorGUI.DisabledScope(!running))
{
foreach (var addr in k_SortedAddresses)
EditorGUILayout.LabelField(addr, EditorStyles.miniBoldLabel);
var count = CountHandlers();
var prefix = m_ShowAddressFoldout ? "Hide" : "Show";
m_ShowAddressFoldout = EditorGUILayout.Foldout(m_ShowAddressFoldout, $"{prefix} {count} Listening Addresses", true);

if (m_ShowAddressFoldout)
{
foreach (var addr in k_SortedAddresses)
EditorGUILayout.LabelField(addr, EditorStyles.miniBoldLabel);
}
}

serializedObject.ApplyModifiedProperties();

if (EditorHelp.Show)
Expand Down
69 changes: 56 additions & 13 deletions Editor/Scripts/Inspectors/Output/PropertyOutputInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ namespace OscCore
[CustomEditor(typeof(PropertyOutput), true)]
class PropertyOutputInspector : Editor
{
class MemberInfoComparer : IComparer<MemberInfo>
{
public int Compare(MemberInfo x, MemberInfo y)
{
return string.Compare(x?.Name, y?.Name, StringComparison.Ordinal);
}
}

static readonly MemberInfoComparer k_MemberComparer = new MemberInfoComparer();

static readonly GUIContent k_EmptyContent = new GUIContent();
static readonly GUIContent k_PropTypeContent = new GUIContent("Type", "The type of the selected property");
static readonly GUIContent k_ComponentContent = new GUIContent("Component",
Expand Down Expand Up @@ -41,7 +51,7 @@ class PropertyOutputInspector : Editor
string m_PreviousComponentName;
int m_ComponentIndex;

PropertyInfo[] m_Properties;
MemberInfo[] m_PropertiesAndFields;
string[] m_PropertyNames;
int m_PropertyIndex;

Expand Down Expand Up @@ -97,7 +107,7 @@ void OnEnable()

m_ComponentIndex = Array.IndexOf(m_CachedComponentNames, sourceCompRef.GetType().Name);
if(m_ComponentIndex >= 0)
GetComponentProperties();
GetComponentFieldsAndProperties();

if (sourceCompRef != null)
{
Expand Down Expand Up @@ -159,7 +169,7 @@ void ComponentDropdown()
m_ComponentIndex = newIndex;
var compName = m_CachedComponentNames[newIndex];
if (compName != m_PreviousComponentName)
GetComponentProperties();
GetComponentFieldsAndProperties();

m_PropertyIndex = -1;
m_PreviousComponentName = compName;
Expand All @@ -182,10 +192,23 @@ void PropertyDropdown()
m_PropertyIndex = newIndex;
m_PropertyNameProp.stringValue = m_PropertyNames[m_PropertyIndex];

var info = m_Properties[m_PropertyIndex];
var type = info.PropertyType;
m_PropertyTypeNameProp.stringValue = type.Name;
m_Target.Property = info;
var info = m_PropertiesAndFields[m_PropertyIndex];

Type type;
var asProp = info as PropertyInfo;
if (asProp != null)
{
type = asProp.PropertyType;
m_Target.Property = asProp;
}
else
{
var asField = info as FieldInfo;
m_Target.Field = asField;
type = asField?.FieldType;
}

m_PropertyTypeNameProp.stringValue = type?.Name;

m_DrawVector3Filter = type == typeof(Vector3);
m_DrawVector2Filter = type == typeof(Vector2);
Expand All @@ -209,7 +232,6 @@ void PropertyDropdown()
}
}


void DrawVector3ElementFilter()
{
using (new EditorGUILayout.HorizontalScope())
Expand Down Expand Up @@ -276,19 +298,40 @@ void DrawVector2ElementFilter()
m_PreviousVec2FilterEnumValue = enumValueIndex;
}

void GetComponentProperties()
void GetComponentFieldsAndProperties()
{
var comp = m_CachedComponents[m_ComponentIndex];
var properties = comp.GetType().GetProperties();
m_Properties = properties.Where(p => k_SupportedTypes.Contains(p.PropertyType.FullName)).ToArray();
m_PropertyNames = m_Properties.Select(m => m.Name).ToArray();

var type = comp.GetType();
var properties = type.GetProperties()
.Where(p => k_SupportedTypes.Contains(p.PropertyType.FullName)).ToArray();

var fields = type.GetFields()
.Where(f => k_SupportedTypes.Contains(f.FieldType.FullName)).ToArray();

m_PropertiesAndFields = new MemberInfo[properties.Length + fields.Length];

int i;
for (i = 0; i < properties.Length; i++)
{
m_PropertiesAndFields[i] = properties[i];
}

var fieldsStart = i;
for (; i < m_PropertiesAndFields.Length; i++)
{
m_PropertiesAndFields[i] = fields[i - fieldsStart];
}

Array.Sort(m_PropertiesAndFields, k_MemberComparer);
m_PropertyNames = m_PropertiesAndFields.Select(m => m.Name).ToArray();
}

void CleanComponents()
{
m_CachedComponents = null;
m_CachedComponentNames = null;
m_Properties = null;
m_PropertiesAndFields = null;
m_PropertyNames = null;
m_ComponentIndex = -1;
m_PropertyIndex = -1;
Expand Down
41 changes: 34 additions & 7 deletions Editor/Scripts/MonitorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public class MonitorWindow : EditorWindow
bool m_UseAlt;
List<string> m_ActiveQueueBuffer;

string m_ServerLabel = "";

bool m_NeedsRepaint;
bool m_ShowNoServerWarning;
int m_PreviousServerCount;

bool m_PreviouslyPlaying;

void OnEnable()
{
m_PreviousServerCount = 0;
m_ActiveQueueBuffer = m_ToQueue;
if (OscServer.PortToServer.Count == 0)
m_ShowNoServerWarning = true;
Expand All @@ -38,33 +43,57 @@ void OnEnable()
void OnDisable()
{
m_Server?.RemoveMonitorCallback(Monitor);
m_PreviousServerCount = 0;
}

void HandleServerChanges()
{
if (m_PreviousServerCount == 0 && OscServer.PortToServer.Count > 0)
if (OscServer.PortToServer.Count > m_PreviousServerCount)
{
m_Server = OscServer.PortToServer.First().Value;
m_Server.AddMonitorCallback(Monitor);
m_PreviousServerCount = OscServer.PortToServer.Count;
m_ServerLabel = $"Messages being received on port {m_Server.Port}";
m_ShowNoServerWarning = false;

if (!Application.isPlaying)
EditorApplication.update += Update;
}
else if (m_PreviousServerCount > 0 && OscServer.PortToServer.Count == 0)
else if (OscServer.PortToServer.Count < m_PreviousServerCount)
{
m_Server?.RemoveMonitorCallback(Monitor);
m_Server = null;
m_ServerLabel = null;
m_ShowNoServerWarning = true;
m_PreviousServerCount = OscServer.PortToServer.Count;

if (!Application.isPlaying)
EditorApplication.update -= Update;
}

m_PreviousServerCount = OscServer.PortToServer.Count;
}

void HandleModeChange()
{
if (EditorApplication.isPlaying != m_PreviouslyPlaying)
{
m_PreviousServerCount = 0;
lock (m_LogMessages)
{
m_LogMessages.Clear();
m_ToQueueAlt.Clear();
m_ToQueue.Clear();
}
}

m_PreviouslyPlaying = EditorApplication.isPlaying;
}

void Update()
{
// only run every 10 frames to reduce flickering
if (Time.frameCount % 10 != 0) return;
if (Time.frameCount % 2 != 0) return;

HandleModeChange();
HandleServerChanges();

lock (m_LogMessages)
Expand Down Expand Up @@ -110,8 +139,6 @@ void Update()
if(m_NeedsRepaint) Repaint();
}

string m_ServerLabel = "";

public void OnGUI()
{
const string noServerWarning = "No OSC Servers are currently active, so no messages can be received";
Expand Down
51 changes: 10 additions & 41 deletions Runtime/Scenes/Property Sender Example.unity
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ LightmapSettings:
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 0
m_LightmapEditorSettings:
serializedVersion: 12
serializedVersion: 10
m_Resolution: 2
m_BakeResolution: 10
m_AtlasSize: 512
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
Expand All @@ -77,26 +76,18 @@ LightmapSettings:
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 256
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 256
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVREnvironmentMIS: 0
m_PVRFilteringMode: 2
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_ShowResolutionOverlay: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
Expand Down Expand Up @@ -146,14 +137,12 @@ Light:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 170076733}
m_Enabled: 1
serializedVersion: 10
serializedVersion: 8
m_Type: 1
m_Shape: 0
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 0.3
m_Range: 10
m_SpotAngle: 30
m_InnerSpotAngle: 21.80208
m_CookieSize: 10
m_Shadows:
m_Type: 2
Expand All @@ -163,40 +152,19 @@ Light:
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_CullingMatrixOverride:
e00: 1
e01: 0
e02: 0
e03: 0
e10: 0
e11: 1
e12: 0
e13: 0
e20: 0
e21: 0
e22: 1
e23: 0
e30: 0
e31: 0
e32: 0
e33: 1
m_UseCullingMatrixOverride: 0
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingLayerMask: 1
m_Lightmapping: 4
m_LightShadowCasterMode: 0
m_AreaSize: {x: 0.52, y: 0.22}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &170076735
Expand Down Expand Up @@ -251,10 +219,9 @@ Camera:
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0}
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2
Expand Down Expand Up @@ -330,9 +297,10 @@ MonoBehaviour:
m_Sender: {fileID: 1670121833}
m_Address: /composition/layers/1/video/opacity
m_Object: {fileID: 170076733}
m_SourceComponent: {fileID: 170076734}
m_PropertyName: intensity
m_PropertyTypeName: Single
m_SourceComponent: {fileID: 170076735}
m_MemberIsProperty: 1
m_PropertyName: childCount
m_PropertyTypeName: Int32
m_SendVector2Elements: 0
m_SendVector3Elements: 0
--- !u!4 &1670121832
Expand Down Expand Up @@ -379,6 +347,7 @@ MonoBehaviour:
m_Address: /composition/layers/2/video/opacity
m_Object: {fileID: 1670121830}
m_SourceComponent: {fileID: 1670121832}
m_MemberIsProperty: 1
m_PropertyName: position
m_PropertyTypeName: Vector3
m_SendVector2Elements: 0
Expand Down
Loading

0 comments on commit d133d19

Please sign in to comment.