Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Install and setup Sticky

A topic by CatyboyStudio created Oct 13, 2022 Views: 139 Replies: 1
Viewing posts 1 to 2
(7 edits)

Install

Before each version upgrade, delete the installed code first

- Install from package file

  • Launch the Unity editor and open the project
  • Go to menu Assets->Import Package->Custom Package
  • Select the package file and click Open
  • Click the Import button to install package

Know how it work

The plug-in uses the "Builder" to build the related data into the UIElements control

- Builders are divided into three types according to the type of data built

  1. Object Builder - build Class/Struct data to control
  2. Array Builder - build Array/List data to control
  3. Property Builder - build property/ArrayElement to control
Now look at the following examples to understand the concepts

Source Code

public class SampleTest : MonoBehaviour     
{         
    public int Value1;         
    [Serializable]         
    public class NestClass         
    {             
        public int Nest1;         
    }         
    public NestClass Value2;         
    public int[] Array1;     
}

Introduce

public class SampleTest : MonoBehaviour  <-- apply ObjectBuilder(RootObject)
{              
    public int Value1; <-- apply PropertyBuilder
    [Serializable]              
    public class NestClass <-- apply ObjectBuilder(NestObject)           
    {                      
        public int Nest1; <-- apply PropertyBuilder
    }              
    public NestClass Value2; <-- apply PropertyBuilder then apply ObjectBuilder
    public int[] Array1; <-- apply ArrayBuilder then apply PropertyBuilder(ArrayElements)
}

- Builders are divided into different types according to how they are implemented

  • UnityBuilder - Unity built-in implementation solution (IMGUI)
  • ToolkitBuilder - the plug-in implementation solution (UIToolkit WithAttributes)
Below according to different environments and scenarios, learn how to Setup the relevant Builder

Setup editor environment

- Root object builder in Inspector

By default, after installing this plug-in, the ToolkitInspector is automatically launched as an Object's Inspector to build root object

If you want to launch ToolkitInspector only for specific Objects, modify the file

Assets/UIToolkitWithAttributes/Editor/Scripts/Config/DefaultToolkitInspector.cs

[CanEditMultipleObjects]
//[CustomEditor(typeof(UnityEngine.Object), true)]
[CustomEditor(typeof(HereYouClassName1))]
[CustomEditor(typeof(HereYouClassName2))]
public class DefaultToolkitInspector : ToolkitInspector
{
}

Comment out the following code

[CustomEditor(typeof(UnityEngine.Object), true)]

Add the object type you want to enable

[CustomEditor(typeof(HereYouClassName1))]
[CustomEditor(typeof(HereYouClassName2))]

- Root object builder in EditorWindow

To enable ToolkitBuilder, the associated EditorWindow type needs to be derived from class ToolkitEditorWindow

Sample code here, ModelInfoEditorWindow is both a EditorWindow and a root object for Builder

public class ModelInfoEditorWindow : ToolkitEditorWindow
{
    MenuItem("Tools/UIToolkitWithAttributes/ModelInfo")]
    public static void ShowWindow()
    {
        var ed = EditorWindow.GetWindow<ModelInfoEditorWindow>();
        ed.Show();
    }
    ...
}

- Nest object builder for Serializable class

<1,1>

By default, use UnityBuilder to handle nest serializable class. In this case, some feature functions cannot take effect, such as properties sorting

If you want to enable ToolkitBuilder, you need to set [ToolkitDrawer] on the property associated with the serializable class, see Example2 below

<1.2 or later>

By default, ToolkitBuilder will enable to handle nest serializable class

If you want to disable this setting, you can use modify file

Assets/UIToolkitWithAttributes/Editor/Scripts/Config/ToolkitApplyScope.cs

Set the following constants to false

public const bool Apply_SerializedProperty_GenericClass = false;


- Nest object builder for none-Serializable class

<1.1>

UnityBuilder will not handle this kind of situation, if want build none-serializable class, ToolkitBuilder must be enabled. For details, refer to the above

<1.2 or later>

By default, ToolkitBuilder will handle it, but none-Serializable property will ignore, if the property not display, set [ShowInInspector] on it

- Array builder

Now UnityBuilder to handle array, ToolkitBuilder can't handle this situation

In later version plan, ToolkitBuilder will be able to handle Array/List

- Skip types

If there are parts of the UnityEngine.Object (or normal Class, Struct) that do not want to use the ToolkitBuilder, you can setup the following codes

Assets/UIToolkitWithAttributes/Editor/Scripts/Config/SkipTypeList.cs

public static Type[] SKIP_TYPEs = new Type[]
{
    typeof(HereYouClassName1),
    typeof(HereYouClassName2),
};

- Serializable property builder

Based on the type of object Builder associated with the property, there are the following cases

-- UnityBuilder as object builder

By default, UnityBuilder use as property builder

If the Toolkit Attribute is set on the property, it MAYBE switched to ToolkitBuilder

In this case, if you find that Attribute is not take effects, you can manually set the ToolkitDrawerAttribute on the relevant properties to enable.

-- ToolkitBuilder as object Builder

ToolkitBuilder use as property builder. But for the properties of NestClass, NestStruct, and Array, ToolkitBuilder may not applied.

In this case, set [ShowInInspector] on the property

Example1 - enable ToolkitBuilder for property

[System.Serializable] 
public class LabelNest1
{     
    [Label("Label2")]   
    [ToolkitDrawer]  
    public int Value1;
}

Example2 - enable ToolkitBuilder for property's object 

[System.Serializable] 
public class LabelNest1
{    
    …
}
[ToolkitDrawer] 
public LabelNest1 Value1;

- none-Serializable property builder

UnityBuilder can't handle this situation

In general, ToolkitBuilder will ignore such attributes unless Toolkit Attribute is set for the property, if the property not display, set [ShowInInspector] on it

- ArrayElement builder

Consistent with the situation of property builder, since UnityBuilder is used as array builder at present, if ToolkitBuilder is not correctly enabled in some places, there is no good solution to deal with it

This solution will be optimized in future releases

Setup runtime environment

After version 1.2, A began supporting the builder of the Runtime environment, of couse, all builder is ToolkitBuilder

For the most part, the instructions are consistent with the Editor environment

To enable ToolkitBuilder in runtime, setup ToolkitRuntimeView as UIElement container then Call method CreateView, passing in a root object as an argument 

ToolkitRuntimeView m_RuntimeView;
private void Start()
{
    ...
    m_RuntimeView.CreateView(RootObject);
}


[SerializeReference]

By default, both UnityBuilder and ToolBuilder do not process property with this Attribute, You need to do the following coding

[SerializeReference]
[InstancePolicy(InstancePolicyAttribute.PolicyType.UsingDerived)]
public ActorType Actor;