Example #1
0
    private void Awake()
    {
        popupUITable = ResourceManager.LoadAsset(tablePath, "PopupUITable", resLinkType) as PopupUITable;

        ShowModal(false);
    }
    static bool ReadExcelFile(string excelPath, string prefabPath)
    {
        GameObject stringTableInstance = null;

        lastMsg = string.Empty;

        try
        {
            Excel itemData = ExcelHelper.LoadExcel(excelPath);

            if (itemData == null)
            {
                return(false);
            }

            List <ExcelTable> itemDataTable = itemData.Tables;

            if (itemDataTable.Count > 0)
            {
                for (int i = 0; i < itemDataTable.Count; i++)
                {
                    string           prefabFilePath = prefabPath + "/PopupUITable.asset";
                    ScriptableObject popupUITableSO = (ScriptableObject)AssetDatabase.LoadAssetAtPath(prefabFilePath, typeof(ScriptableObject));
                    if (popupUITableSO == null)
                    {
                        popupUITableSO = ScriptableObject.CreateInstance <PopupUITable>();
                        AssetDatabase.CreateAsset(popupUITableSO, prefabFilePath);
                        popupUITableSO.hideFlags = HideFlags.NotEditable;
                    }

                    PopupUITable popupUIDataTable = (PopupUITable)popupUITableSO;

                    popupUIDataTable.popupUIInfoList.Clear();

                    int indexColumn = 0;
                    int pathColumn  = 0;
                    int tagColumn   = 0;

                    for (int column = 1; column <= itemDataTable[i].NumberOfColumns; column++)
                    {
                        if (Convert.ToString(itemDataTable[i].GetValue(1, column)) == "Index")
                        {
                            indexColumn = column;
                        }
                        if (Convert.ToString(itemDataTable[i].GetValue(1, column)) == "Path")
                        {
                            pathColumn = column;
                        }
                        if (Convert.ToString(itemDataTable[i].GetValue(1, column)) == "Tag")
                        {
                            tagColumn = column;
                        }
                    }

                    for (int row = 2; row <= itemDataTable[i].NumberOfRows; row++)
                    {
                        if (Convert.ToString(itemDataTable[i].GetValue(row, indexColumn)).Equals(""))
                        {
                            continue;
                        }

                        int    index = Convert.ToInt32(itemDataTable[i].GetValue(row, indexColumn));
                        string path  = Convert.ToString(itemDataTable[i].GetValue(row, pathColumn));
                        string tag   = Convert.ToString(itemDataTable[i].GetValue(row, tagColumn));

                        PopupUITable.PopupUIInfo popupUIInfo = new PopupUITable.PopupUIInfo();

                        popupUIInfo.index = index;
                        popupUIInfo.path  = path;
                        popupUIInfo.tag   = tag;

                        popupUIDataTable.popupUIInfoList.Add(popupUIInfo);
                    }

                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    EditorUtility.SetDirty(popupUITableSO);
                }

                lastMsg = "Succeeded import data to prefab file : PopupUITable";
            }
            else
            {
                lastMsg = "Result : Fail. Reason : Data was not found.";
            }

            return(true);
        } catch (Exception e)
        {
            UnityEngine.Debug.Log(e.Message);
            lastMsg = "Result : fail\nMessage : " + e.Message;
            return(false);
        } finally {
            if (stringTableInstance != null)
            {
                DestroyImmediate(stringTableInstance);
            }
        }
    }