Exemplo n.º 1
0
        public LevelPlane(Project2Game game, Level level, Vector3 position, SlopeType slopeType, float slopeHeight = 16f, int xSize = Level.PreferedTileWidth, int ySize = Level.PreferedTileHeight)
            : base (game, level, position)
        {
            this.xSize = xSize;
            this.ySize = ySize; // this should be z size for consistency in 3D
            float frontHeight = 0f;
            float backHeight = 0f;
            if (slopeType == SlopeType.SlopeUp) { backHeight = slopeHeight; }
            if (slopeType == SlopeType.SlopeDown) { frontHeight = slopeHeight; }

            // calculate the angle of gradient
            var angle = (float)Math.Atan2(backHeight - frontHeight, xSize - 0); //y_2 - y_2 / x_2 - x_1 = gradient
            var separation = xSize; // disatance between walls (default to tile width)
            var wallWidth = 2.0f; // width of wall
            var wallHeight = 4.0f; // height of wall
            // vertical displacement of wall, offset so it sits on the ground
            var heightDisplacement = Math.Abs((backHeight - frontHeight)/2.0f) + wallHeight / 2.0f;
            // instantiate a wall for either side of the plane
            
            var box1 = new Box(game, game.models["box"], position + new Vector3(0f, heightDisplacement, ySize / 2.0f), new Vector3(wallWidth, wallHeight, ySize), new Vector3(0, -angle, 0));
            var box2 = new Box(game, game.models["box"], position + new Vector3(separation, heightDisplacement, ySize / 2.0f), new Vector3(wallWidth, wallHeight, ySize), new Vector3(0, -angle, 0));
            box1.PhysicsDescription.IsStatic = true;
            box2.PhysicsDescription.IsStatic = true;
            AddChild(box1);
            AddChild(box2);

            if (slopeType == SlopeType.Flat)
            {
                //this.physicsPuzzles.Add(new PhysicsPuzzles.SeeSaw(game, this, new Vector3(32, 0, 32)));
            }
            // add floor
            var floor = new FlatTerrain(game, position, (float)xSize, (float)ySize, frontHeight, backHeight);
            floor.PhysicsDescription.IsStatic = true;
            AddChild(floor);

        }
    public override void OnInspectorGUI()
    {
        FlatTerrain controlScript = target as FlatTerrain;

        _terrain = _terrain ?? controlScript.GetComponent <Terrain>();


        if (_terrain.materialType != Terrain.MaterialType.Custom)
        {
            _terrain.materialType     = Terrain.MaterialType.Custom;
            _terrain.materialTemplate = controlScript.FlatMaterial;
        }

        EditorGUI.BeginChangeCheck();
        bool isHardEdgesEnabled = _terrain.materialTemplate.IsKeywordEnabled(_hardEdgesName);
        bool hardEdges          = EditorGUILayout.Toggle("Hard Texture Edges", isHardEdgesEnabled);

        if (EditorGUI.EndChangeCheck())
        {
            if (hardEdges)
            {
                _terrain.materialTemplate.EnableKeyword(_hardEdgesName);
            }
            else
            {
                _terrain.materialTemplate.DisableKeyword(_hardEdgesName);
            }
        }

        EditorGUI.BeginChangeCheck();
        bool isRimEnabled = _terrain.materialTemplate.IsKeywordEnabled(_rimLightingName);
        bool rim          = EditorGUILayout.Toggle("Rim Lighting", isRimEnabled);

        if (EditorGUI.EndChangeCheck())
        {
            if (rim)
            {
                _terrain.materialTemplate.EnableKeyword(_rimLightingName);
            }
            else
            {
                _terrain.materialTemplate.DisableKeyword(_rimLightingName);
            }
        }

        EditorGUI.BeginDisabledGroup(!isRimEnabled);
        EditorGUI.BeginChangeCheck();
        float hurr = EditorGUILayout.Slider("Rim Value", this._terrain.materialTemplate.GetFloat("_RimPower"), 0.01f, 10.0f);

        if (EditorGUI.EndChangeCheck())
        {
            this._terrain.materialTemplate.SetFloat("_RimPower", hurr);
        }
        EditorGUI.EndDisabledGroup();


        var  tileScale = new Vector2(this.TileScale.x, this.TileScale.z);
        bool isTiled   = true;

        SplatPrototype[] array = this._terrain.terrainData.splatPrototypes;
        for (int index = 0; index < array.Length; index++)
        {
            isTiled = isTiled && (array[index].tileSize == tileScale);
        }

        EditorGUI.BeginChangeCheck();
        isTiled = EditorGUILayout.Toggle("Tile Splat Textures", isTiled);
        if (EditorGUI.EndChangeCheck())
        {
            var scale = _defaultTextureScale;
            if (isTiled)
            {
                scale = tileScale;
            }
            for (int index = 0; index < array.Length; index++)
            {
                array[index].tileSize = scale;
            }

            this._terrain.terrainData.splatPrototypes = array;
            EditorUtility.SetDirty(this._terrain);
        }
    }