/// <summary> /// 创建Unity 序列化资源Asset /// </summary> /// <typeparam name="T"></typeparam> public static void CreateUnityAsset <T>() where T : ScriptableObject { T asset = ScriptableObject.CreateInstance <T>(); string assetPathAndName = EditorDialogUtility.SaveFileDialog("保存Asset资源", "", "", "asset"); Debug.Log("assetPathAndName= " + assetPathAndName); assetPathAndName = assetPathAndName.Substring(assetPathAndName.IndexOf("Assets")); Debug.Log("CreateUnityAsset >>>path :" + assetPathAndName); AssetDatabase.CreateAsset(asset, assetPathAndName); //创建资源Asset AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
//[MenuItem("Assets/创建精灵 SpriteRender 预制体")] public static void CreateSpriteRender() { UnityEngine.Object selectObj = Selection.activeObject; string path = AssetDatabase.GetAssetPath(selectObj); // Debug.Log(path + " " + System.IO.Path.GetExtension(path).ToLower()); if (System.IO.Path.GetExtension(path).ToLower() != ".png" && System.IO.Path.GetExtension(path).ToLower() != ".jpg") { Debug.Log("Not Sprite"); return; } TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; //获取并转换该资源导入器 // Debug.Log(importer.textureType); if (importer.textureType != TextureImporterType.Sprite) { importer.textureType = TextureImporterType.Sprite; //轻质转换 importer.mipmapEnabled = false; importer.spriteImportMode = SpriteImportMode.Single; AssetDatabase.ImportAsset(path); AssetDatabase.Refresh(); } //修改选中图片资源的格式为Sprite string prefabName = System.IO.Path.GetFileNameWithoutExtension(path); string savePrefabPath = EditorDialogUtility.SaveFileDialog("保存生成的预制体", Application.dataPath + "/Resources", prefabName, "prefab"); if (string.IsNullOrEmpty(savePrefabPath)) { Debug.LogInfor("取消 创建SpriteRender"); return; } Debug.Log("CreateSpriteRender savePrefabPath=" + savePrefabPath); //********需要考虑已经存在的时候只需要替换Sprite TODO // Debug.Log("path=" + path + " savePrefabPath=" + savePrefabPath); GameObject go = new GameObject(prefabName); Sprite sources = AssetDatabase.LoadAssetAtPath <Sprite>(path); go.AddComponent <SpriteRenderer>().sprite = sources; //设置Sprite的引用关系 GameObject prefab = PrefabUtility.CreatePrefab(savePrefabPath.Substring(savePrefabPath.IndexOf("Assets")), go); //创建预制体资源 路径必须从 Assets开始 GameObject.DestroyImmediate(go); AssetDatabase.Refresh(); }
public static void CreatePanelConfgText() { string path = EditorDialogUtility.OpenFileDialog("GetUIPanelConfigure", "", ""); Debug.Log("SourcePath ... " + path); path = path.Substring(path.IndexOf("Assets")); Debug.Log("RelativePath ... " + path.Substring(path.IndexOf("Assets"))); UIPanelConfigure bullet = AssetDatabase.LoadAssetAtPath <UIPanelConfigure>(path); string msg = JsonParser.Serialize(bullet.AllUIPanelConfigure); Debug.Log(msg); //string savePath = EditorDialogUtility.SaveFileDialog("保存Json文本", "", "UIPanelConfg", "txt"); //Debug.Log("CreatePanelConfgText >>savePath= " + savePath); //if (File.Exists(savePath) == false) // File.Create(savePath); //File.WriteAllText(savePath, msg); File.WriteAllText(Application.dataPath + "/" + ConstDefine.UIPanelConfigure + ".txt", msg); AssetDatabase.Refresh(); }
public static void CreateSceneItemConfg_Json() { string path = EditorDialogUtility.OpenFileDialog("Get AllSceneGeneration Items Confg Asset", "", ""); Debug.Log("SourcePath ... " + path); path = path.Substring(path.IndexOf("Assets")); Debug.Log("RelativePath ... " + path.Substring(path.IndexOf("Assets"))); SceneItemGenarationInfor_Total bullet = AssetDatabase.LoadAssetAtPath <SceneItemGenarationInfor_Total>(path); Debug.Log(bullet); string msg = JsonParser.Serialize(bullet.TotalConfgForAllScene); Debug.Log(msg); //string savePath = EditorDialogUtility.SaveFileDialog("±£´æJsonÎı¾", "", "UIPanelConfg", "txt"); //Debug.Log("CreatePanelConfgText >>savePath= " + savePath); //if (File.Exists(savePath) == false) // File.Create(savePath); //File.WriteAllText(savePath, msg); File.WriteAllText(Application.dataPath + "/" + ConstDefine.SceneDynamicConfigure + ".txt", msg); AssetDatabase.Refresh(); }