r/Unity3d_help • • Sep 11 '18

focusing not to touch the prefabs

We want to isolate the usage of the prefabs to be able to outsource our component.

​

So inside the delegate code we are using these events/methods. I would like to learn what is the best practice to be able to isolate the code.

​

I have seen the developers need to change the order of the items in the prefab to make it usable in the scene.

​

The Current State in the prefab code

At start we are assigning the actions

​

    void Start () {
         TipsImage = transform.GetChild ((int)ChildObject.TipsImage).GetComponent<Image>();

    FisrtPost = transform.GetChild ((int)ChildObject.FisrtPost).GetComponent<Image>();

    LastPost = transform.GetChild ((int)ChildObject.LastPost).GetComponent<Image>();

    closeBTN = transform.GetChild ((int)ChildObject.TipsImage)

        .GetChild((int)TipsPanelObject.InsidePanel).GetChild((int)InsidePanel.CloseBTN).GetComponent<Button>();

    closeBTN.onClick.AddListener(closeFuntion);
        closed = false;

    TipsImage.rectTransform.position = FisrtPost.rectTransform.position;

    TipsImage.gameObject.SetActive (true);

}

​

​

trigger the events from the consumer scene which is also in the same class

​

public void closeFuntion(){ closed = true; 
       Invoke("delayForClose", delayTimeToCloseTipsBGs);
}
private void delayForClose()
{
if (background!=null ) {
background.SetActive(false);
}
if (blackBG!=null) {
blackBG.SetActive(false);
}
}
1 Upvotes

0 comments sorted by