Esempio n. 1
0
        public static void SetTextures(Rect terrainRect, Texture2D[] textures, int[] maskGroupNums, VegetationPackagePro package)
        {
            for (int i = 0; i < textures.Length; i++)
            {
                Texture2D tex = textures[i];
                if (tex == null)
                {
                    continue;
                }

                TextureMaskGroup maskGroup = package.TextureMaskGroupList[maskGroupNums[i]];

                //creating new mask only if the mask with the same rect doesn't exist
                TextureMask mask = maskGroup.TextureMaskList.Find(m => m.TextureRect == terrainRect);
                if (mask == null)
                {
                    mask = new TextureMask {
                        TextureRect = terrainRect
                    };
                    maskGroup.TextureMaskList.Add(mask);
                }

                mask.MaskTexture = tex;
            }

            //VegetationSystemPro system = GameObject.FindObjectOfType<VegetationSystemPro>();
            //if (system != null)
            //	system.ClearCache(); //clearing cache causes flickering
            VegetationStudioManager.RefreshTerrainHeightMap();
        }
Esempio n. 2
0
        override public void Update(StrokeSegment[] segments)
        {
#if VEGETATION_STUDIO_PRO
            if (segments.Length > 0)
            {
                StrokeSegment segment = segments[0];
                Bounds        bounds  = new Bounds(new Vector3(segment.currUV.x, 0, segment.currUV.y), Vector3.zero);;
                for (int i = 1; i < segments.Length; i++)
                {
                    segment = segments[i];

                    Vector2 boundsWS = TransformUtilities.transformToWorld(segment.currTerrain, segment.currUV);
                    bounds.Encapsulate(new Vector3(boundsWS.x, 0, boundsWS.y));
                }

                VegetationStudioManager.RefreshTerrainHeightMap(bounds);
            }
#endif
        }
Esempio n. 3
0
    public override void OnSceneGUI()
    {
        Bounds editBounds       = new Bounds();
        bool   updateVegetation = false;

        _terrain = (Terrain)target;
        int buttonIndex = GetActiveButton();

        Event current          = Event.current;
        int   controlId        = GUIUtility.GetControlID(EditorInstance.GetHashCode(), FocusType.Passive);
        var   currentEventType = current.GetTypeForControl(controlId);

        if (buttonIndex <= 3)
        {
            switch (currentEventType)
            {
            case EventType.MouseDown:
            case EventType.MouseUp:
            case EventType.MouseDrag:
                if (current.button == 0)
                {
                    var        size = EditorPrefs.GetInt("TerrainBrushSize");
                    Ray        ray  = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    RaycastHit raycastHit;
                    if (_terrain.GetComponent <Collider>().Raycast(ray, out raycastHit, float.PositiveInfinity))
                    {
                        var   pos       = raycastHit.point;
                        float sizeScale = 5f;
                        editBounds       = new Bounds(pos, new Vector3(size * sizeScale, size, size * sizeScale));
                        updateVegetation = true;
                    }
                }
                break;
            }

            if (currentEventType == EventType.MouseDown)
            {
                _combindedBounds = new Bounds(editBounds.center, editBounds.size);
            }
            else if (currentEventType == EventType.MouseDrag || currentEventType == EventType.MouseUp)
            {
                _combindedBounds.Encapsulate(editBounds);
            }
        }

        base.OnSceneGUI();

        if (updateVegetation)
        {
            if (buttonIndex < 3)
            {
                if (currentEventType == EventType.MouseUp)
                {
                    _combindedBounds.Expand(4f);
                    VegetationStudioManager.RefreshTerrainHeightMap(_combindedBounds);
                }
            }
            else
            {
                editBounds.Expand(1f);
                VegetationStudioManager.ClearCache(editBounds);
            }
        }
    }