private static void AfterInject(AssemblyDefinition ad) { string unityEditorPath = typeof(AssetDatabase).Module.FullyQualifiedName; string path = Path.Combine(Path.GetDirectoryName(Application.dataPath), "UnityEditor.dll"); if (File.Exists(path)) { File.Delete(path); } ad.Write(path); try { string dest = Path.Combine(Path.GetDirectoryName(Application.dataPath), "Library/UnityAssemblies/"); File.Copy(path, dest + "UnityEditor.dll"); File.Copy(path, unityEditorPath, true); } catch (Exception e) { XDebug.LogWarning(e.Message); if (EditorUtility.DisplayDialog("Error", "move folder error. move folder manually please!", "OK")) { HelperEditor.Open(unityEditorPath); HelperEditor.Open(path); } } if (EditorUtility.DisplayDialog("Inject", "UnityEditor.dll Inject Finish, restart your Unity, Yes or Not", "OK", "NO")) { SetSccriptDefine(); RestartUnity(); } }
private static bool PopulateValueSingle(Type fieldType, SerializedProperty property, AutoPopulateAttribute autoPopulate) { Object value = null; Type searchType = GetSearchType(fieldType, autoPopulate); foreach (Object targetObject in property.serializedObject.targetObjects) { MonoBehaviour behaviour = targetObject as MonoBehaviour; if (behaviour == null) { XDebug.LogWarning(targetObject, "Couldn't find target behaviour on {0}.", targetObject); continue; } SerializedObject singleObject = new SerializedObject(targetObject); SerializedProperty singleProperty = singleObject.FindProperty(property.propertyPath); if (singleProperty == null) { XDebug.LogWarning(behaviour, "Couldn't find {0} property for {1}", property.propertyPath, behaviour); continue; } Transform root = FindRoot(behaviour.gameObject, autoPopulate.FindRelativeTo); if (root == null) { continue; } switch (autoPopulate.Find) { case AutoPopulateAttribute.FindBehaviour.Self: value = FindObjectInSelf(root, searchType); break; case AutoPopulateAttribute.FindBehaviour.Children: value = FindObjectInChildren(root, searchType); break; case AutoPopulateAttribute.FindBehaviour.Parent: value = FindObjectInParent(root, searchType); break; default: throw new ArgumentOutOfRangeException(); } SetValue(singleProperty, fieldType, value); singleObject.ApplyModifiedProperties(); } if (value != null) { property.serializedObject.SetIsDifferentCacheDirty(); } return(value != null); }
//[MenuItem("Window/Asset Usages - Refresh", priority = (int) BDJMenuPriority.BDJ)] private static void PopulateAllReferences() { string[] all = AssetDatabase.GetAllAssetPaths(); for (int i = 0; i < all.Length; i++) { string path = all[i]; if (!path.StartsWith("Assets")) { continue; } try { if (GetUsageInfo(path).UpdateReferencees(i, all.Length)) { XDebug.LogWarning("Populate All Cancelled at " + (i * 1f / all.Length).ToString("P0")); EditorUtility.ClearProgressBar(); return; } } catch (Exception e) { Debug.LogException(e); //.LogError("Populate All couldn't get references for " + path + " because " + e.Message); } } EditorUtility.ClearProgressBar(); Instance.Repaint(); Instance.m_Scanned = true; }
public static T EnsureExistsInScene(GameObject go, bool isExpanded = true) { // if we already have set the singleton... use it. if (single != null) { return(single); } // if not, try to find the object in scene and return it. single = FindObjectOfType <T>(); if (single != null) { return(single); } // Don't attempt to make a new one if we are shutting down a game. if (isShuttingDown && Application.isPlaying) { return(single); } XDebug.LogWarning(!XDebug.logWarnings ? null : ("<b>No " + (typeof(T)) + " found in scene. Adding one with default settings.</b> You probably want to edit the settings yourself.")); single = go.AddComponent <T>(); UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(single, isExpanded); return(single); }
/// <summary> /// Finds UI Elements. If none found will create them and return false to indicate that placeholders are being used. /// </summary> /// <returns></returns> public bool FindUIElement() { // First see if this is on a canvas, if so note it if (!canvas) { canvas = GetComponent <Canvas>(); } // Is this a placeholder canvas we just created for another bar? if (canvas && canvas.gameObject.name == PLACEHOLDER_CANVAS_NAME) { // This means another HealthUI created a placeholder, so we will use that canvas. } // If we have a canvas then search for the text/images else if (canvas) { if (canvas.gameObject.name != PLACEHOLDER_CANVAS_NAME) { if (!UIText) { UIText = (searchChildren) ? canvas.GetComponentInChildren <Text>() : canvas.GetComponent <Text>(); } if (!UIImage) { UIImage = (searchChildren) ? canvas.GetComponentInChildren <Image>() : canvas.GetComponent <Image>(); } } } // No canvas, so this may be the UI Element itself this is attached to else { if (!UIText) { UIText = (searchChildren) ? GetComponentInChildren <Text>() : GetComponent <Text>(); } if (!UIImage) { UIImage = (searchChildren) ? GetComponentInChildren <Image>() : GetComponent <Image>(); } } // If nothing was found after all of that - we need to make a canvas and UI elements. if (!UIText && !UIImage) { XDebug.LogWarning(!XDebug.logWarnings ? null : ("NSTSampleHealthUI on gameobject '" + name + "' cannot find any UI Canvas, Text or Image. Will create some placeholders until you supply them."), nst); XDebug.LogError(!XDebug.logErrors ? null : ("NSTSampleHealthUI on gameobject '" + name + "' cannot find a NetworkSyncTransform, UI Text, or UI Image component. Be sure the object we are attaching to conains one of those."), !nst); // Put some bars of this things head if it is an NST - Otherwise they won't make much sense on other objects. if (nst) { CreatePlaceholderVitalBar(monitoredVitalId); } return(false); } return(true); }
public void Initialize() { if (initialized) { return; } initialized = true; // Eliminate any NSTs that are in the scene at startup (they are just trash left by the developer and are not server spawned. if (Application.isPlaying && MasterNetAdapter.NetworkLibrary == NetworkLibrary.UNET) { NSTTools.DestroyAllNSTsInScene(); } /// If enough network lib specific things show up here, I may need to make a new start adapter for network /// but for not, just keeping this here. // Ensure that UNET is sending our packet immediately. #if MIRROR || !UNITY_2019_1_OR_NEWER if (MasterNetAdapter.NetworkLibrary == NetworkLibrary.UNET) { // this is here so we can access the NM out of play mode if (NetworkManager.singleton == null && !Application.isPlaying) { NetworkManager.singleton = UnityEngine.Object.FindObjectOfType <NetworkManager>(); } #if !PUN_2_OR_NEWER && !MIRROR if (NetworkManager.singleton != null) { NetworkManager.singleton.connectionConfig.SendDelay = 0; } #endif } #endif // Not ideal code to prevent hitching issues with vsync being off - ensures a reasonable framerate is being enforced if (QualitySettings.vSyncCount == 0) { if (Application.targetFrameRate <= 0) { Application.targetFrameRate = 60; } else { Application.targetFrameRate = Application.targetFrameRate; } XDebug.LogWarning(!XDebug.logWarnings ? null : ("VSync appears to be disabled, which can cause some problems with Networking. \nEnforcing the current framerate of " + Application.targetFrameRate + " to prevent hitching. Enable VSync or set 'Application.targetFrameRate' as desired if this is not the framerate you would like.")); } }
protected virtual void Awake() { isShuttingDown = false; if (single != null && single != this) { XDebug.LogWarning("Enforcing " + typeof(T) + " singleton. Multiples found."); Destroy(gameObject); } else { single = this as T; } }
public void SetBehaviorTree(string tree) { if (!string.IsNullOrEmpty(tree)) { _is_inited = true; _tree.Initial(_entity); _tree.SetBehaviorTree(tree); _tree.EnableBehaviorTree(true); _tree.SetManual(true); _tick = _ai_tick * _tick_factor; } else { XDebug.LogWarning("ai error: ", tree, _entity.Attributes.Name); } }
protected void Update() { #if XDEBUG foreach (List <SignalPacket> packets in m_SignalsLastFrame.Values) { foreach (SignalPacket packet in packets) { if (packet.NoReceivers) { XDebug.LogWarning(this, "No receivers found for '{0}'", Signal.LookupName(packet.Signal)); } } } #endif m_SignalsLastFrame.Clear(); }
private static string GetOpByType(string type, string obj) { string t = type; switch (type) { case "Vector3": t = "Obj2Vector(" + obj + ");"; break; case "System.String": case "string": t = obj + ".get<std::string>();"; break; case "System.Int32": case "int": t = "(int)" + obj + ".get<double>();"; break; case "System.UInt32": case "uint": t = "(uint)" + obj + ".get<double>();"; break; case "System.Single": case "float": t = "(float)" + obj + ".get<double>();"; break; case "System.Boolean": case "bool": t = obj + ".get<bool>();"; break; case "GameObject": case "Transform": t = string.Empty; XDebug.LogWarning("make cpp code err, gameobject or transform can't initial by editor "); break; default: t = obj + ";"; break; } return(t); }
/// <summary> /// Tries to register this NST as the player prefab (if there is none currently set), after doing some checks to make sure it makes sense to. /// </summary> public static void AddAsRegisteredPrefab(GameObject go, bool playerPrefabCandidate, bool silence = false) { // Doesn't apply to PUN PUNSampleLauncher punl = UnityEngine.Object.FindObjectOfType <PUNSampleLauncher>(); if (punl && !punl.playerPrefab && playerPrefabCandidate) { XDebug.LogWarning("Adding " + go.name + " as the player prefab to " + typeof(PUNSampleLauncher).Name); #if UNITY_2018_3_OR_NEWER GameObject parprefab = PrefabUtility.GetCorrespondingObjectFromSource(go); #else #pragma warning disable CS0618 // Type or member is obsolete GameObject parprefab = (GameObject)PrefabUtility.GetPrefabParent(go); #pragma warning restore CS0618 // Type or member is obsolete #endif punl.playerPrefab = parprefab ? parprefab : go; } }
// public void unloadBundle() { // 释放函数 if (ab != null) { if (this.assets.Count > 0) { XDebug.LogWarning(this.res + ",有还有" + this.assets.Count + "资源未释放"); } ab.Unload(true); ab = null; } // 恢复到初始状态 this.status = XLoadStatus.NONE; }
/// <summary> /// Add a prefab to the Pool list, and create a pool. Returns the list index. /// </summary> /// <param name="_prefab"></param> /// <param name="_growBy"></param> /// <param name="_scriptToAdd">Indicate a typeof(Component) that you want added (if not already there) to the root of all instantiated pool items.</param> /// <returns></returns> public static void AddPrefabToPool(GameObject _prefab, int startingSize = 8, int _growBy = 8, Type _scriptToAdd = null) { if (!_prefab) { XDebug.LogWarning("Attempt to add null object to the pool.", true, true); } if (poolItemDefs.ContainsKey(_prefab)) { return; } pools.Add(_prefab, new Stack <Pool>()); poolItemDefs.Add(_prefab, new PoolItemDef(_prefab, _growBy, _scriptToAdd)); GrowPool(_prefab, startingSize); }
void Start() { XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.LogWarning("XLoger Warning"); XDebug.LogError("XLoger Error"); XDebug.LogChannel("Game", "I am a message fron channel: Game"); XDebug.LogChannel("Data", "I am a message fron channel: Data"); XDebug.LogChannel("Time", "I am a message fron channel: Time"); XDebug.LogWarningChannel("Game", "I am a message fron channel: Game"); XDebug.LogWarningChannel("Data", "I am a message fron channel: Data"); XDebug.LogWarningChannel("Time", "I am a message fron channel: Time"); XDebug.LogErrorChannel("Game", "I am a message fron channel: Game"); XDebug.LogErrorChannel("Data", "I am a message fron channel: Data"); XDebug.LogErrorChannel("Time", "I am a message fron channel: Time"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.Log("XLoger Message"); XDebug.LogWarning("XLoger Warning"); XDebug.LogError("XLoger Error"); XDebug.LogChannel("Game", "I am a message fron channel: Game"); XDebug.LogChannel("Data", "I am a message fron channel: Data"); XDebug.LogChannel("Time", "I am a message fron channel: Time"); XDebug.LogWarningChannel("Game", "I am a message fron channel: Game"); XDebug.LogWarningChannel("Data", "I am a message fron channel: Data"); XDebug.LogWarningChannel("Time", "I am a message fron channel: Time"); XDebug.LogErrorChannel("Game", "I am a message fron channel: Game"); XDebug.LogErrorChannel("Data", "I am a message fron channel: Data"); XDebug.LogErrorChannel("Time", "I am a message fron channel: Time"); }
private static void CheckFx() { fxPath.Clear(); EnumPrefab(_CheckFx, "CheckFx"); string full = ""; foreach (List <string> prefabs in fxPath.Values) { if (prefabs.Count > 1) { string str = ""; foreach (string prefab in prefabs) { str += prefab + "\r\n"; } full += str + "\r\n"; XDebug.LogWarning(str); } } File.WriteAllText("Assets/Resources/Effects/Fx.txt", full); }
private void OnOverrideTextureSignal(Component sender, object data) { Texture texture = data as Texture; if (!texture || !m_MaterialWithTexture || !m_Renderer) { XDebug.Assert(texture, this, "Signal data doesn't contain a texture."); XDebug.Assert(m_MaterialWithTexture, this, "Material reference missing."); XDebug.Assert(m_Renderer, this, "Renderer missing."); return; } Material mat = m_Renderer.materials.FirstOrDefault(MatchingMaterial); if (!mat) { XDebug.LogWarning(this, "No matching texture: " + m_MaterialWithTexture.name); return; } mat.mainTexture = texture; }
public void ValidateSelection(NSTComponent _parent) { List <string> tags = HitGroupSettings.Single.hitGroupTags; if (hitGroupTagId < tags.Count) { // If tag id matches the tag name... this is valid. if (hitGroupTag == tags[hitGroupTagId]) { return; } // if not valid loop through all of the tags and see if we have a name match at a different index. for (int i = 0; i < tags.Count; i++) { if (hitGroupTag == tags[i]) { hitGroupTagId = i; XDebug.LogWarning(!XDebug.logWarnings ? null : (_parent.name + " references hit group named '" + hitGroupTag + "', but that tag is no longer at the same index. " + "Likely this means you have renamed, added or removed a rewind tag and not updated any selection boxes referring to it. Will use the tag of the same name.")); return; } } XDebug.LogWarning(!XDebug.logWarnings ? null : (_parent.name + " references hit group tag named '" + hitGroupTag + "', but that tag does not exist anymore. " + "Likely this means you have renamed, added or removed a rewind tag and not updated a selection boxes referring to it. Will use '" + tags[hitGroupTagId] + "' instead.")); // Name tag couldn't be found, so using the tag that now resides at the index hitGroupTag = tags[hitGroupTagId]; return; } XDebug.LogWarning(!XDebug.logWarnings ? null : (_parent.name + " references hit group tag named '" + hitGroupTag + "', but that tag does not exist anymore. " + "Likely this means you have renamed, added or removed a rewind tag and not updated a selection boxes referring to it. Will use default instead.")); hitGroupTagId = 0; hitGroupTag = tags[0]; }
public void ValidateZoneIdAndName() { // If the list is empty, may mean that UIZones haven't initialized UIZone.GetAllInScene(); if (UIZone.list.Count == 0) { zoneSelector.ZoneId = 0; zoneSelector.ZoneName = ""; return; } // If zoneId is out of range, use zero if (zoneSelector.ZoneId >= UIZone.list.Count) { zoneSelector.ZoneId = 0; } // If the selected name and id don't match, try to guess which one is correct if (UIZone.list[zoneSelector.ZoneId].itemName != zoneSelector.ZoneName) { // First try to find the itemName, if it exists we want that if (zoneSelector.ZoneName != "" && UIZone.lookup.ContainsKey(zoneSelector.ZoneName)) { XDebug.LogWarning(!XDebug.logWarnings ? null : ("Component '" + parent.GetType() + "' references UIZone named '" + zoneSelector.ZoneName + "'. the index doesn't match though. Will use the new index for that zone name.")); zoneSelector.ZoneId = UIZone.lookup[zoneSelector.ZoneName].index; } else { XDebug.LogWarning(!XDebug.logWarnings ? null : ("Component '" + parent.GetType() + "' references UIZone named '" + zoneSelector.ZoneName + "', but it no longer exists. '" + UIZone.list[zoneSelector.ZoneId].itemName + "' will be used instead"), zoneSelector.ZoneName != ""); zoneSelector.ZoneName = UIZone.list[zoneSelector.ZoneId].itemName; } } }
public static NetworkManager GetNetworkManager(bool createMissing = false) { if (MasterNetAdapter.NetLib != NetworkLibrary.UNET) { return(null); } if (NetworkManager.singleton == null) { #if MIRROR List <NetworkManager> mirrorNM = FindObjects.FindObjectsOfTypeAllInScene <Mirror.NetworkManager>(); if (mirrorNM.Count > 0) { return(mirrorNM[0]); } #endif List <NetworkManager> found = FindObjects.FindObjectsOfTypeAllInScene <NetworkManager>(); if (found.Count > 0) { NetworkManager.singleton = found[0]; } else if (createMissing) { Debug.Log("<b>Adding Network Manager</b>"); XDebug.LogWarning(!XDebug.logWarnings ? null : ("No NetworkManager in scene. Adding one now.")); GameObject nmGo = GameObject.Find("Network Manager"); if (nmGo == null) { nmGo = new GameObject("Network Manager"); } NetworkManager.singleton = nmGo.AddComponent <NetworkManager>(); // If we are creating a missing NM, also create a HUD in case user wants that. NetworkManagerHUD hud = nmGo.GetComponent <NetworkManagerHUD>(); if (!hud) { nmGo.AddComponent <NetworkManagerHUD>(); } // Copy the playerprefab over from pun if it exists. //#if MIRROR // var unetHUD = nmGo.GetComponent<UnityEngine.Networking.NetworkManagerHUD>(); // if (unetHUD) // Object.DestroyImmediate(unetHUD); // var unetNM = nmGo.GetComponent<UnityEngine.Networking.NetworkManager>(); // if (unetNM) // Object.DestroyImmediate(unetNM); //#endif } } return(NetworkManager.singleton); }
///// <summary> ///// Check if the Net Library selected in mastersettings doesn't match the library of the adapters. Whill change to the library ///// in MasterSettings if not. ///// </summary> ///// <param name="newLib"></param> //public static bool ChangeLibraries() //{ // return ChangeLibraries(NetLibrarySettings.Single.networkLibrary); //} /// <summary> /// Initiate the Library change process. /// </summary> /// <param name="newLib"></param> public static bool ChangeLibraries(NetworkLibrary newLib) { // Don't do anything if the adapters already are correct if (newLib == MasterNetAdapter.NetworkLibrary && newLib == NSTNetAdapter.NetLibrary) { return(true); } if (newLib == NetworkLibrary.PUN && !PUN_Exists) { Debug.LogError("Photon PUN does not appear to be installed (Cannot find the PhotonNetwork assembly). Be sure it is installed from the asset store for this project."); return(false); } if (newLib == NetworkLibrary.PUN2 && !PUN2_Exists) { Debug.LogError("Photon PUN2 does not appear to be installed (Cannot find the PhotonNetwork assembly). Be sure it is installed from the asset store for this project."); return(false); } if (!EditorUtility.DisplayDialog("Change Network Library To " + System.Enum.GetName(typeof(NetworkLibrary), newLib) + "?", "Changing libraries is a very messy brute force operation (you may see compile errors and may need to restart Unity). " + "Did you really want to do this, or are you just poking at things to see what they do?", "Change Library", "Cancel")) { return(false); } Debug.Log("Removing current adapters from game objects for Network Library change ..."); PurgeLibraryReferences(); // Close and reopen the current scene to remove the bugginess of orphaned scripts. var curscene = EditorSceneManager.GetActiveScene(); var curscenepath = curscene.path; if (EditorUtility.DisplayDialog("Save Scene Before Reload?", "Scene must be reloaded to complete the purging of old library adapters. Would you like to save this scene?", "Save Scene", "Don't Save")) { EditorSceneManager.SaveScene(curscene); } // force a scene close to eliminate weirdness EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single); if (MasterNetAdapter.NetworkLibrary != newLib) { CopyUncompiledAdapters(newLib); } EditorUtility.DisplayDialog("Touch Nothing!", "Wait for the compiling animation in the bottom right of Unity to stop before doing anything. Touching NST related assets will result in broken scripts and errors.", "I Won't Touch, Promise."); // Flag the need for a deep global find of NSTs and NSTMasters in need of adapters XDebug.LogWarning("Add dependencies pending. Clicking on any NST related object in a scene " + "will trigger the final steps of the transition to " + newLib + ". You may need to select the " + "Player Prefab in the scene or asset folder in order to make it the default player object.", true, true); NetLibrarySettings.Single.dependenciesNeedToBeCheckedEverywhere = true; AssetDatabase.Refresh(); EditorUtility.SetDirty(NetLibrarySettings.single); AssetDatabase.SaveAssets(); return(true); }
private static bool PopulateValueArray(Type fieldType, SerializedProperty property, AutoPopulateAttribute autoPopulate) { Object[] values = null; Type elementType = fieldType.GetElementType(); Type searchType = GetSearchType(elementType, autoPopulate); foreach (Object targetObject in property.serializedObject.targetObjects) { MonoBehaviour behaviour = targetObject as MonoBehaviour; if (behaviour == null) { XDebug.LogWarning(targetObject, "Couldn't find target behaviour on {0}.", targetObject); continue; } SerializedObject singleObject = new SerializedObject(targetObject); SerializedProperty singleProperty = singleObject.FindProperty(property.propertyPath); if (singleProperty == null) { XDebug.LogWarning(behaviour, "Couldn't find {0} property for {1}", property.propertyPath, behaviour); continue; } Transform root = FindRoot(behaviour.gameObject, autoPopulate.FindRelativeTo); if (root == null) { XDebug.LogWarning(behaviour, "Couldn't find root object for {0}.", behaviour.gameObject); continue; } switch (autoPopulate.Find) { case AutoPopulateAttribute.FindBehaviour.Self: values = FindObjectsInSelf(root, searchType); break; case AutoPopulateAttribute.FindBehaviour.Children: values = FindObjectsInChildren(root, searchType); break; case AutoPopulateAttribute.FindBehaviour.Parent: values = FindObjectsInParent(root, searchType); break; default: throw new ArgumentOutOfRangeException(); } singleProperty.arraySize = values.Length; for (int i = 0; i < values.Length; i++) { SerializedProperty element = singleProperty.GetArrayElementAtIndex(i); SetValue(element, elementType, values[i]); element.objectReferenceValue = values[i]; } singleObject.ApplyModifiedProperties(); } if (values != null && values.Length > 0) { property.serializedObject.SetIsDifferentCacheDirty(); } return(values != null && values.Length > 0); }
/// <summary> /// Reads update headers for each NST frame update in the incoming bitstream, and passes the bitstream to that NST to read out its /// update information. /// </summary> /// <param name="mirror">True if this is the server, and this is the incoming bitstream. Tells the server that the outstream /// needs to be populated for retransmission to all clients. Also false if this is the server running its own outgoing update.</param> public static void ReceiveUpdate(ref UdpBitStream bitstream, ref UdpBitStream outstream, bool mirror, int senderId) { // Create a new bitstream to ensure ptr is at 0. Same data as master though. bitstream.ptr = 0; int frameid = bitstream.ReadInt(6); if (mirror) { outstream.WriteInt(frameid, 6); } bool isOfftick = frameid == FRAME_COUNT; int sceneIndex = NSTSceneManager.Deserialize(ref bitstream, ref outstream, mirror); bool sceneOutOfSync = HeaderSettings.single.includeSceneIndex && sceneIndex != NSTSceneManager.CurrentSceneIndex; if (sceneOutOfSync) { Debug.LogWarning(frameid + " Out of sync " + sceneIndex + " " + NSTSceneManager.CurrentSceneIndex); } // remove this safety once working //TEST int safety = 0; UpdateType updateType; do { safety++; BandwidthUsage.Start(ref bitstream, BandwidthLogType.UpdateRcv); //stop looking when header is EOS bool notEOS = bitstream.ReadBool(); int mirrorUpdateStartPtr = outstream.ptr; BandwidthUsage.AddUsage(ref bitstream, "NotEOS"); if (mirror) { outstream.WriteBool(notEOS); } if (!notEOS) { break; } // First three bits are the msgtype //TODO this might only need to be two updateType = (UpdateType)bitstream.ReadInt(3); BandwidthUsage.AddUsage(ref bitstream, "UpdateType"); int updateBitstreamPos = outstream.ptr; if (mirror) { outstream.WriteInt((int)updateType, 3); } // Next variable is the NstId - get it to know where to send the rest of the bitstream uint nstid = bitstream.ReadUInt(HeaderSettings.single.BitsForNstId); BandwidthUsage.AddUsage(ref bitstream, "NstId"); if (mirror) { outstream.WriteUInt(nstid, HeaderSettings.single.BitsForNstId); } lastNST = NSTTools.GetNstFromId(nstid); BandwidthUsage.SetName(lastNST); int updatelength = bitstream.ReadInt(UPDATELENGTH_BYTE_COUNT_SIZE); if (mirror) { outstream.WriteInt(updatelength, UPDATELENGTH_BYTE_COUNT_SIZE); } BandwidthUsage.AddUsage(ref bitstream, "DataLength"); //Note the starting pos in stream int bodyPtr = bitstream.ptr; // The start pos for modifying update lenght for mirror int mirrorBodyPtr = outstream.ptr; XDebug.LogWarning(!XDebug.logWarnings ? null : ("Incoming Update for nstid: " + nstid + " was from a different scene. Ignoring update to avoid data corruption due to different compression settings."), sceneOutOfSync); XDebug.Log(!XDebug.logInfo ? null : //Debug.Log( ("Message for an NST Object " + nstid + " arrived but that object does not exist. (yet/anymore?) This is normal during startup and shutdown."), lastNST == null); /// Skip reading if the target NST doesn't exist, or if this we compressed with a different scene (codec mismatch likely) if (lastNST == null || sceneOutOfSync) { if (sceneOutOfSync) { Debug.LogWarning(frameid + " skipped entirely due to sceneID mismatch"); } // Forward to the next update start in the incoming stream. bitstream.ptr = bodyPtr + (updatelength << 3); // rewind to the EOS marker and pretend this arrival never occured for the outgoing mirror stream. if (mirror) { /// TODO : Rather than jump ahead, Server should bulk copy the ignored data to outstream in case other clients can use it. outstream.ptr = mirrorUpdateStartPtr; } continue; } // Tell this nst to read its mail. updateType may get modified by server receive for things like teleport. Frame frame = lastNST.ReadUpdate(ref bitstream, ref outstream, frameid, isOfftick, updateType, updatelength, sceneIndex, sceneOutOfSync, mirror); updateType = frame.updateType; // overwrite the updateType of the server outgoing in case it has changed. if (mirror) { outstream.WriteIntAtPos((int)updateType, 3, updateBitstreamPos); } //Advance ptr to next update in stream by force, in case the last update wasn't read for any reason (such as the NST leaving the game) bitstream.ptr = bodyPtr + (updatelength << 3); // write the update byte length for the mirror (not the same value as the incoming due to server side adjustments) if (mirror) { int holdPos = outstream.ptr; outstream.ptr = mirrorBodyPtr - UPDATELENGTH_BYTE_COUNT_SIZE; // get the bytesused rounded up. int bytes = ((holdPos - mirrorBodyPtr) >> 3) + (((holdPos - mirrorBodyPtr) % 8 == 0) ? 0 : 1); outstream.WriteInt(bytes, UPDATELENGTH_BYTE_COUNT_SIZE); outstream.ptr = mirrorBodyPtr + (bytes << 3); } } while (safety < 100); /// NST updates are finished - any data to append to the master update can go here IntegrityCheck.ReadCheck(ref bitstream, ref outstream, "End of All Update Reads", mirror); if (!isOfftick) { MasterRTT.Rcv(ref bitstream, ref outstream, mirror, senderId); } BandwidthUsage.AddUsage(ref bitstream, "RTT checks"); // Very last thing... report the bits that were used. This is conditional to the editor only BandwidthUsage.ReportMasterBits(ref bitstream, BandwidthLogType.MasterIn); }
public void OnJoinRoomFailed() { XDebug.LogWarning("Launcher:OnPhotonRandomJoinFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom(null, new RoomOptions() {maxPlayers = 4}, null);"); MasterNetAdapter.PUN_CreateRoom(null, 8); }