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# console app how to run another program 
Csharp :: oncollisionenter unity 
Csharp :: c# boiler code shortcut 
Csharp :: Add float value to ui text in unity 
Csharp :: even number checker in c# 
Csharp :: c# generate random int in range 
Csharp :: wpf set image source in code behind 
Csharp :: string to list c# 
Csharp :: unity rigidbody freeze all 
Csharp :: c# adding two arrays together 
Csharp :: set ads for children admob unity 
Csharp :: jitter on collision for 2 rigid bodies 
Csharp :: unity rotate vector around point 
Csharp :: get random from list c# 
Csharp :: there are any objects when open project unity 
Csharp :: how to stop player rotating when hit by object 
Csharp :: animations for pause menu 
Csharp :: c# datetime iso 8601 format 
Csharp :: how to show a reference in unity 
Csharp :: C# how to ignore case 
Csharp :: string from byte array c# 
Csharp :: vb.net open file with default program 
Csharp :: how to check is object by this type c# 
Csharp :: unity change color of sprite in script 
Csharp :: wpf update listview itemssource 
Csharp :: c# convert string to enum value 
Csharp :: unity print name of button when click on it 
Csharp :: get length of a string c# 
Csharp :: button not working unity 
Csharp :: run linux command in c# 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =