コード例 #1
0
    // Construct Shared Array For Serveral Entities
    protected override void OnUpdate()
    {
        // 读取数据并存储在 BlobAsset 中
        gmBlobRefs = new List <BlobAssetReference <GroundMotionBlobAsset> >();
        // 获得所有可选 GroundMotion 的名字
        var gms = GmDataReader.GroundMotionFolders(groundMotionPath);

        foreach (var item in gms)
        {
            //FIXME: Debug 运行了两次,表示读取了两次数据? 可能有问题代码
            //Debug.Log(item);
            if (!GetData(item))
            {
                break;
            }

            // 创建 BlobBuilder,赋值 gmArray 和 gmName
            BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp);

            // Blob 声明资产类型
            ref GroundMotionBlobAsset       groundMotionBlobAsset = ref blobBuilder.ConstructRoot <GroundMotionBlobAsset>();
            BlobBuilderArray <GroundMotion> gmArray = blobBuilder.Allocate(ref groundMotionBlobAsset.gmArray, acc.Count);

            // 存储加速度数据为 BlobArray
            // TODO: 也许有新的数据转换方式从 List<Vector3> 到 BlobBuilderArray<GroundMotion>
            for (int i = 0; i < acc.Count; ++i)
            {
                gmArray[i] = new GroundMotion {
                    acceleration = new float3(acc[i])
                };
            }

            // 存储相应地震名字为 BlobString
            blobBuilder.AllocateString(ref groundMotionBlobAsset.gmName, item);

            // 声明 Blob 资产引用
            BlobAssetReference <GroundMotionBlobAsset> groundMotionBlobAssetReference =
                blobBuilder.CreateBlobAssetReference <GroundMotionBlobAsset>(Allocator.Persistent);

            gmBlobRefs.Add(groundMotionBlobAssetReference);
            // 释放 BlobBuilder
            blobBuilder.Dispose();
        }
コード例 #2
0
        public unsafe BlobAssetReference Build(ITreeNode <INodeDataBuilder>[] builders)
        {
            if (NodeType.IsZeroSizeStruct())
            {
                return(BlobAssetReference.Null);
            }
            var blobBuilder = new BlobBuilder(Allocator.Temp, UnsafeUtility.SizeOf(NodeType));

            try
            {
                var dataPtr = blobBuilder.ConstructRootPtrByType(NodeType);
                Build(dataPtr, blobBuilder, builders);
                return(blobBuilder.CreateReferenceByType(NodeType));
            }
            finally
            {
                blobBuilder.Dispose();
            }
        }
コード例 #3
0
    private void Start()
    {
        //boidsToSpawn = 5000;
        // GameObject.Find("Spawn").GetComponentInChildren<Text>().text = "Spawn";
        totalSpawnedBoids = 0;
        entitymanager     = World.DefaultGameObjectInjectionWorld.EntityManager;
        currentPosition   = this.transform.position;
        ea = entitymanager.CreateArchetype(
            typeof(Translation),
            typeof(Rotation),
            typeof(LocalToWorld),
            typeof(RenderMesh),
            typeof(RenderBounds),
            typeof(Boid_ComponentData)
            );
        debugEntities = new List <Entity>();

        try
        {
            BlobBuilder bb = new BlobBuilder(Unity.Collections.Allocator.Temp);
            boidManagerReference = new BlobAssetReference <BoidManagerBLOB>();
            ref BoidManagerBLOB             bmb = ref bb.ConstructRoot <BoidManagerBLOB>();
            BlobBuilderArray <Boid_Manager> blobManagerArray = bb.Allocate(ref bmb.blobManagerArray, 9);
            blobManagerArray[0] = new Boid_Manager
            {
                cohesionBias     = cohesionBias,
                separationBias   = separationBias,
                alignmentBias    = alignmentBias,
                targetBias       = targetBias,
                perceptionRadius = perceptionRadius,
                step             = step,
                cellSize         = cellSize,
                fieldOfView      = fieldOfView,
                maxPercived      = maxPercived
            };
            boidManagerReference = bb.CreateBlobAssetReference <BoidManagerBLOB>(Unity.Collections.Allocator.Persistent);
            bb.Dispose();
        }
コード例 #4
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var scene = EditorSceneManager.OpenScene(ctx.assetPath, OpenSceneMode.Additive);

        try
        {
            var dependencies = AssetDatabase.GetDependencies(scene.path).Where(x => x.ToLower().EndsWith(".prefab"));
            foreach (var dependency in dependencies)
            {
                ctx.DependsOnSourceAsset(dependency);
            }

            var metaPath   = ctx.GetResultPath("scenemeta");
            var subScenes  = SubScene.AllSubScenes;
            var sceneGuids = subScenes.Where(x => x.SceneGUID != default(Hash128)).Select(x => x.SceneGUID).Distinct().ToArray();

            var     builder  = new BlobBuilder(Allocator.Temp);
            ref var metaData = ref builder.ConstructRoot <SceneMetaData>();

            builder.Construct(ref metaData.SubScenes, sceneGuids);
            BlobAssetReference <SceneMetaData> .Write(builder, metaPath, SceneMetaDataImporter.CurrentFileFormatVersion);

            builder.Dispose();
        }
コード例 #5
0
 public void TearDown()
 {
     _builder.Dispose();
 }