コード例 #1
0
ファイル: ItemList.cs プロジェクト: angusmf/ItemListUtil
        public void OnEnable()
        {
            MiscUtils.RemoveNull(Items);

            //initialize ID column headings
            if (Headings != null && Headings.Count > 0)
            {
                if (UPC_Column == null || UPC_Column.Name.value != UPC_ColumnName ||
                    ALU_Column == null || ALU_Column.Name.value != ALU_ColumnName)
                {
                    foreach (ColumnHeading heading in Headings)
                    {
                        if (heading == null || heading.Name == null)
                        {
                            continue;
                        }
                        else
                        {
                            if (heading.Name.value == UPC_ColumnName)
                            {
                                UPC_Column = heading;
                                EditorUtility.SetDirty(this);
                                AssetDatabase.SaveAssets();
                                AssetDatabase.Refresh();
                            }
                            if (heading.Name.value == ALU_ColumnName)
                            {
                                ALU_Column = heading;
                                EditorUtility.SetDirty(this);
                                AssetDatabase.SaveAssets();
                                AssetDatabase.Refresh();
                            }
                        }
                    }
                }
            }

            //initialize our lookups
            if (Items != null && Items.Count > 0)
            {
                if (lookupUPC.Count != Items.Count || lookupALU.Count != Items.Count)
                {
                    lookupUPC.Clear();
                    lookupALU.Clear();
                    lookupALUIndex.Clear();

                    int len = Items.Count;

                    for (int i = 0; i < len; i++)
                    {
                        if (!string.IsNullOrEmpty(Items[i].values[UPC_Column.Index.value]) && lookupUPC.ContainsKey(Items[i].values[UPC_Column.Index.value]))
                        {
                            Debug.LogError(string.Format("Can't add item {0} because UPC {1} already exists.", Items[i].values[ALU_Column.Index.value], Items[i].values[UPC_Column.Index.value]));
                            continue;
                        }
                        if (!string.IsNullOrEmpty(Items[i].values[UPC_Column.Index.value]))
                        {
                            lookupUPC.Add(Items[i].values[UPC_Column.Index.value], Items[i]);
                        }
                        lookupALU.Add(Items[i].values[ALU_Column.Index.value], Items[i]);
                        lookupALUIndex.Add(Items[i].values[ALU_Column.Index.value], i);
                    }
                }
            }
            else
            {
                lookupUPC.Clear();
                lookupALU.Clear();
                lookupALUIndex.Clear();
            }
        }
コード例 #2
0
        private void GetColumnHeadings(ItemList list)
        {
            if (list.Headings.Count == 0 && list.listName != string.Empty)
            {
                if (GUILayout.Button("Get Column Headings"))
                {
                    string sheetPath = UtilScript.GetPath("InventoryItem");

                    if (!string.IsNullOrEmpty(sheetPath))
                    {
                        if (!File.Exists(sheetPath))
                        {
                            Debug.LogWarning(string.Format("Sheet Path {0} does not exist.", sheetPath));
                            return;
                        }

                        string guid = AssetDatabase.CreateFolder("Assets", list.listName);
                        string path = AssetDatabase.GUIDToAssetPath(guid);
                        guid = AssetDatabase.CreateFolder(path, "values");
                        string subPath = AssetDatabase.GUIDToAssetPath(guid);

                        ExcelQuery q = new ExcelQuery(sheetPath);
                        q.GetNewSheet(q.GetSheetNames()[0]);
                        string   err    = string.Empty;
                        string[] titles = q.GetTitle(0, ref err);
                        if (err != string.Empty)
                        {
                            Debug.LogError(string.Format("Could not read sheet titles from first sheet {0} of {1}", q.GetSheetNames()[0], sheetPath));
                            return;
                        }
                        else
                        {
                            int len = titles.Length;
                            for (int i = 0; i < len; i++)
                            {
                                StringDataValue name = Instantiate(list.NameValuePrefab);
                                name.name = "HeadingName_" + titles[i];
                                AssetDatabase.CreateAsset(name, subPath + "/" + name.name + ".asset");
                                IntDataValue index = Instantiate(list.IndexValuePrefab);
                                index.name = "HeadingIndex_" + titles[i];
                                AssetDatabase.CreateAsset(index, subPath + "/" + index.name + ".asset");

                                ColumnHeading newHeading = Instantiate(list.ColumnHeadingPrefab);
                                newHeading.name = "ColumnHeading_" + titles[i];
                                AssetDatabase.CreateAsset(newHeading, path + "/" + newHeading.name + ".asset");

                                newHeading.Name  = name;
                                newHeading.Index = index;

                                newHeading.Name.value  = titles[i];
                                newHeading.Index.value = i;

                                EditorUtility.SetDirty(newHeading);
                                EditorUtility.SetDirty(name);
                                EditorUtility.SetDirty(index);

                                list.Headings.Add(newHeading);
                            }
                        }
                    }
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
                }
            }
        }