public static string GetTmpPrefabPath(string prefab) { string folder = EditorTool.GetFolder(prefab); string filename = EditorTool.GetFileName(prefab, false); int index = 1; string tmp_prefab = folder + filename + "_" + (index++).ToString() + s_prefab_postfix; while (File.Exists(tmp_prefab)) { tmp_prefab = folder + filename + "_" + (index++).ToString() + s_prefab_postfix; } return(tmp_prefab); }
public static string GetLayoutFullPath(string prefab) { string fullpath = prefab.ToLower(); if (!fullpath.StartsWith(ConfigTool.Instance.prefab_prefix.ToLower())) { Debug.LogError("Prefab·��\"" + prefab + "\"���淶"); return(""); } fullpath = fullpath.Substring(ConfigTool.Instance.prefab_prefix.Length); fullpath = ConfigTool.Instance.layout_prefix + fullpath; fullpath = EditorTool.GetProjectFullpath() + fullpath; fullpath = EditorTool.MakesureFolderExit(fullpath) + EditorTool.GetFileName(prefab, false) + s_layout_postfix; return(fullpath); }
public static GameObject LoadLayout(string layout_fullpath, bool for_edit) { string name = EditorTool.GetFileName(layout_fullpath, false); string prefab = LayoutTool.GetPrefabPath(layout_fullpath); if (string.IsNullOrEmpty(prefab)) { return(null); } string tmp_prefab = LayoutTool.GetTmpPrefabPath(prefab); string tmp_prefab_fullname = EditorTool.GetSystemFullpath(tmp_prefab); EditorTool.FileWriteable(tmp_prefab_fullname); File.Copy(layout_fullpath, tmp_prefab_fullname, true); AssetDatabase.Refresh(); //GameObject tmp_prefab_obj = Resources.LoadAssetAtPath(tmp_prefab, typeof(GameObject)) as GameObject; #if UNITY_EDITOR GameObject tmp_prefab_obj = AssetDatabase.LoadAssetAtPath(tmp_prefab, typeof(GameObject)) as GameObject; #else GameObject tmp_prefab_obj = Resources.Load(Trans2ResourcesPath(tmp_prefab), typeof(GameObject)) as GameObject; #endif if (tmp_prefab_obj == null) { Debug.LogError("������Layout�ļ�\"" + layout_fullpath + "\""); FileUtil.DeleteFileOrDirectory(tmp_prefab); AssetDatabase.Refresh(); return(null); } GameObject prefab_obj = Object.Instantiate(tmp_prefab_obj) as GameObject; if (for_edit) { prefab_obj.transform.parent = Root.transform; } prefab_obj.transform.localPosition = tmp_prefab_obj.transform.position; prefab_obj.layer = s_editor_layer; prefab_obj.name = name; RemoveInvalidNode(prefab_obj); FileUtil.DeleteFileOrDirectory(tmp_prefab); AssetDatabase.Refresh(); return(prefab_obj); }