Calling script when completed field in *EDITOR*
I realize this may be super simple, but I'm actually working inside of a Custom List, so I have a Keycode, a Button and two string fields inside of my List, what I want to do is when I finish typing in my last string field, I want to run a script. Any ideas? Thank you! (:
Here is how my code is setup currently - What I need help with is how to get my current focus in the -Editor- then get the string value from this.
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
using UnityEngine.UI;
[CustomEditor(typeof(InputManager))]
public class InputManagerEditor : Editor {
public override void OnInspectorGUI()
{
serializedObject.Update ();
InputManager myTarget = (InputManager)target;
EditorGUILayout.PropertyField(serializedObject.FindProperty("inputManagerList"), true);
if(!GUI.GetNameOfFocusedControl().Equals("") && Event.current.keyCode == KeyCode.Return)
TagEditor.AddToTagMenu(GUI.GetNameOfFocusedControl().ToString());
serializedObject.ApplyModifiedProperties();
}
}
I still have been unable to figure out how to do this, anyone have any ideas?
Answer by Jessespike · Aug 21, 2015 at 05:08 PM
You can probably do a check to see what control is focused and if the field is no longer empty. Simple example, but for a starting point, try something like this:
/*pseudo*/
if (lastFocusedControl == myInputField && myInputField != string.empty) {
//Call your script
}
http://docs.unity3d.com/ScriptReference/GUI-changed.html
http://docs.unity3d.com/ScriptReference/GUI.FocusControl.html
Thank you for replying so quickly, I'm sorry for being late!
So, I'm unsure how to name my TextField... Here is my code. What would be ideal is to actually connect the script call (The if statement) to when my tag field inside of my List is filled out.
CODE:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
[CustomEditor(typeof(Input$$anonymous$$anager))]
public class Input$$anonymous$$anagerEditor : Editor {
public override void OnInspectorGUI()
{
serializedObject.Update ();
EditorGUILayout.PropertyField(serializedObject.FindProperty("input$$anonymous$$anagerList"), true);
EditorGUILayout.TextField("Add tag");
//FIX THIS TODO
if(GUI.GetNameOfFocusedControl().Equals(""))
{
if(Event.current.type == EventType.$$anonymous$$eyUp && Event.current.keyCode == $$anonymous$$eyCode.Return)
{
Debug.Log("Reached");
TagEditor.AddToTag$$anonymous$$enu(GUI.GetNameOfFocusedControl().ToString());
}
}
serializedObject.Apply$$anonymous$$odifiedProperties();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612000912im_/https://answers.unity.com/themes/thub/images/avi.jpg)