Exemple #1
0
        static void StartupModule()
        {
            //Add Shutodown ent
            Application.quitting += ShutdownModule;

            /// Current surpport windows and 64bit
            Check((Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) && System.IntPtr.Size == 8);


            //set unity log function
            VsUtility.Log        = Debug.Log;
            VsUtility.LogError   = Debug.LogError;
            VsUtility.LogWarning = Debug.LogWarning;


            //Set Unity Data and dll path
            VsModule.VsPath          = System.IO.Path.Combine(Application.streamingAssetsPath, "CarSim");
            VsModule.VsEngineUserDir = System.IO.Path.Combine(Application.persistentDataPath, "CarSim_plugin");
            VsModule.EnableVsVehicle = true;

            //In unity VS Connect Server is halfway
            VsModule.EnableVsConnectServer = false;
            //Reset CreateVsConnectServerFunc for Unity
            //VsModule.CreateVsConnectServerFunc = () => new VsConnectServerUnity();

            Log(("CarSim Module starting..."));

            VsModule.StartupModule();
        }
Exemple #2
0
 /// <summary>
 /// Processing at the end of Unity
 /// </summary>
 static void ShutdownModule()
 {
     VsModule.ShutdownModule();
 }
Exemple #3
0
        static void Main(string[] args)
        {
            //Set VSPath to the execution path
            VsModule.VsPath = System.Windows.Forms.Application.StartupPath;
            //
            VsModule.VsEngineUserDir = System.IO.Path.Combine(VsModule.VsPath, "Engine");

            //VSConnectServer is enabled.
            VsModule.EnableVsConnectServer = true;
            //Start Module
            VsModule.StartupModule();


            //Server time(second)
            double worldTime = 0;

            ///Tick Interval time 1 second
            TimeSpan Interval = TimeSpan.FromSeconds(1);



            double nextWorldTime = 0;
            double clientTime    = 0;



            //get server object
            var server = VsConnectServer.Singleton;

            BestMedia.VsDotnet.VsUtility.Check(server != null);

            //Add Server object  and register object
            BestMedia.VsDotnet.VsConnectSolver serverSolver = new BestMedia.VsDotnet.VsConnectSolver()
            {
                VscObjectName = "ServerObject"
            };
            server.RegisterObject(serverSolver);


            //Add age name action. world Time second to minutes.
            serverSolver.GetDoubleFuncs.Add("Age", () => worldTime / 60);


            //Add Client object and register object
            BestMedia.VsDotnet.VsConnectSolver clientSolver = new BestMedia.VsDotnet.VsConnectSolver()
            {
                VscObjectName = "ClientObject"
            };
            server.RegisterObject(clientSolver);

            //Add age name funcrtion that set climent time
            clientSolver.SetDoubleActions.Add("Age", (v) => { clientTime = v; Log($"Client Age{clientTime:0.00}"); });


            //set loop start time
            DateTime LoopStartTime = DateTime.Now;



            while (true)
            {
                ///Calc world time;
                worldTime = (DateTime.Now - LoopStartTime).TotalSeconds;
                Log($"World Age{worldTime/60:0.00}[minutes]");

                //Tick server object
                server.Tick(worldTime, 1);

                //Calc next loop time
                nextWorldTime += Interval.TotalSeconds;
                worldTime      = (DateTime.Now - LoopStartTime).TotalSeconds;

                //Sleep time until next  time
                if (nextWorldTime > worldTime)
                {
                    System.Threading.Thread.Sleep((int)(1000 * (nextWorldTime - worldTime)));
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo consoleKey = Console.ReadKey(true);
                    if (consoleKey.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }



            VsModule.ShutdownModule();
        }