-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from Autumn60/feature/commonPublisher
Feature/common publisher
- Loading branch information
Showing
33 changed files
with
296 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using UnityEngine; | ||
using UnityEditor; | ||
|
||
namespace UnitySensors.Attribute | ||
{ | ||
[CustomPropertyDrawer(typeof(InterfaceAttribute))] | ||
public class InterfaceTypeDrawer : PropertyDrawer | ||
{ | ||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | ||
{ | ||
InterfaceAttribute ia = attribute as InterfaceAttribute; | ||
|
||
if (property.propertyType != SerializedPropertyType.ObjectReference) return; | ||
|
||
MonoBehaviour old = property.objectReferenceValue as MonoBehaviour; | ||
|
||
GameObject temp = null; | ||
string oldName = ""; | ||
|
||
if (Event.current.type == EventType.Repaint) | ||
{ | ||
if (old == null) | ||
{ | ||
temp = new GameObject("None [" + ia.type.Name + "]"); | ||
old = temp.AddComponent<Interface>(); | ||
} | ||
else | ||
{ | ||
oldName = old.name; | ||
old.name = oldName + " [" + ia.type.Name + "]"; | ||
} | ||
} | ||
|
||
MonoBehaviour present = EditorGUI.ObjectField(position, label, old, typeof(MonoBehaviour), true) as MonoBehaviour; | ||
|
||
if (Event.current.type == EventType.Repaint) | ||
{ | ||
if (temp != null) | ||
GameObject.DestroyImmediate(temp); | ||
else | ||
old.name = oldName; | ||
} | ||
|
||
if (old == present) return; | ||
|
||
if (present != null) | ||
{ | ||
if (present.GetType() != ia.type) | ||
present = present.gameObject.GetComponent(ia.type) as MonoBehaviour; | ||
|
||
if (present == null) return; | ||
} | ||
|
||
property.objectReferenceValue = present; | ||
property.serializedObject.ApplyModifiedProperties(); | ||
} | ||
} | ||
|
||
public class Interface : MonoBehaviour | ||
{ | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/UnitySensors/Editor/Attributes/InterfaceDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
Assets/UnitySensors/Runtime/Scripts/Attributes/InterfaceAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using UnityEngine; | ||
using System; | ||
|
||
namespace UnitySensors.Attribute | ||
{ | ||
public class InterfaceAttribute : PropertyAttribute | ||
{ | ||
public Type type; | ||
|
||
public InterfaceAttribute(Type type) | ||
{ | ||
this.type = type; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/UnitySensors/Runtime/Scripts/Attributes/InterfaceAttribute.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
...ySensors/Runtime/Scripts/Visualizers/Sensor/PointCloud/DepthCameraPointCloudVisualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
using UnityEngine; | ||
using UnitySensors.Attribute; | ||
using UnitySensors.DataType.Sensor.PointCloud; | ||
using UnitySensors.Interface.Sensor; | ||
|
||
namespace UnitySensors.Visualization.Sensor | ||
{ | ||
public class DepthCameraPointCloudVisualizer : PointCloudVisualizer<PointXYZ> | ||
{ | ||
[SerializeField, Interface(typeof(IPointCloudInterface<PointXYZ>))] | ||
private Object _source; | ||
|
||
protected override void Start() | ||
{ | ||
base.SetSource(_source as IPointCloudInterface<PointXYZ>); | ||
base.Start(); | ||
} | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
...s/UnitySensors/Runtime/Scripts/Visualizers/Sensor/PointCloud/LiDARPointCloudVisualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
using UnityEngine; | ||
using UnitySensors.Attribute; | ||
using UnitySensors.DataType.Sensor.PointCloud; | ||
using UnitySensors.Interface.Sensor; | ||
|
||
namespace UnitySensors.Visualization.Sensor | ||
{ | ||
public class LiDARPointCloudVisualizer : PointCloudVisualizer<PointXYZI> | ||
{ | ||
[SerializeField, Interface(typeof(IPointCloudInterface<PointXYZI>))] | ||
private Object _source; | ||
|
||
protected override void Start() | ||
{ | ||
base.SetSource(_source as IPointCloudInterface<PointXYZI>); | ||
base.Start(); | ||
} | ||
} | ||
} | ||
} |
13 changes: 12 additions & 1 deletion
13
...tySensors/Runtime/Scripts/Visualizers/Sensor/PointCloud/RGBDCameraPointCloudVisualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
using UnityEngine; | ||
using UnitySensors.Attribute; | ||
using UnitySensors.DataType.Sensor.PointCloud; | ||
using UnitySensors.Interface.Sensor; | ||
|
||
namespace UnitySensors.Visualization.Sensor | ||
{ | ||
public class RGBDCameraPointCloudVisualizer : PointCloudVisualizer<PointXYZRGB> | ||
{ | ||
[SerializeField, Interface(typeof(IPointCloudInterface<PointXYZRGB>))] | ||
private Object _source; | ||
|
||
protected override void Start() | ||
{ | ||
base.SetSource(_source as IPointCloudInterface<PointXYZRGB>); | ||
base.Start(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 1 addition & 15 deletions
16
Assets/UnitySensors/Runtime/Scripts/Visualizers/Visualizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,11 @@ | ||
using UnityEngine; | ||
using UnitySensors.Attribute; | ||
using UnitySensors.Sensor; | ||
|
||
namespace UnitySensors.Visualization | ||
{ | ||
public abstract class Visualizer : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private MonoBehaviour _source; | ||
|
||
private void Start() | ||
{ | ||
if(_source is UnitySensor) | ||
{ | ||
UnitySensor sensor = (UnitySensor)_source; | ||
sensor.onSensorUpdated += Visualize; | ||
} | ||
|
||
Init(_source); | ||
} | ||
|
||
protected abstract void Init(MonoBehaviour source); | ||
protected abstract void Visualize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.