Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Simple node editor

Discussion in 'Extensions & OnGUI' started by unimechanic, Jul 5, 2013.

  1. Cognetic


    Jun 15, 2017
    I have encountered an issue when porting to ios recently that I have a fix for but i'd call it pretty unsatisfactory. I'm sure there is a cleaner fix I just don't have time to go through it.

    The Problem:
    The dynamic port system saves its object list with info such as:
    "Object refID="-750799744" type="System.Collections.Generic.List`1[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken" etc

    This seems to be an issue because I work on windows and obviously have to compile the ios version in xcode on a mac. Its a problem because the info changes for the ios build(possibly because i have to target a different .NET framework) meaning the GetType method fails when reading data from a different compile and the xml doesn't load.

    The Solution
    My simple solution is to manually set the Type rather than using GetType to set it. So, in the XMLImportExport.cs specifically the ImportData method under the //OBJECTS section I insert a manual change for any relevant types.

    Code (CSharp):
    2.      Type type = typeof(List<string>);
    3.                     //this deal with Mac ios issues of assembly mismatch
    4.                   if (typeName.Contains("System.Collections.Generic.List`1[[System.Collections.Generic.List`1[[System.String, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"))
    5.                     {
    6.                         typeName = "System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.String]]";
    7.                         type = typeof(List<List<string>>);
    8.                     }
    9.                     else if (typeName.Contains("System.Collections.Generic.List`1[[System.String, mscorlib,"))
    10.                     {
    11.                         typeName = "System.Collections.Generic.List`1[System.String]";
    12.                         type = typeof(List<string>);
    13.                     }
    14.                     else if (typeName.Contains("System.Collections.Generic.List`1[[System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"))
    15.                     {
    16.                         typeName = "System.Collections.Generic.List`1[System.Collections.Generic.List`1[System.Int32]]";
    17.                         type = typeof(List<List<Int32>>);
    19.                     }
    20.                     else if(typeName.Contains("System.Collections.Generic.List`1[[System.Int32, mscorlib,") )
    21.                     {
    22.                         typeName = "System.Collections.Generic.List`1[System.Int32]";
    23.                         type = typeof(List<Int32>);
    24.                     }
    25.                     else
    26.                     {
    27.                         type = Type.GetType(typeName, true);
    28.                     }
    Anyways, I'm sure there are better solutions or reasons I've missed for why the info is changing, you could also not save that info in the first place.

    I'm just posting this for an FYI and for any suggestions for a better way of approaching the issue.
    Seneral likes this.
  2. gangafinti


    Jun 13, 2013
    I was making a hotkey to focus a node but I noticed that I cannot just set the panning to the node position but I have to invert the node position to get the panning right and have the node in the center of the canvas. But I don't quite understand why? Why do I need to invert the position of the node? Did I just do a space transformation from ? space to ? space? Because the nodes are already in canvas space right? And panning is in canvas space also?

    Code (CSharp):
    1.         [HotkeyAttribute(KeyCode.F, EventModifiers.Control, EventType.KeyUp)]
    2.         private static void FocusNode(NodeEditorInputInfo inputInfo)
    3.         {
    4.             if (GUIUtility.keyboardControl > 0)
    5.                 return;
    6.             NodeEditorState state = inputInfo.editorState;
    7.             if (state.selectedNode != null)
    8.             {
    9.                 inputInfo.SetAsCurrentEnvironment();
    10.                 state.panOffset = new Vector2(-state.selectedNode.position.x, -state.selectedNode.position.y);
    11.                 inputInfo.inputEvent.Use();
    12.             }
    13.         }
    Seneral likes this.
  3. Seneral


    Jun 2, 2014
    Hm it does seem unintuitive I guess, and there's no strong reason for it to be that way anymore. It is basically setting the center of the canvas to the center of the window + panOffset -- NOT the center of the window to the center of the canvas + panOffset, which would be what you expected.
    But yeah, sometimes you need space transformations that can be VERY confusing, even to me - luckily pretty rarely.
    Hope it didn't cause you too much headache!