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

スクリプト言語

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

EditorPrefs.GetBool

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 GetBool(key: string, defaultValue: bool = false): bool;
public static bool GetBool(string key, bool defaultValue = false);
public static def GetBool(key as string, defaultValue as bool = false) as bool

Description

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

キーが存在しない場合、 defaultValue を返します。
rotations/positionsの値を丸めるための設定を行う

	// Simple script that lets you round rotations and
	// round your positions of your selected objects.
	// and it remembers which option is being active

	class EditorPrefsBool extends EditorWindow {

		var showRoundPosition : boolean = true;
		var showRoundRotation : boolean = true;

		@MenuItem("Examples/Round positions-rotations")
		static function Init() {
			var window = GetWindow(EditorPrefsBool);
			window.Show();
		}
		function OnGUI() {
			showRoundPosition = EditorGUILayout.BeginToggleGroup("Round Position",showRoundPosition);
				if(GUILayout.Button("Round Position!"))
					DoRoundPosition();
			EditorGUILayout.EndToggleGroup();
			showRoundRotation = EditorGUILayout.BeginToggleGroup("Round Rotation", showRoundRotation);
				if(GUILayout.Button("Round Rotation!"))
					DoRoundRotation();
			EditorGUILayout.EndToggleGroup();
		}

		function DoRoundPosition() {
			for (var t : Transform in Selection.transforms)
					t.localPosition = Vector3(Mathf.Round(t.localPosition.x),
												Mathf.Round(t.localPosition.z),
												Mathf.Round(t.localPosition.y));
		}
		function DoRoundRotation() {
			for (var t : Transform in Selection.transforms)
				t.rotation = Quaternion.Euler(
								Vector3(Mathf.Round(t.eulerAngles.x / 45f) * 45f,
										Mathf.Round(t.eulerAngles.y / 45f) * 45f,
										Mathf.Round(t.eulerAngles.z / 45f) * 45f));
		}
		function OnFocus() {
			if(EditorPrefs.HasKey("ShowRoundPosition"))
				showRoundPosition = EditorPrefs.GetBool("ShowRoundPosition");
			if(EditorPrefs.HasKey("ShowRoundRotation"))
				showRoundPosition = EditorPrefs.GetBool("ShowRoundRotation");
		}

		function OnLostFocus() {
			EditorPrefs.SetBool("ShowRoundPosition", showRoundPosition);
			EditorPrefs.SetBool("ShowRoundRotation", showRoundRotation);
		}
		function OnDestroy() {
			EditorPrefs.SetBool("ShowRoundPosition", showRoundPosition);
			EditorPrefs.SetBool("ShowRoundRotation", showRoundRotation);
		}
	}