public static void ConvertRectTransformsRecursive(UnityEngine.RectTransform parent, Entity parentEntity,
                                                          RectTransformToEntity rectTransformToEntity, EntityManager commandBuffer,
                                                          ref DotsUIArchetypes archetypes, ref NativeList <LinkedEntityGroup> linkedGroup, bool isPrefab)
        {
            rectTransformToEntity.Add(parent, parentEntity);
            linkedGroup.Add(parentEntity);
#if UNITY_EDITOR
            commandBuffer.SetName(parentEntity, parent.name);
#endif
            m_PooledRectTransformList.Add(parent);
            int childCount = parent.childCount;
            for (int i = 0; i < childCount; i++)
            {
                if (parent.GetChild(i) is UnityEngine.RectTransform childTransform)
                {
                    //if(!childTransform.gameObject.activeInHierarchy)
                    //    continue;
                    Entity child = commandBuffer.CreateEntity(archetypes.GenericChildArchetype);
                    SetRectTransform(commandBuffer, childTransform, child);
                    commandBuffer.SetComponentData(child, new Parent()
                    {
                        Value = parentEntity
                    });
                    if (isPrefab)
                    {
                        commandBuffer.AddComponent(child, typeof(Prefab));
                    }
                    ConvertRectTransformsRecursive(childTransform, child, rectTransformToEntity, commandBuffer,
                                                   ref archetypes, ref linkedGroup, isPrefab);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Instantiate prefab and fill RectTransform to Entity map
        /// </summary>
        /// <param name="rectTransformToEntity"></param>
        /// <returns></returns>
        public Entity Instantiate(RectTransformToEntity rectTransformToEntity)
        {
            Entity instance      = Instantiate();
            var    prefabGroup   = m_Manager.GetBuffer <LinkedEntityGroup>(m_Root);
            var    instanceGroup = m_Manager.GetBuffer <LinkedEntityGroup>(instance);

            for (int i = 0; i < prefabGroup.Length; i++)
            {
                rectTransformToEntity.Add(m_RectTransformToPrefabEntity[prefabGroup[i].Value], instanceGroup[i].Value);
            }

            return(instance);
        }