// ----------------------------- REPLACE GUIDS --------------------------------------- internal bool ReplaceReference(string fromGUID, string toGUID) { if (IsMissing) { return(false); } if (IsReferencable) { var text = string.Empty; if (!File.Exists(assetPath)) { state = FR2_AssetState.MISSING; return(false); } try { text = File.ReadAllText(assetPath).Replace("\r", "\n"); File.WriteAllText(assetPath, text.Replace(fromGUID, toGUID)); return(true); } catch (Exception e) { state = FR2_AssetState.MISSING; //#if FR2_DEBUG Debug.LogWarning("Replace Reference error :: " + e + "\n" + assetPath); //#endif } return(false); } if (type == FR2_AssetType.TERRAIN) { var fromObj = FR2_Unity.LoadAssetWithGUID <Object>(fromGUID); var toObj = FR2_Unity.LoadAssetWithGUID <Object>(toGUID); var found = 0; var terrain = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object)) as TerrainData; if (fromObj is Texture2D) { var arr = terrain.detailPrototypes; for (var i = 0; i < arr.Length; i++) { if (arr[i].prototypeTexture == (Texture2D)fromObj) { found++; arr[i].prototypeTexture = (Texture2D)toObj; } } terrain.detailPrototypes = arr; var arr3 = terrain.splatPrototypes; for (var i = 0; i < arr3.Length; i++) { if (arr3[i].texture == (Texture2D)fromObj) { found++; arr3[i].texture = (Texture2D)toObj; } if (arr3[i].normalMap == (Texture2D)fromObj) { found++; arr3[i].normalMap = (Texture2D)toObj; } } terrain.splatPrototypes = arr3; } if (fromObj is GameObject) { var arr2 = terrain.treePrototypes; for (var i = 0; i < arr2.Length; i++) { if (arr2[i].prefab == (GameObject)fromObj) { found++; arr2[i].prefab = (GameObject)toObj; } } terrain.treePrototypes = arr2; } EditorUtility.SetDirty(terrain); AssetDatabase.SaveAssets(); fromObj = null; toObj = null; terrain = null; FR2_Unity.UnloadUnusedAssets(); return(found > 0); } Debug.LogWarning("Something wrong, should never be here - Ignored <" + assetPath + "> : not a readable type, can not replace ! " + type); return(false); }