From 2ee3ed2fb7a41bc84fa6872ab8e646fd17bc9459 Mon Sep 17 00:00:00 2001 From: VladV Date: Sun, 3 Jul 2022 17:59:35 +0300 Subject: [PATCH] Add samples window - Tools/Tri Inspector/Samples --- Editor.Samples.meta | 8 + Editor.Samples/Buttons.meta | 3 + .../Buttons/Buttons_ButtonSample.cs | 11 + .../Buttons/Buttons_ButtonSample.cs.meta | 3 + .../Buttons_EnumToggleButtonsSample.cs | 25 ++ .../Buttons_EnumToggleButtonsSample.cs.meta | 3 + Editor.Samples/Collections.meta | 3 + .../Collections_ListDrawerSettingsSample.cs | 15 + ...llections_ListDrawerSettingsSample.cs.meta | 3 + .../Collections_TableListSample.cs | 35 +++ .../Collections_TableListSample.cs.meta | 3 + Editor.Samples/Conditionals.meta | 3 + .../Conditionals_DisableIfSample.cs | 10 + .../Conditionals_DisableIfSample.cs.meta | 3 + .../Conditionals_EnableIfSample.cs | 10 + .../Conditionals_EnableIfSample.cs.meta | 3 + .../Conditionals/Conditionals_HideIfSample.cs | 10 + .../Conditionals_HideIfSample.cs.meta | 3 + .../Conditionals/Conditionals_ShowIfSample.cs | 23 ++ .../Conditionals_ShowIfSample.cs.meta | 3 + Editor.Samples/Debug.meta | 3 + .../Debug/Debug_ShowDrawerChainSample.cs | 12 + .../Debug/Debug_ShowDrawerChainSample.cs.meta | 3 + Editor.Samples/Groups.meta | 3 + Editor.Samples/Groups/Groups_GroupsSample.cs | 35 +++ .../Groups/Groups_GroupsSample.cs.meta | 3 + Editor.Samples/Misc.meta | 3 + .../Misc/Misc_OnValueChangedSample.cs | 13 + .../Misc/Misc_OnValueChangedSample.cs.meta | 3 + .../Misc/Misc_PropertyOrderSample.cs | 10 + .../Misc/Misc_PropertyOrderSample.cs.meta | 3 + Editor.Samples/Misc/Misc_ReadOnlySample.cs | 8 + .../Misc/Misc_ReadOnlySample.cs.meta | 3 + .../Misc/Misc_ShowInInspectorSample.cs | 17 ++ .../Misc/Misc_ShowInInspectorSample.cs.meta | 3 + Editor.Samples/SampleWindowStyles.cs | 32 +++ Editor.Samples/SampleWindowStyles.cs.meta | 3 + Editor.Samples/Styling.meta | 3 + .../Styling/Styling_GUIColorSample.cs | 20 ++ .../Styling/Styling_GUIColorSample.cs.meta | 3 + .../Styling/Styling_HideLabelSample.cs | 13 + .../Styling/Styling_HideLabelSample.cs.meta | 3 + .../Styling/Styling_IndentSample.cs | 18 ++ .../Styling/Styling_IndentSample.cs.meta | 3 + .../Styling/Styling_InlineEditorSample.cs | 8 + .../Styling_InlineEditorSample.cs.meta | 3 + .../Styling/Styling_InlinePropertySample.cs | 18 ++ .../Styling_InlinePropertySample.cs.meta | 3 + .../Styling/Styling_LabelTextSample.cs | 14 + .../Styling/Styling_LabelTextSample.cs.meta | 3 + .../Styling/Styling_LabelWidthSample.cs | 13 + .../Styling/Styling_LabelWidthSample.cs.meta | 3 + .../Styling/Styling_PropertySpaceSample.cs | 15 + .../Styling_PropertySpaceSample.cs.meta | 3 + .../Styling/Styling_PropertyTooltipSample.cs | 14 + .../Styling_PropertyTooltipSample.cs.meta | 3 + Editor.Samples/Styling/Styling_TitleSample.cs | 25 ++ .../Styling/Styling_TitleSample.cs.meta | 3 + .../TriInspector.Editor.Samples.asmdef | 18 ++ .../TriInspector.Editor.Samples.asmdef.meta | 7 + Editor.Samples/TriSamplesWindow.cs | 257 ++++++++++++++++++ Editor.Samples/TriSamplesWindow.cs.meta | 3 + Editor.Samples/Validators.meta | 3 + .../Validators/Validators_AssetsOnlySample.cs | 8 + .../Validators_AssetsOnlySample.cs.meta | 3 + .../Validators/Validators_InfoBoxSample.cs | 26 ++ .../Validators_InfoBoxSample.cs.meta | 3 + .../Validators/Validators_RequiredSample.cs | 8 + .../Validators_RequiredSample.cs.meta | 3 + .../Validators_ValidateInputSample.cs | 15 + .../Validators_ValidateInputSample.cs.meta | 3 + Editor/AssemblyInfo.cs | 1 + Editor/TriPropertyTree.cs | 4 +- README.md | 6 + 74 files changed, 894 insertions(+), 2 deletions(-) create mode 100644 Editor.Samples.meta create mode 100644 Editor.Samples/Buttons.meta create mode 100644 Editor.Samples/Buttons/Buttons_ButtonSample.cs create mode 100644 Editor.Samples/Buttons/Buttons_ButtonSample.cs.meta create mode 100644 Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs create mode 100644 Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs.meta create mode 100644 Editor.Samples/Collections.meta create mode 100644 Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs create mode 100644 Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs.meta create mode 100644 Editor.Samples/Collections/Collections_TableListSample.cs create mode 100644 Editor.Samples/Collections/Collections_TableListSample.cs.meta create mode 100644 Editor.Samples/Conditionals.meta create mode 100644 Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs create mode 100644 Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs.meta create mode 100644 Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs create mode 100644 Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs.meta create mode 100644 Editor.Samples/Conditionals/Conditionals_HideIfSample.cs create mode 100644 Editor.Samples/Conditionals/Conditionals_HideIfSample.cs.meta create mode 100644 Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs create mode 100644 Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs.meta create mode 100644 Editor.Samples/Debug.meta create mode 100644 Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs create mode 100644 Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs.meta create mode 100644 Editor.Samples/Groups.meta create mode 100644 Editor.Samples/Groups/Groups_GroupsSample.cs create mode 100644 Editor.Samples/Groups/Groups_GroupsSample.cs.meta create mode 100644 Editor.Samples/Misc.meta create mode 100644 Editor.Samples/Misc/Misc_OnValueChangedSample.cs create mode 100644 Editor.Samples/Misc/Misc_OnValueChangedSample.cs.meta create mode 100644 Editor.Samples/Misc/Misc_PropertyOrderSample.cs create mode 100644 Editor.Samples/Misc/Misc_PropertyOrderSample.cs.meta create mode 100644 Editor.Samples/Misc/Misc_ReadOnlySample.cs create mode 100644 Editor.Samples/Misc/Misc_ReadOnlySample.cs.meta create mode 100644 Editor.Samples/Misc/Misc_ShowInInspectorSample.cs create mode 100644 Editor.Samples/Misc/Misc_ShowInInspectorSample.cs.meta create mode 100644 Editor.Samples/SampleWindowStyles.cs create mode 100644 Editor.Samples/SampleWindowStyles.cs.meta create mode 100644 Editor.Samples/Styling.meta create mode 100644 Editor.Samples/Styling/Styling_GUIColorSample.cs create mode 100644 Editor.Samples/Styling/Styling_GUIColorSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_HideLabelSample.cs create mode 100644 Editor.Samples/Styling/Styling_HideLabelSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_IndentSample.cs create mode 100644 Editor.Samples/Styling/Styling_IndentSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_InlineEditorSample.cs create mode 100644 Editor.Samples/Styling/Styling_InlineEditorSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_InlinePropertySample.cs create mode 100644 Editor.Samples/Styling/Styling_InlinePropertySample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_LabelTextSample.cs create mode 100644 Editor.Samples/Styling/Styling_LabelTextSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_LabelWidthSample.cs create mode 100644 Editor.Samples/Styling/Styling_LabelWidthSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_PropertySpaceSample.cs create mode 100644 Editor.Samples/Styling/Styling_PropertySpaceSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_PropertyTooltipSample.cs create mode 100644 Editor.Samples/Styling/Styling_PropertyTooltipSample.cs.meta create mode 100644 Editor.Samples/Styling/Styling_TitleSample.cs create mode 100644 Editor.Samples/Styling/Styling_TitleSample.cs.meta create mode 100644 Editor.Samples/TriInspector.Editor.Samples.asmdef create mode 100644 Editor.Samples/TriInspector.Editor.Samples.asmdef.meta create mode 100644 Editor.Samples/TriSamplesWindow.cs create mode 100644 Editor.Samples/TriSamplesWindow.cs.meta create mode 100644 Editor.Samples/Validators.meta create mode 100644 Editor.Samples/Validators/Validators_AssetsOnlySample.cs create mode 100644 Editor.Samples/Validators/Validators_AssetsOnlySample.cs.meta create mode 100644 Editor.Samples/Validators/Validators_InfoBoxSample.cs create mode 100644 Editor.Samples/Validators/Validators_InfoBoxSample.cs.meta create mode 100644 Editor.Samples/Validators/Validators_RequiredSample.cs create mode 100644 Editor.Samples/Validators/Validators_RequiredSample.cs.meta create mode 100644 Editor.Samples/Validators/Validators_ValidateInputSample.cs create mode 100644 Editor.Samples/Validators/Validators_ValidateInputSample.cs.meta diff --git a/Editor.Samples.meta b/Editor.Samples.meta new file mode 100644 index 0000000..86abcd5 --- /dev/null +++ b/Editor.Samples.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c0e88f221fc25564eb4caf4d374bab5b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor.Samples/Buttons.meta b/Editor.Samples/Buttons.meta new file mode 100644 index 0000000..1282b1b --- /dev/null +++ b/Editor.Samples/Buttons.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1068a85eb61646efb6cffc2680cf0be3 +timeCreated: 1656857100 \ No newline at end of file diff --git a/Editor.Samples/Buttons/Buttons_ButtonSample.cs b/Editor.Samples/Buttons/Buttons_ButtonSample.cs new file mode 100644 index 0000000..21999dd --- /dev/null +++ b/Editor.Samples/Buttons/Buttons_ButtonSample.cs @@ -0,0 +1,11 @@ +using TriInspector; +using UnityEngine; + +public class Buttons_ButtonSample : ScriptableObject +{ + [Button("Click me!")] + private void DoButton() + { + Debug.Log("Button clicked!"); + } +} \ No newline at end of file diff --git a/Editor.Samples/Buttons/Buttons_ButtonSample.cs.meta b/Editor.Samples/Buttons/Buttons_ButtonSample.cs.meta new file mode 100644 index 0000000..911c9d6 --- /dev/null +++ b/Editor.Samples/Buttons/Buttons_ButtonSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cfc765523b0944faa880f75c257dc865 +timeCreated: 1656857108 \ No newline at end of file diff --git a/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs b/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs new file mode 100644 index 0000000..74c195d --- /dev/null +++ b/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs @@ -0,0 +1,25 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Buttons_EnumToggleButtonsSample : ScriptableObject +{ + [EnumToggleButtons] public SomeEnum someEnum; + [EnumToggleButtons] public SomeFlags someFlags; + + public enum SomeEnum + { + One, + Two, + Three + } + + [Flags] public enum SomeFlags + { + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + AB = A | B, + BC = B | C, + } +} \ No newline at end of file diff --git a/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs.meta b/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs.meta new file mode 100644 index 0000000..7adff58 --- /dev/null +++ b/Editor.Samples/Buttons/Buttons_EnumToggleButtonsSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a5287edf013a41608e8082a8766f1f1a +timeCreated: 1656857128 \ No newline at end of file diff --git a/Editor.Samples/Collections.meta b/Editor.Samples/Collections.meta new file mode 100644 index 0000000..83d9561 --- /dev/null +++ b/Editor.Samples/Collections.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f188dac8f6fb4d7cb4251a6d0a3469a9 +timeCreated: 1656855659 \ No newline at end of file diff --git a/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs b/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs new file mode 100644 index 0000000..bda8374 --- /dev/null +++ b/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using TriInspector; +using UnityEngine; + +public class Collections_ListDrawerSettingsSample : ScriptableObject +{ + [ListDrawerSettings(Draggable = true, + HideAddButton = false, + HideRemoveButton = false, + AlwaysExpanded = false)] + public List list; + + [ListDrawerSettings(Draggable = false, AlwaysExpanded = true)] + public Vector3[] vectors; +} \ No newline at end of file diff --git a/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs.meta b/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs.meta new file mode 100644 index 0000000..2c837d8 --- /dev/null +++ b/Editor.Samples/Collections/Collections_ListDrawerSettingsSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a00395c39c074032849fd8ac4b9dd3b8 +timeCreated: 1656856967 \ No newline at end of file diff --git a/Editor.Samples/Collections/Collections_TableListSample.cs b/Editor.Samples/Collections/Collections_TableListSample.cs new file mode 100644 index 0000000..78f42db --- /dev/null +++ b/Editor.Samples/Collections/Collections_TableListSample.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using TriInspector; +using UnityEngine; + +public class Collections_TableListSample : ScriptableObject +{ + [TableList(Draggable = true, + HideAddButton = false, + HideRemoveButton = false, + AlwaysExpanded = false)] + public List table; + + [Serializable] + public class TableItem + { + [Required] + public Texture icon; + + public string description; + + [Group("Combined"), LabelWidth(16)] + public string A, B, C; + + [Button, Group("Actions")] + public void Test1() + { + } + + [Button, Group("Actions")] + public void Test2() + { + } + } +} \ No newline at end of file diff --git a/Editor.Samples/Collections/Collections_TableListSample.cs.meta b/Editor.Samples/Collections/Collections_TableListSample.cs.meta new file mode 100644 index 0000000..e9f1cd9 --- /dev/null +++ b/Editor.Samples/Collections/Collections_TableListSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 75e67511762f4ce8bb50e9a5edbd0a1a +timeCreated: 1656855664 \ No newline at end of file diff --git a/Editor.Samples/Conditionals.meta b/Editor.Samples/Conditionals.meta new file mode 100644 index 0000000..b2a7560 --- /dev/null +++ b/Editor.Samples/Conditionals.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 25430c3d53e5452496a9480ebfc66910 +timeCreated: 1656857004 \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs b/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs new file mode 100644 index 0000000..4b494a8 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs @@ -0,0 +1,10 @@ +using TriInspector; +using UnityEngine; + +public class Conditionals_DisableIfSample : ScriptableObject +{ + public bool visible; + + [DisableIf(nameof(visible))] + public float val; +} \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs.meta b/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs.meta new file mode 100644 index 0000000..b3f2128 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_DisableIfSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: be63fdfd5bfc446eb40431b63ad4a582 +timeCreated: 1656857086 \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs b/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs new file mode 100644 index 0000000..f96dba4 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs @@ -0,0 +1,10 @@ +using TriInspector; +using UnityEngine; + +public class Conditionals_EnableIfSample : ScriptableObject +{ + public bool visible; + + [EnableIf(nameof(visible))] + public float val; +} \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs.meta b/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs.meta new file mode 100644 index 0000000..31615da --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_EnableIfSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b29947c09fc4b7fa1c4c6061eb945f2 +timeCreated: 1656857082 \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs b/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs new file mode 100644 index 0000000..77e63c8 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs @@ -0,0 +1,10 @@ +using TriInspector; +using UnityEngine; + +public class Conditionals_HideIfSample : ScriptableObject +{ + public bool visible; + + [HideIf(nameof(visible))] + public float val; +} \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs.meta b/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs.meta new file mode 100644 index 0000000..1b9c693 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_HideIfSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2544a3528997409eb700ca65f1be0147 +timeCreated: 1656857076 \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs b/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs new file mode 100644 index 0000000..d075a47 --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs @@ -0,0 +1,23 @@ +using TriInspector; +using UnityEngine; + +public class Conditionals_ShowIfSample : ScriptableObject +{ + public Material material; + public bool toggle; + public SomeEnum someEnum; + + [ShowIf(nameof(material), null)] + public Vector3 showWhenMaterialIsNull; + + [ShowIf(nameof(toggle))] + public Vector3 showWhenToggleIsTrue; + + [ShowIf(nameof(toggle), false)] + public Vector3 showWhenToggleIsFalse; + + [ShowIf(nameof(someEnum), SomeEnum.Two)] + public Vector3 showWhenSomeEnumIsTwo; + + public enum SomeEnum { One, Two, Three } +} \ No newline at end of file diff --git a/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs.meta b/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs.meta new file mode 100644 index 0000000..49a91eb --- /dev/null +++ b/Editor.Samples/Conditionals/Conditionals_ShowIfSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 327bc8430b4746e0860a9017e86853d6 +timeCreated: 1656857013 \ No newline at end of file diff --git a/Editor.Samples/Debug.meta b/Editor.Samples/Debug.meta new file mode 100644 index 0000000..00ca727 --- /dev/null +++ b/Editor.Samples/Debug.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3220f412f1a347aca8175b14166b0664 +timeCreated: 1656857161 \ No newline at end of file diff --git a/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs b/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs new file mode 100644 index 0000000..00f4cb6 --- /dev/null +++ b/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs @@ -0,0 +1,12 @@ +using TriInspector; +using UnityEngine; + +public class Debug_ShowDrawerChainSample : ScriptableObject +{ + [ShowDrawerChain] + [Indent] + [PropertySpace] + [Title("Custom Title")] + [GUIColor(1.0f, 0.8f, 0.8f)] + public Vector3 vec; +} \ No newline at end of file diff --git a/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs.meta b/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs.meta new file mode 100644 index 0000000..0ce3002 --- /dev/null +++ b/Editor.Samples/Debug/Debug_ShowDrawerChainSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 740fa4ad939943b2878ae3059062ba9e +timeCreated: 1656857166 \ No newline at end of file diff --git a/Editor.Samples/Groups.meta b/Editor.Samples/Groups.meta new file mode 100644 index 0000000..7593d59 --- /dev/null +++ b/Editor.Samples/Groups.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d1198759fd8a454ea350699846604c21 +timeCreated: 1656857197 \ No newline at end of file diff --git a/Editor.Samples/Groups/Groups_GroupsSample.cs b/Editor.Samples/Groups/Groups_GroupsSample.cs new file mode 100644 index 0000000..086cadb --- /dev/null +++ b/Editor.Samples/Groups/Groups_GroupsSample.cs @@ -0,0 +1,35 @@ +using TriInspector; +using UnityEngine; + +[DeclareHorizontalGroup("header")] +[DeclareBoxGroup("header/left", Title = "My Left Box")] +[DeclareVerticalGroup("header/right")] +[DeclareBoxGroup("header/right/top", Title = "My Right Box")] +[DeclareTabGroup("header/right/tabs")] +[DeclareBoxGroup("body")] +public class Groups_GroupsSample : ScriptableObject +{ + [Group("header/left")] public bool prop1; + [Group("header/left")] public int prop2; + [Group("header/left")] public string prop3; + [Group("header/left")] public Vector3 prop4; + + [Group("header/right/top")] public string rightProp; + + [Group("body")] public string body1; + [Group("body")] public string body2; + + [Group("header/right/tabs"), Tab("One")] + public float tabOne; + + [Group("header/right/tabs"), Tab("Two")] + public float tabTwo; + + [Group("header/right/tabs"), Tab("Three")] + public float tabThree; + + [Group("header/right"), Button("Click me!")] + public void MyButton() + { + } +} \ No newline at end of file diff --git a/Editor.Samples/Groups/Groups_GroupsSample.cs.meta b/Editor.Samples/Groups/Groups_GroupsSample.cs.meta new file mode 100644 index 0000000..5221df1 --- /dev/null +++ b/Editor.Samples/Groups/Groups_GroupsSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 89326426f95d4de489da63baf6efc988 +timeCreated: 1656857201 \ No newline at end of file diff --git a/Editor.Samples/Misc.meta b/Editor.Samples/Misc.meta new file mode 100644 index 0000000..5182c42 --- /dev/null +++ b/Editor.Samples/Misc.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 93e5166924a248f582d65708efbddf0a +timeCreated: 1656852588 \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_OnValueChangedSample.cs b/Editor.Samples/Misc/Misc_OnValueChangedSample.cs new file mode 100644 index 0000000..f9ee24a --- /dev/null +++ b/Editor.Samples/Misc/Misc_OnValueChangedSample.cs @@ -0,0 +1,13 @@ +using TriInspector; +using UnityEngine; + +public class Misc_OnValueChangedSample : ScriptableObject +{ + [OnValueChanged(nameof(OnMaterialChanged))] + public Material mat; + + private void OnMaterialChanged() + { + Debug.Log("Material changed!"); + } +} \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_OnValueChangedSample.cs.meta b/Editor.Samples/Misc/Misc_OnValueChangedSample.cs.meta new file mode 100644 index 0000000..1417ed7 --- /dev/null +++ b/Editor.Samples/Misc/Misc_OnValueChangedSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7068787aa2c749b992eab640bba2d436 +timeCreated: 1656856619 \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_PropertyOrderSample.cs b/Editor.Samples/Misc/Misc_PropertyOrderSample.cs new file mode 100644 index 0000000..7f16c70 --- /dev/null +++ b/Editor.Samples/Misc/Misc_PropertyOrderSample.cs @@ -0,0 +1,10 @@ +using TriInspector; +using UnityEngine; + +public class Misc_PropertyOrderSample : ScriptableObject +{ + public float first; + + [PropertyOrder(0)] + public float second; +} \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_PropertyOrderSample.cs.meta b/Editor.Samples/Misc/Misc_PropertyOrderSample.cs.meta new file mode 100644 index 0000000..c9ef13b --- /dev/null +++ b/Editor.Samples/Misc/Misc_PropertyOrderSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c14c7b55b1374730833ca86db22fb4fe +timeCreated: 1656856254 \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_ReadOnlySample.cs b/Editor.Samples/Misc/Misc_ReadOnlySample.cs new file mode 100644 index 0000000..b18b280 --- /dev/null +++ b/Editor.Samples/Misc/Misc_ReadOnlySample.cs @@ -0,0 +1,8 @@ +using TriInspector; +using UnityEngine; + +public class Misc_ReadOnlySample : ScriptableObject +{ + [ReadOnly] + public Vector3 vec; +} \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_ReadOnlySample.cs.meta b/Editor.Samples/Misc/Misc_ReadOnlySample.cs.meta new file mode 100644 index 0000000..eea8704 --- /dev/null +++ b/Editor.Samples/Misc/Misc_ReadOnlySample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8188742392614449bf6c0ff330488ea0 +timeCreated: 1656856352 \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs b/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs new file mode 100644 index 0000000..db61176 --- /dev/null +++ b/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs @@ -0,0 +1,17 @@ +using TriInspector; +using UnityEngine; + +public class Misc_ShowInInspectorSample : ScriptableObject +{ + private float _field; + + [ShowInInspector] + public float ReadOnlyProperty => _field; + + [ShowInInspector] + public float EditableProperty + { + get => _field; + set => _field = value; + } +} \ No newline at end of file diff --git a/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs.meta b/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs.meta new file mode 100644 index 0000000..dc0605b --- /dev/null +++ b/Editor.Samples/Misc/Misc_ShowInInspectorSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3e605b771ea2468da31945707d0fb76a +timeCreated: 1656848081 \ No newline at end of file diff --git a/Editor.Samples/SampleWindowStyles.cs b/Editor.Samples/SampleWindowStyles.cs new file mode 100644 index 0000000..24d3103 --- /dev/null +++ b/Editor.Samples/SampleWindowStyles.cs @@ -0,0 +1,32 @@ +using UnityEditor; +using UnityEngine; + +namespace TriInspector.Editor.Samples +{ + internal static class SampleWindowStyles + { + public static readonly GUIStyle Padding; + public static readonly GUIStyle BoxWithPadding; + public static readonly GUIStyle HeaderDisplayNameLabel; + + static SampleWindowStyles() + { + Padding = new GUIStyle(GUI.skin.label) + { + padding = new RectOffset(5, 5, 5, 5), + }; + + BoxWithPadding = new GUIStyle(TriEditorStyles.Box) + { + padding = new RectOffset(5, 5, 5, 5), + }; + + HeaderDisplayNameLabel = new GUIStyle(EditorStyles.largeLabel) + { + fontStyle = FontStyle.Bold, + fontSize = 17, + margin = new RectOffset(5, 5, 5, 0), + }; + } + } +} \ No newline at end of file diff --git a/Editor.Samples/SampleWindowStyles.cs.meta b/Editor.Samples/SampleWindowStyles.cs.meta new file mode 100644 index 0000000..91833f1 --- /dev/null +++ b/Editor.Samples/SampleWindowStyles.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ddb081b7f73a4b58aca6d24aaefbc50e +timeCreated: 1656858907 \ No newline at end of file diff --git a/Editor.Samples/Styling.meta b/Editor.Samples/Styling.meta new file mode 100644 index 0000000..247e7b5 --- /dev/null +++ b/Editor.Samples/Styling.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: da4c8e005b7646358db1c3c4811a1865 +timeCreated: 1656856718 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_GUIColorSample.cs b/Editor.Samples/Styling/Styling_GUIColorSample.cs new file mode 100644 index 0000000..4d42ac9 --- /dev/null +++ b/Editor.Samples/Styling/Styling_GUIColorSample.cs @@ -0,0 +1,20 @@ +using TriInspector; +using UnityEngine; + +public class Styling_GUIColorSample : ScriptableObject +{ + [GUIColor(0.8f, 1.0f, 0.6f)] + public Vector3 vec; + + [GUIColor(0.6f, 0.9f, 1.0f)] + [Button] + public void BlueButton() + { + } + + [GUIColor(1.0f, 0.6f, 0.6f)] + [Button] + public void RedButton() + { + } +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_GUIColorSample.cs.meta b/Editor.Samples/Styling/Styling_GUIColorSample.cs.meta new file mode 100644 index 0000000..f22f334 --- /dev/null +++ b/Editor.Samples/Styling/Styling_GUIColorSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f99fc38989d4471da97400b0a2a812ff +timeCreated: 1656856827 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_HideLabelSample.cs b/Editor.Samples/Styling/Styling_HideLabelSample.cs new file mode 100644 index 0000000..fbacbb8 --- /dev/null +++ b/Editor.Samples/Styling/Styling_HideLabelSample.cs @@ -0,0 +1,13 @@ +using TriInspector; +using UnityEngine; + +public class Styling_HideLabelSample : ScriptableObject +{ + [Title("Wide Vector")] + [HideLabel] + public Vector3 vector; + + [Title("Wide String")] + [HideLabel] + public string str; +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_HideLabelSample.cs.meta b/Editor.Samples/Styling/Styling_HideLabelSample.cs.meta new file mode 100644 index 0000000..6ddf553 --- /dev/null +++ b/Editor.Samples/Styling/Styling_HideLabelSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f39878f7ed574f7898bf55caf8d8e607 +timeCreated: 1656856749 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_IndentSample.cs b/Editor.Samples/Styling/Styling_IndentSample.cs new file mode 100644 index 0000000..eb2cade --- /dev/null +++ b/Editor.Samples/Styling/Styling_IndentSample.cs @@ -0,0 +1,18 @@ +using TriInspector; +using UnityEngine; + +public class Styling_IndentSample : ScriptableObject +{ + [Title("Custom Indent")] + [Indent] + public int a; + + [Indent(2)] + public int b; + + [Indent(3)] + public int c; + + [Indent(4)] + public int d; +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_IndentSample.cs.meta b/Editor.Samples/Styling/Styling_IndentSample.cs.meta new file mode 100644 index 0000000..524d423 --- /dev/null +++ b/Editor.Samples/Styling/Styling_IndentSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1f33bec5e9334e10949fbf94ae0a21f5 +timeCreated: 1656856846 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_InlineEditorSample.cs b/Editor.Samples/Styling/Styling_InlineEditorSample.cs new file mode 100644 index 0000000..eab870b --- /dev/null +++ b/Editor.Samples/Styling/Styling_InlineEditorSample.cs @@ -0,0 +1,8 @@ +using TriInspector; +using UnityEngine; + +public class Styling_InlineEditorSample : ScriptableObject +{ + [InlineEditor] + public Material mat; +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_InlineEditorSample.cs.meta b/Editor.Samples/Styling/Styling_InlineEditorSample.cs.meta new file mode 100644 index 0000000..619734c --- /dev/null +++ b/Editor.Samples/Styling/Styling_InlineEditorSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 151f5ace94624b5b9fa4b4ee34b5e41f +timeCreated: 1656856914 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_InlinePropertySample.cs b/Editor.Samples/Styling/Styling_InlinePropertySample.cs new file mode 100644 index 0000000..d6fac83 --- /dev/null +++ b/Editor.Samples/Styling/Styling_InlinePropertySample.cs @@ -0,0 +1,18 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Styling_InlinePropertySample : ScriptableObject +{ + public MinMax rangeFoldout; + + [InlineProperty(LabelWidth = 40)] + public MinMax rangeInline; + + [Serializable] + public class MinMax + { + public int min; + public int max; + } +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_InlinePropertySample.cs.meta b/Editor.Samples/Styling/Styling_InlinePropertySample.cs.meta new file mode 100644 index 0000000..f7ada42 --- /dev/null +++ b/Editor.Samples/Styling/Styling_InlinePropertySample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e0ee1888cb6649ceafe31245787ac0e5 +timeCreated: 1656856939 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_LabelTextSample.cs b/Editor.Samples/Styling/Styling_LabelTextSample.cs new file mode 100644 index 0000000..55c1490 --- /dev/null +++ b/Editor.Samples/Styling/Styling_LabelTextSample.cs @@ -0,0 +1,14 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Styling_LabelTextSample : ScriptableObject +{ + [LabelText("Custom Label")] + public int val; + + [LabelText("$" + nameof(DynamicLabel))] + public Vector3 vec; + + public string DynamicLabel => DateTime.Now.ToShortTimeString(); +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_LabelTextSample.cs.meta b/Editor.Samples/Styling/Styling_LabelTextSample.cs.meta new file mode 100644 index 0000000..75b3fe3 --- /dev/null +++ b/Editor.Samples/Styling/Styling_LabelTextSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7d6fabaf62504cf682d96b5245e4a3f5 +timeCreated: 1656856777 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_LabelWidthSample.cs b/Editor.Samples/Styling/Styling_LabelWidthSample.cs new file mode 100644 index 0000000..1884a3a --- /dev/null +++ b/Editor.Samples/Styling/Styling_LabelWidthSample.cs @@ -0,0 +1,13 @@ +using TriInspector; +using UnityEngine; + +public class Styling_LabelWidthSample : ScriptableObject +{ + public int defaultWidth; + + [LabelWidth(40)] + public int thin; + + [LabelWidth(300)] + public int customInspectorVeryLongPropertyName; +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_LabelWidthSample.cs.meta b/Editor.Samples/Styling/Styling_LabelWidthSample.cs.meta new file mode 100644 index 0000000..e8a6ae2 --- /dev/null +++ b/Editor.Samples/Styling/Styling_LabelWidthSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 114e6af58ba440469f9a80c8094944f3 +timeCreated: 1656856804 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_PropertySpaceSample.cs b/Editor.Samples/Styling/Styling_PropertySpaceSample.cs new file mode 100644 index 0000000..84e5ad4 --- /dev/null +++ b/Editor.Samples/Styling/Styling_PropertySpaceSample.cs @@ -0,0 +1,15 @@ +using TriInspector; +using UnityEngine; + +public class Styling_PropertySpaceSample : ScriptableObject +{ + [Space, PropertyOrder(0)] + public Vector3 vecField; + + [ShowInInspector, PropertyOrder(1)] + [PropertySpace(SpaceBefore = 10, SpaceAfter = 30)] + public Rect RectProperty { get; set; } + + [PropertyOrder(2)] + public bool b; +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_PropertySpaceSample.cs.meta b/Editor.Samples/Styling/Styling_PropertySpaceSample.cs.meta new file mode 100644 index 0000000..0fb819d --- /dev/null +++ b/Editor.Samples/Styling/Styling_PropertySpaceSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6ba5d5c0bd824ccc8cdfb279d18821c3 +timeCreated: 1656856868 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs b/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs new file mode 100644 index 0000000..62c330b --- /dev/null +++ b/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs @@ -0,0 +1,14 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Styling_PropertyTooltipSample : ScriptableObject +{ + [PropertyTooltip("This is tooltip")] + public Rect rect; + + [PropertyTooltip("$" + nameof(DynamicTooltip))] + public Vector3 vec; + + public string DynamicTooltip => DateTime.Now.ToShortTimeString(); +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs.meta b/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs.meta new file mode 100644 index 0000000..698f44c --- /dev/null +++ b/Editor.Samples/Styling/Styling_PropertyTooltipSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 866d0af24dd1465798f6fc588a18f0ac +timeCreated: 1656856888 \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_TitleSample.cs b/Editor.Samples/Styling/Styling_TitleSample.cs new file mode 100644 index 0000000..5927b59 --- /dev/null +++ b/Editor.Samples/Styling/Styling_TitleSample.cs @@ -0,0 +1,25 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Styling_TitleSample : ScriptableObject +{ + [Title("My Title")] + public string val; + + [Title("$" + nameof(_myTitleField))] + public Rect rect; + + [Title("$" + nameof(MyTitleProperty))] + public Vector3 vec; + + [Title("Button Title")] + [Button] + public void MyButton() + { + } + + private string _myTitleField = "Serialized Title"; + + private string MyTitleProperty => DateTime.Now.ToLongTimeString(); +} \ No newline at end of file diff --git a/Editor.Samples/Styling/Styling_TitleSample.cs.meta b/Editor.Samples/Styling/Styling_TitleSample.cs.meta new file mode 100644 index 0000000..8d6c943 --- /dev/null +++ b/Editor.Samples/Styling/Styling_TitleSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e54656b5b8ed48f2affb7d716661cddd +timeCreated: 1656856725 \ No newline at end of file diff --git a/Editor.Samples/TriInspector.Editor.Samples.asmdef b/Editor.Samples/TriInspector.Editor.Samples.asmdef new file mode 100644 index 0000000..685f36c --- /dev/null +++ b/Editor.Samples/TriInspector.Editor.Samples.asmdef @@ -0,0 +1,18 @@ +{ + "name": "TriInspector.Editor.Samples", + "references": [ + "TriInspector", + "TriInspector.Editor" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [], + "autoReferenced": false, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor.Samples/TriInspector.Editor.Samples.asmdef.meta b/Editor.Samples/TriInspector.Editor.Samples.asmdef.meta new file mode 100644 index 0000000..25945d0 --- /dev/null +++ b/Editor.Samples/TriInspector.Editor.Samples.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 6fd3d95cbfe66d744a1e3a709d4c510d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor.Samples/TriSamplesWindow.cs b/Editor.Samples/TriSamplesWindow.cs new file mode 100644 index 0000000..310e6d6 --- /dev/null +++ b/Editor.Samples/TriSamplesWindow.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using TriInspector.Utilities; +using UnityEditor; +using UnityEditor.IMGUI.Controls; +using UnityEngine; + +namespace TriInspector.Editor.Samples +{ + internal class TriSamplesWindow : EditorWindow + { + private MenuTree _menuTree; + private SearchField _searchField; + + private ScriptableObject _current; + private SerializedObject _currentSerializedObject; + private TriPropertyTree _currentPropertyTree; + private MonoScript _currentMonoScript; + private Vector2 _currentScroll; + + [MenuItem("Tools/Tri Inspector/Samples")] + public static void Open() + { + var window = GetWindow(); + window.titleContent = new GUIContent("Tri Samples"); + window.Show(); + } + + private void OnEnable() + { + _menuTree = new MenuTree(new TreeViewState()); + _menuTree.SelectedTypeChanged += ChangeCurrentSample; + + _searchField = new SearchField(); + _searchField.downOrUpArrowKeyPressed += _menuTree.SetFocusAndEnsureSelectedItem; + + _menuTree.Reload(); + } + + private void OnDisable() + { + ChangeCurrentSample(null); + } + + private void OnGUI() + { + using (new GUILayout.HorizontalScope()) + { + using (new GUILayout.VerticalScope(GUILayout.Width(200))) + { + DrawMenu(); + } + + var separatorRect = GUILayoutUtility.GetLastRect(); + separatorRect.xMin = separatorRect.xMax; + separatorRect.xMax += 1; + GUI.Box(separatorRect, ""); + + using (new GUILayout.VerticalScope()) + { + DrawElement(); + } + } + } + + private void DrawMenu() + { + using (new GUILayout.HorizontalScope(EditorStyles.toolbar, GUILayout.ExpandWidth(true))) + { + GUILayout.Space(5); + _menuTree.searchString = _searchField.OnToolbarGUI(_menuTree.searchString, GUILayout.ExpandWidth(true)); + GUILayout.Space(5); + } + + var menuRect = GUILayoutUtility.GetRect(0, 100000, 0, 100000); + _menuTree.OnGUI(menuRect); + } + + private void DrawElement() + { + if (_currentPropertyTree == null || _currentMonoScript == null) + { + return; + } + + using (var scrollScope = new GUILayout.ScrollViewScope(_currentScroll)) + { + _currentScroll = scrollScope.scrollPosition; + + using (new GUILayout.VerticalScope(SampleWindowStyles.Padding)) + { + GUILayout.Label(_current.name, SampleWindowStyles.HeaderDisplayNameLabel); + + _currentSerializedObject.UpdateIfRequiredOrScript(); + _currentPropertyTree.Update(); + + if (_currentPropertyTree.ValidationRequired) + { + _currentPropertyTree.RunValidation(); + } + + GUILayout.Space(10); + GUILayout.Label("Preview", EditorStyles.boldLabel); + + using (TriGuiHelper.PushEditorTarget(_current)) + using (new GUILayout.VerticalScope(SampleWindowStyles.BoxWithPadding)) + { + var viewWidth = GUILayoutUtility.GetRect(0, 10000, 0, 0).width; + _currentPropertyTree.Draw(viewWidth); + } + + if (_currentSerializedObject.ApplyModifiedProperties()) + { + _currentPropertyTree.RequestValidation(); + } + + if (_currentPropertyTree.RepaintRequired) + { + Repaint(); + } + + GUILayout.Space(10); + GUILayout.Label("Code", EditorStyles.boldLabel); + + using (new GUILayout.VerticalScope(SampleWindowStyles.BoxWithPadding)) + { + GUILayout.TextField(_currentMonoScript.text); + } + } + } + } + + private void ChangeCurrentSample(Type type) + { + if (_current != null) + { + DestroyImmediate(_current); + _current = null; + } + + if (_currentSerializedObject != null) + { + _currentSerializedObject.Dispose(); + _currentSerializedObject = null; + } + + if (_currentPropertyTree != null) + { + _currentPropertyTree.Dispose(); + _currentPropertyTree = null; + } + + _currentScroll = Vector2.zero; + + if (type != null) + { + _current = CreateInstance(type); + _current.name = GetTypeNiceName(type); + _current.hideFlags = HideFlags.DontSave; + + _currentSerializedObject = new SerializedObject(_current); + _currentMonoScript = MonoScript.FromScriptableObject(_current); + _currentPropertyTree = new TriPropertyTreeForSerializedObject(_currentSerializedObject); + } + } + + private static string GetTypeNiceName(Type type) + { + var name = type.Name; + + if (name.Contains('_')) + { + var index = name.IndexOf('_'); + name = name.Substring(index + 1); + } + + if (name.EndsWith("Sample")) + { + name = name.Remove(name.Length - "Sample".Length); + } + + return name; + } + + private class MenuTree : TreeView + { + private readonly Dictionary _groups = new Dictionary(); + + public event Action SelectedTypeChanged; + + public MenuTree(TreeViewState state) : base(state) + { + } + + protected override bool CanMultiSelect(TreeViewItem item) + { + return false; + } + + protected override void SelectionChanged(IList selectedIds) + { + base.SelectionChanged(selectedIds); + + var type = selectedIds.Count > 0 && FindItem(selectedIds[0], rootItem) is SampleItem sampleItem + ? sampleItem.Type + : null; + + SelectedTypeChanged?.Invoke(type); + } + + protected override TreeViewItem BuildRoot() + { + var root = new TreeViewItem(-1, -1); + + var sampleTypes = typeof(TriSamplesWindow).Assembly.GetTypes() + .Where(type => type.BaseType == typeof(ScriptableObject)) + .OrderBy(type => type.Name) + .ToList(); + + var id = 0; + foreach (var sampleType in sampleTypes) + { + var group = sampleType.Name.Split('_')[0]; + + if (!_groups.TryGetValue(group, out var groupItem)) + { + _groups[group] = groupItem = new GroupItem(++id, group); + + root.AddChild(groupItem); + } + + groupItem.AddChild(new SampleItem(++id, sampleType)); + } + + return root; + } + + private class GroupItem : TreeViewItem + { + public GroupItem(int id, string name) : base(id, 0, name) + { + } + } + + private class SampleItem : TreeViewItem + { + public Type Type { get; } + + public SampleItem(int id, Type type) : base(id, 1, GetTypeNiceName(type)) + { + Type = type; + } + } + } + } +} \ No newline at end of file diff --git a/Editor.Samples/TriSamplesWindow.cs.meta b/Editor.Samples/TriSamplesWindow.cs.meta new file mode 100644 index 0000000..c3af872 --- /dev/null +++ b/Editor.Samples/TriSamplesWindow.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8a36cdbb8bee439f988a44ff424593bb +timeCreated: 1656847262 \ No newline at end of file diff --git a/Editor.Samples/Validators.meta b/Editor.Samples/Validators.meta new file mode 100644 index 0000000..18b6dcc --- /dev/null +++ b/Editor.Samples/Validators.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b7160cc0e3bd4f1a8cb43ea3c2b00c7f +timeCreated: 1656856456 \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_AssetsOnlySample.cs b/Editor.Samples/Validators/Validators_AssetsOnlySample.cs new file mode 100644 index 0000000..3b291e5 --- /dev/null +++ b/Editor.Samples/Validators/Validators_AssetsOnlySample.cs @@ -0,0 +1,8 @@ +using TriInspector; +using UnityEngine; + +public class Validators_AssetsOnlySample : ScriptableObject +{ + [AssetsOnly] + public GameObject obj; +} \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_AssetsOnlySample.cs.meta b/Editor.Samples/Validators/Validators_AssetsOnlySample.cs.meta new file mode 100644 index 0000000..d2fd876 --- /dev/null +++ b/Editor.Samples/Validators/Validators_AssetsOnlySample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 374fcd38854b483a83cdde8ef3c1faba +timeCreated: 1656856695 \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_InfoBoxSample.cs b/Editor.Samples/Validators/Validators_InfoBoxSample.cs new file mode 100644 index 0000000..0795009 --- /dev/null +++ b/Editor.Samples/Validators/Validators_InfoBoxSample.cs @@ -0,0 +1,26 @@ +using System; +using TriInspector; +using UnityEngine; + +public class Validators_InfoBoxSample : ScriptableObject +{ + [Title("InfoBox Message Types")] + [InfoBox("Default info box")] + public int a; + + [InfoBox("None info box", TriMessageType.None)] + public int b; + + [InfoBox("Warning info box", TriMessageType.Warning)] + public int c; + + [InfoBox("Error info box", TriMessageType.Error)] + public int d; + + [InfoBox("$" + nameof(DynamicInfo), visibleIf: nameof(VisibleInEditMode))] + public Vector3 vec; + + private string DynamicInfo => "Dynamic info box: " + DateTime.Now.ToLongTimeString(); + + private bool VisibleInEditMode => !Application.isPlaying; +} \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_InfoBoxSample.cs.meta b/Editor.Samples/Validators/Validators_InfoBoxSample.cs.meta new file mode 100644 index 0000000..8b9d649 --- /dev/null +++ b/Editor.Samples/Validators/Validators_InfoBoxSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 86a17b90790548718bdb5d26c8a83c95 +timeCreated: 1656856674 \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_RequiredSample.cs b/Editor.Samples/Validators/Validators_RequiredSample.cs new file mode 100644 index 0000000..5787d8a --- /dev/null +++ b/Editor.Samples/Validators/Validators_RequiredSample.cs @@ -0,0 +1,8 @@ +using TriInspector; +using UnityEngine; + +public class Validators_RequiredSample : ScriptableObject +{ + [Required] + public Material mat; +} \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_RequiredSample.cs.meta b/Editor.Samples/Validators/Validators_RequiredSample.cs.meta new file mode 100644 index 0000000..6acb5b8 --- /dev/null +++ b/Editor.Samples/Validators/Validators_RequiredSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 26503f30077744908a680c7464ee7991 +timeCreated: 1656856504 \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_ValidateInputSample.cs b/Editor.Samples/Validators/Validators_ValidateInputSample.cs new file mode 100644 index 0000000..bc9c198 --- /dev/null +++ b/Editor.Samples/Validators/Validators_ValidateInputSample.cs @@ -0,0 +1,15 @@ +using TriInspector; +using UnityEngine; + +public class Validators_ValidateInputSample : ScriptableObject +{ + [ValidateInput(nameof(ValidateTexture))] + public Texture tex; + + private TriValidationResult ValidateTexture() + { + if (tex == null) return TriValidationResult.Error("Tex is null"); + if (!tex.isReadable) return TriValidationResult.Warning("Tex must be readable"); + return TriValidationResult.Valid; + } +} \ No newline at end of file diff --git a/Editor.Samples/Validators/Validators_ValidateInputSample.cs.meta b/Editor.Samples/Validators/Validators_ValidateInputSample.cs.meta new file mode 100644 index 0000000..74c134b --- /dev/null +++ b/Editor.Samples/Validators/Validators_ValidateInputSample.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 75ac78d47ba34b6380df278a3e641e87 +timeCreated: 1656856540 \ No newline at end of file diff --git a/Editor/AssemblyInfo.cs b/Editor/AssemblyInfo.cs index 985a429..7f6971e 100644 --- a/Editor/AssemblyInfo.cs +++ b/Editor/AssemblyInfo.cs @@ -1,3 +1,4 @@ using System.Runtime.CompilerServices; +[assembly: InternalsVisibleTo("TriInspector.Editor.Samples")] [assembly: InternalsVisibleTo("TriInspector.Editor.Integrations.Odin")] \ No newline at end of file diff --git a/Editor/TriPropertyTree.cs b/Editor/TriPropertyTree.cs index dddbcba..07a2788 100644 --- a/Editor/TriPropertyTree.cs +++ b/Editor/TriPropertyTree.cs @@ -48,7 +48,7 @@ namespace TriInspector RequestRepaint(); } - public void Draw() + public void Draw(float? viewWidth = null) { RepaintRequired = false; @@ -62,7 +62,7 @@ namespace TriInspector } _rootPropertyElement.Update(); - var width = EditorGUIUtility.currentViewWidth; + var width = viewWidth ?? EditorGUIUtility.currentViewWidth; var height = _rootPropertyElement.GetHeight(width); var rect = GUILayoutUtility.GetRect(width, height); rect.xMin += 3; diff --git a/README.md b/README.md index 6f219fa..3a74d33 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ _Advanced inspector attributes for Unity_ - [How to Install](#How-to-Install) - [Roadmap](#Roadmap) +- [Samples](#Samples) - [Attributes](#Attributes) - [Misc](#Misc) - [Validation](#Validation) @@ -35,6 +36,11 @@ After package installation **run the Installer** by double clicking on it. ## Roadmap ![GitHub Repo stars](https://img.shields.io/github/stars/codewriter-packages/Tri-Inspector?style=social) Each star ★ on the project page brings new features closer. See roadmap and more info [here](https://github.com/codewriter-packages/Tri-Inspector/issues/9). +## Samples + +TriInspector has built-in samples at `Tools/Tri Inspector/Samples` menu. +![Samples](https://user-images.githubusercontent.com/26966368/177045336-a3fcf438-3e70-45d0-b753-299e577b2010.png) + ## Attributes ### Misc