when i changed the gameobject’s materail in runtime ,then use PrefabUtility.ReplacePrefab to save prefab ,But when stop play the game,the materail back to old…why?any fix?
public static void ReplacePrefab(GameObject currentObj)
{
string path;
UnityEngine.Object parentObject = EditorUtility.GetPrefabParent(currentObj);
path = AssetDatabase.GetAssetPath(parentObject);
Debug.LogWarning("--------have---path:"+path);
if(path.Length==0)
{
path=prefabeLocalPath+currentObj.name+".prefab";
}
GameObject goo=(GameObject)AssetDatabase.LoadAssetAtPath(path,typeof(GameObject));
if(goo !=null)
{
if (EditorUtility.DisplayDialog("Are you sure?",
path+"already exists. Do you want to overwrite it?",
"Yes",
"No"))
{
// EditorUtility.ReplacePrefab(currentObj,goo,ReplacePrefabOptions.ReplaceNameBased|ReplacePrefabOptions.ConnectToPrefab);
// AssetDatabase.Refresh();
PrefabUtility.ReplacePrefab(currentObj, PrefabUtility.GetPrefabParent(currentObj), ReplacePrefabOptions.ConnectToPrefab|ReplacePrefabOptions.ReplaceNameBased);
}
}else
{
if (EditorUtility.DisplayDialog("Are you sure?",
"creat :"+prefabeLocalPath+currentObj.name+".prefab",
"Yes",
"No"))CreateNew(currentObj,prefabeLocalPath);
}
}