本文整理汇总了C#中UnityEditor.SerializedProperty.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedProperty.SetValue方法的具体用法?C# SerializedProperty.SetValue怎么用?C# SerializedProperty.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedProperty
的用法示例。
在下文中一共展示了SerializedProperty.SetValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
drawPrefixLabel = false;
Begin(position, property, label);
float min = ((SliderAttribute)attribute).min;
float max = ((SliderAttribute)attribute).max;
EditorGUI.BeginChangeCheck();
currentPosition.height = 16;
object value = property.GetValue();
if (value is int) {
property.SetValue(EditorGUI.IntSlider(currentPosition, label, (int)value, (int)min, (int)max));
}
else if (value is float) {
property.SetValue(EditorGUI.Slider(currentPosition, label, (float)value, min, max));
}
else if (value is double) {
property.SetValue(EditorGUI.Slider(currentPosition, label, (float)(double)value, min, max));
}
else {
EditorGUI.HelpBox(currentPosition, "The type of the field must be numerical.", MessageType.Error);
}
if (EditorGUI.EndChangeCheck()) {
property.Clamp(min, max);
}
End();
}
示例2: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Begin(position, property, label);
currentPosition = EditorGUI.PrefixLabel(currentPosition, label);
currentPosition.x -= 1f;
BeginIndent(0);
BeginLabelWidth(27f);
if (isEditingMin && !EditorGUIUtility.editingTextField)
{
property.SetValue("max", Mathf.Max(property.GetValue<float>("max"), property.GetValue<float>("min")));
isEditingMin = false;
}
else if (isEditingMax && !EditorGUIUtility.editingTextField)
{
property.SetValue("min", Mathf.Min(property.GetValue<float>("min"), property.GetValue<float>("max")));
isEditingMax = false;
}
EditorGUI.BeginChangeCheck();
currentPosition.width = currentPosition.width / 2f;
EditorGUI.PropertyField(currentPosition, property.FindPropertyRelative("min"));
if (EditorGUI.EndChangeCheck())
{
if (EditorGUIUtility.editingTextField)
isEditingMin = true;
else
property.SetValue("max", Mathf.Max(property.GetValue<float>("max"), property.GetValue<float>("min")));
}
EditorGUI.BeginChangeCheck();
currentPosition.x += currentPosition.width + 1f;
EditorGUI.PropertyField(currentPosition, property.FindPropertyRelative("max"));
if (EditorGUI.EndChangeCheck())
{
if (EditorGUIUtility.editingTextField)
isEditingMax = true;
else
property.SetValue("min", Mathf.Min(property.GetValue<float>("min"), property.GetValue<float>("max")));
}
EndLabelWidth();
EndIndent();
End();
}
示例3: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
drawPrefixLabel = false;
Begin(position, property, label);
property.SetValue(EditorGUI.LayerField(currentPosition, label, property.GetValue<int>()));
End();
}
示例4: ToggleButton
public void ToggleButton(SerializedProperty boolProperty, GUIContent trueLabel, GUIContent falseLabel) {
Rect indentedPosition = EditorGUI.IndentedRect(currentPosition);
boolProperty.SetValue(EditorGUI.Toggle(indentedPosition, boolProperty.GetValue<bool>(), new GUIStyle("button")));
if (boolProperty.GetValue<bool>()) {
Rect labelPosition = new Rect(indentedPosition.x + indentedPosition.width / 2 - trueLabel.text.GetWidth(EditorStyles.standardFont) / 2 - 16, indentedPosition.y, indentedPosition.width, indentedPosition.height);
EditorGUI.LabelField(labelPosition, trueLabel);
}
else {
Rect labelPosition = new Rect(indentedPosition.x + indentedPosition.width / 2 - falseLabel.text.GetWidth(EditorStyles.standardFont) / 2 - 16, indentedPosition.y, indentedPosition.width, indentedPosition.height);
EditorGUI.LabelField(labelPosition, falseLabel);
}
currentPosition.y += currentPosition.height + 2;
}
示例5: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
drawPrefixLabel = false;
Begin(position, property, label);
string arrayName = ((PopupAttribute)attribute).arrayName;
string onChangeCallback = ((PopupAttribute)attribute).onChangeCallback;
SerializedProperty array = property.serializedObject.FindProperty(arrayName);
int selectedIndex = 0;
List<string> displayedOptions = new List<string>();
if (array != null && property.GetValue() != null) {
for (int i = 0; i < array.arraySize; i++) {
object value = array.GetArrayElementAtIndex(i).GetValue();
if (property.GetValue().Equals(value)) {
selectedIndex = i;
}
if (value != null) {
if (value as Object != null) {
displayedOptions.Add(string.Format("{0} [{1}]", value.GetType().Name, i));
}
else {
displayedOptions.Add(string.Format("{0}", value));
}
}
else {
displayedOptions.Add(" ");
}
}
}
EditorGUI.BeginChangeCheck();
selectedIndex = Mathf.Clamp(EditorGUI.Popup(_currentPosition, label, selectedIndex, displayedOptions.ToGUIContents()), 0, array.arraySize - 1);
if (array != null && array.arraySize != 0 && array.arraySize > selectedIndex) {
property.SetValue(array.GetArrayElementAtIndex(selectedIndex).GetValue());
}
if (EditorGUI.EndChangeCheck()) {
if (!string.IsNullOrEmpty(onChangeCallback)) ((MonoBehaviour)property.serializedObject.targetObject).Invoke(onChangeCallback, 0);
}
End();
}
示例6: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
drawPrefixLabel = false;
Begin(position, property, label);
EditorGUI.BeginChangeCheck();
Array enumValues = Enum.GetValues(fieldInfo.FieldType);
int value = (int)enumValues.GetValue(property.GetValue<int>());
string[] options = GetDisplayOptions();
value = EditorGUI.MaskField(currentPosition, label, value, options);
if (EditorGUI.EndChangeCheck()) {
object enumValue = value == -1 ? Array.IndexOf(enumValues, Enum.ToObject(fieldInfo.FieldType, SumOptions(options))) : Array.IndexOf(enumValues, Enum.ToObject(fieldInfo.FieldType, value));
property.SetValue(enumValue);
}
End();
}
示例7: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
drawPrefixLabel = false;
Begin(position, property, label);
var types = ((TypePopupAttribute)attribute).Types;
var typeNames = types.Convert(type => type.Name);
var typeName = property.GetValue<string>();
var typeIndex = Array.IndexOf(types, Type.GetType(typeName));
EditorGUI.BeginChangeCheck();
BeginIndent(0);
typeIndex = EditorGUI.Popup(currentPosition, typeIndex, typeNames);
EndIndent();
if (EditorGUI.EndChangeCheck())
property.SetValue(types[typeIndex].AssemblyQualifiedName);
End();
}
示例8: ShowPolar2D
void ShowPolar2D(SerializedProperty property)
{
var xProperty = property.FindPropertyRelative("x");
var yProperty = property.FindPropertyRelative("y");
var vector = property.GetValue<Vector2>().ToPolar().Round(0.0001f);
currentPosition.width = currentPosition.width / 2f - 1f;
EditorGUI.BeginChangeCheck();
EditorGUI.BeginProperty(currentPosition, xProperty.ToGUIContent(), xProperty);
vector.x = EditorGUI.FloatField(currentPosition, "R", vector.x);
currentPosition.x += currentPosition.width + 2f;
EditorGUI.EndProperty();
EditorGUI.BeginProperty(currentPosition, yProperty.ToGUIContent(), yProperty);
vector.y = EditorGUI.FloatField(currentPosition, "ϴ", vector.y);
EditorGUI.EndProperty();
if (EditorGUI.EndChangeCheck())
property.SetValue(vector.ToCartesian());
}
示例9: OnEnumFlagSelected
void OnEnumFlagSelected(FlagsOption option, SerializedProperty property)
{
var flags = property.GetValue<IEnumFlag>();
switch (option.Type)
{
case FlagsOption.OptionTypes.Everything:
foreach (IEnumFlag value in enumValues)
flags = flags.Add(value);
break;
case FlagsOption.OptionTypes.Nothing:
foreach (IEnumFlag value in enumValues)
flags = flags.Remove(value);
break;
case FlagsOption.OptionTypes.Custom:
if (option.IsSelected)
flags = flags.Remove((IEnumFlag)option.Value);
else
flags = flags.Add((IEnumFlag)option.Value);
break;
}
property.SetValue(flags);
}
示例10: ShowCallbacks
void ShowCallbacks()
{
callbacksProperty = serializedObject.FindProperty("callbacks");
EditorGUI.BeginDisabledGroup(Application.isPlaying);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Callbacks");
int callerMask = EditorGUILayout.MaskField(callbacksProperty.GetValue<int>(), callbacks);
callbacksProperty.SetValue(callerMask);
EditorGUILayout.EndHorizontal();
EditorGUI.EndDisabledGroup();
List<StateMachineCaller> callers = new List<StateMachineCaller>();
for (int i = 0; i < callbackTypes.Length; i++) {
if ((callerMask & 1 << i) != 0) {
StateMachineCaller caller = stateMachine.GetOrAddComponent(callbackTypes[i]) as StateMachineCaller;
caller.machine = stateMachine;
caller.hideFlags = HideFlags.HideInInspector;
callers.Add(caller);
}
}
for (int i = existingCallers.Length - 1; i >= 0; i--) {
StateMachineCaller caller = existingCallers[i];
if (caller != null && !callers.Contains(caller)) {
callers.Remove(caller);
caller.Remove();
}
}
}
示例11: PropertyField
/// <summary>
/// Displays the property field in the center of the window.
/// This method distinguishes between certain properties.
/// The GameObject tag, for example, shouldn't be displayed with a regular string field.
/// </summary>
/// <param name="p">The SerializedProerty to display</param>
/// <param name="width">The width of the whole thing in the ui</param>
private void PropertyField(SerializedProperty p, float width = 170)
{
if(p.IsRealArray())
{
DisplayArrayProperty(p, width);
}
else
{
var oldValue = p.GetValue();
if(fieldname == "GameObject.TagString")
{
var oldTag = oldValue as string;
var newTag = EditorGUILayout.TagField("", oldTag, GUILayout.Width(width));
if(newTag != oldTag)
{
p.SetValue(newTag);
}
}
else if(fieldname == "GameObject.StaticEditorFlags")
{
DisplayStaticFlagChooser(p, width);
}
else
{
EditorGUILayout.PropertyField(p, new GUIContent(""), GUILayout.Width(width));
}
if(!object.Equals(p.GetValue(), oldValue))
{
p.serializedObject.ApplyModifiedProperties();
UsedNew();
}
}
}
示例12: ToggleButton
public void ToggleButton(SerializedProperty boolProperty, GUIContent trueLabel, GUIContent falseLabel)
{
Rect indentedPosition = EditorGUI.IndentedRect(_currentPosition);
boolProperty.SetValue(ToggleButton(indentedPosition, boolProperty.GetValue<bool>(), trueLabel, falseLabel));
_currentPosition.y += _currentPosition.height + 2;
}
示例13: OnEnumFlagSelected
void OnEnumFlagSelected(FlagsOption option, SerializedProperty property)
{
var enumValue = property.GetValue<int>();
switch (option.Type)
{
case FlagsOption.OptionTypes.Everything:
enumValue = -1;
break;
case FlagsOption.OptionTypes.Nothing:
enumValue = 0;
break;
case FlagsOption.OptionTypes.Custom:
var value = (int)option.Value;
if ((enumValue & value) == value)
enumValue &= ~value;
else
enumValue |= value;
break;
}
property.SetValue(enumValue);
}
示例14: OnByteFlagSelected
void OnByteFlagSelected(FlagsOption option, SerializedProperty property)
{
var byteFlag = property.GetValue<ByteFlag>();
switch (option.Type)
{
case FlagsOption.OptionTypes.Everything:
byteFlag = new ByteFlag(enumValues.Convert((object v) => Convert.ToByte(v)));
break;
case FlagsOption.OptionTypes.Nothing:
byteFlag = ByteFlag.Nothing;
break;
case FlagsOption.OptionTypes.Custom:
byte value = (byte)option.Value;
byteFlag = byteFlag[value] ? byteFlag - value : byteFlag + value;
break;
}
property.SetValue(byteFlag);
}