public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { if (property.isExpanded) { SerializedProperty materialIndexProp = property.FindPropertyRelative("_materialIndex"); eEdtiorType editorType = materialIndexProp.intValue != -1 ? eEdtiorType.Instanced : eEdtiorType.Shared; if (editorType == eEdtiorType.Instanced) { SerializedProperty rendererProp = property.FindPropertyRelative("_renderer"); if (rendererProp.objectReferenceValue as Renderer != null) { return(EditorGUIUtility.singleLineHeight * 4); } else { return(EditorGUIUtility.singleLineHeight * 3); } } else { return(EditorGUIUtility.singleLineHeight * 3); } } return(EditorGUIUtility.singleLineHeight); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty sourceTypeProperty = property.FindPropertyRelative("_sourceType"); SerializedProperty sourceObjectProp = property.FindPropertyRelative("_sourceObject"); SerializedProperty sourceObjectMemberNameProp = property.FindPropertyRelative("_sourceObjectMemberName"); SerializedProperty sourceObjectMemberIndexProp = property.FindPropertyRelative("_sourceObjectMemberIndex"); SerializedProperty valueProperty = property.FindPropertyRelative("_value"); Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); sourceTypeProperty.isExpanded = EditorGUI.Foldout(foldoutPosition, sourceTypeProperty.isExpanded, label != null ? label.text : property.displayName); if (sourceTypeProperty.isExpanded) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; eEdtiorType sourceType = (DynamicValue <T> .eSourceType)sourceTypeProperty.intValue == DynamicValue <T> .eSourceType.Static ? eEdtiorType.Static : eEdtiorType.Source; bool tempOverrideType = AllowDragComponentToSetAsSource() && sourceType == eEdtiorType.Static && EditorUtils.GetDraggingComponent <MonoBehaviour>() != null; if (tempOverrideType) { sourceType = eEdtiorType.Source; } EditorGUI.BeginChangeCheck(); Rect typePosition = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight); eEdtiorType edtiorType = (eEdtiorType)EditorGUI.EnumPopup(typePosition, "Source Type", sourceType); if (EditorGUI.EndChangeCheck()) { sourceObjectProp.objectReferenceValue = null; sourceTypeProperty.intValue = Convert.ToInt32(edtiorType); } Rect valuePosition = new Rect(position.x, typePosition.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight); switch (sourceType) { case eEdtiorType.Source: { DrawSourceObjectField(sourceObjectProp, sourceTypeProperty, sourceObjectMemberNameProp, sourceObjectMemberIndexProp, valuePosition); } break; case eEdtiorType.Static: { DrawStaticValueField(valuePosition, valueProperty); } break; } EditorGUI.indentLevel = origIndent; } EditorGUI.EndProperty(); }
public ValueSource(T value = default(T), IValueSource <T> sourceObject = null) { _value = value; _sourceObject = sourceObject as UnityEngine.Object; #if UNITY_EDITOR _editorType = sourceObject != null ? eEdtiorType.Source : eEdtiorType.Static; _editorFoldout = false; _editorHeight = EditorGUIUtility.singleLineHeight * 3; #endif }
public MaterialValueSource(MaterialRefProperty value = default(MaterialRefProperty), IValueSource <float> sourceObject = null) { _value = value; _sourceObject = sourceObject as UnityEngine.Object; #if UNITY_EDITOR _editorType = _sourceObject != null ? eEdtiorType.Source : eEdtiorType.Static; _editorFoldout = false; _editorHeight = EditorGUIUtility.singleLineHeight * 3; #endif }
public MaterialRefProperty(Material material = null, int materialIndex = 0, Renderer renderer = null) { _material = material; _materialIndex = materialIndex; _renderer = renderer; #if UNITY_EDITOR _editorType = materialIndex != -1 ? eEdtiorType.Instance : eEdtiorType.Shared; _editorFoldout = false; _editorHeight = EditorGUIUtility.singleLineHeight; #endif }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float height = EditorGUIUtility.singleLineHeight; if (property.isExpanded) { height += EditorGUIUtility.singleLineHeight; SerializedProperty materialIndexProp = property.FindPropertyRelative("_materialIndex"); eEdtiorType editorType = eEdtiorType.RendererMaterialInstance; if (materialIndexProp.intValue == -1) { editorType = eEdtiorType.SharedMaterial; } else if (materialIndexProp.intValue == MaterialRef.kGraphicMaterialIndex) { editorType = eEdtiorType.UIGraphicMaterialInstance; } if (editorType == eEdtiorType.RendererMaterialInstance) { SerializedProperty rendererProp = property.FindPropertyRelative("_renderer"); if (rendererProp.objectReferenceValue as Renderer != null) { height += EditorGUIUtility.singleLineHeight * 2; } else { height += EditorGUIUtility.singleLineHeight; } } else { height += EditorGUIUtility.singleLineHeight * 3; } } return(height); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { SerializedProperty sourceTypeProperty = property.FindPropertyRelative("_sourceType"); SerializedProperty valueProperty = property.FindPropertyRelative("_value"); float height = EditorGUIUtility.singleLineHeight; if (sourceTypeProperty.isExpanded) { height += EditorGUIUtility.singleLineHeight; eEdtiorType sourceType = (DynamicValue <T> .eSourceType)sourceTypeProperty.intValue == DynamicValue <T> .eSourceType.Static ? eEdtiorType.Static : eEdtiorType.Source; switch (sourceType) { case eEdtiorType.Source: height += EditorGUIUtility.singleLineHeight * 3; break; case eEdtiorType.Static: height += GetStaticValueFieldHeight(valueProperty); break; } } return(height); }
public bool RenderObjectProperties(GUIContent label) { bool dataChanged = false; if (label == null) { label = new GUIContent(); } label.text += " (" + this + ")"; _editorFoldout = EditorGUILayout.Foldout(_editorFoldout, label); if (_editorFoldout) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Draw type dropdown { EditorGUI.BeginChangeCheck(); _editorType = (eEdtiorType)EditorGUILayout.EnumPopup("Material Type", _editorType); if (EditorGUI.EndChangeCheck()) { dataChanged = true; _materialRef.ClearAsset(); _materialIndex = -1; _renderer.ClearComponent(); } } //Draw renderer field if (_editorType == eEdtiorType.Instance) { if (_renderer.RenderObjectProperties(new GUIContent("Renderer"))) { dataChanged = true; _materialRef.ClearAsset(); _materialIndex = 0; } //Show drop down for materials Renderer renderer = _renderer.GetEditorComponent(); if (renderer != null) { string[] materialNames = new string[renderer.sharedMaterials.Length]; for (int i = 0; i < materialNames.Length; i++) { materialNames[i] = renderer.sharedMaterials[i].name; } _materialIndex = EditorGUILayout.Popup("Material", _materialIndex, materialNames); } } else { dataChanged |= _materialRef.RenderObjectProperties(new GUIContent("Material")); } EditorGUI.indentLevel = origIndent; } return(dataChanged); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); SerializedProperty materialProperty = property.FindPropertyRelative("_material"); SerializedProperty materialIndexProp = property.FindPropertyRelative("_materialIndex"); SerializedProperty rendererProp = property.FindPropertyRelative("_renderer"); float yPos = position.y; Rect foldoutPosition = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight); property.isExpanded = EditorGUI.Foldout(foldoutPosition, property.isExpanded, property.displayName); yPos += EditorGUIUtility.singleLineHeight; if (property.isExpanded) { eEdtiorType editorType = materialIndexProp.intValue != -1 ? eEdtiorType.Instanced : eEdtiorType.Shared; int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; //Draw type dropdown { Rect typePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); editorType = (eEdtiorType)EditorGUI.EnumPopup(typePosition, "Material Type", editorType); yPos += EditorGUIUtility.singleLineHeight; if (EditorGUI.EndChangeCheck()) { switch (editorType) { case eEdtiorType.Instanced: { materialProperty.objectReferenceValue = null; materialIndexProp.intValue = 0; //Try to default to renderer component on this object. Component component = property.serializedObject.targetObject as Component; rendererProp.objectReferenceValue = component != null?component.GetComponent <Renderer>() : null; } break; case eEdtiorType.Shared: { materialProperty.objectReferenceValue = null; materialIndexProp.intValue = -1; rendererProp.objectReferenceValue = null; } break; } } } //Draw renderer field if (editorType == eEdtiorType.Instanced) { Rect rendererPosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(rendererPosition, rendererProp, new GUIContent("Renderer")); yPos += EditorGUIUtility.singleLineHeight; if (EditorGUI.EndChangeCheck()) { materialProperty.objectReferenceValue = null; materialIndexProp.intValue = 0; } //Show drop down for materials Renderer renderer = rendererProp.objectReferenceValue as Renderer; if (renderer != null) { Rect valuePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); string[] materialNames = new string[renderer.sharedMaterials.Length]; for (int i = 0; i < materialNames.Length; i++) { materialNames[i] = renderer.sharedMaterials[i].name; } materialIndexProp.intValue = EditorGUI.Popup(valuePosition, "Material", materialIndexProp.intValue, materialNames); yPos += EditorGUIUtility.singleLineHeight; } } else { Rect valuePosition = new Rect(position.x, yPos, position.width, EditorGUIUtility.singleLineHeight); EditorGUI.PropertyField(valuePosition, materialProperty, new GUIContent("Material")); yPos += EditorGUIUtility.singleLineHeight; } EditorGUI.indentLevel = origIndent; } EditorGUI.EndProperty(); }
public static object PropertyField(object obj, GUIContent label, ref bool dataChanged, GUIStyle style, params GUILayoutOption[] options) { MaterialRef materialRef = (MaterialRef)obj; if (label == null) { label = new GUIContent(); } label.text += " (" + materialRef + ")"; bool editorCollapsed = !EditorGUILayout.Foldout(!materialRef._editorCollapsed, label); if (editorCollapsed != materialRef._editorCollapsed) { materialRef._editorCollapsed = editorCollapsed; dataChanged = true; } if (!editorCollapsed) { int origIndent = EditorGUI.indentLevel; EditorGUI.indentLevel++; eEdtiorType editorType = materialRef.GetMaterialIndex() == -1 ? eEdtiorType.Shared : eEdtiorType.Instanced; //Draw type dropdown { EditorGUI.BeginChangeCheck(); editorType = (eEdtiorType)EditorGUILayout.EnumPopup("Material Type", editorType); if (EditorGUI.EndChangeCheck()) { dataChanged = true; materialRef = new MaterialRef(editorType == eEdtiorType.Shared ? -1 : 0); } } //Draw renderer field if (editorType == eEdtiorType.Instanced) { bool renderChanged = false; ComponentRef <Renderer> rendererComponentRef = SerializationEditorGUILayout.ObjectField(materialRef.GetRenderer(), new GUIContent("Renderer"), ref renderChanged); if (renderChanged) { dataChanged = true; materialRef = new MaterialRef(rendererComponentRef, 0); } //Show drop down for materials Renderer renderer = rendererComponentRef.GetComponent(); if (renderer != null) { string[] materialNames = new string[renderer.sharedMaterials.Length]; for (int i = 0; i < materialNames.Length; i++) { materialNames[i] = renderer.sharedMaterials[i].name; } EditorGUI.BeginChangeCheck(); int materialIndex = EditorGUILayout.Popup("Material", materialRef.GetMaterialIndex(), materialNames); if (EditorGUI.EndChangeCheck()) { dataChanged = true; materialRef = new MaterialRef(rendererComponentRef, materialIndex); } } } else { bool assetChanged = false; AssetRef <Material> assetRef = SerializationEditorGUILayout.ObjectField(materialRef.GetAsset(), new GUIContent("Material"), ref assetChanged); if (assetChanged) { dataChanged = true; materialRef = new MaterialRef(assetRef); } } EditorGUI.indentLevel = origIndent; } return(materialRef); }