private void DebugDrawHoverWidget()
    {
        IWidget widget = _gameWorldController.View.WidgetEventDispatcher.MouseOverWidget;

        if (widget != null)
        {
            Vector3 boxUL =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX, widget.WorldY, 0.0f);
            Vector3 boxUR =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX + widget.Width, widget.WorldY, 0.0f);
            Vector3 boxLR =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX + widget.Width, widget.WorldY + widget.Height, 0.0f);
            Vector3 boxLL =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    widget.WorldX, widget.WorldY + widget.Height, 0.0f);

            Debug.DrawLine(boxUL, boxUR, Color.red);
            Debug.DrawLine(boxUR, boxLR, Color.red);
            Debug.DrawLine(boxLR, boxLL, Color.red);
            Debug.DrawLine(boxLL, boxUL, Color.red);

            _widgetLabel.SetLocalPosition(widget.WorldX + (widget.Width / 2.0f), widget.WorldY + (widget.Height / 2.0f));
            _widgetLabel.Text    = widget.GetType().Name;
            _widgetLabel.Visible = true;
        }
    }
    public override void UpdateWorldPosition()
    {
        base.UpdateWorldPosition();

        if (m_gameObject != null)
        {
            m_gameObject.transform.position =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(this.WorldX, this.WorldY, this.Depth);
        }
    }
    public void SetPortraitId(uint portraitId)
    {
        for (int portraitIdx = 0; portraitIdx < ClientGameConstants.GetPortraitCount(); portraitIdx++)
        {
            m_portraits[portraitIdx].Visible = (portraitIdx == portraitId);
        }

        m_nameTextField.Text  = ClientGameConstants.GetDefaultNameForPicture(portraitId);
        m_genderLabel.Text    = GameConstants.GetGenderString(ClientGameConstants.GetGenderForPicture(portraitId));
        m_archetypeLabel.Text = GameConstants.GetArchetypeString(ClientGameConstants.GetArchetypeForPicture(portraitId));
    }
Beispiel #4
0
    public void ShowCharacterData(CharacterData characterEntry)
    {
        for (int portraitIndex = 0; portraitIndex < ClientGameConstants.GetPortraitCount(); portraitIndex++)
        {
            m_portraits[portraitIndex].Visible = (portraitIndex == characterEntry.picture_id);
        }

        m_nameText.Text      = characterEntry.character_name;
        m_genderText.Text    = GameConstants.GetGenderString(ClientGameConstants.GetGenderForPicture((uint)characterEntry.picture_id));
        m_archetypeText.Text = GameConstants.GetArchetypeString(ClientGameConstants.GetArchetypeForPicture((uint)characterEntry.picture_id));
        m_levelText.Text     = characterEntry.power_level.ToString();
        m_gameText.Text      = characterEntry.game_name;

        m_characterDataGroup.Visible = true;
    }
Beispiel #5
0
    public override void UpdateWorldPosition()
    {
        base.UpdateWorldPosition();

        if (m_spriteObject != null)
        {
            float   spriteZ        = 0.0f;
            Vector3 vertexPosition =
                ClientGameConstants.ConvertPixelPositionToVertexPosition(
                    this.WorldX - (m_style.Width / 2.0f),
                    this.WorldY - m_style.BoundsHeight,
                    spriteZ);

            m_spriteObject.transform.position = vertexPosition;
        }
    }
    private void DebugCursorPosition()
    {
        Point2d pixelPosition  = GetMousePixelPosition();
        Point2d screenPosition = ClientGameConstants.ConvertPixelPositionToScreenPosition(pixelPosition);
        Point3d roomPosition   = GameConstants.ConvertPixelPositionToRoomPosition(pixelPosition);
        Vector3 vertexPosition = ClientGameConstants.ConvertPixelPositionToVertexPosition(pixelPosition.x, pixelPosition.y, 0.0f);
        NavRef  navRef         = _gameWorldController.OverlayController.View.CurrentNavRef;

        _positionLabel.Text =
            string.Format(
                "Pixel: {0},{1}\nScreen: {2}, {3}\nRoom: {4}, {5}, {6}\nVertex: {7}, {8}, {9}\nNavRef: {10}",
                pixelPosition.x, pixelPosition.y,
                screenPosition.x, screenPosition.y,
                roomPosition.x, roomPosition.y, roomPosition.z,
                vertexPosition.x, vertexPosition.y, vertexPosition.z,
                navRef.NavCellIndex);
        _positionLabel.Visible = true;
    }
    private void DebugDrawNavMesh()
    {
        RoomKey roomKey = _gameWorldController.Model.CurrentGame.CurrentRoomKey;

        AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

        if (navMesh != null)
        {
            for (uint navCellIndex = 0; navCellIndex < navMesh.GetNavCellCount(); navCellIndex++)
            {
                int connectivityId = navMesh.GetNavCellConnectivityID(navCellIndex);

                if (connectivityId != AsyncRPGSharedLib.Navigation.NavMesh.EMPTY_NAV_CELL)
                {
                    for (MathConstants.eDirection direction = MathConstants.eDirection.first;
                         direction < MathConstants.eDirection.count;
                         direction++)
                    {
                        if (!navMesh.NavCellHasNeighbor(navCellIndex, direction))
                        {
                            Point3d portalLeft, portalRight;
                            Vector3 portalVertexLeft, portalVertexRight;

                            navMesh.ComputePointsOnNavCellSide(navCellIndex, direction, out portalLeft, out portalRight);
                            portalVertexLeft  = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalLeft);
                            portalVertexRight = ClientGameConstants.ConvertRoomPositionToVertexPosition(portalRight);

                            Debug.DrawLine(
                                portalVertexLeft,
                                portalVertexRight,
                                Color.yellow,
                                0.0f,   // duration
                                false); // depth test
                        }
                    }
                }
            }
        }
    }
Beispiel #8
0
    public CharacterThumbnailWidget(
        WidgetGroup parentGroup,
        CharacterThumbnailStyle style,
        CharacterData characterData)
        : base(parentGroup, style.BackgroundWidth, style.BackgroundHeight, 0, 0)
    {
        new ImageWidget(this, style.BackgroundWidth, style.BackgroundHeight, style.Background, 0.0f, 0.0f);

        // Background for the character info
        string      portraitResource = ClientGameConstants.GetResourceNameForPicture((uint)characterData.picture_id);
        ImageWidget portrait         =
            new ImageWidget(
                this,
                style.PortraitWidth, style.PortraitHeight,
                Resources.Load <Texture>(portraitResource),
                5, 5);

        // Character name
        LabelWidget nameLabel =
            new LabelWidget(
                this,
                style.LabelWidth, style.LabelHeight,
                portrait.LocalX + portrait.Width + 3, 0,
                characterData.character_name);

        // Character info
        string archetype  = GameConstants.GetArchetypeString(ClientGameConstants.GetArchetypeForPicture((uint)characterData.picture_id));
        string infoString = "Lvl " + characterData.power_level.ToString() + " " + archetype;

        new LabelWidget(
            this,
            style.LabelWidth, style.LabelHeight,
            portrait.LocalX + portrait.Width + 3,
            nameLabel.LocalY + nameLabel.Height,
            infoString);

        this.Visible = false;
    }
Beispiel #9
0
    private void CreatePortalHotspots(RoomData room)
    {
        foreach (RoomPortal portalEntry in room.RoomPortals)
        {
            AABB2d  boundingBox = new AABB2d();
            Point2d screenP0    = ClientGameConstants.ConvertRoomPositionToScreenPosition(portalEntry.boundingBox.Min);
            Point2d screenP1    = ClientGameConstants.ConvertRoomPositionToScreenPosition(portalEntry.boundingBox.Max);

            boundingBox.EnclosePoint(screenP0);
            boundingBox.EnclosePoint(screenP1);

            m_hotspotWidgets.Add(
                new HotspotWidget(m_rootWidgetGroup,
                                  "Portal" + portalEntry.portal_id.ToString(),
                                  boundingBox.Extents.i,
                                  boundingBox.Extents.j,
                                  boundingBox.Min.x,
                                  boundingBox.Min.y,
                                  new HotspotInfo {
                hotspotType = eHotspotType.portal, hotspotEntity = portalEntry
            }));
        }
    }
Beispiel #10
0
    private void CreateEnergyTankHotspots(RoomData room)
    {
        foreach (EnergyTankData energyTankData in room.EnergyTankMap.Values)
        {
            AABB2d  boundingBox = new AABB2d();
            Point2d screenP0    = ClientGameConstants.ConvertRoomPositionToScreenPosition(energyTankData.boundingBox.Min);
            Point2d screenP1    = ClientGameConstants.ConvertRoomPositionToScreenPosition(energyTankData.boundingBox.Max);

            boundingBox.EnclosePoint(screenP0);
            boundingBox.EnclosePoint(screenP1);

            m_hotspotWidgets.Add(
                new HotspotWidget(m_rootWidgetGroup,
                                  "EnergyTank" + energyTankData.energy_tank_id.ToString(),
                                  boundingBox.Extents.i,
                                  boundingBox.Extents.j,
                                  boundingBox.Min.x,
                                  boundingBox.Min.y,
                                  new HotspotInfo {
                hotspotType = eHotspotType.energy_tank, hotspotEntity = energyTankData
            }));
        }
    }
    public void Start()
    {
        // Create the root widget group
        m_rootWidgetGroup =
            new WidgetGroup(
                null,
                panelWidth, panelHeight,
                Screen.width / 2 - panelWidth / 2, Screen.height / 2 - panelHeight / 2);
        m_rootWidgetGroup.SetWidgetEventListener(this);

        // Background for the game info
        new ImageWidget(m_rootWidgetGroup, panelWidth, panelHeight, panelTexture, 0.0f, 0.0f);

        // Character portraits
        m_portraits = new List <ImageWidget>();
        for (int portraitIndex = 0; portraitIndex < ClientGameConstants.GetPortraitCount(); portraitIndex++)
        {
            ImageWidget portrait = new ImageWidget(
                m_rootWidgetGroup,
                portraitWidth, portraitHeight,
                Resources.Load <Texture>(ClientGameConstants.GetResourceNameForPicture((uint)portraitIndex)),
                PORTRAIT_X, PORTRAIT_Y);

            portrait.Visible = false;
            m_portraits.Add(portrait);
        }

        float statsX = PORTRAIT_X + portraitWidth + BORDER_WIDTH;
        float statsY = PORTRAIT_Y;

        // Character Name
        new LabelWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX, statsY, "Name:");
        m_nameTextField =
            new TextEntryWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX + labelWidth, statsY, "");
        m_nameTextField.Restrict  = @"[^0-9A-Za-z]";
        m_nameTextField.MaxLength = 12;

        // Character Gender
        statsY += labelHeight;
        new LabelWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX, statsY, "Gender:");
        m_genderLabel = new LabelWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX + labelWidth, statsY, "");

        // Character Archetype
        statsY += labelHeight;
        new LabelWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX, statsY, "Archetype:");
        m_archetypeLabel = new LabelWidget(m_rootWidgetGroup, labelWidth, labelHeight, statsX + labelWidth, statsY, "");

        // Creation Status Label
        m_statusLabel           = new LabelWidget(m_rootWidgetGroup, panelWidth, panelHeight, 0, panelHeight - labelHeight, "");
        m_statusLabel.Alignment = TextAnchor.UpperCenter;

        // Create Button
        m_createButton =
            new ButtonWidget(
                m_rootWidgetGroup,
                buttonStyle,
                panelWidth / 3 - buttonStyle.Width / 2, m_statusLabel.LocalY - buttonStyle.Height - 5,
                "Create");

        // Cancel Button
        m_cancelButton =
            new ButtonWidget(
                m_rootWidgetGroup,
                buttonStyle,
                (2 * panelWidth) / 3 - buttonStyle.Width / 2, m_statusLabel.LocalY - buttonStyle.Height - 5,
                "Cancel");

        // Previous Portrait Button
        m_previousPortraitButton =
            new ButtonWidget(
                m_rootWidgetGroup,
                buttonStyle,
                m_createButton.LocalX, m_createButton.LocalY - buttonStyle.Height - 5,
                "<");

        // Next Portrait Button
        m_nextPortraitButton =
            new ButtonWidget(
                m_rootWidgetGroup,
                buttonStyle,
                m_cancelButton.LocalX, m_cancelButton.LocalY - buttonStyle.Height - 5,
                ">");
    }
    public void LoadMap(
        int[] tileIndices,
        uint tileRows,
        uint tileColomns,
        string tileSetMaterialName,
        float tilePixelWidth,
        float tilePixelHeight)
    {
        ClearMap();

        TileRows        = tileRows;
        TileColomns     = tileColomns;
        TilePixelWidth  = tilePixelWidth;
        TilePixelHeight = tilePixelHeight;
        TileSet         = tileSetMaterialName;

        m_gameObject =
            new GameObject(
                "TileGrid_" + this.Name + "_" + tileSetMaterialName,
                typeof(MeshRenderer),
                typeof(MeshFilter));
        m_gameObject.transform.position = Vector3.zero;
        m_gameObject.transform.rotation = Quaternion.identity;

        m_meshFilter   = m_gameObject.GetComponent <MeshFilter>();
        m_meshRenderer = m_gameObject.GetComponent <MeshRenderer>();

        m_material = Resources.Load <Material>("Gfx/TileSets/" + tileSetMaterialName + "_material");
        m_meshRenderer.renderer.material = m_material;
        m_mesh = m_meshFilter.mesh;

        // Generate a regular grid of vertices
        // Top to Bottom, Left to Right
        {
            List <Vector3> vertices      = new List <Vector3>();
            List <Vector2> UVs           = new List <Vector2>();
            List <int>     indices       = new List <int>();
            uint           tileListIndex = 0;

            for (int rowIndex = 0; rowIndex < tileRows; ++rowIndex)
            {
                for (int colIndex = 0; colIndex < tileColomns; ++colIndex)
                {
                    int tileIndex = tileIndices[tileListIndex];

                    if (tileListIndex >= 0)
                    {
                        int startVertexIndex = vertices.Count;

                        // Create 4 vertices in a square, starting from the upper left, going clockwise
                        vertices.Add(
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                this.WorldX + (float)(TilePixelWidth * colIndex),
                                this.WorldY + (float)(TilePixelHeight * rowIndex),
                                this.Depth));
                        vertices.Add(
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                this.WorldX + (float)(TilePixelWidth * (colIndex + 1)),
                                this.WorldY + (float)(TilePixelHeight * rowIndex),
                                this.Depth));
                        vertices.Add(
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                this.WorldX + (float)(TilePixelWidth * (colIndex + 1)),
                                this.WorldY + (float)(TilePixelHeight * (rowIndex + 1)),
                                this.Depth));
                        vertices.Add(
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                this.WorldX + (float)(TilePixelWidth * colIndex),
                                this.WorldY + (float)(TilePixelHeight * (rowIndex + 1)),
                                this.Depth));

                        // Create the UVs for each vertex
                        {
                            float   tileTexelWidth  = 0;
                            float   tileTexelHeight = 0;
                            Vector2 tileTexelOrigin =
                                ComputeTexelInfoForTileIndex(
                                    tileIndex, out tileTexelWidth, out tileTexelHeight);

                            // NOTE: UVs origin is in the lower left of the texture
                            //  _______(1,1)
                            //  |      |
                            //  |      |
                            //  |______|
                            // (0,0)
                            UVs.Add(tileTexelOrigin);
                            UVs.Add(new Vector2(tileTexelOrigin.x + tileTexelWidth, tileTexelOrigin.y));
                            UVs.Add(new Vector2(tileTexelOrigin.x + tileTexelWidth, tileTexelOrigin.y - tileTexelHeight));
                            UVs.Add(new Vector2(tileTexelOrigin.x, tileTexelOrigin.y - tileTexelHeight));
                        }


                        // Create the indices for the two triangles that make up the square
                        indices.Add(startVertexIndex + 0);
                        indices.Add(startVertexIndex + 1);
                        indices.Add(startVertexIndex + 2);
                        indices.Add(startVertexIndex + 0);
                        indices.Add(startVertexIndex + 2);
                        indices.Add(startVertexIndex + 3);
                    }

                    tileListIndex++;
                }
            }

            m_mesh.vertices  = vertices.ToArray();
            m_mesh.uv        = UVs.ToArray();
            m_mesh.triangles = indices.ToArray();
        }
    }
    private void DebugDrawTestVisibility()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point3d startWorldPos = entity.Position;

            Point2d endPixelPos = GetMousePixelPosition();
            Point3d endWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(endPixelPos);

            // Draw the target nav cell
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef startNavRef = navMesh.ComputeNavRefAtPoint(startWorldPos);
                NavRef endNavRef   = navMesh.ComputeNavRefAtPoint(endWorldPos);

                if (startNavRef.IsValid && endNavRef.IsValid)
                {
                    bool  canSee     = navMesh.NavRefCanSeeOtherNavRef(startNavRef, endNavRef);
                    Color debugColor = canSee ? Color.green : Color.red;

                    // Draw a box around the nav cell
                    {
                        Point3d endCenterWorldPos = navMesh.ComputeNavCellCenter((uint)endNavRef.NavCellIndex);
                        Point2d endCenterPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(endCenterWorldPos);
                        float   halfWidth         = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                        Vector3 boxUL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxUR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y - halfWidth, 0.0f);
                        Vector3 boxLR =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x + halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);
                        Vector3 boxLL =
                            ClientGameConstants.ConvertPixelPositionToVertexPosition(
                                endCenterPixelPos.x - halfWidth, endCenterPixelPos.y + halfWidth, 0.0f);

                        Debug.DrawLine(boxUL, boxUR, debugColor);
                        Debug.DrawLine(boxUR, boxLR, debugColor);
                        Debug.DrawLine(boxLR, boxLL, debugColor);
                        Debug.DrawLine(boxLL, boxUL, debugColor);
                    }

                    // Update the visibility status label
                    _visibilityStatusLabel.Text = canSee ? "VISIBLE" : "INVISIBLE";
                    _visibilityStatusLabel.SetLocalPosition(endPixelPos.x, endPixelPos.y);
                    _visibilityStatusLabel.Color   = debugColor;
                    _visibilityStatusLabel.Visible = true;

                    // Render the ray-cast line
                    {
                        Vector3 startVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(startWorldPos);
                        Vector3 endVertex   = ClientGameConstants.ConvertRoomPositionToVertexPosition(endWorldPos);

                        Debug.DrawLine(startVertex, endVertex, debugColor);
                    }
                }
            }
        }
    }
    private void DebugDrawTestPath()
    {
        int             characterID = _gameWorldController.Model.CurrentCharacterID;
        RoomKey         roomKey     = _gameWorldController.Model.CurrentGame.CurrentRoomKey;
        CharacterEntity entity      = _gameWorldController.Model.GetCharacterEntity(characterID);

        if (entity != null)
        {
            Point2d mousePixelPos = GetMousePixelPosition();
            Point3d mouseWorldPos = GameConstants.ConvertPixelPositionToRoomPosition(mousePixelPos);

            // Draw the target nav cell
            string targetLabel = "";
            AsyncRPGSharedLib.Navigation.NavMesh navMesh = PathfindingSystem.GetNavMesh(roomKey);

            if (navMesh != null)
            {
                NavRef navRef = navMesh.ComputeNavRefAtPoint(mouseWorldPos);

                if (navRef.IsValid)
                {
                    Point3d centerWorldPos = navMesh.ComputeNavCellCenter((uint)navRef.NavCellIndex);
                    Point2d centerPixelPos = GameConstants.ConvertRoomPositionToPixelPosition(centerWorldPos);
                    float   halfWidth      = (float)GameConstants.NAV_MESH_PIXEL_SIZE / 2.0f;

                    Vector3 boxUL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxUR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y - halfWidth, 0.0f);
                    Vector3 boxLR =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x + halfWidth, centerPixelPos.y + halfWidth, 0.0f);
                    Vector3 boxLL =
                        ClientGameConstants.ConvertPixelPositionToVertexPosition(
                            centerPixelPos.x - halfWidth, centerPixelPos.y + halfWidth, 0.0f);

                    Debug.DrawLine(boxUL, boxUR, Color.blue);
                    Debug.DrawLine(boxUR, boxLR, Color.blue);
                    Debug.DrawLine(boxLR, boxLL, Color.blue);
                    Debug.DrawLine(boxLL, boxUL, Color.blue);

                    targetLabel = "\nNavCell=" + navRef.NavCellIndex.ToString();
                }

                // Attempt to compute a path from the active player to the mouse
                _pathComputer.BlockingPathRequest(navMesh, roomKey, entity.Position, mouseWorldPos);

                // Update the path status label
                {
                    if (_pathComputer.ResultCode == PathComputer.eResult.success)
                    {
                        _pathStatusLabel.Text  = "VALID" + targetLabel;
                        _pathStatusLabel.Color = Color.green;
                    }
                    else
                    {
                        _pathStatusLabel.Text  = _pathComputer.ResultCode + targetLabel;
                        _pathStatusLabel.Color = Color.red;
                    }

                    _pathStatusLabel.SetLocalPosition(mousePixelPos.x, mousePixelPos.y);
                    _pathStatusLabel.Visible = true;
                }

                // Render the raw path
                for (int stepIndex = 1; stepIndex < _pathComputer.FinalPath.Count; stepIndex++)
                {
                    Point3d previousPoint      = _pathComputer.FinalPath[stepIndex - 1].StepPoint;
                    Point3d currentPoint       = _pathComputer.FinalPath[stepIndex].StepPoint;
                    Vector3 previousPixelPoint = ClientGameConstants.ConvertRoomPositionToVertexPosition(previousPoint);
                    Vector3 currentPixelPoint  = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentPoint);

                    Debug.DrawLine(previousPixelPoint, currentPixelPoint, Color.green);
                }
            }
        }
    }
    private void CreateMesh()
    {
        ClearMesh();

        m_gameObject = new GameObject("VisionCone_" + this.Name, typeof(MeshRenderer), typeof(MeshFilter));
        m_gameObject.transform.position = Vector3.zero;
        m_gameObject.transform.rotation = Quaternion.identity;

        m_meshFilter   = m_gameObject.GetComponent <MeshFilter>();
        m_meshRenderer = m_gameObject.GetComponent <MeshRenderer>();

        m_material = Resources.Load <Material>("Gfx/Materials/VisionCone");
        m_meshRenderer.renderer.material = m_material;
        m_mesh = m_meshFilter.mesh;

        {
            List <Vector3> vertices    = new List <Vector3>();
            List <Vector3> normals     = new List <Vector3>();
            List <Vector2> UVs         = new List <Vector2>();
            List <int>     indices     = new List <int>();
            List <Color>   colors      = new List <Color>();
            int            vertexCount = 0;

            float coneHalfRadians = (ConeAngle / 2.0f) * MathConstants.DEGREES_TO_RADIANS;
            float angleStep       = coneHalfRadians / 10;

            Point3d originRoomPoint  = new Point3d(0.0f, 0.0f, this.Depth);
            Point3d currentRoomPoint = new Point3d();
            Point3d nextRoomPoint    = new Point3d();

            Vector3 vertexOffset = ClientGameConstants.ConvertRoomPositionToVertexPosition(originRoomPoint);

            for (float angle = -coneHalfRadians; angle < coneHalfRadians; angle += angleStep)
            {
                float nextAngle    = angle + angleStep;
                float cosAngle     = (float)Math.Cos((float)angle);
                float sinAngle     = (float)Math.Sin((float)angle);
                float cosNextAngle = (float)Math.Cos((float)nextAngle);
                float sinNextAngle = (float)Math.Sin((float)nextAngle);

                currentRoomPoint.Set(Range * cosAngle, Range * sinAngle, Depth);
                nextRoomPoint.Set(Range * cosNextAngle, Range * sinNextAngle, Depth);

                Vector3 currentVertex = ClientGameConstants.ConvertRoomPositionToVertexPosition(currentRoomPoint) - vertexOffset;
                Vector3 nextVertex    = ClientGameConstants.ConvertRoomPositionToVertexPosition(nextRoomPoint) - vertexOffset;

                // Pie wedges
                {
                    // Create a triangle for each pie slice
                    vertices.Add(Vector3.zero);
                    vertices.Add(currentVertex);
                    vertices.Add(nextVertex);

                    // All normals face the camera
                    normals.Add(zVector);
                    normals.Add(zVector);
                    normals.Add(zVector);

                    // Make the visibility arc partially transparent
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);

                    // Create the UVs for each vertex

                    // NOTE: UVs origin is in the lower left of the texture
                    //  _______(1,1)
                    //  |      |
                    //  |      |
                    //  |______|
                    // (0,0)
                    UVs.Add(textureCenter);
                    UVs.Add(new Vector2(0.5f + 0.5f * cosAngle, 0.5f + 0.5f * sinAngle));
                    UVs.Add(new Vector2(0.5f + 0.5f * cosNextAngle, 0.5f + 0.5f * sinNextAngle));


                    // Create the indices for the triangle that makes up the pie slice
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                }

                // Edge highlight
                {
                    // Create a triangle for each pie slice
                    vertices.Add(currentVertex * 0.99f);
                    vertices.Add(currentVertex);
                    vertices.Add(nextVertex);
                    vertices.Add(currentVertex * 0.99f);
                    vertices.Add(nextVertex);
                    vertices.Add(nextVertex * 0.99f);

                    // All normals face the camera
                    normals.Add(zVector);
                    normals.Add(zVector);
                    normals.Add(zVector);
                    normals.Add(zVector);
                    normals.Add(zVector);
                    normals.Add(zVector);

                    // Make the visibility arc partially transparent
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);
                    colors.Add(transparentWhite);

                    UVs.Add(textureCenter);
                    UVs.Add(textureCenter);
                    UVs.Add(textureCenter);
                    UVs.Add(textureCenter);
                    UVs.Add(textureCenter);
                    UVs.Add(textureCenter);

                    // Create the indices for the triangle that makes up the pie slice
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                    indices.Add(vertexCount++);
                }
            }

            m_mesh.vertices  = vertices.ToArray();
            m_mesh.uv        = UVs.ToArray();
            m_mesh.triangles = indices.ToArray();
            m_mesh.normals   = normals.ToArray();
            m_mesh.colors    = colors.ToArray();
        }
    }
 public GameConstants.eGender GetGender()
 {
     return(ClientGameConstants.GetGenderForPicture(m_pictureId));
 }
Beispiel #17
0
    public CharacterPanelWidget(WidgetGroup parentGroup, CharacterPanelStyle style, float x, float y)
        : base(parentGroup, style.BackgroundWidth, style.BackgroundHeight, x, y)
    {
        // Background for the character info
        new ImageWidget(this, style.BackgroundWidth, style.BackgroundHeight, style.Background, 0, 0);

        // Create a group to hold the data
        m_characterDataGroup = new WidgetGroup(this, style.BackgroundWidth, style.BackgroundHeight, 0.0f, 0.0f);

        // Character Portraits
        m_portraits = new List <ImageWidget>();
        for (int portraitIndex = 0; portraitIndex < ClientGameConstants.GetPortraitCount(); portraitIndex++)
        {
            ImageWidget portrait =
                new ImageWidget(
                    m_characterDataGroup,
                    style.PortraitWidth,
                    style.PortraitHeight,
                    Resources.Load(ClientGameConstants.GetResourceNameForPicture((uint)portraitIndex)) as Texture,
                    5.0f, 5.0f);

            portrait.Visible = false;
            m_portraits.Add(portrait);
        }

        {
            float statsX = style.PortraitWidth + 10.0f;
            float statsY = 5.0f;

            // Character name
            new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX, statsY, "Name:");
            m_nameText =
                new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX + style.LabelWidth, statsY, "");

            // Character gender
            statsY += style.LabelHeight;
            new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX, statsY, "Gender:");
            m_genderText =
                new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX + style.LabelWidth, statsY, "");

            // Character archetype
            statsY += style.LabelHeight;
            new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX, statsY, "Archetype:");
            m_archetypeText =
                new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX + style.LabelWidth, statsY, "");

            // Level
            statsY += style.LabelHeight;
            new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX, statsY, "Level:");
            m_levelText =
                new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX + style.LabelWidth, statsY, "");

            // Game
            statsY += style.LabelHeight;
            new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX, statsY, "Game:");
            m_gameText =
                new LabelWidget(m_characterDataGroup, style.LabelWidth, style.LabelHeight, statsX + style.LabelWidth, statsY, "");
        }

        // By default this isn't visible
        HideCharacterData();
    }
    public void SelectPreviousPicture()
    {
        uint portraitCount = (uint)ClientGameConstants.GetPortraitCount();

        m_pictureId = (m_pictureId + portraitCount - 1) % portraitCount;
    }
 public void SelectNextPicture()
 {
     m_pictureId = (m_pictureId + 1) % (uint)ClientGameConstants.GetPortraitCount();
 }
 public GameConstants.eArchetype GetArchetype()
 {
     return(ClientGameConstants.GetArchetypeForPicture(m_pictureId));
 }