Browse Source

Use the same (physics) componentts and attempt to use custom material

tags/v1.8.0
NorbiPeti 4 years ago
parent
commit
432d6bcf96
1 changed files with 28 additions and 16 deletions
  1. +28
    -16
      GamecraftModdingAPI/Blocks/CustomBlock.cs

+ 28
- 16
GamecraftModdingAPI/Blocks/CustomBlock.cs View File

@@ -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<MeshRenderer>().Length);
if (materials != null)
gameObject.GetComponentsInChildren<MeshRenderer>()[0].sharedMaterials = materials;
ECSGPUIResourceManager.Instance.RegisterRuntimePrefabs(
/*ECSGPUIResourceManager.Instance.RegisterGhostsPrefabsAtRuntime(
new[] {new PrefabData {prefabId = prefabID, prefabName = "Assets/Prefabs/Cube.prefab"}},
new List<GameObject> {gameObject}).Complete();
new List<GameObject> {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<GPUInstancerPrefab>().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<BoxCollider>();
gameObject.AddComponent<Transform>();
Console.WriteLine("Registered prefab to physics");
ECSGPUIResourceManager.Instance.RegisterGhostsPrefabsAtRuntime();
}
else if (gameObject.name == "CTR_CommandBlock")
materials = gameObject.GetComponentsInChildren<MeshRenderer>()[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<GameObject> gos,
List<PrefabData> prefabData)
{
Console.WriteLine("First game object data:\n" + gos[0].GetComponents<Component>()
.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<PhysicsCollider>(current));
}

Console.WriteLine("Adding GPUI prefab");
((GPUInstancerPrefabManager) GPUInstancerManager.activeManagerList.Single(gim =>
gim is GPUInstancerPrefabManager))
.AddRuntimeRegisteredPrefab(gos[index].GetComponent<GPUInstancerPrefab>());
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),


Loading…
Cancel
Save