Dark Deer Games
Topic Author
Posts: 1
Joined: 24 Jun 2021, 16:00

Add Noesis to Existing Unity Project

12 Aug 2021, 22:46

Noesis seems incredibly powerful and useful, however I am really struggling to add it to an existing Unity project. I am attempting to follow the Unity tutorial on the website, but all it seems to recommend is create a new project in Visual Studio using the template, which will create a Unity project for you... but no information on how to add Noesis to an existing project?...

If I am in my existing Unity project, and want to add a Noesis UI, I have absolutely no idea where I would start. Do I create a Blend project? Do I duplicate the samples and retype them? There is no straightforward tutorial for how to do something as simple as creating a new window in an existing Unity project... Am I missing something?
 
User avatar
sfernandez
Site Admin
Posts: 2995
Joined: 22 Dec 2011, 19:20

Re: Add Noesis to Existing Unity Project

16 Aug 2021, 14:07

Hi,

We've been talking many times about the possibility of automatically generating a Blend project from inside Unity. We didn't find a good way to include already created assets but maybe it is interesting to just create an empty Blend project that user can start with.

I created the following script that adds an entry to the Assets menu to open the corresponding Blend project (by creating it first if it doesn't exist) from inside Unity.
using UnityEngine;
using System.IO;
using System;

public class NoesisBlendMenu
{
    [UnityEditor.MenuItem("Assets/Open Blend project", false, 1000)]
    static void OpenBlendProject()
    {
        string projectPath = Path.GetDirectoryName(Application.dataPath);
        string projectName = Path.GetFileName(projectPath);

        if (!File.Exists(Path.Combine(projectPath, projectName + "-blend.sln")))
        {
            CreateBlendProject(projectPath, projectName);
        }

        OpenBlendProject(projectPath, projectName);
    }

    static void OpenBlendProject(string projectPath, string projectName)
    {
        System.Diagnostics.Process.Start(Path.Combine(projectPath, projectName + "-blend.sln"));
    }

    static void CreateBlendProject(string projectPath, string projectName)
    {
        string solutionGUID = Guid.NewGuid().ToString().ToUpper();
        string projectGUID = Guid.NewGuid().ToString().ToUpper();

        CreateBlendSolution(projectPath, projectName, projectGUID, solutionGUID);
        CreateBlendProject(projectPath, projectName, projectGUID);
    }

    static void CreateBlendSolution(string projectPath, string projectName, string projectGUID, string solutionGUID)
    {
        using (var writer = File.CreateText(Path.Combine(projectPath, projectName + "-blend.sln")))
        {
            writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 12.00");
            writer.WriteLine("# Visual Studio Version 16");
            writer.WriteLine("VisualStudioVersion = 16.0.31321.278");
            writer.WriteLine("MinimumVisualStudioVersion = 10.0.40219.1");
            writer.WriteLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + projectName + "-blend\", \"" + projectName + "-blend.csproj\", \"{" + projectGUID + "}\"");
            writer.WriteLine("EndProject");
            writer.WriteLine("Global");
            writer.WriteLine("\tGlobalSection(SolutionConfigurationPlatforms) = preSolution");
            writer.WriteLine("\t\tDebug|Any CPU = Debug|Any CPU");
            writer.WriteLine("\t\tRelease|Any CPU = Release|Any CPU");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(ProjectConfigurationPlatforms) = postSolution");
            writer.WriteLine("\t\t{" + projectGUID + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU");
            writer.WriteLine("\t\t{" + projectGUID + "}.Debug|Any CPU.Build.0 = Debug|Any CPU");
            writer.WriteLine("\t\t{" + projectGUID + "}.Release|Any CPU.ActiveCfg = Release|Any CPU");
            writer.WriteLine("\t\t{" + projectGUID + "}.Release|Any CPU.Build.0 = Release|Any CPU");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(SolutionProperties) = preSolution");
            writer.WriteLine("\t\tHideSolutionNode = FALSE");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("\tGlobalSection(ExtensibilityGlobals) = postSolution");
            writer.WriteLine("\t\tSolutionGuid = {" + solutionGUID + "}");
            writer.WriteLine("\tEndGlobalSection");
            writer.WriteLine("EndGlobal");
        }
    }

    static void CreateBlendProject(string projectPath, string projectName, string projectGUID)
    {
        using (var writer = File.CreateText(Path.Combine(projectPath, projectName + "-blend.csproj")))
        {
            writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            writer.WriteLine("<Project ToolsVersion=\"14.0\" DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">");
            writer.WriteLine("  <PropertyGroup>");
            writer.WriteLine("    <BaseIntermediateOutputPath>Blend\\obj\\</BaseIntermediateOutputPath>");
            writer.WriteLine("  </PropertyGroup>");
            writer.WriteLine("  <Import Project=\"$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props\" Condition=\"Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')\" />");
            writer.WriteLine("  <PropertyGroup>");
            writer.WriteLine("    <Configuration Condition=\" '$(Configuration)' == '' \">Debug</Configuration>");
            writer.WriteLine("    <Platform Condition=\" '$(Platform)' == '' \">AnyCPU</Platform>");
            writer.WriteLine("    <ProjectGuid>{" + projectGUID + "}</ProjectGuid>");
            writer.WriteLine("    <OutputType>WinExe</OutputType>");
            writer.WriteLine("    <AppDesignerFolder>Blend\\Properties</AppDesignerFolder>");
            writer.WriteLine("    <RootNamespace>" + projectName + "</RootNamespace>");
            writer.WriteLine("    <AssemblyName>" + projectName + "</AssemblyName>");
            writer.WriteLine("    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>");
            writer.WriteLine("    <FileAlignment>512</FileAlignment>");
            writer.WriteLine("    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>");
            writer.WriteLine("    <WarningLevel>4</WarningLevel>");
            writer.WriteLine("    <OutputPath>Blend\\bin\\$(Configuration)\\</OutputPath>");
            writer.WriteLine("  </PropertyGroup>");
            writer.WriteLine("  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' \">");
            writer.WriteLine("    <PlatformTarget>AnyCPU</PlatformTarget>");
            writer.WriteLine("    <DebugSymbols>true</DebugSymbols>");
            writer.WriteLine("    <DebugType>full</DebugType>");
            writer.WriteLine("    <Optimize>false</Optimize>");
            writer.WriteLine("    <DefineConstants>DEBUG;TRACE</DefineConstants>");
            writer.WriteLine("    <ErrorReport>prompt</ErrorReport>");
            writer.WriteLine("    <WarningLevel>4</WarningLevel>");
            writer.WriteLine("  </PropertyGroup>");
            writer.WriteLine("  <PropertyGroup Condition=\" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' \">");
            writer.WriteLine("    <PlatformTarget>AnyCPU</PlatformTarget>");
            writer.WriteLine("    <DebugType>pdbonly</DebugType>");
            writer.WriteLine("    <Optimize>true</Optimize>");
            writer.WriteLine("    <DefineConstants>TRACE</DefineConstants>");
            writer.WriteLine("    <ErrorReport>prompt</ErrorReport>");
            writer.WriteLine("    <WarningLevel>4</WarningLevel>");
            writer.WriteLine("  </PropertyGroup>");
            writer.WriteLine("  <ItemGroup>");
            writer.WriteLine("    <Reference Include=\"System\" />");
            writer.WriteLine("    <Reference Include=\"System.Data\" />");
            writer.WriteLine("    <Reference Include=\"System.Xml\" />");
            writer.WriteLine("    <Reference Include=\"Microsoft.CSharp\" />");
            writer.WriteLine("    <Reference Include=\"System.Core\" />");
            writer.WriteLine("    <Reference Include=\"System.Xml.Linq\" />");
            writer.WriteLine("    <Reference Include=\"System.Data.DataSetExtensions\" />");
            writer.WriteLine("    <Reference Include=\"System.Net.Http\" />");
            writer.WriteLine("    <Reference Include=\"System.Xaml\">");
            writer.WriteLine("      <RequiredTargetFramework>4.0</RequiredTargetFramework>");
            writer.WriteLine("    </Reference>");
            writer.WriteLine("    <Reference Include=\"WindowsBase\" />");
            writer.WriteLine("    <Reference Include=\"PresentationCore\" />");
            writer.WriteLine("    <Reference Include=\"PresentationFramework\" />");
            writer.WriteLine("  </ItemGroup>");
            writer.WriteLine("  <ItemGroup>");
            writer.WriteLine("    <ApplicationDefinition Include=\"Blend\\App.xaml\"> ");
            writer.WriteLine("      <Generator>MSBuild:Compile</Generator>");
            writer.WriteLine("      <SubType>Designer</SubType>");
            writer.WriteLine("    </ApplicationDefinition>");
            writer.WriteLine("    <Compile Include=\"Blend\\App.xaml.cs\"> ");
            writer.WriteLine("      <DependentUpon>App.xaml</DependentUpon>");
            writer.WriteLine("      <SubType>Code</SubType>");
            writer.WriteLine("    </Compile>");
            writer.WriteLine("    <Page Include=\"Assets\\" + projectName + "Test.xaml\">");
            writer.WriteLine("      <Generator>MSBuild:Compile</Generator>");
            writer.WriteLine("      <SubType>Designer</SubType>");
            writer.WriteLine("    </Page>");
            writer.WriteLine("    <Compile Include=\"Blend\\Properties\\AssemblyInfo.cs\">");
            writer.WriteLine("      <SubType>Code</SubType>");
            writer.WriteLine("    </Compile>");
            writer.WriteLine("  </ItemGroup>");
            writer.WriteLine("  <ItemGroup>");
            writer.WriteLine("    <AppDesigner Include=\"Blend\\Properties\\\" />");
            writer.WriteLine("    <None Include=\"Blend\\App.config\" />");
            writer.WriteLine("  </ItemGroup>");
            writer.WriteLine("  <ItemGroup>");
            writer.WriteLine("    <PackageReference Include=\"Noesis.GUI.Extensions\" Version=\"3.0.*\" />");
            writer.WriteLine("  </ItemGroup>");
            writer.WriteLine("  <Import Project=\"$(MSBuildToolsPath)\\Microsoft.CSharp.targets\" />");
            writer.WriteLine("  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. ");
            writer.WriteLine("       Other similar extension points exist, see Microsoft.Common.targets.");
            writer.WriteLine("  <Target Name=\"BeforeBuild\">");
            writer.WriteLine("  </Target>");
            writer.WriteLine("  <Target Name=\"AfterBuild\">");
            writer.WriteLine("  </Target>");
            writer.WriteLine("  -->");
            writer.WriteLine("</Project>");
        }

        Directory.CreateDirectory(Path.Combine(projectPath, "Blend", "Properties"));
        using (var writer = File.CreateText(Path.Combine(projectPath, "Blend", "Properties", "AssemblyInfo.cs")))
        {
            writer.WriteLine("using System.Reflection;");
            writer.WriteLine("using System.Resources;");
            writer.WriteLine("using System.Runtime.CompilerServices;");
            writer.WriteLine("using System.Runtime.InteropServices;");
            writer.WriteLine("using System.Windows;");
            writer.WriteLine("");
            writer.WriteLine("// General Information about an assembly is controlled through the following ");
            writer.WriteLine("// set of attributes. Change these attribute values to modify the information");
            writer.WriteLine("// associated with an assembly.");
            writer.WriteLine("[assembly: AssemblyTitle(\"" + projectName + "\")]");
            writer.WriteLine("[assembly: AssemblyDescription(\"\")]");
            writer.WriteLine("[assembly: AssemblyConfiguration(\"\")]");
            writer.WriteLine("[assembly: AssemblyCompany(\"\")]");
            writer.WriteLine("[assembly: AssemblyProduct(\"" + projectName + "\")]");
            writer.WriteLine("[assembly: AssemblyCopyright(\"Copyright ©  2021\")]");
            writer.WriteLine("[assembly: AssemblyTrademark(\"\")]");
            writer.WriteLine("[assembly: AssemblyCulture(\"\")]");
            writer.WriteLine("");
            writer.WriteLine("// Setting ComVisible to false makes the types in this assembly not visible ");
            writer.WriteLine("// to COM components.  If you need to access a type in this assembly from ");
            writer.WriteLine("// COM, set the ComVisible attribute to true on that type.");
            writer.WriteLine("[assembly: ComVisible(false)]");
            writer.WriteLine("");
            writer.WriteLine("//In order to begin building localizable applications, set ");
            writer.WriteLine("//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file");
            writer.WriteLine("//inside a <PropertyGroup>.  For example, if you are using US english");
            writer.WriteLine("//in your source files, set the <UICulture> to en-US.  Then uncomment");
            writer.WriteLine("//the NeutralResourceLanguage attribute below.  Update the \"en-US\" in");
            writer.WriteLine("//the line below to match the UICulture setting in the project file.");
            writer.WriteLine("");
            writer.WriteLine("//[assembly: NeutralResourcesLanguage(\"en-US\", UltimateResourceFallbackLocation.Satellite)]");
            writer.WriteLine("");
            writer.WriteLine("");
            writer.WriteLine("[assembly: ThemeInfo(");
            writer.WriteLine("    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located");
            writer.WriteLine("                                     //(used if a resource is not found in the page, ");
            writer.WriteLine("                                     // or application resource dictionaries)");
            writer.WriteLine("    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located");
            writer.WriteLine("                                              //(used if a resource is not found in the page, ");
            writer.WriteLine("                                              // app, or any theme specific resource dictionaries)");
            writer.WriteLine(")]");
            writer.WriteLine("");
            writer.WriteLine("");
            writer.WriteLine("// Version information for an assembly consists of the following four values:");
            writer.WriteLine("//");
            writer.WriteLine("//      Major Version");
            writer.WriteLine("//      Minor Version ");
            writer.WriteLine("//      Build Number");
            writer.WriteLine("//      Revision");
            writer.WriteLine("//");
            writer.WriteLine("// You can specify all the values or you can default the Build and Revision Numbers ");
            writer.WriteLine("// by using the '*' as shown below:");
            writer.WriteLine("// [assembly: AssemblyVersion(\"1.0.*\")]");
            writer.WriteLine("[assembly: AssemblyVersion(\"1.0.0.0\")]");
            writer.WriteLine("[assembly: AssemblyFileVersion(\"1.0.0.0\")]");
        }

        using (var writer = File.CreateText(Path.Combine(projectPath, "Blend", "App.config")))
        {
            writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            writer.WriteLine("<configuration>");
            writer.WriteLine("    <startup> ");
            writer.WriteLine("        <supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\" />");
            writer.WriteLine("    </startup>");
            writer.WriteLine("</configuration>");
        }

        using (var writer = File.CreateText(Path.Combine(projectPath, "Blend", "App.xaml")))
        {
            writer.WriteLine("<Application x:Class=\"" + projectName + ".App\"");
            writer.WriteLine("  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
            writer.WriteLine("  xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"");
            writer.WriteLine("  xmlns:local=\"clr-namespace:" + projectName + "\"");
            writer.WriteLine("  StartupUri=\"/" + projectName + ";component/Assets/" + projectName + "Test.xaml\">");
            writer.WriteLine("  <Application.Resources>");
            writer.WriteLine("    <ResourceDictionary>");
            writer.WriteLine("      <ResourceDictionary.MergedDictionaries>");
            writer.WriteLine("        <ResourceDictionary Source=\"/Noesis.GUI.Extensions;component/Theme/NoesisTheme.DarkBlue.xaml\"/>");
            writer.WriteLine("      </ResourceDictionary.MergedDictionaries>");
            writer.WriteLine("    </ResourceDictionary>");
            writer.WriteLine("  </Application.Resources>");
            writer.WriteLine("</Application>");
        }

        using (var writer = File.CreateText(Path.Combine(projectPath, "Blend", "App.xaml.cs")))
        {
            writer.WriteLine("using System;");
            writer.WriteLine("using System.Windows;");
            writer.WriteLine("");
            writer.WriteLine("namespace " + projectName);
            writer.WriteLine("{");
            writer.WriteLine("    /// <summary>");
            writer.WriteLine("    /// Interaction logic for App.xaml");
            writer.WriteLine("    /// </summary>");
            writer.WriteLine("    public partial class App : Application");
            writer.WriteLine("    {");
            writer.WriteLine("    }");
            writer.WriteLine("}");
        }

        using (var writer = File.CreateText(Path.Combine(projectPath, "Assets", projectName + "Test.xaml")))
        {
            writer.WriteLine("<Grid");
            writer.WriteLine("  xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
            writer.WriteLine("  xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"> ");
            writer.WriteLine("  <Border Background=\"DodgerBlue\" HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\" Padding=\"50,20\">");
            writer.WriteLine("    <StackPanel>");
            writer.WriteLine("      <TextBlock Text=\"Hello World\" FontSize=\"30\" Foreground=\"White\"/>");
            writer.WriteLine("      <Button Content=\"Button\"/>");
            writer.WriteLine("    </StackPanel>");
            writer.WriteLine("  </Border>");
            writer.WriteLine("</Grid>");
        }
    }
}
Please let me know if that is helpful, we will probably include it in the next release.

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests