Author Topic: Unityscript with WP8 is producing errors  (Read 12139 times)

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Unityscript with WP8 is producing errors
« on: October 19, 2014, 04:01:21 PM »
I'm using Unityscript for my current game. I've done the standard thing of moving the TNet folder under plugins. I can successfully build iOS and Android versions. But the WP8 version kicks out the following errors at build time:

Assets/Plugins/TNet/Client/TNSerializer.cs(965,22): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?
Assets/Plugins/TNet/Client/TNSerializer.cs(972,25): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?
Assets/Plugins/TNet/Client/TNSerializer.cs(1405,49): error CS0246: The type or namespace name `FieldInfo' could not be found. Are you missing a using directive or an assembly reference?

Any ideas on addressing these errors while keeping my code in Unityscript? I'm trying to avoid rewriting my local multiplayer code in C# and using SendMessage commands to share the info with the rest of the project.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #1 on: October 20, 2014, 12:26:07 AM »
You shouldn't put TNet under plugins. It's not a compiled DLL. Just leave TNet's folder under assets.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #2 on: October 20, 2014, 12:39:19 PM »
I'm quoting ArenMook on this thread, http://forum.unity3d.com/threads/released-tnet-tasharen-networking-framework.163681/page-2:
"It has been said that TNet is the easiest of the networking libraries to learn, so it's really up to you. And yes, it will work with UnityScript, but you will want to move its scripts to the Plugins folder, similar to NGUI."

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #3 on: October 20, 2014, 09:26:27 PM »
Well, I stand corrected then.

Have you tried reimporting the latest package of TNet? Have you moved the TNet folder under Plugins or just TNet/Client into Plugins/TNet/Client ?

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #4 on: October 20, 2014, 10:35:07 PM »
Yup, using the brand spanking new 2.0.1 version (which I upgraded to recently in the hopes that this issue might have been fixed).

I had moved the entire TNet folder under plugins. I tried your suggestion but I'm afraid that moving just the client folder under Plugins/TNet produced 51 errors of the "type or namespace name `xxx' could not be found" variety.

As I mentioned before, the frustrating thing is the fact that I'm good as gold on both Android and iOS with the TNet folder under the Plugins folder. It's only on WP8 that I'm getting the 'FieldInfo' not found issue.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #5 on: October 21, 2014, 12:14:54 AM »
The platform you are trying to use (WP8) doesn't support reflection the same way as others, so those parts of the code need to be inside "#if REFLECTION_SUPPORT" tags.
  1. #if REFLECTION_SUPPORT
  2.         static List<string> mFieldNames = new List<string>();
  3.         static List<object> mFieldValues = new List<object>();
  4.  
  5.         /// <summary>
  6.         /// Helper function that retrieves all serializable fields on the specified object and filters them, removing those with null values.
  7.         /// </summary>
  8.  
  9.         static void FilterFields (object obj)
  10.         {
  11.                 Type type = obj.GetType();
  12.                 List<FieldInfo> fields = type.GetSerializableFields();
  13.  
  14.                 mFieldNames.Clear();
  15.                 mFieldValues.Clear();
  16.  
  17.                 for (int i = 0; i < fields.size; ++i)
  18.                 {
  19.                         FieldInfo f = fields[i];
  20.                         object val = f.GetValue(obj);
  21.  
  22.                         if (val != null)
  23.                         {
  24.                                 mFieldNames.Add(f.Name);
  25.                                 mFieldValues.Add(val);
  26.                         }
  27.                 }
  28.         }
  29. #endif
  1.                         case 254: // Serialization using Reflection
  2.                         {
  3. #if REFLECTION_SUPPORT
  4.                                 // Create the object
  5.                                 if (obj == null)
  6.                                 {
  7.                                         obj = type.Create();
  8.                                         if (obj == null) Debug.LogError("Unable to create an instance of " + type);
  9.                                 }
  10.  
  11.                                 if (obj != null)
  12.                                 {
  13.                                         // How many fields have been serialized?
  14.                                         int count = ReadInt(reader);
  15.  
  16.                                         for (int i = 0; i < count; ++i)
  17.                                         {
  18.                                                 // Read the name of the field
  19.                                                 string fieldName = reader.ReadString();
  20.  
  21.                                                 if (string.IsNullOrEmpty(fieldName))
  22.                                                 {
  23.                                                         Debug.LogError("Null field specified when serializing " + type);
  24.                                                         continue;
  25.                                                 }
  26.  
  27.                                                 // Try to find this field
  28.                                                 FieldInfo fi = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
  29.  
  30.                                                 // Read the value
  31.                                                 object val = reader.ReadObject();
  32.  
  33.                                                 // Assign the value
  34.                                                 if (fi != null) fi.SetValue(obj, Serialization.ConvertValue(val, fi.FieldType));
  35.                                                 else Debug.LogError("Unable to set field " + type + "." + fieldName);
  36.                                         }
  37.                                 }
  38. #else
  39.                                 Debug.LogError("Reflection is not supported on this platform");
  40. #endif
  41.                                 return obj;
  42.                         }
I'll make the changes locally and make sure they're in the next update, but until then -- just change them so you get up and running.

P.S. When putting TNet under Plugins, make sure that the Editor folder remains outside it.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #6 on: October 21, 2014, 02:12:50 AM »
Hey Aren,

Progress! Yes, the editor folder is indeed outside the Plugin folder. Your code helped me get past the WP8 FieldInfo issue. But now when I try to build the project I get this error:

Error building Player: Exception: Error: type `System.Runtime.Serialization.Formatters.Binary.BinaryFormatter` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at TNet.Serialization.
Error: type `System.Runtime.Serialization.Formatters.Binary.BinaryFormatter` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at System.Void TNet.Serialization::.cctor().
Error: method `System.Void System.Runtime.Serialization.Formatters.Binary.BinaryFormatter::.ctor()` doesn't exist in target framework. It is referenced from Assembly-CSharp-firstpass.dll at System.Void TNet.Serialization::.cctor().

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #7 on: October 22, 2014, 05:56:09 AM »
WP8 doesn't have a BinaryFormatter?

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #8 on: October 22, 2014, 05:04:11 PM »
Apparently not:

"Binary Serialisation is not supported on Windows Phone (the supporting classes are missing on there)"
http://answers.unity3d.com/questions/678740/savingloading-data-to-windows-phone-8-1.html

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #9 on: October 23, 2014, 03:54:53 PM »
Well, that means that you can't serialize anything custom on a WP8 device. Only built-in simple elements like float, int, Vector3, etc. That's severely limiting...

morty346

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #10 on: November 02, 2014, 04:04:16 PM »
So is there not a solution tot he BinaryFormatter issue then?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #11 on: November 03, 2014, 07:05:26 AM »
As I understand it it's missing altogether, so nope.

morty346

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #12 on: November 04, 2014, 10:45:42 AM »
Once you get around the binary issue there appears to be a whole slew of other issues, from asyncsockets to threads being used different in that version of .net. 

Trying to build against wp8.1 is even worse...

This is very unfortunate... wp8.1 would be a great platform to have supported!! and TNET is the only limitation not allowing it to happen

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #13 on: November 04, 2014, 11:04:20 AM »
The issue lies in the fact that (as I understand it) Microsoft forced Unity to use their half-finished new .NET framework, which happens to be missing a lot of the functionality. If Unity could just stick to Mono, everything would be fine.

morty346

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Unityscript with WP8 is producing errors
« Reply #14 on: November 08, 2014, 11:55:22 PM »
So apparently there is a #define
#if NETFX_CORE/#endif,
that can surround anything that is unique to the wp .net framework

http://docs.unity3d.com/Manual/wp8-1-faq.html


I tried to surround it in the code around all threads,sockets and binary readers, and while it did appear it would work, there was too much cross class mangling going on and worked myself into a fun fix one error create 10 more paradigm and eventually gave up...

But if someone is willing to give it a shot... I think if they simply surround the items with the #define and build with the net core param on, we could have wp8.1 support!