-
- lomoonmoonbird
- Posts: 30
- Joined:
how to sync c# & xaml files between visual studio and unity
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?
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?
Re: how to sync c# & xaml files between visual studio and un
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.
Re: how to sync c# & xaml files between visual studio and un
There was also a detailed post by movra on how to achieve this:
viewtopic.php?f=3&t=818&hilit=workflow#p4464
viewtopic.php?f=3&t=818&hilit=workflow#p4464
-
- lomoonmoonbird
- Posts: 30
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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?
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
- Posts: 30
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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?
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
- Posts: 30
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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.
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
- Posts: 30
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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?
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?
Re: how to sync c# & xaml files between visual studio and un
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:
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:
Code: Select all
#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
- Posts: 30
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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
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
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: how to sync c# & xaml files between visual studio and un
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:
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
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.
- 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:
Code: Select all
#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:
Code: Select all
#if NOESIS [UserControlSource("Assets/TestControl.xaml")] #endif public class TestControl: UserControl { //... }
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: Baidu [Spider], Bing [Bot] and 3 guests