public static bool SaveLayout(string layout_fullpath, GameObject inst) { string prefab = LayoutTool.GetPrefabPath(layout_fullpath); string tmp_prefab = LayoutTool.GetTmpPrefabPath(prefab); PrefabUtility.CreatePrefab(tmp_prefab, inst); AssetDatabase.SaveAssets(); EditorTool.FileWriteable(layout_fullpath); File.Copy(EditorTool.GetSystemFullpath(tmp_prefab), layout_fullpath, true); FileUtil.DeleteFileOrDirectory(tmp_prefab); AssetDatabase.Refresh(); return(true); }
public Texture2D GetBackTexture(string filename) { if (!File.Exists(filename)) { return(null); } string back_texture_fullname = EditorTool.GetSystemFullpath(back_texture); EditorTool.FileWriteable(back_texture_fullname); File.Copy(filename, back_texture_fullname, true); AssetDatabase.Refresh(); return(AssetDatabase.LoadAssetAtPath(back_texture, typeof(Texture2D)) as Texture2D); }
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); }