fixed logic bug and added cache for nolan
This commit is contained in:
@@ -147,6 +147,7 @@ void Misc::Fly(float speed) {
|
|||||||
if (localPlayer == nullptr) return;
|
if (localPlayer == nullptr) return;
|
||||||
|
|
||||||
auto nb = Player::GetNolan();
|
auto nb = Player::GetNolan();
|
||||||
|
|
||||||
app::Transform* _transform = Unity::Transform::Get(localPlayer);
|
app::Transform* _transform = Unity::Transform::Get(localPlayer);
|
||||||
|
|
||||||
if (_transform) {
|
if (_transform) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ app::GameObject* Player::GetLocalPlayer()
|
|||||||
app::GameObject* currentPlayer = playerList->vector[i];
|
app::GameObject* currentPlayer = playerList->vector[i];
|
||||||
|
|
||||||
if (IsNull((app::Object_1*)currentPlayer)) {
|
if (IsNull((app::Object_1*)currentPlayer)) {
|
||||||
return nullptr;
|
continue;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (app::GameObject_GetComponentByName) {
|
if (app::GameObject_GetComponentByName) {
|
||||||
@@ -55,14 +55,10 @@ app::GameObject* Player::GetLocalPlayer()
|
|||||||
if (nbComponent) {
|
if (nbComponent) {
|
||||||
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
||||||
|
|
||||||
if (nb) {
|
if (nb && IsLocalPlayer(nb)) {
|
||||||
if (IsLocalPlayer(nb)) {
|
cachedLocalPlayer = currentPlayer;
|
||||||
return currentPlayer;
|
return currentPlayer;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,24 +68,28 @@ app::GameObject* Player::GetLocalPlayer()
|
|||||||
|
|
||||||
app::NolanBehaviour* Player::GetNolan()
|
app::NolanBehaviour* Player::GetNolan()
|
||||||
{
|
{
|
||||||
app::GameObject* localPlayer = Player::GetLocalPlayer();
|
static app::NolanBehaviour* cachedNolan = nullptr;
|
||||||
app::String* NolanBehaviourStr = reinterpret_cast<app::String*>(il2cpp_string_new("NolanBehaviour"));
|
static app::GameObject* lastLocalPlayer = nullptr;
|
||||||
|
|
||||||
if (localPlayer) {
|
app::GameObject* localPlayer = Player::GetLocalPlayer();
|
||||||
|
if (localPlayer == nullptr) return nullptr;
|
||||||
|
|
||||||
|
if (lastLocalPlayer != localPlayer) {
|
||||||
|
app::String* NolanBehaviourStr = reinterpret_cast<app::String*>(il2cpp_string_new("NolanBehaviour"));
|
||||||
if (app::GameObject_GetComponentByName) {
|
if (app::GameObject_GetComponentByName) {
|
||||||
app::Component* nbComponent = app::GameObject_GetComponentByName(localPlayer, NolanBehaviourStr, nullptr);
|
app::Component* nbComponent = app::GameObject_GetComponentByName(localPlayer, NolanBehaviourStr, nullptr);
|
||||||
|
|
||||||
if (nbComponent) {
|
if (nbComponent) {
|
||||||
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
app::NolanBehaviour* nb = reinterpret_cast<app::NolanBehaviour*>(nbComponent);
|
||||||
|
|
||||||
if (nb) {
|
if (nb) {
|
||||||
return nb;
|
cachedNolan = nb;
|
||||||
|
lastLocalPlayer = localPlayer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return cachedNolan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user