UnityEditor.EditorUtility.SetDirty(this.gameObject);
结合某些Unity脚本更改物体的Inspector上的某些属性然后更改之后
直接更改Unity的预制体功能,用于更改Inspector上的数据之后保存
下边附上我的代码
[ContextMenu("自动给我原本的图片赋值为空")]
public void ClearPictureOrSpriteOrigionName()
{
string myname = null;
if (this.GetComponent<Image>() != null || this.GetComponent<SpriteRenderer>() != null)
{
if (this.GetComponent<Image>() != null)
{
myname = this.GetComponent<Image>().sprite.name;
}
else if (this.GetComponent<SpriteRenderer>() != null)
{
myname = this.GetComponent<SpriteRenderer>().sprite.name;
}
}
if (myname != null)
{
if (this.GetComponent<Image>() != null)
{
this.GetComponent<Image>().sprite = null;
}
else if (this.GetComponent<SpriteRenderer>() != null)
{
this.GetComponent<SpriteRenderer>().sprite = null;
}
UnityEditor.EditorUtility.SetDirty(this.gameObject);
Debug.Log("保存某些数据");
}
}
本文探讨了Unity的EditorUtility.SetDirty方法在游戏开发中的应用,特别是在更新 GameObject Inspector 属性时如何触发预制体的保存。通过使用此方法,开发者可以直接修改Inspector上的数据并确保更改被保存。



5337

被折叠的 条评论
为什么被折叠?



