예제 #1
0
        private void CreateWorld()
        {
            network             = new LiteNetLibNetwork();
            networkCommandQueue = new NetworkCommandQueue(network);
            networkCommandQueue.InitReceived +=
                (sender, init) =>
            {
                rand = new Random(init.Seed);
                for (int i = 0; i < 100; i++)
                {
                    var mushroom = scene.CreateChild("Mushroom");
                    mushroom.Position = new Vector3(rand.Next(90) - 45, 0, rand.Next(90) - 45);
                    mushroom.Rotation = new Quaternion(0, rand.Next(360), 0);
                    mushroom.SetScale(0.5f + rand.Next(20000) / 10000.0f);
                    var mushroomObject = mushroom.CreateComponent <StaticModel>();
                    mushroomObject.Model = ResourceCache.GetModel("Models/Mushroom.mdl");
                    mushroomObject.SetMaterial(ResourceCache.GetMaterial("Materials/Mushroom.xml"));
                }

                simulation.Start(init.SimulationSpeed, init.ActorID, init.AllActors);
            };

            simulation = new Simulation(Contexts.sharedInstance, networkCommandQueue, new ViewService(ResourceCache, scene.GetChild("Jacks")));

            network.Start();
            network.Connect("127.0.0.1", 9050);
        }
    private void Awake()
    {
        Instance = this;

        Log.OnMessage += (sender, args) => Debug.Log(args.Message);

        _commandQueue = new NetworkCommandQueue(_client)
        {
            LagCompensation = 10
        };
        _commandQueue.InitReceived += (sender, init) =>
        {
            AllActorIds = init.AllActors;
            Debug.Log($"Starting simulation. Total actors: {init.AllActors.Length}. Local ActorID: {init.ActorID}");
            Simulation.Start(init.SimulationSpeed, init.ActorID, init.AllActors);
        };

        Simulation = new Simulation(Contexts.sharedInstance, _commandQueue, new UnityGameService(EntityDatabase));
    }