protected virtual void removeInstances(FoliageTile foliageTile, FoliageInstanceList list, float sqrBrushRadius, float sqrBrushFalloffRadius, ref int sampleCount)
 {
     for (int i = list.matrices.Count - 1; i >= 0; i--)
     {
         List <Matrix4x4> list2 = list.matrices[i];
         List <bool>      list3 = list.clearWhenBaked[i];
         for (int j = list2.Count - 1; j >= 0; j--)
         {
             if (!list3[j])
             {
                 Matrix4x4 matrix       = list2[j];
                 Vector3   position     = matrix.GetPosition();
                 float     sqrMagnitude = (position - this.brushWorldPosition).sqrMagnitude;
                 if (sqrMagnitude < sqrBrushRadius)
                 {
                     bool flag = sqrMagnitude < sqrBrushFalloffRadius;
                     this.previewSamples.Add(new FoliagePreviewSample(position, (!flag) ? (Color.red / 2f) : Color.red));
                     if (Input.GetKey(323) && flag && sampleCount > 0)
                     {
                         foliageTile.removeInstance(list, i, j);
                         sampleCount--;
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        public void bakeFoliageSurface(FoliageBakeSettings bakeSettings, FoliageTile foliageTile)
        {
            int num  = (foliageTile.coord.y * FoliageSystem.TILE_SIZE_INT - this.coord.y * Landscape.TILE_SIZE_INT) / FoliageSystem.TILE_SIZE_INT * FoliageSystem.SPLATMAP_RESOLUTION_PER_TILE;
            int num2 = num + FoliageSystem.SPLATMAP_RESOLUTION_PER_TILE;
            int num3 = (foliageTile.coord.x * FoliageSystem.TILE_SIZE_INT - this.coord.x * Landscape.TILE_SIZE_INT) / FoliageSystem.TILE_SIZE_INT * FoliageSystem.SPLATMAP_RESOLUTION_PER_TILE;
            int num4 = num3 + FoliageSystem.SPLATMAP_RESOLUTION_PER_TILE;

            for (int i = num; i < num2; i++)
            {
                for (int j = num3; j < num4; j++)
                {
                    SplatmapCoord splatmapCoord = new SplatmapCoord(i, j);
                    float         num5          = (float)this.coord.x * Landscape.TILE_SIZE + (float)splatmapCoord.y * Landscape.SPLATMAP_WORLD_UNIT;
                    float         num6          = (float)this.coord.y * Landscape.TILE_SIZE + (float)splatmapCoord.x * Landscape.SPLATMAP_WORLD_UNIT;
                    Bounds        bounds        = default(Bounds);
                    bounds.min = new Vector3(num5, 0f, num6);
                    bounds.max = new Vector3(num5 + Landscape.SPLATMAP_WORLD_UNIT, 0f, num6 + Landscape.SPLATMAP_WORLD_UNIT);
                    for (int k = 0; k < Landscape.SPLATMAP_LAYERS; k++)
                    {
                        float num7 = this.sourceSplatmap[i, j, k];
                        if (num7 >= 0.01f)
                        {
                            LandscapeMaterialAsset landscapeMaterialAsset = Assets.find <LandscapeMaterialAsset>(this.materials[k]);
                            if (landscapeMaterialAsset != null)
                            {
                                FoliageInfoCollectionAsset foliageInfoCollectionAsset = Assets.find <FoliageInfoCollectionAsset>(landscapeMaterialAsset.foliage);
                                if (foliageInfoCollectionAsset != null)
                                {
                                    foliageInfoCollectionAsset.bakeFoliage(bakeSettings, this, bounds, num7);
                                }
                            }
                        }
                    }
                }
            }
        }
        public virtual void update()
        {
            Ray        pointerToWorldRay = DevkitInput.pointerToWorldRay;
            RaycastHit raycastHit;

            this.isPointerOnWorld     = PhysicsUtility.raycast(pointerToWorldRay, out raycastHit, 8192f, (int)DevkitFoliageToolOptions.instance.surfaceMask, 0);
            this.pointerWorldPosition = raycastHit.point;
            this.previewSamples.Clear();
            if (!DevkitNavigation.isNavigating && DevkitInput.canEditorReceiveInput)
            {
                if (Input.GetKeyDown(113))
                {
                    this.mode = DevkitFoliageTool.EFoliageMode.PAINT;
                }
                if (Input.GetKeyDown(119))
                {
                    this.mode = DevkitFoliageTool.EFoliageMode.EXACT;
                }
                if (this.mode == DevkitFoliageTool.EFoliageMode.PAINT)
                {
                    if (Input.GetKeyDown(98))
                    {
                        this.isChangingBrushRadius = true;
                        this.beginChangeHotkeyTransaction();
                    }
                    if (Input.GetKeyDown(102))
                    {
                        this.isChangingBrushFalloff = true;
                        this.beginChangeHotkeyTransaction();
                    }
                    if (Input.GetKeyDown(118))
                    {
                        this.isChangingBrushStrength = true;
                        this.beginChangeHotkeyTransaction();
                    }
                }
            }
            if (Input.GetKeyUp(98))
            {
                this.isChangingBrushRadius = false;
                this.endChangeHotkeyTransaction();
            }
            if (Input.GetKeyUp(102))
            {
                this.isChangingBrushFalloff = false;
                this.endChangeHotkeyTransaction();
            }
            if (Input.GetKeyUp(118))
            {
                this.isChangingBrushStrength = false;
                this.endChangeHotkeyTransaction();
            }
            if (this.isChangingBrush)
            {
                Plane plane = default(Plane);
                plane.SetNormalAndPosition(Vector3.up, this.brushWorldPosition);
                float num;
                plane.Raycast(pointerToWorldRay, ref num);
                this.changePlanePosition = pointerToWorldRay.origin + pointerToWorldRay.direction * num;
                if (this.isChangingBrushRadius)
                {
                    this.brushRadius = (this.changePlanePosition - this.brushWorldPosition).magnitude;
                }
                if (this.isChangingBrushFalloff)
                {
                    this.brushFalloff = Mathf.Clamp01((this.changePlanePosition - this.brushWorldPosition).magnitude / this.brushRadius);
                }
                if (this.isChangingBrushStrength)
                {
                    this.brushStrength = (this.changePlanePosition - this.brushWorldPosition).magnitude / this.brushRadius;
                }
            }
            else
            {
                this.brushWorldPosition = this.pointerWorldPosition;
            }
            this.isBrushVisible = (this.isPointerOnWorld || this.isChangingBrush);
            if (!DevkitNavigation.isNavigating && DevkitInput.canEditorReceiveInput)
            {
                if (this.mode == DevkitFoliageTool.EFoliageMode.PAINT)
                {
                    Bounds worldBounds;
                    worldBounds..ctor(this.brushWorldPosition, new Vector3(this.brushRadius * 2f, 0f, this.brushRadius * 2f));
                    float num2 = this.brushRadius * this.brushRadius;
                    float num3 = num2 * this.brushFalloff * this.brushFalloff;
                    float num4 = 3.14159274f * this.brushRadius * this.brushRadius;
                    if (Input.GetKey(306) || Input.GetKey(304))
                    {
                        this.removeWeight += DevkitFoliageToolOptions.removeSensitivity * num4 * this.brushStrength * Time.deltaTime;
                        int num5 = 0;
                        if (this.removeWeight > 1f)
                        {
                            num5 = Mathf.FloorToInt(this.removeWeight);
                            this.removeWeight -= (float)num5;
                        }
                        FoliageBounds foliageBounds = new FoliageBounds(worldBounds);
                        for (int i = foliageBounds.min.x; i <= foliageBounds.max.x; i++)
                        {
                            for (int j = foliageBounds.min.y; j <= foliageBounds.max.y; j++)
                            {
                                FoliageCoord tileCoord = new FoliageCoord(i, j);
                                FoliageTile  tile      = FoliageSystem.getTile(tileCoord);
                                if (tile != null)
                                {
                                    if (!tile.hasInstances)
                                    {
                                        tile.readInstancesOnThread();
                                    }
                                    if (Input.GetKey(306))
                                    {
                                        if (DevkitFoliageTool.selectedInstanceAsset != null)
                                        {
                                            FoliageInstanceList list;
                                            if (tile.instances.TryGetValue(DevkitFoliageTool.selectedInstanceAsset.getReferenceTo <FoliageInstancedMeshInfoAsset>(), out list))
                                            {
                                                this.removeInstances(tile, list, num2, num3, ref num5);
                                            }
                                        }
                                        else if (DevkitFoliageTool.selectedCollectionAsset != null)
                                        {
                                            foreach (FoliageInfoCollectionAsset.FoliageInfoCollectionElement foliageInfoCollectionElement in DevkitFoliageTool.selectedCollectionAsset.elements)
                                            {
                                                FoliageInstancedMeshInfoAsset foliageInstancedMeshInfoAsset = Assets.find <FoliageInfoAsset>(foliageInfoCollectionElement.asset) as FoliageInstancedMeshInfoAsset;
                                                FoliageInstanceList           list2;
                                                if (foliageInstancedMeshInfoAsset != null && tile.instances.TryGetValue(foliageInstancedMeshInfoAsset.getReferenceTo <FoliageInstancedMeshInfoAsset>(), out list2))
                                                {
                                                    this.removeInstances(tile, list2, num2, num3, ref num5);
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        foreach (KeyValuePair <AssetReference <FoliageInstancedMeshInfoAsset>, FoliageInstanceList> keyValuePair in tile.instances)
                                        {
                                            FoliageInstanceList value = keyValuePair.Value;
                                            this.removeInstances(tile, value, num2, num3, ref num5);
                                        }
                                    }
                                }
                            }
                        }
                        RegionBounds regionBounds = new RegionBounds(worldBounds);
                        for (byte b = regionBounds.min.x; b <= regionBounds.max.x; b += 1)
                        {
                            for (byte b2 = regionBounds.min.y; b2 <= regionBounds.max.y; b2 += 1)
                            {
                                List <ResourceSpawnpoint> list3 = LevelGround.trees[(int)b, (int)b2];
                                for (int k = list3.Count - 1; k >= 0; k--)
                                {
                                    ResourceSpawnpoint resourceSpawnpoint = list3[k];
                                    if (!resourceSpawnpoint.isGenerated)
                                    {
                                        if (Input.GetKey(306))
                                        {
                                            if (DevkitFoliageTool.selectedInstanceAsset != null)
                                            {
                                                FoliageResourceInfoAsset foliageResourceInfoAsset = DevkitFoliageTool.selectedInstanceAsset as FoliageResourceInfoAsset;
                                                if (foliageResourceInfoAsset == null || !foliageResourceInfoAsset.resource.isReferenceTo(resourceSpawnpoint.asset))
                                                {
                                                    goto IL_6BB;
                                                }
                                            }
                                            else if (DevkitFoliageTool.selectedCollectionAsset != null)
                                            {
                                                bool flag = false;
                                                foreach (FoliageInfoCollectionAsset.FoliageInfoCollectionElement foliageInfoCollectionElement2 in DevkitFoliageTool.selectedCollectionAsset.elements)
                                                {
                                                    FoliageResourceInfoAsset foliageResourceInfoAsset2 = Assets.find <FoliageInfoAsset>(foliageInfoCollectionElement2.asset) as FoliageResourceInfoAsset;
                                                    if (foliageResourceInfoAsset2 != null && foliageResourceInfoAsset2.resource.isReferenceTo(resourceSpawnpoint.asset))
                                                    {
                                                        flag = true;
                                                        break;
                                                    }
                                                }
                                                if (!flag)
                                                {
                                                    goto IL_6BB;
                                                }
                                            }
                                        }
                                        float sqrMagnitude = (resourceSpawnpoint.point - this.brushWorldPosition).sqrMagnitude;
                                        if (sqrMagnitude < num2)
                                        {
                                            bool flag2 = sqrMagnitude < num3;
                                            this.previewSamples.Add(new FoliagePreviewSample(resourceSpawnpoint.point, (!flag2) ? (Color.red / 2f) : Color.red));
                                            if (Input.GetKey(323) && flag2 && num5 > 0)
                                            {
                                                resourceSpawnpoint.destroy();
                                                list3.RemoveAt(k);
                                                num5--;
                                            }
                                        }
                                    }
                                    IL_6BB :;
                                }
                                List <LevelObject> list4 = LevelObjects.objects[(int)b, (int)b2];
                                for (int l = list4.Count - 1; l >= 0; l--)
                                {
                                    LevelObject levelObject = list4[l];
                                    if (levelObject.placementOrigin == ELevelObjectPlacementOrigin.PAINTED)
                                    {
                                        if (Input.GetKey(306))
                                        {
                                            if (DevkitFoliageTool.selectedInstanceAsset != null)
                                            {
                                                FoliageObjectInfoAsset foliageObjectInfoAsset = DevkitFoliageTool.selectedInstanceAsset as FoliageObjectInfoAsset;
                                                if (foliageObjectInfoAsset == null || !foliageObjectInfoAsset.obj.isReferenceTo(levelObject.asset))
                                                {
                                                    goto IL_888;
                                                }
                                            }
                                            else if (DevkitFoliageTool.selectedCollectionAsset != null)
                                            {
                                                bool flag3 = false;
                                                foreach (FoliageInfoCollectionAsset.FoliageInfoCollectionElement foliageInfoCollectionElement3 in DevkitFoliageTool.selectedCollectionAsset.elements)
                                                {
                                                    FoliageObjectInfoAsset foliageObjectInfoAsset2 = Assets.find <FoliageInfoAsset>(foliageInfoCollectionElement3.asset) as FoliageObjectInfoAsset;
                                                    if (foliageObjectInfoAsset2 != null && foliageObjectInfoAsset2.obj.isReferenceTo(levelObject.asset))
                                                    {
                                                        flag3 = true;
                                                        break;
                                                    }
                                                }
                                                if (!flag3)
                                                {
                                                    goto IL_888;
                                                }
                                            }
                                        }
                                        float sqrMagnitude2 = (levelObject.transform.position - this.brushWorldPosition).sqrMagnitude;
                                        if (sqrMagnitude2 < num2)
                                        {
                                            bool flag4 = sqrMagnitude2 < num3;
                                            this.previewSamples.Add(new FoliagePreviewSample(levelObject.transform.position, (!flag4) ? (Color.red / 2f) : Color.red));
                                            if (Input.GetKey(323) && flag4 && num5 > 0)
                                            {
                                                levelObject.destroy();
                                                list4.RemoveAt(l);
                                                num5--;
                                            }
                                        }
                                    }
                                    IL_888 :;
                                }
                            }
                        }
                    }
                    else if (DevkitFoliageTool.selectedInstanceAsset != null)
                    {
                        this.addFoliage(DevkitFoliageTool.selectedInstanceAsset, 1f);
                    }
                    else if (DevkitFoliageTool.selectedCollectionAsset != null)
                    {
                        foreach (FoliageInfoCollectionAsset.FoliageInfoCollectionElement foliageInfoCollectionElement4 in DevkitFoliageTool.selectedCollectionAsset.elements)
                        {
                            this.addFoliage(Assets.find <FoliageInfoAsset>(foliageInfoCollectionElement4.asset), foliageInfoCollectionElement4.weight);
                        }
                    }
                }
                else if (Input.GetKeyDown(323))
                {
                    if (DevkitFoliageTool.selectedInstanceAsset != null)
                    {
                        if (DevkitFoliageTool.selectedInstanceAsset != null)
                        {
                            DevkitFoliageTool.selectedInstanceAsset.addFoliageToSurface(raycastHit.point, raycastHit.normal, false, false);
                        }
                    }
                    else if (DevkitFoliageTool.selectedCollectionAsset != null)
                    {
                        FoliageInfoCollectionAsset.FoliageInfoCollectionElement foliageInfoCollectionElement5 = DevkitFoliageTool.selectedCollectionAsset.elements[Random.Range(0, DevkitFoliageTool.selectedCollectionAsset.elements.Count)];
                        FoliageInfoAsset foliageInfoAsset = Assets.find <FoliageInfoAsset>(foliageInfoCollectionElement5.asset);
                        if (foliageInfoAsset != null)
                        {
                            foliageInfoAsset.addFoliageToSurface(raycastHit.point, raycastHit.normal, false, false);
                        }
                    }
                }
            }
        }