Using the console block's material

Progressed a lot
This commit is contained in:
Norbi Peti 2020-09-17 23:08:26 +02:00
parent f295f712b6
commit c06ed340a2

View file

@ -13,6 +13,7 @@ using RobocraftX.Common;
using RobocraftX.Schedulers; using RobocraftX.Schedulers;
using Svelto.Tasks; using Svelto.Tasks;
using Svelto.Tasks.ExtraLean; using Svelto.Tasks.ExtraLean;
using Unity.Entities;
using UnityEngine; using UnityEngine;
using UnityEngine.AddressableAssets; using UnityEngine.AddressableAssets;
@ -112,7 +113,7 @@ namespace GamecraftModdingAPI.Blocks
cubeCategory = CubeCategory.ConsoleBlock, cubeCategory = CubeCategory.ConsoleBlock,
inventoryCategory = InventoryCategory.Logic, inventoryCategory = InventoryCategory.Logic,
ID = 500, ID = 500,
Path = "Assets/Cube.prefab", //Index out of range exception: Asset failed to load (wrong path) Path = "Assets/Prefabs/Cube.prefab", //Index out of range exception: Asset failed to load (wrong path)
SpriteName = "CTR_CommandBlock", SpriteName = "CTR_CommandBlock",
CubeNameKey = "strConsoleBlock", CubeNameKey = "strConsoleBlock",
SelectableFaces = new[] {0, 1, 2, 3, 4, 5}, SelectableFaces = new[] {0, 1, 2, 3, 4, 5},
@ -131,19 +132,51 @@ namespace GamecraftModdingAPI.Blocks
[HarmonyPatch] [HarmonyPatch]
public static class GOPatch public static class GOPatch
{ {
private static Material[] materials;
public static void Prefix(uint prefabID, GameObject gameObject) public static void Prefix(uint prefabID, GameObject gameObject)
{ {
Console.WriteLine("ID: " + prefabID + " - Name: " + gameObject.name); Console.WriteLine("ID: " + prefabID + " - Name: " + gameObject.name);
if (gameObject.name == "Cube") if (gameObject.name == "Cube")
{
//Console.WriteLine("Length: " + gameObject.GetComponentsInChildren<MeshRenderer>().Length);
if (materials != null)
gameObject.GetComponentsInChildren<MeshRenderer>()[0].sharedMaterials = materials;
ECSGPUIResourceManager.Instance.RegisterRuntimePrefabs( ECSGPUIResourceManager.Instance.RegisterRuntimePrefabs(
new[] {new PrefabData {prefabId = 500, prefabName = "Assets/Cube.prefab"}}, new[] {new PrefabData {prefabId = 500, prefabName = "Assets/Prefabs/Cube.prefab"}},
new List<GameObject> {gameObject}, 1).Complete(); new List<GameObject> {gameObject}).Complete();
GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(ECSGPUIResourceManager.Instance.prefabManager,
gameObject.GetComponent<GPUInstancerPrefab>().prefabPrototype, new[] {gameObject});
Console.WriteLine("Registered prefab to instancer");
var register = AccessTools.Method("RobocraftX.Common.ECSPhysicResourceManager:RegisterPrefab",
new[] {typeof(uint), typeof(GameObject), typeof(World), typeof(BlobAssetStore)});
register.Invoke(ECSPhysicResourceManager.Instance,
new object[] {prefabID, gameObject, MGPatch.data.Item1, MGPatch.data.Item2});
Console.WriteLine("Registered prefab to physics");
}
else if (gameObject.name == "CTR_CommandBlock")
materials = gameObject.GetComponentsInChildren<MeshRenderer>()[0].sharedMaterials;
} }
public static MethodBase TargetMethod() public static MethodBase TargetMethod()
{ {
return AccessTools.Method("RobocraftX.Common.ECSGPUIResourceManager:RegisterPrefab", return AccessTools.Method("RobocraftX.Common.ECSGPUIResourceManager:RegisterPrefab",
new[] {typeof(uint), typeof(GameObject), typeof(uint)}); new[] {typeof(uint), typeof(GameObject)});
}
}
[HarmonyPatch]
public static class MGPatch
{
internal static (World, BlobAssetStore) data;
public static void Prefix(World physicsWorld, BlobAssetStore blobStore)
{
data = (physicsWorld, blobStore);
}
public static MethodBase TargetMethod()
{
return AccessTools.Method("RobocraftX.CR.MainGame.MainGameCompositionRoot:Init");
} }
} }
@ -154,6 +187,11 @@ namespace GamecraftModdingAPI.Blocks
while (!res.IsDone) yield return Yield.It; while (!res.IsDone) yield return Yield.It;
Console.WriteLine("Loaded custom catalog: " + res.Result.LocatorId); Console.WriteLine("Loaded custom catalog: " + res.Result.LocatorId);
Addressables.AddResourceLocator(res.Result); Addressables.AddResourceLocator(res.Result);
/*Console.WriteLine("Loading Cube asset...");
var loadTask = Addressables.LoadAssetAsync<GameObject>("Assets/Cube.prefab");
while (!loadTask.IsDone) yield return Yield.It;
Console.WriteLine("Exception: "+loadTask.OperationException);
Console.WriteLine("Result: " + loadTask.Result.name);*/
} }
} }
} }