Automatically
How do I use Automatically
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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: WorkerMenu.cs
Copy
43 public void Awake()
44 {
45 // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
46 PhotonNetwork.automaticallySyncScene = true;
47
48 // the following line checks if this client was just created (and not yet online). if so, we connect
49 if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated)
50 {
51 // Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
52 PhotonNetwork.ConnectUsingSettings("0.9");
53 }
54
55 // generate a name for this player, if none is assigned yet
56 if (String.IsNullOrEmpty(PhotonNetwork.playerName))
57 {
58 PhotonNetwork.playerName = "Guest" + Random.Range(1, 9999);
59 }
60
61 // if you wanted more debug out, turn this on:
62 // PhotonNetwork.logLevel = NetworkLogLevel.Full;
63 }
File name: NetworkingPeer.cs
Copy
530 // joins a room and sets your current username as custom actorproperty (will broadcast that)
536 private void ReadoutProperties(Hashtable gameProperties, Hashtable pActorProperties, int targetActorNr)
537 {
538 // Debug.LogWarning("ReadoutProperties gameProperties: " + gameProperties.ToStringFull() + " pActorProperties: " + pActorProperties.ToStringFull() + " targetActorNr: " + targetActorNr);
539 // read game properties and cache them locally
540 if (this.mCurrentGame != null && gameProperties != null)
541 {
542 this.mCurrentGame.CacheProperties(gameProperties);
543 SendMonoMessage(PhotonNetworkingMessage.OnPhotonCustomRoomPropertiesChanged, gameProperties);
544 if (PhotonNetwork.automaticallySyncScene)
545 {
546 this.LoadLevelIfSynced(); // will load new scene if sceneName was changed
547 }
548 }
549
550 if (pActorProperties != null && pActorProperties.Count > 0)
551 {
552 if (targetActorNr > 0)
553 {
554 // we have a single entry in the pActorProperties with one
555 // user's name
556 // targets MUST exist before you set properties
557 PhotonPlayer target = this.GetPlayerWithID(targetActorNr);
558 if (target != null)
559 {
560 Hashtable props = this.GetActorPropertiesForActorNr(pActorProperties, targetActorNr);
561 target.InternalCacheProperties(props);
562 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
563 }
564 }
565 else
566 {
567 // in this case, we've got a key-value pair per actor (each
568 // value is a hashtable with the actor's properties then)
569 int actorNr;
570 Hashtable props;
571 string newName;
572 PhotonPlayer target;
573
574 foreach (object key in pActorProperties.Keys)
575 {
576 actorNr = (int)key;
577 props = (Hashtable)pActorProperties[key];
578 newName = (string)props[ActorProperties.PlayerName];
579
580 target = this.GetPlayerWithID(actorNr);
581 if (target == null)
582 {
583 target = new PhotonPlayer(false, actorNr, newName);
584 this.AddNewPlayer(actorNr, target);
585 }
586
587 target.InternalCacheProperties(props);
588 SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerPropertiesChanged, target, props);
589 }
590 }
591 }
592 }
File name: NetworkingPeer.cs
Copy
3630 internal protected void LoadLevelIfSynced()
3631 {
3632 if (!PhotonNetwork.automaticallySyncScene || PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
3633 {
3634 return;
3635 }
3636
3637 // check if "current level" is set in props
3638 if (!PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
3639 {
3640 return;
3641 }
3642
3643 // if loaded level is not the one defined my master in props, load that level
3644 object sceneId = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
3645 if (sceneId is int)
3646 {
3647 if (Application.loadedLevel != (int)sceneId)
3648 PhotonNetwork.LoadLevel((int)sceneId);
3649 }
3650 else if (sceneId is string)
3651 {
3652 if (Application.loadedLevelName != (string)sceneId)
3653 PhotonNetwork.LoadLevel((string)sceneId);
3654 }
3655 }
File name: NetworkingPeer.cs
Copy
3657 protected internal void SetLevelInPropsIfSynced(object levelId)
3658 {
3659 if (!PhotonNetwork.automaticallySyncScene || !PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
3660 {
3661 return;
3662 }
3663 if (levelId == null)
3664 {
3665 Debug.LogError("Parameter levelId can't be null!");
3666 return;
3667 }
3668
3669 // check if "current level" is already set in props
3670 if (PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
3671 {
3672 object levelIdInProps = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
3673 if (levelIdInProps is int && Application.loadedLevel == (int)levelIdInProps)
3674 {
3675 return;
3676 }
3677 if (levelIdInProps is string && Application.loadedLevelName.Equals((string)levelIdInProps))
3678 {
3679 return;
3680 }
3681 }
3682
3683 // current level is not yet in props, so this client has to set it
3684 Hashtable setScene = new Hashtable();
3685 if (levelId is int) setScene[NetworkingPeer.CurrentSceneProperty] = (int)levelId;
3686 else if (levelId is string) setScene[NetworkingPeer.CurrentSceneProperty] = (string)levelId;
3687 else Debug.LogError("Parameter levelId must be int or string!");
3688
3689 PhotonNetwork.room.SetCustomProperties(setScene);
3690 this.SendOutgoingCommands(); // send immediately! because: in most cases the client will begin to load and not send for a while
3691 }
File name: PhotonNetwork.cs
Copy
526 {
527 get
528 {
529 return _mAutomaticallySyncScene;
530 }
531 set
532 {
533 _mAutomaticallySyncScene = value;
534 if (_mAutomaticallySyncScene && room != null)
535 {
536 networkingPeer.LoadLevelIfSynced();
537 }
538 }
539 }
File name: ReadmeEditor.cs
Copy
17 static ReadmeEditor()
18 {
19 EditorApplication.delayCall += SelectReadmeAutomatically;
20 }
File name: ReadmeEditor.cs
Copy
22 static void SelectReadmeAutomatically()
23 {
24 if (!SessionState.GetBool(kShowedReadmeSessionStateName, false ))
25 {
26 var readme = SelectReadme();
27 SessionState.SetBool(kShowedReadmeSessionStateName, true);
28
29 if (readme && !readme.loadedLayout)
30 {
31 LoadLayout();
32 readme.loadedLayout = true;
33 }
34 }
35 }
Automatically 133 lượt xem
Gõ tìm kiếm nhanh...