Unity 代码设置 SortingLayer 的问题
static void AddSortingLayer(string sortingLayer){
SerializedObject tagsAndLayersManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset"));
SerializedProperty sortingLayersProp = tagsAndLayersManager.FindProperty("m_SortingLayers");
sortingLayersProp.InsertArrayElementAtIndex(sortingLayersProp.arraySize);
var newlayer = sortingLayersProp.GetArrayElementAtIndex(sortingLayersProp.arraySize - 1);
newlayer.FindPropertyRelative("uniqueID").intValue = sortingLayersProp.arraySize - 1;
newlayer.FindPropertyRelative("name").stringValue = sortingLayer;
tagsAndLayersManager.ApplyModifiedProperties();
}
由于直接用代码设置 SortingLayer 代码上传到其他电脑上发现 SortingLayer会出现设置不正确的现象,所以代码中对其 "uniqueID"进行了设置这样就解决了上述问题
页:
[1]