public void SaveSources() { #if UNITY_EDITOR //checking if user data could be saved if (!UnityEditor.AssetDatabase.Contains(texArr)) { Debug.Log("Texture Array is not an asset: could not set source tex"); return; } string arrGuid = texArr.GUID(); string[] newSrcGuids = new string[srcArr.Length]; string[] newAlGuids = new string[srcArr.Length]; for (int i = 0; i < newSrcGuids.Length; i++) { if (srcArr[i].source != null) { newSrcGuids[i] = srcArr[i].source.GUID(); } if (srcArr[i].alpha != null) { newAlGuids[i] = srcArr[i].alpha.GUID(); } } string[] oldSrcGuids = texArr.GetUserData("TexArr_sourceLayers"); string[] oldAlGuids = texArr.GetUserData("TexArr_alphaLayers"); //unlinking sources that are not used anymore for (int i = 0; i < oldSrcGuids.Length; i++) { if (oldSrcGuids[i] == null || oldSrcGuids[i].Length == 0) { continue; } if (newSrcGuids.Contains(oldSrcGuids[i])) { continue; //still used } UnlinkTexture(oldSrcGuids[i], arrGuid, isAlpha: false); } for (int i = 0; i < oldAlGuids.Length; i++) { if (oldAlGuids[i] == null || oldAlGuids[i].Length == 0) { continue; } if (newAlGuids.Contains(oldAlGuids[i])) { continue; //still used } UnlinkTexture(oldSrcGuids[i], arrGuid, isAlpha: true); } //linking new textures for (int i = 0; i < newSrcGuids.Length; i++) { if (newSrcGuids[i] == null || newSrcGuids[i].Length == 0) { continue; } LinkTexture(newSrcGuids[i], arrGuid, isAlpha: false); } for (int i = 0; i < newAlGuids.Length; i++) { if (newAlGuids[i] == null || newAlGuids[i].Length == 0) { continue; } LinkTexture(newSrcGuids[i], arrGuid, isAlpha: true); } //saving array data texArr.SetUserData("TexArr_sourceLayers", newSrcGuids); texArr.SetUserData("TexArr_alphaLayers", newAlGuids); UnityEditor.AssetDatabase.SaveAssets(); UnityEditor.EditorUtility.SetDirty(texArr); UnityEditor.AssetDatabase.Refresh(); #endif }