Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser Preview now supports sub directories #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Assets/AssetBundles.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/AssetBundles/AssetBundles
Binary file not shown.
7 changes: 7 additions & 0 deletions Assets/AssetBundles/AssetBundles.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ManifestFileVersion: 0
CRC: 1256175042
AssetBundleManifest:
AssetBundleInfos:
Info_0:
Name: sample.slo
Dependencies: {}
8 changes: 8 additions & 0 deletions Assets/AssetBundles/AssetBundles.manifest.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/AssetBundles/AssetBundles.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Assets/AssetBundles/sample.slo
Binary file not shown.
35 changes: 35 additions & 0 deletions Assets/AssetBundles/sample.slo.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
ManifestFileVersion: 0
CRC: 4130073870
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: 3eaee4e1f9fde8a2422524ac58d4630c
TypeTreeHash:
serializedVersion: 2
Hash: 1d14c69d2b628eecb355a842fd260673
HashAppended: 0
ClassTypes:
- Class: 1
Script: {instanceID: 0}
- Class: 4
Script: {instanceID: 0}
- Class: 21
Script: {instanceID: 0}
- Class: 23
Script: {instanceID: 0}
- Class: 33
Script: {instanceID: 0}
- Class: 43
Script: {instanceID: 0}
- Class: 48
Script: {instanceID: 0}
- Class: 114
Script: {fileID: 11500000, guid: 5a61987817fbe4b45a87582bcb2be501, type: 3}
- Class: 115
Script: {instanceID: 0}
Assets:
- Assets/Resources/Level Editor Prefabs/Cube.prefab
- Assets/Resources/Level Editor Prefabs/Hole.prefab
- Assets/Resources/Level Editor Prefabs/Flat.prefab
- Assets/Resources/Level Editor Prefabs/Column.prefab
Dependencies: []
8 changes: 8 additions & 0 deletions Assets/AssetBundles/sample.slo.manifest.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/AssetBundles/sample.slo.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
using Newtonsoft.Json.Linq;
using System.Reflection;
using System;
using System.Linq;

namespace GILES.Serialization
{
public class pb_ObjectConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException("Cannot write objects!");
throw new NotImplementedException("Cannot write objects!");
}

public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
JObject o = JObject.Load(reader);
Debug.Log("pb_ObjectContainer Converter:\n" + o.ToString());

var obj = o.GetValue("value").ToObject<dynamic>(serializer);
var obj = o.GetValue("value").ToObject(objectType, serializer);

return ((pb_ObjectWrapper)obj).GetValue();
}
Expand Down
44 changes: 35 additions & 9 deletions Assets/GILES/Code/Classes/pb_ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace GILES
{
Expand All @@ -14,6 +15,9 @@ public class pb_ResourceManager : pb_ScriptableObjectSingleton<pb_ResourceManage
/// A lookup table of available prefabs in the resources folder.
Dictionary<string, GameObject> lookup = new Dictionary<string, GameObject>();

///A layout of all directories and sub directories
List<pb_DirectoryMap> directoryMaps = new List<pb_DirectoryMap>();

/**
* Load all assets listed in pb_Config.Resource_Folder_Paths and populate a lookup table, then
* unload.
Expand All @@ -26,23 +30,23 @@ protected override void OnEnable()
{
GameObject[] prefabs = Resources.LoadAll(resourceFolder).Select(x => x is GameObject ? (GameObject)x : null).Where(y => y != null).ToArray();

#if ASSET_LOADER_DEBUG
#if ASSET_LOADER_DEBUG
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.AppendLine("Loaded Resources: ");
#endif
#endif

// Populate a dictionary to use as a lookup, then unload whatever isn't used
for(int i = 0; i < prefabs.Length; i++)
{
#if ASSET_LOADER_DEBUG
#if ASSET_LOADER_DEBUG
sb.AppendLine(string.Format("{0,-50} : {1}", prefabs[i].name, prefabs[i].GetComponent<pb_MetaDataComponent>().metadata.fileId) );
#endif
#endif
lookup.Add(prefabs[i].GetComponent<pb_MetaDataComponent>().metadata.fileId, prefabs[i]);
}

#if ASSET_LOADER_DEBUG
#if ASSET_LOADER_DEBUG
Debug.Log(sb.ToString());
#endif
#endif

Resources.UnloadUnusedAssets();
}
Expand Down Expand Up @@ -75,7 +79,7 @@ public static GameObject LoadPrefabWithMetadata(pb_MetaData metadata)

switch(metadata.assetType)
{
case AssetType.Resource:
case AssetType.Resource:
{
if(instance.lookup.ContainsKey(metadata.fileId))
{
Expand All @@ -88,12 +92,12 @@ public static GameObject LoadPrefabWithMetadata(pb_MetaData metadata)
}
}

case AssetType.Bundle:
case AssetType.Bundle:
{
return pb_AssetBundles.LoadAsset<GameObject>(metadata.assetBundlePath);
}

default:
default:
{
Debug.LogError("File not found from metadata: " + metadata);
return null;
Expand All @@ -108,6 +112,7 @@ public static IEnumerable<T> LoadAll<T>() where T : UnityEngine.Object
{
List<T> assets = new List<T>();


foreach(string path in pb_Config.Resource_Folder_Paths)
{
assets.AddRange( Resources.LoadAll<T>(path) );
Expand All @@ -119,11 +124,32 @@ public static IEnumerable<T> LoadAll<T>() where T : UnityEngine.Object
{
AssetBundle bundle = pb_AssetBundles.LoadAssetBundleWithName(bundleName);
assets.AddRange( bundle.LoadAllAssets<T>() );
Debug.Log("found bundle: " + assets.Count);
}
catch {}
}

return assets;
}

/**
* Load a specific asset of type T and return. Searches all directories listed in for first appearance of asset.
*/
public static T Load<T>(string name) where T : UnityEngine.Object
{
T asset = null;

foreach(string path in pb_Config.Resource_Folder_Paths)
{
asset = Resources.Load<T> (path + "/" + name);
if (asset != null) {
return asset;
}
}

return null;
}


}
}
94 changes: 94 additions & 0 deletions Assets/GILES/Code/Scripts/GUI/pb_DirectoryMap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Text.RegularExpressions;

public class pb_DirectoryMap {
public string name;
public string path;
public List<pb_DirectoryMap> directories;
public List<string> files;

// Use this for initialization
public pb_DirectoryMap(string Name, string Path){
name = Name;
path = Path;// Should be in the form PathA/PathB/PathC/Name
map(Path);
}

public List<string> getSubDirectoryNames(){
List<string> names = new List<string> ();
foreach (pb_DirectoryMap dir in directories) {
names.Add(dir.name);
}
return names;
}

public string getParentDirectory(){
Regex r = new Regex (".*\\/");
Match m = r.Match(path);
if (m.Success) {
string parDirectory = m.Value;
return parDirectory.Substring (0, parDirectory.Length - 1);
}
return "";
}

public string getRoot(){
Regex r = new Regex(".*?\\/");
Match m = r.Match(path);
return m.Value;
}

public string getPathNoRoot(){
string root = getRoot ();
if (root != "") {
return path.Replace (root, "");
}
return "";
}
public List<string> getFileNames(){
return files;
}

public List<string> getFilesMatch (string pattern){
Regex r = new Regex (pattern);
List<string> matches = new List<string> ();
foreach (string file in files) {
if (r.IsMatch (file)) {
matches.Add (file);
}
}
return matches;
}

public void map (string path) {
directories = new List<pb_DirectoryMap>();
files = new List<string>();
DirectoryInfo info = new DirectoryInfo (Application.dataPath + "/Resources/" + path);
FileInfo[] fileInfo = info.GetFiles ();
foreach (FileInfo fInfo in fileInfo) {
// Decipher between files and folders
if (isFolder (fInfo.Name)) {
string folderName = fInfo.Name.Replace (".meta", "");
directories.Add (new pb_DirectoryMap (folderName, path + '/' + folderName));
} else {
files.Add (fInfo.Name);
}
}
}


bool isFolder(string fName){
int sIndex = fName.LastIndexOf (".meta");
if(sIndex == -1){
return false;
}
if ((fName.Substring (0, sIndex).IndexOf ('.')) != -1) {
return false;
}
return true;
}

}
12 changes: 12 additions & 0 deletions Assets/GILES/Code/Scripts/GUI/pb_DirectoryMap.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading