コード例 #1
0
        //create clone
        public WindowCSVStruct(WindowCSVStruct itemToClone)
        {
            StructName = itemToClone.StructName;

            LinkCSV = itemToClone.LinkCSV;

            IndexPath   = itemToClone.IndexPath;
            OptionsPath = itemToClone.OptionsPath;

            PathDownload = itemToClone.PathDownload;
            FolderName   = itemToClone.FolderName;
            FileName     = itemToClone.FileName;
        }
コード例 #2
0
        /// <summary>
        /// Load File from folder
        /// </summary>
        public static string LoadFile(WindowCSVStruct structCSV)
        {
            //if there is no file, return null
            if (File.Exists(structCSV.PathFile) == false)
            {
                Debug.Log("File not found: " + structCSV.PathFile);
                return(null);
            }

            //create stream at file position
            StreamReader reader = new StreamReader(structCSV.PathFile);

            //then load from file position as value, and close stream
            string value = reader.ReadToEnd();

            reader.Close();

            return(value);
        }
コード例 #3
0
        void SelectItemFromList()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space();

            //create options with name of every item in the list
            string[] optionsList = new string[data.StructCSV.Count];
            for (int i = 0; i < data.StructCSV.Count; i++)
            {
                //check every next element in the list
                for (int j = i + 1; j < data.StructCSV.Count; j++)
                {
                    //if same name already in the list, change it to not have duplicates (because EditorGUILayout.Popup doesn't show duplicates - and now name is used also in LoadFile(string name))
                    while (data.StructCSV[i].StructName.Equals(data.StructCSV[j].StructName))
                    {
                        data.StructCSV[i].StructName += "#";
                    }
                }

                optionsList[i] = data.StructCSV[i].StructName;
            }

            //show every item
            data.IndexStruct = EditorGUILayout.Popup(data.IndexStruct, optionsList);

            EditorGUILayout.Space();

            //set name link
            data.StructCSV[data.IndexStruct].StructName = EditorGUILayout.TextField(data.StructCSV[data.IndexStruct].StructName, EditorStyles.textField);

            EditorGUILayout.Space();

            //create new item at index
            if (GUILayout.Button("Add Item"))
            {
                //clone item
                WindowCSVStruct newItem = new WindowCSVStruct(data.StructCSV[data.IndexStruct]);

                //while there is an item with same name, change it
                while (ArrayUtility.Contains(optionsList, newItem.StructName))
                {
                    newItem.StructName += "#";
                }

                //add item to the list and move index to the item created
                data.StructCSV.Insert(data.IndexStruct + 1, newItem);
                data.IndexStruct += 1;

                return;
            }

            //remove item at index
            if (GUILayout.Button("Remove Item"))
            {
                //only if there are others (always keep 1 in the list)
                if (data.StructCSV.Count > 1)
                {
                    //remove from the list
                    data.StructCSV.RemoveAt(data.IndexStruct);

                    //if index is not at 0, move to previous item in the list
                    if (data.IndexStruct > 0)
                    {
                        data.IndexStruct -= 1;
                    }

                    return;
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }