示例#1
0
 public ExternalInfo(string name, string path, ClipboardProceduralObjects selection, bool isWorkshop)
 {
     m_name              = name;
     m_object            = null;
     this.m_filePath     = path;
     this.isWorkshop     = isWorkshop;
     this.m_selection    = selection;
     this.m_externalType = ClipboardProceduralObjects.ClipboardType.Selection;
 }
示例#2
0
        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;
        }
示例#3
0
        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);
        }