Toggle
How do I use Toggle
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PhotonTransformViewEditor.cs
Copy
220 private void DrawPropertyWithHelpIcon(ref Rect propertyRect, ref bool isHelpOpen, SerializedProperty property, string tooltip)
221 {
222 Rect propertyFieldRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 20, propertyRect.height);
223 string propertyName = ObjectNames.NicifyVariableName(property.name);
224 EditorGUI.PropertyField(propertyFieldRect, property, new GUIContent(propertyName, tooltip));
225
226 Rect helpIconRect = new Rect(propertyFieldRect.xMax + 5, propertyFieldRect.yMin, 20, propertyFieldRect.height);
227 isHelpOpen = GUI.Toggle(helpIconRect, isHelpOpen, PhotonGUI.HelpIcon, GUIStyle.none);
228
229 propertyRect.y += EDITOR_LINE_HEIGHT;
230 }
File name: PhotonTransformViewEditor.cs
Copy
401 private void DrawHeader(string label, SerializedProperty property)
402 {
403 if (property == null)
404 {
405 return;
406 }
407
408 bool newValue = PhotonGUI.ContainerHeaderToggle(label, property.boolValue);
409
410 if (newValue != property.boolValue)
411 {
412 Undo.RecordObject(this.m_Target, "Change " + label);
413 property.boolValue = newValue;
414 EditorUtility.SetDirty(this.m_Target);
415 }
416 }
File name: PhotonEditor.cs
Copy
649 protected virtual void OnGuiSetupCloudAppId()
650 {
651 GUILayout.Label(CurrentLang.AppIdLabel);
652
653 GUILayout.BeginHorizontal();
654 this.cloudAppId = EditorGUILayout.TextField(this.cloudAppId);
655
656 open = GUILayout.Toggle(open, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth(false));
657
658 GUILayout.EndHorizontal();
659
660 if (open) GUILayout.Label(CurrentLang.AppIdInfoLabel);
661
662
663
664 EditorGUILayout.Separator();
665
666 GUILayout.Label(CurrentLang.CloudRegionLabel);
667
668 GUILayout.BeginHorizontal();
669 int toolbarValue = GUILayout.Toolbar((int)selectedRegion, CloudServerRegionNames); // the enum CloudRegionCode is converted into a string[] in init (toolbar can't use enum)
670 helpRegion = GUILayout.Toggle( helpRegion, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth( false ) );
671 GUILayout.EndHorizontal();
672
673
674 if (helpRegion) GUILayout.Label(CurrentLang.RegionalServersInfo);
675 PhotonEditor.selectedRegion = (CloudRegionCode)toolbarValue;
676
677 EditorGUILayout.Separator();
678
679 GUILayout.BeginHorizontal();
680 if (GUILayout.Button(CurrentLang.CancelButton))
681 {
682 GUIUtility.keyboardControl = 0;
683 this.ReApplySettingsToWindow();
684 }
685
686
687
688 if (GUILayout.Button(CurrentLang.SaveButton))
689 {
690 GUIUtility.keyboardControl = 0;
691 this.cloudAppId = this.cloudAppId.Trim();
692 PhotonEditor.Current.UseCloud(this.cloudAppId);
693
694 PhotonEditor.Current.PreferredRegion = PhotonEditor.selectedRegion;
695 PhotonEditor.Current.HostType = (PhotonEditor.Current.PreferredRegion == CloudRegionCode.none)
696 ? ServerSettings.HostingOption.BestRegion
697 : ServerSettings.HostingOption.PhotonCloud;
698 PhotonEditor.Save();
699
700 Inspect();
701 EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
702 }
703
704 GUILayout.EndHorizontal();
705
706
707
708 GUILayout.Space(20);
709
710 GUILayout.Label(CurrentLang.SetupOwnServerLabel);
711
712 if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
713 {
714 //this.photonAddress = ServerSettings.DefaultServerAddress;
715 //this.photonPort = ServerSettings.DefaultMasterPort;
716 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
717 }
718
719 EditorGUILayout.Separator();
720 GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
721 if (GUILayout.Button(CurrentLang.ComparisonPageButton))
722 {
723 Application.OpenURL(UrlCompare);
724 }
725 }
File name: PhotonGUI.cs
Copy
157 public static bool ContainerHeaderToggle( string headline, bool toggle )
158 {
159 return DoContainerHeaderToggle( headline, toggle );
160 }
File name: PhotonGUI.cs
Copy
245 static bool DoContainerHeaderToggle( string headline, bool toggle )
246 {
247 Rect rect = DoContainerHeader( headline, 27, 15 );
248 Rect toggleRect = new Rect( rect.xMin + 5, rect.yMin + 5, EditorGUIUtility.labelWidth, rect.height );
249
250 return EditorGUI.Toggle( toggleRect, toggle );
251 }
File name: PhotonViewInspector.cs
Copy
21 public override void OnInspectorGUI()
22 {
23 #if UNITY_3_5
24 EditorGUIUtility.LookLikeInspector();
25 #endif
26 //EditorGUI.indentLevel = 1;
27
28 m_Target = (PhotonView)this.target;
29 bool isProjectPrefab = EditorUtility.IsPersistent(m_Target.gameObject);
30
31 if( m_Target.ObservedComponents == null )
32 {
33 m_Target.ObservedComponents = new System.Collections.Generic.List
34 }
35
36 if( m_Target.ObservedComponents.Count == 0 )
37 {
38 m_Target.ObservedComponents.Add( null );
39 }
40
41 EditorGUILayout.BeginHorizontal();
42 // Owner
43 if (isProjectPrefab)
44 {
45 EditorGUILayout.LabelField("Owner:", "Set at runtime");
46 }
47 else if (m_Target.isSceneView)
48 {
49 EditorGUILayout.LabelField("Owner", "Scene");
50 }
51 else
52 {
53 PhotonPlayer owner = m_Target.owner;
54 string ownerInfo = (owner != null) ? owner.name : "
55
56 if (string.IsNullOrEmpty(ownerInfo))
57 {
58 ownerInfo = "
59 }
60
61 EditorGUILayout.LabelField("Owner", "[" + m_Target.ownerId + "] " + ownerInfo);
62 }
63
64 // ownership requests
65 EditorGUI.BeginDisabledGroup(Application.isPlaying);
66 m_Target.ownershipTransfer = (OwnershipOption)EditorGUILayout.EnumPopup(m_Target.ownershipTransfer, GUILayout.Width(100));
67 EditorGUI.EndDisabledGroup();
68
69 EditorGUILayout.EndHorizontal();
70
71
72 // View ID
73 if (isProjectPrefab)
74 {
75 EditorGUILayout.LabelField("View ID", "Set at runtime");
76 }
77 else if (EditorApplication.isPlaying)
78 {
79 EditorGUILayout.LabelField("View ID", m_Target.viewID.ToString());
80 }
81 else
82 {
83 int idValue = EditorGUILayout.IntField("View ID [1.."+(PhotonNetwork.MAX_VIEW_IDS-1)+"]", m_Target.viewID);
84 m_Target.viewID = idValue;
85 }
86
87
88
89 // Locally Controlled
90 if (EditorApplication.isPlaying)
91 {
92 string masterClientHint = PhotonNetwork.isMasterClient ? "(master)" : "";
93 EditorGUILayout.Toggle("Controlled locally: " + masterClientHint, m_Target.isMine);
94 }
95
96
97
98 //DrawOldObservedItem();
99 ConvertOldObservedItemToObservedList();
100
101
102 // ViewSynchronization (reliability)
103 if (m_Target.synchronization == ViewSynchronization.Off)
104 {
105 GUI.color = Color.grey;
106 }
107
108 EditorGUILayout.PropertyField( serializedObject.FindProperty( "synchronization" ), new GUIContent( "Observe option:" ) );
109
110 if( m_Target.synchronization != ViewSynchronization.Off &&
111 m_Target.ObservedComponents.FindAll( item => item != null ).Count == 0 )
112 {
113 GUILayout.BeginVertical( GUI.skin.box );
114 GUILayout.Label( "Warning", EditorStyles.boldLabel );
115 GUILayout.Label( "Setting the synchronization option only makes sense if you observe something." );
116 GUILayout.EndVertical();
117 }
118
119 /*ViewSynchronization vsValue = (ViewSynchronization)EditorGUILayout.EnumPopup("Observe option:", m_Target.synchronization);
120 if (vsValue != m_Target.synchronization)
121 {
122 m_Target.synchronization = vsValue;
123 if (m_Target.synchronization != ViewSynchronization.Off && m_Target.observed == null)
124 {
125 EditorUtility.DisplayDialog("Warning", "Setting the synchronization option only makes sense if you observe something.", "OK, I will fix it.");
126 }
127 }*/
128
129 DrawSpecificTypeSerializationOptions();
130
131 GUI.color = Color.white;
132 DrawObservedComponentsList();
133
134 // Cleanup: save and fix look
135 if (GUI.changed)
136 {
137 EditorUtility.SetDirty(m_Target);
138 PhotonViewHandler.HierarchyChange(); // TODO: check if needed
139 }
140
141 GUI.color = Color.white;
142 EditorGUIUtility.LookLikeControls();
143 }
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: PhotonStatsGui.cs
Copy
77 public void TrafficStatsWindow(int windowID)
78 {
79 bool statsToLog = false;
80 TrafficStatsGameLevel gls = PhotonNetwork.networkingPeer.TrafficStatsGameLevel;
81 long elapsedMs = PhotonNetwork.networkingPeer.TrafficStatsElapsedMs / 1000;
82 if (elapsedMs == 0)
83 {
84 elapsedMs = 1;
85 }
86
87 GUILayout.BeginHorizontal();
88 this.buttonsOn = GUILayout.Toggle(this.buttonsOn, "buttons");
89 this.healthStatsVisible = GUILayout.Toggle(this.healthStatsVisible, "health");
90 this.trafficStatsOn = GUILayout.Toggle(this.trafficStatsOn, "traffic");
91 GUILayout.EndHorizontal();
92
93 string total = string.Format("Out|In|Sum:\t{0,4} | {1,4} | {2,4}", gls.TotalOutgoingMessageCount, gls.TotalIncomingMessageCount, gls.TotalMessageCount);
94 string elapsedTime = string.Format("{0}sec average:", elapsedMs);
95 string average = string.Format("Out|In|Sum:\t{0,4} | {1,4} | {2,4}", gls.TotalOutgoingMessageCount / elapsedMs, gls.TotalIncomingMessageCount / elapsedMs, gls.TotalMessageCount / elapsedMs);
96 GUILayout.Label(total);
97 GUILayout.Label(elapsedTime);
98 GUILayout.Label(average);
99
100 if (this.buttonsOn)
101 {
102 GUILayout.BeginHorizontal();
103 this.statsOn = GUILayout.Toggle(this.statsOn, "stats on");
104 if (GUILayout.Button("Reset"))
105 {
106 PhotonNetwork.networkingPeer.TrafficStatsReset();
107 PhotonNetwork.networkingPeer.TrafficStatsEnabled = true;
108 }
109 statsToLog = GUILayout.Button("To Log");
110 GUILayout.EndHorizontal();
111 }
112
113 string trafficStatsIn = string.Empty;
114 string trafficStatsOut = string.Empty;
115 if (this.trafficStatsOn)
116 {
117 trafficStatsIn = "Incoming: " + PhotonNetwork.networkingPeer.TrafficStatsIncoming.ToString();
118 trafficStatsOut = "Outgoing: " + PhotonNetwork.networkingPeer.TrafficStatsOutgoing.ToString();
119 GUILayout.Label(trafficStatsIn);
120 GUILayout.Label(trafficStatsOut);
121 }
122
123 string healthStats = string.Empty;
124 if (this.healthStatsVisible)
125 {
126 healthStats = string.Format(
127 "ping: {6}[+/-{7}]ms\nlongest delta between\nsend: {0,4}ms disp: {1,4}ms\nlongest time for:\nev({3}):{2,3}ms op({5}):{4,3}ms",
128 gls.LongestDeltaBetweenSending,
129 gls.LongestDeltaBetweenDispatching,
130 gls.LongestEventCallback,
131 gls.LongestEventCallbackCode,
132 gls.LongestOpResponseCallback,
133 gls.LongestOpResponseCallbackOpCode,
134 PhotonNetwork.networkingPeer.RoundTripTime,
135 PhotonNetwork.networkingPeer.RoundTripTimeVariance);
136 GUILayout.Label(healthStats);
137 }
138
139 if (statsToLog)
140 {
141 string complete = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n{5}", total, elapsedTime, average, trafficStatsIn, trafficStatsOut, healthStats);
142 Debug.Log(complete);
143 }
144
145 // if anything was clicked, the height of this window is likely changed. reduce it to be layouted again next frame
146 if (GUI.changed)
147 {
148 this.statsRect.height = 100;
149 }
150
151 GUI.DragWindow();
152 }
File name: ToggleValue.cs
Copy
13 void Awake() {
14 int value = PlayerPrefs.GetInt(GameManager.CAMERA_VIEW,0);
15 toggle.isOn = (value == 1) ? true : false;
16 init = true;
17 }
File name: ToggleValue.cs
Copy
19 public void OnValueChanged() {
20 bool value = toggle.isOn;
21 PlayerPrefs.SetInt(GameManager.CAMERA_VIEW,(value) ? 1 : 0);
22 }
Download file with original file name:Toggle
Toggle 139 lượt xem
Gõ tìm kiếm nhanh...