Destroyed
How do I use Destroyed
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: NetworkingPeer.cs
Copy
1962 public void ExecuteRPC(Hashtable rpcData, PhotonPlayer sender)
1963 {
1964 if (rpcData == null || !rpcData.ContainsKey((byte)0))
1965 {
1966 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
1967 return;
1968 }
1969
1970 // ts: updated with "flat" event data
1971 int netViewID = (int)rpcData[(byte)0]; // LIMITS PHOTONVIEWS&PLAYERS
1972 int otherSidePrefix = 0; // by default, the prefix is 0 (and this is not being sent)
1973 if (rpcData.ContainsKey((byte)1))
1974 {
1975 otherSidePrefix = (short)rpcData[(byte)1];
1976 }
1977
1978 string inMethodName;
1979 if (rpcData.ContainsKey((byte)5))
1980 {
1981 int rpcIndex = (byte)rpcData[(byte)5]; // LIMITS RPC COUNT
1982 if (rpcIndex > PhotonNetwork.PhotonServerSettings.RpcList.Count - 1)
1983 {
1984 Debug.LogError("Could not find RPC with index: " + rpcIndex + ". Going to ignore! Check PhotonServerSettings.RpcList");
1985 return;
1986 }
1987 else
1988 {
1989 inMethodName = PhotonNetwork.PhotonServerSettings.RpcList[rpcIndex];
1990 }
1991 }
1992 else
1993 {
1994 inMethodName = (string)rpcData[(byte)3];
1995 }
1996
1997 object[] inMethodParameters = null;
1998 if (rpcData.ContainsKey((byte)4))
1999 {
2000 inMethodParameters = (object[])rpcData[(byte)4];
2001 }
2002
2003 if (inMethodParameters == null)
2004 {
2005 inMethodParameters = new object[0];
2006 }
2007
2008 PhotonView photonNetview = this.GetPhotonView(netViewID);
2009 if (photonNetview == null)
2010 {
2011 int viewOwnerId = netViewID/PhotonNetwork.MAX_VIEW_IDS;
2012 bool owningPv = (viewOwnerId == this.mLocalActor.ID);
2013 bool ownerSent = (viewOwnerId == sender.ID);
2014
2015 if (owningPv)
2016 {
2017 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! View was/is ours." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID);
2018 }
2019 else
2020 {
2021 Debug.LogWarning("Received RPC \"" + inMethodName + "\" for viewID " + netViewID + " but this PhotonView does not exist! Was remote PV." + (ownerSent ? " Owner called." : " Remote called.") + " By: " + sender.ID + " Maybe GO was destroyed but RPC not cleaned up.");
2022 }
2023 return;
2024 }
2025
2026 if (photonNetview.prefix != otherSidePrefix)
2027 {
2028 Debug.LogError(
2029 "Received RPC \"" + inMethodName + "\" on viewID " + netViewID + " with a prefix of " + otherSidePrefix
2030 + ", our prefix is " + photonNetview.prefix + ". The RPC has been ignored.");
2031 return;
2032 }
2033
2034 // Get method name
2035 if (inMethodName == string.Empty)
2036 {
2037 Debug.LogError("Malformed RPC; this should never occur. Content: " + SupportClass.DictionaryToString(rpcData));
2038 return;
2039 }
2040
2041 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2042 Debug.Log("Received RPC: " + inMethodName);
2043
2044
2045 // SetReceiving filtering
2046 if (photonNetview.group != 0 && !allowedReceivingGroups.Contains(photonNetview.group))
2047 {
2048 return; // Ignore group
2049 }
2050
2051 Type[] argTypes = new Type[0];
2052 if (inMethodParameters.Length > 0)
2053 {
2054 argTypes = new Type[inMethodParameters.Length];
2055 int i = 0;
2056 for (int index = 0; index < inMethodParameters.Length; index++)
2057 {
2058 object objX = inMethodParameters[index];
2059 if (objX == null)
2060 {
2061 argTypes[i] = null;
2062 }
2063 else
2064 {
2065 argTypes[i] = objX.GetType();
2066 }
2067
2068 i++;
2069 }
2070 }
2071
2072 int receivers = 0;
2073 int foundMethods = 0;
2074 MonoBehaviour[] mbComponents = photonNetview.GetComponents
2075 for (int componentsIndex = 0; componentsIndex < mbComponents.Length; componentsIndex++)
2076 {
2077 MonoBehaviour monob = mbComponents[componentsIndex];
2078 if (monob == null)
2079 {
2080 Debug.LogError("ERROR You have missing MonoBehaviours on your gameobjects!");
2081 continue;
2082 }
2083
2084 Type type = monob.GetType();
2085
2086 // Get [RPC] methods from cache
2087 List
2088 if (this.monoRPCMethodsCache.ContainsKey(type))
2089 {
2090 cachedRPCMethods = this.monoRPCMethodsCache[type];
2091 }
2092
2093 if (cachedRPCMethods == null)
2094 {
2095 List
2096
2097 this.monoRPCMethodsCache[type] = entries;
2098 cachedRPCMethods = entries;
2099 }
2100
2101 if (cachedRPCMethods == null)
2102 {
2103 continue;
2104 }
2105
2106 // Check cache for valid methodname+arguments
2107 for (int index = 0; index < cachedRPCMethods.Count; index++)
2108 {
2109 MethodInfo mInfo = cachedRPCMethods[index];
2110 if (mInfo.Name == inMethodName)
2111 {
2112 foundMethods++;
2113 ParameterInfo[] pArray = mInfo.GetParameters();
2114 if (pArray.Length == argTypes.Length)
2115 {
2116 // Normal, PhotonNetworkMessage left out
2117 if (this.CheckTypeMatch(pArray, argTypes))
2118 {
2119 receivers++;
2120 object result = mInfo.Invoke((object)monob, inMethodParameters);
2121 if (mInfo.ReturnType == typeof(IEnumerator))
2122 {
2123 monob.StartCoroutine((IEnumerator)result);
2124 }
2125 }
2126 }
2127 else if ((pArray.Length - 1) == argTypes.Length)
2128 {
2129 // Check for PhotonNetworkMessage being the last
2130 if (this.CheckTypeMatch(pArray, argTypes))
2131 {
2132 if (pArray[pArray.Length - 1].ParameterType == typeof(PhotonMessageInfo))
2133 {
2134 receivers++;
2135
2136 int sendTime = (int)rpcData[(byte)2];
2137 object[] deParamsWithInfo = new object[inMethodParameters.Length + 1];
2138 inMethodParameters.CopyTo(deParamsWithInfo, 0);
2139 deParamsWithInfo[deParamsWithInfo.Length - 1] = new PhotonMessageInfo(sender, sendTime, photonNetview);
2140
2141 object result = mInfo.Invoke((object)monob, deParamsWithInfo);
2142 if (mInfo.ReturnType == typeof(IEnumerator))
2143 {
2144 monob.StartCoroutine((IEnumerator)result);
2145 }
2146 }
2147 }
2148 }
2149 else if (pArray.Length == 1 && pArray[0].ParameterType.IsArray)
2150 {
2151 receivers++;
2152 object result = mInfo.Invoke((object)monob, new object[] { inMethodParameters });
2153 if (mInfo.ReturnType == typeof(IEnumerator))
2154 {
2155 monob.StartCoroutine((IEnumerator)result);
2156 }
2157 }
2158 }
2159 }
2160 }
2161
2162 // Error handling
2163 if (receivers != 1)
2164 {
2165 string argsString = string.Empty;
2166 for (int index = 0; index < argTypes.Length; index++)
2167 {
2168 Type ty = argTypes[index];
2169 if (argsString != string.Empty)
2170 {
2171 argsString += ", ";
2172 }
2173
2174 if (ty == null)
2175 {
2176 argsString += "null";
2177 }
2178 else
2179 {
2180 argsString += ty.Name;
2181 }
2182 }
2183
2184 if (receivers == 0)
2185 {
2186 if (foundMethods == 0)
2187 {
2188 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" marked with the [RPC](C#) or @RPC(JS) property! Args: " + argsString);
2189 }
2190 else
2191 {
2192 Debug.LogError("PhotonView with ID " + netViewID + " has no method \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString);
2193 }
2194 }
2195 else
2196 {
2197 Debug.LogError("PhotonView with ID " + netViewID + " has " + receivers + " methods \"" + inMethodName + "\" that takes " + argTypes.Length + " argument(s): " + argsString + ". Should be just one?");
2198 }
2199 }
2200 }
File name: NetworkingPeer.cs
Copy
2656 public void LocalCleanPhotonView(PhotonView view)
2657 {
2658 view.destroyedByPhotonNetworkOrQuit = true;
2659 this.photonViewList.Remove(view.viewID);
2660 }
File name: NetworkingPeer.cs
Copy
2688 public void RegisterPhotonView(PhotonView netView)
2689 {
2690 if (!Application.isPlaying)
2691 {
2692 this.photonViewList = new Dictionary
2693 return;
2694 }
2695
2696 if (netView.viewID == 0)
2697 {
2698 // don't register views with ID 0 (not initialized). they register when a ID is assigned later on
2699 Debug.Log("PhotonView register is ignored, because viewID is 0. No id assigned yet to: " + netView);
2700 return;
2701 }
2702
2703 if (this.photonViewList.ContainsKey(netView.viewID))
2704 {
2705 // if some other view is in the list already, we got a problem. it might be undestructible. print out error
2706 if (netView != photonViewList[netView.viewID])
2707 {
2708 Debug.LogError(string.Format("PhotonView ID duplicate found: {0}. New: {1} old: {2}. Maybe one wasn't destroyed on scene load?! Check for 'DontDestroyOnLoad'. Destroying old entry, adding new.", netView.viewID, netView, photonViewList[netView.viewID]));
2709 }
2710
2711 //this.photonViewList.Remove(netView.viewID); // TODO check if we chould Destroy the GO of this view?!
2712 this.RemoveInstantiatedGO(photonViewList[netView.viewID].gameObject, true);
2713 }
2714
2715 // Debug.Log("adding view to known list: " + netView);
2716 this.photonViewList.Add(netView.viewID, netView);
2717 //Debug.LogError("view being added. " + netView); // Exit Games internal log
2718
2719 if (PhotonNetwork.logLevel >= PhotonLogLevel.Full)
2720 Debug.Log("Registered PhotonView: " + netView.viewID);
2721 }
File name: PhotonNetwork.cs
Copy
1988 public static void UnAllocateViewID(int viewID)
1989 {
1990 manuallyAllocatedViewIds.Remove(viewID);
1991
1992 if (networkingPeer.photonViewList.ContainsKey(viewID))
1993 {
1994 Debug.LogWarning(string.Format("UnAllocateViewID() should be called after the PhotonView was destroyed (GameObject.Destroy()). ViewID: {0} still found in: {1}", viewID, networkingPeer.photonViewList[viewID]));
1995 }
1996 }
File name: PhotonView.cs
Copy
290 protected internal void OnApplicationQuit()
291 {
292 destroyedByPhotonNetworkOrQuit = true; // on stop-playing its ok Destroy is being called directly (not by PN.Destroy())
293 }
File name: PhotonView.cs
Copy
295 protected internal void OnDestroy()
296 {
297 if (!this.destroyedByPhotonNetworkOrQuit)
298 {
299 PhotonNetwork.networkingPeer.LocalCleanPhotonView(this);
300 }
301
302 if (!this.destroyedByPhotonNetworkOrQuit && !Application.isLoadingLevel)
303 {
304 if (this.instantiationId > 0)
305 {
306 // if this viewID was not manually assigned (and we're not shutting down or loading a level), you should use PhotonNetwork.Destroy() to get rid of GOs with PhotonViews
307 Debug.LogError("OnDestroy() seems to be called without PhotonNetwork.Destroy()?! GameObject: " + this.gameObject + " Application.isLoadingLevel: " + Application.isLoadingLevel);
308 }
309 else
310 {
311 // this seems to be a manually instantiated PV. if it's local, we could warn if the ID is not in the allocated-list
312 if (this.viewID <= 0)
313 {
314 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is 0. Was it ever (manually) set?", this));
315 }
316 else if (this.isMine && !PhotonNetwork.manuallyAllocatedViewIds.Contains(this.viewID))
317 {
318 Debug.LogWarning(string.Format("OnDestroy manually allocated PhotonView {0}. The viewID is local (isMine) but not in manuallyAllocatedViewIds list. Use UnAllocateViewID() after you destroyed the PV.", this));
319 }
320 }
321 }
322 }
File name: BossHealth.cs
Copy
28 public void Health(int damage){
29 if (!invulnerable) {
30 if (!health.gameObject.activeInHierarchy) {
31 health.gameObject.SetActive (true);
32 }
33
34 if (health.value > 0) {
35 health.value -= damage;
36 }
37
38 if (health.value == 0) {
39 BossDestroyed ();
40 }
41 }
42 }
File name: BossHealth.cs
Copy
44 void BossDestroyed(){
45 Destroy (gameObject);
46 GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent
47 GameObject.FindGameObjectWithTag ("Spawner").transform.GetComponent
48 if(GameController.instance != null && MusicController.instance != null){
49 if(GameController.instance.isMusicOn){
50 MusicController.instance.audioSource.PlayOneShot (MusicController.instance.bossExplode);
51 }
52 }
53 Instantiate (explode, transform.position, Quaternion.identity);
54 for (int i = 0; i < 5; i++) {
55 Instantiate (coin, transform.position, Quaternion.identity);
56 }
57 }
File name: GameplayController.cs
Copy
88 void GameIsOnPlay(){
89 /*if (PlayerBullet () == 0) {
90 timeAfterLastShot += Time.deltaTime;
91 camera.isFollowing = false;
92 if (timeAfterLastShot > 2f) {
93 if (AllStopMoving () && AllEnemiesDestroyed ()) {
94 if (!gameFinished) {
95 gameFinished = true;
96 Debug.Log ("Hello World");
97 }
98 } else if (AllStopMoving () && !AllEnemiesDestroyed ()) {
99 if (!gameFinished) {
100 gameFinished = true;
101 Debug.Log ("Hi World");
102 }
103 }
104 }
105
106 }*/
107
108 if(checkGameStatus){
109 timeAfterLastShot += Time.deltaTime;
110 if (timeAfterLastShot > 2f) {
111 if (AllStopMoving () || Time.time - timeSinceStartedShot > 8f) {
112 if (AllEnemiesDestroyed ()) {
113 if (!gameFinished) {
114 gameFinished = true;
115 GameWin ();
116 timeAfterLastShot = 0;
117 checkGameStatus = false;
118 }
119 } else {
120 if (PlayerBullet () == 0) {
121 if (!gameFinished) {
122 gameFinished = true;
123 timeAfterLastShot = 0;
124 checkGameStatus = false;
125 GameLost ();
126 }
127 } else {
128 checkGameStatus = false;
129 camera.isFollowing = false;
130 timeAfterLastShot = 0;
131 }
132 }
133 }
134 }
135
136 }
137
138 }
File name: GameplayController.cs
Copy
182 private bool AllEnemiesDestroyed(){
183 return enemies.All(x => x == null);
184 }
Destroyed 169 lượt xem
Gõ tìm kiếm nhanh...