惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
S
Secure Thoughts
月光博客
月光博客
美团技术团队
雷峰网
雷峰网
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
News and Events Feed by Topic
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Forbes - Security
Forbes - Security
W
WeLiveSecurity
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
G
GRAHAM CLULEY
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
AI
AI
Last Week in AI
Last Week in AI
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
云风的 BLOG
云风的 BLOG
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Recent Announcements
Recent Announcements
Webroot Blog
Webroot Blog
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
罗磊的独立博客
The Register - Security
The Register - Security
Blog — PlanetScale
Blog — PlanetScale
T
Threat Research - Cisco Blogs
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
B
Blog
腾讯CDC
Microsoft Azure Blog
Microsoft Azure Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Engineering at Meta
Engineering at Meta
Latest news
Latest news
IT之家
IT之家
D
DataBreaches.Net
博客园 - 司徒正美
N
Netflix TechBlog - Medium
V
V2EX
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - _Sin

UnityGUI扩展实例:图片挖洞效果 Mask的反向实现 how to combine jpg + separate alpha in png? unity 全屏乱影 BlitMultiTap Unity Shader Billboard Unity Shaders Vertex & Fragment Shader入门 Unity3d三大光照渲染介绍 Jenkins 搭建U3D自动发布 IOS Jenkins 搭建U3D自动发布 Android Color Space Max批量导出工具 手游比重 不得不存!UI设计新手不可错过的7条实用法则 Unity3D游戏在iOS上因为trampolines闪退的原因与解决办法 [Unity3D]引擎崩溃、异常、警告、BUG与提示总结及解决方法 unity3d ngui 字体制作 工具与示例 幽默的理解六种Socket I/O模型 Unity3d Socket C# sourecode Flex与c# Socket通信 C# 解析JSON数据格式 Mono 源码
unity3d DefineManager 全局宏定义
_Sin · 2015-05-04 · via 博客园 - _Sin

/**
* Editor Wizard for easily managing global defines in Unity
* Place in Assets/Editor folder, or if you choose to place elsewhere
* be sure to also modify the DEF_MANAGER_PATH constant.
* @khenkel
*/

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;

public class DefineManager : EditorWindow
{
const string DEF_MANAGER_PATH = "Assets/Editor/DefineManager.cs";

enum Compiler
{
CSharp,
Editor,
UnityScript,
Boo
}
Compiler compiler = Compiler.Editor;

// http://forum.unity3d.com/threads/93901-global-define/page2
// Do not modify these paths
const int COMPILER_COUNT = 4;
const string CSHARP_PATH = "Assets/smcs.rsp";
const string EDITOR_PATH = "Assets/gmcs.rsp";
const string UNITYSCRIPT_PATH = "Assets/us.rsp";
const string BOO_PATH = "Assets/boo.rsp";

List<string> csDefines = new List<string>();
List<string> booDefines = new List<string>();
List<string> usDefines = new List<string>();
List<string> editorDefines = new List<string>();

[MenuItem("Window/Define Manager")]
public static void OpenDefManager()
{
EditorWindow.GetWindow<DefineManager>(true, "Global Define Manager", true);
}

void OnEnable()
{
csDefines = ParseRspFile(CSHARP_PATH);
usDefines = ParseRspFile(UNITYSCRIPT_PATH);
booDefines = ParseRspFile(BOO_PATH);
editorDefines = ParseRspFile(EDITOR_PATH);
}

List<string> defs;
Vector2 scroll = Vector2.zero;
void OnGUI()
{
Color oldColor = GUI.backgroundColor;

GUILayout.BeginHorizontal();
for(int i = 0; i < COMPILER_COUNT; i++)
{
if(i == (int)compiler)
GUI.backgroundColor = Color.gray;

GUIStyle st;
switch(i)
{
case 0:
st = EditorStyles.miniButtonLeft;
break;
case COMPILER_COUNT-1:
st = EditorStyles.miniButtonRight;
break;
default:
st = EditorStyles.miniButtonMid;
break;
}

if(GUILayout.Button( ((Compiler)i).ToString(), st))
compiler = (Compiler)i;

GUI.backgroundColor = oldColor;
}
GUILayout.EndHorizontal();

switch(compiler)
{
case Compiler.CSharp:
defs = csDefines;
break;

case Compiler.Editor:
defs = editorDefines;
break;

case Compiler.UnityScript:
defs = usDefines;
break;

case Compiler.Boo:
defs = booDefines;
break;
}

GUILayout.Label(compiler.ToString() + " User Defines");

scroll = GUILayout.BeginScrollView(scroll);
for(int i = 0; i < defs.Count; i++)
{
GUILayout.BeginHorizontal();

defs[i] = EditorGUILayout.TextField(defs[i]);

GUI.backgroundColor = Color.red;
if(GUILayout.Button("x", GUIStyle.none, GUILayout.MaxWidth(18)))
defs.RemoveAt(i);
GUI.backgroundColor = oldColor;

GUILayout.EndHorizontal();

GUI.backgroundColor = Color.cyan;
if(GUILayout.Button("Add"))
defs.Add("NEW_DEFINE");

GUILayout.EndScrollView();


GUILayout.BeginHorizontal();
GUI.backgroundColor = Color.green;
if( GUILayout.Button("Apply") )
{
SetDefines(compiler, defs);
AssetDatabase.ImportAsset(DEF_MANAGER_PATH, ImportAssetOptions.ForceUpdate);
OnEnable();
}

GUI.backgroundColor = Color.red;
if(GUILayout.Button("Apply All", GUILayout.MaxWidth(64)))
for(int i = 0; i < COMPILER_COUNT; i++)
{
SetDefines((Compiler)i, defs);
AssetDatabase.ImportAsset(DEF_MANAGER_PATH, ImportAssetOptions.ForceUpdate);
OnEnable();
}

GUILayout.EndHorizontal();
GUI.backgroundColor = oldColor;
}

void SetDefines(Compiler compiler, List<string> defs)
{
switch(compiler)
{
case Compiler.CSharp:
WriteDefines(CSHARP_PATH, defs);
break;

case Compiler.UnityScript:
WriteDefines(UNITYSCRIPT_PATH, defs);
break;

case Compiler.Boo:
WriteDefines(BOO_PATH, defs);
break;

case Compiler.Editor:
WriteDefines(EDITOR_PATH, defs);
break;
}
}

List<string> ParseRspFile(string path)
{
if(!File.Exists(path))
return new List<string>();

string[] lines = File.ReadAllLines(path);
List<string> defs = new List<string>();

foreach(string cheese in lines)
{
if(cheese.StartsWith("-define:"))
{
defs.AddRange( cheese.Replace("-define:", "").Split(';') );
}
}

return defs;
}

void WriteDefines(string path, List<string> defs)
{
if(defs.Count < 1 && File.Exists(path))
{
File.Delete(path);

if(File.Exists(path + ".meta"))
File.Delete(path + ".meta");

AssetDatabase.Refresh();
return;
}

StringBuilder sb = new StringBuilder();
sb.Append("-define:");

for(int i = 0; i < defs.Count; i++)
{
sb.Append(defs[i]);
if(i < defs.Count-1) sb.Append(";");
}

using (StreamWriter writer = new StreamWriter(path, false))
{
writer.Write(sb.ToString());
}
}
}