Unity3d DEFINEMANAGER Global macro definition

Source: Internet
Author: User

/**
*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 ();

}

Guilayout.space (4);

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 ());
}
}
}

Unity3d DEFINEMANAGER Global macro definition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.