Skip to content

Commit

Permalink
merge new mod kit
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrpg committed Nov 21, 2021
1 parent 2a30b62 commit 2e2c94e
Show file tree
Hide file tree
Showing 20 changed files with 505 additions and 5,581 deletions.
6 changes: 6 additions & 0 deletions .vsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "1.0",
"components": [
"Microsoft.VisualStudio.Workload.ManagedGame"
]
}
Binary file modified Assets/AtomEditor.dll
Binary file not shown.
Binary file modified Assets/AtomGame.dll
Binary file not shown.
27 changes: 27 additions & 0 deletions Assets/Editor/AssetViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ private void ShowWindow()

private string searchText = "";

private string gamedir = "";

private int selectedCategoryIdx = -1;
private string[] categoryNames;

private void OnEnable()
{
gamedir = PlayerPrefs.GetString("GAME_CONTENT_DIR", "");

guiSkin = (GUISkin)Resources.Load("AssetViewer");
if (AssetViewerDB.IsLoaded)
{
Expand Down Expand Up @@ -81,6 +85,28 @@ private void OnGUI()
}

EditorGUILayout.Space();

EditorGUILayout.BeginHorizontal();

EditorGUILayout.LabelField("Game Content Path", gamedir);

if (GUILayout.Button(
new GUIContent("...", "setup game path to StreamingAssets/Content"),
lastSkin.button))
{

gamedir = EditorUtility.OpenFolderPanel("StreamingAssets/Conent path", "", "");
PlayerPrefs.SetString("GAME_CONTENT_DIR", gamedir);

AssetViewerDB.Load();
guiSkin = (GUISkin)Resources.Load("AssetViewer");
GUI.skin = guiSkin;
}

EditorGUILayout.EndHorizontal();

EditorGUILayout.Space();

EditorGUILayout.BeginHorizontal();

if (GUI.Button(EditorGUILayout.GetControlRect(false),
Expand All @@ -93,6 +119,7 @@ private void OnGUI()
}

searchText = EditorGUILayout.TextField(searchText);

if (categoryNames?.Length > 0)
{
selectedCategoryIdx = EditorGUILayout.Popup(selectedCategoryIdx, categoryNames);
Expand Down
61 changes: 42 additions & 19 deletions Assets/Editor/AssetViewerDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public static string GetBundleAssetPath(UnityEngine.Object obj)

public static void Load()
{
if(Application.isPlaying)
if (Application.isPlaying)
{
return;
}

loadedAssets.Clear();
assetCategories.Clear();
AssetBundle.UnloadAllAssetBundles(true);
Expand All @@ -83,30 +84,58 @@ public static void Load()

var categoriesSet = new HashSet<string>();

foreach (string f in Directory.GetFiles(Application.streamingAssetsPath))
LoadBundles(Application.streamingAssetsPath, categoriesSet);

var gdir = PlayerPrefs.GetString("GAME_CONTENT_DIR", "");
LoadBundles(gdir, categoriesSet);

assetCategories.AddRange(categoriesSet.OrderBy(x => x));
EditorUtility.ClearProgressBar();

IsLoaded = true;
OnUpdated?.Invoke();
}

private static void LoadBundles(string path, HashSet<string> categoriesSet)
{
if(path.Length == 0)
{
return;
}

foreach (string f in Directory.GetFiles(path))
{
try
{
if (!Path.HasExtension(f))
if (!Path.HasExtension(f) || Path.GetExtension(f) == ".bundle")
{
AssetBundle bundle = AssetBundle.LoadFromFile(f);
ResourceManager.AddBundle("", bundle);
ResourceManager.AddBundle(bundle.name, bundle);

string[] allAssetNames = bundle.GetAllAssetNames();
int progress = 0;
foreach (var asset in allAssetNames)
{
Object obj = bundle.LoadAsset(asset);
if (obj is ScriptableObject || obj is TextAsset)
if (asset.IndexOf(".asset") >= 0 || asset.IndexOf(".json") >= 0)
{
var category = GetCategoryFromAssetName(asset);
loadedAssets.Add(new LoadedAsset
Object obj = bundle.LoadAsset(asset);
if (obj is ScriptableObject || obj is TextAsset)
{
Asset = obj,
AssetName = asset,
AssetCategory = category,
});
categoriesSet.Add(category);
var category = GetCategoryFromAssetName(asset);

if(asset.Contains("/levels")) // union one category
{
category = "levels";
}

loadedAssets.Add(new LoadedAsset
{
Asset = obj,
AssetName = asset,
AssetCategory = category,
});
categoriesSet.Add(category);
}
}

if (EditorUtility.DisplayCancelableProgressBar("Asset bundle", "Load Asset", (float)progress / allAssetNames.Length))
Expand All @@ -123,12 +152,6 @@ public static void Load()
Debug.Log("Bundle skip");
}
}

assetCategories.AddRange(categoriesSet.OrderBy(x => x));
EditorUtility.ClearProgressBar();

IsLoaded = true;
OnUpdated?.Invoke();
}

private static string GetCategoryFromAssetName(string assetName)
Expand Down
107 changes: 107 additions & 0 deletions Assets/Editor/SceneList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;

using System.Reflection;

public class SceneList : EditorWindow
{
[MenuItem("Game/Scene List")]
static public void Init()
{
GetWindow<SceneList>().Show();
}

public void Awake()
{
Refresh();
}



void Refresh()
{
sceneList.Clear();

foreach (var bundle in ResourceManager.bundles)
{

if (bundle is ResourceManager.UnityBundle unityBundle)
{
//if (unityBundle.modName == "levels")
{
foreach (var prefab in unityBundle.GetAllAssetNames())
{
if (prefab.Contains("/levels/") && prefab.Contains(".prefab"))
{
sceneList.Add(prefab, false);
}
}
}
}
}
}

Dictionary<string, bool> sceneList = new Dictionary<string, bool>();

Vector2 listScrollPos = Vector2.zero;

string filter = "";

public static void NotEditableTransform(GameObject go)
{
for (int i = go.transform.childCount - 1; i >= 0; --i)
{
NotEditableTransform(go.transform.GetChild(i).gameObject);
}

go.hideFlags |= HideFlags.NotEditable;
}


public void OnGUI()
{
if (GUILayout.Button("[Refresh]"))
{
Refresh();
}

EditorGUILayout.BeginHorizontal();
filter = EditorGUILayout.TextField(filter);
if(GUILayout.Button("[X]"))
{
filter = "";
}
EditorGUILayout.EndHorizontal();
//GUILayout.Space(20);

listScrollPos = EditorGUILayout.BeginScrollView(listScrollPos);

string filterLow = filter.ToLower();
foreach (var scene in sceneList)
{
if (filter.Length == 0 || scene.Key.ToLower().Contains(filterLow))
{
if (GUILayout.Button(scene.Key))
{
var playInEditor = GameObject.FindObjectOfType<PlayInEditor>();

if(playInEditor == null)
{
var goPIE = new GameObject("PlayInEditor");
playInEditor = goPIE.AddComponent<PlayInEditor>();
}

playInEditor.spawnScene = scene.Key;
playInEditor.SpawnScene();
}
}
}

EditorGUILayout.EndScrollView();
}
}
//#endif
11 changes: 11 additions & 0 deletions Assets/Editor/SceneList.cs.meta

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

Loading

0 comments on commit 2e2c94e

Please sign in to comment.