Website may be up and down over next few months. I'm currently doing a complete overhaul of everything. Going back to simple individual .htm pages, new overall site theme, sanitizing and cleaning up html of all pages and blog posts, attempting to implement a new tooling and publishing system etc etc.

If your Unity code requires conditional compilation symbols to be present this bit of code may come in handy. After unity compiles your scripts it executes any classes that have the InitializeOnLoad attribute. You can call the SetupConditionalCompilation method provided in the code snippet below to ensure that the conditional compilation symbols persist in your unity project. If a symbol was not present and was added it will write out a notification in the unity console.

ConditionalStartup

[InitializeOnLoad]
public class GridMappingSetup
{
    static GridMappingSetup()
    {
        var types = new[] { BuildTargetGroup.Standalone, BuildTargetGroup.WebPlayer };
        var toInclude = new[] { "CBXControls", "GridMapping", "QuickTools", "ToolService", "TileMaterialCreation" };

        SetupConditionalCompilation(types, toInclude);
    }
}

public static void SetupConditionalCompilation(BuildTargetGroup[] platformTargets, string[] symbolsToInclude)
{
    foreach (var type in platformTargets)
    {
        var hasEntry = new bool[symbolsToInclude.Length];
        var conditionals = PlayerSettings.GetScriptingDefineSymbolsForGroup(type).Trim();
        var parts = conditionals.Split(';');
        var changed = false;

        foreach (var part in parts)
        {
            for (int i = 0; i < symbolsToInclude.Length; i++)
            {
                if (part.Trim() == symbolsToInclude[i].Trim())
                {
                    hasEntry[i] = true;
                    break;
                }
            }
        }

        for (int i = 0; i < hasEntry.Length; i++)
        {
            if (!hasEntry[i])
            {
                conditionals += (String.IsNullOrEmpty(conditionals) ? String.Empty : ";") + symbolsToInclude[i];
                changed = true;
            }
        }

        PlayerSettings.SetScriptingDefineSymbolsForGroup(type, conditionals);

        if (changed)
        {
            Debug.Log(String.Format("Updated player conditional compilation symbols for {0}: {1}", type, conditionals));
        }
    }
}

Add comment



biuquote
  • Comment
  • Preview
Loading






Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume