EditorUtility.SetDirty在Untiy中的作用以及应用

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("保存某些数据");
           
        }
  
    }

猜你喜欢

转载自blog.csdn.net/charlsdm/article/details/125606366