Exemplo n.º 1
0
    static void UpdateAnim()
    {
        string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

        HashSet <string> guids = new HashSet <string>(AssetDatabase.FindAssets("", new string[] { assetPath }));

        Dictionary <string, Sprite> sprites = new Dictionary <string, Sprite>();

        foreach (string guid in guids)
        {
            Object[] objs = AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetDatabase.GUIDToAssetPath(guid));
            foreach (Object o in objs)
            {
                if (o is Sprite)
                {
                    sprites.Add(o.name, o as Sprite);
                }
            }
        }

        Dictionary <string, Cartoon> Cartoons = new Dictionary <string, Cartoon>();
        List <Sprite> tempss = new List <Sprite>();

        for (int i = 0; i < 1000; ++i)
        {
            string animName = string.Format("anim_{0}_", i);
            for (int j = 0; j < 100; ++j)
            {
                string frameName = animName + j;
                Sprite s         = null;
                if (sprites.TryGetValue(frameName, out s))
                {
                    tempss.Add(s);
                }
            }

            if (tempss.Count != 0)
            {
                Cartoon c = new Cartoon();
                c.name    = i.ToString();
                c.fps     = 5f;
                c.sprites = tempss.ToArray();
                c.width   = (int)c.sprites[0].rect.width;
                c.height  = (int)c.sprites[0].rect.height;

                Cartoons.Add(i.ToString(), c);

                tempss.Clear();
            }
        }

        SymbolTextInit sti      = Resources.Load <SymbolTextInit>("SymbolTextInit");
        FieldInfo      info     = typeof(SymbolTextInit).GetField("cartoons", BindingFlags.Instance | BindingFlags.NonPublic);
        List <Cartoon> cartoons = new List <Cartoon>(Cartoons.Values);

        cartoons.Sort((Cartoon x, Cartoon y) =>
        {
            return(int.Parse(x.name).CompareTo(int.Parse(y.name)));
        });

        info.SetValue(sti, cartoons.ToArray());
        EditorUtility.SetDirty(sti);
    }
 public async Task UpdateCartoon(string id, Cartoon cartoonIn)
 {
     await _cartoonStoreDBService.UpdateCartoonAsync(id, cartoonIn);
 }
Exemplo n.º 3
0
 public CartoonCard(Cartoon cartoon)
 {
     InitializeComponent();
     this.cartoonlist = cartoon;
 }
        public async Task <Cartoon> PostCartoon(Cartoon cartoonIn)
        {
            var cartoon = await _cartoonStoreDBService.AddCartoonAsync(cartoonIn);

            return(cartoon);
        }
        /// <summary>
        /// Создать новый м/с
        /// </summary>
        public void CreateNewCartoon()
        {
            if (CanCreateNewCartoon is false)
            {
                return;
            }
            using (var ctx = new CVDbContext(AppDataPath))
            {
                var newCartoon = new Cartoon
                {
                    Name        = SelectedCartoon.Name,
                    Checked     = true,
                    Description = SelectedCartoon.Description
                };

                ctx.Cartoons.Add(newCartoon);
                ctx.SaveChanges();
                ctx.CartoonWebSites
                .First(cws => cws.CartoonWebSiteId == GlobalIdList.WebSiteId)
                .Cartoons.Add(ctx.Cartoons.ToList().Last());
                ctx.SaveChanges();

                newCartoon             = ctx.Cartoons.ToList().Last();
                GlobalIdList.CartoonId = newCartoon.CartoonId;

                CartoonVoiceOver voiceOver;
                if (VoiceOvers.Any() is false)
                {
                    ctx.VoiceOvers.Add(new CartoonVoiceOver
                    {
                        Name = $"{SelectedCartoon.Name}_VO"
                    });
                    ctx.SaveChanges();
                    voiceOver = ctx.VoiceOvers.ToList().Last();
                }
                else
                {
                    voiceOver = ctx.VoiceOvers
                                .First(vo => vo.Cartoons
                                       .Any(c => c.CartoonId == newCartoon.CartoonId));
                }

                voiceOver.Cartoons.Add(newCartoon);
                newCartoon.CartoonVoiceOvers.Add(voiceOver);

                var parent = ((CartoonsEditorViewModel)Parent);

                var cartoonUrl = new CartoonUrl
                {
                    CartoonWebSiteId = parent.SelectedWebSite.CartoonWebSiteId,
                    WebSiteUrl       = parent.SelectedWebSite.Url,
                    CartoonId        = newCartoon.CartoonId,
                    Checked          = true,
                    Url = SelectedCartoonUrl.Url
                };

                newCartoon.CartoonUrls.Add(cartoonUrl);
                ctx.SaveChanges();

                TempCartoonSnapshot = JsonConvert.SerializeObject(SelectedCartoon);
                NotifyOfPropertyChange(() => CanSaveChanges);

                parent.Cartoons.Add(newCartoon);
                parent.NotifyOfPropertyChange(() => parent.Cartoons);
                parent.Cartoons.Remove(parent.Cartoons.First(c => c.Name == NewElementString));
                parent.Cartoons.Add(new Cartoon {
                    Name = NewElementString
                });
                parent.SelectedCartoon = parent.Cartoons.First(c => c.CartoonId == GlobalIdList.CartoonId);
            }
        }
Exemplo n.º 6
0
 public async Task UpdateCartoonAsync(string id, Cartoon cartoonIn)
 {
     await this._writeCartoon.ReplaceOneAsync(cartoon => cartoon.Id == id, cartoonIn);
 }
Exemplo n.º 7
0
        public async Task <Cartoon> AddCartoonAsync(Cartoon cartoon)
        {
            await _writeCartoon.InsertOneAsync(cartoon);

            return(cartoon);
        }
Exemplo n.º 8
0
    static void UpdateAnim()
    {
        Dictionary <string, List <Frame> > anims = new Dictionary <string, List <Frame> >();
        {
            HashSet <string> guids = new HashSet <string>(AssetDatabase.FindAssets("", new string[] { "Assets" }));
            foreach (string guid in guids)
            {
                string   assetPath = AssetDatabase.GUIDToAssetPath(guid);
                Object[] objs      = AssetDatabase.LoadAllAssetRepresentationsAtPath(assetPath);
                foreach (Object o in objs)
                {
                    if (!(o is Sprite) || !assetPath.Contains("/anim_"))
                    {
                        continue;
                    }

                    string name;
                    int    frame;
                    int    time;
                    {
                        string fileName = System.IO.Path.GetFileNameWithoutExtension(assetPath);
                        int    sp       = fileName.LastIndexOf('_');
                        name = fileName.Substring(5, sp - 5);
                        int sp1 = fileName.LastIndexOf('#');
                        if (sp1 == -1)
                        {
                            frame = int.Parse(fileName.Substring(sp + 1));
                            time  = (int)(1f / 6f * 1000);
                        }
                        else
                        {
                            frame = int.Parse(fileName.Substring(sp + 1, sp1 - sp - 1));
                            time  = int.Parse(fileName.Substring(sp1 + 1));
                        }
                    }

                    if (!anims.TryGetValue(name, out var f))
                    {
                        anims.Add(name, f = new List <Frame>());
                    }

                    f.Add(new Frame
                    {
                        index = frame,
                        frame = new Cartoon.Frame
                        {
                            sprite = new DSprite(o as Sprite),
                            delay  = time * 0.001f,
                        },
                    });
                }
            }
        }

        Dictionary <string, Cartoon> Cartoons = new Dictionary <string, Cartoon>();
        {
            foreach (var ator in anims)
            {
                Cartoon cartoon = new Cartoon();
                Cartoons.Add(ator.Key, cartoon);
                cartoon.name = ator.Key;

                var frames = ator.Value;
                int count  = frames.Count;
                cartoon.frames = new Cartoon.Frame[count];
                for (int i = 0; i < count; ++i)
                {
                    var f = frames[i];
                    cartoon.frames[f.index - 1] = f.frame;
                }

                var fs = cartoon.frames[0].sprite;
                cartoon.width  = fs.width;
                cartoon.height = fs.height;
            }
        }

        SymbolTextInit sti      = Resources.Load <SymbolTextInit>("SymbolTextInit");
        FieldInfo      info     = typeof(SymbolTextInit).GetField("cartoons", BindingFlags.Instance | BindingFlags.NonPublic);
        List <Cartoon> cartoons = new List <Cartoon>(Cartoons.Values);

        cartoons.Sort(Sorted);

        info.SetValue(sti, cartoons.ToArray());
        EditorUtility.SetDirty(sti);
    }