From 432d6bcf969cedd3db1ea1b3670af0cae20c24cf Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 12 Dec 2020 02:28:42 +0100 Subject: [PATCH] Use the same (physics) componentts and attempt to use custom material --- GamecraftModdingAPI/Blocks/CustomBlock.cs | 44 ++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/GamecraftModdingAPI/Blocks/CustomBlock.cs b/GamecraftModdingAPI/Blocks/CustomBlock.cs index b960101..7c5d6db 100644 --- a/GamecraftModdingAPI/Blocks/CustomBlock.cs +++ b/GamecraftModdingAPI/Blocks/CustomBlock.cs @@ -3,27 +3,22 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Reflection.Emit; -using System.Text.Formatting; using DataLoader; -using GamecraftModdingAPI.Utility; using GPUInstancer; using HarmonyLib; -using RobocraftX.Blocks.Ghost; +using RobocraftX.Blocks; using RobocraftX.Common; -using RobocraftX.Schedulers; +using RobocraftX.Rendering; using Svelto.DataStructures; -using Svelto.ECS.Extensions.Unity; using Svelto.Tasks; -using Svelto.Tasks.ExtraLean; using Unity.Entities; using Unity.Entities.Conversion; using Unity.Physics; using UnityEngine; using UnityEngine.AddressableAssets; using BoxCollider = UnityEngine.BoxCollider; -using Collider = UnityEngine.Collider; using Material = UnityEngine.Material; +using Object = UnityEngine.Object; namespace GamecraftModdingAPI.Blocks { @@ -122,7 +117,7 @@ namespace GamecraftModdingAPI.Blocks } } - [HarmonyPatch] + /*[HarmonyPatch] public static class RendererPatch { private static Material[] materials; @@ -134,9 +129,16 @@ namespace GamecraftModdingAPI.Blocks //Console.WriteLine("Length: " + gameObject.GetComponentsInChildren().Length); if (materials != null) gameObject.GetComponentsInChildren()[0].sharedMaterials = materials; - ECSGPUIResourceManager.Instance.RegisterRuntimePrefabs( + /*ECSGPUIResourceManager.Instance.RegisterGhostsPrefabsAtRuntime( new[] {new PrefabData {prefabId = prefabID, prefabName = "Assets/Prefabs/Cube.prefab"}}, - new List {gameObject}).Complete(); + new List {gameObject});#1# + GameObject go = Object.Instantiate(gameObject); + go.SetActive(false); + AccessTools.Method("RobocraftX.Rendering.ECSGPUIResourceManager:RegisterNewPrefabAtRuntime") + .Invoke(ECSGPUIResourceManager.Instance, + new object[] {(uint) ((int) prefabID * 2 + 1), gameObject, true}); + //ECSGPUIResourceManager.Instance.RegisterNewPrefabAtRuntime((uint) ((int)prefabID * 2 + 1), gameObject, true); //.isOcclusionCulling = false; + UnityEngine.Object.Destroy(gameObject); GPUInstancerAPI.AddInstancesToPrefabPrototypeAtRuntime(ECSGPUIResourceManager.Instance.prefabManager, gameObject.GetComponent().prefabPrototype, new[] {gameObject}); Console.WriteLine("Registered prefab to instancer"); @@ -144,7 +146,7 @@ namespace GamecraftModdingAPI.Blocks /*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});*/ + new object[] {prefabID, gameObject, MGPatch.data.Item1, MGPatch.data.Item2});#1# /*Console.WriteLine( "Entity: " + ECSPhysicResourceManager.Instance.GetUECSPhysicEntityPrefab(prefabID)); Console.WriteLine("Prefab ID: " + PrefabsID.DBIDMAP[500]); @@ -155,22 +157,23 @@ namespace GamecraftModdingAPI.Blocks Console.WriteLine("Collider type: " + componentData.ColliderPtr->Type); CollisionFilter filter = componentData.Value.Value.Filter; Console.WriteLine("Filter not empty: " + !filter.IsEmpty); - }*/ + }#1# //MGPatch.data.Item1.EntityManager.GetComponentData<>() gameObject.AddComponent(); gameObject.AddComponent(); Console.WriteLine("Registered prefab to physics"); + ECSGPUIResourceManager.Instance.RegisterGhostsPrefabsAtRuntime(); } else if (gameObject.name == "CTR_CommandBlock") materials = gameObject.GetComponentsInChildren()[0].sharedMaterials; } public static MethodBase TargetMethod() - { + {RobocraftX.Common.ECSGPUIResourceManager.RegisterPrefab return AccessTools.Method("RobocraftX.Common.ECSGPUIResourceManager:RegisterPrefab", new[] {typeof(uint), typeof(GameObject)}); } - } + }*/ [HarmonyPatch] public static class RMPatch @@ -180,6 +183,9 @@ namespace GamecraftModdingAPI.Blocks FasterList gos, List prefabData) { + Console.WriteLine("First game object data:\n" + gos[0].GetComponents() + .Select(c => c + " - " + c.name + " " + c.GetType()) + .Aggregate((a, b) => a + "\n" + b)); for (var index = 0; index < prefabData.Count; index++) { var data = prefabData[index]; @@ -200,12 +206,18 @@ namespace GamecraftModdingAPI.Blocks Console.WriteLine("Entity " + current + " has collider: " + entityManager.HasComponent(current)); } + + Console.WriteLine("Adding GPUI prefab"); + ((GPUInstancerPrefabManager) GPUInstancerManager.activeManagerList.Single(gim => + gim is GPUInstancerPrefabManager)) + .AddRuntimeRegisteredPrefab(gos[index].GetComponent()); + Console.WriteLine("Added GPUI prefab"); } } public static MethodBase TargetMethod() { - return AccessTools.Method("RobocraftX.Common.ECSResourceManagerUtility:RelinkEntities", + return AccessTools.Method("RobocraftX.Blocks.ECSResourceManagerUtility:RelinkEntities", new[] { typeof(World),