lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

how to sync c# & xaml files between visual studio and unity

30 Mar 2016, 10:04

Hi
I use visual studio 2015 and blend to code C# files and design xaml,but i have to copy these files into unity folder every time i create new one.any approach can make life easier?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: how to sync c# & xaml files between visual studio and un

30 Mar 2016, 11:24

The recommended approach is sharing the location of items between Visual Studio and Unity. You can do that is for example you store the Visual Studio solution at the root of the Unity project. We follow this approach in many of our samples. Have a look at the MenuDemo for example.
 
kguner
Posts: 17
Joined: 07 Apr 2015, 18:38
Contact:

Re: how to sync c# & xaml files between visual studio and un

31 Mar 2016, 01:29

There was also a detailed post by movra on how to achieve this:

viewtopic.php?f=3&t=818&hilit=workflow#p4464
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: how to sync c# & xaml files between visual studio and un

31 Mar 2016, 04:27

Hi
Thanks,this article i had read before,when i create a project in Blend,the folder should be as movra said

SolutionName
-- SolutionName.sln (created by Blend)
-- WpfApplication1
---- WpfApplication1.sln (created by UnityVS)
---- Assets
------ MVVM
-------- ViewModels
-------- Views

but mine do not have the WpfApplication1.sln (created by UnityVS) file,instead of WpfApplication1.csproj file.
they are
SolutionName
-- SolutionName.sln (created by Blend)
-- WpfApplication1
---- bin
---- obj
---- Properties
---- App.config
---- App.xaml
---- App.xaml.cs
---- MainWindow.xaml
---- MainWindow.xaml.cs
---- WpfApplication1.csproj


and I created Assets folder under WpfApplication1 ,but can not open in unity,was i doing something wrong?
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: how to sync c# & xaml files between visual studio and un

31 Mar 2016, 04:32

Hi

I had tried again,and it worked , i can open it in the unity,but the Assets folder and Noesis reference doesn't appear in the blend Solution Explorer, how to solve this?
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: how to sync c# & xaml files between visual studio and un

31 Mar 2016, 04:40

Hi

Sorry for my careless, i find the show all files button,and it seems work fine,Thanks for all of you to help me. :)
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: how to sync c# & xaml files between visual studio and un

31 Mar 2016, 04:59

Hi

But how to use Noesis reference in Blend? as morva said, create a new project in the same solution and create dummy class to store them. i have no clue how to do it ,can you specify more detail?
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: how to sync c# & xaml files between visual studio and un

01 Apr 2016, 01:22

Hi,

Have your inspected the the MenuDemo sample commented above? There you can find .cs files that are both used in Microsoft Blend/Visual Studio and Unity using preprocessor directives. For example:
#if UNITY_STANDALONE || UNITY_ANDROID || UNITY_IOS || UNITY_WINRT_8_1
 #define UNITY
#endif

#if UNITY
 using Noesis;
#else
 using System;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Controls.Primitives;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Input;
#endif
 
lomoonmoonbird
Topic Author
Posts: 30
Joined: 15 Mar 2016, 04:41

Re: how to sync c# & xaml files between visual studio and un

01 Apr 2016, 04:46

Hi
I have looked through the GameMenu Demo,when i dragged the file in unity to visual studio or open the file in unity with visual studio,they automatically had the unity and noesis reference,but visual studio blend didn't, how to add reference to blend? I also added the preprocessor,but only in visual studio ,so i have to edit .cs file in visual studio and .xaml file in blend , any way make life easier ? thanks :)
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: how to sync c# & xaml files between visual studio and un

04 Apr 2016, 12:28

Hi,

Let's see if I can help here.

When working in Blend (outside Unity) classes from Noesis are not used, the WPF framework is used instead. So there is no need to include any Noesis assembly reference. That is the reason why you have to use the preprocessor directives at the top of each .cs file, to be able to apply different code depending on whether the file is compiled in Blend for WPF, or in Unity/Visual Studio for Noesis.

If you want to be able to use Blend to design the xamls and share the same code-behind files with Unity, you should follow the next steps:
  • Create a WPF application project in Blend. This will create .sln and .csproj files that are only valid for Blend, not Unity. As I said before there is no need to add any reference to a Noesis assembly.
  • Inside Blend, add to the project a folder named Assets. Open Unity and click "OPEN" on the start screen to select that Assets folder as root of your Unity project.
  • Every time you want to add content (UserControls, code classes, images, fonts...) to your Unity project you should do it from Blend.
For example, imagine you want to create a new UserControl, then:
  • Go to Blend, right click the Assets folder selecting "Add new item...", and choose UserControl writing the name of the class (TestControl for example).
  • This will add two files to your Blend project: TestControl.xaml and TestControl.xaml.cs.
  • Open TestControl.xaml.cs and add at the very top of the file the following:
    #if UNITY_5
    #define NOESIS
    #endif
    
    #if NOESIS
      using Noesis;
      using System;
      using System.Collections;
      //add here namespaces required when compiling in Unity
    #else
      using System;
      using System.Collections;
      using System.Windows;
      using System.Windows.Controls;
      using System.Windows.Controls.Primitives;
      //add here namespaces required when compiling in Blend
    #endif
  • Whenever there is a part of code that differs between WPF and Noesis use the NOESIS preprocessor directive to write the appropriate code in each case. For example, in Noesis you have to specify the xaml associated with the UserControl using an attribute. If you created it inside Assets/TestControl.xaml, then add the following:
    #if NOESIS
    [UserControlSource("Assets/TestControl.xaml")]
    #endif
    public class TestControl: UserControl
    {
      //...
    }
If you want to try how your UserControl looks in Blend you just need to right click TestControl.xaml on the project to set it as the "Startup" file and "Run Project" (F5 key).

You can then go to Unity, create a new scene adding a NoesisGUIPanel component to the Main Camera and assign the TestControl.xaml to its Xaml property. You should be able to click "Play" and see the UserControl created in Blend in the Unity Game view. Double clicking the TestControl.xaml.cs file from Unity will open in Visual Studio the Unity .csproj (different from Blend) and it will allow you to debug the scripts as you play in Unity.

I hope this will help you understand how to use the power of Blend to design your xaml files while working in Unity.

Regards,
-Sergio

Who is online

Users browsing this forum: No registered users and 1 guest