示例#1
0
    public MobWidget(WidgetGroup parentGroup, MobWidgetStyle style, MobData mobData) :
        base(
            parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).x,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).y) // Gross
    {
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        m_style = style;

        m_title =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                -m_style.BoundsHeight - style.LabelHeight,            // local y
                mobType.Label);                                       // text
        m_title.Alignment = TextAnchor.UpperCenter;

        m_energy =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                0,                                                    // local y
                "");                                                  // text
        m_energy.Alignment = TextAnchor.UpperCenter;
        this.Energy        = mobData.energy;

        // Create the sprite game object
        {
            string archetype      = mobType.Name;
            string gameObjectPath = "Gfx/Sprites/Enemies/" + archetype + "/" + archetype + "_sprite";

            m_spriteObject =
                GameObject.Instantiate(
                    Resources.Load <GameObject>(gameObjectPath)) as GameObject;
            m_spriteAnimator = m_spriteObject.GetComponent <Animator>();

            UpdateWorldPosition();
        }

        // Create the dialog label
        m_dialog =
            new LabelWidget(
                this,
                style.DialogWidth,                                     // width
                style.DialogHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.DialogWidth / 2.0f), // local x
                m_title.LocalY - style.DialogHeight,                   // local y
                "");                                                   // text
        m_dialog.FontSize  = 14;
        m_dialog.Color     = Color.red;
        m_dialog.Alignment = TextAnchor.UpperCenter;
        m_dialog.Visible   = false;

        // Set the initial animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);

        // Create the vision cone
        m_visionCone =
            new VisionConeWidget(
                this,
                mobType.Name + mobData.mob_id.ToString(),
                mobType.VisionConeDistance,
                mobType.VisionConeAngleDegrees,
                0.0f,
                0.0f,
                0.0f);
        m_visionCone.ConeFacing = MathConstants.GetAngleForDirection(MathConstants.eDirection.down);
    }
示例#2
0
    // Gross
    public MobWidget(WidgetGroup parentGroup, MobWidgetStyle style, MobData mobData)
        : base(parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).x,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).y)
    {
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        m_style = style;

        m_title =
            new LabelWidget(
                this,
                style.LabelWidth, // width
                style.LabelHeight, // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                -m_style.BoundsHeight - style.LabelHeight, // local y
                mobType.Label); // text
        m_title.Alignment = TextAnchor.UpperCenter;

        m_energy =
            new LabelWidget(
                this,
                style.LabelWidth, // width
                style.LabelHeight, // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                0, // local y
                ""); // text
        m_energy.Alignment = TextAnchor.UpperCenter;
        this.Energy = mobData.energy;

        // Create the sprite game object
        {
            string archetype = mobType.Name;
            string gameObjectPath = "Gfx/Sprites/Enemies/" + archetype + "/" + archetype + "_sprite";

            m_spriteObject =
                GameObject.Instantiate(
                    Resources.Load<GameObject>(gameObjectPath)) as GameObject;
            m_spriteAnimator = m_spriteObject.GetComponent<Animator>();

            UpdateWorldPosition();
        }

        // Create the dialog label
        m_dialog =
            new LabelWidget(
                this,
                style.DialogWidth, // width
                style.DialogHeight, // height
                (m_style.Width / 2.0f) - (m_style.DialogWidth / 2.0f), // local x
                m_title.LocalY - style.DialogHeight, // local y
                ""); // text
        m_dialog.FontSize = 14;
        m_dialog.Color = Color.red;
        m_dialog.Alignment = TextAnchor.UpperCenter;
        m_dialog.Visible = false;

        // Set the initial animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);

        // Create the vision cone
        m_visionCone =
            new VisionConeWidget(
                this,
                mobType.Name + mobData.mob_id.ToString(),
                mobType.VisionConeDistance,
                mobType.VisionConeAngleDegrees,
                0.0f,
                0.0f,
                0.0f);
        m_visionCone.ConeFacing = MathConstants.GetAngleForDirection(MathConstants.eDirection.down);
    }