MyPlugin.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using UnityEngine;
  3. using System.Runtime.InteropServices;
  4. using GPUECSAnimationBaker.Engine.AnimatorSystem;
  5. public class MyPlugin : MonoBehaviour
  6. {
  7. public Material material;
  8. public Mesh mesh;
  9. const int numInstances = 10;
  10. struct MyInstanceData
  11. {
  12. public Matrix4x4 objectToWorld;
  13. public float myOtherData;
  14. public uint renderingLayerMask;
  15. };
  16. // void Update()
  17. // {
  18. // RenderParams rp = new RenderParams(material);
  19. // MyInstanceData[] instData = new MyInstanceData[numInstances];
  20. // for(int i=0; i<numInstances; ++i)
  21. // {
  22. // instData[i].objectToWorld = Matrix4x4.Translate(new Vector3(-4.5f+i, 0.0f, 5.0f));
  23. // instData[i].renderingLayerMask = (i & 1) == 0 ? 1u : 2u;
  24. // }
  25. // Graphics.RenderMeshInstanced(rp, mesh, 0, instData);
  26. // }
  27. void Update()
  28. {
  29. RenderParams rp = new RenderParams(material);
  30. Matrix4x4[] instData = new Matrix4x4[numInstances];
  31. for(int i=0; i<numInstances; ++i)
  32. instData[i] = Matrix4x4.Translate(new Vector3(-4.5f+i, 0.0f, 5.0f));
  33. Graphics.RenderMeshInstanced(rp, mesh, 0, instData);
  34. }
  35. // public GPUAnimtion GPUAnimtion;
  36. //
  37. // public int index;
  38. //
  39. // private void Start()
  40. // {
  41. // GPUAnimtion = new GPUAnimtion();
  42. // GpuEcsAnimatorBehaviour gpuEcsAnimatorBehaviour= gameObject.transform.GetComponentInChildren<GpuEcsAnimatorBehaviour>();
  43. // GPUAnimtion.Init(gpuEcsAnimatorBehaviour);
  44. // }
  45. //
  46. // [ContextMenu("dsada")]
  47. // public void TestSet()
  48. // {
  49. // GPUAnimtion.SetAnimtionIndex(index);
  50. // }
  51. //
  52. // private void Update()
  53. // {
  54. // GPUAnimtion.Update();
  55. // // Graphics.DrawMeshInstanced();
  56. // }
  57. // // 声明C++函数
  58. // [DllImport("ThreadTool")]
  59. // private static extern int Add(int a, int b);
  60. //
  61. // [DllImport("ThreadTool")]
  62. // private static extern void CallCSharpFunction(Callback callback);
  63. //
  64. // // 定义回调委托
  65. // public delegate int Callback(int value);
  66. //
  67. // // C#回调函数
  68. // private int MyCallback(int value)
  69. // {
  70. // Debug.Log("C# received value from C++: " + value);
  71. // return value * 2;
  72. // }
  73. //
  74. // void Start()
  75. // {
  76. // // 调用C++函数
  77. // int result = Add(5, 3);
  78. // Debug.Log("Result from C++: " + result); // 输出: Result from C++: 8
  79. //
  80. // // 注册C#回调函数并调用C++函数
  81. // CallCSharpFunction(MyCallback);
  82. // }
  83. }