PocHelper.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public static class PocHelper
  5. {
  6. public static void SetLayer(Transform t, int layer)
  7. {
  8. t.gameObject.layer = layer;
  9. for (int i = 0; i < t.childCount; i++)
  10. {
  11. SetLayer(t.GetChild(i), layer);
  12. }
  13. }
  14. public static void SetObjectCameraMirror(Transform t, bool mirror, int resolutionWidth = 0)
  15. {
  16. Camera[] cameras = t.GetComponentsInChildren<Camera>(true);
  17. for (int i = 0; i < cameras.Length; i++)
  18. {
  19. CameraImageMirror cim = cameras[i].gameObject.GetComponent<CameraImageMirror>();
  20. if (cim == null)
  21. cim = cameras[i].gameObject.AddComponent<CameraImageMirror>();
  22. cim.enabled = mirror;
  23. if (mirror)
  24. PostEffectHelper.renderTextureWidth = resolutionWidth;
  25. }
  26. }
  27. public static void PlaySound(AudioClip clip, bool repeat = false)
  28. {
  29. }
  30. public static void StopSound(AudioClip clip)
  31. {
  32. }
  33. public static void PlayGoAnim(GameObject go, string animOrStateName)
  34. {
  35. go.SetActive(true);
  36. Animation anim = go.GetComponent<Animation>();
  37. if (anim != null)
  38. {
  39. anim.enabled = true;
  40. if (string.IsNullOrEmpty(animOrStateName))
  41. {
  42. if (anim.playAutomatically)
  43. {
  44. go.SetActive(false);
  45. go.SetActive(true);
  46. }
  47. else
  48. anim.Play();
  49. }
  50. else
  51. anim.Play(animOrStateName);
  52. }
  53. else
  54. {
  55. Animator animator = go.GetComponent<Animator>();
  56. if (animator != null)
  57. {
  58. animator.enabled = true;
  59. if (!string.IsNullOrEmpty(animOrStateName))
  60. animator.Play(animOrStateName);
  61. }
  62. }
  63. }
  64. public static void StopGoAnim(GameObject go)
  65. {
  66. go.SetActive(true);
  67. Animation anim = go.GetComponent<Animation>();
  68. if (anim != null && anim.isPlaying)
  69. anim.Stop();
  70. else
  71. {
  72. Animator animator = go.GetComponent<Animator>();
  73. if (animator != null && animator.enabled)
  74. animator.StopPlayback();
  75. }
  76. }
  77. public static GameObject CreateTransformHolder(GameObject go)
  78. {
  79. if (go == null)
  80. return null;
  81. GameObject holder = new GameObject("Holder_" + go.name);
  82. holder.transform.SetParent(go.transform.parent);
  83. holder.transform.localPosition = Vector3.zero;
  84. holder.transform.localEulerAngles = Vector3.zero;
  85. holder.transform.localScale = Vector3.one;
  86. holder.SetActive(go.activeInHierarchy);
  87. go.transform.SetParent(holder.transform);
  88. go.SetActive(true);
  89. return holder;
  90. }
  91. public static Transform CreateTransformHolder(Transform t)
  92. {
  93. if (t == null)
  94. return null;
  95. return CreateTransformHolder(t.gameObject).transform;
  96. }
  97. public static bool IsPlayingAnim(Animator[] animators, bool ignoreRepeatMotion = true)
  98. {
  99. if (animators == null || animators.Length == 0)
  100. return false;
  101. for(int idx =0; idx < animators.Length;idx++)
  102. {
  103. Animator anim = animators[idx];
  104. if (anim.enabled)
  105. {
  106. if (anim.IsInTransition(0))
  107. return true;
  108. AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
  109. if (ignoreRepeatMotion)
  110. {
  111. if (stateInfo.length > 0 && stateInfo.normalizedTime < 1)
  112. return true;
  113. }
  114. else
  115. {
  116. if (stateInfo.length > 0 && (stateInfo.normalizedTime < 1 || stateInfo.loop))
  117. return true;
  118. }
  119. }
  120. }
  121. return false;
  122. }
  123. public static bool IsPlayingAnim(GameObject go, bool ignoreRepeatMotion = true)
  124. {
  125. Animator[] animators = go.GetComponentsInChildren<Animator>();
  126. for (int i = 0; i < animators.Length; i++)
  127. {
  128. if (animators[i].enabled)
  129. {
  130. if (animators[i].IsInTransition(0))
  131. return true;
  132. AnimatorStateInfo stateInfo = animators[i].GetCurrentAnimatorStateInfo(0);
  133. if (ignoreRepeatMotion)
  134. {
  135. if (stateInfo.length > 0 && stateInfo.normalizedTime < 1)
  136. return true;
  137. }
  138. else
  139. {
  140. if (stateInfo.length > 0 && (stateInfo.normalizedTime < 1 || stateInfo.loop))
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. public static bool IsInRange(this Vector3 v, Vector3 min, Vector3 max, float compareDeviation)
  148. {
  149. return v.x >= min.x - compareDeviation && v.x <= max.x + compareDeviation
  150. && v.y >= min.y - compareDeviation && v.y <= max.y + compareDeviation
  151. && v.z >= min.z - compareDeviation && v.z <= max.z + compareDeviation;
  152. }
  153. public static bool IsInRange(this Vector3 v, Vector3 min, Vector3 max)
  154. {
  155. return v.x >= min.x && v.x <= max.x
  156. && v.y >= min.y && v.y <= max.y
  157. && v.z >= min.z && v.z <= max.z;
  158. }
  159. public static Vector3 ClampPosition(this Vector3 v, Vector3 min, Vector3 max)
  160. {
  161. return new Vector3(Mathf.Clamp(v.x, min.x, max.x), Mathf.Clamp(v.y, min.y, max.y), Mathf.Clamp(v.z, min.z, max.z));
  162. }
  163. public static Vector3 RandomPosition(Vector3 min, Vector3 max)
  164. {
  165. return new Vector3 (Random.Range (min.x, max.x), Random.Range (min.y, max.y), Random.Range (min.z, max.z));
  166. }
  167. public static bool DirEqual(this Vector3 v1, Vector3 v2, float compareDeviation = 1e-3f)
  168. {
  169. if (Mathf.Abs(v1.x) < Mathf.Abs(v1.y))
  170. {
  171. if (Mathf.Abs(v1.y) < Mathf.Abs(v1.z))
  172. {
  173. //max z
  174. if (v1.z.FEqual(0, compareDeviation))
  175. return v2.FEqual(Vector3.zero, compareDeviation);
  176. else
  177. return v2.z * v1.z > 0 && v2.FEqual(v1 * (v2.z / v1.z), compareDeviation);
  178. }
  179. else
  180. {
  181. //max y
  182. if (v1.y.FEqual(0, compareDeviation))
  183. return v2.FEqual(Vector3.zero, compareDeviation);
  184. else
  185. return v2.y * v1.y > 0 && v2.FEqual(v1 * (v2.y / v1.y), compareDeviation);
  186. }
  187. }
  188. else if (Mathf.Abs(v1.x) < Mathf.Abs(v1.z))
  189. {
  190. //max z
  191. if (v1.z.FEqual(0, compareDeviation))
  192. return v2.FEqual(Vector3.zero, compareDeviation);
  193. else
  194. return v2.z * v1.z > 0 && v2.FEqual(v1 * (v2.z / v1.z), compareDeviation);
  195. }
  196. else
  197. {
  198. //max x
  199. if (v1.x.FEqual(0, compareDeviation))
  200. return v2.FEqual(Vector3.zero, compareDeviation);
  201. else
  202. return v2.x * v1.x > 0 && v2.FEqual(v1 * (v2.x / v1.x), compareDeviation);
  203. }
  204. }
  205. //两直线最短距离,要求d1,d2为标准化向量
  206. public static float MinSqrDistanceOfLine(Vector3 p1, Vector3 d1, Vector3 p2, Vector3 d2, out float resultT1, out float resultT2)
  207. {
  208. Vector3 c = Vector3.Cross(d1, d2);
  209. float sqrMagnitude = Vector3.SqrMagnitude(c);
  210. if (sqrMagnitude < 1e-5f)
  211. {
  212. //平行/重合
  213. resultT1 = 0;
  214. resultT2 = Vector3.Dot(p1 - p2, d2);
  215. return Vector3.SqrMagnitude(p1 - (p2 + resultT2 * d2));
  216. }
  217. else
  218. {
  219. resultT1 = Vector3.Dot(Vector3.Cross((p2 - p1), d2), c) / sqrMagnitude;
  220. resultT2 = Vector3.Dot(Vector3.Cross((p2 - p1), d1), c) / sqrMagnitude;
  221. return Vector3.SqrMagnitude((p1 + resultT1 * d1) - (p2 + resultT2 * d2));
  222. }
  223. }
  224. public static float SqrDistanceToLine(this Vector3 p, Vector3 p0, Vector3 d, out float t)
  225. {
  226. t = Vector3.Dot(p - p0, d);
  227. return Vector3.SqrMagnitude(p - (p0 + t * d));
  228. }
  229. public static bool RayHitCheckCylinder(Ray r, Vector3 p, float radius, float height)
  230. {
  231. float sqrRadius = radius * radius;
  232. float t1, t2;
  233. float minSqrDistance = MinSqrDistanceOfLine(r.origin, r.direction, p, Vector3.up, out t1, out t2);
  234. if (minSqrDistance >= sqrRadius)
  235. return false;
  236. if (t1 < 0)
  237. {
  238. minSqrDistance = r.origin.SqrDistanceToLine(p, Vector3.up, out t2);
  239. if (minSqrDistance >= sqrRadius)
  240. return false;
  241. if (t2 <= 0 || t2 >= height)
  242. minSqrDistance = Mathf.Min(Vector3.SqrMagnitude(p - r.origin), Vector3.SqrMagnitude(p + Vector3.up * height - r.origin));
  243. return minSqrDistance < sqrRadius;
  244. }
  245. else
  246. {
  247. if (t2 <= 0 || t2 >= height)
  248. minSqrDistance = Mathf.Min(
  249. p.SqrDistanceToLine(r.origin, r.direction, out t1),
  250. (p + Vector3.up * height).SqrDistanceToLine(r.origin, r.direction, out t1)
  251. );
  252. return minSqrDistance < sqrRadius;
  253. }
  254. }
  255. public static Transform SearchFirstInChildrenByName(this Transform t, string name)
  256. {
  257. if (t.name == name)
  258. return t;
  259. for (int i = 0; i < t.childCount; i++)
  260. {
  261. Transform found = SearchFirstInChildrenByName(t.GetChild(i), name);
  262. if (found != null)
  263. return found;
  264. }
  265. return null;
  266. }
  267. public static void AttachChild(this Transform t, Transform child, string path = null, bool isFullPath = true)
  268. {
  269. if (string.IsNullOrEmpty(path))
  270. child.SetParent(t);
  271. else
  272. {
  273. if (isFullPath)
  274. {
  275. Transform attachParent = t.Find(path);
  276. if (attachParent != null)
  277. child.SetParent(attachParent);
  278. }
  279. else
  280. {
  281. Transform attachParent = t.SearchFirstInChildrenByName(path);
  282. if (attachParent != null)
  283. child.SetParent(attachParent);
  284. }
  285. }
  286. }
  287. public delegate bool CheckObjectCallback<T>(T element);
  288. public delegate void DoObjectCallback<T>(T element);
  289. public delegate T2 ConvertObjectCallback<T1, T2>(T1 element);
  290. public static int CheckElementCount<T>(this T[] srcArray, CheckObjectCallback<T> cb)
  291. {
  292. int cnt = 0;
  293. for (int i = 0; i < srcArray.Length; i++)
  294. {
  295. if (cb(srcArray[i]))
  296. cnt++;
  297. }
  298. return cnt;
  299. }
  300. public static bool CheckAll<T>(this T[] srcArray, CheckObjectCallback<T> cb)
  301. {
  302. for (int i = 0; i < srcArray.Length; i++)
  303. {
  304. if (!cb(srcArray[i]))
  305. return false;
  306. }
  307. return true;
  308. }
  309. public static int CheckElementCount<T>(this System.Collections.Generic.List<T> srcList, CheckObjectCallback<T> cb)
  310. {
  311. int cnt = 0;
  312. for (int i = 0; i < srcList.Count; i++)
  313. {
  314. if (cb(srcList[i]))
  315. cnt++;
  316. }
  317. return cnt;
  318. }
  319. public static bool CheckAll<T>(this System.Collections.Generic.List<T> srcList, CheckObjectCallback<T> cb)
  320. {
  321. for (int i = 0; i < srcList.Count; i++)
  322. {
  323. if (!cb(srcList[i]))
  324. return false;
  325. }
  326. return true;
  327. }
  328. public static System.Collections.Generic.List<T> SelectFromArray<T>(this T[] srcArray, CheckObjectCallback<T> cb)
  329. {
  330. System.Collections.Generic.List<T> resultList = new System.Collections.Generic.List<T>();
  331. for (int i = 0; i < srcArray.Length; i++)
  332. {
  333. if (cb(srcArray[i]))
  334. resultList.Add(srcArray[i]);
  335. }
  336. return resultList;
  337. }
  338. public static void DoForAll<T>(this T[] srcArray, DoObjectCallback<T> cb)
  339. {
  340. for (int i = 0; i < srcArray.Length; i++)
  341. cb(srcArray[i]);
  342. }
  343. public static System.Collections.Generic.List<T> SelectFromList<T>(this System.Collections.Generic.List<T> srcList, CheckObjectCallback<T> cb)
  344. {
  345. System.Collections.Generic.List<T> resultList = new System.Collections.Generic.List<T>();
  346. for (int i = 0; i < srcList.Count; i++)
  347. {
  348. if (cb(srcList[i]))
  349. resultList.Add(srcList[i]);
  350. }
  351. return resultList;
  352. }
  353. public static void DoForAll<T>(this System.Collections.Generic.List<T> srcList, DoObjectCallback<T> cb)
  354. {
  355. for (int i = 0; i < srcList.Count; i++)
  356. cb(srcList[i]);
  357. }
  358. public static T FindFirst<T>(this T[] srcArray, CheckObjectCallback<T> cb)
  359. {
  360. for (int i = 0; i < srcArray.Length; i++)
  361. {
  362. if (cb(srcArray[i]))
  363. return srcArray[i];
  364. }
  365. return default(T);
  366. }
  367. public static int IndexOf<T>(this T[] srcArray, CheckObjectCallback<T> cb)
  368. {
  369. for (int i = 0; i < srcArray.Length; i++)
  370. {
  371. if (cb(srcArray[i]))
  372. return i;
  373. }
  374. return -1;
  375. }
  376. public static T FindFirst<T>(this System.Collections.Generic.List<T> srcList, CheckObjectCallback<T> cb)
  377. {
  378. for (int i = 0; i < srcList.Count; i++)
  379. {
  380. if (cb(srcList[i]))
  381. return srcList[i];
  382. }
  383. return default(T);
  384. }
  385. public static T2[] ConvertArray<T1, T2>(this T1[] srcArray, ConvertObjectCallback<T1, T2> cb)
  386. {
  387. T2[] result = new T2[srcArray.Length];
  388. for (int i = 0; i < srcArray.Length; i++)
  389. result[i] = cb(srcArray[i]);
  390. return result;
  391. }
  392. public static void RemoveComponentsInChildren<T>(this Transform t) where T : Component
  393. {
  394. for (int i = 0; i < t.childCount; i++)
  395. RemoveComponentsInChildren<T>(t.GetChild(i));
  396. while (t.GetComponent<T>() != null)
  397. {
  398. T com = t.GetComponent<T>();
  399. GameObject.DestroyImmediate(com);
  400. }
  401. }
  402. public static int MiddleSearch<T>(this System.Collections.Generic.List<T> list, int idx, CheckObjectCallback<T> cb)
  403. {
  404. if (idx < list.Count && idx >= 0)
  405. {
  406. if (cb(list[idx]))
  407. return idx;
  408. }
  409. int offset = 1;
  410. while (idx + offset < list.Count || idx - offset >= 0)
  411. {
  412. if (idx + offset >= 0 && idx + offset < list.Count && cb(list[idx + offset]))
  413. return idx + offset;
  414. if (idx - offset >= 0 && idx - offset < list.Count && cb(list[idx - offset]))
  415. return idx - offset;
  416. offset++;
  417. }
  418. return -1;
  419. }
  420. public static void ResetAnimationToStart(Animation anim)
  421. {
  422. if (anim != null && anim.clip != null)
  423. {
  424. string name = anim.clip.name;
  425. anim[name].speed = -1;
  426. anim.Play(name);
  427. }
  428. }
  429. public static void ReplayResetAnimation(Animation anim)
  430. {
  431. if (anim != null && anim.clip != null)
  432. {
  433. string name = anim.clip.name;
  434. anim[name].speed = 1;
  435. anim.Play(name);
  436. }
  437. }
  438. public static string FormatDescription(string desc, float seconds, float[] values, float rate = 1f, int secondPrecision = 0, int percentPrecision = 1, int valuePrecision = 0)
  439. {
  440. string result = desc;
  441. if (result.Contains("%t"))
  442. result = result.Replace("%t", seconds.ToString("F" + secondPrecision.ToString()));
  443. if (result.Contains("%r"))
  444. result = result.Replace("%r", (rate * 100).ToString("F" + percentPrecision.ToString()));
  445. int idx = 0;
  446. while (idx < values.Length)
  447. {
  448. float value = values[idx];
  449. char c = (char)('a' + idx);
  450. if (result.Contains("%" + c))
  451. result = result.Replace("%" + c, (value * 0.01f).ToString("F" + percentPrecision.ToString()));
  452. char C = (char)('A' + idx);
  453. if (result.Contains("%" + C))
  454. result = result.Replace("%" + C, value.ToString("F" + valuePrecision.ToString()));
  455. idx++;
  456. }
  457. result = result.Replace("%%", "%");
  458. return result;
  459. }
  460. public static string FormatUpgradeDescription(string desc, float seconds, float[] values, float rate, float deltaSeconds, float[] deltaValues, float deltaRate, int secondPrecision = 0, int percentPrecision = 1, int valuePrecision = 0)
  461. {
  462. string result = desc;
  463. if (result.Contains ("%t")) {
  464. if (deltaSeconds < 1e-4f)
  465. result = result.Replace ("%t", seconds.ToString ("F" + secondPrecision.ToString ()));
  466. else
  467. result = result.Replace ("%t", seconds.ToString ("F" + secondPrecision.ToString ())
  468. + string.Format ("(+{0})", deltaSeconds.ToString ("F" + secondPrecision.ToString ())));
  469. }
  470. if (result.Contains ("%r")) {
  471. if (deltaRate < 1e-4f)
  472. result = result.Replace ("%r", (rate * 100).ToString ("F" + percentPrecision.ToString ()));
  473. else
  474. result = result.Replace ("%r", (rate * 100).ToString ("F" + percentPrecision.ToString ())
  475. + string.Format ("(+{0})", (deltaRate * 100).ToString ("F" + percentPrecision.ToString ())));
  476. }
  477. int idx = 0;
  478. while (idx < values.Length)
  479. {
  480. float value = values[idx];
  481. float addValue = deltaValues[idx];
  482. char c = (char)('a' + idx);
  483. if (result.Contains ("%" + c)) {
  484. if (addValue < 1e-4f)
  485. result = result.Replace ("%" + c, (value * 0.01f).ToString ("F" + percentPrecision.ToString ()));
  486. else
  487. result = result.Replace ("%" + c, (value * 0.01f).ToString ("F" + percentPrecision.ToString ())
  488. + string.Format ("(+{0}%)", (addValue * 0.01f).ToString ("F" + percentPrecision.ToString ())));
  489. }
  490. char C = (char)('A' + idx);
  491. if (result.Contains ("%" + C)) {
  492. if (addValue < 1e-4f)
  493. result = result.Replace ("%" + C, value.ToString ("F" + valuePrecision.ToString ()));
  494. else
  495. result = result.Replace ("%" + C, value.ToString ("F" + valuePrecision.ToString ())
  496. + string.Format ("(+{0})", addValue.ToString ("F" + valuePrecision.ToString ())));
  497. }
  498. idx++;
  499. }
  500. result = result.Replace("%%", "%");
  501. return result;
  502. }
  503. public static string FormatDescription(string desc, float seconds, float[] values, float[] nextValues, float rate = 1f, int secondPrecision = 0, int percentPrecision = 1, int valuePrecision = 0)
  504. {
  505. string result = desc;
  506. if (result.Contains("%t"))
  507. result = result.Replace("%t", seconds.ToString("F" + secondPrecision.ToString()));
  508. if (result.Contains("%r"))
  509. result = result.Replace("%r", (rate * 100).ToString("F" + percentPrecision.ToString()));
  510. int idx = 0;
  511. while (idx < values.Length)
  512. {
  513. float value = values[idx];
  514. float nextValue = nextValues[idx];
  515. char c = (char)('a' + idx);
  516. if (result.Contains("%" + c))
  517. result = result.Replace("%" + c, (value * 0.01f).ToString("F" + percentPrecision.ToString()));
  518. if (result.Contains("%(" + c + "+1)"))
  519. result = result.Replace("%(" + c + "+1)", (nextValue * 0.01f).ToString("F" + percentPrecision.ToString()));
  520. char C = (char)('A' + idx);
  521. if (result.Contains("%" + C))
  522. result = result.Replace("%" + C, value.ToString("F" + valuePrecision.ToString()));
  523. if (result.Contains("%(" + C + "+1)"))
  524. result = result.Replace("%(" + C + "+1)", nextValue.ToString("F" + valuePrecision.ToString()));
  525. idx++;
  526. }
  527. result = result.Replace("%%", "%");
  528. return result;
  529. }
  530. public static Vector3 ConvertCfgVector3(object obj)
  531. {
  532. try
  533. {
  534. float[] values = ((List<object>)obj).ConvertAll(a =>
  535. {
  536. if (a.GetType() == typeof(System.Single))
  537. return (float)a;
  538. else if (a.GetType() == typeof(System.Int32))
  539. return (float)(System.Int32)a;
  540. else return (float)a;
  541. }).ToArray();
  542. return new Vector3(values[0], values[1], values[2]);
  543. }
  544. catch
  545. {
  546. //Log.E("ConvertCfgVector3:{0}", obj.ToString());
  547. return Vector3.zero;
  548. }
  549. }
  550. public static Vector2 ConvertCfgVector2(object obj)
  551. {
  552. try
  553. {
  554. float[] values = ((List<object>)obj).ConvertAll(a =>
  555. {
  556. if (a.GetType() == typeof(System.Single))
  557. return (float)a;
  558. else if (a.GetType() == typeof(System.Int32))
  559. return (float)(System.Int32)a;
  560. else return (float)a;
  561. }).ToArray();
  562. return new Vector2(values[0], values[1]);
  563. }
  564. catch
  565. {
  566. //Log.E("ConvertCfgVector2:{0}", obj.ToString());
  567. return Vector2.zero;
  568. }
  569. }
  570. #if UNITY_EDITOR
  571. public static void DrawDirCubeGizmos(Vector3 pos, Vector3 size, Vector3 forward, Vector3 up)
  572. {
  573. Vector3 right = Vector3.Cross (forward, up);
  574. Vector3 halfSize = 0.5f * size;
  575. Vector3 v1 = pos - halfSize.x * right - halfSize.y * up - halfSize.z * forward;
  576. Vector3 v2 = v1 + size.x * right;
  577. Vector3 v3 = v2 + size.z * forward;
  578. Vector3 v4 = v1 + size.z * forward;
  579. Vector3 v5 = v1 + size.y * up;
  580. Vector3 v6 = v2 + size.y * up;
  581. Vector3 v7 = v3 + size.y * up;
  582. Vector3 v8 = v4 + size.y * up;
  583. Gizmos.DrawLine (v1, v2);
  584. Gizmos.DrawLine (v2, v3);
  585. Gizmos.DrawLine (v3, v4);
  586. Gizmos.DrawLine (v4, v1);
  587. Gizmos.DrawLine (v5, v6);
  588. Gizmos.DrawLine (v6, v7);
  589. Gizmos.DrawLine (v7, v8);
  590. Gizmos.DrawLine (v8, v5);
  591. Gizmos.DrawLine (v1, v5);
  592. Gizmos.DrawLine (v2, v6);
  593. Gizmos.DrawLine (v3, v7);
  594. Gizmos.DrawLine (v4, v8);
  595. }
  596. #endif
  597. }