NOT
How do I use N O T
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: OnClickRequestOwnership.cs
Copy
8 public void OnClick()
9 {
10 if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
11 {
12 Vector3 colVector = new Vector3( Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ), Random.Range( 0.0f, 1.0f ) );
13 this.photonView.RPC( "ColorRpc", PhotonTargets.AllBufferedViaServer, colVector );
14 }
15 else
16 {
17 if( this.photonView.ownerId == PhotonNetwork.player.ID )
18 {
19 Debug.Log( "Not requesting ownership. Already mine." );
20 return;
21 }
22
23 this.photonView.RequestOwnership();
24 }
25 }
File name: ChatGui.cs
Copy
58 public void Start()
59 {
60 DontDestroyOnLoad(this.gameObject);
61 Application.runInBackground = true; // this must run in background or it will drop connection if not focussed.
62
63 if (string.IsNullOrEmpty(this.UserName))
64 {
65 this.UserName = "user" + Environment.TickCount%99; //made-up username
66 }
67
68 chatClient = new ChatClient(this);
69 chatClient.Connect(ChatAppId, "1.0", this.UserName, null);
70
71 if (this.AlignBottom)
72 {
73 this.GuiRect.y = Screen.height - this.GuiRect.height;
74 }
75 if (this.FullScreen)
76 {
77 this.GuiRect.x = 0;
78 this.GuiRect.y = 0;
79 this.GuiRect.width = Screen.width;
80 this.GuiRect.height = Screen.height;
81 }
82
83 Debug.Log(this.UserName);
84 }
File name: ChatGui.cs
Copy
103 public void OnGUI()
104 {
105 if (!this.IsVisible)
106 {
107 return;
108 }
109
110 GUI.skin.label.wordWrap = true;
111 //GUI.skin.button.richText = true; // this allows toolbar buttons to have bold/colored text. nice to indicate new msgs
112 //GUILayout.Button("lala"); // as richText, html tags could be in text
113
114
115 if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return))
116 {
117 if ("ChatInput".Equals(GUI.GetNameOfFocusedControl()))
118 {
119 // focus on input -> submit it
120 GuiSendsMsg();
121 return; // showing the now modified list would result in an error. to avoid this, we just skip this single frame
122 }
123 else
124 {
125 // assign focus to input
126 GUI.FocusControl("ChatInput");
127 }
128 }
129
130 GUI.SetNextControlName("");
131 GUILayout.BeginArea(this.GuiRect);
132
133 GUILayout.FlexibleSpace();
134
135 if (this.chatClient.State != ChatState.ConnectedToFrontEnd)
136 {
137 GUILayout.Label("Not in chat yet.");
138 }
139 else
140 {
141 List
142 int countOfPublicChannels = channels.Count;
143 channels.AddRange(this.chatClient.PrivateChannels.Keys);
144
145 if (channels.Count > 0)
146 {
147 int previouslySelectedChannelIndex = this.selectedChannelIndex;
148 int channelIndex = channels.IndexOf(this.selectedChannelName);
149 this.selectedChannelIndex = (channelIndex >= 0) ? channelIndex : 0;
150
151 this.selectedChannelIndex = GUILayout.Toolbar(this.selectedChannelIndex, channels.ToArray(), GUILayout.ExpandWidth(false));
152 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
153
154 this.doingPrivateChat = (this.selectedChannelIndex >= countOfPublicChannels);
155 this.selectedChannelName = channels[this.selectedChannelIndex];
156
157 if (this.selectedChannelIndex != previouslySelectedChannelIndex)
158 {
159 // changed channel -> scroll down, if private: pre-fill "to" field with target user's name
160 this.scrollPos.y = float.MaxValue;
161 if (this.doingPrivateChat)
162 {
163 string[] pieces = this.selectedChannelName.Split(new char[] {':'}, 3);
164 this.userIdInput = pieces[1];
165 }
166 }
167
168 GUILayout.Label(ChatGui.WelcomeText);
169
170 if (this.chatClient.TryGetChannel(selectedChannelName, this.doingPrivateChat, out this.selectedChannel))
171 {
172 for (int i = 0; i < this.selectedChannel.Messages.Count; i++)
173 {
174 string sender = this.selectedChannel.Senders[i];
175 object message = this.selectedChannel.Messages[i];
176 GUILayout.Label(string.Format("{0}: {1}", sender, message));
177 }
178 }
179
180 GUILayout.EndScrollView();
181 }
182 }
183
184
185 GUILayout.BeginHorizontal();
186 if (doingPrivateChat)
187 {
188 GUILayout.Label("to:", GUILayout.ExpandWidth(false));
189 GUI.SetNextControlName("WhisperTo");
190 this.userIdInput = GUILayout.TextField(this.userIdInput, GUILayout.MinWidth(100), GUILayout.ExpandWidth(false));
191 string focussed = GUI.GetNameOfFocusedControl();
192 if (focussed.Equals("WhisperTo"))
193 {
194 if (this.userIdInput.Equals("username"))
195 {
196 this.userIdInput = "";
197 }
198 }
199 else if (string.IsNullOrEmpty(this.userIdInput))
200 {
201 this.userIdInput = "username";
202 }
203
204 }
205 GUI.SetNextControlName("ChatInput");
206 inputLine = GUILayout.TextField(inputLine);
207 if (GUILayout.Button("Send", GUILayout.ExpandWidth(false)))
208 {
209 GuiSendsMsg();
210 }
211 GUILayout.EndHorizontal();
212 GUILayout.EndArea();
213 }
File name: GUICustomAuth.cs
Copy
58 public void SetStateAuthOrNot()
59 {
60 RootOf3dButtons.SetActive(true);
61 guiState = GuiState.AuthOrNot;
62 }
File name: HubGui.cs
Copy
28 void OnGUI()
29 {
30 GUI.skin = this.Skin;
31 GUILayout.Space(10);
32
33 GUILayout.BeginHorizontal();
34 GUILayout.Space(10);
35 scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37 GUILayout.Label("Basics", m_Headline);
38 if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39 {
40 demoDescription = "
41 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42 }
43 if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44 {
45 demoDescription = "
46 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47 }
48 if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49 {
50 demoDescription = "
51 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52 }
53
54 GUILayout.Label("Advanced", m_Headline);
55 if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56 {
57 demoDescription = "
58 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59 this.webLink = new DemoBtn();
60 }
61 if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62 {
63 demoDescription = "
64 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65 this.webLink = new DemoBtn();
66 }
67
68 GUILayout.Label("Feature Demos", m_Headline);
69 if (GUILayout.Button("Chat", GUILayout.Width(280)))
70 {
71 demoDescription = "
72 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73 this.webLink = new DemoBtn();
74 }
75 if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76 {
77 demoDescription = "
78 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79 this.webLink = new DemoBtn();
80 }
81 if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82 {
83 demoDescription = "
84 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85 this.webLink = new DemoBtn();
86 }
87 if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88 {
89 demoDescription = "
90 this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91 this.webLink = new DemoBtn();
92 }
93 if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94 {
95 demoDescription = "
96 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97 this.webLink = new DemoBtn();
98 }
99
100 GUILayout.Label("Tutorial", m_Headline);
101 if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102 {
103 demoDescription = "
104 this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105 this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106 }
107 GUILayout.EndScrollView();
108
109 GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110 GUILayout.Label(demoDescription);
111 GUILayout.Space(10);
112 if (!string.IsNullOrEmpty(this.demoBtn.Text))
113 {
114 if (GUILayout.Button(this.demoBtn.Text))
115 {
116 Application.LoadLevel(this.demoBtn.Link);
117 }
118 }
119 if (!string.IsNullOrEmpty(this.webLink.Text))
120 {
121 if (GUILayout.Button(this.webLink.Text))
122 {
123 Application.OpenURL(this.webLink.Link);
124 }
125 }
126 GUILayout.EndVertical();
127
128
129 GUILayout.EndHorizontal();
130 }
File name: CubeLerp.cs
Copy
12 public void Awake()
13 {
14 if (photonView.isMine)
15 {
16 this.enabled = false; // due to this, Update() is not called on the owner client.
17 }
18
19 latestCorrectPos = transform.position;
20 onUpdatePos = transform.position;
21 }
File name: IELdemo.cs
Copy
59 public void OnGUI()
60 {
61 GUILayout.Space(10);
62 if (PhotonNetwork.isMasterClient)
63 {
64 GUILayout.Label("Move the cubes with the left and right keys. Run another client to check movement (smoothing) behaviour.");
65 GUILayout.Label("Ping: " + PhotonNetwork.GetPing());
66 }
67 else if (PhotonNetwork.isNonMasterClientInRoom)
68 {
69 GUILayout.Label("Check how smooth the movement is");
70 GUILayout.Label("Ping: " + PhotonNetwork.GetPing());
71 }
72 else
73 {
74 GUILayout.Label("Not connected..." + PhotonNetwork.connectionStateDetailed);
75 }
76 }
File name: WorkerMenu.cs
Copy
65 public void OnGUI()
66 {
67 if (this.Skin != null)
68 {
69 GUI.skin = this.Skin;
70 }
71
72 if (!PhotonNetwork.connected)
73 {
74 if (PhotonNetwork.connecting)
75 {
76 GUILayout.Label("Connecting to: " + PhotonNetwork.ServerAddress);
77 }
78 else
79 {
80 GUILayout.Label("Not connected. Check console output. Detailed connection state: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.ServerAddress);
81 }
82
83 if (this.connectFailed)
84 {
85 GUILayout.Label("Connection failed. Check setup and use Setup Wizard to fix configuration.");
86 GUILayout.Label(String.Format("Server: {0}", new object[] {PhotonNetwork.ServerAddress}));
87 GUILayout.Label("AppId: " + PhotonNetwork.PhotonServerSettings.AppID);
88
89 if (GUILayout.Button("Try Again", GUILayout.Width(100)))
90 {
91 this.connectFailed = false;
92 PhotonNetwork.ConnectUsingSettings("0.9");
93 }
94 }
95
96 return;
97 }
98
99 Rect content = new Rect((Screen.width - WidthAndHeight.x)/2, (Screen.height - WidthAndHeight.y)/2, WidthAndHeight.x, WidthAndHeight.y);
100 GUI.Box(content,"Join or Create Room");
101 GUILayout.BeginArea(content);
102
103 GUILayout.Space(40);
104
105 // Player name
106 GUILayout.BeginHorizontal();
107 GUILayout.Label("Player name:", GUILayout.Width(150));
108 PhotonNetwork.playerName = GUILayout.TextField(PhotonNetwork.playerName);
109 GUILayout.Space(158);
110 if (GUI.changed)
111 {
112 // Save name
113 PlayerPrefs.SetString("playerName", PhotonNetwork.playerName);
114 }
115 GUILayout.EndHorizontal();
116
117 GUILayout.Space(15);
118
119 // Join room by title
120 GUILayout.BeginHorizontal();
121 GUILayout.Label("Roomname:", GUILayout.Width(150));
122 this.roomName = GUILayout.TextField(this.roomName);
123
124 if (GUILayout.Button("Create Room", GUILayout.Width(150)))
125 {
126 PhotonNetwork.CreateRoom(this.roomName, new RoomOptions() { maxPlayers = 10 }, null);
127 }
128
129 GUILayout.EndHorizontal();
130
131 // Create a room (fails if exist!)
132 GUILayout.BeginHorizontal();
133 GUILayout.FlexibleSpace();
134 //this.roomName = GUILayout.TextField(this.roomName);
135 if (GUILayout.Button("Join Room", GUILayout.Width(150)))
136 {
137 PhotonNetwork.JoinRoom(this.roomName);
138 }
139
140 GUILayout.EndHorizontal();
141
142
143 if (!string.IsNullOrEmpty(this.ErrorDialog))
144 {
145 GUILayout.Label(this.ErrorDialog);
146
147 if (timeToClearDialog < Time.time)
148 {
149 timeToClearDialog = 0;
150 this.ErrorDialog = "";
151 }
152 }
153
154 GUILayout.Space(15);
155
156 // Join random room
157 GUILayout.BeginHorizontal();
158
159 GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");
160 GUILayout.FlexibleSpace();
161 if (GUILayout.Button("Join Random", GUILayout.Width(150)))
162 {
163 PhotonNetwork.JoinRandomRoom();
164 }
165
166
167 GUILayout.EndHorizontal();
168
169 GUILayout.Space(15);
170 if (PhotonNetwork.GetRoomList().Length == 0)
171 {
172 GUILayout.Label("Currently no games are available.");
173 GUILayout.Label("Rooms will be listed here, when they become available.");
174 }
175 else
176 {
177 GUILayout.Label(PhotonNetwork.GetRoomList().Length + " rooms available:");
178
179 // Room listing: simply call GetRoomList: no need to fetch/poll whatever!
180 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
181 foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
182 {
183 GUILayout.BeginHorizontal();
184 GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
185 if (GUILayout.Button("Join", GUILayout.Width(150)))
186 {
187 PhotonNetwork.JoinRoom(roomInfo.name);
188 }
189
190 GUILayout.EndHorizontal();
191 }
192
193 GUILayout.EndScrollView();
194 }
195
196 GUILayout.EndArea();
197 }
File name: WorkerMenu.cs
Copy
206 public void OnPhotonCreateRoomFailed()
207 {
208 this.ErrorDialog = "Error: Can't create room (room name maybe already used).";
209 Debug.Log("OnPhotonCreateRoomFailed got called. This can happen if the room exists (even if not visible). Try another room name.");
210 }
Download file with original file name:NOT
NOT 131 lượt xem
Gõ tìm kiếm nhanh...