/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; if (!drawAsPreview) { if (entry.BaseValueType.IsInterface) { entry.WeakSmartValue = SirenixEditorFields.PolymorphicObjectField( label, entry.WeakSmartValue, entry.BaseValueType, entry.Property.GetAttribute <AssetsOnlyAttribute>() == null); } else { entry.WeakSmartValue = SirenixEditorFields.UnityObjectField( label, entry.WeakSmartValue as UnityEngine.Object, entry.BaseValueType, entry.Property.GetAttribute <AssetsOnlyAttribute>() == null); } } else { entry.WeakSmartValue = SirenixEditorFields.UnityPreviewObjectField( label, entry.WeakSmartValue as UnityEngine.Object, entry.BaseValueType, entry.Property.GetAttribute <AssetsOnlyAttribute>() == null, GeneralDrawerConfig.Instance.SquareUnityObjectFieldHeight, GeneralDrawerConfig.Instance.SquareUnityObjectAlignment); } }
/// <summary> /// Draws the property. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <T> entry, GUIContent label) { EditorGUI.BeginChangeCheck(); var drawAsPreview = entry.Context.Get(this, "drawPreview", (bool?)null); if (drawAsPreview.Value == null) { var flags = GeneralDrawerConfig.Instance.SquareUnityObjectEnableFor; drawAsPreview.Value = (int)flags != 0 && ( (flags & GeneralDrawerConfig.UnityObjectType.Components) != 0 && typeof(Component).IsAssignableFrom(typeof(T)) || (flags & GeneralDrawerConfig.UnityObjectType.GameObjects) != 0 && typeof(GameObject).IsAssignableFrom(typeof(T)) || (flags & GeneralDrawerConfig.UnityObjectType.Materials) != 0 && typeof(Material).IsAssignableFrom(typeof(T)) || (flags & GeneralDrawerConfig.UnityObjectType.Sprites) != 0 && typeof(Sprite).IsAssignableFrom(typeof(T)) || (flags & GeneralDrawerConfig.UnityObjectType.Textures) != 0 && typeof(Texture).IsAssignableFrom(typeof(T))); if (!drawAsPreview.Value.Value && (flags & GeneralDrawerConfig.UnityObjectType.Others) != 0) { bool isOther = !typeof(Component).IsAssignableFrom(typeof(T)) && !typeof(GameObject).IsAssignableFrom(typeof(T)) && !typeof(Material).IsAssignableFrom(typeof(T)) && !typeof(Sprite).IsAssignableFrom(typeof(T)) && !typeof(Texture).IsAssignableFrom(typeof(T)); if (isOther) { drawAsPreview.Value = true; } } } if (!drawAsPreview.Value.Value) { entry.WeakSmartValue = SirenixEditorFields.UnityObjectField( label, entry.WeakSmartValue as UnityEngine.Object, entry.BaseValueType, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null); } else { entry.WeakSmartValue = SirenixEditorFields.UnityPreviewObjectField( label, entry.WeakSmartValue as UnityEngine.Object, entry.BaseValueType, entry.Property.Info.GetAttribute <AssetsOnlyAttribute>() == null, GeneralDrawerConfig.Instance.SquareUnityObjectFieldHeight, GeneralDrawerConfig.Instance.SquareUnityObjectAlignment); } if (EditorGUI.EndChangeCheck()) { entry.Values.ForceMarkDirty(); } }
protected override void DrawPropertyLayout(GUIContent label) { SirenixEditorGUI.BeginBox(); { SirenixEditorGUI.BeginToolbarBoxHeader(); { var rect = GUILayoutUtility.GetRect(0, 19); var unityObjectFieldRect = rect.Padding(2).AlignLeft(rect.width / 2); var methodSelectorRect = rect.Padding(2).AlignRight(rect.width / 2 - 5); var dInfo = this.GetDelegateInfo(); var intlabel = new GUIContent("some type"); EditorGUI.BeginChangeCheck(); var someType = SirenixEditorFields.Dropdown(intlabel, tempType, SupportedReturnTypes); /*public static bool Dropdown<T>(Rect rect, IList<int> selected, IList<T> items, bool multiSelection)*/ var newTarget = SirenixEditorFields.UnityObjectField(unityObjectFieldRect, dInfo.Target, typeof(UnityEngine.Object), true); if (EditorGUI.EndChangeCheck()) { this.tmpTarget = newTarget; this.tempType = someType; } EditorGUI.BeginChangeCheck(); var selectorText = (dInfo.Method == null || this.tmpTarget) ? "Select a method" : dInfo.Method.Name; var newMethod = MethodSelector.DrawSelectorDropdown(methodSelectorRect, selectorText, this.CreateSelector); if (EditorGUI.EndChangeCheck()) { this.CreateAndAssignNewDelegate(newMethod.FirstOrDefault()); this.tmpTarget = null; } } SirenixEditorGUI.EndToolbarBoxHeader(); // Draws the rest of the ICustomEvent, and since we've drawn the label, we simply pass along null. for (int i = 0; i < this.Property.Children.Count; i++) { var child = this.Property.Children[i]; if (child.Name == "Result") { continue; } child.Draw(); } } SirenixEditorGUI.EndBox(); }
/// <summary> /// Not yet documented. /// </summary> protected override void DrawPropertyLayout(IPropertyValueEntry <GUIStyleState> entry, GUIContent label) { var property = entry.Property; var isVisible = property.Context.Get(this, "isVisible", AllEditorGUI.ExpandFoldoutByDefault); isVisible.Value = AllEditorGUI.Foldout(isVisible.Value, label ?? GUIContent.none); if (AllEditorGUI.BeginFadeGroup(isVisible, isVisible.Value)) { EditorGUI.indentLevel++; entry.SmartValue.background = (Texture2D)SirenixEditorFields.UnityObjectField(label, entry.SmartValue.background, typeof(Texture2D), true); entry.SmartValue.textColor = EditorGUILayout.ColorField(label ?? GUIContent.none, entry.SmartValue.textColor); EditorGUI.indentLevel--; } AllEditorGUI.EndFadeGroup(); }
protected override void DrawPropertyLayout(GUIContent label) { Set set = ValueEntry.SmartValue; // default height 16p or 18p Rect rect = EditorGUILayout.GetControlRect(false, 64f); var fieldRect = new Rect(rect.x, rect.center.y - DefaultHeight / 2, set.item != null ? rect.width / 3 : rect.width, DefaultHeight); set.item = (Item)SirenixEditorFields.UnityObjectField(fieldRect, set.item, typeof(Item), false); if (set.item != null && set.item.sprite != null) { var addButtonRect = new Rect(rect.max.x - ButtonWidth, rect.center.y - ButtonHeight - 2, ButtonWidth, ButtonHeight); if (GUI.Button(addButtonRect, "+")) { set.quantity++; } var removeButtonRect = new Rect(rect.max.x - ButtonWidth, rect.center.y + 2, ButtonWidth, ButtonHeight); if (GUI.Button(removeButtonRect, "-")) { set.quantity--; } var style = new GUIStyle { fontSize = 20, fontStyle = FontStyle.Bold }; var labelRect = new Rect(rect.max.x - ButtonWidth - QuantityWidth - 15, rect.center.y - QuantityHeight / 2, QuantityWidth, QuantityHeight); EditorGUI.LabelField(labelRect, "x" + set.quantity, style); Sprite sprite = set.item.sprite; var spriteRect = new Rect(sprite.rect.x / sprite.texture.width, sprite.rect.y / sprite.texture.height, sprite.rect.width / sprite.texture.width, sprite.rect.height / sprite.texture.height); float spriteCenterX = fieldRect.max.x + (labelRect.x - fieldRect.max.x) / 2 - 32; GUI.DrawTextureWithTexCoords(new Rect(spriteCenterX, rect.center.y - TextureSize / 2, TextureSize, TextureSize), sprite.texture, spriteRect); } if (set.quantity < 1) { set.quantity = 1; } ValueEntry.SmartValue = set; }
protected override void DrawPropertyLayout(GUIContent label) { // TODO: Raise Error Box if not in build settings - https://github.com/starikcetin/unity-scene-reference/blob/upm/SceneReference.cs#L254 var newScene = SirenixEditorFields.UnityObjectField(label, _currentScene, typeof(SceneAsset), false) as SceneAsset; if (newScene == _currentScene) { return; } _currentScene = newScene; if (_currentScene == null) { ValueEntry.SmartValue = null; } else if (newScene != null) { ValueEntry.SmartValue = newScene; } }
/// <summary> /// Draws the property with GUILayout support. /// </summary> protected override void DrawPropertyLayout(GUIContent label) { var entry = this.ValueEntry; var property = entry.Property; if (label != null) { this.isVisible = SirenixEditorGUI.Foldout(this.isVisible, label); if (SirenixEditorGUI.BeginFadeGroup(isVisible, this.isVisible)) { EditorGUI.indentLevel++; entry.SmartValue.background = (Texture2D)SirenixEditorFields.UnityObjectField(label, entry.SmartValue.background, typeof(Texture2D), true); entry.SmartValue.textColor = EditorGUILayout.ColorField(label ?? GUIContent.none, entry.SmartValue.textColor); EditorGUI.indentLevel--; } SirenixEditorGUI.EndFadeGroup(); } else { entry.SmartValue.background = (Texture2D)SirenixEditorFields.UnityObjectField(label, entry.SmartValue.background, typeof(Texture2D), true); entry.SmartValue.textColor = EditorGUILayout.ColorField(label ?? GUIContent.none, entry.SmartValue.textColor); } }
protected override void DrawPropertyLayout(GUIContent label) { var rect = EditorGUILayout.GetControlRect(); if (label != null) { rect = EditorGUI.PrefixLabel(rect, label); } var sceneReferenceAsset = this.ValueEntry.SmartValue; Object obj = (sceneReferenceAsset) ? sceneReferenceAsset.FindSceneAsset() : null; var sceneAsset = (SceneAsset)SirenixEditorFields.UnityObjectField(rect, obj, typeof(SceneAsset), false); var scenePath = AssetDatabase.GetAssetPath(sceneAsset); if (sceneAsset == null || string.IsNullOrEmpty(scenePath)) { this.ValueEntry.SmartValue = null; } else if (sceneReferenceAsset == null || sceneReferenceAsset.path != scenePath) { this.ValueEntry.SmartValue = SceneReferenceAsset.FindOrCreate(scenePath); } }
protected override void DrawPropertyLayout(GUIContent label) { if (!(this.ValueEntry.ValueState == PropertyValueState.NullReference || this.ValueEntry.ValueState == PropertyValueState.ReferenceValueConflict)) { this.CallNextDrawer(label); return; } if (Event.current.type == EventType.Layout) { this.isBroken = false; var count = this.ValueEntry.ValueCount; for (int i = 0; i < count; i++) { var component = this.ValueEntry.Values[i]; if (ComponentIsBroken(component, ref this.realWrapperInstance)) { this.isBroken = true; break; } } if (this.isBroken && autoFix) { this.isBroken = false; for (int i = 0; i < this.ValueEntry.ValueCount; i++) { T fixedComponent = null; if (ComponentIsBroken(this.ValueEntry.Values[i], ref fixedComponent) && fixedComponent) { (this.ValueEntry as IValueEntryActualValueSetter <T>).SetActualValue(i, fixedComponent); } } this.ValueEntry.Update(); } } if (!this.isBroken) { this.CallNextDrawer(label); return; } var rect = EditorGUILayout.GetControlRect(label != null); var btnRect = rect.AlignRight(20); var controlRect = rect.SetXMax(btnRect.xMin - 5); object newInstance = null; EditorGUI.BeginChangeCheck(); { if (this.ValueEntry.BaseValueType.IsInterface) { newInstance = SirenixEditorFields.PolymorphicObjectField(controlRect, label, this.realWrapperInstance, this.ValueEntry.BaseValueType, this.allowSceneViewObjects); } else { newInstance = SirenixEditorFields.UnityObjectField( controlRect, label, this.realWrapperInstance, this.ValueEntry.BaseValueType, this.allowSceneViewObjects) as Component; } } if (EditorGUI.EndChangeCheck()) { this.ValueEntry.WeakSmartValue = newInstance; } if (GUI.Button(btnRect, " ", EditorStyles.miniButton)) { var popup = new FixBrokenUnityObjectWrapperPopup(this.ValueEntry); OdinEditorWindow.InspectObjectInDropDown(popup, 300); } if (Event.current.type == EventType.Repaint) { GUI.DrawTexture(btnRect, EditorIcons.ConsoleWarnicon, ScaleMode.ScaleToFit); } }
private void DrawModels() { if (!Application.isPlaying) { EditorGUILayout.LabelField("Enter Play Mode to view Models."); return; } if (Selection.activeObject == null) { EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject"); return; } GameObject rootGameObject = Selection.activeObject as GameObject; if (rootGameObject == null) { EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject"); return; } _inspectedRoot = rootGameObject.GetComponent <RichMVCContextRoot>(); if (_inspectedRoot == null) { EditorGUILayout.LabelField("Select a RichMVCContext Root GameObject"); return; } SirenixEditorFields.UnityObjectField("Inspecting", _inspectedRoot, typeof(RichMVCContextRoot), true); SirenixEditorGUI.DrawThickHorizontalSeperator(5f, 5f, 5f); CrossContext context = _inspectedRoot.context as CrossContext; EditorGUILayout.Toggle("Context Found", context != null); if (context == null) { return; } FieldInfo fieldInfo = typeof(CrossContextInjectionBinder).BaseType.GetField("bindings", BindingFlags.Instance | BindingFlags.NonPublic); EditorGUILayout.Toggle("Bindings Found", fieldInfo != null); if (fieldInfo == null) { return; } InjectionBinder injectionBinder = context.injectionBinder as CrossContextInjectionBinder; EditorGUILayout.Toggle("InjectionBinder Casted", injectionBinder != null); if (injectionBinder == null) { return; } SirenixEditorGUI.DrawThickHorizontalSeperator(5f, 5f, 5f); SirenixEditorGUI.Title("Bindings", "", TextAlignment.Center, false); SirenixEditorGUI.BeginBox(); object bindings = fieldInfo.GetValue(injectionBinder); Dictionary <object, Dictionary <object, IBinding> > bindingDictionaries = (Dictionary <object, Dictionary <object, IBinding> >)bindings; if (bindingDictionaries == null) { return; } foreach (object mainKey in bindingDictionaries.Keys) { string typeName; if (!(mainKey is Type)) { continue; } Type mainKeyType = mainKey as Type; if (_ignoredTypeList.Contains(mainKeyType)) { continue; } IBinding binding = injectionBinder.GetBinding(mainKeyType); if (binding == null) { continue; } SirenixEditorGUI.BeginBox(); typeName = mainKey.ToString(); SirenixEditorGUI.Title(mainKeyType.Name, "", TextAlignment.Center, false); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); object instance = injectionBinder.GetInstance(mainKeyType); if (GUILayout.Button("Inspect", GUILayout.Height(20), GUILayout.Width(80))) { OdinEditorWindow.InspectObject(instance); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); SirenixEditorGUI.EndBox(); SirenixEditorGUI.DrawHorizontalLineSeperator(2f, 2f, 2f); } SirenixEditorGUI.EndBox(); }
protected override void OnGUI() { _repaintSheduled = false; GUILayout.BeginHorizontal(); if (GUILayout.Button("Clear")) { _properties.Clear(); } Rect settingsRect = GUILayoutUtility.GetRect(24, 24, GUILayout.ExpandWidth(false)).AlignLeft(20).AlignCenterY(20); if (SirenixEditorGUI.IconButton(settingsRect, _showSettings ? EditorIcons.SettingsCog.Inactive : EditorIcons.SettingsCog.Active, "Settings")) { _showSettings = !_showSettings; } GUILayout.EndHorizontal(); if (_showSettings) { GUILayout.BeginHorizontal(); GUILayout.Space(40); GUI.changed = false; Rect rect = GUILayoutUtility.GetRect(1, EditorGUIUtility.singleLineHeight, GUILayout.ExpandWidth(true)); _labelWidth = GUI.HorizontalSlider(rect, _labelWidth, rect.xMin, rect.xMax); if (GUI.changed) { EditorPrefs.SetFloat("OWW_labelWidth", _labelWidth); } EditorGUILayout.LabelField("Label Width", GUILayout.Width(70)); GUILayout.EndHorizontal(); } GUILayout.Space(5); bool first = true; if (_properties.Count == 0) { EditorGUILayout.LabelField("Right-click any property in an Inspector and select 'Watch' to make it show up here.", SirenixGUIStyles.MultiLineCenteredLabel); } GUIHelper.PushLabelWidth(_labelWidth - 30); for (int i = 0; i < _properties.Count; i++) { TreeValuesHolder holder = _properties[i]; holder.CheckRefresh(); if (!first) { GUILayout.Space(5); } first = false; Rect titleRect = SirenixEditorGUI.BeginBox(" " + holder.Tree.TargetType.Name); titleRect = titleRect.AlignTop(21); if (holder.ParentObject != null) { Rect alignRight = titleRect.AlignRight(200).AlignCenterY(16).AlignLeft(180); GUIHelper.PushGUIEnabled(false); SirenixEditorFields.UnityObjectField(alignRight, holder.ParentObject, typeof(GameObject), true); GUIHelper.PopGUIEnabled(); } if (SirenixEditorGUI.IconButton(titleRect.AlignRight(20).AlignCenterY(18), EditorIcons.X)) { _properties.RemoveAt(i--); } Rect titleDragDropRect = titleRect.AlignLeft(30).AlignCenter(20, 20); EditorIcons.List.Draw(titleDragDropRect); TreeValuesHolder treedragdrop = (TreeValuesHolder)DragAndDropUtilities.DragAndDropZone(titleDragDropRect, holder, typeof(TreeValuesHolder), false, false); if (treedragdrop != holder) { int treeDragDropIndex = _properties.IndexOf(treedragdrop); Swap(_properties, treeDragDropIndex, i); } if (holder.Tree.UnitySerializedObject?.targetObject == null) { EditorGUILayout.LabelField($"This component is no longer valid in the current context (loaded different scene?)", SirenixGUIStyles.MultiLineLabel); } else { InspectorUtilities.BeginDrawPropertyTree(holder.Tree, true); for (int index = 0; index < holder.ValuePaths.Count; index++) { string path = holder.ValuePaths[index]; GUILayout.BeginHorizontal(); Rect rect1 = GUILayoutUtility.GetRect(EditorGUIUtility.singleLineHeight + 5, EditorGUIUtility.singleLineHeight + 3, GUILayout.ExpandWidth(false)).AlignRight(EditorGUIUtility.singleLineHeight + 2); EditorIcons.List.Draw(rect1); ValueDragDropHolder dragdrop = (ValueDragDropHolder)DragAndDropUtilities.DragAndDropZone(rect1, new ValueDragDropHolder(holder, index), typeof(ValueDragDropHolder), false, false); if (dragdrop.TreeValuesHolder == holder && dragdrop.Index != index) { string ptemp = holder.ValuePaths[index]; holder.ValuePaths[index] = holder.ValuePaths[dragdrop.Index]; holder.ValuePaths[dragdrop.Index] = ptemp; } InspectorProperty propertyAtPath = holder.Tree.GetPropertyAtPath(path); if (propertyAtPath == null) { propertyAtPath = holder.Tree.GetPropertyAtUnityPath(path); } if (propertyAtPath != null) { propertyAtPath.Draw(); } else { EditorGUILayout.LabelField($"Could not find property ({path})"); } if (SirenixEditorGUI.IconButton(EditorIcons.X)) { holder.ValuePaths.RemoveAt(index--); if (holder.ValuePaths.Count == 0) { _properties.RemoveAt(i--); } } GUILayout.Space(3); GUILayout.EndHorizontal(); } InspectorUtilities.EndDrawPropertyTree(holder.Tree); } SirenixEditorGUI.EndBox(); } GUIHelper.PopLabelWidth(); }
public override void OnGUI(Rect propertyRect, SerializedProperty property, GUIContent label) { var sceneNameProperty = property.FindPropertyRelative(SCENE_NAME_PROPERTY); var sceneIndexProperty = property.FindPropertyRelative(SCENE_INDEX_PROPERTY); var enabledProperty = property.FindPropertyRelative(SCENE_ENABLED_PROPERTY); EditorGUI.BeginProperty(propertyRect, new GUIContent(property.displayName), property); EditorGUI.BeginChangeCheck(); // Draw Object Selector for SceneAssets var sceneAssetRect = new Rect { position = propertyRect.position, size = new Vector2(propertyRect.width, EditorGUIUtility.singleLineHeight) }; var oldSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(sceneNameProperty.stringValue); #if ODIN_INSPECTOR var sceneAsset = SirenixEditorFields.UnityObjectField(sceneAssetRect, oldSceneAsset, typeof(SceneAsset), false); #else var sceneAsset = EditorGUI.ObjectField(sceneAssetRect, oldSceneAsset, typeof(SceneAsset), false); #endif var sceneAssetPath = AssetDatabase.GetAssetPath(sceneAsset); if (sceneNameProperty.stringValue != sceneAssetPath) { sceneNameProperty.stringValue = sceneAssetPath; } if (string.IsNullOrEmpty(sceneNameProperty.stringValue)) { sceneIndexProperty.intValue = -1; enabledProperty.boolValue = false; } // Draw preview fields for scene information. var titleLabelRect = sceneAssetRect; titleLabelRect.y += EditorGUIUtility.singleLineHeight; EditorGUI.LabelField(titleLabelRect, SCENE_PREVIEW_TITLE); EditorGUI.BeginDisabledGroup(true); var nameRect = titleLabelRect; nameRect.y += EditorGUIUtility.singleLineHeight; var indexRect = nameRect; indexRect.y += EditorGUIUtility.singleLineHeight; var enabledRect = indexRect; enabledRect.y += EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(nameRect, sceneNameProperty); EditorGUI.PropertyField(indexRect, sceneIndexProperty); EditorGUI.PropertyField(enabledRect, enabledProperty); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } EditorGUI.EndProperty(); }