Ejemplo n.º 1
0
        public void DrawHands(float weaponAngle, Vector3 weaponPosition, CompWeaponExtensions compWeaponExtensions,
                              bool flipped)
        {
            Material handMat =
                GraphicDatabase.Get <Graphic_Single>("Overlays/Hand", ShaderDatabase.CutoutSkin, Vector2.one,
                                                     pawn.story.SkinColor).MatSingle;

            Mesh handsMesh = MeshPool.GridPlane(Vector2.one);

            if (compWeaponExtensions.FirstHandPosition != Vector3.zero)
            {
                Vector3 handPosition = compWeaponExtensions.FirstHandPosition;
                if (flipped)
                {
                    handPosition = -handPosition;
                    // keep z the same
                    handPosition.z = -handPosition.z;
                }

                Graphics.DrawMesh(handsMesh,
                                  weaponPosition + handPosition.RotatedBy(weaponAngle),
                                  Quaternion.AngleAxis(weaponAngle, Vector3.up), handMat, 0);
            }
            if (compWeaponExtensions.SecondHandPosition != Vector3.zero)
            {
                Vector3 handPosition = compWeaponExtensions.SecondHandPosition;
                if (flipped)
                {
                    handPosition = -handPosition;
                    // keep z the same
                    handPosition.z = -handPosition.z;
                }

                Graphics.DrawMesh(handsMesh,
                                  weaponPosition + handPosition.RotatedBy(weaponAngle),
                                  Quaternion.AngleAxis(weaponAngle, Vector3.up), handMat, 0);
            }

            //// for debug
            //var centerMat =
            //    GraphicDatabase.Get<Graphic_Single>("Overlays/Hand", ShaderDatabase.CutoutSkin, Vector2.one,
            //        Color.red).MatSingle;

            //Graphics.DrawMesh(handsMesh, weaponPosition + new Vector3(0, 0.001f, 0),
            //    Quaternion.AngleAxis(weaponAngle, Vector3.up), centerMat, 0);
        }
Ejemplo n.º 2
0
        // draws hands on equipment and adjusts aiming angle position, if corresponding Comp is specified
        public new void DrawEquipmentAiming(Thing equipment, Vector3 weaponDrawLoc, float aimAngle)
        {
            CompWeaponExtensions compWeaponExtensions = pawn.equipment.Primary.TryGetComp <CompWeaponExtensions>();

            float   weaponAngle;
            Vector3 weaponPositionOffset = Vector3.zero;

            Mesh weaponMesh;
            bool flipped;
            bool aiming = Aiming();

            if (aimAngle > 110 && aimAngle < 250)
            {
                flipped = true;

                // flip weapon texture
                weaponMesh = MeshPool.GridPlaneFlip(equipment.Graphic.drawSize);

                if (!aiming && compWeaponExtensions != null)
                {
                    weaponPositionOffset += compWeaponExtensions.WeaponPositionOffset;
                    // flip x position offset
                    weaponPositionOffset.x = -weaponPositionOffset.x;
                }

                weaponAngle  = aimAngle - 180f;
                weaponAngle -= !aiming
                    ? equipment.def.equippedAngleOffset
                    : (compWeaponExtensions?.AttackAngleOffset ?? 0);
            }
            else
            {
                flipped = false;

                weaponMesh = MeshPool.GridPlane(equipment.Graphic.drawSize);

                if (!aiming && compWeaponExtensions != null)
                {
                    weaponPositionOffset += compWeaponExtensions.WeaponPositionOffset;
                }

                weaponAngle  = aimAngle;
                weaponAngle += !aiming
                    ? equipment.def.equippedAngleOffset
                    : (compWeaponExtensions?.AttackAngleOffset ?? 0);
            }

            if (pawn.Rotation == Rot4.West || pawn.Rotation == Rot4.North)
            {
                // draw weapon beneath the pawn
                weaponPositionOffset += new Vector3(0, -0.5f, 0);
            }

            // weapon angle and position offsets based on current attack animation sequence
            DoAttackAnimationOffsets(ref weaponAngle, ref weaponPositionOffset, flipped);

            Graphic_StackCount graphic_StackCount = equipment.Graphic as Graphic_StackCount;
            Material           weaponMat          = graphic_StackCount != null
                ? graphic_StackCount.SubGraphicForStackCount(1, equipment.def).MatSingle
                : equipment.Graphic.MatSingle;

            // draw weapon
            Graphics.DrawMesh(weaponMesh, weaponDrawLoc + weaponPositionOffset,
                              Quaternion.AngleAxis(weaponAngle, Vector3.up),
                              weaponMat, 0);

            // draw hands on equipment, if CompWeaponExtensions defines them
            if (compWeaponExtensions != null)
            {
                DrawHands(weaponAngle, weaponDrawLoc + weaponPositionOffset, compWeaponExtensions, flipped);
            }
        }