コード例 #1
0
        private void FillAutoTileAnimations(Texture2DRegion org, Texture2DRegion to, Size cell_size, int frame_count, EAutoTileType autotile_type)
        {
            // animation frames are horizontal layout
            var org_frame_cell_size = new Size((int)org.rect.width / frame_count, (int)org.rect.height);
            var to_frame_cell_size  = new Size((int)to.rect.width / frame_count, (int)to.rect.height);

            for (var i = 0; i < frame_count; ++i)
            {
                FillAutoTileTexture(
                    org.SubRegionFromIdx(i, org_frame_cell_size),
                    to.SubRegionFromIdx(i, to_frame_cell_size),
                    cell_size, autotile_type);
            }
        }
コード例 #2
0
        private void OnGUI()
        {
            m_OrgTexture      = EditorGUILayout.ObjectField(m_OrgTexture, typeof(Texture2D), false) as Texture2D;
            m_AnimationFrames = EditorGUILayout.IntField("Animation Frames", m_AnimationFrames);
            m_AnimationSpeed  = EditorGUILayout.FloatField("Animation Speed", m_AnimationSpeed);
            m_Type            = (EAutoTileType)EditorGUILayout.EnumPopup("AutoTile Type", m_Type);

            if (m_OrgTexture != null)
            {
                // precheck texture size is valid!
                if (!IsValid())
                {
                    EditorGUILayout.HelpBox("Texture size is not match!", MessageType.Error);
                    GUI.enabled = false;
                }

                if (GUILayout.Button("MakeAutoTile"))
                {
                    TextureImporter imp;
                    var             org_path = AssetDatabase.GetAssetPath(m_OrgTexture);

                    // make sure the texture is readable!
                    if (!m_OrgTexture.isReadable)
                    {
                        imp            = TextureImporter.GetAtPath(org_path) as TextureImporter;
                        imp.isReadable = true;
                        imp.SaveAndReimport();
                    }

                    Size cell_size;
                    if (m_Type == EAutoTileType.RPG_MAKER_XP)
                    {
                        cell_size = new Size(32);
                    }
                    else
                    {
                        cell_size = new Size(48);
                    }

                    var org_tex_region = new Texture2DRegion(m_OrgTexture);
                    var new_tex_region = new Texture2DRegion(cell_size.Scale(8 * m_AnimationFrames, 6));
                    FillAutoTileAnimations(org_tex_region, new_tex_region, cell_size, m_AnimationFrames, m_Type);

                    // save the reordered texture and reload it
                    var path = Path.Combine(Path.GetDirectoryName(org_path), Path.GetFileNameWithoutExtension(org_path) + "_Split.png");
                    path = AssetDatabase.GenerateUniqueAssetPath(path);
                    File.WriteAllBytes(path, new_tex_region.texture.EncodeToPNG());
                    AssetDatabase.ImportAsset(path);

                    // calc all sprite meta data
                    var sheet           = new SpriteMetaData[XP_AUTOTILE_MAP.Count * m_AnimationFrames];
                    var frame_cell_size = new Size((int)new_tex_region.rect.width / m_AnimationFrames, (int)new_tex_region.rect.height);

                    for (var i = 0; i < m_AnimationFrames; ++i)
                    {
                        var sub_rect = new_tex_region.rect.SubRectFromIdx(i, frame_cell_size);
                        for (var j = 0; j < XP_AUTOTILE_MAP.Count; ++j)
                        {
                            var meta = new SpriteMetaData
                            {
                                name      = string.Format("tile_{0}_{1}", i, j),
                                rect      = sub_rect.SubRectFromIdx(j, cell_size),
                                border    = Vector4.zero,
                                alignment = (int)SpriteAlignment.Center,
                                pivot     = new Vector2(0.5f, 0.5f)
                            };
                            sheet[i * XP_AUTOTILE_MAP.Count + j] = meta;
                        }
                    }

                    // reimport the texture to generate all sprites
                    imp                     = TextureImporter.GetAtPath(path) as TextureImporter;
                    imp.textureType         = TextureImporterType.Sprite;
                    imp.spritePixelsPerUnit = cell_size.width;
                    imp.spriteImportMode    = SpriteImportMode.Multiple;
                    imp.mipmapEnabled       = false;
                    imp.filterMode          = FilterMode.Point;
                    imp.spritesheet         = sheet;
                    imp.SaveAndReimport();

                    // get all the sprites
                    var objs = AssetDatabase.LoadAllAssetsAtPath(path);
                    var sprs = new List <Sprite>();
                    foreach (var obj in objs)
                    {
                        if (obj is Sprite)
                        {
                            sprs.Add(obj as Sprite);
                        }
                    }

                    // generate the auto tile asset
                    var auto_tile = ScriptableObject.CreateInstance <AutoTile>();

                    // use the last sprite as the default, to show in the palette.
                    auto_tile.m_DefaultSprite = sprs.GetSpriteByIdx(0, 47);

                    auto_tile.m_TilingRules = new List <AutoTile.TilingRule>(XP_RULE_MAP.Count);
                    for (var i = 0; i < XP_RULE_MAP.Count; ++i)
                    {
                        var rule = new AutoTile.TilingRule();
                        rule.m_Neighbors = XP_RULE_MAP[i];
                        rule.m_Sprites   = sprs.GetSpritesByIdx(m_AnimationFrames, i);
                        if (m_AnimationFrames > 1)
                        {
                            rule.m_AnimationSpeed = m_AnimationSpeed;
                            rule.m_Output         = AutoTile.TilingRule.OutputSprite.Animation;
                        }
                        else
                        {
                            rule.m_Output = AutoTile.TilingRule.OutputSprite.Single;
                        }
                        auto_tile.m_TilingRules.Add(rule);
                    }

                    var auto_tile_path = Path.Combine(Path.GetDirectoryName(org_path), Path.GetFileNameWithoutExtension(org_path) + "_RuleTile.asset");
                    auto_tile_path = AssetDatabase.GenerateUniqueAssetPath(auto_tile_path);

                    AssetDatabase.CreateAsset(auto_tile, auto_tile_path);
                }

                GUI.enabled = true;

                //if (GUILayout.Button("Test A2")) {
                //    MakeAutoTile_A2(@"E:\RPGMakerMV\Project1\img\tilesets\Inside_A2.png");
                //}
            }
        }
コード例 #3
0
ファイル: EAutoTileType.cs プロジェクト: GodLesZ/svn-dump
		public static bool HasNot(this EAutoTileType Type, EAutoTileType HasType) {
			return Type.Has(HasType) == false;
		}
コード例 #4
0
        private void FillAutoTileTexture(Texture2DRegion org, Texture2DRegion to, Size cell_size, EAutoTileType autotile_type)
        {
            for (var i = 0; i < XP_AUTOTILE_MAP.Count; ++i)
            {
                var map = XP_AUTOTILE_MAP[i];
                if (autotile_type == EAutoTileType.RPG_MAKER_MV)
                {
                    map = map.Select(idx => MV_XP_REMAP[idx]).ToArray();
                }

                CopyRegion(org, map, to, i, cell_size);
            }
        }
コード例 #5
0
ファイル: EAutoTileType.cs プロジェクト: GodLesZ/svn-dump
		public static bool HasAll(this EAutoTileType Type, EAutoTileType HasType) {
			return (Type & HasType) == HasType;
		}
コード例 #6
0
ファイル: EAutoTileType.cs プロジェクト: GodLesZ/svn-dump
		public static bool Has(this EAutoTileType Type, EAutoTileType HasType) {
			return (Type & HasType) != EAutoTileType.None;
		}
コード例 #7
0
 public static bool HasNot(this EAutoTileType Type, EAutoTileType HasType)
 {
     return(Type.Has(HasType) == false);
 }
コード例 #8
0
 public static bool HasAll(this EAutoTileType Type, EAutoTileType HasType)
 {
     return((Type & HasType) == HasType);
 }
コード例 #9
0
 public static bool Has(this EAutoTileType Type, EAutoTileType HasType)
 {
     return((Type & HasType) != EAutoTileType.None);
 }