Esempio n. 1
0
    private void CreateGameList()
    {
        if (MinigamePanels != null)
        {
            foreach (GameObject go in MinigamePanels)
            {
                Destroy(go);
            }
        }

        MinigamePanels = new List <GameObject>();

        int count = 0;

        foreach (GameObject go in GameManager.Instance.MiniGame_Objects)
        {
            GameObject newGame = Instantiate(MinigameListing_Prefab, MinigameScroll_Object.transform);
            newGame.GetComponent <MinigameBTNObject>().GameName = go.GetComponent <BaseGame>().Name;
            if (!MinigameData.FileExists(newGame.GetComponent <MinigameBTNObject>().GameName))
            {
                MinigameData MGD = new MinigameData();
                MGD.GameName      = newGame.GetComponent <MinigameBTNObject>().GameName;
                MGD.TimeActivated = new DateTime(1999, 12, 31).ToString();
                MGD.Highscore     = 0;
                MGD.Org           = (GameManager.Organizations)count;
                MGD.SaveGameData();
            }
            MinigamePanels.Add(newGame);
            count++;
        }
    }
Esempio n. 2
0
    // Activates game for 24 hours
    public static void Activate(string gameName)
    {
        MinigameData mgd = RetrieveData(gameName);

        mgd.TimeActivated = DateTime.Now.ToString();
        mgd.SaveGameData();
    }
Esempio n. 3
0
 /// <summary> Retrieves and deserializes the remember me data for use if it exists </summary>
 public static MinigameData RetrieveData(string gameName)
 {
     try
     {
         if (FileExists(gameName))
         {
             FileStream fs   = new FileStream(Application.persistentDataPath + "/" + gameName + ".dat", FileMode.Open);
             byte[]     data = new byte[fs.Length];
             fs.Read(data, 0, data.Length);
             fs.Close();
             MinigameData MGD = BytesToData(data);
             return(MGD);
         }
         else
         {
             MinigameData MGD = new MinigameData();
             MGD.GameName      = gameName;
             MGD.TimeActivated = DateTime.Now.ToString();
             MGD.Highscore     = 0;
             SaveData(MGD);
             return(MGD);
         }
     }
     catch (Exception e)
     {
         Debug.Log("ERROR: " + e.Message);
     }
     return(new MinigameData());
 }
Esempio n. 4
0
    const int _maxStarCount = 3;                                /// 환경에 생성할 수 있는 별의 총 개수

    /* 초기화를 두개의 함수로 분리
     * 게임시작시 단 한번 초기화해도 되는 부분(Awake 함수)과
     * 게임을 재도전할때마다 초기화해야되는 부분(Start 함수)을 분리하였다.
     * 이를 통해 단 한번 초기화해도 되는 부분이 여러번 호출되어 CPU가 낭비되는 일이 없도록 하였다.
     */
    /* [클린성] 가독성을 위해서 Enumeration 이용
     * 코드의 가독성을 위해서 Enumeration을 적극이용하는 편이다.
     * 또한 int형으로도 형변환이 되어 index를 가독성있게 표현하는데 큰 역할을 한다.
     */
    /// <summary>
    /// 게임 입장시, "단 한번만" 초기화해도 되는 부분을 이 함수에서 초기화한다.
    /// </summary>
    void Awake()
    {
        _playerController = GameObject.FindWithTag("Player").GetComponent <DogPlayerController>();
        var minigameDataSet = GameObject.FindWithTag("Managers").GetComponentInChildren <MinigameDataSet>();

        _data = minigameDataSet.GetMinigameData(MinigameType.Type.CatchGame);
        Initialize();
    }
    public void DisableActivity()
    {
        minigameData = null;

        active = false;
        activityWarp.parent.DOScale(Vector3.zero, 0.3f).OnComplete(() => activityWarp.gameObject.SetActive(true));
        activityIcon.GetComponent <SpriteRenderer>().DOFade(0f, 0.5f);
    }
    public void ActivateActivity(MinigameData minigameData)
    {
        this.minigameData = minigameData;

        active = true;
        activityWarp.gameObject.SetActive(true);
        activityIcon.GetComponent <SpriteRenderer>().DOFade(1f, 0.5f);
        activityWarp.parent.DOScale(Vector3.one, 0.3f);
        animator.runtimeAnimatorController = minigameData.iconAnimator;
    }
Esempio n. 7
0
    public void Start()
    {
        MinigameData data = MinigameData.LoadGameData(GameName);

        if (data.IsActive())
        {
            gameObject.GetComponent <Image>().sprite = GameManager.Instance.MiniGame_Objects.First(o => o.name.Contains(GameName)).GetComponent <GameUI>().Active_Img;
        }
        else
        {
            gameObject.GetComponent <Image>().sprite = GameManager.Instance.MiniGame_Objects.First(o => o.name.Contains(GameName)).GetComponent <GameUI>().Inactive_Img;
        }
    }
Esempio n. 8
0
 /// <summary> Serializes the data for the remember me </summary>
 public static void SaveData(MinigameData MGData)
 {
     try
     {
         byte[]     data = DataToBytes(MGData);
         FileStream fs   = new FileStream(Application.persistentDataPath + "/" + MGData.GameName + ".dat", FileMode.Create);
         fs.Write(data, 0, data.Length);
         fs.Close();
     }
     catch (Exception e)
     {
         Debug.Log("ERROR: " + e.Message);
     }
 }
Esempio n. 9
0
    public void Clicked()
    {
        MinigameData data = MinigameData.LoadGameData(GameName);

        if (data.IsActive())
        {
            foreach (GameObject go in GameManager.Instance.MiniGame_Objects)
            {
                if (go.name == GameName + "_UI")
                {
                    GameObject GameUI = Instantiate(go, UIManager.Instance.MainCanvas.transform);
                    GameManager.Minigame = GameUI.GetComponent <BaseGame>();
                    GameManager.MGD      = MinigameData.RetrieveData(GameName);
                }
            }
            GameManager.Instance.SetState(GameManager.GameState.Minigame);
        }
    }
Esempio n. 10
0
 /// <summary> Converts Bytes to MinigameData for use </summary>
 private static MinigameData BytesToData(byte[] bytes)
 {
     try
     {
         MinigameData ud   = new MinigameData();
         int          size = Marshal.SizeOf(ud);
         IntPtr       ptr  = Marshal.AllocHGlobal(size);
         Marshal.Copy(bytes, 0, ptr, size);
         ud = (MinigameData)Marshal.PtrToStructure(ptr, ud.GetType());
         Marshal.FreeHGlobal(ptr);
         return(ud);
     }
     catch (Exception e)
     {
         Debug.Log("ERROR: " + e.Message);
     }
     return(new MinigameData());
 }
Esempio n. 11
0
    /// <summary> Converts a MinigameData to Bytes for storage </summary>
    private static byte[] DataToBytes(MinigameData MGData)
    {
        try
        {
            int    size   = Marshal.SizeOf(MGData);
            byte[] buffer = new byte[size];
            IntPtr ptr    = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(MGData, ptr, true);
            Marshal.Copy(ptr, buffer, 0, size);
            Marshal.FreeHGlobal(ptr);

            return(buffer);
        }
        catch (Exception e)
        {
            Debug.Log("ERROR: " + e.Message);
        }
        return(new byte[0]);
    }
Esempio n. 12
0
    /// <summary> Unlocks a specific organizations minigame </summary>
    public void Unlock(Organizations org)
    {
        string gname = MiniGame_Objects[(int)org].name.Replace("_UI", "");

        MinigameData.Activate(gname);
    }