Completed









How do I use Completed
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: AccountService.cs Copy
93     public void RegisterByEmailAsync(string email, Origin origin, Action callback = null)
94     {
95         this.registrationCallback = callback;
96         this.AppId = string.Empty;
97         this.Message = string.Empty;
98         this.ReturnCode = -1;
99
100         try
101         {
102             HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(this.RegistrationUri(email, (byte)origin));
103             req.Timeout = 5000;
104             req.BeginGetResponse(this.OnRegisterByEmailCompleted, req);
105         }
106         catch (Exception ex)
107         {
108             this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
109             this.Exception = ex;
110             if (this.registrationCallback != null)
111             {
112                 this.registrationCallback(this);
113             }
114         }
115     }
File name: AccountService.cs Copy
121     private void OnRegisterByEmailCompleted(IAsyncResult ar)
122     {
123         try
124         {
125             HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
126             HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse;
127
128             if (response != null && response.StatusCode == HttpStatusCode.OK)
129             {
130                 // no error. use the result
131                 StreamReader reader = new StreamReader(response.GetResponseStream());
132                 string result = reader.ReadToEnd();
133
134                 this.ParseResult(result);
135             }
136             else
137             {
138                 // a response but some error on server. show message
139                 this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
140             }
141         }
142         catch (Exception ex)
143         {
144             // not even a response. show message
145             this.Message = "Failed to connect to Cloud Account Service. Please register via account website.";
146             this.Exception = ex;
147         }
148
149         if (this.registrationCallback != null)
150         {
151             this.registrationCallback(this);
152         }
153     }
File name: PhotonConverter.cs Copy
18     public static void RunConversion()
19     {
20         //Ask if user has made a backup.
21         int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22         switch (option)
23         {
24             case 0:
25                 break;
26             case 1:
27                 return;
28             case 2:
29                 PickFolderAndConvertScripts();
30                 return;
31             default:
32                 return;
33         }
34
35         //REAAAALY?
36         bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37         if (!result)
38         {
39             return;
40         }
41         Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43         //Ask to save current scene (optional)
44         EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46         EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48         //Convert NetworkViews to PhotonViews in Project prefabs
49         //Ask the user if we can move all prefabs to a resources folder
50         bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53         string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54         foreach (string prefab in prefabs)
55         {
56             EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58             Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59             int converted = 0;
60             foreach (Object obj in objs)
61             {
62                 if (obj != null && obj.GetType() == typeof(GameObject))
63                     converted += ConvertNetworkView(((GameObject)obj).GetComponents(), false);
64             }
65             if (movePrefabs && converted > 0)
66             {
67                 //This prefab needs to be under the root of a Resources folder!
68                 string path = prefab.Replace("\\", "/");
69                 int lastSlash = path.LastIndexOf("/");
70                 int resourcesIndex = path.LastIndexOf("/Resources/");
71                 if (resourcesIndex != lastSlash - 10)
72                 {
73                     if (path.Contains("/Resources/"))
74                     {
75                         Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76                     }
77                     //This prefab NEEDS to be placed under a resources folder
78                     string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79                     EnsureFolder(resourcesFolder);
80                     string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81                     string error = AssetDatabase.MoveAsset(prefab, newPath);
82                     if (error != "")
83                         Debug.LogError(error);
84                     Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85                 }
86             }
87         }
88
89         //Convert NetworkViews to PhotonViews in scenes
90         string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91         foreach (string sceneName in sceneFiles)
92         {
93             EditorApplication.OpenScene(sceneName);
94             EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96             int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97             if (converted2 > 0)
98             {
99                 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100                 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102                 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103                 EditorApplication.SaveScene(EditorApplication.currentScene);
104             }
105
106         }
107
108         //Convert C#/JS scripts (API stuff)
109         List scripts = GetScriptsInFolder("Assets");
110
111         EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112         ConvertScripts(scripts);
113
114         Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115         EditorUtility.ClearProgressBar();
116
117         EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118     }
File name: NetworkingPeer.cs Copy
495     protected internal void LocalCleanupAnythingInstantiated(bool destroyInstantiatedGameObjects)
496     {
497         if (tempInstantiationData.Count > 0)
498         {
499             Debug.LogWarning("It seems some instantiation is not completed, as instantiation data is used. You should make sure instantiations are paused when calling this method. Cleaning now, despite this.");
500         }
501
502         // Destroy GO's (if we should)
503         if (destroyInstantiatedGameObjects)
504         {
505             // Fill list with Instantiated objects
506             HashSet instantiatedGos = new HashSet();
507             foreach (PhotonView view in this.photonViewList.Values)
508             {
509                 if (view.isRuntimeInstantiated)
510                 {
511                     instantiatedGos.Add(view.gameObject); // HashSet keeps each object only once
512                 }
513             }
514
515             foreach (GameObject go in instantiatedGos)
516             {
517                 this.RemoveInstantiatedGO(go, true);
518             }
519         }
520
521         // photonViewList is cleared of anything instantiated (so scene items are left inside)
522         // any other lists can be
523         this.tempInstantiationData.Clear(); // should be empty but to be safe we clear (no new list needed)
524         PhotonNetwork.lastUsedViewSubId = 0;
525         PhotonNetwork.lastUsedViewSubIdStatic = 0;
526     }

Completed 97 lượt xem

Gõ tìm kiếm nhanh...