Converting Code from JavaScript to C#

What is the best means of converting JavaScript to C Sharp with a minimal amount of user interaction, meaning one that best converts the code without the user having to fix much of the code. Right now I use the converter at "http://www.m2h.nl/files/js_to_c.php", it works for the most part but it can't properly convert "var" over to C# and you must then specify a specific variable as that is what C# requires compared to the more openness of JavaScript variables. Such as when I convert the following code:

/* 
*  This file is part of the Unity networking tutorial by M2H (http://www.M2H.nl)
*  The original author of this code is Mike Hergaarden, even though some small parts 
*  are copied from the Unity tutorials/manuals.
*  Feel free to use this code for your own projects, drop us a line if you made something exciting! 
*/
#pragma strict

public var gameName = "Example4";
public var serverPort =  35001;

public var hostData : HostData[];

private var natCapable : ConnectionTesterStatus = ConnectionTesterStatus.Undetermined;
public var filterNATHosts = false;
private var probingPublicIP = false;
private var doneTestingNAT = false;
private var timer : float = 0.0;

private var hideTest = false;
private var testMessage = "Undetermined NAT capabilities";

private var tryingToConnectPlayNow : boolean = false;
public var tryingToConnectPlayNowNumber : int = 0;

private var remotePort : int[] = new int[3];
private var remoteIP : String[] = new String[3];
public var connectionInfo : String = "";

public var lastMSConnectionAttemptForcedNat : boolean= false;
private var NAToptionWasSwitchedForTesting : boolean = false;
private var officialNATstatus : boolean = Network.useNat;
public var errorMessage : String = "";
private var lastPlayNowConnectionTime : float;

public var nowConnecting : boolean = false;

function Awake ()
{
    sortedHostList = new Array ();

    // Start connection test
    natCapable = Network.TestConnection();

    // What kind of IP does this machine have? TestConnection also indicates this in the
    // test results
    if (Network.HavePublicAddress()){
        Debug.Log("This machine has a public IP address");
    }else{
        Debug.Log("This machine has a private IP address");
    }   

    /* //If you dont want to use the Unity masterserver..
    Network.natFacilitatorIP = myMasterServerIP;
    Network.natFacilitatorPort = 11111;//Change this
    MasterServer.ipAddress = myMasterServerIP;
    MasterServer.port = 22222;//Change this
    Network.connectionTesterIP = myMasterServerIP;
    Network.connectionTesterPort = 33333;//Change this
    */

}

function Start(){//must be in start because of coroutine

    yield WaitForSeconds(0.5);
    var tries : int=0;
    while(tries<=10){       
        if(hostData && hostData.length>0){
            //Waiting for hostData
        }else{
            FetchHostList(true);
        }
        yield WaitForSeconds(0.5);
        tries++;
    }
}

function OnFailedToConnectToMasterServer(info: NetworkConnectionError)
{
    //Yikes
}

function OnFailedToConnect(info: NetworkConnectionError)
{
    Debug.Log("FailedToConnect info:"+info);
    FailedConnRetry(info);      
}

function Connect(ip : String, port : int, usenat : boolean){
    // Enable NAT functionality based on what the hosts if configured to do
    Network.useNat = usenat;
    lastMSConnectionAttemptForcedNat = usenat;

    Debug.Log("Connecting to "+ip+":"+port+" NAT:"+usenat);
    Network.Connect(ip, port);      
    nowConnecting=true; 
}

//This second definition of Connect can handle the ip string[] passed by the masterserver
function Connect(ip : String[], port : int, usenat : boolean){
    // Enable NAT functionality based on what the hosts if configured to do
    Network.useNat = usenat;
    lastMSConnectionAttemptForcedNat = usenat;

    Debug.Log("Connecting to "+ip[0]+":"+port+" NAT:"+usenat);
    Network.Connect(ip, port);      
    nowConnecting=true; 
}

function StartHost(players : int, port : int){
    if(players<=1){
        players=1;
    }
    //Network.InitializeSecurity();
    Network.InitializeServer(players, port);
}

function OnConnectedToServer(){
    //Stop communication until in the game
    Network.isMessageQueueRunning = false;

    //Save these details so we can use it in the next scene
    PlayerPrefs.SetString("connectIP", Network.connections[0].ipAddress);
    PlayerPrefs.SetInt("connectPort", Network.connections[0].port);
}

function FailedConnRetry(info: NetworkConnectionError){
    if(info == NetworkConnectionError.InvalidPassword){
        mayRetry=false;
    }

    nowConnecting=false;

    //Quickplay
    if(tryingToConnectPlayNow){
        //Try again without NAT if we used NAT
        if(mayRetry && Network.useNat && lastMSConnectionAttemptForcedNat){
            Debug.Log("Failed connect 1A: retry without NAT");

            remotePort[0]=serverPort;//Fall back to default server port
            Connect(remoteIP, remotePort[0], false);
            lastPlayNowConnectionTime=Time.time;
        }else{
            //We didn't use NAT and failed
            Debug.Log("Failed connect 1B: Don't retry");

            //Reset NAT to org. value
            Network.useNat=officialNATstatus;

            //Connect to next playnow/quickplay host
            tryingToConnectPlayNowNumber++;
            tryingToConnectPlayNow=false;
        }
    }else{
        //Direct connect or via host list manually
        connectionInfo="Failed to connect!";

        if(mayRetry && Network.useNat && lastMSConnectionAttemptForcedNat){
            //Since the last connect forced NAT usage,
            // let's try again without NAT.     
            Network.useNat=false;
            Network.Connect(remoteIP, remotePort[0]);
            nowConnecting=true;
            lastPlayNowConnectionTime=Time.time;

        }else{
            Debug.Log("Failed 2b");

            if(info == NetworkConnectionError.InvalidPassword){
                errorMessage="Failed to connect: Wrong password supplied";
            }else if(info == NetworkConnectionError.TooManyConnectedPlayers){
                errorMessage="Failed to connect: Server is full";
            }else{
                errorMessage="Failed to connect";
            }

            //reset to default port
            remotePort[0]=serverPort;

            //Reset nat to tested value
            Network.useNat=officialNATstatus;

        }
    }   
}

public var CONNECT_TIMEOUT : float = 0.75;
public var CONNECT_NAT_TIMEOUT : float = 5.00;

//Our quickplay function: Go trough the gameslist and try to connect to all games
function PlayNow(timeStarted : float ){

        var i : int=0;

        for (var myElement in sortedHostList)
        {
            var element=hostData[myElement];

            // Do not try NAT enabled games if we cannot do NAT punchthrough
            // Do not try connecting to password protected games
            if ( !(filterNATHosts && element.useNat) && !element.passwordProtected  )
            {
                aHost=1;

                if(element.connectedPlayers<element.playerLimit)
                {                   
                    if(tryingToConnectPlayNow){
                        var natText;
                        if(Network.useNat){
                            natText=" with option 1/2";
                        }else{
                            natText=" with option 2/2";
                        }
                        if((!Network.useNat && lastPlayNowConnectionTime+CONNECT_TIMEOUT<=Time.time) || (Network.useNat  && lastPlayNowConnectionTime+CONNECT_NAT_TIMEOUT<=Time.time)){
                            Debug.Log("Interrupted by timer, NAT:"+Network.useNat);
                            FailedConnRetry(NetworkConnectionError.ConnectionFailed);                           
                        }
                        return "Trying to connect to host "+(tryingToConnectPlayNowNumber+1)+"/"+sortedHostList.length+" "+natText; 
                    }       
                    if(!tryingToConnectPlayNow && tryingToConnectPlayNowNumber<=i){
                        Debug.Log("Trying to connect to game NR "+i+" & "+tryingToConnectPlayNowNumber);
                        tryingToConnectPlayNow=true;
                        tryingToConnectPlayNowNumber=i;

                        // Enable NAT functionality based on what the hosts if configured to do
                        lastMSConnectionAttemptForcedNat=element.useNat;
                        Network.useNat = element.useNat;
                        var connectPort : int=element.port;
                        if (Network.useNat){
                            print("Using Nat punchthrough to connect");
                        }else{
                            //connectPort=serverPort; //bad idea!
                            print("Connecting directly to host");
                        }
                        Debug.Log("connecting to "+element.gameName+" "+element.ip+":"+connectPort);
                        Network.Connect(element.ip, connectPort);   
                        lastPlayNowConnectionTime=Time.time;
                    }
                    i++;        
                }
            }           
        }

        //If we reach this point then either we've parsed the whole list OR the list is still empty

        //Dont give up yet: Give MS 7 seconds to feed the list
        if(Time.time<timeStarted+7){
            FetchHostList(true);    
            return "Waiting for masterserver..."+Mathf.Ceil((timeStarted+7)-Time.time); 
        }

        if(!tryingToConnectPlayNow){
            return "failed";
        }

}

function Update() {
    // If network test is undetermined, keep running
    if (!doneTestingNAT) {
        TestConnection();
    }
}

function TestConnection() {
    // Start/Poll the connection test, report the results in a label and react to the results accordingly
    natCapable = Network.TestConnection();
    switch (natCapable) {
        case ConnectionTesterStatus.Error: 
            testMessage = "Problem determining NAT capabilities";
            doneTestingNAT = true;
            break;

        case ConnectionTesterStatus.Undetermined: 
            testMessage = "Undetermined NAT capabilities";
            doneTestingNAT = false;
            break;

        case ConnectionTesterStatus.PrivateIPNoNATPunchthrough: 
            testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, local LAN games only.";
            filterNATHosts = true;
            Network.useNat = true;
            doneTestingNAT = true;
            break;

        case ConnectionTesterStatus.PrivateIPHasNATPunchThrough:
            if (probingPublicIP)
                testMessage = "Non-connectable public IP address (port "+ serverPort +" blocked), NAT punchthrough can circumvent the firewall.";
            else
                testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality.";
            // NAT functionality is enabled in case a server is started,
            // clients should enable this based on if the host requires it
            Network.useNat = true;
            doneTestingNAT = true;
            break;

        case ConnectionTesterStatus.PublicIPIsConnectable:
            testMessage = "Directly connectable public IP address.";
            Network.useNat = false;
            doneTestingNAT = true;
            break;

        // This case is a bit special as we now need to check if we can 
        // cicrumvent the blocking by using NAT punchthrough
        case ConnectionTesterStatus.PublicIPPortBlocked:
            testMessage = "Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible.";
            Network.useNat = false;
            // If no NAT punchthrough test has been performed on this public IP, force a test
            if (!probingPublicIP)
            {
                Debug.Log("Testing if firewall can be circumnvented");
                natCapable = Network.TestConnectionNAT();
                probingPublicIP = true;
                timer = Time.time + 10;
            }
            // NAT punchthrough test was performed but we still get blocked
            else if (Time.time > timer)
            {
                probingPublicIP = false;        // reset
                Network.useNat = true;
                doneTestingNAT = true;
            }
            break;
        case ConnectionTesterStatus.PublicIPNoServerStarted:
            testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready.";
            break;
        default: 
            testMessage = "Error in test routine, got " + natCapable;
    }
    officialNATstatus=Network.useNat;
    if(doneTestingNAT){
        Debug.Log("TestConn:"+testMessage);
        Debug.Log("TestConn:"+natCapable + " " + probingPublicIP + " " + doneTestingNAT);
    }
}

private var lastHostListRequest : float = 0;

//Request the host limit, but we limit these requests
//Max once every two minutes automatically, max once every 5 seconds when manually requested
function FetchHostList(manual : boolean){
    var timeout : int = 120;
    if(manual){
        timeout=5;
    }

    if(lastHostListRequest==0 || Time.realtimeSinceStartup > lastHostListRequest + timeout){
            lastHostListRequest = Time.realtimeSinceStartup;
            MasterServer.RequestHostList (gameName);            
            yield WaitForSeconds(1);//We gotta wait :/          
            hostData = MasterServer.PollHostList();
            yield WaitForSeconds(1);//We gotta wait :/  
            CreateSortedArray();
            Debug.Log("Requested new host list, got: "+hostData.length);
    }

}

//The code below is all about sorting the game list by playeramount

public var sortedHostList : Array;

function CreateSortedArray(){

    sortedHostList = new Array();   

    var i : int=0;
    var data : HostData[] = hostData;
    for (var element in data)
    {
        AddToArray(i);
        i++;        
    }           
}

function AddToArray(nr : int){
    sortedHostList.Add (nr);    
    SortLastItem();
}

function SortLastItem(){
    if(sortedHostList.length<=1){
        return;
    }
    for(var i=sortedHostList.length-1;i>0;i--){
    var value1 : int= hostData[sortedHostList[i-1]].connectedPlayers;
    var value2 : int = hostData[sortedHostList*].connectedPlayers;*
 *if(value1<value2){*
 *SwapArrayItem((i-1), i);*
 *}else{*
 *//Sorted!*
 *return;*
 *}*
 *}*
*}*
*function SwapArrayItem(nr1, nr2){*
 *var tmp=sortedHostList[nr1];*
 *sortedHostList[nr1]=sortedHostList[nr2];*
 *sortedHostList[nr2]=tmp;*
*}*
*```*
*<p>The code then ends up as:</p>*
*```*
*// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden*
*// Do test the code! You usually need to change a few small bits.*
*using UnityEngine;*
*using System.Collections;*
*public class MYCLASSNAME : MonoBehaviour {*
_/*_ 
_*  This file is part of the Unity networking tutorial by M2H (http://www.M2H.nl)_
_*  The original author of this code is Mike Hergaarden, even though some small parts_ 
_*  are copied from the Unity tutorials/manuals._
_*  Feel free to use this code for your own projects, drop us a line if you made something exciting!_ 
_*/_
*public FIXME_VAR_TYPE gameName= "Example4";*
*public FIXME_VAR_TYPE serverPort=  35001;*
*public HostData[] hostData;*
*private ConnectionTesterStatus natCapable = ConnectionTesterStatus.Undetermined;*
*public FIXME_VAR_TYPE filterNATHosts= false;*
*private FIXME_VAR_TYPE probingPublicIP= false;*
*private FIXME_VAR_TYPE doneTestingNAT= false;*
*private float timer = 0.0f;*
*private FIXME_VAR_TYPE hideTest= false;*
*private FIXME_VAR_TYPE testMessage= "Undetermined NAT capabilities";*
*private bool  tryingToConnectPlayNow = false;*
*public int tryingToConnectPlayNowNumber = 0;*
*private int[] remotePort = new int[3];*
*private string[] remoteIP = new string[3];*
*public string connectionInfo = "";*
*public bool  lastMSConnectionAttemptForcedNat= false;*
*private bool  NAToptionWasSwitchedForTesting = false;*
*private bool  officialNATstatus = Network.useNat;*
*public string errorMessage = "";*
*private float lastPlayNowConnectionTime;*
*public bool  nowConnecting = false;*
*void  Awake (){*
 *sortedHostList = new Array ();*
 *// Start connection test*
 *natCapable = Network.TestConnection();*
 *// What kind of IP does this machine have? TestConnection also indicates this in the*
 *// test results*
 *if (Network.HavePublicAddress()){*
 *Debug.Log("This machine has a public IP address");*
 *}else{*
 *Debug.Log("This machine has a private IP address");*
 *}* 
 _/* //If you dont want to use the Unity masterserver.._
 *Network.natFacilitatorIP = myMasterServerIP;*
 *Network.natFacilitatorPort = 11111;//Change this*
 *MasterServer.ipAddress = myMasterServerIP;*
 *MasterServer.port = 22222;//Change this*
 *Network.connectionTesterIP = myMasterServerIP;*
 *Network.connectionTesterPort = 33333;//Change this*
 _*/_
*}*
*void  Start (){//must be in start because of coroutine*
 *yield return new WaitForSeconds(0.5f);*
 *int tries=0;*
 *while(tries<=10){* 
 *if(hostData && hostData.length>0){*
 *//Waiting for hostData*
 *}else{*
 *FetchHostList(true);*
 *}*
 *yield return new WaitForSeconds(0.5f);*
 *tries++;*
 *}*
*}*
*void  OnFailedToConnectToMasterServer ( NetworkConnectionError info  ){*
 *//Yikes*
*}*
*void  OnFailedToConnect ( NetworkConnectionError info  ){*
 *Debug.Log("FailedToConnect info:"+info);*
 *FailedConnRetry(info);* 
*}*
*void  Connect ( string ip ,   int port ,   bool usenat  ){*
 *// Enable NAT functionality based on what the hosts if configured to do*
 *Network.useNat = usenat;*
 *lastMSConnectionAttemptForcedNat = usenat;*
 *Debug.Log("Connecting to "+ip+":"+port+" NAT:"+usenat);*
 *Network.Connect(ip, port);* 
 *nowConnecting=true;* 
*}*
*//This second definition of Connect can handle the ip string[] passed by the masterserver*
*void  Connect ( string[] ip ,   int port ,   bool usenat  ){*
 *// Enable NAT functionality based on what the hosts if configured to do*
 *Network.useNat = usenat;*
 *lastMSConnectionAttemptForcedNat = usenat;*
 *Debug.Log("Connecting to "+ip[0]+":"+port+" NAT:"+usenat);*
 *Network.Connect(ip, port);* 
 *nowConnecting=true;* 
*}*
*void  StartHost ( int players ,   int port  ){*
 *if(players<=1){*
 *players=1;*
 *}*
 *//Network.InitializeSecurity();*
 *Network.InitializeServer(players, port);*
*}*
*void  OnConnectedToServer (){*
 *//Stop communication until in the game*
 *Network.isMessageQueueRunning = false;*
 *//Save these details so we can use it in the next scene*
 *PlayerPrefs.SetString("connectIP", Network.connections[0].ipAddress);*
 *PlayerPrefs.SetInt("connectPort", Network.connections[0].port);*
*}*
*void  FailedConnRetry ( NetworkConnectionError info  ){*
 *if(info == NetworkConnectionError.InvalidPassword){*
 *mayRetry=false;*
 *}*
 *nowConnecting=false;*
 *//Quickplay*
 *if(tryingToConnectPlayNow){*
 *//Try again without NAT if we used NAT*
 *if(mayRetry && Network.useNat && lastMSConnectionAttemptForcedNat){*
 *Debug.Log("Failed connect 1A: retry without NAT");*
 *remotePort[0]=serverPort;//Fall back to default server port*
 *Connect(remoteIP, remotePort[0], false);*
 *lastPlayNowConnectionTime=Time.time;*
 *}else{*
 *//We didn't use NAT and failed*
 *Debug.Log("Failed connect 1B: Don't retry");*
 *//Reset NAT to org. value*
 *Network.useNat=officialNATstatus;*
 *//Connect to next playnow/quickplay host*
 *tryingToConnectPlayNowNumber++;*
 *tryingToConnectPlayNow=false;*
 *}*
 *}else{*
 *//Direct connect or via host list manually*
 *connectionInfo="Failed to connect!";*
 *if(mayRetry && Network.useNat && lastMSConnectionAttemptForcedNat){*
 *//Since the last connect forced NAT usage,*
 *// let's try again without NAT.* 
 *Network.useNat=false;*
 *Network.Connect(remoteIP, remotePort[0]);*
 *nowConnecting=true;*
 *lastPlayNowConnectionTime=Time.time;*
 *}else{*
 *Debug.Log("Failed 2b");*
 *if(info == NetworkConnectionError.InvalidPassword){*
 *errorMessage="Failed to connect: Wrong password supplied";*
 *}else if(info == NetworkConnectionError.TooManyConnectedPlayers){*
 *errorMessage="Failed to connect: Server is full";*
 *}else{*
 *errorMessage="Failed to connect";*
 *}*
 *//reset to default port*
 *remotePort[0]=serverPort;*
 *//Reset nat to tested value*
 *Network.useNat=officialNATstatus;*
 *}*
 *}* 
*}*
*public float CONNECT_TIMEOUT = 0.75f;*
*public float CONNECT_NAT_TIMEOUT = 5.00f;*
*//Our quickplay function: Go trough the gameslist and try to connect to all games*
*void  PlayNow ( float timeStarted   ){*
 *int i=0;*
 *foreach(var myElement in sortedHostList)*
 *{*
 *FIXME_VAR_TYPE element=hostData[myElement];*
 *// Do not try NAT enabled games if we cannot do NAT punchthrough*
 *// Do not try connecting to password protected games*
 *if ( !(filterNATHosts && element.useNat) && !element.passwordProtected  )*
 *{*
 *aHost=1;*
 *if(element.connectedPlayers<element.playerLimit)*
 *{* 
 *if(tryingToConnectPlayNow){*
 *FIXME_VAR_TYPE natText;*
 *if(Network.useNat){*
 *natText=" with option 1/2";*
 *}else{*
 *natText=" with option 2/2";*
 *}*
 *if((!Network.useNat && lastPlayNowConnectionTime+CONNECT_TIMEOUT<=Time.time) || (Network.useNat  && lastPlayNowConnectionTime+CONNECT_NAT_TIMEOUT<=Time.time)){*
 *Debug.Log("Interrupted by timer, NAT:"+Network.useNat);*
 *FailedConnRetry(NetworkConnectionError.ConnectionFailed);* 
 *}*
 *return "Trying to connect to host "+(tryingToConnectPlayNowNumber+1)+"/"+sortedHostList.length+" "+natText;* 
 *}* 
 *if(!tryingToConnectPlayNow && tryingToConnectPlayNowNumber<=i){*
 *Debug.Log("Trying to connect to game NR "+i+" & "+tryingToConnectPlayNowNumber);*
 *tryingToConnectPlayNow=true;*
 *tryingToConnectPlayNowNumber=i;*
 *// Enable NAT functionality based on what the hosts if configured to do*
 *lastMSConnectionAttemptForcedNat=element.useNat;*
 *Network.useNat = element.useNat;*
 *int connectPort=element.port;*
 *if (Network.useNat){*
 *print("Using Nat punchthrough to connect");*
 *}else{*
 *//connectPort=serverPort; //bad idea!*
 *print("Connecting directly to host");*
 *}*
 *Debug.Log("connecting to "+element.gameName+" "+element.ip+":"+connectPort);*
 *Network.Connect(element.ip, connectPort);* 
 *lastPlayNowConnectionTime=Time.time;*
 *}*
 *i++;* 
 *}*
 *}* 
 *}*
 *//If we reach this point then either we've parsed the whole list OR the list is still empty*
 *//Dont give up yet: Give MS 7 seconds to feed the list*
 *if(Time.time<timeStarted+7){*
 *FetchHostList(true);* 
 *return "Waiting for masterserver..."+Mathf.Ceil((timeStarted+7)-Time.time);* 
 *}*
 *if(!tryingToConnectPlayNow){*
 *return "failed";*
 *}*
*}*
*void  Update (){*
 *// If network test is undetermined, keep running*
 *if (!doneTestingNAT) {*
 *TestConnection();*
 *}*
*}*
*void  TestConnection (){*
 *// Start/Poll the connection test, report the results in a label and react to the results accordingly*
 *natCapable = Network.TestConnection();*
 *switch (natCapable) {*
 *case ConnectionTesterStatus.Error:* 
 *testMessage = "Problem determining NAT capabilities";*
 *doneTestingNAT = true;*
 *break;*
 *case ConnectionTesterStatus.Undetermined:* 
 *testMessage = "Undetermined NAT capabilities";*
 *doneTestingNAT = false;*
 *break;*
 *case ConnectionTesterStatus.PrivateIPNoNATPunchthrough:* 
 *testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, local LAN games only.";*
 *filterNATHosts = true;*
 *Network.useNat = true;*
 *doneTestingNAT = true;*
 *break;*
 *case ConnectionTesterStatus.PrivateIPHasNATPunchThrough:*
 *if (probingPublicIP)*
 *testMessage = "Non-connectable public IP address (port "+ serverPort +" blocked), NAT punchthrough can circumvent the firewall.";*
 *else*
 *testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality.";*
 *// NAT functionality is enabled in case a server is started,*
 *// clients should enable this based on if the host requires it*
 *Network.useNat = true;*
 *doneTestingNAT = true;*
 *break;*
 *case ConnectionTesterStatus.PublicIPIsConnectable:*
 *testMessage = "Directly connectable public IP address.";*
 *Network.useNat = false;*
 *doneTestingNAT = true;*
 *break;*
 *// This case is a bit special as we now need to check if we can* 
 *// cicrumvent the blocking by using NAT punchthrough*
 *case ConnectionTesterStatus.PublicIPPortBlocked:*
 *testMessage = "Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible.";*
 *Network.useNat = false;*
 *// If no NAT punchthrough test has been performed on this public IP, force a test*
 *if (!probingPublicIP)*
 *{*
 *Debug.Log("Testing if firewall can be circumnvented");*
 *natCapable = Network.TestConnectionNAT();*
 *probingPublicIP = true;*
 *timer = Time.time + 10;*
 *}*
 *// NAT punchthrough test was performed but we still get blocked*
 *else if (Time.time > timer)*
 *{*
 *probingPublicIP = false;        // reset*
 *Network.useNat = true;*
 *doneTestingNAT = true;*
 *}*
 *break;*
 *case ConnectionTesterStatus.PublicIPNoServerStarted:*
 *testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready.";*
 *break;*
 *default:* 
 *testMessage = "Error in test routine, got " + natCapable;*
 *}*
 *officialNATstatus=Network.useNat;*
 *if(doneTestingNAT){*
 *Debug.Log("TestConn:"+testMessage);*
 *Debug.Log("TestConn:"+natCapable + " " + probingPublicIP + " " + doneTestingNAT);*
 *}*
*}*
*private float lastHostListRequest = 0;*
*//Request the host limit, but we limit these requests*
*//Max once every two minutes automatically, max once every 5 seconds when manually requested*
*void  FetchHostList ( bool manual  ){*
 *int timeout = 120;*
 *if(manual){*
 *timeout=5;*
 *}*
 *if(lastHostListRequest==0 || Time.realtimeSinceStartup > lastHostListRequest + timeout){*
 *lastHostListRequest = Time.realtimeSinceStartup;*
 *MasterServer.RequestHostList (gameName);* 
 *yield return new WaitForSeconds(1);//We gotta wait :/* 
 *hostData = MasterServer.PollHostList();*
 *yield return new WaitForSeconds(1);//We gotta wait :/* 
 *CreateSortedArray();*
 *Debug.Log("Requested new host list, got: "+hostData.length);*
 *}*
*}*
*//The code below is all about sorting the game list by playeramount*
*public Array sortedHostList;*
*void  CreateSortedArray (){*
 *sortedHostList = new Array();* 
 *int i=0;*
 *HostData[] data = hostData;*
 *foreach(var element in data)*
 *{*
 *AddToArray(i);*
 *i++;* 
 *}* 
*}*
*void  AddToArray ( int nr  ){*
 *sortedHostList.Add (nr);* 
 *SortLastItem();*
*}*
*void  SortLastItem (){*
 *if(sortedHostList.length<=1){*
 *return;*
 *}*
 *for(FIXME_VAR_TYPE i=sortedHostList.length-1;i>0;i--){*
 *int value1= hostData[sortedHostList[i-1]].connectedPlayers;*
 _int value2 = hostData[sortedHostList*].connectedPlayers;*_
 _*if(value1<value2){*_
 _*SwapArrayItem((i-1), i);*_
 _*}else{*_
 _*//Sorted!*_
 _*return;*_
 _*}*_
 _*}*_
_*}*_
_*void  SwapArrayItem (nr1, nr2){*_
 <em>*FIXME_VAR_TYPE tmp=sortedHostList[nr1];*</em>
 _*sortedHostList[nr1]=sortedHostList[nr2];*_
 _*sortedHostList[nr2]=tmp;*_
_*}*_
_*}*_
_*```*_
_*<hr>*_
<em>*<p>As you see, the "var" parts get turned into "FIXME_VAR_TYPE" because it doesn't know the proper var, is there any list of any kind showing the differnet variable types you can use or could someone please tell me the proper things to put in those spots. And should I make the "Array" places into "Array List"? Any help or another converter would be appreciated.</p>*</em>

Actually, converting UnityScript to C# is probably best done via a .NET reverse compiler, of which there are quite a few available. Simply put the UnityScript file into Unity and let Unity compile the file. Then, grab the bytecode DLL from the folder [yourProject]/Library/ScriptAssemblies

Then, finally, take a .NET reverse compiler like .NET Reflector, use the DLL (it's called "Assembly - UnityScript.dll", or, if you have editor scripts in UnityScript you might need to look for the file "Assembly - UnityScript - Editor.dll"), look up the class in the tree, do disassemble on it, and show the methods - there you go.

What you get there is perfect C# code that will compile without any problem (well, it is compiled already). The only thing that will be missing is the comments; but you could easily copy those over if you really need them (obviously depends on what you want to use this for).

This is also a very interesting way to figure out how certain things in UnityScript/JavaScript are actually implemented in bytecode (it's sometimes good to know because sometimes, UnityScript will "look very simple" but produce code that's simply less than perfect ;-) ).

All of the FIXME_VAR_TYPE instances in the code are either bool, string or int (should be fairly easy to work out which is which)

And yes - you'll need to change Array to ArrayList, though that should be the only change I think seeing as ArrayList has Add just the same as Array

I don't think there is another convertor, so that's the best you're going to get (and I'll be honest, it's pretty damned good considering unity's javascript isn't much like other javascript implementations)

If you need to search for a list of types, MSDN has a pretty long list you can look through

You should change

public var gameName = "Example4";
public var serverPort =  35001;
...
public var filterNATHosts = false;

to

public var gameName : String = "Example4";
public var serverPort : int = 35001;
...
public var filterNATHosts : boolean = false;

and so on.

I don't know why `#pragma strict` does not complain about it (probably because you assign the variables directly), but if you tell javascript what type the variables are, your converter will know it, too.

I recently faced this same question myself and in my madness decided to write a new conversion tool…

For simple to medium complexity projects CSharpatron really will do everything necessary to fully convert a project from Unityscript to C# (e.g. I can convert the old Penelope example project in under 5 minutes with zero manual edits). For more complex projects (e.g. my own project at 107,000 lines), it brings conversion time down to a few hours with supporting tools for every step of the way.

CSharpatron is available on the Asset Store here. Hope it helps someone else.

Chris

http://www.m2h.nl/files/js_to_c.php

using UnityEngine;
using System.Collections.Generic;

public class Decal1 : MonoBehaviour
{
static public int dCount;

//The gameObjects that will be affected by the decal.
[HideInInspector]
public GameObject[] affectedObjects;

public float maxAngle = 90.0f;

private float angleCosine;

//Decal1 bounds. We'll never show it on inspector as user should
//not modify this value.
[HideInInspector]
public Bounds bounds;

#region STATE PROPERTIES
[HideInInspector]
public float previousUVAngle;

[HideInInspector]
public Vector3 previousPosition;

[HideInInspector]
public Quaternion previousRotation;

[HideInInspector]
public Vector3 previousScale;

[HideInInspector]
public float previousMaxAngle;

[HideInInspector]
public float previousPushDistance = 0.009f;

[HideInInspector]
public Vector2 previousTiling;

[HideInInspector]
public Vector2 previousOffset;

[HideInInspector]
public bool useMeshCollider;
#endregion

#region UV PROPERTIES
//[HideInInspector]
public Vector2 tiling = Vector2.one;

//[HideInInspector]
public Vector2 offset = Vector2.zero;

[HideInInspector]
public float uvAngle = 0.0f;
private float uCos;
private float vSin;
#endregion

public Material decalMaterial;

[HideInInspector]
public DecalMode decalMode;

#region DECAL CREATION PROPERTIES
private List<DecalPolygon> startPolygons;
private List<DecalPolygon> clippedPolygons;

[HideInInspector]
public Vector4 bottomPlane;

[HideInInspector]
public Vector4 topPlane;

[HideInInspector]
public Vector4 leftPlane;

[HideInInspector]
public Vector4 rightPlane;

[HideInInspector]
public Vector4 frontPlane;

[HideInInspector]
public Vector4 backPlane;

[HideInInspector]
public Vector3 decalNormal;// = transf.MultiplyVector(-transform.forward);

[HideInInspector]
public Vector3 decalCenter;// = transf.MultiplyPoint(transform.position);

[HideInInspector]
public Vector3 decalTangent;// = transf.MultiplyVector(transform.right);

[HideInInspector]
public Vector3 decalBinormal;// = transf.MultiplyVector(transform.up);

[HideInInspector]
public Vector3 decalSize;// = transf.MultiplyPoint(transform.lossyScale);
#endregion

public float pushDistance = 0.009f;

private List<MeshCombineUtility.MeshInstance> instancesList;

//Should the system stop checking for objects that will be affected?
public bool checkAutomatically;
public LayerMask affectedLayers;
public bool affectOtherDecals;
public bool affectInactiveRenderers;

#region INSPECTOR PROPERTIES
[HideInInspector]
public bool showAffectedObjectsOptions;

[HideInInspector]
public bool showObjects;
#endregion

// private void OnDrawGizmosSelected()
// {
// Gizmos.DrawIcon(transform.position, “decal_icon”);
// }

private void OnDrawGizmosSelected()
{
	//Calculate current decal bounds.
	CalculateBounds();
	
	//Gizmos.DrawRay(decalCenter, decalNormal);
	
	//Draw the helper gizmos with the correct object matrix.
	Gizmos.matrix = transform.localToWorldMatrix;
	Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}

//Method responsible for calculating decal's bounds, used to detect the 
//affected objects.
public void CalculateBounds()
{
	//Extend decal's bounds a little in order to make sure that everything will
	//still working when the projector is rotated.
	bounds = new Bounds(transform.position, transform.lossyScale * 1.414214f);
}

//Method responsible for constructing the Decal Mesh, based on the affected objects.
public void CalculateDecal()
{
	ClearDecals();
	
	maxAngle = Mathf.Clamp(maxAngle, 0.0f, 180.0f);
	angleCosine = Mathf.Cos(maxAngle * Mathf.Deg2Rad);
	
	uvAngle = Mathf.Clamp(uvAngle, 0.0f, 360.0f);
	uCos = Mathf.Cos(uvAngle * Mathf.Deg2Rad);
	vSin = Mathf.Sin(uvAngle * Mathf.Deg2Rad);
	
	if(affectedObjects == null)
	{
		//Debug.LogWarning("No object will be affected. Decal will not be calculated.");
		return;
	}
	else if(affectedObjects.Length <= 0)
	{
		//Debug.LogWarning("No object will be affected. Decal will not be calculated.");
		return;
	}
	
	//Current transform matrix
	Matrix4x4 myTransform = transform.worldToLocalMatrix;
	
	instancesList = new List<MeshCombineUtility.MeshInstance>();
	
	for(int i = 0; i < affectedObjects.Length; i++)
	{
		if(affectedObjects *== null) continue;*

_ CalculateObjectDecal(affectedObjects*, myTransform);_
_
}*_

* if(instancesList.Count > 0)*
* {*
* MeshCombineUtility.MeshInstance[] instances = new MeshCombineUtility.MeshInstance[instancesList.Count];*
* for(int i = 0; i < instances.Length; i++)*
* {*
instances = instancesList*;*
* }*

* MeshRenderer r = gameObject.GetComponent();*
* if(r == null)*
* {*
* r = gameObject.AddComponent();*
* }*

* r.material = decalMaterial;*

* MeshFilter fi = gameObject.GetComponent();*

* if(fi == null)*
* {*
* fi = gameObject.AddComponent();*
* }*
* else*
* {*
* DestroyImmediate(fi.sharedMesh);*
* }*

* Mesh finalMesh = MeshCombineUtility.Combine(instances, true);*

* if(pushDistance > 0.0f)*
* {*
* List<List> relations = new List<List>();*
* Vector3[] vert = finalMesh.vertices;*
* Vector3[] normals = finalMesh.normals;*

* bool[] usedIndex = new bool[vert.Length];*
* for(int i = 0; i < usedIndex.Length; i++)*
* {*
_ usedIndex = false;
* }*_

* for(int i = 0; i < vert.Length; i++)*
* {*
_ if(usedIndex*) continue;*_

* List c = new List();*
* c.Add(i);*

_ usedIndex = true;_

* for(int j = i + 1; j < vert.Length; j++)*
* {*
* if(usedIndex[j]) continue;*

_ if(Vector3.Distance(vert*, vert[j]) < 0.001f)
{
c.Add(j);*_

* usedIndex[j] = true;*
* }*
* } *

* relations.Add(c);*
* }*

* foreach(List l in relations)*
* {*
* Vector3 nNormal = Vector3.zero;*
* foreach(int i in l)*
* {*
_ nNormal += normals*;
}*_

* nNormal = (nNormal / l.Count).normalized;*

* foreach(int i in l)*
* {*
vert += nNormal * (pushDistance);
* }*
* }*

* finalMesh.vertices = vert;*
* }*

* finalMesh.name = “DecalMesh”;*

* fi.mesh = finalMesh;*
* for(int i = 0; i < instancesList.Count; i++)*
* {*
_ DestroyImmediate(instancesList*.mesh);
}
}*_

* instancesList.Clear();*
* instancesList = null;*
* }*

* public void ClearDecals()*
* {*
* MeshFilter auxFilter = gameObject.GetComponent();*

* if(auxFilter != null)*
* {*
* DestroyImmediate(auxFilter.sharedMesh);*
* DestroyImmediate(auxFilter);*
* }*

* MeshRenderer auxRenderer = gameObject.GetComponent();*

* if(auxRenderer != null)*
* {*
* DestroyImmediate(auxRenderer);*
* }*
* }*
* public void CalculateObjectDecal(GameObject obj, Matrix4x4 cTransform)*
* {*
* Mesh m = null;*

* if(decalMode == DecalMode.MESH_COLLIDER)
_ {
if(obj.GetComponent() != null)
{
m = obj.GetComponent().sharedMesh;
}
else*

* {
m = null;
}
}*_

* if(m == null || decalMode == DecalMode.MESH_FILTER)
_ {
if(obj.GetComponent() == null) return;*_

* m = obj.GetComponent().sharedMesh;*
* }*

* if(m == null || m.name.ToLower().Contains(“combined”))*
* {*
* return;*
* }*
* decalNormal = obj.transform.InverseTransformDirection(transform.forward);*
* decalCenter = obj.transform.InverseTransformPoint(transform.position);*
* decalTangent = obj.transform.InverseTransformDirection(transform.right);*
* decalBinormal = obj.transform.InverseTransformDirection(transform.up);*
* decalSize = new Vector3(transform.lossyScale.x / obj.transform.lossyScale.x, transform.lossyScale.y / obj.transform.lossyScale.y, transform.lossyScale.z / obj.transform.lossyScale.z);//transf.MultiplyPoint(transform.lossyScale);*

_ bottomPlane = new Vector4(-decalBinormal.x, -decalBinormal.y, -decalBinormal.z, (decalSize.y * 0.5f) + Vector3.Dot(decalCenter, decalBinormal));
topPlane = new Vector4(decalBinormal.x, decalBinormal.y, decalBinormal.z, (decalSize.y * 0.5f) - Vector3.Dot(decalCenter, decalBinormal));
rightPlane = new Vector4(-decalTangent.x, -decalTangent.y, -decalTangent.z, (decalSize.x * 0.5f) + Vector3.Dot(decalCenter, decalTangent));
leftPlane = new Vector4(decalTangent.x, decalTangent.y, decalTangent.z, (decalSize.x * 0.5f) - Vector3.Dot(decalCenter, decalTangent));
frontPlane = new Vector4(decalNormal.x, decalNormal.y, decalNormal.z, (decalSize.z * 0.5f) - Vector3.Dot(decalCenter, decalNormal));
backPlane = new Vector4(-decalNormal.x, -decalNormal.y, -decalNormal.z, (decalSize.z * 0.5f) + Vector3.Dot(decalCenter, decalNormal));_

* int[] triangles = m.triangles;*
* Vector3[] vertices = m.vertices;*
* Vector3[] normals = m.normals;*
* Vector4[] tangents = m.tangents;*

* float dot;*
* int i1, i2, i3;*
* Vector3 v1, v2, v3;*
* Vector3 n1;*
* Vector3 t1, t2, t3;*

* DecalPolygon t;*
* startPolygons = new List();*

* for(int i = 0; i < triangles.Length; i += 3)*
* {*
_ i1 = triangles*;
i2 = triangles[i+1];
i3 = triangles[i+2];*_

* v1 = vertices[i1];*
* v2 = vertices[i2];*
* v3 = vertices[i3];*
* n1 = normals[i1];*

* dot = Vector3.Dot(n1, -decalNormal);*

* if(dot <= angleCosine) continue;*
* t1 = tangents[i1];*
* t2 = tangents[i2];*
* t3 = tangents[i3];*

* t = new DecalPolygon();*
* t.verticeCount = 3;*
* t.vertice[0] = v1;*
* t.vertice[1] = v2;*
* t.vertice[2] = v3;*

* t.normal[0] = n1;*
* t.normal[1] = n1;*
* t.normal[2] = n1;*

* t.tangent[0] = t1;*
* t.tangent[1] = t2;*
* t.tangent[2] = t3;*

* startPolygons.Add(t);*
* }*

* Mesh aux = CreateMesh(ClipMesh(), obj.transform);*

* if(aux != null)*
* {*
* MeshCombineUtility.MeshInstance instance = new MeshCombineUtility.MeshInstance();*
* instance.mesh = aux;*
* instance.subMeshIndex = 0;*
_ instance.transform = transform.worldToLocalMatrix * obj.transform.localToWorldMatrix;
* instancesList.Add(instance);
}*_

* aux = null;*

* startPolygons.Clear();*
* startPolygons = null;*
* clippedPolygons.Clear();*
* clippedPolygons = null;*

* triangles = null;*
* normals = null;*
* vertices = null;*
* tangents = null;*

* System.GC.Collect();*
* }*

* private Mesh CreateMesh(int totalVertices, Transform to)*
* {*
* if(clippedPolygons == null) return null;*

* if(clippedPolygons.Count <= 0) return null;*

* if(totalVertices < 3) return null;*

_ int newTris = new int[(totalVertices - 2) * 3];
* Vector3 newVertices = new Vector3[totalVertices];
Vector3 newNormals = new Vector3[totalVertices];
Vector2 newUv = new Vector2[totalVertices];
Vector4 newTangents = new Vector4[totalVertices];*_

* int count = 0;*
* int trisCount = 0;*
* int oCount = 0;*

* float u, v, tempU, tempV;*
* Vector3 dir;*

* float one_over_w = 1.0f / decalSize.x;
float one_over_h = 1.0f / decalSize.y;*

* foreach(DecalPolygon p in clippedPolygons)*
* { *
* for(int i = 0; i < p.verticeCount; i++)*
* {*
_ newVertices[count] = p.vertice*;
newNormals[count] = p.normal;
newTangents[count] = p.tangent;
if(i < p.verticeCount - 2)
{
newTris[trisCount] = oCount;
newTris[trisCount+1] = count+1;
newTris[trisCount+2] = count+2;
trisCount += 3;
}*_

* count++;*
* }*
* oCount = count;*
* }*

* for(int i = 0; i < newVertices.Length; i++)*
* {*
_ dir = newVertices - decalCenter;_

tempU = (Vector3.Dot(dir, decalTangent) * one_over_w);// + 0.5f);// * tiling.x;// + offset.x;
tempV = (Vector3.Dot(dir, decalBinormal) * one_over_h);// + 0.5f);// * tiling.y;// + offset.y;

_ u = tempU * uCos - tempV * vSin + 0.5f;
v = tempU * vSin + tempV * uCos + 0.5f;_

_ u *= tiling.x;
v *= tiling.y;_

* u += offset.x;*
* v += offset.y;*
newUv = new Vector2(u, v);// * vSin);
* }*

* Mesh m = new Mesh();*
* m.vertices = newVertices;*
* m.normals = newNormals;*
* m.triangles = newTris;*
* m.uv = newUv;*
* m.uv1 = newUv;*
* m.uv2 = newUv; *
* m.tangents = newTangents;*

* return m;*
* }*
* private int ClipMesh()*
* {*
* DecalPolygon tempFace, face;*

* int totalVertices = 0;*

* if(clippedPolygons == null) clippedPolygons = new List();*
* else clippedPolygons.Clear();*

* for(int i = 0; i < startPolygons.Count; i++)*
* {*
_ face = startPolygons*;
tempFace = DecalPolygon.ClipPolygonAgainstPlane(face, frontPlane);
if(tempFace != null)
{
tempFace = DecalPolygon.ClipPolygonAgainstPlane(tempFace, backPlane);
if(tempFace != null)
{
tempFace = DecalPolygon.ClipPolygonAgainstPlane(tempFace, rightPlane);
if(tempFace != null)
{
tempFace = DecalPolygon.ClipPolygonAgainstPlane(tempFace, leftPlane);
if(tempFace != null)
{
tempFace = DecalPolygon.ClipPolygonAgainstPlane(tempFace, bottomPlane);
if(tempFace != null)
{
tempFace = DecalPolygon.ClipPolygonAgainstPlane(tempFace, topPlane);
if(tempFace != null)
{
totalVertices += tempFace.verticeCount;
clippedPolygons.Add(tempFace);
}
}
}
}
}
}
}*_

* return totalVertices;*
* }*

* //Has the Decal changed since the last call to this method?*
* public bool HasChanged()*
* {*
* Transform t = transform;*
* bool changed = false;*
* maxAngle = Mathf.Clamp(maxAngle, 0.0f, 180.0f);*
* uvAngle = Mathf.Clamp(uvAngle, 0.0f, 360.0f);*

* if(previousPosition != t.position)*
* {*
* changed = true;*
* }*
* else if(previousScale != t.lossyScale)*
* {*
* changed = true;*
* }*
* else if(previousRotation != t.rotation)*
* {*
* changed = true;*
* }*
* else if(previousPushDistance != pushDistance)*
* {*
* changed = true;*
* }*
* else if(previousTiling != tiling)*
* {*
* changed = true;*
* }*
* else if(previousOffset != offset)*
* {*
* changed = true;*
* }*
* else if(previousMaxAngle != maxAngle)*
* {*
* changed = true;*
* }*
* else if(previousUVAngle != uvAngle)*
* {*
* changed = true;*
* }*

* previousUVAngle = uvAngle;*
* previousMaxAngle = maxAngle;*
* previousTiling = tiling;*
* previousOffset = offset;*
* previousPushDistance = pushDistance;*
* previousPosition = t.position;*
* previousRotation = t.rotation;*
* previousScale = t.lossyScale;*

* return changed;*
* }*
}