示例#1
0
        public FoliageToolFoliageAssetButton(FoliageInfoAsset newAsset)
        {
            this.asset = newAsset;
            base.transform.anchorMin = new Vector2(0f, 1f);
            base.transform.anchorMax = new Vector2(1f, 1f);
            base.transform.pivot     = new Vector2(0.5f, 1f);
            base.transform.sizeDelta = new Vector2(0f, 30f);
            Sleek2Label sleek2Label = new Sleek2Label();

            sleek2Label.transform.reset();
            sleek2Label.textComponent.text  = this.asset.name;
            sleek2Label.textComponent.color = Sleek2Config.darkTextColor;
            this.addElement(sleek2Label);
        }
示例#2
0
        protected virtual void addFoliage(FoliageInfoAsset foliageAsset, float weightMultiplier)
        {
            if (foliageAsset == null)
            {
                return;
            }
            float num       = 3.14159274f * this.brushRadius * this.brushRadius;
            float newRadius = Mathf.Sqrt(foliageAsset.density / DevkitFoliageToolOptions.instance.densityTarget / 3.14159274f);
            float num2;

            if (!this.addWeights.TryGetValue(foliageAsset, out num2))
            {
                this.addWeights.Add(foliageAsset, 0f);
            }
            num2 += DevkitFoliageToolOptions.addSensitivity * num * this.brushStrength * weightMultiplier * Time.deltaTime;
            if (num2 > 1f)
            {
                this.previewSamples.Clear();
                int num3 = Mathf.FloorToInt(num2);
                num2 -= (float)num3;
                for (int i = 0; i < num3; i++)
                {
                    float num4       = this.brushRadius * Random.value;
                    float brushAlpha = this.getBrushAlpha(num4);
                    if (Random.value >= brushAlpha)
                    {
                        float num5 = 6.28318548f * Random.value;
                        float num6 = Mathf.Cos(num5) * num4;
                        float num7 = Mathf.Sin(num5) * num4;
                        Ray   ray;
                        ray..ctor(this.brushWorldPosition + new Vector3(num6, this.brushRadius, num7), new Vector3(0f, -1f, 0f));
                        RaycastHit raycastHit;
                        if (PhysicsUtility.raycast(ray, out raycastHit, this.brushRadius * 2f, (int)DevkitFoliageToolOptions.instance.surfaceMask, 0))
                        {
                            SphereVolume sphereVolume = new SphereVolume(raycastHit.point, newRadius);
                            if (foliageAsset.getInstanceCountInVolume(sphereVolume) <= 0)
                            {
                                if (Input.GetKey(323))
                                {
                                    foliageAsset.addFoliageToSurface(raycastHit.point, raycastHit.normal, false, false);
                                }
                            }
                        }
                    }
                }
            }
            this.addWeights[foliageAsset] = num2;
        }
示例#3
0
        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);
                        }
                    }
                }
            }
        }
示例#4
0
        // Token: 0x06001126 RID: 4390 RVA: 0x0007084C File Offset: 0x0006EC4C
        protected virtual void handleSearchFieldTyped(Sleek2Field field, string value)
        {
            if (this.searchLength == -1 || value.Length < this.searchLength)
            {
                this.searchInfoAssets.Clear();
                Assets.find <FoliageInfoAsset>(this.searchInfoAssets);
                this.searchCollectionAssets.Clear();
                Assets.find <FoliageInfoCollectionAsset>(this.searchCollectionAssets);
            }
            this.searchLength = value.Length;
            this.foliagePanel.clearElements();
            this.foliagePanel.transform.offsetMin = new Vector2(0f, 0f);
            this.foliagePanel.transform.offsetMax = new Vector2(0f, 0f);
            if (value.Length > 0)
            {
                string[] array = value.Split(new char[]
                {
                    ' '
                });
                for (int i = this.searchInfoAssets.Count - 1; i >= 0; i--)
                {
                    FoliageInfoAsset foliageInfoAsset = this.searchInfoAssets[i];
                    bool             flag             = true;
                    switch (foliageInfoAsset.assetOrigin)
                    {
                    case EAssetOrigin.OFFICIAL:
                        flag &= FoliageToolWindow.showOfficialAssets;
                        break;

                    case EAssetOrigin.CURATED:
                        flag &= FoliageToolWindow.showCuratedAssets;
                        break;

                    case EAssetOrigin.WORKSHOP:
                        flag &= FoliageToolWindow.showWorkshopAssets;
                        break;

                    case EAssetOrigin.MISC:
                        flag &= FoliageToolWindow.showMiscAssets;
                        break;
                    }
                    if (flag)
                    {
                        foreach (string value2 in array)
                        {
                            if (foliageInfoAsset.name.IndexOf(value2, StringComparison.InvariantCultureIgnoreCase) == -1)
                            {
                                flag = false;
                                break;
                            }
                        }
                    }
                    if (!flag)
                    {
                        this.searchInfoAssets.RemoveAtFast(i);
                    }
                }
                for (int k = this.searchCollectionAssets.Count - 1; k >= 0; k--)
                {
                    FoliageInfoCollectionAsset foliageInfoCollectionAsset = this.searchCollectionAssets[k];
                    bool flag2 = true;
                    switch (foliageInfoCollectionAsset.assetOrigin)
                    {
                    case EAssetOrigin.OFFICIAL:
                        flag2 &= FoliageToolWindow.showOfficialAssets;
                        break;

                    case EAssetOrigin.CURATED:
                        flag2 &= FoliageToolWindow.showCuratedAssets;
                        break;

                    case EAssetOrigin.WORKSHOP:
                        flag2 &= FoliageToolWindow.showWorkshopAssets;
                        break;

                    case EAssetOrigin.MISC:
                        flag2 &= FoliageToolWindow.showMiscAssets;
                        break;
                    }
                    if (flag2)
                    {
                        foreach (string value3 in array)
                        {
                            if (foliageInfoCollectionAsset.name.IndexOf(value3, StringComparison.InvariantCultureIgnoreCase) == -1)
                            {
                                flag2 = false;
                                break;
                            }
                        }
                    }
                    if (!flag2)
                    {
                        this.searchCollectionAssets.RemoveAtFast(k);
                    }
                }
                if (this.searchInfoAssets.Count + this.searchCollectionAssets.Count <= 64)
                {
                    this.searchInfoAssets.Sort(new FoliageToolWindow.FoliageToolAssetComparer());
                    this.searchCollectionAssets.Sort(new FoliageToolWindow.FoliageToolAssetComparer());
                    foreach (FoliageInfoAsset newAsset in this.searchInfoAssets)
                    {
                        FoliageToolFoliageAssetButton foliageToolFoliageAssetButton = new FoliageToolFoliageAssetButton(newAsset);
                        foliageToolFoliageAssetButton.clicked += this.handleFoliageAssetButtonClicked;
                        this.foliagePanel.addElement(foliageToolFoliageAssetButton);
                    }
                    foreach (FoliageInfoCollectionAsset newAsset2 in this.searchCollectionAssets)
                    {
                        FoliageToolFoliageCollectionAssetButton foliageToolFoliageCollectionAssetButton = new FoliageToolFoliageCollectionAssetButton(newAsset2);
                        foliageToolFoliageCollectionAssetButton.clicked += this.handleFoliageCollectionAssetButtonClicked;
                        this.foliagePanel.addElement(foliageToolFoliageCollectionAssetButton);
                    }
                }
            }
        }