Override this method if you want to change the label of the Preview area. Implement this method to show asset information on top of the asset preview. The first entry point for Preview Drawing. Implement this method to make a custom UIElements inspector.ĭiscards unsaved changes to the contents of the editor.Ĭall this function to draw the header of the editor. Mp.gun = ( GameObject) EditorGUILayout.ObjectField ("Gun Object", mp.gun, typeof( GameObject), allowSceneObjects) ProgressBar (mp.armor / 100.0f, "Armor") īool allowSceneObjects = ! EditorUtility.IsPersistent (target) Mp.armor = EditorGUILayout.IntSlider ("Armor", mp.armor, 0, 100) ProgressBar (mp.damage / 100.0f, "Damage") Mp.damage = EditorGUILayout.IntSlider ("Damage", mp.damage, 0, 100) MyPlayerAlternative mp = (MyPlayerAlternative)target Public class MyPlayerEditorAlternative : Editor No handling of multi-object editing, undo, and Prefab overrides! Custom Editor the "old" way by modifying the script variables directly. Public class MyPlayerAlternative : MonoBehaviour Rect rect = GUILayoutUtility.GetRect (18, 18, " TextField") ĮditorGUI.ProgressBar (rect, value, label) Get a rect for the progress bar using the same margins as a textfield: Void ProgressBar (float value, string label) SerializedObject.ApplyModifiedProperties () Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. ProgressBar (armorProp.intValue / 100.0f, "Armor") ĮditorGUILayout.PropertyField (gunProp, new GUIContent ("Gun Object")) If (!armorProp.hasMultipleDifferentValues) Only show the armor progress bar if all the objects have the same armor value: ProgressBar (damageProp.intValue / 100.0f, "Damage") ĮditorGUILayout.IntSlider (armorProp, 0, 100, new GUIContent ("Armor")) If (!damageProp.hasMultipleDifferentValues) Only show the damage progress bar if all the objects have the same damage value: Update the serializedProperty - always do this in the beginning of OnInspectorGUI.ĮditorGUILayout.IntSlider (damageProp, 0, 100, new GUIContent ("Damage")) GunProp = serializedObject.FindProperty ("gun") Automatic handling of multi-object editing, undo, and Prefab overrides.ĭamageProp = serializedObject.FindProperty ("damage") ĪrmorProp = serializedObject.FindProperty ("armor") Custom Editor using SerializedProperties. If you use UIElements and have Editor.CreateInspectorGUI overwritten, any existing IMGUI implementation using Editor.OnInspectorGUI on the same Editor will be ignored. To create a custom inspector using IMGUI, you have to override the Editor.OnInspectorGUI on the Editor class. To create a custom inspector using UIElements, you have to override the Editor.CreateInspectorGUI on the Editor class. You can either use UIElements to build your custom UI or you can use IMGUI. If this approach is used a user can select multiple assets in the hierarchy window and change the values for all of them at once. System to edit them, since this automatically handles multi-object editing, undo, and Prefab overrides. Instead of modifying script variables directly, it's advantageous to use the SerializedObject and SerializedProperty If you want the Editor to support multi-object editing, you can use the CanEditMultipleObjects attribute. There are multiple ways to design custom Editors. You can attach the Editor to a custom component by using the CustomEditor attribute. For example, use a custom editor to change the appearance of the script in the Inspector.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |