Exemplo n.º 1
0
        static UnityEngine.Object[] FindAllAtlas(UnityEngine.Object[] select = null)
        {
            atlasInfoDic.Clear();
            DirectoryInfo dir = new DirectoryInfo("Assets/ArtRes/Language/");

            FileInfo[] files = dir.GetFiles("*.prefab", SearchOption.AllDirectories);
            List <UnityEngine.Object> atlas = new List <UnityEngine.Object>();

            for (int j = 0, maxj = files.Length; j < maxj; ++j)
            {
                string basePath = "Assets" + files[j].FullName.Substring(Application.dataPath.Length);
                basePath = basePath.Replace('\\', '/');
                UnityEngine.Object o = AssetDatabase.LoadMainAssetAtPath(basePath);
                if (o != null && PrefabUtility.GetPrefabType(o) == PrefabType.Prefab)
                {
                    UnityEngine.Object t = (o as GameObject).GetComponent(typeof(UIAtlas));
                    if (t != null && !atlas.Contains(t))
                    {
                        atlas.Add(t);
                        AtlasInfo ai = new AtlasInfo();
                        ai.select           = false;
                        ai.trimAlpha        = true;
                        ai.unityPacking     = true;
                        ai.forceSquareAtlas = false;
                        atlasInfoDic.Add(t, ai);
                    }
                }
            }
            return(atlas.ToArray());
        }
 public void SetAsStyle(Material topMaterial, Material sideMaterial, AtlasInfo uvAtlas)
 {
     _materialOptions.customStyleOptions.texturingType             = UvMapType.Atlas;
     _materialOptions.customStyleOptions.materials[0].Materials[0] = topMaterial;
     _materialOptions.customStyleOptions.materials[1].Materials[0] = sideMaterial;
     _materialOptions.customStyleOptions.atlasInfo = uvAtlas;
     _materialOptions.HasChanged = true;
 }
Exemplo n.º 3
0
 static void LoadConfig()
 {
     config = AssetDatabase.LoadAssetAtPath <AtlasInfo>(PathConfig.atlasConfig);
     if (config == null)
     {
         config = new AtlasInfo(PathConfig.spritePath, PathConfig.atlasTargetPath);
         AssetDatabase.CreateAsset(config, PathConfig.atlasConfig);
     }
 }
Exemplo n.º 4
0
 public void SetAsStyle(Material topMaterial, Material sideMaterial, AtlasInfo uvAtlas, ScriptablePalette palette)
 {
     _materialOptions.texturingType             = UvMapType.Atlas;
     _materialOptions.materials[0].Materials[0] = topMaterial;
     _materialOptions.materials[1].Materials[0] = sideMaterial;
     _materialOptions.atlasInfo    = uvAtlas;
     _materialOptions.colorPalette = palette;
     _materialOptions.HasChanged   = true;
 }
Exemplo n.º 5
0
    private void GenAllAtlas()
    {
        for (int i = 0; i < _atlasInfoList.Count; ++i)
        {
            AtlasInfo _atlasInfo = _atlasInfoList[i];
            GenAtlas(_atlasInfo.sName, _atlasInfo.imps);
        }

        AssetDatabase.Refresh();
    }
        public GeometryExtrusionWithAtlasOptions(GeometryExtrusionOptions extrusionOptions, UVModifierOptions uvOptions)
        {
            extrusionType         = extrusionOptions.extrusionType;
            extrusionGeometryType = extrusionOptions.extrusionGeometryType;
            propertyName          = extrusionOptions.propertyName;
            minimumHeight         = extrusionOptions.minimumHeight;
            maximumHeight         = extrusionOptions.maximumHeight;

            texturingType = uvOptions.texturingType;
            atlasInfo     = uvOptions.atlasInfo;
        }
Exemplo n.º 7
0
    private void ClearAtlas()
    {
        //Clear Atlas prefab
        string[] names = Directory.GetFiles(_uiAtlasOutFullPath, "*.prefab", SearchOption.AllDirectories);
        string   name  = null;

        for (int i = 0; i < names.Length; ++i)
        {
            bool isUseful = false;
            name = Path.GetFileNameWithoutExtension(names[i]);

            EditorUtility.DisplayProgressBar("清理Atlas", name, (float)i * 0.5f / (float)names.Length);

            for (int j = 0; j < _atlasInfoList.Count; ++j)
            {
                AtlasInfo _atlasInfo = _atlasInfoList[j];
                if (_atlasInfo.sName.Equals(name))
                {
                    isUseful = true;
                    break;
                }
            }

            if (!isUseful)
            {
                File.Delete(names[i]);
            }
        }
        //Clear Atlas texture
        names = Directory.GetFiles(_uiTextureOutFullPath, "*.png", SearchOption.AllDirectories);
        for (int i = 0; i < names.Length; ++i)
        {
            bool isUseful = false;
            name = Path.GetFileNameWithoutExtension(names[i]);
            EditorUtility.DisplayProgressBar("清理Atlas", name, (float)i * 0.5f / (float)names.Length + 0.5f);
            for (int j = 0; j < _atlasInfoList.Count; ++j)
            {
                AtlasInfo _atlasInfo = _atlasInfoList[j];
                if (_atlasInfo.sName.Equals(name))
                {
                    isUseful = true;
                    break;
                }
            }

            if (!isUseful)
            {
                File.Delete(names[i]);
            }
        }
        AssetDatabase.Refresh();
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 8
0
    public Sprite GetSprite(string sprName)
    {
        string atlasName = m_AtlasMap.GetAtlasNameBySpriteName(sprName);

        if (string.IsNullOrEmpty(atlasName))
        {
            return(null);
        }
        AtlasInfo atlasInfo = GetAtlasInfo(atlasName);

        return(atlasInfo.GetSprite(sprName));
    }
Exemplo n.º 9
0
        private static void _extract(string type)
        {
            Console.WriteLine("Start to extract {0}", type);
            AtlasInfo info  = _components[type];
            Atlas     atlas = Atlas.FromAtlas(info.Path, info.Format);

            foreach (VirtualTexture texture in atlas.Sources)
            {
                Console.WriteLine("Writing {0} to specified output directory...", Path.GetFileName(texture.Path));
                texture.SaveAsPng(Path.Combine(_output_dir, texture.Path) + ".png");
            }
        }
Exemplo n.º 10
0
    private void MakeAtlas(PlatformType pt)
    {
        Texture2D[] texs = new Texture2D[_tex.Count];
        int         area = 0;

        for (int i = 0; i < _tex.Count; i++)
        {
            texs[i] = _tex[i];
            area   += (texs[i].width * texs[i].height);
        }
        int       imageSize = Mathf.ClosestPowerOfTwo((int)Mathf.Sqrt((int)(area * 1.15f)));
        Texture2D imgAtlas  = new Texture2D(0, 0);
        AtlasInfo info      = new AtlasInfo();

        if (pt == PlatformType.ios)
        {
            imgAtlas = new Texture2D(imageSize, imageSize, TextureFormat.PVRTC_RGBA4, false);
            info     = new AtlasInfo(imgAtlas.PackTextures(texs, 2, imageSize));
        }
        else if (pt == PlatformType.android)
        {
            imgAtlas = new Texture2D(imageSize, imageSize, TextureFormat.ASTC_RGBA_8x8, false);
            info     = new AtlasInfo(imgAtlas.PackTextures(texs, 2, imageSize));
        }
        else if (pt == PlatformType.pc)
        {
            imgAtlas = new Texture2D(imageSize, imageSize, TextureFormat.DXT5, false);
            info     = new AtlasInfo(imgAtlas.PackTextures(texs, 2, imageSize));
        }

        byte[] bytes = imgAtlas.EncodeToPNG();

        if (!Directory.Exists(ProcessInfo.Path + "/" + pt.ToString()))
        {
            Directory.CreateDirectory(ProcessInfo.Path + "/" + pt.ToString());
        }

        if (File.Exists(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png"))
        {
            File.Delete(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png");
        }
        File.WriteAllBytes(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png", bytes);

        string infoJSON = JsonConvert.SerializeObject(info);



        /*StreamWriter sw = new StreamWriter (ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".txt");
         * sw.Write (infoJSON);
         * sw.Close ();
         */
    }
Exemplo n.º 11
0
    //读取图集配置 key = spName   value = abName
    private void readAtlasInfo()
    {
        string      path = Path.Combine(Define.abPre, infoPath);
        AssetBundle ab   = AssetBundle.LoadFromFile(path);

        string[]  names = ab.GetAllAssetNames();
        AtlasInfo info  = ab.LoadAsset(names[0]) as AtlasInfo;

        for (int i = 0; i < info.keys.Count; i++)
        {
            atlasMap.Add(info.keys[i], info.abs[i]);
        }
    }
Exemplo n.º 12
0
 private void DrawAtlasInfo(AtlasInfo atlasInfo)
 {
     GUILayout.BeginVertical();
     {
         GUILayout.BeginHorizontal();
         {
             GUILayout.Space(16.0f);
             GUILayout.Label(atlasInfo.atlasName + " (" + atlasInfo.RefAtlasReferenceTo() + ")");
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndVertical();
 }
Exemplo n.º 13
0
        private void AssignAssets(StyleAssetPathBundle styleAssetPathBundle)
        {
            Material topMaterial  = Resources.Load(styleAssetPathBundle.topMaterialPath, typeof(Material)) as Material;
            Material sideMaterial = Resources.Load(styleAssetPathBundle.sideMaterialPath, typeof(Material)) as Material;

            AtlasInfo         atlas   = Resources.Load(styleAssetPathBundle.atlasPath, typeof(AtlasInfo)) as AtlasInfo;
            ScriptablePalette palette = Resources.Load(styleAssetPathBundle.palettePath, typeof(ScriptablePalette)) as ScriptablePalette;

            materials[0].Materials[0] = new Material(topMaterial);
            materials[1].Materials[0] = new Material(sideMaterial);
            atlasInfo    = atlas;
            colorPalette = palette;
        }
Exemplo n.º 14
0
    private void ParseAtlas2()
    {
        CalBeReferences();

        for (int i = 0; i < _atlasInfoList.Count; ++i)
        {
            AtlasInfo aInfo = _atlasInfoList[i];
            for (int j = 0; j < aInfo.spriteInfos.Count; ++j)
            {
                SpriteInfo sInfo = aInfo.spriteInfos[j];
                sInfo.refCount = GetRefCount(sInfo.sPath);
            }
        }
    }
        public static GeometryMaterialOptions AssignAssets(GeometryMaterialOptions geometryMaterialOptions, StyleAssetPathBundle styleAssetPathBundle)
        {
            Material topMaterial  = Resources.Load(styleAssetPathBundle.topMaterialPath, typeof(Material)) as Material;
            Material sideMaterial = Resources.Load(styleAssetPathBundle.sideMaterialPath, typeof(Material)) as Material;

            AtlasInfo         atlas   = Resources.Load(styleAssetPathBundle.atlasPath, typeof(AtlasInfo)) as AtlasInfo;
            ScriptablePalette palette = Resources.Load(styleAssetPathBundle.palettePath, typeof(ScriptablePalette)) as ScriptablePalette;

            geometryMaterialOptions.materials[0].Materials[0] = new Material(topMaterial);
            geometryMaterialOptions.materials[1].Materials[0] = new Material(sideMaterial);
            geometryMaterialOptions.atlasInfo    = atlas;
            geometryMaterialOptions.colorPalette = palette;

            return(geometryMaterialOptions);
        }
Exemplo n.º 16
0
    public Vector4 GetPadding(string spriteName)
    {
        Vector4 padding = Vector4.zero;

        if (m_PaddingDic.TryGetValue(spriteName, out padding))
        {
            return(padding);
        }
        string    atlasName = m_AtlasMap.GetAtlasNameBySpriteName(spriteName);
        AtlasInfo atlasInfo = GetAtlasInfo(atlasName);

        padding = atlasInfo.GetPadding(spriteName);
        m_PaddingDic.Add(spriteName, padding);
        return(padding);
    }
Exemplo n.º 17
0
    public bool GetIsPolyAtlas(string spriteName)
    {
        bool isPoly;

        if (m_IsPolyDic.TryGetValue(spriteName, out isPoly))
        {
            return(isPoly);
        }
        string    atlasName = m_AtlasMap.GetAtlasNameBySpriteName(spriteName);
        AtlasInfo atlasInfo = GetAtlasInfo(atlasName);

        isPoly = atlasInfo.m_IsPoly;
        m_IsPolyDic.Add(spriteName, isPoly);
        return(isPoly);
    }
Exemplo n.º 18
0
    public void GetSpriteAndMat(string sprName, out Sprite spr, out Material mat)
    {
        string atlasName = m_AtlasMap.GetAtlasNameBySpriteName(sprName);

        if (string.IsNullOrEmpty(atlasName))
        {
            mat = null;
            spr = null;
            return;
        }
        AtlasInfo atlasInfo = GetAtlasInfo(atlasName);

        mat = atlasInfo.m_Mat;
        spr = atlasInfo.GetSprite(sprName);
    }
Exemplo n.º 19
0
        // height in meters
        public static void AssignBuildings(Building type, float min, float max, AbstractMap map, bool combineMesh = false)
        {
            if (type == Building.Road)
            {
                return;
            }

            VectorSubLayerProperties vectorSubLayerProperties = new VectorSubLayerProperties();

            vectorSubLayerProperties.colliderOptions.colliderType           = ColliderType.MeshCollider;
            vectorSubLayerProperties.coreOptions.combineMeshes              = false;
            vectorSubLayerProperties.coreOptions.geometryType               = VectorPrimitiveType.Polygon;
            vectorSubLayerProperties.coreOptions.layerName                  = "building";
            vectorSubLayerProperties.coreOptions.snapToTerrain              = true;
            vectorSubLayerProperties.coreOptions.combineMeshes              = combineMesh;
            vectorSubLayerProperties.extrusionOptions.extrusionType         = ExtrusionType.PropertyHeight;
            vectorSubLayerProperties.extrusionOptions.extrusionScaleFactor  = 1.3203f;
            vectorSubLayerProperties.extrusionOptions.propertyName          = "height";
            vectorSubLayerProperties.extrusionOptions.extrusionGeometryType = ExtrusionGeometryType.RoofAndSide;
            vectorSubLayerProperties.moveFeaturePositionTo                  = PositionTargetType.CenterOfVertices;
            vectorSubLayerProperties.coreOptions.sublayerName               = type.ToString();

            string    atlasPath = "Atlases/" + type.ToString() + "BuildingAtlas";
            AtlasInfo atlasInfo = Resources.Load(atlasPath) as AtlasInfo;
            Material  material  = Resources.Load(Constants.buildingMaterialPath) as Material;
            GeometryMaterialOptions materialOptions = new GeometryMaterialOptions();

            materialOptions.SetDefaultMaterialOptions();
            materialOptions.customStyleOptions.texturingType             = UvMapType.Atlas;
            materialOptions.customStyleOptions.materials[0].Materials[0] = material;
            materialOptions.customStyleOptions.materials[1].Materials[0] = material;
            materialOptions.customStyleOptions.atlasInfo = atlasInfo;
            materialOptions.SetStyleType(StyleTypes.Custom);
            vectorSubLayerProperties.materialOptions        = materialOptions;
            vectorSubLayerProperties.buildingsWithUniqueIds = true;
            if (min < 100)
            {
                vectorSubLayerProperties.filterOptions.AddNumericFilterInRange("height", min, max);
                vectorSubLayerProperties.filterOptions.AddNumericFilterEquals("height", max);
            }
            else
            {
                vectorSubLayerProperties.filterOptions.AddNumericFilterGreaterThan("height", min);
            }

            map.VectorData.AddFeatureSubLayer(vectorSubLayerProperties);
        }
Exemplo n.º 20
0
    public AtlasInfo AddIconTextureToAtlas(Texture2D tex)
    {
        if (iconAtlasList.Count == 0)
        {
            iconAtlasList.Add(new AtlasTexture(1, 88));
        }
        else if (iconAtlasList.Single(a => a.atlasId == iconAtlasList.Count).textureCount >= 200)
        {
            iconAtlasList.Add(new AtlasTexture(iconAtlasList.Count + 1, 88));
        }
        AtlasTexture tmp  = iconAtlasList.Single(a => a.atlasId == iconAtlasList.Count);
        AtlasInfo    info = new AtlasInfo();

        info.atlasId       = iconAtlasList.Count;
        info.textureId     = tmp.textureCount;
        info.uvRect        = tmp.AddTexture(tex);
        info.packedTexture = tmp.packedTexture;
        return(info);
    }
Exemplo n.º 21
0
    private void ParseAtlas()
    {
        _atlasInfoDic.Clear();
        _atlasInfoList.Clear();

        List <string> tmp = new List <string>();

        string[] files = Directory.GetFiles(_uiAssetsFullPath, "*.png", SearchOption.AllDirectories);

        for (int i = 0; i < files.Length; ++i)
        {
            EditorUtility.DisplayProgressBar("图集统计", files[i], (float)i / (float)files.Length);

            string path = files[i].Remove(0, Directory.GetCurrentDirectory().Length + 1);

            TextureImporter imp = AssetImporter.GetAtPath(path) as TextureImporter;

            string atlasName = ParseAtlasName(imp.spritePackingTag);

            AtlasInfo _atlasInfo = null;

            if (!_atlasInfoDic.TryGetValue(atlasName, out _atlasInfo))
            {
                _atlasInfo               = new AtlasInfo();
                _atlasInfo.isSel         = false;
                _atlasInfo.isShowDetails = false;
                _atlasInfoDic[atlasName] = _atlasInfo;
                _atlasInfoList.Add(_atlasInfo);
                _atlasInfo.sName = atlasName;
            }
            SpriteInfo spriteInfo = new SpriteInfo();
            _atlasInfo.spriteInfos.Add(spriteInfo);
            _atlasInfo.imps.Add(imp);
            spriteInfo.sPath = path;
            spriteInfo.sName = Path.GetFileName(spriteInfo.sPath);
        }

        _hasAtlasData = true;
        EditorUtility.ClearProgressBar();
    }
Exemplo n.º 22
0
        private void RefreshAtlasNameList()
        {
            m_AtlasNames = Packer.atlasNames;
            m_AtlasInfos.Clear();

            for (var i = 0; i < m_AtlasNames.Length; i++)
            {
                var atlasName             = m_AtlasNames[i];
                List <AtlasInfo> infos    = new List <AtlasInfo>();
                Texture2D[]      textures = Packer.GetTexturesForAtlas(atlasName);
                foreach (var texture in textures)
                {
                    AtlasInfo info = new AtlasInfo
                    {
                        texture = texture,
                        format  = texture.format.ToString(),
                        size    = string.Format("{0}x{1}", texture.width, texture.height)
                    };
                    infos.Add(info);
                }
                m_AtlasInfos.Add(infos);
            }
        }
Exemplo n.º 23
0
        private void AssignAssets(StyleAssetPathBundle styleAssetPathBundle)
        {
            Material topMaterial  = Resources.Load(styleAssetPathBundle.topMaterialPath, typeof(Material)) as Material;
            Material sideMaterial = Resources.Load(styleAssetPathBundle.sideMaterialPath, typeof(Material)) as Material;

            AtlasInfo         atlas   = Resources.Load(styleAssetPathBundle.atlasPath, typeof(AtlasInfo)) as AtlasInfo;
            ScriptablePalette palette = Resources.Load(styleAssetPathBundle.palettePath, typeof(ScriptablePalette)) as ScriptablePalette;

            Material[] tempMaterials = new Material[2];


            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i].Materials[0] != null)
                {
                    tempMaterials[i]          = materials[i].Materials[0];
                    materials[i].Materials[0] = null;
                }
            }

            materials[0].Materials[0] = new Material(topMaterial);
            materials[1].Materials[0] = new Material(sideMaterial);

            for (int i = 0; i < materials.Length; i++)
            {
                if (tempMaterials[i] != null)
                {
                    tempMaterials[i].Destroy();
                }
            }

            Resources.UnloadUnusedAssets();

            atlasInfo    = atlas;
            colorPalette = palette;
        }
Exemplo n.º 24
0
    private static void SetupDeviceToAtlasInfo()
    {
        _deviceToAtlasInfo = new Dictionary <RSAtlasHelper.Device, List <AtlasInfo> >();

        RSAtlasHelper.Device[] devices = { RSAtlasHelper.Device.Tablet, RSAtlasHelper.Device.Phone };

        for (int i = 0; i < devices.Length; ++i)
        {
            var device  = devices[i];
            var dirInfo = new DirectoryInfo(string.Format("Assets/Resources/Atlases/{0}/", device));
            if (dirInfo == null || !dirInfo.Exists)
            {
                continue;
            }
            var fis        = dirInfo.GetFiles("*.prefab");
            var atlasNames = new List <string>();
            foreach (var fi in fis)
            {
                atlasNames.Add(fi.Name.Split('@')[0]);
            }

            _deviceToAtlasInfo[device] = new List <AtlasInfo>();
            foreach (var atlasName in atlasNames)
            {
                var atlasInfo = new AtlasInfo();
                atlasInfo.atlasName = atlasName;
                if (device == RSAtlasHelper.Device.Tablet)
                {
                    atlasInfo.hdAtlas = RSAtlasHelper.GetAtlas(atlasName, device, RSAtlasHelper.AtlasType.HD);
                }
                atlasInfo.refAtlas = RSAtlasHelper.GetAtlas(atlasName, device, RSAtlasHelper.AtlasType.Ref);
                atlasInfo.sdAtlas  = RSAtlasHelper.GetAtlas(atlasName, device, RSAtlasHelper.AtlasType.SD);
                _deviceToAtlasInfo[device].Add(atlasInfo);
            }
        }
    }
Exemplo n.º 25
0
    private void ShowAtlasList()
    {
        if (!_hasAtlasData)
        {
            ParseAtlas();
        }

        AtlasInfo _atlasInfo = null;

        if (_atlasInfoList != null && _atlasInfoList.Count > 0)
        {
            _scrAtlas = EditorGUILayout.BeginScrollView(_scrAtlas);


            for (int i = 0; i < _atlasInfoList.Count; ++i)
            {
                EditorGUILayout.BeginHorizontal(GUI.skin.box);
                _atlasInfo               = _atlasInfoList[i];
                _atlasInfo.isSel         = GUILayout.Toggle(_atlasInfo.isSel, _atlasInfo.sName, GUILayout.Width(400));
                _atlasInfo.isShowDetails = EditorGUILayout.Foldout(_atlasInfo.isShowDetails, "显示详情");
                EditorGUILayout.EndHorizontal();
                if (_atlasInfo.isShowDetails)
                {
                    for (int j = 0; j < _atlasInfo.spriteInfos.Count; ++j)
                    {
                        ShowSpriteInfo(_atlasInfo.spriteInfos[j]);
                    }
                }
            }

            EditorGUILayout.EndScrollView();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("全选"))
            {
                bool isAllTrue = true;
                for (int i = 0; i < _atlasInfoList.Count; ++i)
                {
                    if (_atlasInfoList[i].isSel == false)
                    {
                        isAllTrue = false;
                        break;
                    }
                }

                for (int i = 0; i < _atlasInfoList.Count; ++i)
                {
                    _atlasInfoList[i].isSel = !isAllTrue;
                }
            }

            if (GUILayout.Button("生成图集"))
            {
                for (int i = 0; i < _atlasInfoList.Count; ++i)
                {
                    _atlasInfo = _atlasInfoList[i];
                    if (_atlasInfo.isSel)
                    {
                        GenAtlas(_atlasInfo.sName, _atlasInfo.imps);
                    }
                }
                EditorUtility.DisplayDialog("UIEditor", "图集生成完成", "ok");
            }

            if (GUILayout.Button("清理多余Atlas"))
            {
                ClearAtlas();
                EditorUtility.DisplayDialog("UIEditor", "图集清理完成", "ok");
            }

            if (GUILayout.Button("图集分析"))
            {
                ParseAtlas2();
                EditorUtility.DisplayDialog("UIEditor", "图集分析完成", "ok");
            }

            EditorGUILayout.EndHorizontal();
        }

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("统计图集"))
        {
            ParseAtlas();
            EditorUtility.DisplayDialog("UIEditor", "图集统计完成", "ok");
        }

        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 26
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        for (int i = 0; i < importedAssets.Length; i++)
        {
            string assetPath = importedAssets[i].Replace("\\", "/");
            if (!assetPath.StartsWith("Assets/Localization/") && !assetPath.StartsWith("Assets/Res/"))
            {
                continue;
            }
            if (!AssetDatabase.IsValidFolder(assetPath))
            {
                continue;                                          //非文件夹文件
            }
            DirectoryInfo dirAssetInfo = new DirectoryInfo(assetPath);
            for (int j = 0; j < _atlasRuleDir.Length; j++)
            {
                AtlasInfo atlasInfo_Rule = _atlasRuleDir[j];
                if (!assetPath.Equals(atlasInfo_Rule.dir) && !assetPath.StartsWith(atlasInfo_Rule.dir + "/"))
                {
                    continue;
                }
                //命中目标文件夹
                if (dirAssetInfo.Parent.FullName.Equals(atlasInfo_Rule.fullName))
                {
                    FileInfo[] atlasFiles  = dirAssetInfo.GetFiles("*.spriteatlas", SearchOption.AllDirectories);
                    FileInfo   targetAtlas = null; //文件夹下直属Atlas
                    for (int k = 0; k < atlasFiles.Length; k++)
                    {
                        FileInfo file = atlasFiles[k];
                        if (targetAtlas == null)
                        {
                            if (file.Directory.FullName.Equals(dirAssetInfo.FullName))
                            {
                                targetAtlas = file;
                            }
                        }
                        else
                        {
                            file.Delete(); //删除其他的Atlas
                        }
                    }

                    string targetName = atlasInfo_Rule.prefix_name + "_" + dirAssetInfo.Name + "_Atlas.spriteatlas";
                    if (targetAtlas == null) //没有找到直属Atlas
                    {
                        AssetDatabase.CreateAsset(new SpriteAtlas(), assetPath + "/" + targetName);
                        targetAtlas = new FileInfo(dirAssetInfo.FullName + "/" + targetName);
                    }
                    else
                    {
                        AssetDatabase.RenameAsset(assetPath + "/" + targetAtlas.Name, targetName); //改名
                        targetAtlas = new FileInfo(dirAssetInfo.FullName + "/" + targetName);
                    }
                    //对Atlas进行设置
                    SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath <SpriteAtlas>(assetPath + "/" + targetAtlas.Name);
                    SpriteAtlasPackingSettings packingSettings = atlas.GetPackingSettings();
                    packingSettings.enableRotation     = atlasInfo_Rule.isRotation;
                    packingSettings.enableTightPacking = atlasInfo_Rule.isTight;
                    packingSettings.padding            = 2;
                    atlas.SetPackingSettings(packingSettings);

                    TextureImporterPlatformSettings platformSettings = atlas.GetPlatformSettings("iPhone");
                    platformSettings.overridden = true;
                    if (platformSettings.maxTextureSize > 2048)
                    {
                        platformSettings.maxTextureSize = 2048;
                    }
                    platformSettings.format = TextureImporterFormat.ASTC_RGBA_6x6;
                    atlas.SetPlatformSettings(platformSettings);

                    atlas.Remove(atlas.GetPackables());
                    atlas.Add(new [] { AssetDatabase.LoadAssetAtPath <Object>(assetPath) });
                }
                break;
            }
        }
    }
Exemplo n.º 27
0
        void OnGUI()
        {
            GUILayout.Space(20);

            GUIStyle titleStyle = new GUIStyle(EditorStyles.label);

            titleStyle.fontSize         = 32;
            titleStyle.normal.textColor = Color.white;
            titleStyle.fontStyle        = FontStyle.Bold;

            titleStyle.stretchWidth  = true;
            titleStyle.stretchHeight = true;

            titleStyle.alignment = TextAnchor.MiddleCenter;

            GUILayout.BeginVertical();

            EditorGUILayout.LabelField("Mapbox Atlas Template Generator", titleStyle, GUILayout.Height(100));

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical(GUILayout.MinWidth(200), GUILayout.MaxWidth(300));

            EditorGUI.BeginChangeCheck();

            EditorGUI.indentLevel++;

            m_atlasInfo = EditorGUILayout.ObjectField("Atlas info:", m_atlasInfo, typeof(AtlasInfo), true) as Mapbox.Unity.MeshGeneration.Data.AtlasInfo;

            EditorGUILayout.Space();

            m_generateFacadesTemplate = EditorGUILayout.Toggle("Create Facades", m_generateFacadesTemplate);
            m_generateRoofsTemplate   = EditorGUILayout.Toggle("Create Roofs", m_generateRoofsTemplate);

            if (EditorGUI.EndChangeCheck())
            {
                if (m_atlasInfo != null)
                {
                    int facadeCount = m_generateFacadesTemplate ? m_atlasInfo.Textures.Count : 0;
                    int roofCount   = m_generateRoofsTemplate ? m_atlasInfo.Roofs.Count : 0;

                    int textureCount = facadeCount + roofCount;

                    m_colors = new Color[textureCount];

                    float hueIncrement = (float)1.0f / textureCount;
                    float hue          = 0.0f;

                    for (int i = 0; i < textureCount; i++)
                    {
                        m_colors[i] = Color.HSVToRGB(hue, 1.0f, 1.0f);
                        hue        += hueIncrement;
                    }
                }
                else
                {
                    m_colors = new Color[0];
                    CreateTexture();
                }
            }

            EditorGUI.BeginChangeCheck();

            m_textureResolution = Mathf.Clamp(EditorGUILayout.IntField("Texture resolution:", m_textureResolution), _MIN_TEX_SIZE, _MAX_TEX_SIZE);

            if (EditorGUI.EndChangeCheck())
            {
                CreateTexture();
            }

            EditorGUILayout.Space();

            if (m_colors != null)
            {
                for (int i = 0; i < m_colors.Length; i++)
                {
                    string colorFieldName = string.Format("Color {0}", i);
                    m_colors[i] = EditorGUILayout.ColorField(colorFieldName, m_colors[i]);
                }
            }

            if (GUILayout.Button("Generate Template"))
            {
                if (m_atlasInfo == null)
                {
                    EditorUtility.DisplayDialog("Atlas Template Generator", "Error: No AtlasInfo object selected.", "Ok");
                    return;
                }
                if (!m_generateFacadesTemplate && !m_generateRoofsTemplate)
                {
                    EditorUtility.DisplayDialog("Atlas Template Generator", "Error: Template generation requires Create Facades and/or Create Roofs to be enabled.", "Ok");
                    return;
                }
                GenerateTemplate();
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Save to file"))
            {
                SaveTextureAsPNG();
            }

            EditorGUI.indentLevel--;

            GUILayout.EndVertical();

            GUIStyle boxStyle = new GUIStyle();

            boxStyle.alignment = TextAnchor.UpperLeft;

            GUILayout.Box(m_texture, boxStyle, GUILayout.Width(300), GUILayout.Height(300), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.Space(20);
        }
Exemplo n.º 28
0
 public GeometryExtrusionWithAtlasOptions(UVModifierOptions uvOptions)
 {
     texturingType = uvOptions.texturingType;
     atlasInfo     = uvOptions.atlasInfo;
 }
Exemplo n.º 29
0
    private void MakeAtlas(PlatformType pt)
    {
        Texture2D[] texs = new Texture2D[_tex.Count];
        int area = 0;
        for(int i =0; i < _tex.Count; i++)
        {
            texs[i] = _tex[i];
            area += (texs[i].width * texs[i].height);
        }
        int imageSize = Mathf.ClosestPowerOfTwo((int)Mathf.Sqrt((int)(area * 1.15f)));
        Texture2D imgAtlas = new Texture2D (0, 0);
        AtlasInfo info = new AtlasInfo ();

        if(pt == PlatformType.ios)
        {
            imgAtlas = new Texture2D(imageSize,imageSize,TextureFormat.PVRTC_RGBA4,false);
            info = new AtlasInfo( imgAtlas.PackTextures(texs,2,imageSize));
        }
        else if(pt == PlatformType.android)
        {
            imgAtlas = new Texture2D(imageSize,imageSize, TextureFormat.ASTC_RGBA_8x8,false);
            info = new AtlasInfo( imgAtlas.PackTextures(texs,2,imageSize));
        }
        else if(pt == PlatformType.pc)
        {
            imgAtlas = new Texture2D(imageSize,imageSize, TextureFormat.DXT5,false);
            info = new AtlasInfo( imgAtlas.PackTextures(texs,2,imageSize));
        }

        byte[] bytes = imgAtlas.EncodeToPNG();

        if(!Directory.Exists(ProcessInfo.Path + "/" + pt.ToString()))
        {
            Directory.CreateDirectory (ProcessInfo.Path + "/" + pt.ToString());
        }

        if(File.Exists(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png"))
        {
            File.Delete(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png");
        }
        File.WriteAllBytes(ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".png", bytes);

        string infoJSON = JsonConvert.SerializeObject (info);

        /*StreamWriter sw = new StreamWriter (ProcessInfo.Path + "/" + pt.ToString() + "/" + ProcessInfo.FileName + ".txt");
        sw.Write (infoJSON);
        sw.Close ();
        */
    }