Magically import images and more into Gamecraft as blocks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

46 lines
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using Unity.Mathematics;
  5. using GamecraftModdingAPI.Blocks;
  6. namespace Pixi.Common
  7. {
  8. public static class ConversionUtility
  9. {
  10. private static Dictionary<string, BlockIDs> blockEnumMap = null;
  11. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  12. private static void loadBlockEnumMap()
  13. {
  14. blockEnumMap = new Dictionary<string, BlockIDs>();
  15. foreach(BlockIDs e in Enum.GetValues(typeof(BlockIDs)))
  16. {
  17. blockEnumMap[e.ToString()] = e;
  18. }
  19. }
  20. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  21. public static BlockIDs BlockIDsToEnum(string name)
  22. {
  23. if (blockEnumMap == null) loadBlockEnumMap();
  24. if (blockEnumMap.ContainsKey(name)) return blockEnumMap[name];
  25. return BlockIDs.Invalid;
  26. }
  27. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  28. public static float3 FloatArrayToFloat3(float[] vec)
  29. {
  30. if (vec.Length < 3) return float3.zero;
  31. return new float3(vec[0], vec[1], vec[2]);
  32. }
  33. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  34. public static float[] Float3ToFloatArray(float3 vec)
  35. {
  36. return new float[3] {vec.x, vec.y, vec.z};
  37. }
  38. }
  39. }