Exemple #1
0
    void Start()
    {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.pauseStateChanged += EditorApplication_pauseStateChanged;
#endif
        Definitions.Logger.LogError += (s) => Debug.LogError(s);
        Definitions.Logger.Log      += (s) => Debug.LogError(s);
        SyncTypesMap.Init();
        EnvironmentAPI.Curve = new UnityCurveApi();
        DefsHolder.Instance  = new Defs(new FolderLoader(Application.dataPath + "/../../Yogollag/Defs"));
        Debug.LogError(DefsHolder.Instance.Deserializer.Loader.GetRoot());
        foreach (var root in DefsHolder.Instance.Deserializer.Loader.AllPossibleRoots)
        {
            //Debug.LogError(root);
            DefsHolder.Instance.LoadDef <BaseDef>(root);
        }
        server = new SimpleServer();
        server.Start(9043);
        client = new SimpleClient();
        client.Start(new RemoteConnectionToken()
        {
            IP = "127.0.0.1", Port = 9043
        }, false);
        _source = new CancellationTokenSource();
        Yogollag.EnvironmentAPI.Input = new UnityInputImpl();
        Yogollag.EnvironmentAPI.Time  = new UnityTimeImpl();
        EnvironmentAPI.Draw           = new UnityDrawImpl()
        {
            material = SimpleDrawMaterial
        };
        EnvironmentAPI.Win   = new UnityWindowApi();
        EnvironmentAPI.Imgui = new UnityImguiApi();
        Task.Run(async() =>
        {
            while (!_source.Token.IsCancellationRequested)
            {
                UnityEngine.Profiling.Profiler.BeginSample("SERVER TICK");
                server.Update();
                UnityEngine.Profiling.Profiler.EndSample();
                await Task.Delay(5);
            }
        });
        client._node.LostEntity += _node_LostEntity;
    }