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条)