Browse Source

Using the console block's material

Progressed a lot
tags/v1.8.0
NorbiPeti 3 years ago
parent
commit
c06ed340a2
1 changed files with 42 additions and 4 deletions
  1. +42
    -4
      GamecraftModdingAPI/Blocks/CustomBlock.cs

+ 42
- 4
GamecraftModdingAPI/Blocks/CustomBlock.cs View File

@@ -13,6 +13,7 @@ using RobocraftX.Common;
using RobocraftX.Schedulers;
using Svelto.Tasks;
using Svelto.Tasks.ExtraLean;
using Unity.Entities;
using UnityEngine;
using UnityEngine.AddressableAssets;

@@ -112,7 +113,7 @@ namespace GamecraftModdingAPI.Blocks
cubeCategory = CubeCategory.ConsoleBlock,
inventoryCategory = InventoryCategory.Logic,
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",
CubeNameKey = "strConsoleBlock",
SelectableFaces = new[] {0, 1, 2, 3, 4, 5},
@@ -131,19 +132,51 @@ namespace GamecraftModdingAPI.Blocks
[HarmonyPatch]
public static class GOPatch
{
private static Material[] materials;
public static void Prefix(uint prefabID, GameObject gameObject)
{
Console.WriteLine("ID: " + prefabID + " - Name: " + gameObject.name);
if (gameObject.name == "Cube")
{
//Console.WriteLine("Length: " + gameObject.GetComponentsInChildren<MeshRenderer>().Length);
if (materials != null)
gameObject.GetComponentsInChildren<MeshRenderer>()[0].sharedMaterials = materials;
ECSGPUIResourceManager.Instance.RegisterRuntimePrefabs(
new[] {new PrefabData {prefabId = 500, prefabName = "Assets/Cube.prefab"}},
new List<GameObject> {gameObject}, 1).Complete();
new[] {new PrefabData {prefabId = 500, prefabName = "Assets/Prefabs/Cube.prefab"}},
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()
{
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;
Console.WriteLine("Loaded custom catalog: " + res.Result.LocatorId);
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);*/
}
}
}

Loading…
Cancel
Save