-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using UnityEngine; | ||
#if UNITY_EDITOR | ||
using UnityEditor; | ||
#endif | ||
|
||
namespace VirtueSky.Misc | ||
{ | ||
#if UNITY_EDITOR | ||
public static class GetFile | ||
{ | ||
public static T GetConfigFromFolder<T>(string path) where T : ScriptableObject | ||
{ | ||
var fileEntries = Directory.GetFiles(path, ".", SearchOption.AllDirectories); | ||
|
||
foreach (var fileEntry in fileEntries) | ||
if (fileEntry.EndsWith(".asset")) | ||
{ | ||
var item = | ||
AssetDatabase.LoadAssetAtPath<T>(fileEntry.Replace("\\", "/")); | ||
if (item) | ||
return item; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static List<T> GetConfigsFromFolder<T>(string path) where T : ScriptableObject | ||
{ | ||
var fileEntries = Directory.GetFiles(path, ".", SearchOption.AllDirectories); | ||
var result = new List<T>(); | ||
foreach (var fileEntry in fileEntries) | ||
if (fileEntry.EndsWith(".asset")) | ||
{ | ||
var item = AssetDatabase.LoadAssetAtPath<T>(fileEntry.Replace("\\", "/")); | ||
|
||
if (item) | ||
result.Add(item); | ||
} | ||
|
||
if (result.Count > 0) | ||
return result; | ||
|
||
return null; | ||
} | ||
|
||
public static T GetConfigFromResource<T>(string path) where T : ScriptableObject | ||
{ | ||
T config = | ||
Resources.Load<T>(path); | ||
if (config != null) | ||
{ | ||
return config; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static T GetPrefabFromFolder<T>(string path) where T : MonoBehaviour | ||
{ | ||
var fileEntries = Directory.GetFiles(path, ".", SearchOption.AllDirectories); | ||
|
||
foreach (var fileEntry in fileEntries) | ||
if (fileEntry.EndsWith(".prefab")) | ||
{ | ||
var item = | ||
AssetDatabase.LoadAssetAtPath<T>(fileEntry.Replace("\\", "/")); | ||
if (item) | ||
return item; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static List<T> GetPrefabsFromFolder<T>(string path) where T : MonoBehaviour | ||
{ | ||
var fileEntries = Directory.GetFiles(path, ".", SearchOption.AllDirectories); | ||
var result = new List<T>(); | ||
foreach (var fileEntry in fileEntries) | ||
if (fileEntry.EndsWith(".prefab")) | ||
{ | ||
var item = AssetDatabase.LoadAssetAtPath<T>(fileEntry.Replace("\\", "/")); | ||
|
||
if (item) | ||
result.Add(item); | ||
} | ||
|
||
if (result.Count > 0) | ||
return result; | ||
|
||
return null; | ||
} | ||
} | ||
#endif | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.