Exemple #1
0
 /// <summary>
 /// Tries the get table from the folder.
 /// If table doesn't exist, return null.
 /// </summary>
 /// <param name="_table">Table.</param>
 public void TryGetTable(out GS.Resource.ResourceTable _table)
 {
     if (tables.Length > 0)
     {
         _table = tables[0];
         return;
     }
     _table = null;
 }
Exemple #2
0
 /// <summary>
 /// Gets the table with the name.
 /// </summary>
 /// <param name="_name">Name.</param>
 /// <param name="_table">Table.</param>
 public void GetTableWithName(string _name, out GS.Resource.ResourceTable _table)
 {
     GS.Resource.ResourceTable table = null;
     for (int i = 0; i < tables.Length; i++)
     {
         if (tables[i].name.Equals(_name))
         {
             table = tables[i];
         }
     }
     _table = table;
 }
Exemple #3
0
        private void CopyAssets()
        {
            // TODO ResourceFolderEditor Copy assets!
            var _class = target as GS.Resource.ResourceFolder;

            // Create new resource type using same ResourceFolder in same resource path.
            GS.Resource.ResourceFolder folder = (GS.Resource.ResourceFolder)ScriptableObject.CreateInstance(typeof(GS.Resource.ResourceFolder));
            folder.path        = _class.path;
            folder.resourceKey = _class.resourceKey;
            folder.resource    = _resource;

            // Create possibly missing directory.
            CreateDirectory(_resource);

            List <GS.Resource.ResourceTable> _tables = new List <GS.Resource.ResourceTable>();

            foreach (GS.Resource.ResourceTable _table in _class.tables)
            {
                // Create asset and set values
                GS.Resource.ResourceTable asset = (GS.Resource.ResourceTable)ScriptableObject.CreateInstance(_table.GetType());
                asset.name         = _table.name;
                asset.updateEvents = _table.updateEvents;
                _tables.Add(asset);

                // Create ResourceTable asset
                AssetDatabase.CreateAsset(asset, string.Format(
                                              "Assets/Resources/{0}/{1}/{2}.asset",
                                              folder.path, folder.resource,
                                              // Get old ResourceTable location, split path and cut extension off it.
                                              AssetDatabase.GetAssetPath(_table).Split('/').Last().Split('.')[0]
                                              ));
            }
            folder.tables = _tables.ToArray();

            // Get old ResourceFolder location and cut extension from it.
            string folderLocation = AssetDatabase.GetAssetPath(_class).Split('.')[0];
            int    folderCount    = AssetDatabase.FindAssets(
                string.Format("{0} t:GS.Resource.ResourceFolder", folderLocation.Split('/').Last()),
                new[] { folderLocation.Remove(folderLocation.LastIndexOfAny("/".ToCharArray())) }).Length;

            // Create ResourceFolder asset
            AssetDatabase.CreateAsset(folder, string.Format(
                                          "{0}{1}.asset", folderLocation, folderCount - 1));

            // Finalize all created assets
            AssetDatabase.SaveAssets();
            _tables.Clear();
        }
Exemple #4
0
        private void AddAsset(string assetName)
        {
            var _class = target as GS.Resource.ResourceFolder;

            // If directory is missing, create it.
            CreateDirectory(_class.resource);
            FindAssetTypes();

            // Create asset and set values
            GS.Resource.ResourceTable asset = (GS.Resource.ResourceTable)
                                              ScriptableObject.CreateInstance(assetTypes[selectedAssetType]);

            string filePath = string.Format(
                "Assets/Resources/{0}/{1}/{2}.asset",
                serializedObject.FindProperty("path").stringValue,
                serializedObject.FindProperty("resource").stringValue,
                assetName
                );

            AssetDatabase.CreateAsset(asset, filePath);
            asset.name         = "New ResourceTable";
            asset.updateEvents = new string[] { _class.resourceKey };
            AssetDatabase.SaveAssets();

            // Find the edited property
            SerializedProperty prop = serializedObject.FindProperty("tables");

            // Add new item to array.
            int x = prop.arraySize;

            prop.InsertArrayElementAtIndex(x);
            prop.GetArrayElementAtIndex(x).objectReferenceValue = asset;
            serializedObject.ApplyModifiedProperties();

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