【m】插件上传

This commit is contained in:
2026-04-28 16:48:04 +08:00
parent 459db5ec01
commit 753878bdbb
631 changed files with 91583 additions and 11 deletions

View File

@@ -0,0 +1,112 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(BitrateAttribute))]
class BitrateDrawer : PropertyDrawer
{
SerializedProperty propertyMinimum;
SerializedProperty propertyMaximum;
bool cache = false;
bool changed = false;
int minLimit;
int maxLimit;
static readonly GUIContent s_bitrateLabel =
EditorGUIUtility.TrTextContent("Bitrate (kbits/sec)", "A range of bitrate of streaming.");
static readonly GUIContent s_minBitrateLabel =
EditorGUIUtility.TrTextContent("Min");
static readonly GUIContent s_maxBitrateLabel =
EditorGUIUtility.TrTextContent("Max");
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (!cache)
{
propertyMinimum = property.FindPropertyInChildren("min");
propertyMaximum = property.FindPropertyInChildren("max");
var attr = attribute as BitrateAttribute;
minLimit = attr.minValue;
maxLimit = attr.maxValue;
property.Reset();
cache = true;
}
var rect = position;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.BeginProperty(rect, label, property);
float minValue = propertyMinimum.intValue;
float maxValue = propertyMaximum.intValue;
// slider
EditorGUI.BeginChangeCheck();
rect = EditorGUI.PrefixLabel(rect, s_bitrateLabel);
EditorGUI.MinMaxSlider(rect, ref minValue, ref maxValue, minLimit, maxLimit);
int min = (int)minValue;
int max = (int)maxValue;
if (EditorGUI.EndChangeCheck())
{
propertyMinimum.intValue = min;
propertyMaximum.intValue = max;
changed = true;
}
EditorGUI.EndProperty();
// min value
EditorGUI.BeginChangeCheck();
rect.y += EditorGUIUtility.singleLineHeight;
min = EditorGUI.IntField(rect, s_minBitrateLabel, min);
if (EditorGUI.EndChangeCheck())
{
min = Mathf.Max(min, minLimit);
min = Mathf.Min(min, max);
propertyMinimum.intValue = min;
changed = true;
}
// max value
EditorGUI.BeginChangeCheck();
rect.y += EditorGUIUtility.singleLineHeight;
max = EditorGUI.IntField(rect, s_maxBitrateLabel, max);
if (EditorGUI.EndChangeCheck())
{
max = Mathf.Min(max, maxLimit);
max = Mathf.Max(min, max);
propertyMaximum.intValue = max;
changed = true;
}
if (changed)
{
if (Application.isPlaying)
{
var objectReferenceValue = property.serializedObject.targetObject;
var type = objectReferenceValue.GetType();
var attribute = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var methodName = "SetBitrate";
var method = type.GetMethod(methodName, attribute);
method.Invoke(objectReferenceValue, new object[] { (uint)min, (uint)max });
}
changed = false;
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
//var height = 0f;
return EditorGUIUtility.singleLineHeight * 3;
//return height;
}
}
}

View File

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

View File

@@ -0,0 +1,284 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(CodecAttribute))]
class CodecDrawer : PropertyDrawer
{
interface Codec
{
string name { get; }
string mimeType { get; }
string sdpFmtpLine { get; }
int channelCount { get; }
int sampleRate { get; }
string optionTitle { get; }
int order { get; }
}
class AudioCodec : Codec
{
public string name { get { return codec_.name; } }
public string mimeType { get { return codec_.mimeType; } }
public string sdpFmtpLine { get { return codec_.sdpFmtpLine; } }
public int channelCount { get { return codec_.channelCount; } }
public int sampleRate { get { return codec_.sampleRate; } }
public string optionTitle
{
get
{
return $"{codec_.channelCount} channel";
}
}
public int order { get { return codec_.channelCount; } }
public AudioCodec(AudioCodecInfo codec)
{
codec_ = codec;
}
AudioCodecInfo codec_;
}
class VideoCodec : Codec
{
public string name { get { return codec_.name; } }
public string mimeType { get { return codec_.mimeType; } }
public string sdpFmtpLine { get { return codec_.sdpFmtpLine; } }
public string optionTitle
{
get
{
switch (codec_)
{
case H264CodecInfo h264Codec:
return $"{h264Codec.profile} Profile, Level {h264Codec.level.ToString().Insert(1, ".")}";
case VP9CodecInfo vp9codec:
return $"Profile {(int)vp9codec.profile}";
case AV1CodecInfo av1codec:
return $"Profile {(int)av1codec.profile}";
}
return null;
}
}
public int channelCount { get { throw new NotSupportedException(); } }
public int sampleRate { get { throw new NotSupportedException(); } }
public int order
{
get
{
switch (codec_)
{
case H264CodecInfo h264Codec:
return (int)h264Codec.profile;
case VP9CodecInfo vp9codec:
return (int)vp9codec.profile;
case AV1CodecInfo av1codec:
return (int)av1codec.profile;
}
return 0;
}
}
public VideoCodec(VideoCodecInfo codec)
{
codec_ = codec;
}
VideoCodecInfo codec_;
}
SerializedProperty propertyMimeType;
SerializedProperty propertySdpFmtpLine;
SerializedProperty propertyChannelCount;
SerializedProperty propertySampleRate;
IEnumerable<Codec> codecs;
string[] codecNames = new string[] { "Default" };
string[] codecOptions = new string[] { };
IEnumerable<Codec> selectedCodecs;
GUIContent codecLabel;
int selectCodecIndex = 0;
int selectCodecOptionIndex = 0;
bool hasCodecOptions = false;
bool cache = false;
bool changed = false;
static readonly GUIContent s_audioCodecLabel =
EditorGUIUtility.TrTextContent("Audio Codec", "Audio encoding codec.");
static readonly GUIContent s_videoCodecLabel =
EditorGUIUtility.TrTextContent("Video Codec", "Video encoding codec.");
static IEnumerable<Codec> GetAvailableCodecs(UnityEngine.Object target)
{
if (target is VideoStreamSender)
{
return VideoStreamSender.GetAvailableCodecs().Select(codec => new VideoCodec(codec));
}
else if (target is VideoStreamReceiver)
{
return VideoStreamReceiver.GetAvailableCodecs().Select(codec => new VideoCodec(codec));
}
else if (target is AudioStreamSender)
{
return AudioStreamSender.GetAvailableCodecs().Select(codec => new AudioCodec(codec));
}
else if (target is AudioStreamReceiver)
{
return AudioStreamReceiver.GetAvailableCodecs().Select(codec => new AudioCodec(codec));
}
throw new ArgumentException();
}
static GUIContent GetCodecLabel(UnityEngine.Object target)
{
if (target is VideoStreamSender || target is VideoStreamReceiver)
{
return s_videoCodecLabel;
}
else if (target is AudioStreamSender || target is AudioStreamReceiver)
{
return s_audioCodecLabel;
}
throw new ArgumentException();
}
int FindOptionIndex(IEnumerable<Codec> codecs)
{
return Array.FindIndex(codecs.ToArray(), codec =>
{
if (codec is VideoCodec)
return codec.sdpFmtpLine == propertySdpFmtpLine.stringValue;
else
return
codec.sdpFmtpLine == propertySdpFmtpLine.stringValue &&
codec.channelCount == propertyChannelCount.intValue &&
codec.sampleRate == propertySampleRate.intValue;
});
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (!cache)
{
propertyMimeType = property.FindPropertyInChildren("m_MimeType");
propertySdpFmtpLine = property.FindPropertyInChildren("m_SdpFmtpLine");
propertyChannelCount = property.FindPropertyInChildren("m_ChannelCount");
propertySampleRate = property.FindPropertyInChildren("m_SampleRate");
codecs = GetAvailableCodecs(property.serializedObject.targetObject);
codecNames = codecNames.Concat(codecs.Select(codec => codec.name)).Distinct().ToArray();
var mimeType = propertyMimeType.stringValue;
var codecName = mimeType.GetCodecName();
selectedCodecs = codecs.Where(codec => codec.name == codecName).OrderBy(codec => codec.order);
codecOptions = selectedCodecs.Select(codec => codec.optionTitle).ToArray();
if (!selectedCodecs.Any())
selectCodecIndex = 0;
else
selectCodecIndex = Array.FindIndex(codecNames, codec => codec == codecName);
codecLabel = GetCodecLabel(property.serializedObject.targetObject);
hasCodecOptions = codecOptions.Length > 1;
if (hasCodecOptions)
selectCodecOptionIndex = FindOptionIndex(selectedCodecs);
cache = true;
}
var rect = position;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.BeginProperty(rect, label, propertyMimeType);
rect = EditorGUI.PrefixLabel(rect, codecLabel);
EditorGUI.BeginChangeCheck();
selectCodecIndex = EditorGUI.Popup(rect, selectCodecIndex, codecNames);
if (EditorGUI.EndChangeCheck())
{
if (0 < selectCodecIndex)
{
string codecName = codecNames[selectCodecIndex];
selectedCodecs = codecs.Where(codec => codec.name == codecName).OrderBy(codec => codec.order);
codecOptions = selectedCodecs.Select(codec => codec.optionTitle).ToArray();
hasCodecOptions = codecOptions.Length > 1;
var codec = selectedCodecs.First();
propertyMimeType.stringValue = codec.mimeType;
propertySdpFmtpLine.stringValue = codec.sdpFmtpLine;
if (propertyChannelCount != null)
propertyChannelCount.intValue = codec.channelCount;
if (propertySampleRate != null)
propertySampleRate.intValue = codec.sampleRate;
}
else
{
propertyMimeType.stringValue = null;
propertySdpFmtpLine.stringValue = null;
if (propertyChannelCount != null)
propertyChannelCount.intValue = 0;
if (propertySampleRate != null)
propertySampleRate.intValue = 0;
hasCodecOptions = false;
}
}
EditorGUI.EndProperty();
int codecIndex = selectCodecIndex - 1;
if (0 < codecIndex)
{
if (hasCodecOptions && 0 < codecOptions.Length)
{
// sdp fmtp line
rect.y += EditorGUIUtility.singleLineHeight;
EditorGUI.BeginProperty(rect, label, propertySdpFmtpLine);
EditorGUI.BeginChangeCheck();
selectCodecOptionIndex = EditorGUI.Popup(rect, selectCodecOptionIndex, codecOptions);
if (EditorGUI.EndChangeCheck())
{
var codec = selectedCodecs.ElementAt(selectCodecOptionIndex);
propertySdpFmtpLine.stringValue = codec.sdpFmtpLine;
if (propertyChannelCount != null)
propertyChannelCount.intValue = codec.channelCount;
if (propertySampleRate != null)
propertySampleRate.intValue = codec.sampleRate;
}
EditorGUI.EndProperty();
}
}
if (changed)
{
// todo: not supported changing codecs in play mode.
//if (Application.isPlaying)
//{
// var objectReferenceValue = property.serializedObject.targetObject;
// var type = objectReferenceValue.GetType();
// var attribute = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
// var methodName = "SetCodec";
// var method = type.GetMethod(methodName, attribute);
// method.Invoke(objectReferenceValue, new object[] { newValue });
//}
changed = false;
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property == null)
throw new System.ArgumentNullException(nameof(property));
int lineCount = hasCodecOptions ? 2 : 1;
return EditorGUIUtility.singleLineHeight * lineCount;
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ffbb807e4a1ab4440a236d73776265b3
timeCreated: 1637904184

View File

@@ -0,0 +1,99 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(FrameRateAttribute))]
class FrameRateDrawer : PropertyDrawer
{
readonly GUIContent[] frameRateText =
{
EditorGUIUtility.TrTextContent("Default"),
EditorGUIUtility.TrTextContent("10"),
EditorGUIUtility.TrTextContent("15"),
EditorGUIUtility.TrTextContent("20"),
EditorGUIUtility.TrTextContent("30"),
EditorGUIUtility.TrTextContent("60"),
};
readonly float?[] frameRateValues =
{
null,
10,
15,
20,
30,
60
};
readonly GUIContent s_FramerateLabel =
EditorGUIUtility.TrTextContent("Framerate",
"Video encoding framerate.");
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
float value = property.floatValue;
var selectIndex = 1;
while (selectIndex < frameRateValues.Length && !Mathf.Approximately(value, frameRateValues[selectIndex].Value))
{
++selectIndex;
}
// default value
if (selectIndex == frameRateValues.Length)
selectIndex = 0;
var popupRect = position;
popupRect.height = EditorGUIUtility.singleLineHeight;
selectIndex = EditorGUI.Popup(popupRect, s_FramerateLabel,
selectIndex, frameRateText);
float newValue;
var cutomValueRect = position;
cutomValueRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
cutomValueRect.height = 0;
if (0 < selectIndex && selectIndex < frameRateValues.Length)
{
newValue = frameRateValues[selectIndex].Value;
}
else
{
newValue = 0;
}
if (!Mathf.Approximately(value, newValue))
{
if (Application.isPlaying)
{
var objectReferenceValue = property.serializedObject.targetObject;
var type = objectReferenceValue.GetType();
var attribute = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var methodName = "SetFrameRate";
var method = type.GetMethod(methodName, attribute);
method.Invoke(objectReferenceValue, new object[] { newValue });
}
else
{
property.floatValue = newValue;
}
}
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property == null)
throw new System.ArgumentNullException(nameof(property));
var height = 0f;
// Popup.
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
return height;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6955fbf0f885c624786f638fdcca131a
timeCreated: 1637904184

View File

@@ -0,0 +1,27 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(RenderTextureDepthBufferAttribute))]
public class RenderTextureDepthBufferDrawer : PropertyDrawer
{
readonly GUIContent[] renderTextureDepthBuffer = new GUIContent[3]
{
EditorGUIUtility.TrTextContent("No depth buffer"),
EditorGUIUtility.TrTextContent("At least 16 bits depth (no stencil)"),
EditorGUIUtility.TrTextContent("At least 24 bits depth (with stencil)")
};
readonly int[] renderTextureDepthBufferValues = new int[3] { 0, 16, 24 };
readonly GUIContent depthBuffer = EditorGUIUtility.TrTextContent("Depth Buffer", "Format of the depth buffer.");
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.IntPopup(position, property, renderTextureDepthBuffer, renderTextureDepthBufferValues, depthBuffer);
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(RenderTextureAntiAliasingAttribute))]
public class RenderTexureAntiAliasingDrawer : PropertyDrawer
{
readonly GUIContent[] renderTextureAntiAliasing = new GUIContent[4]
{
EditorGUIUtility.TrTextContent("None"),
EditorGUIUtility.TrTextContent("2 samples"),
EditorGUIUtility.TrTextContent("4 samples"),
EditorGUIUtility.TrTextContent("8 samples")
};
readonly int[] renderTextureAntiAliasingValues = new int[4] { 1, 2, 4, 8 };
readonly GUIContent antiAliasing =
EditorGUIUtility.TrTextContent("Anti-aliasing", "Number of anti-aliasing samples.");
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.IntPopup(position, property, renderTextureAntiAliasing, renderTextureAntiAliasingValues, antiAliasing);
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,89 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(ScaleResolutionAttribute))]
class ScaleResolutionDrawer : PropertyDrawer
{
readonly GUIContent[] scaleFactorText =
{
EditorGUIUtility.TrTextContent("No Scale"),
EditorGUIUtility.TrTextContent("1 \u2215 2"),
EditorGUIUtility.TrTextContent("1 \u2215 4"),
EditorGUIUtility.TrTextContent("1 \u2215 8"),
EditorGUIUtility.TrTextContent("1 \u2215 16"),
};
readonly float[] scaleFactorValues =
{
1,
2,
4,
8,
16,
};
readonly GUIContent s_ScaleResolutionLabel =
EditorGUIUtility.TrTextContent("Scale Resolution Down",
"Downscaling video resolution to reduce bandwidth.");
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
float value = property.floatValue;
var selectIndex = 1;
while (selectIndex < scaleFactorValues.Length && !Mathf.Approximately(value, scaleFactorValues[selectIndex]))
{
++selectIndex;
}
// default value
if (selectIndex == scaleFactorValues.Length)
selectIndex = 0;
var popupRect = position;
popupRect.height = EditorGUIUtility.singleLineHeight;
selectIndex = EditorGUI.Popup(popupRect, s_ScaleResolutionLabel,
selectIndex, scaleFactorText);
float newValue;
var cutomValueRect = position;
cutomValueRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
cutomValueRect.height = 0;
newValue = scaleFactorValues[selectIndex];
if (!Mathf.Approximately(value, newValue))
{
property.floatValue = newValue;
if (Application.isPlaying)
{
var objectReferenceValue = property.serializedObject.targetObject;
var type = objectReferenceValue.GetType();
var attribute = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var methodName = "SetScaleResolutionDown";
var method = type.GetMethod(methodName, attribute);
method.Invoke(objectReferenceValue, new object[] { newValue });
}
}
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property == null)
throw new System.ArgumentNullException(nameof(property));
var height = 0f;
// Popup.
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
return height;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f81bb4eb3b702494db296db9976c321f
timeCreated: 1637904184

View File

@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(SignalingSettingsAttribute))]
class SignalingSettingsDrawer : PropertyDrawer
{
private VisualElement editorGUI;
private PopupField<string> popupFieldSignalingType;
private ISignalingSettingEditor editor;
private Dictionary<Type, SignalingSettings> table = new Dictionary<Type, SignalingSettings>();
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
editor = CreateEditor(property);
var root = new VisualElement();
root.RegisterCallback<SerializedPropertyChangeEvent, SerializedProperty>(OnSignalingSettingsObjectChange, property);
var box = new Box();
root.Add(box);
editorGUI = editor.CreateInspectorGUI(property);
popupFieldSignalingType = CreatePopUpSignalingType(property, "Signaling Type");
popupFieldSignalingType.RegisterValueChangedCallback(e => OnPopupFieldValueChange(e, property));
box.Add(popupFieldSignalingType);
box.Add(editorGUI);
return root;
}
ISignalingSettingEditor CreateEditor(SerializedProperty property)
{
var settings = fieldInfo.GetValue(property.serializedObject.targetObject) as SignalingSettings;
var type = CustomSignalingSettingsEditor.FindInspectorTypeByInspectedType(settings.GetType());
return Activator.CreateInstance(type) as ISignalingSettingEditor;
}
PopupField<string> CreatePopUpSignalingType(SerializedProperty property, string label)
{
var settings = fieldInfo.GetValue(property.serializedObject.targetObject) as SignalingSettings;
var defaultValue = CustomSignalingSettingsEditor.FindLabelByInspectedType(settings.GetType());
var choices = CustomSignalingSettingsEditor.Labels().ToList();
var field = new PopupField<string>(label: label, choices: choices, defaultValue: defaultValue);
field.tooltip = "Choose the signaling type. \"WebSocket\" or \"HTTP Polling\".";
return field;
}
static void ReplaceVisualElement(VisualElement oldValue, VisualElement newValue)
{
var root = oldValue.parent;
var index = root.IndexOf(oldValue);
root.Remove(oldValue);
root.Insert(index, newValue);
}
void OnSignalingSettingsObjectChange(SerializedPropertyChangeEvent e, SerializedProperty property)
{
var settings = fieldInfo.GetValue(property.serializedObject.targetObject) as SignalingSettings;
var label = CustomSignalingSettingsEditor.FindLabelByInspectedType(settings.GetType());
if (popupFieldSignalingType.value == label)
return;
popupFieldSignalingType.value = label;
RecreateEditorGUI(label, property);
}
void OnPopupFieldValueChange(ChangeEvent<string> e, SerializedProperty property)
{
if (!(fieldInfo.GetValue(property.serializedObject.targetObject) is SignalingSettings settings))
return;
// cache current settings.
var type = settings.GetType();
table[type] = settings;
var label = e.newValue;
RecreateEditorGUI(label, property);
}
void RecreateEditorGUI(string label, SerializedProperty property)
{
var inspectedType = CustomSignalingSettingsEditor.FindInspectedTypeByLabel(label);
if (!table.ContainsKey(inspectedType))
{
var newSettings = Activator.CreateInstance(inspectedType) as SignalingSettings;
table.Add(inspectedType, newSettings);
}
property.managedReferenceValue = table[inspectedType];
property.serializedObject.ApplyModifiedProperties();
var inspectorType = CustomSignalingSettingsEditor.FindInspectorTypeByInspectedType(inspectedType);
editor = Activator.CreateInstance(inspectorType) as ISignalingSettingEditor;
var newValue = editor.CreateInspectorGUI(property);
// Unbind old element to serializedObject.
editorGUI.Unbind();
ReplaceVisualElement(editorGUI, newValue);
editorGUI = newValue;
// bind new element to serializedObject.
editorGUI.Bind(property.serializedObject);
}
}
/// <summary>
///
/// </summary>
public interface ISignalingSettingEditor
{
VisualElement CreateInspectorGUI(SerializedProperty property);
}
[CustomSignalingSettingsEditor(typeof(HttpSignalingSettings), "HTTP Polling")]
internal class HttpSignalingSettingsEditor : ISignalingSettingEditor
{
public VisualElement CreateInspectorGUI(SerializedProperty property)
{
VisualElement root = new VisualElement();
root.Add(new PropertyField(property.FindPropertyRelative("m_url"), "URL"));
root.Add(new PropertyField(property.FindPropertyRelative("m_interval"), "Polling Interval (msec)"));
root.Add(new PropertyField(property.FindPropertyRelative("m_iceServers"), "ICE Servers"));
return root;
}
}
[CustomSignalingSettingsEditor(typeof(WebSocketSignalingSettings), "WebSocket")]
internal class WebSocketSignalingSettingsEditor : ISignalingSettingEditor
{
public VisualElement CreateInspectorGUI(SerializedProperty property)
{
VisualElement root = new VisualElement();
root.Add(new PropertyField(property.FindPropertyRelative("m_url"), "URL"));
root.Add(new PropertyField(property.FindPropertyRelative("m_iceServers"), "ICE Servers"));
return root;
}
}
}

View File

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

View File

@@ -0,0 +1,130 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace Unity.RenderStreaming.Editor
{
[CustomPropertyDrawer(typeof(StreamingSizeAttribute))]
class StreamingSizeDrawer : PropertyDrawer
{
readonly GUIContent[] streamingSizeText =
{
EditorGUIUtility.TrTextContent("640 x 480"),
EditorGUIUtility.TrTextContent("1280 x 720"),
EditorGUIUtility.TrTextContent("1600 x 1200"),
EditorGUIUtility.TrTextContent("1920 x 1200"),
EditorGUIUtility.TrTextContent("2560 x 1440"),
EditorGUIUtility.TrTextContent("Custom")
};
readonly Vector2Int[] streamingSizeValues =
{
new Vector2Int(640, 480),
new Vector2Int(1280, 720), new Vector2Int(1600, 1200),
new Vector2Int(1920, 1200), new Vector2Int(2560, 1440),
};
readonly GUIContent s_StreamingSizeLabel =
EditorGUIUtility.TrTextContent("Streaming Size",
"Streaming size should match display aspect ratio.");
readonly GUIContent s_customValueLabel =
EditorGUIUtility.TrTextContent("Custom Value",
"Supporting resolutions are difference each platforms.");
private static readonly string s_HelpBoxText =
"Note that streaming might not operate properly " +
"when set some resolutions. " +
"Platforms or type of encoders are depended.";
private bool IsCustomValue(Vector2Int value)
{
return !ArrayUtility.Contains(streamingSizeValues, value);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);
Vector2Int value = property.vector2IntValue;
var selectIndex = 0;
while (selectIndex < streamingSizeValues.Length &&
value != streamingSizeValues[selectIndex])
{
++selectIndex;
}
var popupRect = position;
popupRect.height = EditorGUIUtility.singleLineHeight;
selectIndex = EditorGUI.Popup(popupRect, s_StreamingSizeLabel,
selectIndex, streamingSizeText);
Vector2Int newValue;
var cutomValueRect = position;
cutomValueRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (selectIndex < streamingSizeValues.Length)
{
newValue = streamingSizeValues[selectIndex];
cutomValueRect.height = 0;
}
else
{
if (!IsCustomValue(value))
{
value = Vector2Int.zero;
}
cutomValueRect.height = EditorGUIUtility.singleLineHeight;
newValue = EditorGUI.Vector2IntField(cutomValueRect, s_customValueLabel, value);
}
if (property.vector2IntValue != newValue)
{
if (Application.isPlaying)
{
var objectReferenceValue = property.serializedObject.targetObject;
var type = objectReferenceValue.GetType();
var attribute = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
var methodName = "SetTextureSize";
var method = type.GetMethod(methodName, attribute);
method.Invoke(objectReferenceValue, new object[] { newValue });
}
else
{
property.vector2IntValue = newValue;
}
}
var helpBoxRect = position;
helpBoxRect.y = cutomValueRect.y + cutomValueRect.height + EditorGUIUtility.standardVerticalSpacing;
helpBoxRect.height = EditorGUIUtility.singleLineHeight * 2;
EditorGUI.HelpBox(helpBoxRect, s_HelpBoxText, MessageType.Info);
EditorGUI.EndProperty();
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property == null)
throw new System.ArgumentNullException(nameof(property));
var height = 0f;
// Popup.
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// Custom values
Vector2Int value = property.vector2IntValue;
if (IsCustomValue(value))
{
height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
//helpbox;
height += EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing;
return height;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c55e741d09a34fedbb25a0f925106b25
timeCreated: 1637904184