/// <summary>
        /// Create a gameobject in the GroupDesigner that can be used to track location and size
        /// of SubGroups. Currently it assumes they are spawned from a Object Path in the parent
        /// Clearing Group. The LBPrefabItem component type may need to be changed for subgroups
        /// not created from an Object Path.
        /// </summary>
        /// <param name="parentTfrm"></param>
        /// <param name="parentGroup"></param>
        /// <param name="parentGroupMember"></param>
        /// <param name="subGroup"></param>
        /// <param name="subGroupPosition"></param>
        /// <param name="subGroupRotation"></param>
        /// <param name="subGroupRadius"></param>
        /// <param name="regionIdx"></param>
        /// <returns></returns>
        public static LBGroupDesignerItem CreateSubGroupItem(Transform parentTfrm, LBGroup parentGroup, LBGroupMember parentGroupMember, LBGroup subGroup, Vector3 subGroupPosition, Vector3 subGroupRotation, float subGroupRadius, int regionIdx)
        {
            LBGroupDesignerItem lbGroupDesignerItem = null;

            if (parentGroup != null && parentTfrm != null && subGroup != null)
            {
                // [DESIGNER] (parentGroupName.subgroup:subGroupName.regionnumber)
                GameObject subGroupGO = new GameObject("[DESIGNER] (" + (string.IsNullOrEmpty(parentGroup.groupName) ? "ParentGroup" : parentGroup.groupName) + ".subgroup:" + (string.IsNullOrEmpty(subGroup.groupName) ? "SubGroup" : subGroup.groupName) + "." + (regionIdx + 1) + ")");

                if (subGroupGO != null)
                {
                    Quaternion rotation = Quaternion.Euler(subGroupRotation);
                    subGroupGO.transform.SetPositionAndRotation(subGroupPosition, rotation);
                    subGroupGO.transform.SetParent(parentTfrm);
                    lbGroupDesignerItem = subGroupGO.AddComponent <LBGroupDesignerItem>();
                    if (lbGroupDesignerItem != null)
                    {
                        lbGroupDesignerItem.isSubGroup     = true;
                        lbGroupDesignerItem.SubGroupGUID   = subGroup == null ? string.Empty : subGroup.GUID;
                        lbGroupDesignerItem.position       = subGroupPosition;
                        lbGroupDesignerItem.rotation       = rotation;
                        lbGroupDesignerItem.subGroupRadius = subGroupRadius;
                        lbGroupDesignerItem.FindGroupDesigner();

                        if (parentGroupMember != null)
                        {
                            lbGroupDesignerItem.objPathGroupMemberGUID = parentGroupMember.GUID;
                            lbGroupDesignerItem.isObjPathMember        = parentGroupMember.lbMemberType == LBGroupMember.LBMemberType.ObjPath;
                        }
                        else
                        {
                            lbGroupDesignerItem.objPathGroupMemberGUID = string.Empty;
                            lbGroupDesignerItem.isObjPathMember        = false;
                        }
                    }

                    LBPrefabItem lbPrefabItem = subGroupGO.AddComponent <LBPrefabItem>();
                    if (lbPrefabItem != null)
                    {
                        lbPrefabItem.prefabItemType = LBPrefabItem.PrefabItemType.ObjPathDesignerPrefab;
                        // Add the GUID of the object path GroupMember so that we can track them in the scene
                        // It lets us enable/disable existing prefabs when using the Object Path Designer
                        // If this Group is being spawned from a parent group, assign the member GUID from that parent instead
                        // of using the current member GUID. This ensures that the Designers can disable and enable the correct gameobject
                        // for subgroups.
                        lbPrefabItem.groupMemberGUID = parentGroupMember != null ? parentGroupMember.GUID : subGroup.GUID;
                    }
                }
            }

            return(lbGroupDesignerItem);
        }
Esempio n. 2
0
        private void OnEnable()
        {
            lbGroupDesignerItem = (LBGroupDesignerItem)target;
            if (lbGroupDesignerItem != null)
            {
                lbGroupDesignerItem.position = lbGroupDesignerItem.transform.position;
                lbGroupDesignerItem.rotation = lbGroupDesignerItem.transform.rotation;
                lbGroupDesignerItem.scale    = lbGroupDesignerItem.transform.localScale;

                // Get a reference to the group from the designer.
                if (lbGroupDesignerItem.lbGroupDesigner != null)
                {
                    lbGroup = lbGroupDesignerItem.lbGroupDesigner.lbGroup;
                }

                prevPosition = lbGroupDesignerItem.position;
            }
        }