当前位置: 首页>>代码示例>>C#>>正文


C# SerializedProperty.GetInstance方法代码示例

本文整理汇总了C#中UnityEditor.SerializedProperty.GetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedProperty.GetInstance方法的具体用法?C# SerializedProperty.GetInstance怎么用?C# SerializedProperty.GetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEditor.SerializedProperty的用法示例。


在下文中一共展示了SerializedProperty.GetInstance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGUI

		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
		{
			var intent = EditorGUI.indentLevel;
			position = EditorGUI.IndentedRect(position);
			EditorGUI.indentLevel = 0;
			EditorGUI.BeginChangeCheck();

			var prefabInstance = property.serializedObject.targetObject as PEPrefabScript;
			var modificationInstance = property.GetInstance<PEModifications.PropertyData>();

			SerializedProperty prefabProperty;
			SerializedProperty instanceProperty;
			modificationInstance.GetProperties(out prefabProperty, out instanceProperty, prefabInstance);
			if (instanceProperty == null)
				return;
		
			var mode = property.FindPropertyRelative("Mode");

			var color = GUI.color;
			GUI.color = mode.enumValueIndex == 0 ? new Color(1, 1, 1, 1) : (mode.enumValueIndex == 1 ? new Color(0, 1, 0, 1) : new Color(1, 0, 0, 1));
			position.x -= 6;
			position.width += 6;
			GUI.Box(position, "", "Window");

			position.x += 12;
			position.width -= 18;

			GUI.color = color;

			var enabled = GUI.enabled;
			GUI.enabled = false;

			var height = EditorGUI.GetPropertyHeight(instanceProperty);
			position.y += EditorGUIUtility.singleLineHeight + 3;
			if (prefabProperty != null)
				EditorGUI.PropertyField(new Rect(position) { height = height }, prefabProperty, true);
			else
				EditorGUI.LabelField(new Rect(position) { height = height }, "Property not exist");

			position.y += height + 2;
			GUI.enabled = enabled;
		
			EditorGUI.PropertyField(new Rect(position) { height = height }, instanceProperty, true); 
			position.y += height;

			var buttons = GetButtonsData(prefabInstance, prefabProperty, instanceProperty);
			position.y += 3;
			var startRect = new Rect(position) {
				height = 15,
				width = position.width / (buttons.Length + 1),
			};

			var lw = EditorGUIUtility.labelWidth;
			EditorGUIUtility.labelWidth = 0;
			EditorGUIUtility.fieldWidth = 0;
			EditorGUI.PropertyField(new Rect(startRect) { width = startRect.width - 6 }, mode, new GUIContent("", "Select proprty mode"), true);
			EditorGUIUtility.labelWidth = lw;

			startRect.x += startRect.width;
			var i = 0;
			foreach (var button in buttons)
			{
				var style = i == 0 ? EditorStyles.miniButtonLeft : (i == buttons.Length - 1 ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid);
				if (GUI.Button(startRect, button.Key, style))
					button.Value();
				startRect.x += startRect.width;
				i++;
			}
			startRect.x = position.x;
			startRect.y += startRect.height;

			if (EditorGUI.EndChangeCheck())
			{
				instanceProperty.serializedObject.ApplyModifiedProperties();
				if (prefabProperty != null)
					prefabProperty.serializedObject.ApplyModifiedProperties();
			}
			EditorGUI.indentLevel = intent;
		}
开发者ID:Zammy,项目名称:ProjectSpaceship,代码行数:79,代码来源:PEModificationsDrawer.cs


注:本文中的UnityEditor.SerializedProperty.GetInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。