MegaFiersWindow.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. 
  2. using UnityEditor;
  3. using UnityEngine;
  4. // TODO: Select axis for shapes
  5. // TODO: Add new spline to shape
  6. // TODO: Button to recalc lengths
  7. // TEST: Build a simple scene in max then have a road, barrier, fence etc
  8. // Import of simple text file for path
  9. public class MegaFiersWindow : EditorWindow
  10. {
  11. static bool showcommon;
  12. //string name = "Shape";
  13. //static MegaAxis axis = MegaAxis.Y;
  14. //static bool drawknots = true;
  15. //static bool drawhandles = true;
  16. //static float stepdist = 0.1f;
  17. //static float knotsize = 0.05f;
  18. static Color col1 = Color.yellow;
  19. static Color col2 = Color.green;
  20. static MegaNormalMethod NormalMethod = MegaNormalMethod.Mega;
  21. // Add menu named "My Window" to the Window menu
  22. [MenuItem("Component/MegaFiers")]
  23. static void Init()
  24. {
  25. // Get existing open window or if none, make a new one:
  26. //MegaShapeWindow window = (MegaShapeWindow)EditorWindow.GetWindow(typeof(MegaShapeWindow));
  27. EditorWindow.GetWindow(typeof(MegaFiersWindow), false, "MegaFiers");
  28. }
  29. #if false
  30. public class Buttons
  31. {
  32. public Buttons() {}
  33. public Buttons(string _but, System.Type _classname)
  34. {
  35. Create(null, _but, _classname);
  36. }
  37. public Buttons(string _tooltip, string _but, System.Type _classname)
  38. {
  39. Create(_tooltip, _but, _classname);
  40. }
  41. public void Create(string _tooltip, string _but, System.Type _classname)
  42. {
  43. classname = _classname;
  44. Texture image = (Texture)AssetDatabase.LoadAssetAtPath("Assets/Mega-Fiers/Editor/Icons/" + _but, typeof(Texture));
  45. //Texture image = (Texture)AssetDatabase.LoadAssetAtPath("Assets/Mega-Fiers/Editor/Icons/" + "mybendicon.png", typeof(Texture));
  46. if ( image == null )
  47. Debug.Log("Didnt load icon " + _but);
  48. else
  49. content = new GUIContent(image, classname.ToString() + " a Mesh");
  50. }
  51. public System.Type classname;
  52. public GUIContent content;
  53. }
  54. static Buttons[] buts = new Buttons[] {
  55. new Buttons("Bend a Mesh", "mybendicon.png", typeof(MegaBend)),
  56. new Buttons("Bubble a Mesh", "mybubbleicon.png", typeof(MegaBubble)),
  57. new Buttons("Bulge a Mesh", "mybendicon.png", typeof(MegaBulge)),
  58. new Buttons("mybendicon.png", typeof(MegaCrumple)),
  59. new Buttons("mybendicon.png", typeof(MegaCurveDeform)),
  60. new Buttons("mybendicon.png", typeof(MegaCylindrify)),
  61. new Buttons("mybendicon.png", typeof(MegaDisplace)),
  62. new Buttons("mybendicon.png", typeof(MegaFFD2x2x2)),
  63. new Buttons("mybendicon.png", typeof(MegaFFD3x3x3)),
  64. new Buttons("mybendicon.png", typeof(MegaFFD4x4x4)),
  65. new Buttons("myhumpicon.png", typeof(MegaHump)),
  66. new Buttons("mymelticon.png", typeof(MegaMelt)),
  67. new Buttons("mynoiseicon.png", typeof(MegaNoise)),
  68. new Buttons("mybendicon.png", typeof(MegaPageFlip)),
  69. new Buttons("mybendicon.png", typeof(MegaPaint)),
  70. new Buttons("mybendicon.png", typeof(MegaPathDeform)),
  71. new Buttons("mybendicon.png", typeof(MegaPivotAdjust)),
  72. new Buttons("mybendicon.png", typeof(MegaPointCache)),
  73. new Buttons("mypushicon.png", typeof(MegaPush)),
  74. new Buttons("mybendicon.png", typeof(MegaRadialSkew)),
  75. new Buttons("mybendicon.png", typeof(MegaRipple)),
  76. new Buttons("mybendicon.png", typeof(MegaRopeDeform)),
  77. new Buttons("mybendicon.png", typeof(MegaRubber)),
  78. new Buttons("mybendicon.png", typeof(MegaSimpleMod)),
  79. new Buttons("mybendicon.png", typeof(MegaSinusCurve)),
  80. new Buttons("myskewicon.png", typeof(MegaSkew)),
  81. new Buttons("myspherifyicon.png", typeof(MegaSpherify)),
  82. new Buttons("mystretchicon.png", typeof(MegaStretch)),
  83. new Buttons("mytapericon.png", typeof(MegaTaper)),
  84. new Buttons("mytwisticon.png", typeof(MegaTwist)),
  85. new Buttons("mybendicon.png", typeof(MegaVertexAnim)),
  86. new Buttons("mybendicon.png", typeof(MegaVertNoise)),
  87. new Buttons("mybendicon.png", typeof(MegaWave)),
  88. new Buttons("mybendicon.png", typeof(MegaWorldPathDeform)),
  89. #if false
  90. "Bend", "MegaBend",
  91. "Bubble", "MegaBubble",
  92. "Bulge", "MegaBulge",
  93. "Crumple", "MegaCrumple",
  94. "Curve Deform", "MegaCurveDeform",
  95. "Cylindrify", "MegaCylindrify",
  96. "Displace", "MegaDisplace",
  97. "FFD2x2x2", "MegaFFD2x2x2",
  98. "FFD3x3x3", "MegaFFD3x3x3",
  99. "FFD4x4x4", "MegaFFD4x4x4",
  100. "Hump", "MegaHump",
  101. "Melt", "MegaMelt",
  102. "Noise", "MegaNoise",
  103. "PageFlip", "MegaPageFlip",
  104. "Paint", "MegaPaint",
  105. "Path Deform", "MegaPathDeform",
  106. "Pivot Adjust", "MegaPivotAdjust",
  107. "Point Cache", "MegaPointCache",
  108. "Push", "MegaPush",
  109. "Radial Skew", "MegaRadialSkew",
  110. "Ripple", "MegaRipple",
  111. "Rope 2D", "MegaRopeDeform",
  112. "Rubber", "MegaRubber",
  113. "SimpleMod", "MegaSimpleMod",
  114. "SinusCurve", "MegaSinusCurve",
  115. "Skew", "MegaSkew",
  116. "Spherify", "MegaSpherify",
  117. "Stretch", "MegaStretch",
  118. "Taper", "MegaTaper",
  119. "Twist", "MegaTwist",
  120. "VertexAnim", "MegaVertexAnim",
  121. "VertNoise", "MegaVertNoise",
  122. "Wave", "MegaWave",
  123. "World PathDeform", "MegaWorldPathDeform",
  124. #endif
  125. };
  126. #endif
  127. //void Update()
  128. //{
  129. //Debug.Log("Mouse " + Input.mousePosition);
  130. //Debug.Log("Update");
  131. //}
  132. #if false
  133. public float scrollx = 0.0f;
  134. void DoScrollIcons(GameObject obj, Buttons[] buttons, float width, int bstep, bool modobj)
  135. {
  136. //EditorGUILayout.BeginHorizontal(GUIStyle.none);
  137. //EditorGUILayout.BeginArea(Rect(10, 10, 100, 100));
  138. Rect pos = new Rect(0, 0, 400.0f, 64.0f);
  139. pos.x = scrollx;
  140. for ( int i = 0; i < buttons.Length; i++ )
  141. {
  142. //if ( GUILayout.Button(buttons[i].image, GUILayout.Width(width)) )
  143. if ( buttons[i].content != null && GUI.Button(pos, buttons[i].content, GUIStyle.none) )
  144. {
  145. AddModType(obj, buttons[i].classname, modobj);
  146. }
  147. pos.x += width;
  148. }
  149. //EditorGUILayout.EndHorizontal();
  150. }
  151. #endif
  152. #if false
  153. void DoIcons(GameObject obj, Buttons[] buttons, float width, int bstep, bool modobj)
  154. {
  155. int off = 0;
  156. //width /= 4.0f;
  157. //bstep *= 4;
  158. for ( int i = 0; i < buttons.Length; i++ )
  159. {
  160. if ( off == 0 )
  161. {
  162. EditorGUILayout.BeginHorizontal(GUIStyle.none);
  163. }
  164. //if ( GUILayout.Button(buttons[i].image, GUILayout.Width(width)) )
  165. if ( buttons[i].content != null && GUILayout.Button(buttons[i].content, GUIStyle.none, GUILayout.Width(width), GUILayout.Height(48.0f)) )
  166. {
  167. AddModType(obj, buttons[i].classname, modobj);
  168. }
  169. off++;
  170. if ( off == bstep )
  171. {
  172. off = 0;
  173. EditorGUILayout.EndHorizontal();
  174. }
  175. }
  176. if ( off != 0 )
  177. {
  178. EditorGUILayout.EndHorizontal();
  179. }
  180. }
  181. #endif
  182. static Color modcol = new Color(0.75f, 0.75f, 1.0f);
  183. static Color uvmodscol = new Color(1.0f, 0.75f, 0.75f);
  184. static Color warpcol = new Color(0.75f, 1.0f, 0.75f);
  185. static Color selmodscol = new Color(1.0f, 1.0f, 0.75f);
  186. static Color utilmodscol = new Color(0.75f, 1.0f, 1.0f);
  187. static MegaModBut[] mods = new MegaModBut[] {
  188. new MegaModBut("Bend", "Bend a mesh", typeof(MegaBend), modcol),
  189. new MegaModBut("Bubble", "Bubble a mesh", typeof(MegaBubble), modcol),
  190. new MegaModBut("Bulge", "Add a Bulge to a mesh", typeof(MegaBulge), modcol),
  191. new MegaModBut("Crumple", "Crumple up a mesh, based on Unity Crumple", typeof(MegaCrumple), modcol),
  192. new MegaModBut("Curve", "Use a curve to bend a mesh", typeof(MegaCurveDeform), modcol),
  193. new MegaModBut("Cylindrify", "Cylindrify a mesh", typeof(MegaCylindrify), modcol),
  194. new MegaModBut("Displace", "Displace vertices using a texture", typeof(MegaDisplace), modcol),
  195. new MegaModBut("FFD 2x2x2", "FFD with a 2x2x2 lattice", typeof(MegaFFD2x2x2), modcol),
  196. new MegaModBut("FFD 3x3x3", "FFD with a 3x3x3 lattice", typeof(MegaFFD3x3x3), modcol),
  197. new MegaModBut("FFD 4x4x4", "FFD with a 4x4x4 lattice", typeof(MegaFFD4x4x4), modcol),
  198. new MegaModBut("Hump", "Add humps to a mesh", typeof(MegaHump), modcol),
  199. new MegaModBut("Melt", "Melt a mesh", typeof(MegaMelt), modcol),
  200. new MegaModBut("Morph", "Morph a mesh", typeof(MegaMorph), modcol),
  201. new MegaModBut("MorphOMat", "MorphOMatic a mesh", typeof(MegaMorphOMatic), modcol),
  202. new MegaModBut("Noise", "Add noise to a mesh", typeof(MegaNoise), modcol),
  203. new MegaModBut("PageFlip", "Make a page turning effect", typeof(MegaPageFlip), modcol),
  204. new MegaModBut("Paint", "Paint deformation onto a mesh", typeof(MegaPaint), modcol),
  205. new MegaModBut("Path", "Deform a mesh along a path", typeof(MegaPathDeform), modcol),
  206. new MegaModBut("Pivot", "Alter pivot point on a mesh", typeof(MegaPivotAdjust), modcol),
  207. new MegaModBut("PointCache", "Point cache animation or vertices", typeof(MegaPointCache), modcol),
  208. new MegaModBut("Push", "Push vertices along their normals", typeof(MegaPush), modcol),
  209. new MegaModBut("RadialSkew", "Radial skew a mesh", typeof(MegaRadialSkew), modcol),
  210. new MegaModBut("Ripple", "Add a ripple to a mesh", typeof(MegaRipple), modcol),
  211. new MegaModBut("Rope", "Deform a mesh using 2D Rope physics", typeof(MegaRopeDeform), modcol),
  212. new MegaModBut("Rubber", "Add secondary rubber motion to a mesh", typeof(MegaRubber), modcol),
  213. new MegaModBut("Simple", "Example of a simple mod", typeof(MegaSimpleMod), modcol),
  214. new MegaModBut("Sinus", "Sin wave deformation based on Unity example", typeof(MegaSinusCurve), modcol),
  215. new MegaModBut("Skew", "Skew a mesh", typeof(MegaSkew), modcol),
  216. new MegaModBut("Spherify", "Turn a mesh into a sphere", typeof(MegaSpherify), modcol),
  217. new MegaModBut("Squeeze", "Squeeze a mesh", typeof(MegaSqueeze), modcol),
  218. new MegaModBut("Stretch", "Squash and stretch a mesh", typeof(MegaStretch), modcol),
  219. new MegaModBut("Taper", "Taper a mesh", typeof(MegaTaper), modcol),
  220. new MegaModBut("Twist", "Twist a mesh", typeof(MegaTwist), modcol),
  221. new MegaModBut("VertAnim", "Animate vertices on a mesh", typeof(MegaVertexAnim), modcol),
  222. new MegaModBut("Vert Noise", "Add Vertical noise to a mesh", typeof(MegaVertNoise), modcol),
  223. new MegaModBut("Wave", "Add a wave to a mesh", typeof(MegaWave), modcol),
  224. new MegaModBut("World Path", "Deform a mesh along a path in world space", typeof(MegaWorldPathDeform), modcol),
  225. };
  226. static MegaModBut[] warpmods = new MegaModBut[] {
  227. new MegaModBut("Warp Bind", "Bind a mesh to a World Space Warp", typeof(MegaWarpBind), warpcol),
  228. new MegaModBut("Bend", "Bend Warp", typeof(MegaBendWarp), warpcol),
  229. new MegaModBut("Noise", "Noise Warp", typeof(MegaNoiseWarp), warpcol),
  230. new MegaModBut("Ripple", "Ripple Warp", typeof(MegaRippleWarp), warpcol),
  231. new MegaModBut("Skew", "Skew Warp", typeof(MegaSkewWarp), warpcol),
  232. new MegaModBut("Stretch", "Stretch Warp", typeof(MegaStretchWarp), warpcol),
  233. new MegaModBut("Taper", "Taper Warp", typeof(MegaTaperWarp), warpcol),
  234. new MegaModBut("Twist", "Twist Warp", typeof(MegaTwistWarp), warpcol),
  235. new MegaModBut("Wave", "Wave Warp", typeof(MegaWaveWarp), warpcol),
  236. };
  237. static MegaModBut[] uvmods = new MegaModBut[] {
  238. new MegaModBut("UVAdjust", "Transform a meshes UV coords", typeof(MegaUVAdjust), uvmodscol),
  239. new MegaModBut("UVTile", "Animate UVs to playback sprite anim", typeof(MegaUVTiles), uvmodscol),
  240. };
  241. static MegaModBut[] selmods = new MegaModBut[] {
  242. new MegaModBut("VertCol", "Select vertices by vertex color", typeof(MegaVertColSelect), selmodscol),
  243. new MegaModBut("Vol Select", "Select vertices by volumes", typeof(MegaVolSelect), selmodscol),
  244. };
  245. static MegaModBut[] utilmods = new MegaModBut[] {
  246. new MegaModBut("Anim", "Animate morph percents", typeof(MegaMorphAnim), utilmodscol),
  247. new MegaModBut("Animator", "Use anim clips to animate morphs", typeof(MegaMorphAnimator), utilmodscol),
  248. new MegaModBut("BallBounce", "Simulate soft ball bouncing", typeof(MegaBallBounce), utilmodscol),
  249. new MegaModBut("Book", "Book builder", typeof(MegaBook), utilmodscol),
  250. new MegaModBut("MultiCore", "Script to toggle multicore support", typeof(MegaToggleMultiCore), utilmodscol),
  251. new MegaModBut("Page", "Build a page mesh for books", typeof(MegaMeshPage), utilmodscol),
  252. new MegaModBut("Scroll", "Simulate an old paper scroll", typeof(MegaScroll), utilmodscol),
  253. new MegaModBut("WalkBridge", "Helper to move a character across a bridge", typeof(MegaWalkBridge), utilmodscol),
  254. new MegaModBut("WalkRope", "Helper to move a character across a rope bridge", typeof(MegaWalkRope), utilmodscol),
  255. };
  256. #if false
  257. static MegaModBut[] uvmods1 = new MegaModBut[] {
  258. new ModBut("UVAdjust", "Transform a meshes UV coords", typeof(MegaUVAdjust), uvmodscol),
  259. new ModBut("UVTile", "Animate UVs to playback sprite anim", typeof(MegaUVTiles), uvmodscol),
  260. };
  261. static string[] mods1 = new string[] {
  262. "Bend", "MegaBend",
  263. "Bubble", "MegaBubble",
  264. "Bulge", "MegaBulge",
  265. "Crumple", "MegaCrumple",
  266. "Curve", "MegaCurveDeform",
  267. "Cylindrify", "MegaCylindrify",
  268. "Displace", "MegaDisplace",
  269. "FFD 2x2x2", "MegaFFD2x2x2",
  270. "FFD 3x3x3", "MegaFFD3x3x3",
  271. "FFD 4x4x4", "MegaFFD4x4x4",
  272. "Hump", "MegaHump",
  273. "Melt", "MegaMelt",
  274. "Noise", "MegaNoise",
  275. "PageFlip", "MegaPageFlip",
  276. "Paint", "MegaPaint",
  277. "Path", "MegaPathDeform",
  278. "Pivot", "MegaPivotAdjust",
  279. "PointCache", "MegaPointCache",
  280. "Push", "MegaPush",
  281. "RadialSkew", "MegaRadialSkew",
  282. "Ripple", "MegaRipple",
  283. "Rope 2D", "MegaRopeDeform",
  284. "Rubber", "MegaRubber",
  285. "SimpleMod", "MegaSimpleMod",
  286. "SinusCurve", "MegaSinusCurve",
  287. "Skew", "MegaSkew",
  288. "Spherify", "MegaSpherify",
  289. "Stretch", "MegaStretch",
  290. "Taper", "MegaTaper",
  291. "Twist", "MegaTwist",
  292. "VertexAnim", "MegaVertexAnim",
  293. "VertNoise", "MegaVertNoise",
  294. "Wave", "MegaWave",
  295. "World Path", "MegaWorldPathDeform",
  296. };
  297. static string[] uvmods = new string[] {
  298. "UVAdjust", "MegaUVAdjust",
  299. "UVTile", "MegaUVTile",
  300. };
  301. static string[] selmods = new string[] {
  302. "Vert Col", "MegaVertColSelect",
  303. "Vol Select", "MegaVolSelect",
  304. };
  305. static string[] morphmods = new string[] {
  306. "Morph", "MegaMorph",
  307. "MorphOMatic", "MegaMorphOMatic",
  308. };
  309. static string[] utils = new string[] {
  310. "Anim", "MegaMorphAnim",
  311. "Animator", "MegaMorphAnimator",
  312. "Ball Bounce", "BallBounce",
  313. "Book Builder", "MegaBook",
  314. "MultiCore", "ToggleMultiCore",
  315. "Page", "MegaMeshPage",
  316. "Scroll", "Scroll",
  317. "Walk Bridge", "WalkBridge",
  318. "Walk Rope", "WalkRope",
  319. };
  320. #endif
  321. #if false
  322. void AddMod(GameObject go, string name, bool modobj)
  323. {
  324. if ( go )
  325. {
  326. MeshFilter mf = go.GetComponent<MeshFilter>();
  327. if ( mf != null )
  328. {
  329. if ( modobj )
  330. {
  331. MegaModifyObject mod = go.GetComponent<MegaModifyObject>();
  332. if ( mod == null )
  333. {
  334. mod = go.AddComponent<MegaModifyObject>();
  335. mod.NormalMethod = NormalMethod;
  336. }
  337. }
  338. if ( name != null )
  339. {
  340. MegaModifier md = (MegaModifier)go.AddComponent(name);
  341. if ( md )
  342. {
  343. md.gizCol1 = col1;
  344. md.gizCol2 = col2;
  345. }
  346. }
  347. }
  348. }
  349. }
  350. #endif
  351. void AddModType(GameObject go, System.Type name, bool modobj)
  352. {
  353. if ( go )
  354. {
  355. if ( !name.IsSubclassOf(typeof(MegaModifier)) && !name.IsSubclassOf(typeof(MegaWarp)) )
  356. {
  357. go.AddComponent(name);
  358. }
  359. else
  360. {
  361. MeshFilter mf = go.GetComponent<MeshFilter>();
  362. if ( mf != null )
  363. {
  364. if ( modobj )
  365. {
  366. if ( name.IsSubclassOf(typeof(MegaModifier)) )
  367. {
  368. MegaModifyObject mod = go.GetComponent<MegaModifyObject>();
  369. if ( mod == null )
  370. {
  371. mod = go.AddComponent<MegaModifyObject>();
  372. mod.NormalMethod = NormalMethod;
  373. }
  374. }
  375. }
  376. if ( name != null )
  377. {
  378. if ( name.IsSubclassOf(typeof(MegaModifier)) )
  379. {
  380. MegaModifier md = (MegaModifier)go.AddComponent(name);
  381. if ( md )
  382. {
  383. md.gizCol1 = col1;
  384. md.gizCol2 = col2;
  385. }
  386. }
  387. else
  388. {
  389. if ( name.IsSubclassOf(typeof(MegaWarp)) )
  390. {
  391. MegaWarp md = (MegaWarp)go.AddComponent(name);
  392. if ( md )
  393. {
  394. md.GizCol1 = col1;
  395. md.GizCol2 = col2;
  396. }
  397. }
  398. else
  399. {
  400. go.AddComponent(name);
  401. }
  402. }
  403. }
  404. }
  405. else
  406. {
  407. if ( name.IsSubclassOf(typeof(MegaWarp)) )
  408. {
  409. MegaWarp md = (MegaWarp)go.AddComponent(name);
  410. if ( md )
  411. {
  412. md.GizCol1 = col1;
  413. md.GizCol2 = col2;
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. // Put common params in, and each shape has its sections
  421. Vector2 scroll = Vector2.zero;
  422. //bool showmods = false;
  423. //bool showuvmods = false;
  424. //bool showselmods = false;
  425. //bool showmorphmods = false;
  426. //bool showutilsmods = false;
  427. #if false
  428. void DoButtons(GameObject obj, string[] buttons, float width, int bstep, bool modobj)
  429. {
  430. Color c = GUI.backgroundColor;
  431. int off = 0;
  432. Color guicol = GUI.color;
  433. GUI.color = Color.blue;
  434. GUI.backgroundColor = Color.red;
  435. GUI.contentColor = Color.green;
  436. Color col1 = new Color(1.0f, 0.627f, 0.0f);
  437. Color col2 = new Color(0.0f, 0.627f, 1.0f);
  438. for ( int i = 0; i < buttons.Length; i += 2 )
  439. {
  440. if ( (i & 2) == 0 )
  441. GUI.color = col1; //Color.blue;
  442. else
  443. GUI.color = col2; //Color.yellow;
  444. if ( off == 0 )
  445. {
  446. EditorGUILayout.BeginHorizontal();
  447. }
  448. if ( GUILayout.Button(buttons[i], GUILayout.Width(width)) )
  449. AddMod(obj, buttons[i + 1], modobj);
  450. off++;
  451. if ( off == bstep )
  452. {
  453. off = 0;
  454. EditorGUILayout.EndHorizontal();
  455. }
  456. }
  457. if ( off != 0 )
  458. EditorGUILayout.EndHorizontal();
  459. GUI.backgroundColor = c;
  460. GUI.color = guicol;
  461. GUI.contentColor = Color.white;
  462. }
  463. #endif
  464. int DoButtons(GameObject obj, MegaModBut[] buttons, float width, int bstep, bool modobj, int off)
  465. {
  466. Color c = GUI.backgroundColor;
  467. //int off = 0;
  468. GUI.backgroundColor = Color.blue;
  469. Color guicol = GUI.color;
  470. GUI.color = new Color(1, 1, 1, 1); //Color.white;
  471. GUI.backgroundColor = new Color(0, 0, 0, 0); //Color.white;
  472. GUI.contentColor = Color.white;
  473. //Color col1 = new Color(1.0f, 0.627f, 0.0f);
  474. //Color col2 = new Color(0.0f, 0.627f, 1.0f);
  475. for ( int i = 0; i < buttons.Length; i++ )
  476. {
  477. //if ( (i & 2) == 0 )
  478. //GUI.backgroundColor = buttons[i].color; //Color.blue;
  479. GUI.contentColor = buttons[i].color; //Color.blue;
  480. //else
  481. // GUI.backgroundColor = col2; //Color.yellow;
  482. //Color co = buttons[i].color * 0.08f;
  483. //co.a = 0.18f;
  484. GUI.backgroundColor = buttons[i].color * 0.08f;
  485. if ( off == 0 )
  486. {
  487. EditorGUILayout.BeginHorizontal();
  488. }
  489. //if ( GUILayout.Button(buttons[i].content, GUILayout.Width(width)) )
  490. if ( GUILayout.Button(buttons[i].content, GUILayout.Width(width)) )
  491. AddModType(obj, buttons[i].classname, modobj);
  492. off++;
  493. if ( off == bstep )
  494. {
  495. off = 0;
  496. EditorGUILayout.EndHorizontal();
  497. }
  498. }
  499. //if ( off != 0 )
  500. // EditorGUILayout.EndHorizontal();
  501. GUI.backgroundColor = c;
  502. GUI.color = guicol;
  503. return off;
  504. }
  505. public int toolbarInt = 0;
  506. public string[] toolbarStrings = new string[] {"All", "Mod", "Warp", "UV", "Sel", "Util" };
  507. void OnGUI()
  508. {
  509. //name = EditorGUILayout.TextField("Name", name);
  510. scroll = EditorGUILayout.BeginScrollView(scroll);
  511. GameObject obj = Selection.activeGameObject;
  512. float width = this.position.width; // / 2.0f;
  513. //if ( obj )
  514. {
  515. //MeshFilter mf = obj.GetComponent<MeshFilter>();
  516. //if ( mf != null )
  517. {
  518. //if ( GUILayout.Button("Modify Object") ) AddMod(obj, null, true); //.AddComponent<MegaModifyObject>();
  519. float butwidth = 80.0f;
  520. int bstep = (int)(width / butwidth);
  521. if ( bstep == 0 )
  522. bstep = 1;
  523. //int off = 0;
  524. //showmods = EditorGUILayout.Foldout(showmods, "Modifiers");
  525. toolbarInt = GUILayout.Toolbar(toolbarInt, toolbarStrings, GUILayout.MaxWidth(250.0f));
  526. //if ( showmods )
  527. {
  528. int off = 0;
  529. //DoScrollIcons(obj, buts, 48.0f, (int)(width / 48.0f), true);
  530. //DoIcons(obj, buts, 48.0f, (int)(width / 48.0f), true);
  531. switch ( toolbarInt )
  532. {
  533. case 0:
  534. off = DoButtons(obj, mods, (width / bstep) - 6.0f, bstep, true, off);
  535. off = DoButtons(obj, warpmods, (width / bstep) - 6.0f, bstep, true, off);
  536. off = DoButtons(obj, uvmods, (width / bstep) - 6.0f, bstep, true, off);
  537. off = DoButtons(obj, selmods, (width / bstep) - 6.0f, bstep, true, off);
  538. off = DoButtons(obj, utilmods, (width / bstep) - 6.0f, bstep, true, off);
  539. break;
  540. case 1: DoButtons(obj, mods, (width / bstep) - 6.0f, bstep, true, off); break;
  541. case 2: DoButtons(obj, warpmods, (width / bstep) - 6.0f, bstep, true, off); break;
  542. case 3: DoButtons(obj, uvmods, (width / bstep) - 6.0f, bstep, true, off); break;
  543. case 4: DoButtons(obj, selmods, (width / bstep) - 6.0f, bstep, true, off); break;
  544. case 5: DoButtons(obj, utilmods, (width / bstep) - 6.0f, bstep, true, off); break;
  545. }
  546. if ( off != 0 )
  547. EditorGUILayout.EndHorizontal();
  548. //GUI.backgroundColor = Color.grey;
  549. #if false
  550. if ( GUILayout.Button("Modify Object") ) AddMod(obj, null, true); //.AddComponent<MegaModifyObject>();
  551. showcommon = EditorGUILayout.Foldout(showcommon, "Common");
  552. if ( showcommon )
  553. {
  554. NormalMethod = (MegaNormalMethod)EditorGUILayout.EnumPopup("Normal Method", NormalMethod);
  555. //axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", axis);
  556. col1 = EditorGUILayout.ColorField("Color 1", col1);
  557. col2 = EditorGUILayout.ColorField("Color 2", col2);
  558. }
  559. #endif
  560. #if false
  561. for ( int i = 0; i < mods.Length; i += 2 )
  562. {
  563. if ( off == 0 )
  564. {
  565. EditorGUILayout.BeginHorizontal();
  566. }
  567. if ( GUILayout.Button(mods[i], GUILayout.Width((width / bstep) - 6.0f)) )
  568. AddMod(obj, mods[i + 1]);
  569. off++;
  570. if ( off == bstep )
  571. {
  572. off = 0;
  573. EditorGUILayout.EndHorizontal();
  574. }
  575. }
  576. #endif
  577. }
  578. //showuvmods = EditorGUILayout.Foldout(showuvmods, "UV Modifiers");
  579. //if ( showuvmods )
  580. // DoButtons(obj, uvmods, (width / bstep) - 6.0f, bstep, true);
  581. //showmorphmods = EditorGUILayout.Foldout(showmorphmods, "Morph");
  582. //if ( showmorphmods )
  583. // DoButtons(obj, morphmods, (width / bstep) - 6.0f, bstep, true);
  584. //showselmods = EditorGUILayout.Foldout(showselmods, "Selection");
  585. //if ( showselmods )
  586. // DoButtons(obj, selmods, (width / bstep) - 6.0f, bstep, true);
  587. //showutilsmods = EditorGUILayout.Foldout(showutilsmods, "Utils");
  588. //if ( showutilsmods )
  589. // DoButtons(obj, utils, (width / bstep) - 6.0f, bstep, false);
  590. }
  591. }
  592. EditorGUILayout.EndScrollView();
  593. }
  594. #if false
  595. static void CreateShape(string type)
  596. {
  597. Vector3 pos = UnityEditor.SceneView.lastActiveSceneView.pivot;
  598. MegaShape ms = null;
  599. GameObject go = new GameObject(type + " Shape");
  600. switch ( type )
  601. {
  602. case "Circle": ms = go.AddComponent<MegaShapeCircle>(); break;
  603. case "Star": ms = go.AddComponent<MegaShapeStar>(); break;
  604. case "NGon": ms = go.AddComponent<MegaShapeNGon>(); break;
  605. case "Arc": ms = go.AddComponent<MegaShapeArc>(); break;
  606. case "Ellipse": ms = go.AddComponent<MegaShapeEllipse>(); break;
  607. case "Rectangle": ms = go.AddComponent<MegaShapeRectangle>(); break;
  608. case "Helix": ms = go.AddComponent<MegaShapeHelix>(); break;
  609. }
  610. go.transform.position = pos;
  611. Selection.activeObject = go;
  612. if ( ms != null )
  613. {
  614. ms.axis = axis;
  615. ms.drawHandles = drawhandles;
  616. ms.drawKnots = drawknots;
  617. ms.col1 = col1;
  618. ms.col2 = col2;
  619. ms.KnotSize = knotsize;
  620. ms.stepdist = stepdist;
  621. }
  622. }
  623. #endif
  624. }