コード例 #1
0
    public static void Log(object component, EntityManager manager,
                           GameObjectConversionSystem conversionSystem)
    {
        var em = manager;
        var sb = new StringBuilder();

        sb.AppendLine("Conversion Component: " + component.GetType());
        var primaryEntity = conversionSystem.GetPrimaryEntity(((Component)component).gameObject);

        sb.AppendLine("Behaviour Reference Entity: " + primaryEntity);
        var primaryTypes = em.GetComponentTypes(primaryEntity);

        foreach (var type in primaryTypes)
        {
            sb.AppendLine("Component Types: " + type);
        }

        sb.AppendLine("");

        foreach (var innerEntity in conversionSystem.GetEntities(((Component)component).gameObject))
        {
            sb.AppendLine("Behaviour Reference Entity: " + innerEntity);
            var innerTypes = em.GetComponentTypes(innerEntity);
            foreach (var type in innerTypes)
            {
                sb.AppendLine("Component Types: " + type);
            }
        }

        Debug.Log(sb.ToString());
    }
コード例 #2
0
    public static void AddAbilityComponents(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem, AbilitySetup[] abilities)
    {
        dstManager.AddComponentData(entity, new AbilityCollection.State());

        // Create ability entities
        var abilityEntities = new List <Entity>(abilities.Length);

        for (int i = 0; i < abilities.Length; i++)
        {
            var e = conversionSystem.GetEntities(abilities[i].ability);
            e.MoveNext();
            var abilityEntity = e.Current;

            if (abilityEntities.Contains(abilityEntity))
            {
                GameDebug.LogError("Ability " + abilities[i].ability + " registered multiple times in abilities list");
            }

            abilityEntities.Add(abilityEntity);
        }

        // Add abilities to ability buffer
        dstManager.AddBuffer <AbilityCollection.AbilityEntry>(entity);
        var abilityBuffer = dstManager.GetBuffer <AbilityCollection.AbilityEntry>(entity);

        for (int i = 0; i < abilities.Length; i++)
        {
            var entry = new AbilityCollection.AbilityEntry
            {
                entity       = abilityEntities[i],
                abilityType  = abilities[i].abilityTypeFlags,
                canRunWith   = abilities[i].canRunWithFlags,
                canInterrupt = abilities[i].canInterruptFlags,
            };

            if (abilities[i].ActivateButtons.Count > 4)
            {
                GameDebug.LogError("A maximum of 4 activate buttons are allowed. Currently specified:" + abilities[i].ActivateButtons.Count);
            }

            if (abilities[i].ActivateButtons.Count > 0)
            {
                entry.ActivateButton0 = abilities[i].ActivateButtons[0];
            }
            if (abilities[i].ActivateButtons.Count > 1)
            {
                entry.ActivateButton1 = abilities[i].ActivateButtons[1];
            }
            if (abilities[i].ActivateButtons.Count > 2)
            {
                entry.ActivateButton2 = abilities[i].ActivateButtons[2];
            }
            if (abilities[i].ActivateButtons.Count > 3)
            {
                entry.ActivateButton3 = abilities[i].ActivateButtons[3];
            }

            abilityBuffer.Add(entry);
        }
    }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        dstManager.AddComponentData(entity, new CustomIndexComponent {
            Value = Index
        });

        var sb = new StringBuilder();

        sb.AppendLine("Adding CustomIndexComponent to entity: " + entity);
        sb.AppendLine("PrimaryEntity: " + conversionSystem.GetPrimaryEntity(this));
        sb.AppendLine("GetEntities.First: " + conversionSystem.GetEntities(this).First());
        Debug.Log(sb.ToString());
    }
コード例 #4
0
        static void setStreamComponentValues
        (
            GameObjectConversionSystem gcs,
            Transform[] bones, Entity drawInstanceEntity
        )
        {
            var em = gcs.DstEntityManager;

            var qStreamEntity =
                from bone in bones
                from ent in gcs.GetEntities(bone)
                where em.HasComponent <Stream.RelationData>(ent)
                select ent
            ;

            em.AddComponentData(qStreamEntity, new Stream.DrawLinkData {
                DrawEntity = drawInstanceEntity
            });
        }
コード例 #5
0
        public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
        {
            var em  = dstManager;
            var ent = getPostureOrBoneEntity_(conversionSystem, entity, this.gameObject);

            addHitQueryComponent[(int)Useage](this, em, ent);

            return;


            Entity getPostureOrBoneEntity_(GameObjectConversionSystem gcs_, Entity mainEntity_, GameObject mainObject_)
            {
                var em_ = gcs_.DstEntityManager;

                if (em_.HasComponent <Translation>(mainEntity_))
                {
                    return(mainEntity_);
                }

                return(conversionSystem.GetEntities(mainObject_)
                       .Do(x => Debug.Log($"{em_.GetName_(x)} - {mainObject_.name}"))
                       .First(x => em_.HasComponent <Translation>(x)));
            }
        }
コード例 #6
0
        public static void ConvertAnimation(
            EntityManager dstEntityManager,
            GameObjectConversionSystem conversionSystem,
            Component component)
        {
            var bakedData = Bakery.BakeClips(component.gameObject);

            if (bakedData == null || bakedData.AnimationCount <= 0)
            {
                return;
            }

            var offset        = 0;
            var animClipArray = new NativeList <AnimationClipInfo>(bakedData.AnimationCount, Allocator.Temp);

            foreach (var anim in bakedData.Animations)
            {
                animClipArray.Add(new AnimationClipInfo
                {
                    Offset     = offset,
                    ClipLength = anim.ClipLength,
                    FrameCount = anim.FramesCount,
                    WrapMode   = AnimationClipInfo.ToMode(anim.WrapMode),
                });
                offset += anim.FramesCount;
            }

            var animationBakedBuffer = new AnimationBakedBuffer(bakedData.Buffer);

            var renderers = component.GetComponentsInChildren <Renderer>();

            foreach (var renderer in renderers)
            {
                if (renderer == null)
                {
                    Debug.LogWarning("Missing renderer");
                    continue;
                }

                var primaryRendererEntity = conversionSystem.GetPrimaryEntity(renderer);

                dstEntityManager.AddComponent <BoneIndexOffset>(primaryRendererEntity);

                dstEntityManager.AddComponent <AnimatedTag>(primaryRendererEntity);
                dstEntityManager.AddComponent <AnimationState>(primaryRendererEntity);
                dstEntityManager.AddComponent <BoneIndexOffset>(primaryRendererEntity);
                dstEntityManager.AddComponentData(primaryRendererEntity, new BonesCount {
                    Value = bakedData.BonesCount
                });
                dstEntityManager.AddSharedComponentData(primaryRendererEntity, animationBakedBuffer);
                dstEntityManager.AddBuffer <AnimationClipInfo>(primaryRendererEntity).CopyFrom(animClipArray);

                foreach (var rendererEntity in conversionSystem.GetEntities(renderer))
                {
                    if (dstEntityManager.HasComponent <RenderMesh>(rendererEntity))
                    {
                        var renderMesh    = dstEntityManager.GetSharedComponentData <RenderMesh>(rendererEntity);
                        var renderMeshKey = ToHash128(ref renderMesh);
                        if (!sharedMesh.ContainsKey(renderMeshKey))
                        {
                            sharedMesh.Add(renderMeshKey, BakeryUtils.CopyAndFillBonesUV(renderMesh.mesh));
                        }
                        if (!sharedMaterial.ContainsKey(renderMeshKey))
                        {
                            var size    = BakeryUtils.NextPowerOfTwo((int)math.sqrt(animationBakedBuffer.Length));
                            var texture = new Texture2D(size, size, TextureFormat.RGBAFloat,
                                                        false)
                            {
                                wrapMode   = TextureWrapMode.Clamp,
                                filterMode = FilterMode.Point,
                                anisoLevel = 0,
                            };
                            animationBakedBuffer.SetPixels(texture);
                            texture.Apply(false, false);

                            var material = Object.Instantiate(renderMesh.material);
                            material.SetTexture(AnimationsNameId, texture);
                            material.SetVector(AnimationsSizeNameId, new Vector4(size, size));

                            sharedMaterial.Add(renderMeshKey, material);
                        }

                        renderMesh.mesh     = sharedMesh[renderMeshKey];
                        renderMesh.material = sharedMaterial[renderMeshKey];

                        dstEntityManager.SetSharedComponentData(rendererEntity, renderMesh);
                    }
                }
            }

            animClipArray.Dispose();
        }