using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
public enum DisplayMode
{
[InspectorName("2D")]
TwoD,
[InspectorName("3D")]
ThreeD
}
public class CameraFeed : MonoBehaviour
{
public DisplayMode displayMode;
public Renderer cameraPlaneRenderer;
public RawImage cameraDisplay;
void Start()
{
WebCamTexture webcamTexture = new WebCamTexture();
if (displayMode == DisplayMode.TwoD)
{
cameraDisplay.texture = webcamTexture;
}
else if (displayMode == DisplayMode.ThreeD)
{
cameraPlaneRenderer.material.mainTexture = webcamTexture;
}
webcamTexture.Play();
}
}
[CustomEditor(typeof(CameraFeed))]
public class CameraFeedEditor : Editor
{
public override void OnInspectorGUI()
{
CameraFeed cameraFeed = (CameraFeed)target;
cameraFeed.displayMode = (DisplayMode)EditorGUILayout.EnumPopup("Display Mode", cameraFeed.displayMode);
if (cameraFeed.displayMode == DisplayMode.TwoD)
{
cameraFeed.cameraDisplay = (RawImage)EditorGUILayout.ObjectField("Camera Display (2D)", cameraFeed.cameraDisplay, typeof(RawImage), true);
}
else if (cameraFeed.displayMode == DisplayMode.ThreeD)
{
cameraFeed.cameraPlaneRenderer = (Renderer)EditorGUILayout.ObjectField("Camera Plane Renderer (3D)", cameraFeed.cameraPlaneRenderer, typeof(Renderer), true);
}
}
}