Skip to content

Commit

Permalink
修改Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoqingqing committed Feb 14, 2017
1 parent c0c6820 commit 4b99203
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
29 changes: 29 additions & 0 deletions unity_helper/Editor/CreateFileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@
/// </summary>
public class CreateFileEditor : Editor
{
[MenuItem("Assets/Create/xLua File")]
static void CreateXLuaFile()
{
var fileEx = "lua.txt";
//获取当前所选择的目录(相对于Assets的路径)
var selectPath = AssetDatabase.GetAssetPath(Selection.activeObject);
var path = Application.dataPath.Replace("Assets", "") + "/";
var newFileName = "new_xlua." + fileEx;
var newFilePath = selectPath + "/" + newFileName;
var fullPath = path + newFilePath;

//简单的重名处理
if (File.Exists(fullPath))
{
var newName = "new_xlua-" + UnityEngine.Random.Range(0, 100) + "." + fileEx;
newFilePath = selectPath + "/" + newName;
fullPath = fullPath.Replace(newFileName, newName);
}

//如果是空白文件,编码并没有设成UTF-8
File.WriteAllText(fullPath, "-- test", Encoding.UTF8);

AssetDatabase.Refresh();

//选中新创建的文件
var asset = AssetDatabase.LoadAssetAtPath(newFilePath, typeof(Object));
Selection.activeObject = asset;
}

[MenuItem("Assets/Create/Lua File")]
static void CreateLuaFile()
{
Expand Down
24 changes: 24 additions & 0 deletions unity_helper/Editor/MenuEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Diagnostics;
using UnityEngine;
using UnityEditor;

public class MenuEditor : ScriptableObject
{
[MenuItem("Tools/打开Persister目录")]
static void OpenPersister()
{
Process.Start(Application.persistentDataPath);
}

[MenuItem("Tools/清除所有的PlayerPrefs")]
static void ClearPrefs()
{
PlayerPrefs.DeleteAll();
}

[MenuItem("Tools/清除所有的EditorPrefs")]
static void ClearEditorPrefs()
{
EditorPrefs.DeleteAll();
}
}

0 comments on commit 4b99203

Please sign in to comment.