public static bool LoadLayers() { string[] LayerNames = new string[] { Constants.LAYER_SOCKET, Constants.LAYER_INTERACTION }; bool Result = false; SerializedObject Manager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); SerializedProperty SerializedLayers = Manager.FindProperty("layers"); foreach (string LayerName in LayerNames) { bool IsFound = false; for (int i = 0; i <= 31; i++) { SerializedProperty SerializedProperty = SerializedLayers.GetArrayElementAtIndex(i); if (SerializedProperty != null && LayerName.Equals(SerializedProperty.stringValue)) { IsFound = true; break; } } if (!IsFound) { Result = true; SerializedProperty SerializedSlot = null; for (int i = 8; i <= 31; i++) { SerializedProperty sp = SerializedLayers.GetArrayElementAtIndex(i); if (sp != null && string.IsNullOrEmpty(sp.stringValue)) { SerializedSlot = sp; break; } } if (SerializedSlot != null) { SerializedSlot.stringValue = LayerName; Debug.Log("<b><color=cyan>[Easy Build System]</color></b> : The layer (<b>" + LayerName + "</b>) has been added."); } else { Debug.LogError("<b><color=cyan>[Easy Build System]</color></b> : Could not find an open Layer Slot for : " + LayerName); } } } Manager.ApplyModifiedProperties(); return(Result); }