Пример #1
0
 private static void UpdateLightmapData()
 {
     foreach (RecordLightData _recordLightData in _lodGameObjectDataList)
     {
         LightDataWrapper _lightDataWrapper = _recordLightData._lightDataWrapper;
         foreach (LightData _lightData in _lightDataWrapper._lightDatas)
         {
             Renderer _render = _lightData._obj.GetComponent <Renderer>();
             _lightData._index  = _render.lightmapIndex;
             _lightData._offset = _render.lightmapScaleOffset;
         }
     }
 }
Пример #2
0
    private static void RecordLODLightmapDatas()
    {
        LODGroup[] _objs = FindObjectsOfType <LODGroup>();
        foreach (LODGroup _obj in _objs)
        {
            if (_obj.gameObject.activeSelf == false)
            {
                continue;
            }

            RecordLightData _recordLightdata = new RecordLightData();
            LOD[]           _lods            = _obj.GetLODs();
            for (int i = 0; i < _obj.lodCount; i++)
            {
                LOD        _lod;
                Renderer[] _renderers;
                if (i == 0)
                {
                    _lod       = _lods[0];
                    _renderers = _lod.renderers;
                    foreach (Renderer _render in _renderers)
                    {
                        LightData _lightData = new LightData();
                        _lightData._obj = _render.gameObject;
                        //_lightData._index = _render.lightmapIndex;
                        //_lightData._offset = _render.lightmapScaleOffset;
                        _recordLightdata._lightDataWrapper._lightDatas.Add(_lightData);
                    }
                }

                _lod       = _lods[i];
                _renderers = _lod.renderers;
                LightDataWrapper _lightDataWrapper = new LightDataWrapper();

                foreach (Renderer _render in _renderers)
                {
                    LightData _lightData = new LightData();
                    _lightData._obj    = _render.gameObject;
                    _lightData._index  = _render.lightmapIndex;
                    _lightData._offset = _render.lightmapScaleOffset;
                    _lightDataWrapper._lightDatas.Add(_lightData);
                }
                if (i == 0)
                {
                    _lightDataWrapper.isLOD0 = true;
                }
                _recordLightdata._childrens.Add(_lightDataWrapper);
            }
            _lodGameObjectDataList.Add(_recordLightdata);
        }
    }
Пример #3
0
    private static void CorrectLightmapData()
    {
        string     _tmpPath = _lightingDataAssetPath.Substring(6);
        FileStream _fs      = new FileStream(Application.dataPath + _tmpPath, FileMode.Open);

        byte[] _bytes = new byte[_fs.Length];
        _fs.Read(_bytes, 0, (int)_fs.Length);
        foreach (RecordLightData _recordLightData in _lodGameObjectDataList)
        {
            LightDataWrapper _lightDataWrapper = _recordLightData._lightDataWrapper;
            for (int i = 0; i < _lightDataWrapper._lightDatas.Count; i++)
            {
                LightData _lightData      = _lightDataWrapper._lightDatas[i];
                int       _tIdx           = _lightData._index;
                float     _tx             = _lightData._offset.x;
                float     _ty             = _lightData._offset.y;
                float     _toffsetx       = _lightData._offset.z;
                float     _toffsety       = _lightData._offset.w;
                byte[]    _txValues       = BitConverter.GetBytes(_tx);
                byte[]    _tyValues       = BitConverter.GetBytes(_ty);
                byte[]    _toffsetxValues = BitConverter.GetBytes(_toffsetx);
                byte[]    _toffsetyValues = BitConverter.GetBytes(_toffsety);
                //index
                byte[] _tIdxValues = BitConverter.GetBytes(_tIdx);
                _tIdxValues[2] = 255;
                _tIdxValues[3] = 255;
                byte[] _ttotalBuffer = new byte[20];
                Buffer.BlockCopy(_tIdxValues, 0, _ttotalBuffer, 0, 4);
                Buffer.BlockCopy(_txValues, 0, _ttotalBuffer, 4, 4);
                Buffer.BlockCopy(_tyValues, 0, _ttotalBuffer, 8, 4);
                Buffer.BlockCopy(_toffsetxValues, 0, _ttotalBuffer, 12, 4);
                Buffer.BlockCopy(_toffsetyValues, 0, _ttotalBuffer, 16, 4);
                foreach (LightDataWrapper _lightDataWrapperChild in _recordLightData._childrens)
                {
                    if (i > _lightDataWrapperChild._lightDatas.Count)
                    {
                        continue;
                    }
                    LightData _lightDataChild = _lightDataWrapperChild._lightDatas[i];
                    Renderer  _render         = _lightDataChild._obj.GetComponent <Renderer>();

                    _render.lightmapIndex       = _lightData._index;
                    _render.lightmapScaleOffset = _lightData._offset;

                    int   _rIdx     = _lightDataChild._index;
                    float _rx       = _lightDataChild._offset.x;
                    float _ry       = _lightDataChild._offset.y;
                    float _roffsetx = _lightDataChild._offset.z;
                    float _roffsety = _lightDataChild._offset.w;

                    byte[] _rxValues       = BitConverter.GetBytes(_rx);
                    byte[] _ryValues       = BitConverter.GetBytes(_ry);
                    byte[] _roffsetxValues = BitConverter.GetBytes(_roffsetx);
                    byte[] _roffsetyValues = BitConverter.GetBytes(_roffsety);
                    //index
                    byte[] _rIdxValues = BitConverter.GetBytes(_rIdx);
                    _rIdxValues[2] = 255;
                    _rIdxValues[3] = 255;

                    byte[] _rtotalBuffer = new byte[20];
                    Buffer.BlockCopy(_rIdxValues, 0, _rtotalBuffer, 0, 4);
                    Buffer.BlockCopy(_rxValues, 0, _rtotalBuffer, 4, 4);
                    Buffer.BlockCopy(_ryValues, 0, _rtotalBuffer, 8, 4);
                    Buffer.BlockCopy(_roffsetxValues, 0, _rtotalBuffer, 12, 4);
                    Buffer.BlockCopy(_roffsetyValues, 0, _rtotalBuffer, 16, 4);
                    int _v = FindBuffer(_bytes, _rtotalBuffer);
                    if (_v != -1)
                    {
                        _fs.Seek(_v, SeekOrigin.Begin);
                        _fs.Write(_ttotalBuffer, 0, 20);
                    }
                }
            }
        }

        _fs.Flush();
        _fs.Close();
    }