Ejemplo n.º 1
0
        //public static void ReadAsset<T>(T asset) where T : ScriptableObject, IDataAsset
        //{
        //    asset.Read();
        //    string folderPath = Helper.ImportSetting.DataAssetRelativePath;
        //    Helper.CreateDirectoryIfNotExist(folderPath);

        //    AssetDatabase.CreateAsset(asset, folderPath + "/TestEnumDataTable.asset");
        //    AssetDatabase.SaveAssets();

        //    //EditorUtility.FocusProjectWindow();
        //    //Selection.activeObject = asset;
        //}

        public static void ReadAsset(UnityEngine.Object asset)
        {
            var dataAsset = asset as IDataAsset;

            dataAsset.Read();
            string folderPath = Helper.ImportSetting.DataAssetRelativePathToProject;

            Helper.CreateDirectoryIfNotExist(folderPath);

            string assetName = CSVDataAssetAttribute.GetDataTableName(asset);

            if (assetName == null)
            {
                throw new CSVParseException("Cannot find name for asset: " + asset.GetType().Name);
            }

            AssetDatabase.CreateAsset(asset, folderPath + "/" + assetName + ".asset");
            AssetDatabase.SaveAssets();

            //EditorUtility.FocusProjectWindow();
            //Selection.activeObject = asset;
        }
Ejemplo n.º 2
0
        public void ReadFromDataAsset()
        {
            string dataAssetPath = CSVDataAssetAttribute.GetDataTableName(typeof(T));

            if (Helper.ImportSetting.DataAssetRelativePathToProject.Trim() != "")
            {
                dataAssetPath = Helper.ImportSetting.DataAssetRelativePathToProject + "/" + dataAssetPath;
            }

            dataAssetPath = Helper.GetRelativePathToResourcesFolder(dataAssetPath);

            var           obj       = Resources.Load(dataAssetPath);
            DataAsset <T> dataAsset = obj as DataAsset <T>;

            data = new Dictionary <string, T>();
            for (int i = 0; i < dataAsset.data.Length; i++)
            {
                var entry = dataAsset.data[i];
                var key   = entry.internal_dataEntryID;

                data.Add(key, entry);
            }
            dataCount = data.Keys.Count;
        }