public static ContraptionDataset LoadContraptionDataset(string levelName) { #if !UNITY_EDITOR XmlSerializer xmlSerializer = new XmlSerializer(typeof(ContraptionDataset)); ContraptionDataset result = new ContraptionDataset(); string str = WPFPrefs.ContraptionFileName(levelName); string str2 = "ux0:" + Path.DirectorySeparatorChar + "data"; if (!File.Exists(str2 + "/" + str)) { return(new ContraptionDataset()); } try { FileStream fileStream = new FileStream(str2 + "/" + str, FileMode.Open); byte[] array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); byte[] buffer = WPFPrefs.m_crypto.Decrypt(array, 0); MemoryStream stream = new MemoryStream(buffer); result = (xmlSerializer.Deserialize(stream) as ContraptionDataset); fileStream.Close(); } catch { } return(result); #else ContraptionDataset result = new ContraptionDataset(); return(result); #endif }
private void PreBuildContraption(ContraptionDataset cds) { foreach (ContraptionDataset.ContraptionDatasetUnit contraptionDatasetUnit in cds.ContraptionDatasetList) { GameObject part = this.gameData.GetPart((BasePart.PartType)contraptionDatasetUnit.partType); if (part) { BasePart component = part.GetComponent <BasePart>(); BasePart basePart = this.levelManager.BuildPart(contraptionDatasetUnit, component); basePart.m_static = true; this.ContraptionProto.IncreaseStaticPartCount(); } } }
public Contraption CreateContraption(TextAsset contraptionData) { this.m_contraptionData = contraptionData; Vector2 v = base.transform.position; v.x = -5f + -15f * (float)Screen.width / (float)Screen.height; base.transform.position = v; Transform transform = UnityEngine.Object.Instantiate <Transform>(this.m_gameData.m_contraptionPrefab, base.transform.position, Quaternion.identity); transform.parent = base.transform; this.m_contraption = transform.GetComponent <Contraption>(); ContraptionDataset cds = WPFPrefs.LoadContraptionDataset(this.m_contraptionData); this.BuildContraption(cds); this.m_contraption.StartContraption(); this.m_contraption.ActivateAllPoweredParts(); return(this.m_contraption); }
public static void SaveLevelBluePrint(string levelName, ContraptionDataset cds, bool isSuperBlueprint = false, int superBluePrintIndex = 0) { #if !UNITY_EDITOR XmlSerializer xmlSerializer = new XmlSerializer(typeof(ContraptionDataset)); MemoryStream memoryStream = new MemoryStream(); StreamWriter textWriter = new StreamWriter(memoryStream, Encoding.UTF8); xmlSerializer.Serialize(textWriter, cds); byte[] array = memoryStream.ToArray(); memoryStream.Close(); string path = (!isSuperBlueprint) ? "Data/Contraptions" : "Data/SuperContraptions"; string path2 = levelName + "_contraption" + ((!isSuperBlueprint) ? string.Empty : string.Format("_{0:00}", superBluePrintIndex + 1)) + ".xml"; //string path3 = Path.Combine(Application.dataPath, path); //string path4 = Path.Combine(path, path2); FileStream fileStream = new FileStream("ux0:" + Path.DirectorySeparatorChar + "data" + path2, FileMode.Create); fileStream.Write(array, 0, array.Length); fileStream.Close(); #endif }
public static void SaveContraptionDataset(string levelName, ContraptionDataset cds) { #if !UNITY_EDITOR XmlSerializer xmlSerializer = new XmlSerializer(typeof(ContraptionDataset)); MemoryStream memoryStream = new MemoryStream(); StreamWriter textWriter = new StreamWriter(memoryStream, Encoding.UTF8); xmlSerializer.Serialize(textWriter, cds); byte[] clearTextBytes = memoryStream.ToArray(); memoryStream.Close(); byte[] array = WPFPrefs.m_crypto.Encrypt(clearTextBytes); string str = WPFPrefs.ContraptionFileName(levelName); //string text = "ux0:" + Path.DirectorySeparatorChar + "data" + "/contraptions"; //Directory.CreateDirectory(text); FileStream fileStream = new FileStream("ux0:" + Path.DirectorySeparatorChar + "data" + "/" + str, FileMode.Create); fileStream.Write(array, 0, array.Length); fileStream.Close(); #endif }
public void BuildContraption(ContraptionDataset cds) { if (cds == null || cds.ContraptionDatasetList == null) { return; } foreach (ContraptionDataset.ContraptionDatasetUnit contraptionDatasetUnit in cds.ContraptionDatasetList) { ConstructionUI.PartDesc partDesc = this.levelManager.ConstructionUI.FindPartDesc((BasePart.PartType)contraptionDatasetUnit.partType); if (partDesc != null) { BasePart customPart = this.gameData.GetCustomPart(partDesc.part.m_partType, contraptionDatasetUnit.customPartIndex); if (customPart != null) { this.levelManager.BuildPart(contraptionDatasetUnit, customPart); partDesc.useCount++; } } } }
public static ContraptionDataset LoadContraptionDataset(TextAsset textAsset) { #if !UNITY_EDITOR XmlSerializer xmlSerializer = new XmlSerializer(typeof(ContraptionDataset)); ContraptionDataset result = new ContraptionDataset(); try { MemoryStream memoryStream = new MemoryStream(textAsset.bytes); result = (xmlSerializer.Deserialize(memoryStream) as ContraptionDataset); memoryStream.Close(); } catch { } //ContraptionDataset result = new ContraptionDataset(); return(result); #else ContraptionDataset result = new ContraptionDataset(); return(result); #endif }
private void BuildContraption(ContraptionDataset cds) { Dictionary <BasePart.PartType, int> dictionary = new Dictionary <BasePart.PartType, int>(); foreach (ContraptionDataset.ContraptionDatasetUnit contraptionDatasetUnit in cds.ContraptionDatasetList) { BasePart.PartType partType = (BasePart.PartType)contraptionDatasetUnit.partType; List <BasePart> list = new List <BasePart>(this.m_gameData.GetCustomPart(partType).PartList); for (int i = 0; i < list.Count; i++) { if (!list[i].craftable && !list[i].lootCrateReward) { list.RemoveAt(i--); } } BasePart basePart; if (dictionary.ContainsKey(partType)) { basePart = ((dictionary[partType] != -1) ? list[dictionary[partType]] : this.m_gameData.GetPart(partType).GetComponent <BasePart>()); } else if (UnityEngine.Random.Range(0, 100) > 50 && list.Count > 0) { int num = UnityEngine.Random.Range(0, list.Count); basePart = list[num]; dictionary.Add(partType, num); } else { basePart = this.m_gameData.GetPart(partType).GetComponent <BasePart>(); dictionary.Add(partType, -1); } if (contraptionDatasetUnit == null) { } if (basePart == null) { } this.BuildPart(contraptionDatasetUnit, basePart); } }