Example #1
0
        public GeneratorProcess Generate(Config config)
        {
            this.sizeXbits = config.worldSize.worldSizeBitsX;
            this.sizeYbits = config.worldSize.worldSizeBitsY;
            this.sizeZbits = config.worldSize.worldSizeBitsZ;

            sizeX = 1 << sizeXbits;
            sizeY = 1 << sizeYbits;
            sizeZ = 1 << sizeZbits;

            gameplay = config.gameplay.gameplay;
            gameplay.Init(this);
			
			tileManager.Create(config.tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
			itemManager.Create(config.itemDefinitions);
			
            avatarManager.Create(config.avatarDefinitions);

			sectorManager.Create();
			dayCycleManager.Create(config.dayInfo);

            configSurroundings = config.worldGenerator.surroundings;
            configExtraMaterials = config.extraMaterials;

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            return gameplay.Generate(config);
		}
    public void CreateSurroundings(ConfigSurroundings configSurroundings)
    {
        if (configSurroundings.surroundingMaterial >= 0)
        {
            float SURROUNDING_PLANE_SIZE = 1000.0f;
            float SURROUNDING_PLANE_SCALE = 10.0f;

            float surroundingLevel = configSurroundings.surroundingLevel.EvaluateInt(gameManagerUnity.world);
            surroundingLevel += configSurroundings.surroundingOffsetY;

            CubeWorld.World.CubeWorld world = gameManagerUnity.world;

            goContainer = new GameObject();
            goContainer.name = "Surroundings";
            goContainer.transform.position = new Vector3(0, 0, 0);
            goContainer.transform.rotation = Quaternion.identity;
            goContainer.transform.localScale = new Vector3(1, 1, 1);

            GameObject goPlane1 = GameObject.CreatePrimitive(PrimitiveType.Plane);
            goPlane1.name = "A1";
            goPlane1.transform.parent = goContainer.transform;
            GameObject goPlane2 = GameObject.CreatePrimitive(PrimitiveType.Plane);
            goPlane2.name = "A2";
            goPlane2.transform.parent = goContainer.transform;
            GameObject goPlane3 = GameObject.CreatePrimitive(PrimitiveType.Plane);
            goPlane3.name = "A3";
            goPlane3.transform.parent = goContainer.transform;
            GameObject goPlane4 = GameObject.CreatePrimitive(PrimitiveType.Plane);
            goPlane4.name = "A4";
            goPlane4.transform.parent = goContainer.transform;

            goPlane1.renderer.material = new Material(materialSurrounding);
            goPlane2.renderer.material = new Material(materialSurrounding);
            goPlane3.renderer.material = new Material(materialSurrounding);
            goPlane4.renderer.material = new Material(materialSurrounding);
			
            Texture2D surroundingTexture = GraphicsUnity.GetTilesetTexture((Texture2D) gameManagerUnity.materialTransparent.mainTexture, configSurroundings.surroundingMaterial);
            surroundingTexture.wrapMode = TextureWrapMode.Repeat;

            goPlane1.renderer.material.mainTexture = surroundingTexture;
            goPlane2.renderer.material.mainTexture = surroundingTexture;
            goPlane3.renderer.material.mainTexture = surroundingTexture;
            goPlane4.renderer.material.mainTexture = surroundingTexture;

            goPlane1.transform.localScale = new Vector3(world.sizeX / SURROUNDING_PLANE_SCALE, 0, SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE);
            goPlane1.transform.position = new Vector3(world.sizeX / 2.0f - 0.5f, surroundingLevel - 0.5f, -SURROUNDING_PLANE_SIZE / 2.0f - 0.5f);
            goPlane1.renderer.material.mainTextureScale = new Vector2(goPlane1.transform.localScale.x * SURROUNDING_PLANE_SCALE, goPlane1.transform.localScale.z * SURROUNDING_PLANE_SCALE);

            goPlane2.transform.localScale = new Vector3(world.sizeX / SURROUNDING_PLANE_SCALE, 0, SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE);
            goPlane2.transform.position = new Vector3(world.sizeX / 2.0f - 0.5f, surroundingLevel - 0.5f, world.sizeZ - 0.5f + SURROUNDING_PLANE_SIZE / 2.0f);
            goPlane2.renderer.material.mainTextureScale = new Vector2(goPlane2.transform.localScale.x * SURROUNDING_PLANE_SCALE, goPlane2.transform.localScale.z * SURROUNDING_PLANE_SCALE);

            goPlane3.transform.localScale = new Vector3(SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE, 0, SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE * 2.0f + world.sizeX / SURROUNDING_PLANE_SCALE);
            goPlane3.transform.position = new Vector3(world.sizeX + SURROUNDING_PLANE_SIZE / 2.0f - 0.5f, surroundingLevel - 0.5f, world.sizeZ / 2.0f - 0.5f);
            goPlane3.renderer.material.mainTextureScale = new Vector2(goPlane3.transform.localScale.x * SURROUNDING_PLANE_SCALE, goPlane3.transform.localScale.z * SURROUNDING_PLANE_SCALE);

            goPlane4.transform.localScale = new Vector3(SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE, 0, SURROUNDING_PLANE_SIZE / SURROUNDING_PLANE_SCALE * 2.0f + world.sizeX / SURROUNDING_PLANE_SCALE);
            goPlane4.transform.position = new Vector3(-SURROUNDING_PLANE_SIZE / 2.0f - 0.5f, surroundingLevel - 0.5f, world.sizeZ / 2.0f - 0.5f);
            goPlane4.renderer.material.mainTextureScale = new Vector2(goPlane4.transform.localScale.x * SURROUNDING_PLANE_SCALE, goPlane4.transform.localScale.z * SURROUNDING_PLANE_SCALE);

            goSurroundings.Add(goPlane1);
            goSurroundings.Add(goPlane2);
            goSurroundings.Add(goPlane3);
            goSurroundings.Add(goPlane4);
        }
    }
Example #3
0
        private void Load(BinaryReader br, bool isMultiplayer)
        {
            this.sizeXbits = br.ReadInt32();
            this.sizeYbits = br.ReadInt32();
            this.sizeZbits = br.ReadInt32();

            sizeX = 1 << sizeXbits;
            sizeY = 1 << sizeYbits;
            sizeZ = 1 << sizeZbits;

            if (isMultiplayer == false)
            {
                string gameplayId = br.ReadString();

                gameplay = GameplayFactory.GetGameplayById(gameplayId);
                gameplay.Init(this);
                gameplay.Load(br);
            }
            else
            {
                gameplay.Init(this);
            }

            configSurroundings = new ConfigSurroundings();
            configSurroundings.Load(br);
        }