private static bool HandleType(InvokeWrapper wrapper, object[] objects, SerializedObject fallback) { if (!wrapper.CanRead()) { return(false); } var drawerInfo = InvokeWrapperInspectorDrawer.GetDrawerMethod(wrapper.GetContainingType()); if (wrapper.HasAttribute <InspectorSeparatorAttribute>()) { InspectorGUI.BrandSeparator(); } EditorGUI.showMixedValue = !wrapper.AreValuesEqual(objects); object value = null; bool changed = false; if (drawerInfo.IsValid) { value = drawerInfo.Drawer.Invoke(null, new object[] { objects, wrapper }); changed = UnityEngine.GUI.changed && (drawerInfo.IsNullable || value != null); } // Fallback to Unity types rendered with property drawers. else if (fallback != null && !wrapper.GetContainingType().FullName.StartsWith("AGXUnity.")) { var serializedProperty = fallback.FindProperty(wrapper.Member.Name); // This is currently only tested on: // private InputActionAssert m_inputAsset = null; // public InputActionAsset InputAsset { get ... set ... } // public InputActionMap InputMap = null; // And serializedProperty.objectReferenceValue prints error: // type is not a supported pptr value // for 'InputMap' when changed (not assigned, just manipulated). // When we catch the 'm_inputAsset' we may do objectReferenceValue and // can propagate the value to the C# property. var assignSupported = false; if (serializedProperty == null && wrapper.Member.Name.Length > 2) { var fieldName = "m_" + char.ToLower(wrapper.Member.Name[0]) + wrapper.Member.Name.Substring(1); serializedProperty = fallback.FindProperty(fieldName); assignSupported = serializedProperty != null; } if (serializedProperty != null) { EditorGUILayout.PropertyField(serializedProperty); if (UnityEngine.GUI.changed && assignSupported) { changed = true; value = serializedProperty.objectReferenceValue; } } } // Reset changed state so that non-edited values // are propagated to other properties. UnityEngine.GUI.changed = false; EditorGUI.showMixedValue = false; if (!changed) { return(false); } foreach (var obj in objects) { object newValue = value; if (drawerInfo.IsValid && drawerInfo.CopyOp != null) { newValue = wrapper.GetValue(obj); // CopyOp returns the new value for value types. var ret = drawerInfo.CopyOp.Invoke(null, new object[] { value, newValue }); if (ret != null) { newValue = ret; } } wrapper.ConditionalSet(obj, newValue); } return(true); }
private void OnGUI() { var iconDirectoryInfo = new DirectoryInfo(IconManager.Directory); if (!iconDirectoryInfo.Exists) { return; } if (iconDirectoryInfo.GetFiles("*.png.meta").Length != m_iconNames.Count) { Debug.LogWarning("Icon count changed - reloading icons..."); OnEnable(); } Undo.RecordObject(EditorData.Instance, "IconManager"); var selectIconDir = false; var editorData = GetEditorData(); m_scroll = EditorGUILayout.BeginScrollView(m_scroll); using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField(GUI.MakeLabel("Icons directory"), GUI.MakeLabel(IconManager.Directory.Replace('\\', '/')), InspectorGUISkin.Instance.TextField); selectIconDir = GUILayout.Button(GUI.MakeLabel("..."), InspectorGUISkin.Instance.Button, GUILayout.Width(24)); } EditorGUILayout.LabelField(GUI.MakeLabel("Number of icons"), GUI.MakeLabel(m_iconNames.Count.ToString()), InspectorGUISkin.Instance.Label); IconManager.Scale = editorData.Float = Mathf.Clamp(EditorGUILayout.Slider(GUI.MakeLabel("Scale"), editorData.Float, 0.0f, 2.0f), 1.0E-3f, 2.0f); var newWidth = EditorGUILayout.Slider(GUI.MakeLabel("Button width"), editorData.Vector2.x, 6.0f, 75.0f); using (new GUI.EnabledBlock(false)) { var newHeight = EditorGUILayout.Slider(GUI.MakeLabel("Button height"), editorData.Vector2.y, 6.0f, 75.0f); InspectorGUISkin.ToolButtonSize = editorData.Vector2 = new Vector2(newWidth, newHeight); } InspectorGUI.BrandSeparator(1, 6); RenderButtons(editorData.Vector2, true, false); InspectorGUI.BrandSeparator(1, 6); RenderButtons(editorData.Vector2, true, true); InspectorGUI.BrandSeparator(1, 6); RenderButtons(editorData.Vector2, false, false); InspectorGUI.BrandSeparator(1, 6); IconManager.NormalColorDark = GetEditorData("NormalColorDark").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Normal Dark"), GetEditorData("NormalColorDark").Color); IconManager.ActiveColorDark = GetEditorData("ActiveColorDark").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Active Dark"), GetEditorData("ActiveColorDark").Color); IconManager.DisabledColorDark = GetEditorData("DisabledColorDark").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Disabled Dark"), GetEditorData("DisabledColorDark").Color); IconManager.NormalColorLight = GetEditorData("NormalColorLight").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Normal Light"), GetEditorData("NormalColorLight").Color); IconManager.ActiveColorLight = GetEditorData("ActiveColorLight").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Active Light"), GetEditorData("ActiveColorLight").Color); IconManager.DisabledColorLight = GetEditorData("DisabledColorLight").Color = EditorGUILayout.ColorField(GUI.MakeLabel("Disabled Light"), GetEditorData("DisabledColorLight").Color); EditorGUILayout.LabelField(GUI.MakeLabel("Brand color"), new GUIContent(GUI.CreateColoredTexture((int)EditorGUIUtility.currentViewWidth, (int)EditorGUIUtility.singleLineHeight, InspectorGUISkin.BrandColor))); var numLines = 6; var rect = EditorGUILayout.GetControlRect(false, numLines * EditorGUIUtility.singleLineHeight); EditorGUI.SelectableLabel(rect, GetColorsString(), InspectorEditor.Skin.TextFieldMiddleLeft); InspectorGUI.BrandSeparator(1, 6); RenderIcons(IconManager.Scale * 24.0f * Vector2.one); InspectorGUI.BrandSeparator(1, 6); RenderIcons(); InspectorGUI.BrandSeparator(1, 6); EditorGUILayout.EndScrollView(); if (selectIconDir) { var result = EditorUtility.OpenFolderPanel("Icons directory", new DirectoryInfo(IconManager.Directory).Parent.FullName, ""); if (!string.IsNullOrEmpty(result)) { var di = new DirectoryInfo(result); if (di.Exists) { editorData.String = IO.Utils.MakeRelative(result, Application.dataPath); OnEnable(); } } } }
public sealed override void OnInspectorGUI() { if (Utils.KeyHandler.HandleDetectKeyOnGUI(this.targets, Event.current)) { return; } if (IsMainEditor && !typeof(ScriptableObject).IsAssignableFrom(target.GetType())) { var controlRect = EditorGUILayout.GetControlRect(false, 0.0f); if (m_icon == null) { m_icon = IconManager.GetIcon("algoryx_white_shadow_icon"); } if (m_icon != null) { if (m_hideTexture == null) { #if UNITY_2019_3_OR_NEWER var hideColor = Color.Lerp(InspectorGUI.BackgroundColor, Color.white, 0.03f); #else var hideColor = InspectorGUI.BackgroundColor; #endif m_hideTexture = GUI.CreateColoredTexture(1, 1, hideColor); } var hideRect = new Rect(controlRect.x, #if UNITY_2019_3_OR_NEWER controlRect.y - 1.25f * EditorGUIUtility.singleLineHeight - 2, #else controlRect.y - 1.00f * EditorGUIUtility.singleLineHeight - 1, #endif 18, EditorGUIUtility.singleLineHeight + 2); UnityEngine.GUI.DrawTexture(hideRect, m_hideTexture); var iconRect = new Rect(hideRect); iconRect.height = 14.0f; iconRect.width = 14.0f; #if UNITY_2019_3_OR_NEWER iconRect.y += 2.5f; #else iconRect.y += 1.5f; #endif iconRect.x += 3.0f; UnityEngine.GUI.DrawTexture(iconRect, m_icon); } InspectorGUI.BrandSeparator(); } GUILayout.BeginVertical(); ToolManager.OnPreTargetMembers(this.targets); DrawMembersGUI(this.targets, null, serializedObject); ToolManager.OnPostTargetMembers(this.targets); GUILayout.EndVertical(); }