// Add a creation to CreationMgr (multi-player) public static CreationData NewCreation(int object_id, ulong res_hash, float rand_seed) { CreationData creation_data = new CreationData(); creation_data.m_ObjectID = object_id; creation_data.m_HashCode = res_hash; creation_data.m_RandomSeed = rand_seed; if (creation_data.LoadRes()) { creation_data.GenCreationAttr(); creation_data.BuildPrefab(); creation_data.Register(); CreationMgr.AddCreation(creation_data); //creation_data.m_Hp = creation_data.m_Attribute.m_Durability; //creation_data.m_Fuel = creation_data.m_Attribute.m_MaxFuel; Debug.Log("new creation succeed !"); creation_data.UpdateUseTime(); return(creation_data); } else { Debug.LogError("creation generate failed."); } return(null); }
// Import content from a byte buffer public static void Import(byte[] buffer) { if (buffer == null) { return; } if (buffer.Length < 8) { return; } Init(); MemoryStream ms = new MemoryStream(buffer); BinaryReader r = new BinaryReader(ms); int version = r.ReadInt32(); if (VERSION != version) { Debug.LogWarning("The version of CreationMgr is newer than the record."); } switch (version) { case 0x2001: { int count = r.ReadInt32(); for (int i = 0; i < count; i++) { CreationData creation_data = new CreationData(); creation_data.m_ObjectID = r.ReadInt32(); creation_data.m_HashCode = r.ReadUInt64(); creation_data.m_RandomSeed = r.ReadSingle(); //creation_data.m_Hp = r.ReadSingle(); //creation_data.m_Fuel = r.ReadSingle(); // if ( creation_data.m_Hp < 0 ) // { // Debug.LogWarning("Creation " + creation_data.m_ObjectID.ToString() + // " had been crashed, will not load any more.."); // continue; // } if (creation_data.LoadRes()) { creation_data.GenCreationAttr(); creation_data.BuildPrefab(); creation_data.Register(); m_Creations.Add(creation_data.m_ObjectID, creation_data); } else { creation_data.Destroy(); creation_data = null; } } break; } default: break; } r.Close(); ms.Close(); }
public static void CopyCretion(int instanceID) { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; CreationData cd = CreationMgr.GetCreation(instanceID); if (null == cd) { return; } new_creation.m_Resource = cd.m_Resource; new_creation.ReadRes(); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return; } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemAsset.ItemObject item; int send_retval = new_creation.SendToPlayer(out item); Debug.Log("Make creation succeed !"); if (send_retval == 0) { return; // Error } else if (send_retval == -1) { return; // Item Package Full } else { return; // Succeed } } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return; } }
void ExportCreation() { if (VCEditor.s_Scene == null || VCEditor.s_Scene.m_IsoData == null) { Debug.Log("VCEditor IsoData is null!"); return; } new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = VCEditor.s_Scene.m_IsoData.Export(); new_creation.ReadRes(); new_creation.GenCreationAttr(); // 计算属性 if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); } else { Debug.Log("Save creation resource file failed !"); new_creation.Destroy(); return; } GameObject obj = CreationMgr.InstantiateCreation(new_creation.m_ObjectID, 0, true, null); if (obj != null) { if (new_creation.m_Attribute.m_Type == ECreation.Vehicle) { obj.transform.localPosition = ExportPosVehicle.position; } if (new_creation.m_Attribute.m_Type == ECreation.Aircraft) { obj.transform.localPosition = ExportPosAircraft.position; } if (new_creation.m_Attribute.m_Type == ECreation.Boat) { obj.transform.localPosition = ExportPosBoat.position; } ZXCameraCtrl ZXCamera = mMainCamera.GetComponent <ZXCameraCtrl>(); ZXCamera.Following = obj.transform; } creation_obj = obj; }
public static void CopyCretion(ECreation type) { Pathea.PlayerPackageCmpt pkg = Pathea.PeCreature.Instance.mainPlayer.GetCmpt <Pathea.PlayerPackageCmpt>(); if (null == pkg) { return; } List <int> creationInstanceid = pkg.package.GetCreationInstanceId(type); if (creationInstanceid == null || creationInstanceid.Count == 0) { return; } CreationData cd = CreationMgr.GetCreation(creationInstanceid[0]); if (Pathea.PeGameMgr.IsMulti) { ulong hash = CRC64.Compute(cd.m_Resource); ulong fileId = SteamWorkShop.GetFileHandle(hash); VCGameMediator.SendIsoDataToServer(cd.m_IsoData.m_HeadInfo.Name, cd.m_IsoData.m_HeadInfo.SteamDesc, cd.m_IsoData.m_HeadInfo.SteamPreview, cd.m_Resource, SteamWorkShop.AddNewVersionTag(cd.m_IsoData.m_HeadInfo.ScenePaths()), true, fileId, true); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = cd.m_Resource; new_creation.ReadRes(); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return; } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemAsset.ItemObject item; int send_retval = new_creation.SendToPlayer(out item); Debug.Log("Make creation succeed !"); if (send_retval == 0) { return; // Error } else if (send_retval == -1) { return; // Item Package Full } else { return; // Succeed } } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return; } } }
public static int MakeCreation(string path) { TextAsset aseet = Resources.Load <TextAsset>(path); VCIsoData iso = new VCIsoData(); iso.Import(aseet.bytes, new VCIsoOption(false)); // Multi player if (s_MultiplayerMode) { if (!VCConfig.s_Categories.ContainsKey(iso.m_HeadInfo.Category)) { return(-1); } byte[] isodata = iso.Export(); if (isodata == null || isodata.Length <= 0) { return(-1); } ulong hash = CRC64.Compute(isodata); ulong fileId = SteamWorkShop.GetFileHandle(hash); VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc, iso.m_HeadInfo.SteamPreview, isodata, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true); return(0); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = iso.Export(); new_creation.ReadRes(); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return(-1); } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemAsset.ItemObject item; int send_retval = new_creation.SendToPlayer(out item); Debug.Log("Make creation succeed !"); if (send_retval == 0) { return(-1); // Error } else if (send_retval == -1) { return(-4); // Item Package Full } else { if (OnMakeCreation != null) { OnMakeCreation(); } return(0); // Succeed } } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return(-3); } } }
public static void ExportRandIso(string fullpath, int dungeonId, int index) { if (fullpath == "") { return; } if (!File.Exists(fullpath)) { return; } ulong fileId = DungeonIsos.GetFileId(dungeonId, index); VCIsoData iso = new VCIsoData(); using (FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read)) { byte[] iso_buffer = new byte[(int)(fs.Length)]; fs.Read(iso_buffer, 0, (int)(fs.Length)); fs.Close(); iso.Import(iso_buffer, new VCIsoOption(true)); if (Pathea.PeGameMgr.IsMulti) { ulong hash = CRC64.Compute(iso_buffer); VCGameMediator.SendIsoDataToServer(iso.m_HeadInfo.Name, iso.m_HeadInfo.SteamDesc, iso.m_HeadInfo.SteamPreview, iso_buffer, SteamWorkShop.AddNewVersionTag(iso.m_HeadInfo.ScenePaths()), true, fileId, true); NetworkManager.SyncServer(EPacketType.PT_Common_SendRandIsoHash, dungeonId, index, hash); } else { CreationData new_creation = new CreationData(); new_creation.m_ObjectID = CreationMgr.QueryNewId(); new_creation.m_RandomSeed = UnityEngine.Random.value; new_creation.m_Resource = iso_buffer; new_creation.ReadRes(); ulong hash = CRC64.Compute(iso_buffer); // Attr new_creation.GenCreationAttr(); if (new_creation.m_Attribute.m_Type == ECreation.Null) { Debug.LogWarning("Creation is not a valid type !"); new_creation.Destroy(); return; } // SaveRes if (new_creation.SaveRes()) { new_creation.BuildPrefab(); new_creation.Register(); CreationMgr.AddCreation(new_creation); ItemObject item; new_creation.SendToPlayer(out item, false); Debug.Log("Make creation succeed !"); RandomDungenMgr.Instance.ReceiveIsoObj(dungeonId, hash, item.instanceId); } else { Debug.LogWarning("Save creation resource file failed !"); new_creation.Destroy(); return; } } } }