Slider
How do I use Slider
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonLagSimulationGui.cs
Copy
57 private void NetSimWindow(int windowId)
58 {
59 GUILayout.Label(string.Format("Rtt:{0,4} +/-{1,3}", this.Peer.RoundTripTime, this.Peer.RoundTripTimeVariance));
60
61 bool simEnabled = this.Peer.IsSimulationEnabled;
62 bool newSimEnabled = GUILayout.Toggle(simEnabled, "Simulate");
63 if (newSimEnabled != simEnabled)
64 {
65 this.Peer.IsSimulationEnabled = newSimEnabled;
66 }
67
68 float inOutLag = this.Peer.NetworkSimulationSettings.IncomingLag;
69 GUILayout.Label("Lag " + inOutLag);
70 inOutLag = GUILayout.HorizontalSlider(inOutLag, 0, 500);
71
72 this.Peer.NetworkSimulationSettings.IncomingLag = (int)inOutLag;
73 this.Peer.NetworkSimulationSettings.OutgoingLag = (int)inOutLag;
74
75 float inOutJitter = this.Peer.NetworkSimulationSettings.IncomingJitter;
76 GUILayout.Label("Jit " + inOutJitter);
77 inOutJitter = GUILayout.HorizontalSlider(inOutJitter, 0, 100);
78
79 this.Peer.NetworkSimulationSettings.IncomingJitter = (int)inOutJitter;
80 this.Peer.NetworkSimulationSettings.OutgoingJitter = (int)inOutJitter;
81
82 float loss = this.Peer.NetworkSimulationSettings.IncomingLossPercentage;
83 GUILayout.Label("Loss " + loss);
84 loss = GUILayout.HorizontalSlider(loss, 0, 10);
85
86 this.Peer.NetworkSimulationSettings.IncomingLossPercentage = (int)loss;
87 this.Peer.NetworkSimulationSettings.OutgoingLossPercentage = (int)loss;
88
89 // if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
90 if (GUI.changed)
91 {
92 this.WindowRect.height = 100;
93 }
94
95 GUI.DragWindow();
96 }
File name: SliderValueScore.cs
Copy
13 void Awake() {
14 int oldScore = PlayerPrefs.GetInt(GameManager.SCORE_MAX,1);
15 sliderText.text = oldScore.ToString();
16 slider.value = oldScore;
17 init = true;
18 }
File name: SliderValueScore.cs
Copy
20 public void OnValueChanged() {
21 int value = ((int)slider.value);
22 sliderText.text = value.ToString();
23
24 PlayerPrefs.SetInt(GameManager.SCORE_MAX, value);
25
26 int maxGame = value * 2 - 1;
27 PlayerPrefs.SetInt(GameManager.GAME_MAX, maxGame);
28
29 if (init) {
30 GameManager.ResetScores();
31 }
32 }
File name: SliderValueTimer.cs
Copy
13 void Awake() {
14 int oldTimer = PlayerPrefs.GetInt(GameManager.PLAYER_TIMER,GameManager.DEFAULT_PLAYER_TIMER_MIN);
15 sliderText.text = oldTimer.ToString();
16 slider.value = oldTimer;
17 init = true;
18 }
File name: SliderValueTimer.cs
Copy
20 public void OnValueChanged() {
21 int value = ((int)slider.value);
22 sliderText.text = value.ToString();
23
24 PlayerPrefs.SetInt(GameManager.PLAYER_TIMER, value);
25 }
File name: AnimationTestScriptInspector.cs
Copy
9 public override void OnInspectorGUI()
10 {
11 AnimationTestScript myTarget = (AnimationTestScript)target;
12
13 EditorGUILayout.LabelField("Set a trigger:");
14
15 foreach (AnimationTestScript.TriggerType trigger in Enum.GetValues(typeof(AnimationTestScript.TriggerType)))
16 {
17 if (GUILayout.Button(trigger.ToString()))
18 {
19 myTarget.SetTrigger(trigger);
20 }
21 }
22
23 EditorGUILayout.Space();
24 myTarget.Speed = EditorGUILayout.Slider("Movement Speed", myTarget.Speed, 0, 10);
25 }
Download file with original file name:Slider
Slider 130 lượt xem
Gõ tìm kiếm nhanh...