/// <summary> /// Create a new game object. /// </summary> static GameObject CreateGameObject(GameObject prefab, BinaryReader reader) { if (prefab != null) { // The first byte is always the type that identifies what kind of data will follow byte type = reader.ReadByte(); if (type == 0) { // Just a plain game object return(Instantiate(prefab) as GameObject); } else { // Custom creation function object[] objs = reader.ReadArray(prefab); object retVal; if (!UnityTools.ExecuteFirst(GetRCCs(), type, out retVal, objs)) { Debug.LogError("[TNet] Failed to call RCC #" + type + ".\nDid you forget to register it in Awake() via TNManager.AddRCCs?"); UnityTools.Clear(objs); return(null); } UnityTools.Clear(objs); if (retVal == null) { Debug.LogError("[TNet] Instantiating \"" + prefab.name + "\" via RCC #" + type + " returned null.\nDid you forget to return the game object from your RCC?"); } return(retVal as GameObject); } } return(null); }