コード例 #1
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(RendererBounds, LastSystemVersion) && !chunk.DidChange(LocalToWorld, LastSystemVersion))
                {
                    return;
                }

                //@TODO: Delta change...
                var        worldBounds  = chunk.GetNativeArray(WorldRenderBounds);
                var        localBounds  = chunk.GetNativeArray(RendererBounds);
                var        localToWorld = chunk.GetNativeArray(LocalToWorld);
                MinMaxAABB combined     = MinMaxAABB.Empty;

                for (int i = 0; i != localBounds.Length; i++)
                {
                    var transformed = AABB.Transform(localToWorld[i].Value, localBounds[i].Value);

                    worldBounds[i] = new WorldRenderBounds {
                        Value = transformed
                    };
                    combined.Encapsulate(transformed);
                }

                chunk.SetChunkComponentData(ChunkWorldRenderBounds, new ChunkWorldRenderBounds {
                    Value = combined
                });
            }
コード例 #2
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(RectTransformType, LastSystemVersion) && !chunk.DidChange(LocalToWorldType, LastSystemVersion))
                {
                    return;
                }

                var rectTransforms = chunk.GetNativeArray(RectTransformType);
                var localToWorld   = chunk.GetNativeArray(LocalToWorldType);

                var        worldRectTransforms = chunk.GetNativeArray(WorldRectTransformType);
                MinMaxAABB combined            = MinMaxAABB.Empty;

                for (int i = 0; i != rectTransforms.Length; i++)
                {
                    var transformed = AABB.Transform(localToWorld[i].Value, rectTransforms[i].Value);
                    worldRectTransforms[i] = new WorldRectTransform {
                        Value = transformed
                    };
                    combined.Encapsulate(transformed);
                }
                chunk.SetChunkComponentData(ChunkWorldRectTransformType, new ChunkWorldRectTransform {
                    Value = combined
                });
            }
コード例 #3
0
    public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
    {
        var inputAChanged = chunk.DidChange(CInputA_TypeHandle, LastSystemVersion);
        var inputBChanged = chunk.DidChange(CInputB_TypeHandle, LastSystemVersion);

        // If neither component changed, skip the current chunk
        if (!(inputAChanged || inputBChanged))
        {
            return;
        }

        // 为了方便,去掉brust编译
        UnityEngine.Debug.Log("------------Change-------------");

        var InputA_Array = chunk.GetNativeArray(CInputA_TypeHandle);
        var InputB_Array = chunk.GetNativeArray(CInputB_TypeHandle);
        var OutPut_Array = chunk.GetNativeArray(COutput_TypeHandle);


        for (int i = 0; i < chunk.Count; i++)
        {
            OutPut_Array[i] = new COutput
            {
                Value = InputA_Array[i].Value + InputB_Array[i].Value
            };
        }
    }
コード例 #4
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(LocalToWorldType, LastSystemVersion) &&
                    !chunk.DidChange(ChildType, LastSystemVersion))
                {
                    return;
                }

                var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorldType);
                var chunkChildren     = chunk.GetBufferAccessor(ChildType);

                for (var i = 0; i < chunk.Count; i++)
                {
                    var localToWorldMatrix = chunkLocalToWorld[i].Value;
                    var children           = chunkChildren[i];
                    for (var j = 0; j < children.Length; j++)
                    {
                        TopLevelChildren[firstEntityIndex + i + j] = new ChildInfo {
                            Child = children[j].Value, ParentLocalToWorld = localToWorldMatrix
                        }
                    }
                    ;
                }
            }
        }
コード例 #5
0
                public unsafe void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
                {
                    bool didChunkChange =
                        chunk.DidChange(PositionType, m_LastSystemVersion) ||
                        chunk.DidChange(RotationType, m_LastSystemVersion) ||
                        chunk.DidChange(PhysicsColliderType, m_LastSystemVersion);

                    ChunkHasChangesOutput[chunkIndex] = didChunkChange ? 1 : 0;
                }
コード例 #6
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var didChunkChange =
                    chunk.DidChange(LocalToWorldType, LastSystemVersion) ||
                    chunk.DidChange(TranslationType, LastSystemVersion) ||
                    chunk.DidChange(RotationType, LastSystemVersion) ||
                    chunk.DidChange(PhysicsColliderType, LastSystemVersion);

                ChunkHasChangesOutput[chunkIndex] = didChunkChange ? 1 : 0;
            }
コード例 #7
0
            public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
            {
                bool chunkHasChanges
                    = batchInChunk.DidChange(LocalToWorldTypeHandleInfo,
                                             L2WChangeVersion);

                if (!chunkHasChanges)
                {
                    return; // early out if the chunk transforms haven't changed
                }
                NativeArray <LocalToWorld> transforms
                    = batchInChunk.GetNativeArray <LocalToWorld>(LocalToWorldTypeHandleInfo);

                UnityEngine.Bounds bounds = new UnityEngine.Bounds();
                bounds.center = transforms[0].Position;
                for (int i = 1; i < transforms.Length; i++)
                {
                    bounds.Encapsulate(transforms[i].Position);
                }
                batchInChunk.SetChunkComponentData(
                    ChunkAabbTypeHandleInfo,
                    new ChunkAABB()
                {
                    Value = bounds.ToAABB()
                });
            }
コード例 #8
0
            public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
            {
                if (batchInChunk.DidChange(ParentTypeHandle, LastSystemVersion))
                {
                    var chunkPreviousParents = batchInChunk.GetNativeArray(PreviousParentTypeHandle);
                    var chunkParents         = batchInChunk.GetNativeArray(ParentTypeHandle);
                    var chunkEntities        = batchInChunk.GetNativeArray(EntityTypeHandle);

                    for (int j = 0; j < batchInChunk.Count; j++)
                    {
                        if (chunkParents[j].Value != chunkPreviousParents[j].Value)
                        {
                            var childEntity          = chunkEntities[j];
                            var parentEntity         = chunkParents[j].Value;
                            var previousParentEntity = chunkPreviousParents[j].Value;

                            ParentChildrenToAdd.Add(parentEntity, childEntity);
                            UniqueParents.TryAdd(parentEntity, 0);

                            if (previousParentEntity != Entity.Null)
                            {
                                ParentChildrenToRemove.Add(previousParentEntity, childEntity);
                                UniqueParents.TryAdd(previousParentEntity, 0);
                            }

                            chunkPreviousParents[j] = new PreviousParent
                            {
                                Value = parentEntity
                            };
                        }
                    }
                }
            }
コード例 #9
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                bool weaponFiredChanged = chunk.DidChange <Weapon>(WeaponType, LastSystemVersion);

                if (!weaponFiredChanged)
                {
                    return;
                }

                var chunkWeapons      = chunk.GetNativeArray(WeaponType);
                var chunkTranslations = chunk.GetNativeArray(TranslationType);
                var chunkRotations    = chunk.GetNativeArray(RotationType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    Weapon      weapon      = chunkWeapons[i];
                    Translation translation = chunkTranslations[i];
                    Rotation    rotation    = chunkRotations[i];

                    Entity projectile = CommandBuffer.Instantiate(weapon.ProjectilePrefab);
                    CommandBuffer.SetComponent(projectile, new Translation {
                        Value = translation.Value
                    });
                    CommandBuffer.SetComponent(projectile, new Rotation {
                        Value = rotation.Value
                    });
                }
            }
コード例 #10
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (chunk.DidChange(ParentType, LastSystemVersion))
                {
                    var chunkPreviousParents = chunk.GetNativeArray(PreviousParentType);
                    var chunkParents         = chunk.GetNativeArray(ParentType);
                    var chunkEntities        = chunk.GetNativeArray(EntityType);

                    for (int j = 0; j < chunk.Count; j++)
                    {
                        if (chunkParents[j].Value != chunkPreviousParents[j].Value)
                        {
                            var childEntity = chunkEntities[j];

                            ltsAccess[childEntity] = ltsAccess[childEntity].RecordParentChange(tsAccess[childEntity].KeepTimeScaleOnParentChange);
                            var parentEntity         = chunkParents[j].Value;
                            var previousParentEntity = chunkPreviousParents[j].Value;

                            ParentChildrenToAdd.Add(parentEntity, childEntity);
                            UniqueParents.TryAdd(parentEntity, 0);

                            if (previousParentEntity != Entity.Null)
                            {
                                ParentChildrenToRemove.Add(previousParentEntity, childEntity);
                                UniqueParents.TryAdd(previousParentEntity, 0);
                            }
                            chunkPreviousParents[j] = new PreviousParentTime {
                                Value = parentEntity
                            };
                        }
                    }
                }
            }
コード例 #11
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(SpriteAnimationTimeSpeedStateType, LastSystemVersion))
                {
                    return;
                }
                var states             = chunk.GetNativeArray(SpriteAnimationTimeSpeedStateType);
                var playingStates      = chunk.GetNativeArray(SpriteAnimationPlayingStateType);
                var propertyComponents = chunk.GetNativeArray(PropertyType);

                if (propertyComponents.Length > 0)
                {
                    var clipSet = ClipSetFromEntity[Filter.ClipSetEntity][Filter.ClipIndex];
                    for (var i = 0; i < propertyComponents.Length; ++i)
                    {
                        var isPlaying = clipSet.Loop || clipSet.ComputeNormalizedTime(states[i].Time) > clipSet.ComputeNormalizedTime(states[i].PrevioutTime);
                        propertyComponents[i] = new TProperty {
                            Value = clipSet.GetValue(states[i].Time)
                        };
                        if (isPlaying)
                        {
                            playingStates[i] = new SpriteAnimationPlayingState {
                                Value = true
                            }
                        }
                        ;
                    }
                }
            }
        }
コード例 #12
0
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     if (Changed.Value || (!ForceChange && !chunk.DidChange(ChunkType, LastSystemVersion)))
     {
         return;
     }
     Changed.Value = true;
 }
コード例 #13
0
 public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
 {
     if (!ForceChange && !chunk.DidChange(ChunkType, LastSystemVersion))
     {
         return;
     }
     ChangedIndices[chunkIndex] = firstEntityIndex;
 }
コード例 #14
0
                public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
                {
                    bool didBatchChange =
                        batchInChunk.DidChange(LocalToWorldType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(PositionType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(RotationType, m_LastSystemVersion) ||
                        batchInChunk.DidChange(PhysicsColliderType, m_LastSystemVersion) ||
                        batchInChunk.DidOrderChange(m_LastSystemVersion);

                    if (didBatchChange)
                    {
                        // Note that multiple worker threads may be running at the same time.
                        // They either write 1 to Result[0] or not write at all.  In case multiple
                        // threads are writing 1 to this variable, in C#, reads or writes of int
                        // data type are atomic, which guarantees that Result[0] is 1.
                        Result[0] = 1;
                    }
                }
コード例 #15
0
            public void Execute(ArchetypeChunk batchInChunk, int batchIndex)
            {
                bool updateChildrenTransform =
                    batchInChunk.DidChange <LocalToWorld>(LocalToWorldTypeHandle, LastSystemVersion) ||
                    batchInChunk.DidChange <Child>(ChildTypeHandle, LastSystemVersion);

                var chunkLocalToWorld = batchInChunk.GetNativeArray(LocalToWorldTypeHandle);
                var chunkChildren     = batchInChunk.GetBufferAccessor(ChildTypeHandle);

                for (int i = 0; i < batchInChunk.Count; i++)
                {
                    var localToWorldMatrix = chunkLocalToWorld[i].Value;
                    var children           = chunkChildren[i];
                    for (int j = 0; j < children.Length; j++)
                    {
                        ChildLocalToWorld(localToWorldMatrix, children[j].Value, updateChildrenTransform);
                    }
                }
            }
コード例 #16
0
            public void Execute(ArchetypeChunk chunk, int index, int entityOffset)
            {
                bool updateChildrenTimeScale =
                    chunk.DidChange <TimeScale>(TimeScaleType, LastSystemVersion) ||
                    chunk.DidChange <ChildTime>(ChildType, LastSystemVersion);

                var chunkTimeScale = chunk.GetNativeArray(TimeScaleType);
                var chunkChildren  = chunk.GetBufferAccessor(ChildType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var timeScale = chunkTimeScale[i].value;
                    var children  = chunkChildren[i];

                    for (int j = 0; j < children.Length; j++)
                    {
                        ChildTimeScale(timeScale, children[j].Value, updateChildrenTimeScale, 0);
                    }
                }
            }
コード例 #17
0
            public void Execute(ArchetypeChunk chunk, int index, int entityOffset)
            {
                if (!chunk.DidChange(LocalToWorldType, LastSystemVersion) &&
                    !chunk.DidChange(LocalToParentType, LastSystemVersion) &&
                    !chunk.DidChange(ChildType, LastSystemVersion))
                {
                    return;
                }
                var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorldType);
                var chunkChildren     = chunk.GetBufferAccessor(ChildType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var localToWorldMatrix = chunkLocalToWorld[i].Value;
                    var children           = chunkChildren[i];
                    for (int j = 0; j < children.Length; j++)
                    {
                        ChildLocalToWorld(localToWorldMatrix, children[j].Value);
                    }
                }
            }
コード例 #18
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var inputAChanged = chunk.DidChange(InputATypeHandle, LastSystemVersion);
                var inputBChanged = chunk.DidChange(InputBTypeHandle, LastSystemVersion);

                // If neither component changed, skip the current chunk
                if (!(inputAChanged || inputBChanged))
                {
                    return;
                }

                var inputAs = chunk.GetNativeArray(InputATypeHandle);
                var inputBs = chunk.GetNativeArray(InputBTypeHandle);
                var outputs = chunk.GetNativeArray(OutputTypeHandle);

                for (var i = 0; i < outputs.Length; i++)
                {
                    outputs[i] = new Output {
                        Value = inputAs[i].Value + inputBs[i].Value
                    };
                }
            }
コード例 #19
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!ExtractAll && !chunk.DidChange(ChunkType, LastSystemVersion))
                {
                    return;
                }
                var components = chunk.GetNativeArray(ChunkType);

                for (var i = 0; i < components.Length; ++i)
                {
                    Values[firstEntityIndex + i] = new half4x4(components[i].Value);
                }
            }
コード例 #20
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            if (!chunk.DidChange(ChunkType, LastSystemVersion))
            {
                return;
            }
            var entities   = chunk.GetNativeArray(EntityType);
            var components = chunk.GetNativeArray(ChunkType);

            for (var i = 0; i < chunk.Count; ++i)
            {
                ChangedComponents.TryAdd(entities[i], components[i]);
            }
        }
コード例 #21
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                bool structuralChange = chunk.DidChange(SpecCube0Handle, LastSystemVersion);

                if (structuralChange || DefaultSpecCubeChanged)
                {
                    var specCube0s = chunk.GetNativeArray(SpecCube0Handle);

                    for (int i = 0; i < chunk.Count; ++i)
                    {
                        var specCube = specCube0s[i];
                        specCube.Value = DefaultSpecCube;

                        specCube0s[i] = specCube;
                    }
                }
            }
コード例 #22
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(LocalToWorldType, LastSystemVersion))
                {
                    return;
                }

                var chunkLocalToWorld = chunk.GetNativeArray(LocalToWorldType);
                var chunkWorldToLocal = chunk.GetNativeArray(WorldToLocalType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var localToWorld = chunkLocalToWorld[i].Value;
                    chunkWorldToLocal[i] = new WorldToLocal {
                        Value = math.inverse(localToWorld)
                    };
                }
            }
コード例 #23
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var didChange = chunk.DidChange(ComponentAs, LastSystemVersion);

                if (!didChange)
                {
                    return;
                }
                Debug.LogError("JobA running!");
                var compANative = chunk.GetNativeArray(ComponentAs);
                // for (int i = 0; i < compANative.Length; i++)
                // {
                //     compANative[i] = new ComponentA()
                //     {
                //         Value = i,
                //     };
                // }
            }
コード例 #24
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var localToWorldChunkChanged = chunk.DidChange(LocalToWorldType, LastSystemVersion);

                if (ChangedLookAtEntities.Length == 0 && !localToWorldChunkChanged)
                {
                    return;
                }

                var lookAtArray       = chunk.GetNativeArray(LookAtType);
                var localToWorldArray = new NativeArray <LocalToWorld>();

                for (var i = 0; i < chunk.Count; ++i)
                {
                    var lookAtEntity = lookAtArray[i].Value;
                    if (!LocalToWorldFromEntity.Exists(lookAtEntity))
                    {
                        continue;
                    }
                    // Avoid multiple nested rotations
                    if (TransformUtility.ExistsInHierarchy(lookAtEntity, ParentFromEntity, LookFromEntity))
                    {
                        continue;
                    }
                    if (!localToWorldChunkChanged && !ChangedLookAtEntities.ContainsKey(lookAtEntity))
                    {
                        continue;
                    }

                    localToWorldArray = localToWorldArray.IsCreated ? localToWorldArray : chunk.GetNativeArray(LocalToWorldType);
                    var localToWorld = localToWorldArray[i];
                    var forward      = math.normalize(LocalToWorldFromEntity[lookAtEntity].Value.Forward());
                    var up           = math.normalize(LocalToWorldFromEntity[lookAtEntity].Value.Up());
                    if (!math.cross(forward, up).Equals(float3.zero))
                    {
                        localToWorldArray[i] = new LocalToWorld {
                            Value = math.mul(new float4x4(quaternion.LookRotation(forward, up), localToWorld.Position),
                                             float4x4.Scale(localToWorld.Value.Scale()))
                        }
                    }
                    ;
                }
            }
        }
コード例 #25
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var isChange = chunk.DidChange(PositionArch, LastSystemVersion);

                if (!isChange)
                {
                    return;
                }
                var positionNativeArray     = chunk.GetNativeArray(PositionArch);
                var faceNativeArray         = chunk.GetNativeArray(FaceArch);
                var localToWorldNativeArray = chunk.GetNativeArray(LocalToWorldArch);
                var length = positionNativeArray.Length;

                for (int i = 0; i < length; i++)
                {
                    localToWorldNativeArray[i] = new LocalToWorldComponent
                    {
                        Value = float4x4.TRS(positionNativeArray[i].Value, faceNativeArray[i].Value, 1),
                    };
                }
            }
コード例 #26
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(SpriteAnimationStateType, LastSystemVersion))
                {
                    return;
                }
                var states             = chunk.GetNativeArray(SpriteAnimationStateType);
                var propertyComponents = chunk.GetNativeArray(PropertyType);

                if (propertyComponents.Length > 0)
                {
                    ref var clipSet = ref ClipSetFromEntity[Filter.ClipSetEntity][Filter.ClipIndex].Value.Value;
                    for (var i = 0; i < propertyComponents.Length; ++i)
                    {
                        propertyComponents[i] = new TProperty {
                            Value = clipSet.GetValue(states[i].Time)
                        }
                    }
                    ;
                }
            }
コード例 #27
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (!chunk.DidChange(LocalToWorldType, LastSystemVersion) &&
                    !chunk.DidChange(TextDataType, LastSystemVersion) &&
                    !chunk.DidChange(TextRendererType, LastSystemVersion) &&
                    !chunk.DidChange(ColorValueType, LastSystemVersion) &&
                    !chunk.DidChange(ColorMultiplierType, LastSystemVersion) &&
                    !chunk.DidChange(LocalRectTransformType, LastSystemVersion))
                {
                    return;
                }

                var textDataArray              = chunk.GetNativeArray(TextDataType);
                var worldRenderBoundsArray     = chunk.GetNativeArray(LocalRectTransformType);
                var textRendererArray          = chunk.GetNativeArray(TextRendererType);
                var vertexColorArray           = chunk.GetNativeArray(ColorValueType);
                var vertexColorMultiplierArray = chunk.GetNativeArray(ColorMultiplierType);
                var localToWorldArray          = chunk.GetNativeArray(LocalToWorldType);

                var vertexBufferAccessor      = chunk.GetBufferAccessor(VertexType);
                var vertexIndexBufferAccessor = chunk.GetBufferAccessor(VertexIndexType);
                var textLineBufferAccessor    = chunk.GetBufferAccessor(TextLineType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var textRenderer = textRendererArray[i];
                    if (!FontAssetFromEntity.Exists(textRenderer.Font))
                    {
                        continue;
                    }
                    var vertices         = vertexBufferAccessor[i];
                    var vertexIndices    = vertexIndexBufferAccessor[i];
                    var textData         = textDataArray[i];
                    var vertexCount      = textData.Value.LengthInBytes * 4;
                    var vertexIndexCount = textData.Value.LengthInBytes * 6;
                    if (vertexCount != vertices.Length)
                    {
                        vertices.ResizeUninitialized(vertexCount);
                        vertexIndices.ResizeUninitialized(vertexIndexCount);
                    }
                    var lines = textLineBufferAccessor[i];
                    lines.Clear();
                    var renderBounds = worldRenderBoundsArray[i];
                    var localToWorld = localToWorldArray[i];
                    var color        = vertexColorArray[i].Value * vertexColorMultiplierArray[i].Value;
                    PopulateMesh(renderBounds, localToWorld.Value, textRenderer, color, textData, vertices, vertexIndices, lines);
                }
            }
コード例 #28
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var hasScale           = chunk.Has(ScaleType);
                var hasNonUniformScale = chunk.Has(NonUniformScaleType);
                var hasCompositeScale  = chunk.Has(CompositeScaleType);

                if (hasCompositeScale)
                {
                    var didChange = chunk.DidChange(CompositeScaleType, LastSystemVersion) ||
                                    chunk.DidChange(ChildType, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    var chunkCompositeScales = chunk.GetNativeArray(CompositeScaleType);
                    var chunkChildren        = chunk.GetBufferAccessor(ChildType);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        var inverseScale = math.inverse(chunkCompositeScales[i].Value);
                        var children     = chunkChildren[i];
                        for (var j = 0; j < children.Length; j++)
                        {
                            var childEntity = children[j].Value;
                            if (!ParentScaleInverseFromEntity.Exists(childEntity))
                            {
                                continue;
                            }

                            ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {
                                Value = inverseScale
                            };
                        }
                    }
                }
                else if (hasScale)
                {
                    var didChange = chunk.DidChange(ScaleType, LastSystemVersion) ||
                                    chunk.DidChange(ChildType, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    var chunkScales   = chunk.GetNativeArray(ScaleType);
                    var chunkChildren = chunk.GetBufferAccessor(ChildType);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        var inverseScale = float4x4.Scale(1.0f / chunkScales[i].Value);
                        var children     = chunkChildren[i];
                        for (var j = 0; j < children.Length; j++)
                        {
                            var childEntity = children[j].Value;
                            if (!ParentScaleInverseFromEntity.Exists(childEntity))
                            {
                                continue;
                            }

                            ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {
                                Value = inverseScale
                            };
                        }
                    }
                }
                else // if (hasNonUniformScale)
                {
                    var didChange = chunk.DidChange(NonUniformScaleType, LastSystemVersion) ||
                                    chunk.DidChange(ChildType, LastSystemVersion);
                    if (!didChange)
                    {
                        return;
                    }

                    var chunkNonUniformScales = chunk.GetNativeArray(NonUniformScaleType);
                    var chunkChildren         = chunk.GetBufferAccessor(ChildType);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        var inverseScale = float4x4.Scale(1.0f / chunkNonUniformScales[i].Value);
                        var children     = chunkChildren[i];
                        for (var j = 0; j < children.Length; j++)
                        {
                            var childEntity = children[j].Value;
                            if (!ParentScaleInverseFromEntity.Exists(childEntity))
                            {
                                continue;
                            }

                            ParentScaleInverseFromEntity[childEntity] = new ParentScaleInverse {
                                Value = inverseScale
                            };
                        }
                    }
                }
            }
コード例 #29
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                if (chunk.Has(RotationEulerXyzTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerXyzTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerXYZs = chunk.GetNativeArray(RotationEulerXyzTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerXYZ(chunkRotationEulerXYZs[i].Value)
                        };
                    }
                }
                else if (chunk.Has(RotationEulerXzyTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerXzyTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerXZYs = chunk.GetNativeArray(RotationEulerXzyTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerXZY(chunkRotationEulerXZYs[i].Value)
                        };
                    }
                }
                else if (chunk.Has(RotationEulerYxzTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerYxzTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerYXZs = chunk.GetNativeArray(RotationEulerYxzTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerYXZ(chunkRotationEulerYXZs[i].Value)
                        };
                    }
                }
                else if (chunk.Has(RotationEulerYzxTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerYzxTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerYZXs = chunk.GetNativeArray(RotationEulerYzxTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerYZX(chunkRotationEulerYZXs[i].Value)
                        };
                    }
                }
                else if (chunk.Has(RotationEulerZxyTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerZxyTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerZXYs = chunk.GetNativeArray(RotationEulerZxyTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerZXY(chunkRotationEulerZXYs[i].Value)
                        };
                    }
                }
                else if (chunk.Has(RotationEulerZyxTypeHandle))
                {
                    if (!chunk.DidChange(RotationEulerZyxTypeHandle, LastSystemVersion))
                    {
                        return;
                    }

                    var chunkRotations         = chunk.GetNativeArray(RotationTypeHandle);
                    var chunkRotationEulerZYXs = chunk.GetNativeArray(RotationEulerZyxTypeHandle);
                    for (var i = 0; i < chunk.Count; i++)
                    {
                        chunkRotations[i] = new Rotation
                        {
                            Value = quaternion.EulerZYX(chunkRotationEulerZYXs[i].Value)
                        };
                    }
                }
            }
コード例 #30
0
 public static bool DidChange <T>(this ArchetypeChunk chunk, ComponentTypeHandle <T> chunkComponentType, uint version) where T : struct, IComponentData => chunk.DidChange(chunkComponentType.Value, version);