├── Attributes
└── OdinTreeAttribute.cs
├── Editor
└── OdinTreeAttributeDrawer.cs
├── LICENSE
└── README.md
/Attributes/OdinTreeAttribute.cs:
--------------------------------------------------------------------------------
1 | using ParadoxNotion.Design;
2 |
3 | ///
4 | /// Used to draw serialized classes using Odin's PropertyTree
5 | ///
6 | public class OdinTreeAttribute : DrawerAttribute { }
--------------------------------------------------------------------------------
/Editor/OdinTreeAttributeDrawer.cs:
--------------------------------------------------------------------------------
1 | using ParadoxNotion.Design;
2 | using Sirenix.OdinInspector.Editor;
3 | using System;
4 | using UnityEngine;
5 |
6 | ///
7 | /// Draw an object using the Property Tree of Odin
8 | ///
9 | public class OdinTreeAttributeDrawer : AttributeDrawer {
10 |
11 | private PropertyTree propertyTree;
12 | private object obj;
13 |
14 | public override object OnGUI(GUIContent content, object instance) {
15 |
16 | // Create a instance if is null
17 | if (instance == null) {
18 | instance = Activator.CreateInstance(info.field.FieldType);
19 | }
20 |
21 | // Update the object
22 | if (propertyTree == null || obj != instance) {
23 | obj = instance;
24 | propertyTree = PropertyTree.Create(instance);
25 | }
26 |
27 | propertyTree.Draw(false);
28 | return instance;
29 | }
30 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 André Felipe Siqueira
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # OdinTree
2 |
3 | This attribute will make it easier when you need to create custom fields and windows within the NodeCanvas, as this attribute will draws objects using the [Property Tree](https://odininspector.com/tutorials/how-to-create-custom-drawers-using-odin/how-to-use-the-propertytree) in conjunction with the [Attribute Drawer](https://nodecanvas.paradoxnotion.com/documentation/?section=creating-custom-object-drawers).
4 |
5 | Requires [Odin Inspector](https://odininspector.com/) and [NodeCanvas](https://nodecanvas.paradoxnotion.com/).
6 |
7 | # Installation
8 | Simply put the OdinTreeAttributeDrawer.cs file inside an Editor folder and the OdinTreeAttribute.cs in a shared folder, and start using the attribute as shown in the example.
9 |
10 | # Example
11 |
12 | First you create a serialized class using the attribute [System.Serializeble]. Within this class you can use any attribute, including other assets such as [FMODUnity.EventRef].
13 |
14 | ``` c#
15 | [System.Serializable]
16 | public class DialogueConfig {
17 |
18 | [TextArea]
19 | public string text = "This is a dialogue text";
20 |
21 | [ColorPalette("ActorsColors")]
22 | public Color color;
23 |
24 | public PlayableAsset playable;
25 |
26 | [FMODUnity.EventRef]
27 | public string sound;
28 | }
29 | ```
30 | And then just declare your class using the [OdinTree] attribute inside a NodeCanvas class, for example using the ActionTask.
31 |
32 | ``` c#
33 | public class Speak : ActionTask {
34 | [OdinTree] public DialogueConfig dialogueConfig;
35 | }
36 | ```
37 |
38 | Preview:
39 | 
40 |
--------------------------------------------------------------------------------