Cobbler Multi -System Automation Installation

2023-01-30   ES  

一,

GameObject.SetActive () in

Unity 3D and Monobehaviour.Onenable (), Monobehaviour.ondisable ()
Actually the relationship between these three is very simple:
SetActive (TRUE), which triggers Monobehavior.Onenable () event. Even if the object was before the activeSelf == TRUE, the incident would still happen;
setActive (false), which triggers Monobehavior.ondisable () incident. Even if the object was before the activeSELF == false, the event would still happen;

2, problem

In actual development, the use of SetActive is very frequent, so setting the setActive (true), and the object of the SETIVESELF == FALSE, set the setActive (FALSE To. It is normal, or it is inevitable.

This problem comes. For example, we have called SetActive (TRUE) many times in a row, and will also respond to OneNable () multiple times. That is to say, when the state of maintaining the object is that the state of ActiveSelf == True has not changed, the OneNable () method is executed multiple times. At this time, there will be a problem, and of course it may not have a problem. This is mainly based on the logic of people’s implementation in oneNable ().

Same, SetActive (FALSE), and onDisable () have the same problem.

three. Solution

In fact, the method of solving this problem is also very simple, that is, every time SetActive () detects the ActiveSelf state.
We can package a setActive method to replace it:

static public void SetActive(GameObject go, bool state) 
{
    if (go == null)
    {
        return;
    }

    if (go.activeSelf != state)
    {
        go.SetActive(state);
    }
}

source

Related Posts

SpringBoot @Onetoone solves the two -way dead cycle of JPA/Return to JSON data dead loop

HF-NET (2) Global feature positioning and local feature matching based on HF-Net

WeChat Pay Pit

Create uboot environment variable BIN file

Cobbler Multi -System Automation Installation

Random Posts

Announcement on closing the credit card recharge channel to the Alipay account

linux simply read and write a file

MATLAB implements the variable threshold processing of the image segmentation block, and uses the OTSU method for dual value

R language DPLYR package: high -efficiency data processing function (Filter, Groupby, Mutate, Summarise)

Docker lightweight management tool Portainer Xinghe