11
« on: February 01, 2014, 12:09:52 am »
It seems the issue is that in Unity, when SortingLayerName is set to Default, instead of the SortingLayerName string on the renderer being set to the direct string "Default", it is set to the string "", which must mean somewhere Unity is wiping the string when we do this. So I modified tk2dEditorUtility, which seems to work for now. Here's what I did.
public static string SortingLayerNamePopup( string label, string value ) {
string[] names = GetSortingLayerNames();
//BEGIN MY MODIFIED CODE
//If value is not in the array set it to Default
int hasValueInArray = Array.IndexOf(names, value);
if(hasValueInArray == -1)
{
value = "Default";
}
//END MY MODIFIED CODE
if (names.Length == 0) {
return EditorGUILayout.TextField(label, value);
}
else {
int sel = 0;
for (int i = 0; i < names.Length; ++i) {
if (names[i] == value) {
sel = i;
break;
}
}
sel = EditorGUILayout.Popup(label, sel, names);
return names[sel];
}
}
It's a bit hacky, but it seems to do the trick until a better solution is made.