public static bool CreatUIPrefabInstance(int nInstanceId, int nLine) { if (Selection.activeObject == null) { return(false); } if (!(Selection.activeObject is GameObject)) { return(false); } //获取选定路径 var rAssetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (string.IsNullOrEmpty(rAssetPath)) { return(false); } var rCatalog = UtilTool.GetParentPath(rAssetPath); //UIPrefab是否在指定路径下 if (!UtilTool.PathIsSame(rCatalog, UI_PREFAB_FOLDER)) { return(false); } //场景中是否存在Active的UIRoot GameObject rUIRoot = GameObject.Find("UIRoot"); if (!rUIRoot) { //创建UIRoot rUIRoot = AssetDatabase.LoadAssetAtPath(UI_ROOT_PATH, typeof(GameObject)) as GameObject; PrefabUtility.InstantiatePrefab(rUIRoot); } //寻找根节点 var rPopupRoot = GameObject.Find("__popupRoot").transform; var rDynamicRoot = GameObject.Find("__dynamicRoot").transform; //获取选择的prefab var rUIPrefab = AssetDatabase.LoadAssetAtPath(rAssetPath, typeof(GameObject)) as GameObject; //获取脚本 //var rViewContainer = rUIPrefab.GetComponent<ViewContainer>(); //if (rViewContainer) //{ // var curState = rViewContainer.CurState; // var rInstance = null as GameObject; // bool bIsDynamic = curState == ViewState.dispatch || curState == ViewState.overlap || curState == ViewState.fixing; // AddItem(bIsDynamic, rDynamicRoot, rPopupRoot, rUIPrefab, out rInstance); //} return(true); }
/// <summary> /// 得到StreamingAssets下的资源目录路径 /// </summary> public string GetStreamingFile(Platform rPlatform) { int rPlatformIndex = (int)rPlatform; bool isEditor = PlatformIsEditor[rPlatformIndex]; string rRootDir = isEditor ? UtilTool.GetParentPath(Application.dataPath) : Application.streamingAssetsPath; string rPlatformName = PlatformNames[rPlatformIndex]; #if UNITY_ANDROID && UNITY_EDITOR rPlatformName = "Android"; #endif return(rRootDir + "/Assetbundles/" + rPlatformName + "_Assetbundles/"); }
public static bool CreatUIPrefabInstance(int nInstanceId, int nLine) { if (Selection.activeObject == null) { return(false); } if (!(Selection.activeObject is GameObject)) { return(false); } //获取选定路径 var rAssetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (string.IsNullOrEmpty(rAssetPath)) { return(false); } var rCatalog = UtilTool.GetParentPath(rAssetPath); //UIPrefab是否在指定路径下 if (!UtilTool.PathIsSame(rCatalog, mUIPrefabAssetsDir)) { return(false); } //场景中是否存在Active的UIRoot GameObject rUIRoot = GameObject.Find("UIRoot"); if (!rUIRoot) { //创建UIRoot rUIRoot = AssetDatabase.LoadAssetAtPath(mUIRootPath, typeof(GameObject)) as GameObject; PrefabUtility.InstantiatePrefab(rUIRoot); } //寻找根节点 var rDynamicRoot = GameObject.Find("__dynamicRoot").transform; //获取选择的prefab var rUIPrefab = AssetDatabase.LoadAssetAtPath(rAssetPath, typeof(GameObject)) as GameObject; //获取脚本 AddItem(rDynamicRoot, rUIPrefab); return(true); }