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

スクリプト言語

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

EditorPrefs.GetInt

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

public static function GetInt(key: string, defaultValue: int = 0): int;
public static int GetInt(string key, int defaultValue = 0);
public static def GetInt(key as string, defaultValue as int = 0) as int

Description

キーが存在する場合、 key に対応する値を取得します

キーが存在しない場合、 defaultValue を返します。
選択したゲームオブジェクトに複数のスクリプトをアタッチします

	// Simple Editor Script that adds one or more scripts
	// to the selected GameObjects

	class ScriptAdder extends EditorWindow {
		var numComponents = 1;
		var componentsToAdd : MonoScript[];
		@MenuItem("Examples/Script Adder")
		static function Init() {
			var window = GetWindow(ScriptAdder);
			window.Show();
		}
		function Awake() {
			numComponents = EditorPrefs.GetInt("NumberOfComponents", 1);
			componentsToAdd = new MonoScript[numComponents];
		}
		function OnDestroy() {
			EditorPrefs.SetInt("NumberOfComponents", numComponents);
		}
		function OnGUI() {
			if(GUILayout.Button("Clear all components"))
				for(var c : MonoScript in componentsToAdd)
					c = null;
			EditorGUILayout.BeginHorizontal();
				if(GUILayout.Button("-")) IncreaseDecreaseComponents(-1);
				if(GUILayout.Button("+")) IncreaseDecreaseComponents(1);
			EditorGUILayout.EndHorizontal();

			for(var i = 0; i < numComponents; i++)
				componentsToAdd[i] =
					EditorGUILayout.ObjectField("Component", componentsToAdd[i], MonoScript);

			if(GUILayout.Button("Add to selection"))
				if(Selection.activeGameObject)
					for(var go : GameObject in Selection.gameObjects)
						for(var c : MonoScript in componentsToAdd)
							go.AddComponent(c.GetClass());
		}
		function IncreaseDecreaseComponents(num : int) {
			if(numComponents + num == 0) {
				numComponents = 1;
				return;
			}
			numComponents += num ;
			var newArray : MonoScript[] = new MonoScript[numComponents];
			var count = 0;
			if(num > 0)
				for(count = 0; count < componentsToAdd.Length; count++)
					newArray[count] = componentsToAdd[count];
			else
				for(count = 0; count < newArray.Length; count++)
					newArray[count] = componentsToAdd[count];
			componentsToAdd = newArray;
		}
	}