public static async Task <T> ShowWidget <T>(AssetReference assetReference, IWidgetProperties properties) where T : AWidget { if (activeWidgets.ContainsKey(assetReference)) { AWidget returnWidget = activeWidgets[assetReference]; returnWidget.ApplyProperties(properties); return((T)returnWidget); } else if (inactiveWidgetPool.ContainsKey(assetReference)) { AWidget widget = inactiveWidgetPool[assetReference]; widget.ApplyProperties(properties); widget.Show(); activeWidgets.Add(assetReference, widget); inactiveWidgetPool.Remove(assetReference); return((T)widget); } else { GameObject result = await assetReference.LoadAssetAsync <GameObject>().Task; AWidget assetWidget = result.GetComponent <AWidget>(); GameObject parentLayer; if (assetWidget.GetComponentType() == UiComponentType.Static) { parentLayer = staticUiLayer; } else if (assetWidget.GetComponentType() == UiComponentType.Dynamic) { parentLayer = dynamicUiLayer; } else if (assetWidget.GetComponentType() == UiComponentType.Overlay) { parentLayer = overlayUiLayer; } else { Debug.LogError("Layer has not been defined for Widget: " + assetWidget.name); return(null); } AWidget newWidget = GameObject.Instantiate(assetWidget, parentLayer.transform); newWidget.Open(); newWidget.ApplyProperties(properties); activeWidgets.Add(assetReference, newWidget); return((T)newWidget); } }
public void ApplyProperties(IWidgetProperties newProperties) { properties = newProperties; OnNewProperties(); }