public static void AddUIItem <TUIItem, TStyle, TType>(GameObject wrapperObj) where TUIItem : BaseItem { BaseUIItemWrapper <TUIItem, TStyle, TType> baseUIItemWrapper = wrapperObj.GetComponent <BaseUIItemWrapper <TUIItem, TStyle, TType> >(); GameObject uiItemObj = CreatePrefabAtPath(GetAssetItemPath <TUIItem, TStyle, TType>(wrapperObj));; TUIItem uiItem = uiItemObj.GetComponent <TUIItem>(); if (IsMultiAssetType(typeof(TUIItem))) { (uiItem as MultiAssetsItem <TStyle, TType>).SetItem(baseUIItemWrapper.Style, baseUIItemWrapper.Type); } else if (IsSingleAssetType(typeof(TUIItem))) { (uiItem as SingleAssetItem <TType>).SetItem(baseUIItemWrapper.Type); } else if (IsBaseItemType(typeof(TUIItem))) { uiItem.ReshowItem(baseUIItemWrapper.Type as BaseItemData); } if (uiItemObj != null) { GameObjectUtility.SetParentAndAlign(uiItemObj, wrapperObj); Undo.RegisterCreatedObjectUndo(uiItemObj, "Create" + uiItemObj.name); } }
private static string GetAssetItemPath <TUIItem, TStyle, TType>(GameObject wrapperObj) where TUIItem : BaseItem { string typeName = typeof(TUIItem).Name; string assetSubPath = "AssetItems/" + typeName + "/" + typeName; string itemSubPath = "Items/"; if (IsMultiAssetType(typeof(TUIItem))) { return(m_UIItemPrefabRootPath + assetSubPath + ".prefab"); } else if (IsSingleAssetType(typeof(TUIItem))) { string styleName = ""; BaseUIItemWrapper <TUIItem, TStyle, TType> baseUIItemWrapper = wrapperObj.GetComponent <BaseUIItemWrapper <TUIItem, TStyle, TType> >(); styleName = Enum.GetName(typeof(TStyle), baseUIItemWrapper.Style); return(string.Format(m_UIItemPrefabRootPath + assetSubPath + "_{0}.prefab", styleName)); } else if (IsBaseItemType(typeof(TUIItem))) { BaseUIItemWrapper <TUIItem, TStyle, TType> baseUIItemWrapper = wrapperObj.GetComponent <BaseUIItemWrapper <TUIItem, TStyle, TType> >(); string styleName = Enum.GetName(typeof(TStyle), baseUIItemWrapper.Style); return(m_UIItemPrefabRootPath + itemSubPath + styleName + ".prefab"); } Debug.Log("Without prefab path:" + typeof(TUIItem).Name); return(""); }