public void RecreateGroups(Dictionary <CacheProceduralObject, ProceduralObject> createdObjects)
        {
            if (groupInformation == null)
            {
                return;
            }
            if (groupInformation.Count == 0)
            {
                return;
            }

            foreach (var kvp in createdObjects)
            {
                if (!groupInformation.ContainsKey(kvp.Key))
                {
                    continue;
                }

                if (createdObjects[groupInformation[kvp.Key]].group == null)
                {
                    var group = POGroup.CreateGroupWithRoot(createdObjects[groupInformation[kvp.Key]]);
                    ProceduralObjectsLogic.instance.groups.Add(group);
                }
                createdObjects[groupInformation[kvp.Key]].group.AddToGroup(kvp.Value);
            }
        }
Exemple #2
0
        public static POGroup CreateGroupWithRoot(ProceduralObject root)
        {
            var group = new POGroup();

            group.objects.Add(root);
            root.isRootOfGroup = true;
            root.group         = group;
            group.root         = root;
            return(group);
        }
Exemple #3
0
 public static void DeleteGroup(ProceduralObjectsLogic logic, POGroup group)
 {
     foreach (ProceduralObject obj in group.objects)
     {
         logic.moduleManager.DeleteAllModules(obj);
         logic.activeIds.Remove(obj.id);
         logic.proceduralObjects.Remove(obj);
     }
     logic.groups.Remove(group);
 }
 public void MakeSelectionList(List <ProceduralObject> list, POGroup selectedGroup)
 {
     this.selection_objects = new Dictionary <CacheProceduralObject, Vector3>();
     for (int i = 0; i < list.Count; i++)
     {
         var     obj = list[i];
         Vector3 relativePos;
         if (i == 0)
         {
             relativePos = Vector3.zero;
         }
         else
         {
             relativePos = obj.m_position - list[0].m_position;
         }
         var cachePO = new CacheProceduralObject(obj);
         cachePO.temp_id = obj.id;
         cachePO.parent  = -1;
         this.selection_objects.Add(cachePO, relativePos);
     }
     if (selectedGroup != null)
     {
         groupInformation = null;
         return;
     }
     else
     {
         groupInformation = new Dictionary <CacheProceduralObject, CacheProceduralObject>();
         for (int i = 0; i < list.Count; i++)
         {
             var obj = list[i];
             if (obj.group == null)
             {
                 continue;
             }
             if (obj.isRootOfGroup)
             {
                 continue;
             }
             if (!list.Contains(obj.group.root))
             {
                 continue;
             }
             groupInformation.Add(selection_objects.Keys.ToList()[i],
                                  selection_objects.Keys.ToList()[list.IndexOf(obj.group.root)]);
             selection_objects.Keys.ToList()[i].parent = obj.group.root.id;
         }
     }
 }
        public static List <POGroup> BuildGroupsFromData(this ProceduralObjectsLogic logic)
        {
            var poGroups = new List <POGroup>();

            try
            {
                foreach (var po in logic.proceduralObjects)
                {
                    if (po._groupRootIdData == -2)
                    {
                        continue;
                    }
                    if (po._groupRootIdData == -1)
                    {
                        if (po.group == null)
                        {
                            poGroups.Add(POGroup.CreateGroupWithRoot(po));
                        }
                    }
                    else
                    {
                        var root = logic.proceduralObjects.GetObjectWithId(po._groupRootIdData);
                        if (root == null)
                        {
                            Debug.LogWarning("[ProceduralObjects] Object #" + po.id + " was supposed to be part of a group but the root could not be found ! Assigning no group.");
                            continue;
                        }
                        if (root.group == null)
                        {
                            poGroups.Add(POGroup.CreateGroupWithRoot(root));
                        }

                        root.group.AddToGroup(po);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[ProceduralObjects] Error while loading the groups. Skipping all together. " + e);
            }
            return(poGroups);
        }
Exemple #6
0
        public static List <ProceduralObject> ExplodeGroup(ProceduralObjectsLogic logic, POGroup group)
        {
            var list = new List <ProceduralObject>();

            foreach (var obj in group.objects)
            {
                list.Add(obj);
                obj.group         = null;
                obj.isRootOfGroup = false;
            }
            logic.groups.Remove(group);
            return(list);
        }
Exemple #7
0
        public static List <ProceduralObject> AllObjectsInSelection(List <ProceduralObject> selection, POGroup selectedGroup)
        {
            if (selectedGroup != null)
            {
                return(selection);
            }

            var list = new List <ProceduralObject>();

            foreach (var obj in selection)
            {
                if (obj.isRootOfGroup)
                {
                    list.AddRange(obj.group.objects);
                }
                else
                {
                    list.Add(obj);
                }
            }
            return(list);
        }
        public static POGroup ConstructSubBuildings(ProceduralObject obj)
        {
            var logic = ProceduralObjectsLogic.instance;

            if (obj.baseInfoType != "BUILDING")
            {
                return(null);
            }
            var pos = new List <ProceduralObject>();

            pos.Add(obj);
            // Sub buildings
            var subBuildings = obj._baseBuilding.m_subBuildings;

            if (subBuildings.Length >= 1)
            {
                for (int i = 0; i < subBuildings.Length; i++)
                {
                    var subB = subBuildings[i];
                    if (subB == null)
                    {
                        continue;
                    }
                    if (subB.m_buildingInfo == null)
                    {
                        continue;
                    }
                    if (subB.m_buildingInfo.m_mesh == null)
                    {
                        continue;
                    }
                    if (!subB.m_buildingInfo.m_mesh.isReadable)
                    {
                        continue;
                    }
                    int id = 0;
                    try
                    {
                        ProceduralObject sub = new ProceduralObject();
                        id = logic.proceduralObjects.GetNextUnusedId();
                        sub.ConstructObject(subB.m_buildingInfo, id);
                        float a = -(subB.m_angle * Mathf.Rad2Deg) % 360f;
                        if (a < 0)
                        {
                            a += 360f;
                        }
                        sub.m_rotation = Quaternion.Euler(sub.m_rotation.eulerAngles.x, a, sub.m_rotation.eulerAngles.z) * obj.m_rotation;
                        sub.m_position = VertexUtils.RotatePointAroundPivot(subB.m_position + obj.m_position, obj.m_position, obj.m_rotation);
                        pos.Add(sub);
                        logic.proceduralObjects.Add(sub);
                    }
                    catch
                    {
                        if (id != 0)
                        {
                            if (logic.activeIds.Contains(id))
                            {
                                logic.activeIds.Remove(id);
                            }
                        }
                    }
                }
            }
            if (pos.Count < 2)
            {
                return(null);
            }
            var group = POGroup.MakeGroup(logic, pos, pos[0]);

            return(group);
        }