public static void createPrefab(string name) { string path = "Assets/Resources/Atlas"; string prefabName = "Common"; string prefabExtName = "prefab"; string resFullPath = string.Format("{0}.{1}", Path.Combine(path, prefabName), prefabExtName); resFullPath = UtilPath.normalPath(resFullPath); Type[] comArr = new Type[1]; comArr[0] = typeof(Image); GameObject prefabRootGo = new GameObject(prefabName, comArr); Image image = prefabRootGo.GetComponent <Image>(); Sprite[] allSpritesArr = AtlasPrefabUtil.loadAllSprite(); image.sprite = allSpritesArr[0]; // 创建预制,并且添加到编辑器中,以便进行检查 PrefabUtility.CreatePrefab(resFullPath, prefabRootGo, ReplacePrefabOptions.ConnectToPrefab); //UnityEngine.Object emptyPrefab = PrefabUtility.CreateEmptyPrefab(resFullPath); //PrefabUtility.ReplacePrefab(prefabRootGo, emptyPrefab, ReplacePrefabOptions.ConnectToPrefab); //刷新编辑器 AssetDatabase.Refresh(); }
public void addSprite2SO(SOSpriteList soSprite) { string assetsImagePath = ExportUtil.convFullPath2AssetsPath(m_fullPath); Sprite[] allSpritesArr = AtlasPrefabUtil.loadAllSprite(assetsImagePath); soSprite.addSprite(m_subPathNoExt, allSpritesArr[0]); }
public void addAnimator2SO(SOAnimatorController soAnimator) { string assetsImagePath = ExportUtil.convFullPath2AssetsPath(m_fullPath); RuntimeAnimatorController asset = AtlasPrefabUtil.loadAllAsset <RuntimeAnimatorController>(assetsImagePath); soAnimator.addAnimator(m_subPathNoExt, asset); }
// inPath 类似这样 Assets/Res/Image/UI/Common/denglu_srk.png , outPath = Assets/Prefabs/Resources/Atlas/aaa.asset public void packSprite(string inPath, string outPath) { m_soSprite = ScriptableObject.CreateInstance <SOSpriteList>(); Sprite[] spriteArr = AtlasPrefabUtil.loadAllSprite(inPath); m_soSprite.addSprite("aaa", spriteArr[0]); AssetDatabase.CreateAsset(m_soSprite, outPath); }
public void addImageComponent(GameObject go_) { GameObject parGo = go_; GameObject curGo = null; for (int idx = 0; idx < m_pathArr.Length; ++idx) { curGo = new GameObject(m_pathArr[idx]); curGo.transform.SetParent(parGo.transform); parGo = curGo; } Image image = curGo.AddComponent <Image>(); string assetsImagePath = ExportUtil.convFullPath2AssetsPath(m_fullPath); Sprite[] allSpritesArr = AtlasPrefabUtil.loadAllSprite(assetsImagePath); image.sprite = allSpritesArr[0]; }