Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

custom editor unity

using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(MyComponent))]
[CanEditMultipleObjects]
public class MyComponentEditor : Editor 
{    
    public override void OnInspectorGUI()
    {
        MyComponent myComponent = (MyComponent)target;
        
        DrawDefaultInspector();
        
        if(GUILayout.Button("MyButton"))
        {
        	myComponent.doSomething();
        }
    }
}
Comment

unity custom editor

// MapGenerator is class on which this custom editor will be called
using UnityEditor;
[CustomEditor(typeof(MapGenerator))]
public class Edit : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI(); 
        // if you remove |^|(base.OnInspectorGUI(); )
        // variable in inspector may not show up properly
        
        MapGenerator mapGenerator = (MapGenerator)target;
        mapGenerator.Function();
    }
}

// another approach it is called only if there is change in the value.

using UnityEditor;
[CustomEditor(typeof(MapGenerator))]
public class Edit : Editor
{
    public override void OnInspectorGUI()
    {
        MapGenerator mapGenerator = (MapGenerator)target;
        if(DrawDefaultInspector())
        {
           	mapGenerator.Function();
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# convert list t to datatable 
Csharp :: public tmpro text 
Csharp :: get key value from object c# 
Csharp :: c# create console for winform 
Csharp :: unity get game version 
Csharp :: c# for statement 
Csharp :: gcd of list of number 
Csharp :: c# isdigit mehod 
Csharp :: how to deactivate an object unity 
Csharp :: how to make an ui to follow gameobject 
Csharp :: generate random dark colors programatically in android 
Csharp :: convert list string to list long c# 
Csharp :: how to get type of an object in c# 
Csharp :: Change Level in Unity 
Csharp :: c# windows forms open directory in explorer 
Csharp :: increase value in dictionary against a key in c# 
Csharp :: c# get the first 4 characters in the list 
Csharp :: c# findindex 
Csharp :: c# switch case greater than 
Csharp :: how to add rigidbody in unity 
Csharp :: how to get unique list in c# 
Csharp :: array reduce c# 
Csharp :: get all classes that extend a class c# 
Csharp :: unity game object remove parent 
Csharp :: input field to float unity 
Csharp :: sorting list by date time dec in c# 
Csharp :: which game engine is best 
Csharp :: c# Program to check if a given year is leap year 
Csharp :: why is called c# 
Csharp :: window height in C# forms 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =