hfiani
1
hello i need to create dynamically sorting layers by code (C#).
then i can get its ID and give to a sprite.
i need to do this since i have no idea what is the exact number of the sprites, and each sprite HAS to have its own sorting layer
PS: not a normal Layer, but the Sorting Layer
i tried:
SortingLayer sl = new SortingLayer ();
sl.name = "something";
sl.id = 12;
but obviously this does not work.
any help?
@hfiani
Something like this should work (editor only)
SerializedObject tagsAndLayersManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
SerializedProperty sortingLayersProp = tagsAndLayersManager.FindProperty("m_SortingLayers");
sortingLayersProp.InsertArrayElementAtIndex(sortingLayersProp.arraySize);
var newlayer = sortingLayersProp.GetArrayElementAtIndex(sortingLayersProp.arraySize);
newlayer.FindPropertyRelative("uniqueID").intValue = UnityEngine.Random.Range(int.MinValue, int.MaxValue);
newlayer.FindPropertyRelative("name").stringValue = "my new layer";
tagsAndLayersManager.ApplyModifiedProperties();
hfiani
2
no one knows the answer to this question? i searched a lot but found nothing