コード例 #1
0
        public static Vector2 MuzzlePosition(Vector2 sourceLoc, Verb_LaunchProjectileCE instance)
        {
            //    Log.Message("MuzzlePosition CE");
            Vector2 result = sourceLoc;
            //    Log.Message("MuzzlePosition CE sourceLoc: " + sourceLoc);
            string msg      = "CE MuzzlePosition {0}: {1}, aimAngle: {2}";
            float  aimAngle = 0f;

            if (instance.EquipmentSource is Thing equipment)
            {
                //    Log.Message("MuzzlePosition CE EquipmentSource: " + equipment);
                Thing   launcher    = instance.Shooter;
                Vector3 origin      = new Vector3(sourceLoc.x, 0, sourceLoc.y);
                Vector3 destination = instance.CurrentTarget.Cell.ToVector3Shifted();
                if ((destination - origin).MagnitudeHorizontalSquared() > 0.001f)
                {
                    aimAngle = (destination - origin).AngleFlat();
                }
                IDrawnWeaponWithRotation rotation = equipment as IDrawnWeaponWithRotation;
                if (rotation != null)
                {
                    //    Log.Message(rotation + " is IDrawnWeaponWithRotation with RotationOffset: " + rotation.RotationOffset);
                    aimAngle += rotation.RotationOffset;
                }
                Log.Message(string.Format(msg, "Original", sourceLoc, aimAngle));
                GunDrawExtension gunDrawExtension = equipment.def.GetModExtensionFast <GunDrawExtension>();
                if (gunDrawExtension != null)
                {
                    Log.Message("gunDrawExtension");
                }
                else
                if (equipment.def.HasComp(typeof(OgsCompOversizedWeapon.CompOversizedWeapon)))
                {
                    OgsCompOversizedWeapon.CompOversizedWeapon compOversized = equipment.TryGetCompFast <OgsCompOversizedWeapon.CompOversizedWeapon>();
                    if (compOversized != null)
                    {
                        bool    DualWeapon     = compOversized.Props != null && compOversized.Props.isDualWeapon;
                        Vector3 offsetMainHand = default(Vector3);
                        Vector3 offsetOffHand  = default(Vector3);
                        float   offHandAngle   = aimAngle;
                        float   mainHandAngle  = aimAngle;

                        OgsCompOversizedWeapon.OversizedUtil.SetAnglesAndOffsets(equipment, equipment as ThingWithComps, aimAngle, launcher, ref offsetMainHand, ref offsetOffHand, ref offHandAngle, ref mainHandAngle, true, DualWeapon && !compOversized.FirstAttack);
                        Vector3 vector = DualWeapon && !compOversized.FirstAttack ? offsetOffHand : offsetMainHand;
                        //    Vector3 vector = compOversized.AdjustRenderOffsetFromDir(equippable.PrimaryVerb.CasterPawn, !compOversized.FirstAttack);
                        origin += vector;
                    }
                }
                origin = equipment.MuzzlePositionFor(origin, aimAngle);
                result = new Vector2(origin.x, origin.z);
            }
            Log.Message(string.Format(msg, "result", result, aimAngle));
            return(result);
        }
コード例 #2
0
            private static void DrawMesh(Mesh mesh, Vector3 position, Quaternion rotation, Material mat, int layer, Thing eq, float aimAngle)
            {
                GunDrawExtension drawData = eq.def.GetModExtension <GunDrawExtension>() ?? new GunDrawExtension();
                Matrix4x4        matrix   = new Matrix4x4();
                Vector3          scale    = new Vector3(drawData.DrawSize.x, 1, drawData.DrawSize.y);
                Vector3          posVec   = new Vector3(drawData.DrawOffset.x, 0, drawData.DrawOffset.y);

                if (aimAngle > 200 && aimAngle < 340)
                {
                    posVec.x *= -1;
                }

                matrix.SetTRS(position + posVec.RotatedBy(rotation.eulerAngles.y), rotation, scale);
                Graphics.DrawMesh(mesh, matrix, mat, layer);
            }