- Home /
Serializable class with interactivity
I'm curious to know, is it possible to call functions from serializable classes similar to the a custom editor for creating buttons and toggles.
example
[CustomPropertyDrawer(typeof(PathNode))]
public class PathNodeDrawer : PropertyDrawer {
public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) {
EditorGUIUtility.LookLikeControls ();
position.xMin += 4;
position.xMax -= 4;
//EditorGUI.BeginProperty (position, label, property);
position = EditorGUI.PrefixLabel(position,GUIUtility.GetControlID (FocusType.Passive), label);
property.FindPropertyRelative("location").vector3Value = EditorGUI.Vector3Field(new Rect (position.x, position.y - 16, position.width, position.height),"", property.FindPropertyRelative("location").vector3Value);
//EditorGUI.EndProperty ();
}
}
creates something that looks like this in the inspector (see image)
where the class "location" Vector3 is I want to place a button that does a function for the in the scene
so i have some ideas on how i should do that, (like storing the functions and variables for the editor in the class itself). anyone else have a cleaner method?
You can create your own static class with helper methods which you can call from anywhere.
this is true, but that doesn't work in this case. i essentially need a button in custom gui so that i can activate widgets in the scene that change the fields you see there
I'm sorry i wasn't very clear lol, I need a button that can act on an array of instances of something that has been created in a class through inspector (like waypoints in a pathing system that each have special ways of setting them but still need to do it through inspector)
Well I'm afraid I'm still not clear on your problem. You mention in your question something about a "location" class, but nothing like that is visible in the screenshot you posted. So I'm unsure now if you're talking about a button in the scene or in the inspector. Either way, having a button in the inspector that calls a method in a static class should be doable. That method would poll the scene for whatever kind of object you're interested in and do its work on n number of objects found. You shouldn't dirty up your game code with values that will only be used in the editor. :)
Your answer
Follow this Question
Related Questions
Custom Inspector for a [System.Serializable] 2 Answers
Logic Problems using for loops 0 Answers
Serializable attribute defaulting on play 1 Answer
Draw specific Object Inspector into Rect 1 Answer
layout serializable objects in unity 1 Answer