Hello folks!
Short question: can I write an extension method for a sealed class?
Long question and explanation: after watching this tutorial on Unity website, I was trying to extend EditorGUILayout class to create a simple custom box. I wrote this small piece of code that compiles without any problem:
using UnityEngine;
using UnityEditor;
using System.Collections;
public static class ExtensionMethods {
public static void InfoButton(this EditorGUILayout obj, string description){
Debug.Log("works");
}
}
but when I try to use it by writing
EditorGUILayout.InfoButton("asd");
I get this erroy:
`UnityEditor.EditorGUILayout' does not contain a definition for `InfoButton'
I am not sure what really happens behind the scene when I extend a method, and I am not sure why this code doesn’t work. However, while watching this unofficial repo I saw that EditodGUILayout is a sealed class. Can these two things be related? I know I can write a local function and put the same exact code, but I am trying to learn something new ![]()