コード例 #1
0
        public override void Init()
        {
            base.Init();
            var material = Obj.GetComponent <Renderer>().material;
            var texture  = material.mainTexture as Texture2D;

            if (texture == null)
            {
                Debug.LogError("The material does not have a main texture!", material);
                return;
            }
            if (texture.width != texture.height)
            {
                Debug.LogError("Texture is not square! will not generate terrain.", texture);
                return;
            }

            // Get the texture values (these need to be grabbed here because we can't get them
            // outside of the main thread)
            var tPixels = texture.GetPixels();
            var tWidth  = texture.width;
            var tHeight = texture.height;

            // TODO: This is not working. Runs a dynamically generated texture to plug onto a sphere (planet)
            // Run this async
            //Task.Factory.StartNew(() =>
            //{
            //    // Run atmospheric initalise AFTER minerals
            //    // this is so we get the same atmos density and mineral density for gas planets
            //    MaterialWealth.Init();
            //    Atmosphere.Init();

            //    // This is a very slow process
            //    return TerrainGenerator.GenerateHeightmap(material, tPixels, tHeight, tWidth, Seed);
            //}).ContinueWith(FinaliseInit, TaskScheduler.FromCurrentSynchronizationContext());

            // --------------------------------------------------
            // This is shitty sync code
            MaterialWealth.Init();
            Atmosphere.Init();

            // This is a very slow process
            //var tex = TerrainGenerator.GenerateHeightmap(material, tPixels, tHeight, tWidth, Seed);

            //var finalTex = new Texture2D(tex.Width, tex.Height);
            //finalTex.SetPixels(tex.Image);
            //finalTex.Apply();

            //var finalMat = new Material(Obj.GetComponent<Renderer>().material) { mainTexture = finalTex };

            //Obj.GetComponent<Renderer>().material = finalMat;
            // ----------------------------------------------------
        }