Example #1
0
        private void RefreshSurfaceCubeObj(BlockType type, byte extendId, bool isFirst)
        {
            if (_surfaceCube == null)
            {
                GameObject cubePrefab = ResourceManager.Instance.LoadAsset <GameObject>(SURFACECUBEPATH) as GameObject;
                _surfaceCube = GameObject.Instantiate <GameObject>(cubePrefab);
                _surfaceCube.transform.parent = mountPoint;
                if (isFirst)
                {
                    _surfaceCube.transform.localPosition = cubePrefab.transform.localPosition;
                    _surfaceCube.transform.localRotation = cubePrefab.transform.localRotation;
                    _surfaceCube.transform.localScale    = cubePrefab.transform.localScale;
                }
                else
                {
                    _surfaceCube.transform.localPosition = Vector3.zero;
                    _surfaceCube.transform.localRotation = Quaternion.identity;
                    _surfaceCube.transform.localScale    = cubePrefab.transform.localScale;
                }
            }
            _surfaceCube.SetActive(false);

            if (!WorldTextureProvider.IsCanUseProvider)
            {
                WorldTextureProvider.Instance.Pack();
            }
            WorldTextureType worldTextureType = WorldTextureProvider.Instance.GetTextureType(type, extendId);
            Texture2D        tex = WorldTextureProvider.Instance.GetAtlasTexture(worldTextureType);

            _surfaceCube.GetComponent <MeshRenderer>().material.mainTexture = tex;
        }
        public float GetTileHeight(WorldTextureType type)
        {
            PackTexture packTexture;

            if (_packTextureMap.TryGetValue(type, out packTexture))
            {
                return(packTexture.GetTileHeight());
            }
            throw new Exception("不存在类型为" + type + "的纹理图集!");
        }
        public Texture2D GetAtlasTexture(WorldTextureType type)
        {
            PackTexture packTexture;

            if (_packTextureMap.TryGetValue(type, out packTexture))
            {
                return(packTexture.Texture);
            }
            throw new Exception("不存在类型为" + type + "的纹理图集!");
        }
Example #4
0
        public PackTexture(WorldTextureType textureType, int width = 1024, int height = 1024, TextureFormat format = TextureFormat.DXT5, bool useOptimize = false)
        {
//            this.name = name;
            this.textureType = textureType;
            this.useOptimize = useOptimize;
            subTextureList   = new List <Texture2D>();
//            subTextureIdxMap = new Dictionary<string, int>();
            keyList          = new List <int>();
            atlas            = new Texture2D(width, height, format, true);
            atlas.anisoLevel = 16;
            atlas.wrapMode   = TextureWrapMode.Clamp;
            maxAtlasSize     = width > height ? width : height;
        }
Example #5
0
        private void CreateExplodeParticle(WorldPos pos, Block block, Vector3 normal)
        {
            ParticleSystem explode = particleQueue.Dequeue();

            Renderer  render = explode.GetComponent <Renderer>();
            Direction dir    = Direction.left;
            //更新光照
            int      direction = CheckNormal(normal);
            WorldPos lightPos  = pos;

            if (direction != 0)
            {
                dir      = (Direction)direction;
                lightPos = new WorldPos(pos.x + Mathf.RoundToInt(normal.x), pos.y + Mathf.RoundToInt(normal.y),
                                        pos.z + Mathf.RoundToInt(normal.z));
            }

            int   sunLightLevel   = World.world.GetSunLight(lightPos.x, lightPos.y, lightPos.z);
            int   blockLightLevel = World.world.GetBlockLight(lightPos.x, lightPos.y, lightPos.z);
            float lightIntensity  = MTBSkyBox.Instance.GetLightIntensity(sunLightLevel, blockLightLevel);

            render.material.SetFloat("_lightIntensity", lightIntensity);
            //更新贴图
            ResetExplode(explode);
            BlockAttributeCalculator calculator = BlockAttributeCalculatorFactory.GetCalculator(block.BlockType);
            byte             resExtendId        = calculator.GetResourceExtendId(block.ExtendId);
            WorldTextureType type = WorldTextureProvider.Instance.GetTextureType(block.BlockType, resExtendId);

            render.material.mainTexture = WorldTextureProvider.Instance.GetAtlasTexture(type);
            Rect rect = WorldTextureProvider.Instance.GetBlockTextureRect(block.BlockType, resExtendId, dir);

            if (rect != null)
            {
                render.material.SetFloat("_OffsetX", rect.x);
                render.material.SetFloat("_OffsetY", rect.y);
                render.material.SetFloat("_Width", rect.width);
                render.material.SetFloat("_Random", UnityEngine.Random.Range(0, 1f));
                explode.transform.position = new Vector3(pos.x + 0.5f, pos.y + 0.1f, pos.z + 0.5f);
            }
            explode.Play();
            particleQueue.Enqueue(explode);
        }
        private void PackTexture(PackTexture packTexture, string path, WorldTextureType type)
        {
            var gameObjects  = Resources.LoadAll <Texture2D>(path);
            int picExtendKey = 0;

            foreach (var item in gameObjects)
            {
                string[] result = item.name.Split('_');
                if (result.Length <= 3)
                {
                    continue;
                }
                string[] idResult = result[2].Split('-');
                int      id       = (Convert.ToInt32(idResult[0]) << 4);
                if (idResult.Length == 2)
                {
                    id += (Convert.ToInt32(idResult[1]) & 15);
                }

                int packTextureKey = GetPackTextureKey(id, picExtendKey);
                packTexture.AddTexture(item, packTextureKey);
                if (!_idToTextureTypeMap.ContainsKey(id))
                {
                    _idToTextureTypeMap.Add(id, type);
                }
                for (int i = 3; i < result.Length; i++)
                {
                    switch (result[i])
                    {
                    case "up":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.up, packTextureKey, packTexture);
                        break;

                    case "down":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.down, packTextureKey, packTexture);
                        break;

                    case "left":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.left, packTextureKey, packTexture);
                        break;

                    case "right":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.right, packTextureKey, packTexture);
                        break;

                    case "front":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.front, packTextureKey, packTexture);
                        break;

                    case "back":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.back, packTextureKey, packTexture);
                        break;

                    case "all":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.up, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.down, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.left, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.right, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.front, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.back, packTextureKey, packTexture);
                        break;

                    case "side":
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.left, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.right, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.front, packTextureKey, packTexture);
                        SaveTexture(_idKeyList, _picKeyList, _listPackTexture, id, Direction.back, packTextureKey, packTexture);
                        break;
                    }
                }
                picExtendKey++;
            }
            packTexture.Pack();
//			packTexture.Texture.Compress(true);
            _packTextureMap.Add(type, packTexture);
        }