Exemplo n.º 1
0
    /// <summary>
    /// ガチャ回す
    /// </summary>
    public void OnButtonGacya()
    {
        //ガチャ結果保存用Dictionary初期化 (ID:出た回数)
        Dictionary <int, int> GacyaResult = new Dictionary <int, int>();

        //ガチャ結果保存用Dictionary初期化
        foreach (var t in SoData.sheets[0].list)
        {
            GacyaResult.Add(t.ID, 0);
        }

        //ガチャ回数分回す
        for (int i = 0; i < mGacyaCount; i++)
        {
            int id = Lottery();
            if (GacyaResult.ContainsKey(id))
            {
                GacyaResult[id] += 1;
            }
        }

        //ガチャ結果
        string tStr = String.Empty;

        foreach (var t in GacyaResult)
        {
            Debug.Log($"ガチャ:ID:{t.Key} 出た回数:{t.Value}");
            Entity_Gacya00.Param param = GetIdToElement(t.Key);
            if (param != null)
            {
                float probability = (float)t.Value / (float)mGacyaCount;
                tStr += $"{param.Type} 回数:{t.Value} 確率:{probability:p2} \n";
            }
            TextResultList.text = tStr;
        }

        TextResultTitle.text = $"【結果】{mGacyaCount}回";
    }
Exemplo n.º 2
0
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            if (!filePath.Equals(asset))
            {
                continue;
            }

            Entity_Gacya00 data = (Entity_Gacya00)AssetDatabase.LoadAssetAtPath(exportPath, typeof(Entity_Gacya00));
            if (data == null)
            {
                data = ScriptableObject.CreateInstance <Entity_Gacya00> ();
                AssetDatabase.CreateAsset((ScriptableObject)data, exportPath);
                data.hideFlags = HideFlags.NotEditable;
            }

            data.sheets.Clear();
            using (FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                IWorkbook book = null;
                if (Path.GetExtension(filePath) == ".xls")
                {
                    book = new HSSFWorkbook(stream);
                }
                else
                {
                    book = new XSSFWorkbook(stream);
                }

                foreach (string sheetName in sheetNames)
                {
                    ISheet sheet = book.GetSheet(sheetName);
                    if (sheet == null)
                    {
                        Debug.LogError("[QuestData] sheet not found:" + sheetName);
                        continue;
                    }

                    Entity_Gacya00.Sheet s = new Entity_Gacya00.Sheet();
                    s.name = sheetName;

                    for (int i = 1; i <= sheet.LastRowNum; i++)
                    {
                        IRow  row  = sheet.GetRow(i);
                        ICell cell = null;

                        Entity_Gacya00.Param p = new Entity_Gacya00.Param();

                        cell = row.GetCell(0); p.ID = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(1); p.Type = (cell == null ? "" : cell.StringCellValue);
                        cell = row.GetCell(2); p.Weight = (int)(cell == null ? 0 : cell.NumericCellValue);
                        cell = row.GetCell(3); p.Probability = (cell == null ? 0.0 : cell.NumericCellValue);
                        s.list.Add(p);
                    }
                    data.sheets.Add(s);
                }
            }

            ScriptableObject obj = AssetDatabase.LoadAssetAtPath(exportPath, typeof(ScriptableObject)) as ScriptableObject;
            EditorUtility.SetDirty(obj);
        }
    }