public T InstantiateUiView <T>( string prefabIdentity, Vector2?position, UiViewLayer uiViewLayer) where T : UiView { var prefabToCreate = Prefabs.FirstOrDefault(reference => reference.Identity == prefabIdentity).Prefab; if (prefabToCreate == null) { throw new PrefabNotFoundException(prefabIdentity); } var prefab = Instantiate(prefabToCreate, Vector3.zero, Quaternion.identity, Canvas.transform); prefab.transform.localPosition = position ?? prefabToCreate.transform.localPosition; prefab.name = prefabIdentity; var prefabComponent = prefab.GetComponent <T>(); if (prefabComponent == null) { throw new PrefabDoesntHaveSpecifiedComponent(prefabIdentity); } prefabComponent.SetUiViewLayer(uiViewLayer); return(prefabComponent); }
public static int GetUiViewLayerZPosition(this UiViewLayer uiViewLayer) { switch (uiViewLayer) { case UiViewLayer.Glass: return(-9); case UiViewLayer.Foreground: return(-5); case UiViewLayer.Midground: return(0); case UiViewLayer.Background: return(5); default: throw new Exception("UiViewLayer not supported"); } }
public T InstantiateEntityView <T, TE>( string prefabIdentity, TE entityReference, Vector2?position, UiViewLayer uiViewLayer) where T : EntityView <TE> where TE : Entity { var prefabComponent = InstantiateUiView <T>(prefabIdentity, position, uiViewLayer); var entityView = (EntityView <TE>)prefabComponent; entityView.SetEntityReference(entityReference); var prefab = prefabComponent.gameObject; prefab.name = entityView.EntityReference.ToIdentity(IdentityType.Basic); return(prefabComponent); }
public void SetUiViewLayer(UiViewLayer uiViewLayer) { this.UiViewLayer = uiViewLayer; }
public static int GetOrderInUi(UiViewLayer uiViewLayer, UiViewLayerOrder orderInUi) { return(GetUiViewLayerZPosition(uiViewLayer) + (int)orderInUi); }