Пример #1
0
    // public AudioClip BgAudio;

    // private AudioSource audio = null;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("ChooseControl Start");
        _tipPanel = (GameObject)Instantiate(Resources.Load("Prefabs/UI/TipBg"));
        _tipPanel.transform.SetParent(gameObject.transform, false);
        _tipPanel.transform.position = new Vector2(Screen.width / 2, Screen.height / 2);
        _tipPanel.SetActive(false);
        //查找Bg
        _stageNodes = new StageNode[25];
        GameObject stageList = GameObject.Find("StageList");

        for (int i = 0; i < 25; i++)
        {
            _stageNodes[i] = stageList.transform.Find("Stage" + i).gameObject.GetComponent <StageNode>();
        }
        var         userData = UserDataManager.GetInstance().GetUserData();
        Stage       st       = ConfigManager.GetInstance().GetStage(userData.CurrentStage);
        UserChapter uc       = userData.GetUserChapter(st.ChapterId);

        Debug.Log("userData.CurrentStage=" + userData.CurrentStage + ",st.ChapterId=" + st.ChapterId + ",uc.ChaperId=" + uc.ChapterId);
        LoadChapter(uc);
        // audio = GetComponent<AudioSource>();
        // audio.clip = BgAudio;
        // audio.Play();
    }
Пример #2
0
        public async Task <UserChapter> InsertUserChapter(UserChapter userChapter)
        {
            context.UserChapters.Add(userChapter);
            await context.SaveChangesAsync();

            return(userChapter);
        }
Пример #3
0
    public void LoadChapter(UserChapter userChapter)
    {
        //加载标题
        ChapterNode   cn = GameObject.Find("Bg").GetComponent <ChapterNode>();
        ConfigManager cm = ConfigManager.GetInstance();

        _chapter = cm.GetChapter(userChapter.ChapterId);
        cn.LoadData(_chapter, userChapter);

        Chapter chapter = ConfigManager.GetInstance().GetChapter(userChapter.ChapterId);

        //加载关卡按钮
        for (int i = 0; i < _stageNodes.Length; i++)
        {
            if (i >= chapter.Stages.Count)
            {
                _stageNodes[i].LoadData(null, null);
            }
            else if (i >= userChapter.Stages.Count)
            {
                _stageNodes[i].LoadData(ConfigManager.GetInstance().GetStage(chapter.Stages[i].StageId), null);
            }
            else
            {
                Debug.Log("chapter.Stages[i].StageId=" + chapter.Stages[i].StageId);
                Debug.Log("userChapter.Stages[i]=" + userChapter.Stages[i]);
                _stageNodes[i].LoadData(ConfigManager.GetInstance().GetStage(chapter.Stages[i].StageId), userChapter.Stages[i]);
            }
        }
    }
Пример #4
0
    private void OnOneKey(UEvent evt)
    {
        Debug.Log("OnOneKey");
        //查找到点击的关卡
        UserDataManager.GetInstance().OneKeyOpen();
        UserChapter uc = UserDataManager.GetInstance().GetUserData().GetUserChapter(_chapter.ChapterId);

        LoadChapter(uc);
    }
Пример #5
0
 private async Task InsertUserChapter(int userId, int chapterId)
 {
     var userChapter = new UserChapter()
     {
         ChapterId      = chapterId,
         UserId         = userId,
         CompletionDate = DateTime.UtcNow
     };
     await courseRepo.InsertUserChapter(userChapter);
 }
        public void Update(UserChapter userChapterParam)
        {
            var userChapter = _context.UserChapter.Find(userChapterParam.Id);

            if (userChapter == null)
            {
                throw new AppException("User Chapter not found");
            }

            ValidateUserChapterParams(userChapterParam);

            _context.UserChapter.Update(userChapter);
            _context.SaveChanges();
        }
Пример #7
0
    //加载数据
    public void LoadData(Chapter chapter, UserChapter userChapter)
    {
        if (!_inited)
        {
            init();
        }

        //设置BG
        Texture2D t = Resources.Load <Texture2D>("Textures/UI/StageChoose/" + chapter.ChapterBg);

        _bg.sprite    = Sprite.Create(t, new Rect(0f, 0f, t.width, t.height), new Vector2(0.5f, 0.5f));
        t             = Resources.Load <Texture2D>("Textures/UI/StageChoose/" + chapter.ChapterTitle);
        _title.sprite = Sprite.Create(t, new Rect(0f, 0f, t.width, t.height), new Vector2(0.5f, 0.5f));
        //TODO 设置按钮调用
    }
        public UserChapter Create(UserChapter userChapter)
        {
            userChapter.Status = "ENABLED";

            ValidateUserChapterParams(userChapter);

            if (_context.UserChapter.Any(x => x.ChapterId == userChapter.ChapterId && x.UserId == userChapter.UserId && x.Status == userChapter.Status))
            {
                throw new AppException("User Chapter data already exists.");
            }

            _context.UserChapter.Add(userChapter);
            _context.SaveChanges();

            return(userChapter);
        }
        public UserChapter UpdateByUserIdAndChapterId(UserChapter userChapterParam)
        {
            var userChapter = _context.UserChapter.FirstOrDefault(x => x.UserId == userChapterParam.UserId && x.ChapterId == userChapterParam.ChapterId);

            if (userChapter == null)
            {
                throw new AppException("User Chapter not found");
            }

            ValidateUserChapterParams(userChapterParam);
            userChapter.Status = userChapterParam.Status;

            _context.UserChapter.Update(userChapter);
            _context.SaveChanges();

            return(userChapter);
        }
Пример #10
0
    private void OnPreChapterClick(UEvent evt)
    {
        Debug.Log("OnPreChapterClick _chapter=" + _chapter.ChapterId);
        //查找到点击的关卡
        if (_chapter.PreChapter == null)
        {
            showTip("已经是第一章");
            return;
        }
        UserChapter uc = UserDataManager.GetInstance().GetUserData().GetUserChapter(_chapter.PreChapter.ChapterId);

        if (uc == null)
        {
            showTip("未知错误");
            return;
        }
        _chapter = _chapter.PreChapter;
        LoadChapter(uc);
    }
Пример #11
0
    private void OnNextChapterClick(UEvent evt)
    {
        Debug.Log("OnNextChapterClick");
        //查找到点击的关卡
        if (_chapter.NextChapter == null)
        {
            showTip("已经是最后一关");
            return;
        }
        UserChapter uc = UserDataManager.GetInstance().GetUserData().GetUserChapter(_chapter.NextChapter.ChapterId);

        if (uc == null)
        {
            showTip("通关本章节开启下一章");
            return;
        }
        _chapter = _chapter.NextChapter;
        LoadChapter(uc);
    }
Пример #12
0
    public bool OpenStage(Stage stage)
    {
        //是否有当前章节
        UserChapter uc = null;

        foreach (var c in Chapters)
        {
            if (c.ChapterId == stage.ChapterId)
            {
                uc = c;
                break;
            }
        }

        if (uc != null)
        {
            foreach (var s in uc.Stages)
            {
                if (stage.StageId == s.StageId)
                {
                    return(false);
                }
            }
        }
        else
        {
            UserChapter nuc = new UserChapter();
            nuc.Stages    = new List <UserStage>();
            nuc.ChapterId = stage.ChapterId;
            uc            = nuc;
            Chapters.Add(uc);
        }

        UserStage us = new UserStage();

        us.StageId   = stage.StageId;
        us.Star      = 0;
        us.Completed = false;
        uc.Stages.Add(us);
        DBManager.WriteUserData();
        return(true);
    }
Пример #13
0
    public void parseJson(JsonData jd)
    {
        DeviceId = jd["DeviceId"].ToString();
        Chapters = new List <UserChapter>();
        foreach (JsonData chapter in jd["Chapters"])
        {
            UserChapter uc = new UserChapter();
            uc.parseJson(chapter);
            Chapters.Add(uc);
        }

        if (jd["CurrentStage"] != null)
        {
            CurrentStage = Int32.Parse(jd["CurrentStage"].ToString());
        }
        else
        {
            CurrentStage = 0;
        }
    }
Пример #14
0
    private void InitUserData()
    {
        _userData = new UserData();
        //初始化第一章第一关
        _userData.DeviceId = System.Guid.NewGuid().ToString();
        Chapter            c        = ConfigManager.GetInstance().GetAllChapters()[0];
        List <UserChapter> chapters = new List <UserChapter>();
        UserChapter        uc       = new UserChapter();

        uc.ChapterId = c.ChapterId;
        uc.Stages    = new List <UserStage>();
        chapters.Add(uc);
        Stage     s  = c.Stages[0];
        UserStage us = new UserStage();

        us.StageId   = s.StageId;
        us.Completed = false;
        us.Star      = 0;
        uc.Stages.Add(us);
        _userData.Chapters     = chapters;
        _userData.CurrentStage = s.StageId;
        DBManager.WriteUserData();
    }
        // private helper methods
        private static void ValidateUserChapterParams(UserChapter userChapter)
        {
            if (userChapter.ChapterId == 0)
            {
                throw new AppException("chapterId is required.");
            }

            if (userChapter.UserId == 0)
            {
                throw new AppException("userId is required.");
            }

            if (string.IsNullOrWhiteSpace(userChapter.Status))
            {
                throw new AppException("status is required.");
            }

            string[] validStatusArray = { "ENABLED", "DISABLED", "IN PROGRESS" };
            if (!validStatusArray.Contains(userChapter.Status.ToUpper()))
            {
                throw new AppException("status must be in ['ENABLED', 'DISABLED', 'IN PROGRESS' ]");
            }
        }