ConditionChecker¶
A component meant to be attached on any GameObject via Unity.
This is a general purpose component to essentially disable or move offscreen a GameObject that doesn't fufill certain conditions regarding flags slots and regionalsflags. It implements this using MainManager.CheckIfCanExist which is used throughout the game and it is the system NPCControl also uses for disabling themselves when their flags requirements aren't met. The purpose of using this component is it allows to have the same logic, but done completely standalone from any GameObject in Unity. It has a Start where most of the logic happen and a LateUpdate that may move the GameObject offscreen after the fact.
It has several public fields to configure its behavior:
requires
: The require parameter to send to MainManager.CheckIfCanExist which is a list of flags slots that must be true for the GameObject to exist (can be empty or have its first element be negative to have no required flag slots)limit
: The limit parameter to send to MainManager.CheckIfCanExist which is a list of flags slots where any among them must be false for the GameObject to exist (can be empty or have its first element be negative to have no limit flag slots)regionID
: The regionalflag parameter to send to MainManager.CheckIfCanExist which is a regionalflag slot of the current area that must be false for the GameObject to exist (can be negative to have no regionalflag slot requirement)spriteflagchange
: A flag slot that if true on Start, it will cause the GameObject's SpriteRenderer (if it exists)'s sprite to change tospritetochange
. If the value is negative, this feature is disabledactivepos
: The local position (or position ifworldpos
is true) to set the GameObject on LateUpdate if it fails the MainManager.CheckIfCanExist requirements. If the magnitude of this is 0.1 or below, LateUpdate checks effectively are disabledstartpos
(not editable via the inspector): This contains the GameObject position it had on Start, but it is exposed programmatically (meant for reading)startangle
(not editable via the inspector): This contains the GameObject angles it had on Start, but it is exposed programmatically (meant for reading)spritetochange
: The sprite to change the GameObject's SpriteRenderer to if thespriteflagchange
check is fufilled and the feature is enableddontdelete
: If true, the GameObject won't be disabled on Start if it fails to meet the MainManager.CheckIfCanExist requirementsworldpos
: This determines what theactivepos
will do if the MainManager.CheckIfCanExist requirements during LateUpdate. If it's true, the GameObject's position is set toactivepos
and if it's false, the GameObject's local position is set toactivepos
pauseactive
: If this is true, the MainManager.CheckIfCanExist requirements are never disabled on LateUpdate, even when the game is paused after 20.0 frames
Essentially, there's 2 parts divided in the Start and LateUpdate:
- Start does 2 things:
- If
dontdelete
is false, MainManager.CheckIfCanExist is called (this feature is disabled otherwise). If it succeeds, nothing happens, but if it fails, what happens depends on if the GameObject where if it has an NPCControl, itsentity
.iskill
is set to true which will effectively cause NPCControl to disable it. If it's not an NPCControl, it's disabled and moved offscreen at 9999.0 in y with the Animator component destroyed if it exists - If
spriteflagchange
isn't negative and the GameObject has a SpriteRenderer, its sprite is set tospritetochange
- If
- LateUpdate only manages one thing if
activepos
's magnitude is above 0.1 (otherwise, this feature is disabled). It involves the GameObject toactivepos
(by position or local position depending onworldpos
) if another MainManager.CheckIfCanExist check fails. This is only checked every 5 LateUpdate cycles, but after 20.0 frames, checks are disabled if the game is paused (unlesspauseactive
is true in which case checks happens even if the game is paused). It's essentially a way to move the GameObject out of the way after the fact if it's not destroyed by then