How to select a Term to be opened from editor view
7 years 9 months ago #2114
by Goscalyon
How to select a Term to be opened from editor view was created by Goscalyon
Hello,
Just to clarify the rather vague shortened question: How to select a Term in a LanguageSource set to be in an Opened state from an editor script.
Below is the small code I have to open the LanguageSource as selected object and I tried to work on finding a way to make a term the selected one.
I tried figuring out how the opening/closing of terms is done in i2 itself, but I think that is done entirely through the inspector.
How would I go about doing this?
Just to clarify the rather vague shortened question: How to select a Term in a LanguageSource set to be in an Opened state from an editor script.
Below is the small code I have to open the LanguageSource as selected object and I tried to work on finding a way to make a term the selected one.
I tried figuring out how the opening/closing of terms is done in i2 itself, but I think that is done entirely through the inspector.
void SelectLocalizationTerm(string term) {
source = LocalizationManager.Sources[0];
if(source != null) {
Selection.activeObject = source;
LocalizationEditor.mKeyToExplore = term;
LocalizationEditor.SelectTerm(term, true);
}
}
How would I go about doing this?
Please Log in or Create an account to join the conversation.
7 years 9 months ago #2116
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic How to select a Term to be opened from editor view
Hi,
Sorry, but I'm not following your question.
I tried that code and it opens correctly the I2Languages.prefab in the Terms tab and expands the correct term.
Is that not working for you?
Sorry, but I'm not following your question.
I tried that code and it opens correctly the I2Languages.prefab in the Terms tab and expands the correct term.
Is that not working for you?
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Please Log in or Create an account to join the conversation.
7 years 9 months ago #2118
by Goscalyon
Replied by Goscalyon on topic How to select a Term to be opened from editor view
The idea is that I use a button from a custom editor window to do this, but it only opens the Languages.prefab and doesn't expand the term.
Please Log in or Create an account to join the conversation.
7 years 9 months ago - 7 years 9 months ago #2119
by Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
Replied by Frank on topic How to select a Term to be opened from editor view
Hi,
I just tried the same code and it opened the prefab and selected/expanded the term
This is the code I used:
Assets/TestScript.cs
Assets/Editor/TestScriptInspector.cs
Clicking the "Test" button executed the action.
Can you try that and see if it works for you?
If it does, then there is something else in the rest of your inspector that its causing the issue. Maybe the inspector gets opened for a bit longer than what it should.
If that's the case, you could try delaying the execution of the command for a frame:
That will wait until the rest of your inspector gets executed, and only then, at the end of the frame, it calls the SetLocalizationTerm, ensuring that nothing else clear the variable.
Hope that helps,
Frank
I just tried the same code and it opened the prefab and selected/expanded the term
This is the code I used:
Assets/TestScript.cs
using UnityEngine;
public class TestScript : MonoBehaviour
{
}
Assets/Editor/TestScriptInspector.cs
using UnityEngine;
using UnityEditor;
using I2.Loc;
[CustomEditor(typeof(TestScript))]
public class TestScriptInspector: Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Test"))
{
SelectLocalizationTerm("new");
}
}
void SelectLocalizationTerm(string term)
{
if (LocalizationManager.Sources.Count == 0)
LocalizationManager.UpdateSources();
var source = LocalizationManager.Sources[0];
if (source != null)
{
Selection.activeObject = source;
LocalizationEditor.mKeyToExplore = term;
}
}
}
Clicking the "Test" button executed the action.
Can you try that and see if it works for you?
If it does, then there is something else in the rest of your inspector that its causing the issue. Maybe the inspector gets opened for a bit longer than what it should.
If that's the case, you could try delaying the execution of the command for a frame:
using UnityEngine;
using UnityEditor;
using I2.Loc;
[CustomEditor(typeof(TestScript))]
public class TestScriptInspector: Editor
{
public override void OnInspectorGUI()
{
if (GUILayout.Button("Test"))
{
EditorApplication.delayCall += ()=>SelectLocalizationTerm("new"); //----------------- See the change here
}
}
void SelectLocalizationTerm(string term)
{
if (LocalizationManager.Sources.Count == 0)
LocalizationManager.UpdateSources();
var source = LocalizationManager.Sources[0];
if (source != null)
{
Selection.activeObject = source;
LocalizationEditor.mKeyToExplore = term;
}
}
}
That will wait until the rest of your inspector gets executed, and only then, at the end of the frame, it calls the SetLocalizationTerm, ensuring that nothing else clear the variable.
Hope that helps,
Frank
Are you Give I2L 5 stars!
Are you Please lets us know how to improve it!
To get the betas as soon as they are ready,
check this out
Last edit: 7 years 9 months ago by Frank.
The following user(s) said Thank You: Goscalyon
Please Log in or Create an account to join the conversation.
7 years 9 months ago #2120
by Goscalyon
Replied by Goscalyon on topic How to select a Term to be opened from editor view
Ok so I actually did get it working, but it seems it only actually expands the term as soon as I focus on the I2 inspector. This may be caused by the fact the term is set from an EditorWindow instead of an inspector like your example suggests. But this works atleast, thanks for your help!
Please Log in or Create an account to join the conversation.
Time to create page: 0.162 seconds