言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

EditorWindow.OnSelectionChange()

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Called whenever the selection has changed.


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;
		}
	}