private void createSelectionClipboard() { var fileLines = File.ReadAllLines(m_filePath); Dictionary <CacheProceduralObject, Vector3> objects = new Dictionary <CacheProceduralObject, Vector3>(); CacheProceduralObject obj = null; Vector3 relativePos = Vector3.zero; var modulesData = new List <Dictionary <string, string> >(); Dictionary <string, string> currentModuleData = null; string name = ""; for (int i = 0; i < fileLines.Count(); i++) { try { if (currentModuleData != null) { if (fileLines[i].Contains("{")) { continue; } else if (fileLines[i].Contains("}")) { modulesData.Add(currentModuleData); currentModuleData = null; continue; } else if (fileLines[i].Contains(" = ")) { currentModuleData.Add(fileLines[i].GetUntilOrEmpty(" = ").Trim(), fileLines[i].GetStringAfter(" = ").Trim()); } continue; } else if (fileLines[i].Contains("name = ")) { name = fileLines[i].Replace("name = ", "").Trim(); } else if (fileLines[i].Contains("{")) { obj = new CacheProceduralObject(); obj.tilingFactor = 8; obj.m_color = Color.white; obj.parent = -1; obj.meshStatus = 2; relativePos = Vector3.zero; modulesData = new List <Dictionary <string, string> >(); } else if (fileLines[i].Contains("}")) { obj.modules = ModuleManager.LoadModulesFromData(modulesData, false, null); objects[obj] = relativePos; modulesData = null; obj = null; relativePos = Vector3.zero; } else if (fileLines[i].Contains("baseInfoType = ")) { obj.baseInfoType = fileLines[i].Replace("baseInfoType = ", ""); } else if (fileLines[i].Contains("basePrefabName = ")) { obj.basePrefabName = fileLines[i].Replace("basePrefabName = ", ""); } else if (fileLines[i].Contains("relativePosition = ")) { relativePos = fileLines[i].Replace("relativePosition = ", "").ParseVector3(); } else if (fileLines[i].Contains("absPosition = ")) { obj._staticPos = fileLines[i].Replace("absPosition = ", "").ParseVector3(); } else if (fileLines[i].Contains("renderDistance = ")) { obj.renderDistance = float.Parse(fileLines[i].Replace("renderDistance = ", "")); } else if (fileLines[i].Contains("renderDistLocked = ")) { obj.renderDistLocked = bool.Parse(fileLines[i].Replace("renderDistLocked = ", "")); } else if (fileLines[i].Contains("isPloppableAsphalt = ")) { obj.isPloppableAsphalt = bool.Parse(fileLines[i].Replace("isPloppableAsphalt = ", "")); } else if (fileLines[i].Contains("rotation = ")) { obj.m_rotation = VertexUtils.ParseQuaternion(fileLines[i].Replace("rotation = ", "")); } else if (fileLines[i].Contains("disableRecalculation = ")) { obj.disableRecalculation = bool.Parse(fileLines[i].Replace("disableRecalculation = ", "")); } else if (fileLines[i].Contains("tilingFactor = ")) { obj.tilingFactor = int.Parse(fileLines[i].Replace("tilingFactor = ", "")); } else if (fileLines[i].Contains("parenting = ")) { var splited = fileLines[i].Replace("parenting = ", "").Trim().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); obj.temp_id = int.Parse(splited[0]); obj.parent = int.Parse(splited[1]); } else if (fileLines[i].Contains("disableRecalculation = ")) { obj.disableRecalculation = bool.Parse(fileLines[i].Replace("disableRecalculation = ", "")); } else if (fileLines[i].Contains("flipFaces = ")) { obj.flipFaces = bool.Parse(fileLines[i].Replace("flipFaces = ", "")); } else if (fileLines[i].Contains("disableCastShadows = ")) { obj.disableCastShadows = bool.Parse(fileLines[i].Replace("disableCastShadows = ", "")); } else if (fileLines[i].Contains("color = ")) { obj.m_color = SerializableColor.Parse(fileLines[i].Replace("color = ", "")); } else if (fileLines[i].Contains("normalsRecalc = ")) { obj.normalsRecalculation = (NormalsRecalculation)Enum.Parse(typeof(NormalsRecalculation), fileLines[i].Replace("normalsRecalc = ", ""), true); } else if (fileLines[i].Contains("visibility = ")) { obj.visibility = (ProceduralObjectVisibility)Enum.Parse(typeof(ProceduralObjectVisibility), fileLines[i].Replace("visibility = ", ""), true); } else if (fileLines[i].Contains("textParam: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseText(fileLines[i], FontManager.instance)); } else if (fileLines[i].Contains("colorRect: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseColorRect(fileLines[i])); } else if (fileLines[i].Contains("customTexture = ")) { obj.customTexture = TextureManager.instance.FindTexture(fileLines[i].Replace("customTexture = ", "")); /* * if (fileLines[i].Replace("customTexture = ", "") == "null") * obj.customTexture = null; * else if (!availableTextures.Any(tex => tex.name == fileLines[i].Replace("customTexture = ", ""))) * Debug.LogError("[ProceduralObjects] A saved object was found with a texture that doesn't exist anymore with the name " + fileLines[i].Replace("customTexture = ", "") + ", therefore loading the default object texture"); * else * obj.customTexture = availableTextures.FirstOrDefault(tex => tex.name == fileLines[i].Replace("customTexture = ", "")); */ } else if (fileLines[i].Contains("ORIGINALMODEL")) { obj.meshStatus = 1; } else if (fileLines[i].Contains("MODULE")) { try { if (fileLines[i + 1].Contains("{")) { currentModuleData = new Dictionary <string, string>(); } } catch { continue; } } else if (fileLines[i].Contains("VERTICES ")) { obj.allVertices = new Vector3[int.Parse(fileLines[i].Replace("VERTICES ", ""))]; } else if (fileLines[i].Contains("vertex")) { string[] split = fileLines[i].Replace("vertex ", "").Split(new string[] { " = " }, StringSplitOptions.RemoveEmptyEntries); obj.allVertices[int.Parse(split[0])] = VertexUtils.ParseVector3(split[1]); } } catch { Debug.LogError("[ProceduralObjects] Error while loading an object from export at path : " + m_filePath); } } ClipboardProceduralObjects selec = new ClipboardProceduralObjects(ClipboardProceduralObjects.ClipboardType.Selection); selec.selection_objects = objects; var groupInfo = new Dictionary <CacheProceduralObject, CacheProceduralObject>(); var objlist = objects.Keys.ToList(); foreach (var o in objlist) { if (o.parent == -1) { continue; } try { var parent = objlist.First(po => po.temp_id == o.parent); groupInfo.Add(o, parent); } catch { continue; } } if (groupInfo.Count > 0) { selec.groupInformation = groupInfo; } this.m_name = name; this.m_selection = selec; this.m_externalType = ClipboardProceduralObjects.ClipboardType.Selection; }
private void LoadSelectionExternal(string[] fileLines, string path, List <Texture2D> availableTextures, bool fromWorkshop, FontManager fManager) { Dictionary <CacheProceduralObject, Vector3> objects = new Dictionary <CacheProceduralObject, Vector3>(); CacheProceduralObject obj = null; Vector3 relativePos = Vector3.zero; string name = ""; for (int i = 0; i < fileLines.Count(); i++) { if (fileLines[i].Contains("name = ")) { name = fileLines[i].Replace("name = ", "").Trim(); } else if (fileLines[i].Contains("{")) { obj = new CacheProceduralObject(); obj.tilingFactor = 8; relativePos = Vector3.zero; } else if (fileLines[i].Contains("}")) { objects[obj] = relativePos; obj = null; relativePos = Vector3.zero; } else if (fileLines[i].Contains("baseInfoType = ")) { obj.baseInfoType = fileLines[i].Replace("baseInfoType = ", ""); } else if (fileLines[i].Contains("basePrefabName = ")) { obj.basePrefabName = fileLines[i].Replace("basePrefabName = ", ""); } else if (fileLines[i].Contains("relativePosition = ")) { relativePos = fileLines[i].Replace("relativePosition = ", "").ParseVector3(); } else if (fileLines[i].Contains("renderDistance = ")) { obj.renderDistance = float.Parse(fileLines[i].Replace("renderDistance = ", "")); } // else if (lines[i].Contains("scale = ")) // obj.scale = float.Parse(lines[i].Replace("scale = ", "")); else if (fileLines[i].Contains("isPloppableAsphalt = ")) { obj.isPloppableAsphalt = bool.Parse(fileLines[i].Replace("isPloppableAsphalt = ", "")); } else if (fileLines[i].Contains("rotation = ")) { obj.m_rotation = VertexUtils.ParseQuaternion(fileLines[i].Replace("rotation = ", "")); } else if (fileLines[i].Contains("disableRecalculation = ")) { obj.disableRecalculation = bool.Parse(fileLines[i].Replace("disableRecalculation = ", "")); } else if (fileLines[i].Contains("tilingFactor = ")) { obj.tilingFactor = int.Parse(fileLines[i].Replace("tilingFactor = ", "")); } else if (fileLines[i].Contains("textParam: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseText(fileLines[i], fManager)); } else if (fileLines[i].Contains("colorRect: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseColorRect(fileLines[i])); } else if (fileLines[i].Contains("customTexture = ")) { if (fileLines[i].Replace("customTexture = ", "") == "null") { obj.customTexture = null; } else if (!availableTextures.Any(tex => tex.name == fileLines[i].Replace("customTexture = ", ""))) { Debug.LogError("[ProceduralObjects] A saved object was found with a texture that doesn't exist anymore with the name " + fileLines[i].Replace("customTexture = ", "") + ", therefore loading the default object texture"); } else { obj.customTexture = availableTextures.FirstOrDefault(tex => tex.name == fileLines[i].Replace("customTexture = ", "")); } } else if (fileLines[i].Contains("VERTICES ")) { obj.allVertices = new Vector3[int.Parse(fileLines[i].Replace("VERTICES ", ""))]; } else if (fileLines[i].Contains("vertex")) { string[] split = fileLines[i].Replace("vertex ", "").Split(new string[] { " = " }, StringSplitOptions.RemoveEmptyEntries); obj.allVertices[int.Parse(split[0])] = VertexUtils.ParseVector3(split[1]); } } ClipboardProceduralObjects selec = new ClipboardProceduralObjects(ClipboardProceduralObjects.ClipboardType.Selection); selec.selection_objects = objects; ExternalInfo info = new ExternalInfo(name, path, selec, fromWorkshop); m_externals.Add(info); }
private void createSingleClipboard() { var lines = File.ReadAllLines(m_filePath); CacheProceduralObject obj = new CacheProceduralObject(); try { obj.tilingFactor = 8; obj.m_color = Color.white; string name = ""; var modulesData = new List <Dictionary <string, string> >(); Dictionary <string, string> currentModuleData = null; bool original = lines.Any(s => s.Contains("ORIGINALMODEL")); if (original) { obj.meshStatus = 1; } else { obj.meshStatus = 2; } for (int i = 0; i < lines.Count(); i++) { if (currentModuleData != null) { if (lines[i].Contains("{")) { continue; } else if (lines[i].Contains("}")) { modulesData.Add(currentModuleData); currentModuleData = null; continue; } else if (lines[i].Contains(" = ")) { currentModuleData.Add(lines[i].GetUntilOrEmpty(" = ").Trim(), lines[i].GetStringAfter(" = ").Trim()); } } if (lines[i].Contains("name = ")) { name = lines[i].Replace("name = ", "").Trim(); } else if (lines[i].Contains("baseInfoType = ")) { obj.baseInfoType = lines[i].Replace("baseInfoType = ", ""); } else if (lines[i].Contains("basePrefabName = ")) { obj.basePrefabName = lines[i].Replace("basePrefabName = ", ""); } else if (lines[i].Contains("renderDistance = ")) { obj.renderDistance = float.Parse(lines[i].Replace("renderDistance = ", "")); } else if (lines[i].Contains("renderDistLocked = ")) { obj.renderDistLocked = bool.Parse(lines[i].Replace("renderDistLocked = ", "")); } // else if (lines[i].Contains("scale = ")) // obj.scale = float.Parse(lines[i].Replace("scale = ", "")); else if (lines[i].Contains("isPloppableAsphalt = ")) { obj.isPloppableAsphalt = bool.Parse(lines[i].Replace("isPloppableAsphalt = ", "")); } else if (lines[i].Contains("tilingFactor = ")) { obj.tilingFactor = int.Parse(lines[i].Replace("tilingFactor = ", "")); } else if (lines[i].Contains("rotation = ")) { obj.m_rotation = VertexUtils.ParseQuaternion(lines[i].Replace("rotation = ", "")); } else if (lines[i].Contains("disableRecalculation = ")) { obj.disableRecalculation = bool.Parse(lines[i].Replace("disableRecalculation = ", "")); } else if (lines[i].Contains("color = ")) { obj.m_color = SerializableColor.Parse(lines[i].Replace("color = ", "")); } else if (lines[i].Contains("flipFaces = ")) { obj.flipFaces = bool.Parse(lines[i].Replace("flipFaces = ", "")); } else if (lines[i].Contains("disableCastShadows = ")) { obj.disableCastShadows = bool.Parse(lines[i].Replace("disableCastShadows = ", "")); } else if (lines[i].Contains("normalsRecalc = ")) { obj.normalsRecalculation = (NormalsRecalculation)Enum.Parse(typeof(NormalsRecalculation), lines[i].Replace("normalsRecalc = ", ""), true); } else if (lines[i].Contains("visibility = ")) { obj.visibility = (ProceduralObjectVisibility)Enum.Parse(typeof(ProceduralObjectVisibility), lines[i].Replace("visibility = ", ""), true); } else if (lines[i].Contains("customTexture = ")) { obj.customTexture = TextureManager.instance.FindTexture(lines[i].Replace("customTexture = ", "")); /* * if (lines[i].Replace("customTexture = ", "") == "null") * obj.customTexture = null; * else if (!availableTextures.Any(tex => tex.name == lines[i].Replace("customTexture = ", ""))) * Debug.LogError("[ProceduralObjects] A saved object was found with a texture that doesn't exist anymore with the name " + lines[i].Replace("customTexture = ", "") + ", therefore loading the default object texture"); * else * obj.customTexture = availableTextures.FirstOrDefault(tex => tex.name == lines[i].Replace("customTexture = ", "")); */ } else if (lines[i].Contains("textParam: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseText(lines[i], FontManager.instance)); } else if (lines[i].Contains("colorRect: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseColorRect(lines[i])); } else if (lines[i].Contains("MODULE")) { try { if (lines[i + 1].Contains("{")) { currentModuleData = new Dictionary <string, string>(); } } catch { continue; } } else if (!original) { if (lines[i].Contains("VERTICES ")) { obj.allVertices = new Vector3[int.Parse(lines[i].Replace("VERTICES ", ""))]; } else if (lines[i].Contains("vertex")) { string[] split = lines[i].Replace("vertex ", "").Split(new string[] { " = " }, StringSplitOptions.RemoveEmptyEntries); obj.allVertices[int.Parse(split[0])] = VertexUtils.ParseVector3(split[1]); } } } obj.modules = ModuleManager.LoadModulesFromData(modulesData, false, null); } catch { Debug.LogError("[ProceduralObjects] Couldn't load an External Procedural Object : Invalid, corrupted or edited file at path : " + m_filePath); } this.m_externalType = ClipboardProceduralObjects.ClipboardType.Single; this.m_object = obj; }
private void LoadOneExternal(string path, List <Texture2D> availableTextures, bool fromWorkshop, FontManager fManager) { try { var lines = File.ReadAllLines(path); if (lines.Any(line => line.Contains("externaltype = selection"))) { LoadSelectionExternal(lines, path, availableTextures, fromWorkshop, fManager); } else { CacheProceduralObject obj = new CacheProceduralObject(); obj.tilingFactor = 8; string name = ""; for (int i = 0; i < lines.Count(); i++) { if (lines[i].Contains("name = ")) { name = lines[i].Replace("name = ", "").Trim(); } else if (lines[i].Contains("baseInfoType = ")) { obj.baseInfoType = lines[i].Replace("baseInfoType = ", ""); } else if (lines[i].Contains("basePrefabName = ")) { obj.basePrefabName = lines[i].Replace("basePrefabName = ", ""); } else if (lines[i].Contains("renderDistance = ")) { obj.renderDistance = float.Parse(lines[i].Replace("renderDistance = ", "")); } // else if (lines[i].Contains("scale = ")) // obj.scale = float.Parse(lines[i].Replace("scale = ", "")); else if (lines[i].Contains("isPloppableAsphalt = ")) { obj.isPloppableAsphalt = bool.Parse(lines[i].Replace("isPloppableAsphalt = ", "")); } else if (lines[i].Contains("tilingFactor = ")) { obj.tilingFactor = int.Parse(lines[i].Replace("tilingFactor = ", "")); } else if (lines[i].Contains("rotation = ")) { obj.m_rotation = VertexUtils.ParseQuaternion(lines[i].Replace("rotation = ", "")); } else if (lines[i].Contains("disableRecalculation = ")) { obj.disableRecalculation = bool.Parse(lines[i].Replace("disableRecalculation = ", "")); } else if (lines[i].Contains("customTexture = ")) { if (lines[i].Replace("customTexture = ", "") == "null") { obj.customTexture = null; } else if (!availableTextures.Any(tex => tex.name == lines[i].Replace("customTexture = ", ""))) { Debug.LogError("[ProceduralObjects] A saved object was found with a texture that doesn't exist anymore with the name " + lines[i].Replace("customTexture = ", "") + ", therefore loading the default object texture"); } else { obj.customTexture = availableTextures.FirstOrDefault(tex => tex.name == lines[i].Replace("customTexture = ", "")); } } else if (lines[i].Contains("textParam: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseText(lines[i], fManager)); } else if (lines[i].Contains("colorRect: ")) { if (obj.textParam == null) { obj.textParam = new TextParameters(); } obj.textParam.AddField(TextField.ParseColorRect(lines[i])); } else if (lines[i].Contains("VERTICES ")) { obj.allVertices = new Vector3[int.Parse(lines[i].Replace("VERTICES ", ""))]; } else if (lines[i].Contains("vertex")) { string[] split = lines[i].Replace("vertex ", "").Split(new string[] { " = " }, StringSplitOptions.RemoveEmptyEntries); obj.allVertices[int.Parse(split[0])] = VertexUtils.ParseVector3(split[1]); } } ExternalInfo info = new ExternalInfo(name, path, obj, fromWorkshop); m_externals.Add(info); } } catch { Debug.LogError("[ProceduralObjects] Couldn't load an External Procedural Object : Invalid, corrupted or edited file at path : " + path); } }