Skip to content

Instantly share code, notes, and snippets.

@sugi-cho
Last active April 18, 2016 08:31
Show Gist options
  • Save sugi-cho/7b89f234961c82901315d07b1d656ba2 to your computer and use it in GitHub Desktop.
Save sugi-cho/7b89f234961c82901315d07b1d656ba2 to your computer and use it in GitHub Desktop.
.cgincファイルを作る、EditorScript
using UnityEngine;
using UnityEditor;
using System.IO;
public class CreateCgincExtent{
[MenuItem("Assets/Create/cginc file")]
public static void CreateCginc()
{
var path = GetCurrentProjectWindowPath();
path = Path.Combine(path, "newCginc.cginc");
path = AssetDatabase.GenerateUniqueAssetPath(path);
File.WriteAllText(path, "#ifndef NEW_CGINC\n#define NEW_CGINC\n\n#endif");
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
static string GetCurrentProjectWindowPath()
{
var o = Selection.GetFiltered(typeof(Object), SelectionMode.Assets)[0];
var path = AssetDatabase.GetAssetPath(o);
if (!AssetDatabase.IsValidFolder(path))
path = Path.GetDirectoryName(path);
return path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment