Как использовать методы из [RegisterTypeinil2cpp] в MelonLoader?C#

Место общения программистов C#
Anonymous
Как использовать методы из [RegisterTypeinil2cpp] в MelonLoader?

Сообщение Anonymous »

Я сталкиваюсь с проблемой в проекте Melonloader-Mod, где метод SetData класса BasicShooter, кажется, не оценивается правильно, когда я создаю создание компонента через код. Вот фрагмент кода: < /p>
BasicShooter basicShooter = prefab.AddComponent();
basicShooter.SetData("Shooter", 0, 0, 0);
< /code>
Однако, когда я использую тот же метод в Melonloader с UnityExplorer, он работает так же, как и ожидалось. Это несоответствие загадочно, и я хотел бы понять, почему это происходит. < /P>
[RegisterTypeInIl2Cpp]
public class BasicShooter : MonoBehaviour
{

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

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

public Bullet AnimShooting()
{
Vector3 position = transform.Find(ShootPos).transform.position;
Bullet bullet = Board.Instance.GetComponent().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();
public string ShootPos { get; set; }
public int theBulletType { get; set; }
public int theBulletWay { get; set; }
public int theBulletDamage { get; set; }
}


Подробнее здесь: https://stackoverflow.com/questions/794 ... elonloader

Вернуться в «C#»