示例#1
0
        private void SetUpScreenSpaceCamera(Canvas canvas, Entity entity)
        {
            if (canvas.worldCamera == null)
            {
                throw new InvalidOperationException($"Target camera is null or destroyed. Canvas {canvas}");
            }
            var proxy = canvas.worldCamera.GetComponent <CameraImageRenderProxy>();

            if (proxy == null)
            {
                proxy = canvas.worldCamera.gameObject.AddComponent <CameraImageRenderProxy>();
            }
            DstEntityManager.AddSharedComponentData(entity, new CanvasTargetCamera()
            {
                Target = proxy
            });
            DstEntityManager.AddComponentData(entity, new CanvasScreenSize
            {
                Value = new int2(canvas.worldCamera.pixelWidth, canvas.worldCamera.pixelHeight)
            });
        }
        protected void ConvertSelectable(Selectable selectable)
        {
            var entity = GetPrimaryEntity(selectable);

            DstEntityManager.AddComponent(entity, typeof(Input.Selectable));
            var    colors = selectable.colors;
            Entity target = TryGetPrimaryEntity(selectable.targetGraphic);

            DstEntityManager.AddComponentData(entity, new Input.SelectableColor()
            {
                Normal         = colors.normalColor.ToFloat4(),
                Hover          = colors.highlightedColor.ToFloat4(),
                Pressed        = colors.pressedColor.ToFloat4(),
                Selected       = colors.selectedColor.ToFloat4(),
                Disabled       = colors.disabledColor.ToFloat4(),
                TransitionTime = colors.fadeDuration,
                Target         = target
            });

            RegisterEventHandler(entity, Input.PointerEventType.SelectableGroup);
        }
示例#3
0
        protected override void OnUpdate()
        {
            Entities
            .WithNone(typeof(UnityEngine.Canvas))
            .ForEach((UnityEngine.UI.Toggle utoggle, UnityEngine.RectTransform urc) =>
            {
                var toggleEntity         = GetPrimaryEntity(utoggle);
                var baseGraphicEntity    = GetPrimaryEntity(utoggle.targetGraphic);
                var toggledGraphicEntity = GetPrimaryEntity(utoggle.graphic);

                DstEntityManager.AddComponentData(toggleEntity, new Toggleable
                {
                    IsToggled      = utoggle.isOn,
                    ToggledGraphic = toggledGraphicEntity
                });

                var buttonColors = utoggle.colors;
                DstEntityManager.AddComponentData(toggleEntity, new Selectable
                {
                    Graphic          = baseGraphicEntity,
                    IsInteractable   = utoggle.IsInteractable(),
                    NormalColor      = buttonColors.normalColor.linear.ToTiny(),
                    HighlightedColor = buttonColors.highlightedColor.linear.ToTiny(),
                    PressedColor     = buttonColors.pressedColor.linear.ToTiny(),
                    SelectedColor    = buttonColors.selectedColor.linear.ToTiny(),
                    DisabledColor    = buttonColors.disabledColor.linear.ToTiny(),
                });

                var uiName = new UIName()
                {
                    Name = utoggle.name
                };
                DstEntityManager.AddComponentData(toggleEntity, uiName);
                if (utoggle.name.Length > uiName.Name.Capacity)
                {
                    Debug.LogWarning($"UIName '{utoggle.name}' is too long and is being truncated. It may not be found correctly at runtime.");
                }
                DstEntityManager.AddComponent <UIState>(toggleEntity);
            });
        }
示例#4
0
        void GetInputDataFromAuthoringComponent(T shape)
        {
            if (!ShouldConvertShape(shape))
            {
                return;
            }

            var body = GetPrimaryBody(shape);

            var instance = new ColliderInstance
            {
                AuthoringComponentId = shape.GetInstanceID(),
                BodyEntity           = GetPrimaryEntity(body),
                ShapeEntity          = GetPrimaryEntity(shape),
                BodyFromShape        = ColliderInstance.GetCompoundFromChild(shape.transform, body.transform)
            };

            var data = GenerateComputationData(shape, instance, m_ConvexColliderPoints, m_MeshColliderVertices, m_MeshColliderTriangles);

            data.Instance.ConvertedAuthoringComponentIndex = m_EndColliderConversionSystem.PushAuthoringComponent(shape);
            data.Instance.ConvertedBodyTransformIndex      = m_EndColliderConversionSystem.PushAuthoringComponent(body.transform);
            m_ShapeComputationData.Add(data);

            if (BlobComputationContext.NeedToComputeBlobAsset(data.Instance.Hash))
            {
                if (data.ShapeType == ShapeType.ConvexHull)
                {
                    m_ConvexColliderJobs.TryAdd(data.Instance.Hash, data.ConvexHullProperties);
                }
                else if (data.ShapeType == ShapeType.Mesh)
                {
                    m_MeshColliderJobs.TryAdd(data.Instance.Hash, data.MeshProperties);
                }
            }

            if (body == shape.gameObject)
            {
                DstEntityManager.PostProcessTransformComponents(instance.BodyEntity, body.transform, BodyMotionType.Static);
            }
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((TextRenderer displayText) =>
            {
                var textEntity = GetPrimaryEntity(displayText);

                var fontAsset = GetPrimaryEntity(displayText.Font);
                DstEntityManager.AddComponentData(textEntity, new Text.TextRenderer
                {
                    FontMaterial        = fontAsset,
                    MeshColor           = displayText.Color.linear.ToTiny(),
                    Size                = displayText.Size,
                    HorizontalAlignment = displayText.Alignment
                });
                DstEntityManager.AddComponentData(textEntity, new Unity.Tiny.Rendering.CameraMask {
                    mask = (ulong)(1 << displayText.gameObject.layer)
                });

                var text = displayText.Text;
                DstEntityManager.AddBufferFromString <TextRendererString>(textEntity, text);
            });
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((RectTransform transform) => {
                var entity = GetPrimaryEntity(transform);

                // Add anchoring if the min max anchors are equal (e.g. one of the presets)
                if (transform.anchorMin == transform.anchorMax)
                {
                    // Adding the anchors - which is taking the anchored position
                    DstEntityManager.AddComponentData(entity, new Anchor {
                        Distance = transform.anchoredPosition,
                        State    = transform.ToAnchor()
                    });
                }
                else
                {
                    DstEntityManager.AddComponentData(entity, new Stretch {
                        Value = StretchedState.StretchXY
                    });
                }
            });
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.MeshRenderer uMeshRenderer) =>
            {
                MeshFilter uMeshfilter = uMeshRenderer.gameObject.GetComponent <MeshFilter>();
                UnityEngine.Mesh uMesh = uMeshfilter.sharedMesh;
                var meshEntity         = GetPrimaryEntity(uMesh);

                var mrEntity  = GetPrimaryEntity(uMeshRenderer);
                var matEntity = DstEntityManager.GetComponentData <Unity.Tiny.Rendering.MeshRenderer>(mrEntity).material;

                //Add empty MeshRenderData component that will be filled by the mesh conversion.
                if (DstEntityManager.HasComponent <SimpleMaterial>(matEntity))
                {
                    DstEntityManager.AddComponent <SimpleMeshRenderData>(meshEntity);
                }
                else if (DstEntityManager.HasComponent <LitMaterial>(matEntity))
                {
                    DstEntityManager.AddComponent <LitMeshRenderData>(meshEntity);
                }
            });
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.SpriteRenderer uSpriteRenderer) =>
            {
                var entity = GetPrimaryEntity(uSpriteRenderer);

                DstEntityManager.SetName(entity, "SpriteRenderer: " + uSpriteRenderer.name);

                var uWorldToLocalMatrix = uSpriteRenderer.transform.worldToLocalMatrix;
                var uWorldBounds        = uSpriteRenderer.bounds;
                var localBounds         = new AABB()
                {
                    Center  = uWorldToLocalMatrix.MultiplyPoint(uWorldBounds.center),
                    Extents = uSpriteRenderer.bounds.extents
                };

                var uSortingLayerId = uSpriteRenderer.sortingLayerID;
                var renderingLayer  = uSpriteRenderer.gameObject.layer;
                DstEntityManager.AddComponentData(entity, new Renderer2D()
                {
                    RenderingLayer = renderingLayer,
                    SortingLayer   = (short)UnityEngine.SortingLayer.GetLayerValueFromID(uSortingLayerId),
                    OrderInLayer   = (short)uSpriteRenderer.sortingOrder,
                    Bounds         = localBounds,
                });

                DstEntityManager.AddComponentData(entity, new SpriteRenderer
                {
                    Sprite          = GetPrimaryEntity(uSpriteRenderer.sprite),
                    Material        = GetPrimaryEntity(uSpriteRenderer.sharedMaterial),
                    MaskInteraction = uSpriteRenderer.maskInteraction.ToU2DSpriteMaskInteraction(),
                    Color           = new float4(
                        uSpriteRenderer.color.r,
                        uSpriteRenderer.color.g,
                        uSpriteRenderer.color.b,
                        uSpriteRenderer.color.a),
                });
            });
        }
示例#9
0
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.SkinnedMeshRenderer uSkinnedMeshRenderer) =>
            {
                var sharedMaterials    = uSkinnedMeshRenderer.sharedMaterials;
                UnityEngine.Mesh uMesh = uSkinnedMeshRenderer.sharedMesh;
                var meshEntity         = GetPrimaryEntity(uMesh);

                for (int i = 0; i < uMesh.subMeshCount; i++)
                {
                    Entity targetMaterial = MeshRendererConversion.FindTargetMaterialEntity(this, sharedMaterials, i);
                    ConvertOriginalSubMesh(this, uSkinnedMeshRenderer, uMesh, meshEntity, i, targetMaterial);
                }

                if (DstEntityManager.HasComponent <GPUSkinnedMeshDrawRange>(meshEntity))
                {
                    ConvertGPUSkinnedSubMesh(this, uSkinnedMeshRenderer, uMesh, meshEntity);
                }

                ConvertSkinnedMeshBoneInfoToTransformEntity(this, uSkinnedMeshRenderer);
            });
        }
        public void CopyEntitiesToOtherWorld()
        {
            CreateTestData(out var entity0, 5);
            CreateTestData(out var entity1, 6);

            SrcEntityManager.AddComponentData(entity0, new EcsTestManagedDataEntity("0", entity1));
            SrcEntityManager.AddComponentData(entity1, new Disabled());
            SrcEntityManager.AddComponentData(entity1, new Prefab());

            SrcEntityManager.AddChunkComponentData(SrcEntityManager.UniversalQuery, new EcsTestData2(7));

            using (var srcEntities = new NativeArray <Entity>(new[] { entity0, entity1 }, Allocator.Temp))
                using (var dstEntities = new NativeArray <Entity>(2, Allocator.Temp))
                {
                    // create extra entities to ensure entity id's aren't the same by accident
                    DstEntityManager.CreateEntity();

                    DstEntityManager.CopyEntitiesFrom(SrcEntityManager, srcEntities, dstEntities);

                    TestValues(dstEntities[0], 5, 0);
                    Assert.AreEqual(dstEntities[1], DstEntityManager.GetComponentData <EcsTestManagedDataEntity>(dstEntities[0]).value1);
                    Assert.AreEqual("0", DstEntityManager.GetComponentData <EcsTestManagedDataEntity>(dstEntities[0]).value0);
                    Assert.IsFalse(DstEntityManager.HasComponent <EcsTestManagedDataEntity>(dstEntities[1]));

                    // Prefab & Disabled tag is kept in the clone - this is a copy not instantiate semantic
                    Assert.IsFalse(DstEntityManager.HasComponent <Disabled>(dstEntities[0]));
                    Assert.IsFalse(DstEntityManager.HasComponent <Prefab>(dstEntities[0]));
                    Assert.IsTrue(DstEntityManager.HasComponent <Disabled>(dstEntities[1]));
                    Assert.IsTrue(DstEntityManager.HasComponent <Prefab>(dstEntities[1]));

                    TestValues(dstEntities[1], 6, 0);
                }

            Assert.AreEqual(2, SrcEntityManager.UniversalQuery.CalculateEntityCount());
            Assert.AreEqual(3, DstEntityManager.UniversalQuery.CalculateEntityCount());

            SrcEntityManager.Debug.CheckInternalConsistency();
            DstEntityManager.Debug.CheckInternalConsistency();
        }
示例#11
0
 protected override void OnUpdate()
 {
     Entities.ForEach((UnityEngine.ParticleSystemRenderer uParticleSystemRenderer) =>
     {
         var eParticleSystemRenderer = GetPrimaryEntity(uParticleSystemRenderer);
         UnityEngine.Mesh uMesh      = uParticleSystemRenderer.mesh;
         if (uParticleSystemRenderer.renderMode == ParticleSystemRenderMode.Mesh && uMesh != null)
         {
             var eMesh     = GetPrimaryEntity(uMesh);
             var eMaterial = GetPrimaryEntity(uParticleSystemRenderer.sharedMaterial);
             if (DstEntityManager.HasComponent <LitMaterial>(eMaterial))
             {
                 DstEntityManager.AddComponent <LitMeshRenderData>(eMesh);
                 DstEntityManager.RemoveComponent <SimpleMeshRenderData>(eMesh);
             }
             else if (DstEntityManager.HasComponent <SimpleMaterial>(eMaterial))
             {
                 DstEntityManager.AddComponent <SimpleMeshRenderData>(eMesh);
                 DstEntityManager.RemoveComponent <LitMeshRenderData>(eMesh);
             }
         }
     });
 }
示例#12
0
 protected override void OnUpdate()
 {
     Entities.ForEach((DotsNavPlane plane, DotsNavNavmesh navmesh) =>
     {
         var entity     = GetPrimaryEntity(navmesh);
         navmesh.Entity = entity;
         navmesh.World  = DstEntityManager.World;
         DstEntityManager.AddComponentData(entity, new NavmeshComponent
                                           (
                                               plane.Size,
                                               navmesh.ExpectedVerts,
                                               navmesh.MergePointDistance,
                                               navmesh.CollinearMargin
                                           ));
         DstEntityManager.AddBuffer <DestroyedTriangleElement>(entity);
         DstEntityManager.AddComponentData(entity, new NavmeshDrawComponent
         {
             DrawMode           = navmesh.DrawMode,
             ConstrainedColor   = plane.ConstrainedColor,
             UnconstrainedColor = plane.UnconstrainedColor
         });
     });
 }
示例#13
0
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.AudioClip audioClip) =>
            {
                var entity = GetPrimaryEntity(audioClip);

                AudioClip tinyAudioClip = new AudioClip();
                tinyAudioClip.loadType = (audioClip.loadType == UnityEngine.AudioClipLoadType.CompressedInMemory) ? AudioClipLoadType.CompressedInMemory : AudioClipLoadType.DecompressOnPlay;
                tinyAudioClip.channels = audioClip.channels;
                tinyAudioClip.samples = audioClip.samples;
                tinyAudioClip.frequency = audioClip.frequency;

                DstEntityManager.AddComponentData<AudioClip>(entity, tinyAudioClip);
                DstEntityManager.AddComponent<AudioClipUsage>(entity);
                DstEntityManager.AddBuffer<AudioClipCompressed>(entity);
                DstEntityManager.AddBuffer<AudioClipUncompressed>(entity);
                DstEntityManager.AddComponent<AudioClipLoadFromFile>(entity);

                var exportGuid = GetGuidForAssetExport(audioClip);
                DstEntityManager.AddComponent<AudioClipLoadFromFileAudioFile>(entity);
                DstEntityManager.SetBufferFromString<AudioClipLoadFromFileAudioFile>(entity, "Data/" + exportGuid.ToString());
            });
        }
示例#14
0
        protected override void OnUpdate()
        {
            Entities.ForEach((DotsNavAgent agent) =>
            {
                var entity   = GetPrimaryEntity(agent);
                agent.World  = DstEntityManager.World;
                agent.Entity = entity;
                Assert.IsTrue(agent.Radius > 0, "Radius must be larger than 0");

                DstEntityManager.AddComponentData(entity, new Data.AgentComponent
                {
                    Radius = agent.Radius,
                    State  = AgentState.Inactive
                });

                DstEntityManager.AddComponentData(entity, new AgentDirectionComponent());
                DstEntityManager.AddBuffer <PathSegmentElement>(entity);
                DstEntityManager.AddBuffer <TriangleElement>(entity);
                DstEntityManager.AddComponentData(entity, new AgentDrawComponent {
                    Draw = true
                });
            });
        }
示例#15
0
        private void ConvertParticleLitMaterial(Entity entity, Material uMaterial)
        {
            //Do the conversion
            var     texAlbedo = GetTextureEntity(uMaterial, "_BaseMap");
            var     texMetal  = GetTextureEntity(uMaterial, "_MetallicGlossMap");
            Vector2 textScale = uMaterial.GetTextureScale("_BaseMap");
            Vector2 textTrans = uMaterial.GetTextureOffset("_BaseMap");

            //Check if _Emission shader keyword has been enabled for that material
            float3 emissionColor = new float3(0.0f);

            if (uMaterial.IsKeywordEnabled("_EMISSION"))
            {
                UnityEngine.Color uEmissionColor = uMaterial.GetColor("_EmissionColor").linear;
                emissionColor = new float3(uEmissionColor.r, uEmissionColor.g, uEmissionColor.b);
            }

            UnityEngine.Color baseColor = uMaterial.GetColor("_BaseColor").linear;
            DstEntityManager.AddComponentData <LitMaterial>(entity, new LitMaterial()
            {
                texAlbedoOpacity      = texAlbedo,
                constAlbedo           = new float3(baseColor.r, baseColor.g, baseColor.b),
                constOpacity          = baseColor.a,
                constEmissive         = emissionColor,
                texMetal              = texMetal,
                texNormal             = GetTextureEntity(uMaterial, "_BumpMap"),
                texEmissive           = GetTextureEntity(uMaterial, "_EmissionMap"),
                constMetal            = uMaterial.GetFloat("_Metallic"),
                constSmoothness       = uMaterial.GetFloat("_Smoothness"),
                normalMapZScale       = uMaterial.GetFloat("_BumpScale"),
                twoSided              = IsTwoSided(uMaterial),
                transparent           = uMaterial.GetInt("_Surface") == 1,
                smoothnessAlbedoAlpha = ContainsShaderKeyword(uMaterial, "_SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A"),
                scale  = new float2(textScale[0], textScale[1]),
                offset = AdjustTextureOffset(textTrans, textScale)
            });
        }
示例#16
0
文件: Button.cs 项目: cdwfs/RubyGates
    protected override void OnUpdate()
    {
        Entities.ForEach((Button button, BoxCollider2D box) =>
        {
            var buttonEntity = GetPrimaryEntity(button);

            DstEntityManager.AddComponents(buttonEntity, new ComponentTypes(new ComponentType[]
            {
                typeof(ClickableNode),
                typeof(ToggleCount),
                typeof(IsMouseHovering),
            }));

            // Convert bounding box to ClickableNode
            var bounds    = box.bounds;
            var boundsMin = bounds.min;
            var boundsMax = bounds.max;
            DstEntityManager.SetComponentData(buttonEntity, new ClickableNode
            {
                RectMin = new float2(boundsMin.x, boundsMin.y),
                RectMax = new float2(boundsMax.x, boundsMax.y),
            });

            // redundant, but hey
            DstEntityManager.SetComponentData(buttonEntity, new ToggleCount {
                Value = 0
            });

            if (button.initiallyOn)
            {
                // Set initial NodeOutput
                DstEntityManager.SetComponentData(buttonEntity, new NodeOutput {
                    Value = 1
                });
            }
        });
    }
示例#17
0
        protected override void OnUpdate()
        {
            var bakedAnimationsQuery = DstEntityManager.CreateEntityQuery(new EntityQueryDesc
            {
                All = new[]
                {
                    ComponentType.ReadOnly <BakedAnimationClip>()
                },
                Options = EntityQueryOptions.IncludeDisabled | EntityQueryOptions.IncludePrefab
            });

            var commandBuffer          = new EntityCommandBuffer(Allocator.TempJob);
            var bakedAnimationEntities = bakedAnimationsQuery.ToEntityArray(Allocator.TempJob);

            for (int entityIndex = 0; entityIndex < bakedAnimationEntities.Length; ++entityIndex)
            {
                commandBuffer.DestroyEntity(bakedAnimationEntities[entityIndex]);
            }

            var animationBindingNameQuery = DstEntityManager.CreateEntityQuery(new EntityQueryDesc
            {
                All = new[]
                {
                    ComponentType.ReadOnly <AnimationBindingName>()
                },
                Options = EntityQueryOptions.IncludeDisabled | EntityQueryOptions.IncludePrefab
            });

            commandBuffer.RemoveComponent <AnimationBindingName>(animationBindingNameQuery);

            commandBuffer.Playback(DstEntityManager);
            commandBuffer.Dispose();

            bakedAnimationEntities.Dispose();

            TinyAnimationConversionState.Clear();
        }
示例#18
0
        protected override void OnUpdate()
        {
            Entities.ForEach((SkinnedMeshRenderer renderer) =>
            {
                foreach (var bone in renderer.bones)
                {
                    foreach (var boneEntity in GetEntities(bone))
                    {
                        DstEntityManager.AddComponent <Disabled>(boneEntity);
                    }
                }

                var entity = GetPrimaryEntity(renderer);
                DstEntityManager.AddComponent <KeepTag>(entity);

                var rootEntity = entity;
                do
                {
                    if (!DstEntityManager.HasComponent <Parent>(rootEntity))
                    {
                        DstEntityManager.AddComponent <KeepTag>(rootEntity);
                        if (!rootEntity.Equals(entity))
                        {
                            DstEntityManager.AddComponentData(entity, new Parent {
                                Value = rootEntity
                            });
                        }

                        rootEntity = Entity.Null;
                    }
                    else
                    {
                        rootEntity = DstEntityManager.GetComponentData <Parent>(rootEntity).Value;
                    }
                } while (!rootEntity.Equals(Entity.Null));
            });
        }
示例#19
0
        public void EntityManagerPatcher_ApplyChanges_ChangeAppliesToAllPrefabInstances([Values] bool prefabTag)
        {
            using (var differ = new EntityManagerDiffer(SrcWorld, Allocator.TempJob))
                using (var patcher = new EntityManagerPatcher(DstWorld, Allocator.TempJob))
                {
                    // Create a prefab in the source world.
                    var entityGuid = CreateEntityGuid();
                    var prefab     = SrcEntityManager.CreateEntity();
                    SrcEntityManager.AddComponentData(prefab, entityGuid);
                    SrcEntityManager.AddComponentData(prefab, new EcsTestData());

                    if (prefabTag)
                    {
                        SrcEntityManager.AddComponentData(prefab, new Prefab());
                    }

                    // Sync to the dst world. At this point the dst world will have a single entity.
                    PushChanges(differ, patcher);

                    var dstPrefab = GetEntity(DstEntityManager, entityGuid);

                    // Spawn some more instances of this thing in the dst world.
                    var dstInstance0 = DstEntityManager.Instantiate(dstPrefab);
                    var dstInstance1 = DstEntityManager.Instantiate(dstPrefab);

                    // Mutate the original prefab in the src world.
                    SrcEntityManager.SetComponentData(prefab, new EcsTestData(10));

                    // Sync to the dst world.
                    PushChanges(differ, patcher);

                    // The changes should be propagated to all instances.
                    Assert.AreEqual(10, DstEntityManager.GetComponentData <EcsTestData>(dstPrefab).value);
                    Assert.AreEqual(10, DstEntityManager.GetComponentData <EcsTestData>(dstInstance0).value);
                    Assert.AreEqual(10, DstEntityManager.GetComponentData <EcsTestData>(dstInstance1).value);
                }
        }
        void Convert(Component animationComponent)
        {
            var animationClips = TinyAnimationConversionState.GetAllAnimationClips(animationComponent);

            if (animationClips.Length == 0)
            {
                return;
            }

            var rootGameObject   = animationComponent.gameObject;
            var gameObjectEntity = TryGetPrimaryEntity(rootGameObject);

            if (gameObjectEntity == Entity.Null)
            {
                throw new Exception($"Could not get a conversion entity for {animationComponent.GetType().Name} on {rootGameObject}.");
            }

            DstEntityManager.AddBuffer <TinyAnimationClipRef>(gameObjectEntity);

            foreach (var clip in animationClips)
            {
                Convert(rootGameObject, clip, gameObjectEntity);
            }

            var clipReferences    = DstEntityManager.GetBuffer <TinyAnimationClipRef>(gameObjectEntity);
            var currentClipEntity = clipReferences[0].Value;

            DstEntityManager.AddComponentData(gameObjectEntity, new TinyAnimationPlayer {
                CurrentClip = currentClipEntity, CurrentIndex = 0
            });

            if (PlaysAutomatically(animationComponent))
            {
                DstEntityManager.AddComponent <UpdateAnimationTimeTag>(currentClipEntity);
                DstEntityManager.AddComponent <ApplyAnimationResultTag>(currentClipEntity);
            }
        }
示例#21
0
        private void ConvertTextMeshPro(TextMeshProUGUI tmp)
        {
            var entity    = GetPrimaryEntity(tmp);
            var fontAsset = GetPrimaryEntity(tmp.font);

            //if (tmp.font == null)
            //{
            //    Debug.LogError($"TextMeshProConverter - font asset cannot be null reference. Object: {tmp}", tmp);
            //    return;
            //}

            //if (!TryGetAssetEntity(new LegacyTextFontAsset{ Asset = tmp.font, FontMaterial = tmp.font.material }, out var fontAsset))
            //{
            //    fontAsset = TextUtils.CreateFontAssetFromTmp(DstEntityManager, tmp.font);
            //}

            DstEntityManager.AddComponentData(entity, new TextRenderer()
            {
                Font      = fontAsset,
                Size      = tmp.fontSize,
                Alignment = tmp.alignment,
                Bold      = (tmp.fontStyle & FontStyles.Bold) == FontStyles.Bold,
                Italic    = (tmp.fontStyle & FontStyles.Italic) == FontStyles.Italic
            });
            var textBuffer = DstEntityManager.AddBuffer <TextData>(entity);
            var content    = tmp.text;

            textBuffer.ResizeUninitialized(content.Length);
            unsafe
            {
                fixed(char *textPtr = content)
                UnsafeUtility.MemCpy(textBuffer.GetUnsafePtr(), textPtr, content.Length * sizeof(char));
            }
            DstEntityManager.AddBuffer <ControlVertexData>(entity);
            DstEntityManager.AddBuffer <ControlVertexIndex>(entity);
            DstEntityManager.AddComponent(entity, typeof(RebuildElementMeshFlag));
        }
        protected override void OnUpdate()
        {
            Entities.ForEach((UnityEngine.Camera uCamera) =>
            {
                var entity = GetPrimaryEntity(uCamera);

                var camera             = new Unity.Tiny.Rendering.Camera();
                camera.clearFlags      = uCamera.clearFlags.ToTiny();
                camera.backgroundColor = uCamera.backgroundColor.linear.ToTiny();
                camera.viewportRect    = uCamera.rect.ToTiny();
                camera.fov             = uCamera.orthographic ? uCamera.orthographicSize : uCamera.fieldOfView;
                camera.mode            = uCamera.orthographic ? ProjectionMode.Orthographic : ProjectionMode.Perspective;
                camera.clipZNear       = uCamera.nearClipPlane;
                camera.clipZFar        = uCamera.farClipPlane;
                camera.aspect          = (float)1920 / (float)1080; //fixed for now
                DstEntityManager.AddComponentData(entity, camera);

                // For CameraSettings2D
                float3 customSortAxisSetting = new float3(0, 0, 1.0f);
                if (UnityEngine.Rendering.GraphicsSettings.transparencySortMode == UnityEngine.TransparencySortMode.CustomAxis)
                {
                    customSortAxisSetting = UnityEngine.Rendering.GraphicsSettings.transparencySortAxis;
                }
                DstEntityManager.AddComponentData(entity, new Unity.Tiny.Rendering.CameraSettings2D
                {
                    customSortAxis = customSortAxisSetting
                });

                if (DstEntityManager.HasComponent <NonUniformScale>(entity))
                {
                    DstEntityManager.SetComponentData(entity, new NonUniformScale()
                    {
                        Value = new float3(1f)
                    });
                }
            });
        }
示例#23
0
        private void ConvertSelectable(Selectable selectable)
        {
            var entity = GetPrimaryEntity(selectable);

            DstEntityManager.AddComponent(entity, typeof(DotsUI.Input.Selectable));
            var    colors = selectable.colors;
            Entity target = TryGetPrimaryEntity(selectable.targetGraphic);

            DstEntityManager.AddComponentData(entity, new DotsUI.Input.SelectableColor()
            {
                Normal         = colors.normalColor.ToFloat4(),
                Hover          = colors.highlightedColor.ToFloat4(),
                Pressed        = colors.pressedColor.ToFloat4(),
                Selected       = colors.selectedColor.ToFloat4(),
                Disabled       = colors.disabledColor.ToFloat4(),
                TransitionTime = colors.fadeDuration,
                Target         = target
            });

            var pointerInputReceiver = GetOrAddComponent <Input.PointerInputReceiver>(DstEntityManager, entity);

            pointerInputReceiver.ListenerTypes |= Input.PointerEventType.SelectableGroup;
            DstEntityManager.SetComponentData(entity, pointerInputReceiver);
        }
    protected override void OnUpdate()
    {
        Entities.ForEach((HLOD hlod) =>
        {
            if (!hlod.autoLODSections)
            {
                return;
            }

            var section  = DstEntityManager.GetSharedComponentData <SceneSection>(GetPrimaryEntity(hlod));
            var lodCount = hlod.LODParentTransforms.Length;

            for (int i = 0; i < lodCount; ++i)
            {
                // Lowest LOD in section 0, everything else in section 1
                section.Section = (i == lodCount - 1) ? 0 : 1;
                var lodParent   = hlod.LODParentTransforms[i];
                if (lodParent != null)
                {
                    RecursivelySetSection(hlod.LODParentTransforms[i], section);
                }
            }
        });
    }
示例#25
0
        private void AddTextData(Entity e, string text)
        {
            var length = text.Length;

            var txtBuffer = DstEntityManager.AddBuffer <CharElement>(e);

            txtBuffer.ResizeUninitialized(length);

            for (int i = 0; i < length; i++)
            {
                txtBuffer[i] = text[i];
            }

            var vertexBuffer = DstEntityManager.AddBuffer <LocalVertexData>(e);

            vertexBuffer.ResizeUninitialized(text.Length);

            for (int i = 0; i < text.Length; i++)
            {
                vertexBuffer[i] = default;
            }

            var indexBuffer = DstEntityManager.AddBuffer <LocalTriangleIndexElement>(e);
        }
示例#26
0
        internal void SubmitCollider(
            UnityEngine.Collider2D collider,
            ref BlobAssetReference <Collider> colliderBlob)
        {
            // Fetch any rigidbody we're attached to.
            var rigidbody = collider.attachedRigidbody;

            // Are we attached to a rigidbody?
            if (rigidbody != null)
            {
                // Yes, so add as a mapping to the rigidbody entity for now in-case we're a compound collider.
                RigidbodyToColliderMapping.Add(GetPrimaryEntity(rigidbody), colliderBlob);

                // Declare a dependency between the rigidbody and the collider components.
                DeclareDependency(rigidbody, collider);
                return;
            }

            // No attached Rigidbody2D so add the collider blob onto this Entity.
            // NOTE: This is the implicit static collider case.
            DstEntityManager.AddComponentData(GetPrimaryEntity(collider), new PhysicsColliderBlob {
                Collider = colliderBlob
            });
        }
        private void ConvertImage(Image image)
        {
            var assetQuery = DstEntityManager.CreateEntityQuery(ComponentType.ReadOnly <SpriteAsset>());
            var entity     = GetPrimaryEntity(image);
            var sprite     = image.sprite ?? m_DefaultSprite;
            var asset      = new SpriteAsset()
            {
                Value = sprite,
            };

            assetQuery.SetFilter(asset);
            Entity assetEntity;

            if (assetQuery.CalculateEntityCount() == 0)
            {
                assetEntity = DstEntityManager.CreateEntity(typeof(SpriteAsset), typeof(SpriteVertexData));
                DstEntityManager.SetSharedComponentData(assetEntity, new SpriteAsset {
                    Value = sprite
                });
            }
            else
            {
                using (var assetEntityArray = assetQuery.ToEntityArray(Allocator.TempJob))
                    assetEntity = assetEntityArray[0];
            }
            SpriteImage spriteImage = new SpriteImage
            {
                Asset = assetEntity
            };

            DstEntityManager.AddComponentData(entity, spriteImage);
            DstEntityManager.AddBuffer <ControlVertexData>(entity);
            DstEntityManager.AddBuffer <ControlVertexIndex>(entity);
            DstEntityManager.AddComponent(entity, typeof(ElementVertexPointerInMesh));
            DstEntityManager.AddComponent(entity, typeof(RebuildElementMeshFlag));
        }
示例#28
0
        private void ConvertButton(Button button)
        {
            var entity = GetPrimaryEntity(button);

            DstEntityManager.AddComponent(entity, typeof(Controls.Button));
        }
示例#29
0
        private void ConvertMask(RectMask2D mask)
        {
            var entity = GetPrimaryEntity(mask);

            DstEntityManager.AddComponent <RectMask>(entity);
        }
示例#30
0
        protected override void OnUpdate()
        {
            Entities.WithNone <DontConvertColliderTag>().ForEach((UnityEngine.SphereCollider goSphere) =>
            {
                float3 lossyScale = goSphere.transform.lossyScale;
                if (math.cmax(lossyScale) - math.cmin(lossyScale) > 1.0E-5f)
                {
                    UnityEngine.Debug.LogWarning(
                        $"Failed to convert {goSphere}. Only uniform scaling is supported on SphereCollider. Lossy Scale divergence was: {math.cmax(lossyScale) - math.cmin(lossyScale)}");
                    return;
                }

                Entity entity      = GetPrimaryEntity(goSphere);
                Collider icdSphere = new SphereCollider
                {
                    center = goSphere.center,
                    radius = goSphere.radius * goSphere.transform.localScale.x
                };
                DstEntityManager.AddComponentData(entity, icdSphere);
            });

            Entities.WithNone <DontConvertColliderTag>().ForEach((UnityEngine.CapsuleCollider goCap) =>
            {
                float3 lossyScale = goCap.transform.lossyScale;
                if (math.cmax(lossyScale) - math.cmin(lossyScale) > 1.0E-5f)
                {
                    UnityEngine.Debug.LogWarning("Failed to convert " + goCap + ". Only uniform scaling is supported on CapsuleCollider.");
                    return;
                }

                Entity entity = GetPrimaryEntity(goCap);
                float3 dir;
                if (goCap.direction == 0)
                {
                    dir = new float3(1f, 0f, 0f);
                }
                else if (goCap.direction == 1)
                {
                    dir = new float3(0f, 1, 0f);
                }
                else
                {
                    dir = new float3(0f, 0f, 1f);
                }
                Collider icdCap = new CapsuleCollider
                {
                    pointB = (float3)goCap.center + ((goCap.height / 2f - goCap.radius) * goCap.transform.lossyScale.x * dir),
                    pointA = (float3)goCap.center - ((goCap.height / 2f - goCap.radius) * goCap.transform.lossyScale.x * dir),
                    radius = goCap.radius * goCap.transform.lossyScale.x
                };
                DstEntityManager.AddComponentData(entity, icdCap);
            });

            Entities.WithNone <DontConvertColliderTag>().ForEach((UnityEngine.BoxCollider goBox) =>
            {
                float3 lossyScale = goBox.transform.lossyScale;

                Entity entity   = GetPrimaryEntity(goBox);
                Collider icdBox = new BoxCollider
                {
                    center   = goBox.center,
                    halfSize = goBox.size * lossyScale / 2f
                };
                DstEntityManager.AddComponentData(entity, icdBox);
            });
        }