EditorUtility.SetDirty 设置已改变

static function SetDirty (target : Object) : void


Marks target object as dirty.


Unity internally uses the dirty flag to find out when assets have changed and need to be saved to disk.


E.g. if you modify a prefab's MonoBehaviour or ScriptableObject variables, you must tell Unity that the value has changed. Unity builtin components internally call SetDirty whenever a property changes. MonoBehaviour or ScriptableObject don't do this automatically so if you want your value to be saved you need to call SetDirty.


// C# Example
// Set Wrapmode of each imported texture to Clamp
using UnityEngine;
using UnityEditor;
using System.Collections;

public class TexturePreprocessor : AssetPostprocessor {
	void OnPostProcessTexture() {
		TextureImporter textureImporter = assetImporter as TextureImporter;
		textureImporter.mipmapEnabled = false;

		string path = textureImporter.assetPath;

		Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));
		Texture2D texture = asset as Texture2D;

		if (texture != null) {
			Debug.Log("Texture path: " + path);
			texture.wrapMode = TextureWrapMode.Clamp;
		} else {
			Debug.Log("error " + path);
Page last updated: 2011-7-15