Exemplo n.º 1
0
        private void CalculateAndCacheTransforms()
        {
            if (cellToProcess.Count == 0)
            {
                return;
            }
            bool willSkipFrame = false;

            try
            {
                NativeArray <float>   prototypePivotOffset = new NativeArray <float>(prototypes.Count, Allocator.TempJob);
                NativeArray <Vector3> prototypeSize        = new NativeArray <Vector3>(prototypes.Count, Allocator.TempJob);
                for (int i = 0; i < prototypes.Count; ++i)
                {
                    prototypePivotOffset[i] = prototypes[i].pivotOffset;
                    prototypeSize[i]        = prototypes[i].size;
                }

                JobHandle[] handles = new JobHandle[cellToProcess.Count];
                for (int i = 0; i < cellToProcess.Count; ++i)
                {
                    int                   cellIndex  = cellToProcess[i];
                    GGrassPatch           cell       = cells[cellIndex];
                    GGrassPatchNativeData nativeData = new GGrassPatchNativeData(cell.Instances);
                    cellsNativeData[cellIndex] = nativeData;

                    GCalculateGrassTransformJob job = new GCalculateGrassTransformJob()
                    {
                        instances            = nativeData.instances,
                        transforms           = nativeData.trs,
                        prototypePivotOffset = prototypePivotOffset,
                        prototypeSize        = prototypeSize,
                        terrainSize          = terrainSize,
                        terrainPos           = terrainPosition
                    };
                    //handles[i] = job.Schedule();
                    handles[i] = job.Schedule(nativeData.instances.Length, 100);
                }

                GJobUtilities.CompleteAll(handles);

                prototypePivotOffset.Dispose();
                prototypeSize.Dispose();
            }
            catch (System.InvalidOperationException)
            {
                willSkipFrame = true;
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }

            if (willSkipFrame)
            {
                throw new GSkipFrameException();
            }
        }
Exemplo n.º 2
0
        private void GetGrassPosition(GFoliageDistributionMapGeneratorParams param, GGrassPatch patch, List <Vector2> pos)
        {
            pos.Clear();
            HashSet <int>         indices   = new HashSet <int>(param.GrassPrototypeIndices);
            List <GGrassInstance> instances = patch.Instances;

            for (int i = 0; i < instances.Count; ++i)
            {
                if (indices.Contains(instances[i].PrototypeIndex))
                {
                    pos.Add(new Vector2(instances[i].Position.x, instances[i].Position.z));
                }
            }
        }