c# - How to use methods from [RegisterTypeInIl2Cpp] in MelonLoader? - Stack Overflow

I'm encountering an issue in MelonLoader-Mod project where the SetData method of BasicShooter clas

I'm encountering an issue in MelonLoader-Mod project where the SetData method of BasicShooter class does not seem to evaluate correctly when I instantiate the component via code. Here’s a snippet of the code:

BasicShooter basicShooter = prefab.AddComponent<BasicShooter>();
basicShooter.SetData("Shooter", 0, 0, 0);

However, when I use the same method in MelonLoader with UnityExplorer, it works as expected. This discrepancy is puzzling, and I would like to understand why this is happening.

[RegisterTypeInIl2Cpp]
public class BasicShooter : MonoBehaviour
{

    public BasicShooter() : base(ClassInjector.DerivedConstructorPointer<BasicShooter>()) => ClassInjector.DerivedConstructorBody(this);

    public BasicShooter(IntPtr i) : base(i)
    {
    }

    public Bullet AnimShooting()
    {
        Vector3 position = transform.Find(ShootPos).transform.position;
        Bullet bullet = Board.Instance.GetComponent<CreateBullet>().SetBullet((float)(position.x + 0.1f), position.y, plant.thePlantRow, theBulletType, theBulletWay);
        bullet.theBulletDamage = theBulletDamage;
        return bullet;
    }
    public void SetData(string shootPos, int bulletType, int bulletWay, int bulletDamage)
    {
        (ShootPos, theBulletType, theBulletWay, theBulletDamage) = (shootPos, bulletType, bulletWay, bulletDamage);
        MelonLogger.Msg($"SetData {ShootPos} {theBulletType} {theBulletWay} {theBulletDamage}");
    }

    public Shooter plant => gameObject.GetComponent<Shooter>();
    public string ShootPos { get; set; }
    public int theBulletType { get; set; }
    public int theBulletWay { get; set; }
    public int theBulletDamage { get; set; }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744867536a4598064.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信