예제 #1
0
        //lightmap纹理加载全部完成后的回调,初始化LightmapData数组
        private void OnLoadLightmap(SceneLightInfo lmInfo)
        {
            //初始化LightmapData数组
            if (m_lightmDatas == null ||
                (m_lightmDatas.Length == 0 && lmInfo.DataCount > 0))
            {
                {
                    m_lightmDatas = new LightmapData[lmInfo.DataCount];
                    for (int i = 0; i < m_lightmDatas.Length; i++)
                    {
                        m_lightmDatas[i] = new LightmapData();
                    }
                }

                for (int i = 0; i < lmInfo.lightmapTexNames.Length; i++)
                {
                    LightmapData corData     = m_lightmDatas[lmInfo.dataIndexes[i]];
                    Texture2D    lightmapTex = null;
                    if (m_listLightmapTex[i] != null)
                    {
                        lightmapTex = m_listLightmapTex[i];
                    }

                    switch (lmInfo.types[i])
                    {
                    case SceneLightInfo.ELightmapType.color:
                        corData.lightmapColor = lightmapTex;
                        break;

                    case SceneLightInfo.ELightmapType.dir:
                        corData.lightmapDir = lightmapTex;
                        break;

                    case SceneLightInfo.ELightmapType.shadowmask:
                        corData.shadowMask = lightmapTex;
                        break;
                    }
                }
            }

            LightmapSettings.lightmaps     = m_lightmDatas;
            LightmapSettings.lightmapsMode = lmInfo.lightmapMode;
        }
예제 #2
0
        /// <summary>
        /// 获取主角(0-1)位置
        /// </summary>
        //public Vector2 PlayerPosPercent
        //{
        //    get
        //    {
        //        if (m_mapInfo == null)
        //        {
        //            return Vector2.zero;
        //        }

        //        Vector2 mapOri = m_mapInfo.originPos.ToVector2();
        //        return new Vector2((m_playerPos.x - mapOri.x) / m_mapInfo.xLenth,
        //            (m_playerPos.z - mapOri.y) / m_mapInfo.zLenth);
        //    }
        //}

        //public float GetHeight(Vector2 pos)
        //{
        //    if (m_mapInfo == null || m_heightMap == null)
        //    {
        //        return 0.0f;
        //    }

        //    float xf = ((pos.x - m_mapInfo.heightMapOriX) / m_mapInfo.heightMapSizeX);
        //    float yf = ((pos.y - m_mapInfo.heightMapOriZ) / m_mapInfo.heightMapSizeZ);
        //    //xf = Mathf.Clamp(xf, 0.0f, 1.0f);
        //    //yf = Mathf.Clamp(yf, 0.0f, 1.0f);
        //    //xf = xf * 1024 - 0.5f;
        //    //yf = yf * 1024 - 0.5f;
        //    //int x = (int)xf;
        //    //int y = (int)yf;
        //    //xf -= x;
        //    //yf -= y;
        //    //int x2 = Mathf.Clamp(x + 1, 0, 1023);
        //    //int y2 = Mathf.Clamp(y + 1, 0, 1023);
        //    //x = Mathf.Clamp(x, 0, 1023);
        //    //y = Mathf.Clamp(y, 0, 1023);

        //    //float[] valueArr = new float[4];
        //    //valueArr[0] = YuGraphAlgorithm.SamplarRG(m_heightMap, x, y);// m_heightMap.GetPixel(x, y).r;
        //    //valueArr[1] = YuGraphAlgorithm.SamplarRG(m_heightMap, x2, y);//m_heightMap.GetPixel(x2, y).r;
        //    //valueArr[2] = YuGraphAlgorithm.SamplarRG(m_heightMap, x, y2);//m_heightMap.GetPixel(x, y2).r;
        //    //valueArr[3] = YuGraphAlgorithm.SamplarRG(m_heightMap, x2, y2);//m_heightMap.GetPixel(x2, y2).r;

        //    //float valueFin = YuGraphAlgorithm.LinearSamplar(new Vector2(xf, yf), valueArr);

        //    float valueFin = YuGraphAlgorithm.LinearSamplarRG(m_heightMap, xf, yf);

        //    return valueFin * m_mapInfo.heightMapSizeY + m_mapInfo.heightMapMinY + 0.01f;
        //}


        //打开地图时,构建马上需要的场景对象、数据
        private void BuildMap()
        {
            //初始化lightmap
            if (m_mapInfo.lightmapInfo != null)
            {
                SceneLightInfo lmInfo = m_mapInfo.lightmapInfo;

                //初始化lightmap纹理资源
                if (m_listLightmapTex == null)
                {
                    m_listLightmapTex = new List <Texture2D>();
                }
                m_listLightmapTex.Clear();
                if (m_listLightmapTex.Count == 0 && lmInfo.DataCount > 0)
                {
                    for (int i = 0; i < lmInfo.lightmapTexPath.Length; i++)
                    {
                        m_listLightmapTex.Add(null);
                        //---读取lightmap纹理资源的操作
                        var texture = AssetDatabase.LoadAssetAtPath <Texture2D>(lmInfo.lightmapTexPath[i]);
                        if (texture == null)
                        {
#if UNITY_EDITOR
                            Debug.LogError("lightMap纹理读取失败:" + lmInfo.lightmapTexNames[i]);
#endif
                        }

                        m_listLightmapTex[i] = texture;

                        //最后一个图片加载完成则初始化LightmapData数组
                        if (i == lmInfo.lightmapTexPath.Length - 1)
                        {
                            OnLoadLightmap(lmInfo);
                        }
                    }
                }

                //设置天空盒
                RenderSettings.skybox = m_skyBoxMat;
            }

            //设置主平行光
            if (m_mapInfo.hasLight)
            {
                m_mainLight.enabled            = true;
                m_mainLight.color              = m_mapInfo.lightColor.ToVector4();
                m_mainLight.intensity          = m_mapInfo.lightIntensity;
                m_mainLight.transform.position = m_mapInfo.lightPos.ToVector3();
                m_mainLight.transform.forward  = m_mapInfo.lightDir.ToVector3();
            }
            else
            {
                m_mainLight.enabled = false;
            }

            //设置雾
            if (m_mapInfo.hasFog)
            {
                RenderSettings.fog              = true;
                RenderSettings.fogColor         = m_mapInfo.fogColor.ToVector4();
                Camera.main.backgroundColor     = m_mapInfo.fogColor.ToVector4();
                RenderSettings.fogMode          = (FogMode)m_mapInfo.fogMode;
                RenderSettings.fogStartDistance = m_mapInfo.fogStart;
                RenderSettings.fogEndDistance   = m_mapInfo.fogEnd;
                RenderSettings.fogDensity       = m_mapInfo.fogDensity;
            }
            else
            {
                RenderSettings.fog = false;
            }

            //创建的游戏场景对象父节点
            if (m_mapInfo.layers != null)
            {
                foreach (var info in m_mapInfo.layers) //创建
                {
                    if (!m_dicLayer.ContainsKey(info.layerName))
                    {
                        GameObject gameObj = new GameObject(info.layerName);
                        gameObj.transform.position    = info.pos.ToVector3();
                        gameObj.transform.eulerAngles = info.rot.ToVector3();
                        gameObj.transform.localScale  = info.scal.ToVector3();
                        m_dicLayer.Add(info.layerName, gameObj);

                        if (info.layerName == m_curMapName)
                        {
                            m_rootObj = gameObj;
                            m_rootObj.transform.SetParent(GameObject.Find("SceneRoot").transform);
                        }
                    }
                }

                if (m_rootObj == null)
                {
                    Debug.LogError("错误,没有找到地图根节点!");
                }

                foreach (var info in m_mapInfo.layers) //设置父级
                {
                    string parentName = MyMapTool.GetNameByELater(info.parentLayer, m_curMapName);

                    if (!string.IsNullOrEmpty(parentName) && m_dicLayer.ContainsKey(info.layerName))
                    {
                        GameObject gameObj   = m_dicLayer[info.layerName];
                        GameObject parentObj = m_dicLayer[parentName];
                        if (gameObj != null)
                        {
                            gameObj.transform.parent = parentObj != null ? parentObj.transform : null;
                        }
                    }
                }
            }

            //    //请求跳跃点数据
            //    if (m_areaInfo == null)
            //    {
            //        m_getJumpPointEventId = m_eventModule.WatchEvent(
            //            YuUnityEventCode.Scene_SendJumpPoint, OnGetJumpPoint);
            //        m_eventModule.TriggerEvent(YuUnityEventCode.Scene_RequestJumpPoint,
            //            null, m_curMapId);
            //    }
        }