EditorWindow.OnSelectionChange 当选择改变

function OnSelectionChange () : void

Description描述

Called whenever the selection has changed.

只要选择发生改变时调用。

EditorWindow.OnSelectionChange 当选择改变

Saves the current selection and load it later with a simple click.
保存当前选择并带有简单的点击加载它

// Simple example that lets you save the current selection and load it.
//让你保持当前选择并加载它
class SelectionChange extends EditorWindow {
	var selectionIDs : int[];
	@MenuItem("Example/Selection Saver")
	static function Init() {
		var window = GetWindow(SelectionChange);
		window.Show();
	}
	function OnGUI() {
		if(GUILayout.Button("Save"))
			SaveSelection();
		if(GUILayout.Button("Load"))
			LoadLastSavedSelection();
	}
	function OnSelectionChange() {
		selectionIDs = Selection.instanceIDs;
	}
	function SaveSelection() {
		var saveStr = "";
		for(var i : int in selectionIDs)
		saveStr += i.ToString() + ";";
		saveStr = saveStr.TrimEnd(char.Parse(";"));
		EditorPrefs.SetString("SelectedIDs",saveStr);
	}
	function LoadLastSavedSelection() {
		var strIDs : String[] = EditorPrefs.GetString("SelectedIDs").Split(char.Parse(";"));

		var ids : int[] = new int[strIDs.Length];
		for(var i = 0; i < strIDs.Length; i++)
			ids[i] = parseInt(strIDs[i]);
		Selection.instanceIDs = ids;
	}
}
最后修改:2011年6月24日 Friday 14:57

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。