Esempio n. 1
0
        public void Lod(LodMode lodMode)
        {
            Vector3 cameraPosition = cameraMainT.position;

            for (int i = 0; i < lods.Length - 1; i++)
            {
                lods[i].sphere.center = cameraPosition;
                lods[i].sphere.radius = distances[i + 1];
            }

            // if (Benchmark.active) lodBenchmark.Start();
            if (lodMode == LodMode.Automatic)
            {
                octree.AutoLodInternal(lods, lodCulled ? lodCullDistance : -1);
            }
            else
            {
                octree.LodInternal(lods, showLod);
            }
            // if (Benchmark.active) lodBenchmark.Stop();
        }
Esempio n. 2
0
        internal void InitSelection()
        {
            if (unityTerrain != null)
            {
                Object.DestroyImmediate(unityTerrain);
                unityTerrain = null;
                if (defaultChild != null)
                {
                    Selection.activeTransform = defaultChild.transform;
                    vertexInfo = trisInfo = partsOfTerrain = 0;
                    if (nbrTerrainObject == 0)
                    {
                        TerrainObject t = defaultChild.gameObject.GetComponent <TerrainObject>();
                        t.enabledLODSystem = activateLOD;
                        t.enabledBillboard = activateBillboard;
                        t.enabledLayerCul  = activateLayerCul;
                        t.closeView        = closeView;
                        t.normalView       = normalView;
                        t.farView          = farView;
                        t.backgroundView   = backgroundView;
                        t.master           = 1;
                    }
                }
            }

            if (currentSelect != null &&
                currentSelect.GetComponent <TerrainObject>() != null &&
                currentSelect.GetComponent <TerrainObject>().material != null)
            {
                currentSelect.gameObject.layer = LayerType.TERRAIN;
                initMaster = false;
                TerrainObject to = currentSelect.GetComponent <TerrainObject>();
                for (int i = 0, len = layers.Length; i < len; i++)
                {
                    if (to.material.HasProperty(layers[i].name))
                    {
                        layers[i].texture = to.material.GetTexture(layers[i].name);
                        layers[i].tile    = to.material.GetTextureScale(layers[i].name);
                    }
                    else
                    {
                        layers[i].texture = null;
                    }
                    layers[i].bumpTexture = to.material.HasProperty(layers[i].bumpName)
                        ? to.material.GetTexture(layers[i].bumpName)
                        : null;
                    if (to.material.HasProperty("_ShininessL" + i))
                    {
                        layers[i].shiness = to.material.GetFloat("_ShininessL" + i);
                    }
                }
                if (to.material.HasProperty("_SpecColor"))
                {
                    shinessColor = to.material.GetColor("_SpecColor");
                }

                TerrainObject curr = currentSelect.gameObject.GetComponent <TerrainObject>();

                CheckShader();

                activateLOD       = curr.enabledLODSystem;
                activateBillboard = curr.enabledBillboard;
                activateLayerCul  = curr.enabledLayerCul;

                maxViewDist    = curr.maxViewDistance;
                lod2Start      = curr.lod2Start;
                lod3Start      = curr.lod3Start;
                updateInterval = curr.interval;
                playerCamera   = curr.playerCamera;
                billInterval   = curr.billboardInterval;
                billDist       = curr.billmaxViewDistance;
                backgroundView = curr.backgroundView;
                farView        = curr.farView;
                normalView     = curr.normalView;
                closeView      = curr.closeView;

                lodController = curr.mode == 1 ? LodMode.Mass_Control : LodMode.Independent_Control;

                billboardAxis = curr.axis == 0 ? BillBoardAxis.Y_Axis : BillBoardAxis.All_Axis;
                lodOcclusion  = curr.lodBasedOnScript
                    ? OcclusionMode.Max_View_Disance
                    : OcclusionMode.Layer_Cull_Distance;

                billboardOcclusion = curr.billboardBaseOnScript
                    ? OcclusionMode.Max_View_Disance
                    : OcclusionMode.Layer_Cull_Distance;

                billActivate = curr.billboardPosition != null && curr.billboardPosition.Length > 0;
                lodActivate  = curr.objPostion != null && curr.objPostion.Length > 0;

                if (playerCamera == null && Camera.main)
                {
                    playerCamera = Camera.main.transform;
                }
                else if (playerCamera == null && !Camera.main)
                {
                    Camera[] cam = Object.FindObjectsOfType <Camera>();

                    foreach (Camera t in cam)
                    {
                        if (t.GetComponent <AudioListener>())
                        {
                            playerCamera = t.transform;
                        }
                    }
                }


                if (curr.material.HasProperty("_Control2") && curr.material.GetTexture("_Control2"))
                {
                    maskTexture2 = curr.material.GetTexture("_Control2") as Texture2D;
                }
                else
                {
                    maskTexture2 = null;
                }
                if (curr.material.HasProperty("_Control"))
                {
                    maskTextureUV = curr.material.GetTextureScale("_Control").x;
                    maskTexture   = curr.material.GetTexture("_Control") as Texture2D;
                    initialized   = true;
                }
            }
            Projector[] projectorObj = Object.FindObjectsOfType <Projector>();
            if (projectorObj.Length > 0)
            {
                foreach (var p in projectorObj)
                {
                    if (p.gameObject.name == TerrainCenter.PREVIEWER_NAME)
                    {
                        Object.DestroyImmediate(p.gameObject);
                    }
                }
            }
            terrainDat      = null;
            vertexInfo      = 0;
            trisInfo        = 0;
            partsOfTerrain  = 0;
            textures        = null;
            terrainSelectId = Selection.activeInstanceID;
        }