MB3_MultiMeshBakerEditor.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //----------------------------------------------
  2. // MeshBaker
  3. // Copyright © 2011-2012 Ian Deane
  4. //----------------------------------------------
  5. using UnityEngine;
  6. using System.Collections;
  7. using System.IO;
  8. using System;
  9. using System.Collections.Specialized;
  10. using System.Collections.Generic;
  11. using System.Text.RegularExpressions;
  12. using UnityEditor;
  13. using DigitalOpus.MB.Core;
  14. [CustomEditor(typeof(MB3_MultiMeshBaker))]
  15. public class MB3_MultiMeshBakerEditor : Editor {
  16. MB3_MeshBakerEditorInternal mbe = new MB3_MeshBakerEditorInternal();
  17. [MenuItem(@"GameObject/Create Other/Mesh Baker/TextureBaker and MultiMeshBaker",false,100)]
  18. public static GameObject CreateNewMeshBaker(){
  19. MB3_TextureBaker[] mbs = (MB3_TextureBaker[]) GameObject.FindObjectsOfType(typeof(MB3_TextureBaker));
  20. Regex regex = new Regex(@"\((\d+)\)$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
  21. int largest = 0;
  22. try{
  23. for (int i = 0; i < mbs.Length; i++){
  24. Match match = regex.Match(mbs[i].name);
  25. if (match.Success){
  26. int val = Convert.ToInt32(match.Groups[1].Value);
  27. if (val >= largest)
  28. largest = val + 1;
  29. }
  30. }
  31. } catch(Exception e){
  32. if (e == null) e = null; //Do nothing supress compiler warning
  33. }
  34. GameObject nmb = new GameObject("TextureBaker (" + largest + ")");
  35. nmb.transform.position = Vector3.zero;
  36. MB3_TextureBaker tb = nmb.AddComponent<MB3_TextureBaker>();
  37. tb.packingAlgorithm = MB2_PackingAlgorithmEnum.MeshBakerTexturePacker;
  38. nmb.AddComponent<MB3_MeshBakerGrouper>();
  39. GameObject meshBaker = new GameObject("MultiMeshBaker");
  40. meshBaker.AddComponent<MB3_MultiMeshBaker>();
  41. meshBaker.transform.parent = nmb.transform;
  42. return nmb;
  43. }
  44. void OnEnable()
  45. {
  46. mbe.OnEnable(serializedObject);
  47. }
  48. void OnDisable()
  49. {
  50. mbe.OnDisable();
  51. }
  52. public override void OnInspectorGUI(){
  53. mbe.OnInspectorGUI(serializedObject, (MB3_MeshBakerCommon) target, typeof(MB3_MeshBakerEditorWindow));
  54. }
  55. }