コード例 #1
0
        /// <summary>
        /// Initialised the Sector. <paramref name="traversable"/> will be ignored
        /// if the texture in in the 'not traversable' textures list.
        /// </summary>
        /// <returns>The init.</returns>
        /// <param name="currentCoord">The coordinate of the Sector.</param>
        /// <param name="texture">The texture of the Sector.</param>
        /// <param name="traversable">
        /// Whether the sector is traversable (ignored
        /// if texture is in the 'not traversable' list).
        /// </param>
        public void Init(SectorMaterials sectorMaterials, Coord currentCoord, SectorTexture texture, bool traversable)
        {
            // setup base vars
            _renderer = gameObject.GetComponentInChildren <MeshRenderer>();

            gameObject.transform.position = Layout.Default.HexToPixel(currentCoord); // get the position the sector should be in
            Traversable = traversable && !notTraversableTextures.Contains(texture);  // work out whether the sector is traversable or not

            // Setup materials
            _sectorMaterials         = sectorMaterials;
            _defaultMaterial         = _sectorMaterials.GetMaterial(texture, Traversable ? SectorMaterialType.Normal : SectorMaterialType.Dark);
            _highlightBrightMaterial = _sectorMaterials.GetMaterial(texture, SectorMaterialType.Bright);
            _highlightDimmedMaterial = _sectorMaterials.GetMaterial(texture, SectorMaterialType.Dimmed);
            ApplyMaterial(_defaultMaterial);
        }
コード例 #2
0
 /// <summary>
 /// Gets the material for the SectorTexture and SectorMaterialType.
 /// </summary>
 /// <returns>The material.</returns>
 /// <param name="texture">The texture to get.</param>
 /// <param name="type">The version of the texture to get.</param>
 public Material GetMaterial(SectorTexture texture, SectorMaterialType type) => _materials[texture][type];
コード例 #3
0
 /// <summary>
 /// Creates a new material using the normal one of the given SectorTexture.
 /// </summary>
 /// <param name="texture">The texture to use.</param>
 /// <returns>The new material copied from the base.</returns>
 Material GetFromDefaultMat(SectorTexture texture) => new Material(_materials[texture][SectorMaterialType.Normal]);
コード例 #4
0
 /// <summary>
 /// Adds the default material to the material dictionary.
 /// </summary>
 /// <param name="texture">The enum that will reference it.</param>
 /// <param name="material">The normal material.</param>
 void AddDefaultMat(SectorTexture texture, Material material)
 {
     _materials.Add(texture, new Dictionary <SectorMaterialType, Material> {
         { SectorMaterialType.Normal, material }
     });
 }
コード例 #5
0
        public SectorTextureResult Get(Room room, int x, int z, BlockFace face)
        {
            SectorTexture SectorTexture = SectorTexture.None;
            Vector4       Color;
            Vector4       Overlay = new Vector4();
            bool          Dimmed  = false;

            // Choose base color
            switch (face)
            {
            case BlockFace.PositiveZ_QA:
            case BlockFace.NegativeZ_QA:
            case BlockFace.NegativeX_QA:
            case BlockFace.PositiveX_QA:
            case BlockFace.DiagonalQA:
            case BlockFace.PositiveZ_ED:
            case BlockFace.NegativeZ_ED:
            case BlockFace.NegativeX_ED:
            case BlockFace.PositiveX_ED:
            case BlockFace.DiagonalED:
                Color = ColoringInfo.SectorColorScheme.ColorWallLower;
                if (room.Blocks[x, z].WallPortal != null)
                {
                    Color = ColoringInfo.SectorColorScheme.ColorPortalFace;
                }
                break;

            case BlockFace.PositiveZ_Middle:
            case BlockFace.NegativeZ_Middle:
            case BlockFace.NegativeX_Middle:
            case BlockFace.PositiveX_Middle:
            case BlockFace.DiagonalMiddle:
                Color = ColoringInfo.SectorColorScheme.ColorWall;
                if (room.Blocks[x, z].WallPortal != null)
                {
                    Color = ColoringInfo.SectorColorScheme.ColorPortalFace;
                }
                break;

            case BlockFace.PositiveZ_WS:
            case BlockFace.NegativeZ_WS:
            case BlockFace.NegativeX_WS:
            case BlockFace.PositiveX_WS:
            case BlockFace.DiagonalWS:
            case BlockFace.PositiveZ_RF:
            case BlockFace.NegativeZ_RF:
            case BlockFace.NegativeX_RF:
            case BlockFace.PositiveX_RF:
            case BlockFace.DiagonalRF:
                Color = ColoringInfo.SectorColorScheme.ColorWallUpper;
                if (room.Blocks[x, z].WallPortal != null)
                {
                    Color = ColoringInfo.SectorColorScheme.ColorPortalFace;
                }
                break;

            case BlockFace.Floor:
            case BlockFace.FloorTriangle2:
                // For now, we only render rectangular solid highlights, so use single rectangle solid shape in UsedShapes list, and use first and only entry in returned highlight list.
                var currentHighlights = ColoringInfo.GetColors(ColoringInfo.SectorColorScheme, room, x, z, ProbeAttributesThroughPortals, IgnoredHighlightsForFloor, UsedShapes);
                if (currentHighlights != null)
                {
                    Color = currentHighlights[0].Color;
                }
                else
                {
                    Color = ColoringInfo.SectorColorScheme.ColorFloor;
                }

                if (room.Blocks[x, z].Floor.DiagonalSplit != DiagonalSplit.None)
                {
                    if ((room.Blocks[x, z].Floor.DiagonalSplit > DiagonalSplit.XpZp && face == BlockFace.Floor) ||
                        (room.Blocks[x, z].Floor.DiagonalSplit <= DiagonalSplit.XpZp && face == BlockFace.FloorTriangle2))
                    {
                        Dimmed = true;
                    }
                }
                break;

            case BlockFace.Ceiling:
            case BlockFace.CeilingTriangle2:
                // For now, we only render rectangular solid highlights, so use single rectangle solid shape in UsedShapes list, and use first and only entry in returned highlight list.
                var currentHighlights2 = ColoringInfo.GetColors(ColoringInfo.SectorColorScheme, room, x, z, ProbeAttributesThroughPortals, IgnoredHighlightsForCeiling, UsedShapes);
                if (currentHighlights2 != null)
                {
                    Color = currentHighlights2[0].Color;
                }
                else
                {
                    Color = ColoringInfo.SectorColorScheme.ColorFloor;
                }

                if (room.Blocks[x, z].Ceiling.DiagonalSplit != DiagonalSplit.None)
                {
                    if ((room.Blocks[x, z].Ceiling.DiagonalSplit > DiagonalSplit.XpZp && face == BlockFace.Ceiling) ||
                        (room.Blocks[x, z].Ceiling.DiagonalSplit <= DiagonalSplit.XpZp && face == BlockFace.CeilingTriangle2))
                    {
                        Dimmed = true;
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown BlockFlag encountered.");
            }

            // Draw climbable walls
            switch (face)
            {
            case BlockFace.PositiveX_ED:
            case BlockFace.PositiveX_Middle:
            case BlockFace.PositiveX_QA:
            case BlockFace.PositiveX_RF:
            case BlockFace.PositiveX_WS:
            {
                var lookupBlock = room.ProbeLowestBlock(x + 1, z, ProbeAttributesThroughPortals);
                if (lookupBlock.Block != null && lookupBlock.Block.HasFlag(BlockFlags.ClimbNegativeX))
                {
                    Color = ColoringInfo.SectorColorScheme.ColorClimb;
                }
                break;
            }

            case BlockFace.NegativeX_ED:
            case BlockFace.NegativeX_Middle:
            case BlockFace.NegativeX_QA:
            case BlockFace.NegativeX_RF:
            case BlockFace.NegativeX_WS:
            {
                var lookupBlock = room.ProbeLowestBlock(x - 1, z, ProbeAttributesThroughPortals);
                if (lookupBlock.Block != null && lookupBlock.Block.HasFlag(BlockFlags.ClimbPositiveX))
                {
                    Color = ColoringInfo.SectorColorScheme.ColorClimb;
                }
                break;
            }

            case BlockFace.NegativeZ_ED:
            case BlockFace.NegativeZ_Middle:
            case BlockFace.NegativeZ_QA:
            case BlockFace.NegativeZ_RF:
            case BlockFace.NegativeZ_WS:
            {
                var lookupBlock = room.ProbeLowestBlock(x, z - 1, ProbeAttributesThroughPortals);
                if (lookupBlock.Block != null && lookupBlock.Block.HasFlag(BlockFlags.ClimbPositiveZ))
                {
                    Color = ColoringInfo.SectorColorScheme.ColorClimb;
                }
                break;
            }

            case BlockFace.PositiveZ_ED:
            case BlockFace.PositiveZ_Middle:
            case BlockFace.PositiveZ_QA:
            case BlockFace.PositiveZ_RF:
            case BlockFace.PositiveZ_WS:
            {
                var lookupBlock = room.ProbeLowestBlock(x, z + 1, ProbeAttributesThroughPortals);
                if (lookupBlock.Block != null && lookupBlock.Block.HasFlag(BlockFlags.ClimbNegativeZ))
                {
                    Color = ColoringInfo.SectorColorScheme.ColorClimb;
                }
                break;
            }
            }

            // Draw slopes
            if (DrawSlideDirections)
            {
                if (face == BlockFace.Floor || face == BlockFace.FloorTriangle2)
                {
                    var  slopeDirection = room.Blocks[x, z].GetFloorTriangleSlopeDirections()[face == BlockFace.Floor ? 0 : 1];
                    bool flipped        = room.Blocks[x, z].Floor.SplitDirectionIsXEqualsZ;
                    switch (slopeDirection)
                    {
                    case Direction.PositiveX:
                        SectorTexture = flipped ? SectorTexture.slide_east_flip : SectorTexture.slide_east;
                        break;

                    case Direction.NegativeX:
                        SectorTexture = flipped ? SectorTexture.slide_west_flip : SectorTexture.slide_west;
                        break;

                    case Direction.PositiveZ:
                        SectorTexture = flipped ? SectorTexture.slide_north_flip : SectorTexture.slide_north;
                        break;

                    case Direction.NegativeZ:
                        SectorTexture = flipped ? SectorTexture.slide_south_flip : SectorTexture.slide_south;
                        break;
                    }

                    if (slopeDirection != Direction.None)
                    {
                        Overlay = ColoringInfo.SectorColorScheme.ColorSlideDirection;
                    }
                }
            }

            // Draw illegal slopes
            if (DrawIllegalSlopes)
            {
                if (face == BlockFace.Floor || face == BlockFace.FloorTriangle2)
                {
                    if (room.IsIllegalSlope(x, z))
                    {
                        SectorTexture = SectorTexture.illegal_slope;
                        Overlay       = ColoringInfo.SectorColorScheme.ColorIllegalSlope;
                    }
                }
            }

            // Draw selection
            if (SelectionArea.Contains(new VectorInt2(x, z)))
            {
                SectorTexture = SectorTexture.None;
                Color         = ColoringInfo.SectorColorScheme.ColorSelection; // Selection color
                Overlay       = Color;                                         // Overlay is the same as color if sector is selected

                switch (face)
                {
                case BlockFace.Floor:
                case BlockFace.FloorTriangle2:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_right; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_left; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_sw; break;
                    }
                    break;

                case BlockFace.Ceiling:
                case BlockFace.CeilingTriangle2:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_right; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_left; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_sw; break;
                    }
                    break;

                // South faces ------------------------------------------------------------------------------
                case BlockFace.NegativeZ_QA:
                case BlockFace.NegativeZ_ED:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_nw; break;
                    }
                    break;

                case BlockFace.NegativeZ_WS:
                case BlockFace.NegativeZ_RF:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_sw; break;
                    }
                    break;

                case BlockFace.NegativeZ_Middle:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_up_down; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_nw_sw; break;
                    }
                    break;

                // East faces ------------------------------------------------------------------------------
                case BlockFace.NegativeX_QA:
                case BlockFace.NegativeX_ED:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_ne; break;
                    }
                    break;

                case BlockFace.NegativeX_WS:
                case BlockFace.NegativeX_RF:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_se; break;
                    }
                    break;

                case BlockFace.NegativeX_Middle:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_up_down; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.arrow_ne_se; break;
                    }
                    break;

                // North faces ------------------------------------------------------------------------------
                case BlockFace.PositiveZ_QA:
                case BlockFace.PositiveZ_ED:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;

                case BlockFace.PositiveZ_WS:
                case BlockFace.PositiveZ_RF:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;

                case BlockFace.PositiveZ_Middle:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_up_down; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;

                // West faces ------------------------------------------------------------------------------
                case BlockFace.PositiveX_QA:
                case BlockFace.PositiveX_ED:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_up; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_ne; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_nw; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;

                case BlockFace.PositiveX_WS:
                case BlockFace.PositiveX_RF:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_down; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_se; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_sw; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;

                case BlockFace.PositiveX_Middle:
                    switch (SelectionArrow)
                    {
                    case ArrowType.EdgeN: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.EdgeE: SectorTexture = SectorTexture.arrow_up_down; break;

                    case ArrowType.EdgeS: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.EdgeW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNW: SectorTexture = SectorTexture.cross; break;

                    case ArrowType.CornerNE: SectorTexture = SectorTexture.arrow_ne_se; break;

                    case ArrowType.CornerSE: SectorTexture = SectorTexture.arrow_nw_sw; break;

                    case ArrowType.CornerSW: SectorTexture = SectorTexture.cross; break;
                    }
                    break;
                }
            }

            return(new SectorTextureResult
            {
                Color = Color,
                Overlay = Overlay,
                SectorTexture = SectorTexture,
                Dimmed = Dimmed,
                Hidden = room.Hidden && HideHiddenRooms,
                Selected = (SelectionArea.Contains(new VectorInt2(x, z))),
                Highlighted = (HighlightArea.Contains(new VectorInt2(x, z)))
            });
        }