예제 #1
0
        private IResource CreateResource(eResourceType eType, string name, string assetpath, Object objresource, bool isAssetBundle)
        {
            IResource resource = null;

            switch (eType)
            {
            //case E_ResourceType.Actor:
            case eResourceType.UI:
            case eResourceType.Prefab:
                resource = new PrefabResource(objresource, eType, isAssetBundle);
                break;

            //                 case E_ResourceType.UnitySprite:
            //                     resource = new SpriteResource(objresource);
            //                     break;
            case eResourceType.Script:
                resource = new ScriptResource(objresource, isAssetBundle);
                break;

            case eResourceType.SpriteAsset:
                SpritePackerAsset spritePackerAsset = (SpritePackerAsset)objresource;
                resource = new SpriteAssetResource(spritePackerAsset.AllSprites, isAssetBundle);
                break;

            case eResourceType.Scriptable:
                resource = new ScriptableResource(objresource, isAssetBundle);
                break;

            case eResourceType.Texture:
                resource = new TextureResouce(objresource, isAssetBundle);
                break;

            case eResourceType.Sound:
                resource = new SoundResource(objresource, isAssetBundle);
                break;
            }
            resource.InitLoad(name, assetpath);

            Dictionary <int, IResource> dicRes = GetDicResource(eType);

            if (dicRes.ContainsKey(resource.GetHashCode()))
            {
                //           LogManager.GetInstance().LogDebug("CreateResource name error" + name);
            }
            else
            {
                dicRes.Add(resource.GetHashCode(), resource);
            }

            return(resource);
        }
예제 #2
0
    private static void CreateAutoTileMakerPrefabs(string assetPath)
    {
        string[] split = assetPath.Split('/');
        string   name  = split[split.Length - 1];

        name = name.Replace(".png", "");

        //EditorUtility.SetDirty(texture);

        //AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

        Object[] SpriteAssetArr = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(assetPath);
        if (SpriteAssetArr.Length <= 0)
        {
            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        }
        else
        {
            //GameObject gocopy = new GameObject(name);


            //GameObject gocopy = EditorUtility.CreateGameObjectWithHideFlags(name, HideFlags.HideInHierarchy);
            //AutoTileSprite autoTileResource = gocopy.AddComponent<AutoTileSprite>();
            SpritePackerAsset autoTileResource = ScriptableObject.CreateInstance <SpritePackerAsset>();
            autoTileResource.AllSprites = new Sprite[SpriteAssetArr.Length - 1];
            for (int i = 1; i < SpriteAssetArr.Length; i++)
            {
                autoTileResource.AllSprites[i - 1] = (Sprite)SpriteAssetArr[i];
            }
            autoTileResource.AssetName = name;

            //string basePath = Path.GetDirectoryName(assetPath.Substring(0, assetPath.LastIndexOf(".png")));
            string prefabspath = "Assets/Resources/Map/Prefabs/AutoTile";
            if (Directory.Exists(prefabspath) == false)
            {
                MakeDirectory(prefabspath);
            }
            string filecheck = prefabspath + "/" + name + ".asset";
            if (File.Exists(filecheck))
            {
                return;
            }
            AssetDatabase.CreateAsset(autoTileResource, filecheck);
            //Object tempPrefab = PrefabUtility.CreateEmptyPrefab(prefabspath + "/" + name + ".prefab");
            //PrefabUtility.ReplacePrefab(gocopy, tempPrefab, ReplacePrefabOptions.ConnectToPrefab);
            //GameObject.DestroyImmediate(gocopy, true);
        }
    }
예제 #3
0
    private static void CreateAutoTile16Prefabs(string assetPath)
    {
        string[] split = assetPath.Split('/');
        string   name  = split[split.Length - 1];

        name = name.Replace(".png", "");

        string[] split2  = name.Split('_');
        string   subname = split2[split2.Length - 1];

        //EditorUtility.SetDirty(texture);

        //AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

        Object[] SpriteAssetArr = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(assetPath);
        if (SpriteAssetArr.Length <= 0)
        {
            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        }
        else
        {
            string prefabspath = "Assets/Resources/Map/Prefabs/AutoTile";
            if (Directory.Exists(prefabspath) == false)
            {
                MakeDirectory(prefabspath);
            }


            ScriptCsv scriptCsv = new ScriptCsv(prefabspath + "/" + name + ".csv");
            Texture2D texture2D = (Texture2D)SpriteAssetArr[0];
            int       offset    = texture2D.width / 24;

            int count = (SpriteAssetArr.Length - 2) / offset;
            //autoTileResource.ListPack = new TileSpritePackerAsset.TileSpritePacker[count];
            for (int i = 0; i < count; i++)
            {
                int spriteoffset = i * offset + 1;
                SpritePackerAsset spritePackerAsset = ScriptableObject.CreateInstance <SpritePackerAsset>();
                //TileSpritePackerAsset.TileSpritePacker spritePackerAsset = new TileSpritePackerAsset.TileSpritePacker();
                spritePackerAsset.AssetName  = subname + i.ToString();
                spritePackerAsset.AllSprites = new Sprite[offset];
                for (int j = 0; j < offset; j++)
                {
                    spritePackerAsset.AllSprites[j] = (Sprite)SpriteAssetArr[j + spriteoffset];
                }
                //autoTileResource.ListPack[i] = spritePackerAsset;
                string filecheck = prefabspath + "/" + spritePackerAsset.AssetName + ".asset";
                if (File.Exists(filecheck))
                {
                    File.Delete(filecheck);
                }
                AssetDatabase.CreateAsset(spritePackerAsset, filecheck);

                SpriteSheetCsv scSheetCsv = new SpriteSheetCsv();
                scSheetCsv.assetName  = name;
                scSheetCsv.id         = i;
                scSheetCsv.spriteName = spritePackerAsset.AssetName;
                scSheetCsv.numIndex   = i;
                scSheetCsv.numX       = (scSheetCsv.numIndex) % spriteoffset;
                scSheetCsv.numY       = (scSheetCsv.numIndex) / spriteoffset;
                scriptCsv.LstValue.Add(scSheetCsv);
            }

            scriptCsv.Save();
            //autoTileResource.AssetName = name;
        }
    }
예제 #4
0
    private static void CreateCharacterPrefabs(string assetPath)
    {
        //EditorUtility.SetDirty(texture);

        //AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

        string[] split = assetPath.Split('/');
        string   name  = split[split.Length - 1];

        name = name.Replace(".png", "");

        Object[] SpriteAssetArr = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(assetPath);
        if (SpriteAssetArr.Length <= 0)
        {
            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        }
        else
        {
            //GameObject gocopy = new GameObject(name);
            //GameObject gocopy = EditorUtility.CreateGameObjectWithHideFlags(name, HideFlags.HideInHierarchy);
            //AutoTileSprite autoTileResource = gocopy.AddComponent<AutoTileSprite>();



            //             CharacterSpritePackerAsset characterSprite = ScriptableObject.CreateInstance<CharacterSpritePackerAsset>();
            //             characterSprite.AssetName = name;
            //             characterSprite.ListPack = new CharacterSpritePackerAsset.CharacterSpritePacker[11 * 18];

            string prefabspath = "Assets/Resources/Map/Prefabs/Character";
            if (Directory.Exists(prefabspath) == false)
            {
                MakeDirectory(prefabspath);
            }


            ScriptCsv scriptCsv = new ScriptCsv(prefabspath + "/" + name + ".csv");
            Texture2D texture2D = (Texture2D)SpriteAssetArr[0];
            Sprite    sprite    = (Sprite)SpriteAssetArr[1];
            int       offsetX   = (int)(texture2D.width / sprite.rect.width);

            int index = 0;
            for (int i = 0; i < 11; i++)
            {
                for (int j = 0; j < 18; j++)
                {
                    int offset = i * 36 + 1;
                    SpritePackerAsset spritePackerAsset = ScriptableObject.CreateInstance <SpritePackerAsset>();
                    spritePackerAsset.AllSprites    = new Sprite[2];
                    spritePackerAsset.AllSprites[0] = (Sprite)SpriteAssetArr[j + offset];
                    spritePackerAsset.AllSprites[1] = (Sprite)SpriteAssetArr[j + offset + 18];
                    spritePackerAsset.AssetName     = spritePackerAsset.AllSprites[0].name;

                    string filecheck = prefabspath + "/" + spritePackerAsset.AssetName + ".asset";
                    if (File.Exists(filecheck))
                    {
                        File.Delete(filecheck);
                    }

                    AssetDatabase.CreateAsset(spritePackerAsset, filecheck);

                    SpriteSheetCsv scSheetCsv = new SpriteSheetCsv();
                    scSheetCsv.assetName  = name;
                    scSheetCsv.id         = index;
                    scSheetCsv.spriteName = spritePackerAsset.AllSprites[0].name;
                    scSheetCsv.numIndex   = j + offset - 1;
                    scSheetCsv.numX       = (scSheetCsv.numIndex) % offsetX;
                    scSheetCsv.numY       = (scSheetCsv.numIndex) / offsetX;
                    scriptCsv.LstValue.Add(scSheetCsv);



                    index++;
                }
            }
            scriptCsv.Save();
            SpritePackerAsset spriteshadowPackerAsset = ScriptableObject.CreateInstance <SpritePackerAsset>();
            spriteshadowPackerAsset.AllSprites = new Sprite[6];
            index = 0;
            for (int i = 11 * 36 + 1; i < SpriteAssetArr.Length; i++)
            {
                spriteshadowPackerAsset.AllSprites[index++] = (Sprite)SpriteAssetArr[i];
            }
            spriteshadowPackerAsset.AssetName = name;

            string fileshadowcheck = prefabspath + "/" + name + "_shadow.asset";
            if (File.Exists(fileshadowcheck))
            {
                File.Delete(fileshadowcheck);
            }

            AssetDatabase.CreateAsset(spriteshadowPackerAsset, fileshadowcheck);

            //string basePath = Path.GetDirectoryName(assetPath.Substring(0, assetPath.LastIndexOf(".png")));

            //Object tempPrefab = PrefabUtility.CreateEmptyPrefab(prefabspath + "/" + name + ".prefab");
            //PrefabUtility.ReplacePrefab(gocopy, tempPrefab, ReplacePrefabOptions.ConnectToPrefab);
            //GameObject.DestroyImmediate(gocopy, true);
        }
    }
예제 #5
0
    private static void CreateSpritePacker(string assetPath, string outpath)
    {
        string[] split = assetPath.Split('/');
        string   name  = split[split.Length - 1];

        name = name.Replace(".png", "");

        //EditorUtility.SetDirty(texture);

        //AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        //AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);

        Object[] SpriteAssetArr = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(assetPath);
        if (SpriteAssetArr.Length <= 0)
        {
            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        }
        else
        {
            //GameObject gocopy = new GameObject(name);


            //GameObject gocopy = EditorUtility.CreateGameObjectWithHideFlags(name, HideFlags.HideInHierarchy);
            //AutoTileSprite autoTileResource = gocopy.AddComponent<AutoTileSprite>();

            string prefabspath = "Assets/Resources/Map/Prefabs/" + outpath;
            if (Directory.Exists(prefabspath) == false)
            {
                MakeDirectory(prefabspath);
            }
            string filecheck = prefabspath + "/" + name + ".asset";
            if (File.Exists(filecheck))
            {
                File.Delete(filecheck);
            }
            ScriptCsv scriptCsv = new ScriptCsv(prefabspath + "/" + name + ".csv");
            Texture2D texture2D = (Texture2D)SpriteAssetArr[0];
            Sprite    sprite    = (Sprite)SpriteAssetArr[1];

            int offsetX = (int)(texture2D.width / sprite.rect.width);
            int offsetY = (int)(texture2D.height / sprite.rect.height);

            SpritePackerAsset objectPackerSprite = ScriptableObject.CreateInstance <SpritePackerAsset>();
            objectPackerSprite.AllSprites = new Sprite[SpriteAssetArr.Length - 1];
            for (int i = 1; i < SpriteAssetArr.Length; i++)
            {
                objectPackerSprite.AllSprites[i - 1] = (Sprite)SpriteAssetArr[i];
                SpriteSheetCsv scSheetCsv = new SpriteSheetCsv();
                scSheetCsv.assetName  = name;
                scSheetCsv.id         = i - 1;
                scSheetCsv.spriteName = objectPackerSprite.AllSprites[i - 1].name;
                scSheetCsv.numIndex   = scSheetCsv.id;
                scSheetCsv.numX       = scSheetCsv.id % offsetX;
                scSheetCsv.numY       = scSheetCsv.id / offsetX;
                scriptCsv.LstValue.Add(scSheetCsv);
            }
            objectPackerSprite.AssetName = name;
            scriptCsv.Save();

            AssetDatabase.CreateAsset(objectPackerSprite, filecheck);
        }
    }
예제 #6
0
        private IResource MakeSpriteResource(eResourceType eType, ePath ePath, string name)
        {
            string path = StringUtil.Format("{0}/{1}", m_pathManager.GetPath(ePath), name);

            Sprite[]          allresource       = null;
            Object            obj               = null;
            Object            autotile          = null;
            SpritePackerAsset spritePackerAsset = null;

            if (ePath == Resource.ePath.MapAutoTile)
            {
                obj = Resources.Load(path);
                string autotilepath = m_pathManager.GetPath(ePath) + "AutoTile";
                autotile = Resources.Load(autotilepath);
                if (obj is SpritePackerAsset)
                {
                    spritePackerAsset = (SpritePackerAsset)obj;
                    allresource       = spritePackerAsset.AllSprites;
                }
            }
            if (ePath == Resource.ePath.UISprite)
            {
                obj = Resources.Load(path);
            }
            else if (ePath == Resource.ePath.MapAsset || ePath == Resource.ePath.MapAutoAsset || ePath == Resource.ePath.MapActorAsset)
            {
                obj = Resources.Load(path);
                if (obj is SpritePackerAsset)
                {
                    spritePackerAsset = (SpritePackerAsset)obj;
                    allresource       = spritePackerAsset.AllSprites;
                }
            }
            else
            {
                allresource = Resources.LoadAll <Sprite>(path);
            }

            IResource resource = null;

            if (eType == eResourceType.SpriteAsset)
            {
                if (obj == null)
                {
                    Debug.LogError("TileSprite MakeSpriteResource name error" + name);
                    return(null);
                }

                resource = new SpritePackerResource(spritePackerAsset, spritePackerAsset.AllSprites, false);
            }
            else if (eType == eResourceType.Sprite)
            {
                if (obj == null)
                {
                    Debug.LogError("UISprite MakeSpriteResource name error" + name);
                    return(null);
                }

                resource = new SpriteResource(obj, false);
            }
            else
            {
                if (allresource == null)
                {
                    Debug.LogError("SpriteResource name error" + name);
                    return(null);
                }

                resource = new SpritePackerResource(spritePackerAsset, allresource, false);
            }
            string[] split        = path.Split('/');
            string   resourcename = split[split.Length - 1];

            resource.InitLoad(resourcename, path);
            Dictionary <int, IResource> dicRes = GetDicResource(eType);

            if (dicRes.ContainsKey(resource.GetHashCode()))
            {
                Debug.LogError("MakeSpriteResource name error" + name);
            }
            else
            {
                dicRes.Add(resource.GetHashCode(), resource);
            }
            return(resource);
        }