MegaGUI.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. using UnityEngine;
  2. public class MegaGUI : MonoBehaviour
  3. {
  4. public GameObject source;
  5. public GameObject ground;
  6. bool showcommon = false;
  7. bool showgcommon = false;
  8. MegaModifier[] mods;
  9. MegaModifier[] gmods;
  10. bool[] showmod;
  11. bool[] showgmod;
  12. MegaModifiers context = null;
  13. MegaModifiers gcontext = null;
  14. public bool showparams = true;
  15. public bool showgparams = true;
  16. GUIContent[] Axislist;
  17. public float objsize = 2.0f;
  18. GUIContent[] EAxislist;
  19. Vector2 pos = new Vector2();
  20. public float sx = 232.0f; //190.0f;
  21. Rect windowRect = new Rect(10, 5, 200, 500);
  22. public Material mat;
  23. public Material gmat;
  24. void Start()
  25. {
  26. if ( source != null )
  27. {
  28. context = (MegaModifiers)source.GetComponent<MegaModifyObject>();
  29. if ( context != null )
  30. {
  31. mods = source.GetComponents<MegaModifier>();
  32. showmod = new bool[mods.Length];
  33. }
  34. gcontext = (MegaModifiers)ground.GetComponent<MegaModifyObject>();
  35. if ( gcontext != null )
  36. {
  37. gmods = ground.GetComponents<MegaModifier>();
  38. showgmod = new bool[gmods.Length];
  39. }
  40. }
  41. SizeChange();
  42. }
  43. void InitAxis()
  44. {
  45. if ( Axislist == null )
  46. {
  47. // Make some content for the popup list
  48. Axislist = new GUIContent[3];
  49. Axislist[0] = new GUIContent("X");
  50. Axislist[1] = new GUIContent("Y");
  51. Axislist[2] = new GUIContent("Z");
  52. }
  53. }
  54. void InitEAxis()
  55. {
  56. if ( EAxislist == null )
  57. {
  58. // Make some content for the popup list
  59. EAxislist = new GUIContent[3];
  60. EAxislist[0] = new GUIContent("X");
  61. EAxislist[1] = new GUIContent("Y");
  62. EAxislist[2] = new GUIContent("XY");
  63. }
  64. }
  65. GUIContent[] MatList;
  66. void InitMatList()
  67. {
  68. if ( MatList == null )
  69. {
  70. // Make some content for the popup list
  71. MatList = new GUIContent[5];
  72. MatList[0] = new GUIContent("Ice");
  73. MatList[1] = new GUIContent("Glass");
  74. MatList[2] = new GUIContent("Jelly");
  75. MatList[3] = new GUIContent("Plastic");
  76. MatList[4] = new GUIContent("Custom");
  77. }
  78. }
  79. public int EAxisXYZ(string name, int val)
  80. {
  81. InitEAxis();
  82. GUILayout.Label(name);
  83. return GUILayout.SelectionGrid(val, EAxislist, 3, "toggle");
  84. }
  85. public int EditInt(string name, int val)
  86. {
  87. GUILayout.Label(name);
  88. #if !UNITY_FLASH
  89. string s = GUILayout.TextField(val.ToString());
  90. int.TryParse(s, out val);
  91. #endif
  92. return val;
  93. }
  94. public int XYZ(string name, int val)
  95. {
  96. InitAxis();
  97. GUILayout.Label(name);
  98. return GUILayout.SelectionGrid(val, Axislist, 3, "toggle");
  99. }
  100. // Slider pro to size of mesh
  101. public float ProSlider(string name, float val, float low, float high, float pro)
  102. {
  103. GUILayout.Label(name + " " + val.ToString("0.000"));
  104. return GUILayout.HorizontalSlider(val, low * pro * 0.5f, high * pro * 0.5f);
  105. }
  106. public float ProSlider(float val, float low, float high, float pro)
  107. {
  108. return GUILayout.HorizontalSlider(val, low * pro * 0.5f, high * pro * 0.5f);
  109. }
  110. public float Slider(string name, float val, float low, float high)
  111. {
  112. float a = (val - low) / (high - low);
  113. GUILayout.Label(name + " " + val.ToString("0.000"));
  114. float v = GUILayout.HorizontalSlider(a, 0.0f, 1.0f); //low, high);
  115. float delta = v - a;
  116. if ( Input.GetKey(KeyCode.LeftShift) )
  117. {
  118. delta *= 0.001f;
  119. }
  120. a += delta;
  121. return low + (a * (high - low));
  122. }
  123. public float AngleSlider(string name, float val, float scl)
  124. {
  125. GUILayout.Label(name + " " + val.ToString("0.000"));
  126. return GUILayout.HorizontalSlider(val, -360.0f * scl, 360.0f * scl);
  127. }
  128. public float AngleSlider(float val, float scl)
  129. {
  130. return GUILayout.HorizontalSlider(val, -360.0f * scl, 360.0f * scl);
  131. }
  132. Color gr = new Color(1.0f, 0.5f, 0.5f);
  133. Color gg = new Color(0.5f, 1.0f, 0.5f);
  134. Color gb = new Color(0.5f, 0.5f, 1.0f);
  135. public Vector3 AngleSlider(string name, ref Vector3 val, float scl)
  136. {
  137. GUILayout.Label(name + " " + val.x.ToString("0.0") + " " + val.y.ToString("0.0") + " " + val.z.ToString("0.0"));
  138. GUI.color = gr;
  139. val.x = AngleSlider(val.x, scl);
  140. GUI.color = gg;
  141. val.y = AngleSlider(val.y, scl);
  142. GUI.color = gb;
  143. val.z = AngleSlider(val.z, scl);
  144. GUI.color = Color.white;
  145. return val;
  146. }
  147. public Vector3 ProSlider(string name, ref Vector3 val, float low, float high, float pro)
  148. {
  149. GUILayout.Label(name + " " + val.x.ToString("0.0") + " " + val.y.ToString("0.0") + " " + val.z.ToString("0.0"));
  150. GUI.color = gr;
  151. val.x = ProSlider(val.x, low, high, pro);
  152. GUI.color = gg;
  153. val.y = ProSlider(val.y, low, high, pro);
  154. GUI.color = gb;
  155. val.z = ProSlider(val.z, low, high, pro);
  156. GUI.color = Color.white;
  157. return val;
  158. }
  159. public Color ColSlider(string name, ref Color val, float low, float high, float pro)
  160. {
  161. GUILayout.Label(name + " " + val.r.ToString("0.0") + " " + val.g.ToString("0.0") + " " + val.b.ToString("0.0"));
  162. GUI.color = gr;
  163. val.r = ProSlider(val.r, low, high, pro);
  164. GUI.color = gg;
  165. val.g = ProSlider(val.g, low, high, pro);
  166. GUI.color = gb;
  167. val.b = ProSlider(val.b, low, high, pro);
  168. GUI.color = Color.white;
  169. val.a = ProSlider(val.a, low, high, pro);
  170. return val;
  171. }
  172. public float butwidth = 166.0f;
  173. public Color bcol = new Color(245, 177, 17); //190, 75);
  174. public Color bcol1 = new Color(96, 149, 255);
  175. void ShowCommon(MegaModifier md, int i)
  176. {
  177. if ( (i & 1) == 1 )
  178. GUI.color = bcol; //Color.red;
  179. else
  180. GUI.color = bcol1; //Color.red;
  181. if ( GUILayout.Button(md.ModName(), GUILayout.Width(butwidth)) )
  182. showmod[i] = showmod[i] ? false : true;
  183. if ( showmod[i] )
  184. {
  185. GUI.color = Color.white;
  186. md.ModEnabled = GUILayout.Toggle(md.ModEnabled, "Enabled");
  187. if ( showcommon )
  188. {
  189. ProSlider("Offset", ref md.Offset, -4.0f, 4.0f, objsize);
  190. ProSlider("Pos", ref md.gizmoPos, -4.0f, 4.0f, objsize);
  191. ProSlider("Rot", ref md.gizmoRot, -90.0f, 90.0f, objsize);
  192. int order = EditInt("Order", md.Order);
  193. if ( order != md.Order )
  194. {
  195. md.Order = order;
  196. context.Sort();
  197. }
  198. }
  199. }
  200. }
  201. void ShowGCommon(MegaModifier md, int i)
  202. {
  203. if ( (i & 1) == 1 )
  204. GUI.color = bcol; //Color.red;
  205. else
  206. GUI.color = bcol1; //Color.red;
  207. if ( GUILayout.Button(md.ModName(), GUILayout.Width(butwidth)) )
  208. showgmod[i] = showgmod[i] ? false : true;
  209. GUI.color = Color.white; //Color.red;
  210. if ( showgmod[i] )
  211. {
  212. md.ModEnabled = GUILayout.Toggle(md.ModEnabled, "Enabled");
  213. if ( showgcommon )
  214. {
  215. ProSlider("Offset", ref md.Offset, -4.0f, 4.0f, objsize);
  216. ProSlider("Pos", ref md.gizmoPos, -4.0f, 4.0f, objsize);
  217. ProSlider("Rot", ref md.gizmoRot, -90.0f, 90.0f, objsize);
  218. int order = EditInt("Order", md.Order);
  219. if ( order != md.Order )
  220. {
  221. md.Order = order;
  222. gcontext.Sort();
  223. }
  224. }
  225. }
  226. }
  227. void ShowGUI(MegaModifier mod)
  228. {
  229. switch ( mod.ModName() )
  230. {
  231. case "Bend":
  232. {
  233. MegaBend bmod = (MegaBend)mod;
  234. bmod.angle = AngleSlider("Angle", bmod.angle, 2.0f);
  235. bmod.dir = AngleSlider("Direction", bmod.dir, 1.0f);
  236. bmod.axis = (MegaAxis)XYZ("Axis", (int)bmod.axis);
  237. bmod.doRegion = GUILayout.Toggle(bmod.doRegion, "DoRegion");
  238. if ( bmod.doRegion )
  239. {
  240. bmod.from = Slider("From", bmod.from, -40.0f, 0.0f);
  241. bmod.to = Slider("To", bmod.to, 0.0f, 40.0f);
  242. }
  243. }
  244. break;
  245. case "Hump":
  246. MegaHump hmod = (MegaHump)mod;
  247. Vector3 size = mod.bbox.Size();
  248. float sz = size.magnitude * 4.0f;
  249. hmod.amount = ProSlider("Amount", hmod.amount, -2.0f, 2.0f, sz); //objsize);
  250. hmod.cycles = Slider("Cycles", hmod.cycles, 0.0f, 20.0f);
  251. hmod.phase = Slider("Phase", hmod.phase, 0.0f, 10.0f);
  252. hmod.axis = (MegaAxis)XYZ("Axis", (int)hmod.axis);
  253. hmod.animate = GUILayout.Toggle(hmod.animate, "Animate");
  254. if ( hmod.animate )
  255. hmod.speed = Slider("Speed", hmod.speed, -10.0f, 10.0f);
  256. break;
  257. case "Twist":
  258. {
  259. MegaTwist tmod = (MegaTwist)mod;
  260. tmod.angle = AngleSlider("Angle", tmod.angle, 2.0f);
  261. tmod.Bias = Slider("Bias", tmod.Bias, -40.0f, 40.0f);
  262. tmod.axis = (MegaAxis)XYZ("Axis", (int)tmod.axis);
  263. tmod.doRegion = GUILayout.Toggle(tmod.doRegion, "DoRegion");
  264. if ( tmod.doRegion )
  265. {
  266. tmod.from = Slider("From", tmod.from, -40.0f, 0.0f);
  267. tmod.to = Slider("To", tmod.to, 0.0f, 40.0f);
  268. }
  269. }
  270. break;
  271. case "Taper":
  272. {
  273. MegaTaper tmod = (MegaTaper)mod;
  274. tmod.amount = Slider("Amount", tmod.amount, -10.0f, 10.0f);
  275. tmod.axis = (MegaAxis)XYZ("Axis", (int)tmod.axis);
  276. tmod.EAxis = (MegaEffectAxis)EAxisXYZ("EffectAxis", (int)tmod.EAxis);
  277. tmod.dir = AngleSlider("Direction", tmod.dir, 1.0f);
  278. tmod.crv = Slider("Curve", tmod.crv, -10.0f, 10.0f);
  279. tmod.sym = GUILayout.Toggle(tmod.sym, "Symmetry");
  280. tmod.doRegion = GUILayout.Toggle(tmod.doRegion, "Limit Effect");
  281. if ( tmod.doRegion )
  282. {
  283. tmod.from = ProSlider("From", tmod.from, 0.0f, 1.0f, objsize);
  284. tmod.to = ProSlider("To", tmod.to, 0.0f, 1.0f, objsize);
  285. }
  286. }
  287. break;
  288. case "FFD3x3x3":
  289. MegaFFD fmod = (MegaFFD)mod;
  290. for ( int i = 0; i < 27; i++ )
  291. {
  292. string name = "p" + i;
  293. fmod.pt[i] = ProSlider(name, ref fmod.pt[i], -2.0f, 2.0f, objsize);
  294. }
  295. break;
  296. case "Noise":
  297. MegaNoise nmod = (MegaNoise)mod;
  298. nmod.Scale = Slider("Scale", nmod.Scale, 0.0f, 10.0f);
  299. nmod.Freq = Slider("Freq", nmod.Freq, 0.0f, 30.0f);
  300. nmod.Phase = Slider("Phase", nmod.Phase, 0.0f, 10.0f);
  301. nmod.Strength = ProSlider("Strength", ref nmod.Strength, 0.0f, 1.0f, objsize);
  302. nmod.Animate = GUILayout.Toggle(nmod.Animate, "Animate");
  303. nmod.Fractal = GUILayout.Toggle(nmod.Fractal, "Fractal");
  304. if ( nmod.Fractal )
  305. {
  306. nmod.Rough = Slider("Rough", nmod.Rough, 0.0f, 1.0f);
  307. nmod.Iterations = Slider("Iterations", nmod.Iterations, 0.0f, 10.0f);
  308. }
  309. break;
  310. case "Ripple":
  311. MegaRipple rmod = (MegaRipple)mod;
  312. rmod.animate = GUILayout.Toggle(rmod.animate, "Animate");
  313. if ( rmod.animate )
  314. rmod.Speed = Slider("Speed", rmod.Speed, -4.0f, 4.0f);
  315. rmod.amp = ProSlider("Amp", rmod.amp, -1.0f, 1.0f, objsize);
  316. rmod.amp2 = ProSlider("Amp2", rmod.amp2, -1.0f, 1.0f, objsize);
  317. rmod.flex = Slider("Flex", rmod.flex, -10.0f, 10.0f);
  318. rmod.wave = Slider("Wave", rmod.wave, -25.0f, 25.0f);
  319. rmod.phase = Slider("Phase", rmod.phase, -100.0f, 100.0f);
  320. rmod.Decay = Slider("decay", rmod.Decay, 0.0f, 500.0f);
  321. break;
  322. case "Wave":
  323. MegaWave wmod = (MegaWave)mod;
  324. wmod.animate = GUILayout.Toggle(wmod.animate, "Animate");
  325. if ( wmod.animate )
  326. wmod.Speed = Slider("Speed", wmod.Speed, -4.0f, 4.0f);
  327. wmod.amp = ProSlider("Amp", wmod.amp, -1.0f, 1.0f, objsize * 0.75f);
  328. wmod.amp2 = ProSlider("Amp2", wmod.amp2, -1.0f, 1.0f, objsize * 0.75f);
  329. wmod.flex = Slider("Flex", wmod.flex, -10.0f, 10.0f);
  330. wmod.wave = Slider("Wave", wmod.wave, -100.0f, 100.0f);
  331. wmod.phase = Slider("Phase", wmod.phase, -100.0f, 100.0f);
  332. wmod.Decay = Slider("decay", wmod.Decay, 0.0f, 50.0f);
  333. wmod.dir = Slider("Direction", wmod.dir, 0.0f, 90.0f);
  334. break;
  335. case "Stretch":
  336. {
  337. MegaStretch smod = (MegaStretch)mod;
  338. smod.amount = Slider("Amount", smod.amount, -4.0f, 4.0f);
  339. smod.amplify = Slider("Amplify", smod.amplify, -2.0f, 2.0f);
  340. smod.axis = (MegaAxis)XYZ("Axis", (int)smod.axis);
  341. }
  342. break;
  343. case "Bubble":
  344. {
  345. MegaBubble bmod = (MegaBubble)mod;
  346. bmod.radius = ProSlider("Radius", bmod.radius, -1.0f, 4.0f, objsize);
  347. bmod.falloff = ProSlider("Falloff", bmod.falloff, -1.0f, 1.0f, objsize);
  348. }
  349. break;
  350. case "Spherify":
  351. {
  352. MegaSpherify smod = (MegaSpherify)mod;
  353. smod.percent = Slider("Percent", smod.percent, 0.0f, 100.0f);
  354. }
  355. break;
  356. case "Skew":
  357. {
  358. MegaSkew smod = (MegaSkew)mod;
  359. smod.amount = ProSlider("Amount", smod.amount, -2.0f, 2.0f, objsize);
  360. smod.dir = AngleSlider("Dir", smod.dir, 1.0f);
  361. smod.axis = (MegaAxis)XYZ("Axis", (int)smod.axis);
  362. }
  363. break;
  364. case "Melt":
  365. MegaMelt mmod = (MegaMelt)mod;
  366. mmod.Amount = Slider("Amount ", mmod.Amount, 0.0f, 100.0f);
  367. mmod.Spread = Slider("Spread", mmod.Spread, 0.0f, 100.0f);
  368. InitMatList();
  369. GUILayout.Label("Solidity");
  370. mmod.MaterialType = (MegaMeltMat)GUILayout.SelectionGrid((int)mmod.MaterialType, MatList, 2, "toggle");
  371. if ( mmod.MaterialType == MegaMeltMat.Custom )
  372. mmod.Solidity = Slider("Custom", mmod.Solidity, 0.0f, 10.0f);
  373. mmod.axis = (MegaAxis)XYZ("Axis", (int)mmod.axis);
  374. mmod.FlipAxis = GUILayout.Toggle(mmod.FlipAxis, "Flip Axis");
  375. break;
  376. }
  377. }
  378. public void ShowGUI()
  379. {
  380. if ( context )
  381. {
  382. GUI.color = Color.white;
  383. if ( GUILayout.Button("Logo Params", GUILayout.Width(butwidth)) )
  384. showparams = showparams ? false : true;
  385. if ( showparams )
  386. {
  387. context.Enabled = GUILayout.Toggle(context.Enabled, "Enabled");
  388. context.recalcnorms = GUILayout.Toggle(context.recalcnorms, "Recalc Normals");
  389. showcommon = GUILayout.Toggle(showcommon, "Common Params");
  390. for ( int i = 0; i < mods.Length; i++ )
  391. {
  392. ShowCommon(mods[i], i);
  393. if ( showmod[i] )
  394. ShowGUI(mods[i]);
  395. }
  396. }
  397. }
  398. }
  399. void ShowGroundGUI()
  400. {
  401. if ( gcontext )
  402. {
  403. GUI.color = Color.white;
  404. if ( GUILayout.Button("Ground Params", GUILayout.Width(butwidth)) )
  405. showgparams = showgparams ? false : true;
  406. if ( showgparams )
  407. {
  408. gcontext.Enabled = GUILayout.Toggle(gcontext.Enabled, "Enabled");
  409. gcontext.recalcnorms = GUILayout.Toggle(gcontext.recalcnorms, "Recalc Normals");
  410. showgcommon = GUILayout.Toggle(showgcommon, "Common Params");
  411. for ( int i = 0; i < gmods.Length; i++ )
  412. {
  413. ShowGCommon(gmods[i], i);
  414. if ( showgmod[i] )
  415. ShowGUI(gmods[i]);
  416. }
  417. }
  418. }
  419. }
  420. public bool ShowGui = true;
  421. public float dsize = 10.0f;
  422. public float svd = 0.9f;
  423. float svh = 0.0f;
  424. void DoWindow(int windowID)
  425. {
  426. pos = GUILayout.BeginScrollView(pos, GUILayout.Width(sx), GUILayout.Height(svh));
  427. if ( mat != null )
  428. {
  429. Color col = mat.color;
  430. mat.color = ColSlider("Col", ref col, 0.0f, 1.0f, 2.0f);
  431. }
  432. if ( gmat != null )
  433. {
  434. Color col = gmat.color;
  435. gmat.color = ColSlider("Ground", ref col, 0.0f, 1.0f, 2.0f);
  436. }
  437. ShowGUI();
  438. ShowGroundGUI();
  439. GUILayout.EndScrollView();
  440. GUI.DragWindow();
  441. }
  442. void Update()
  443. {
  444. if ( Input.GetKeyUp(KeyCode.Escape) )
  445. {
  446. ShowGui = ShowGui ? false : true;
  447. }
  448. }
  449. void SizeChange()
  450. {
  451. windowRect.yMax = windowRect.yMin + (Screen.height - dsize);
  452. svh = (windowRect.yMax - windowRect.yMin) - svd; //(float)Screen.height * 0.5f; // - dsize; //25.0f; //* 0.955f;
  453. lastscreenheight = Screen.height;
  454. }
  455. float lastscreenheight = 0.0f;
  456. public GUISkin skin;
  457. void OnGUI()
  458. {
  459. if ( ShowGui && mods != null )
  460. {
  461. GUI.skin = skin;
  462. if ( Screen.height != lastscreenheight )
  463. {
  464. SizeChange();
  465. }
  466. windowRect = GUILayout.Window(0, windowRect, DoWindow, source.name + " - Modifiers", GUILayout.Width(100)); //, GUILayout.MinWidth(150), GUILayout.MaxWidth(400)); //BeginArea(new Rect(10, 5, 175, 700));
  467. }
  468. else
  469. {
  470. //float fps = 1.0f / Time.smoothDeltaTime;
  471. //GUI.Label(new Rect(0, 0, 100, 32), fps.ToString("0.0"));
  472. }
  473. }
  474. }