Managing complex prefab hierarchies in Unity3D

I asked this question in several places and still have not completely understood it, so perhaps some smart people will have an idea of ​​how to approach this.

What is the best way to maintain a deep nested prefabricated hierarchy in a project? Say we have several graphic screens consisting of small, common components. For simplicity, let me call the former "views", and the latter - "components". Reflects on semantics (for example, viewing inventory, store view); components are configured, but business logic is not tied to them (for example, a button only cares about the OnTap callback / event handler).

Both views and components can be nested.

GUI views must be reused in multiple scenes.

The main problem with this approach in Unity is that any nested hierarchy that once turned into a assembly file loses references to its child collections, as in this (fully compiled but still valid) example:

- storeView - UIViewHeader - UIHeaderLabel<Text> - UIList - UIListItem - UIThumbnail - UITitleLabel<Text> - UISubTitleLabel<Text> - UIPrimaryButton<Button> - ...

I would like to keep all of these small UI * components in separate builds, but also keep the prefab storeView so that I can easily add it to different scenes. Unfortunately, once we create the prefab storeView, all UF * prefab links will be lost. Given this, we could try a different approach, in which, instead of having a preliminary collection of the storeView with the content, we keep it empty and select one of these several options:

  • View
    • cons: , script, dev.
    • pros: storeView , ,
  • storeView ,
    • : , storeView .
    • pros: , prefab , (imho, , )
  • storeView
    • : , UX ( QA, ..).
    • : , .
  • Prefab Evolution
    • cons: , Nested Prefabs, ? ( , ?)
    • : () , , . , .
  • :
    • : , - , -, ,
    • : , . , , , , ( , ).

, v. , *:

, prefab . UIView subviews (Cocoa), React , - React/Cycle/Elm/-, FRP (, , - , , , , ..).

  • cons: , Unity , , ( :))
  • : , prefabs , (, , , Unity)

  • , , Unity, , 1% .

, , Unity, , () -, , , .

+4
1

. , , .

SceneManager.LoadScene LoadSceneMode.Additive factory, :

public class UIStoreView
{
    public static UIStoreView Instance()
    {
        SceneManager.LoadScene("UIStoreView", LoadSceneMode.Additive);
        return GameObject.Find("UIStoreView");
    }
}

- , storeView = UIStoreView.Instance();.

/ , , , - / , ( , ).

+1

Source: https://habr.com/ru/post/1662868/


All Articles