TD.cs 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. namespace TerrainComposer2
  6. {
  7. static public class TD
  8. {
  9. static public List<Rect> rectSelectList = new List<Rect>();
  10. static public bool showSelectRect;
  11. static public Vector2 posClickMouseDown;
  12. static public int mouseDownButton;
  13. static public TC_ItemBehaviour dropItemReceive;
  14. static public bool startDrag;
  15. static public Event eventCurrent;
  16. static public int countDrawNode;
  17. static public int countDrawNodeCulled;
  18. static public int countDrawTextures;
  19. static public Rect rectWindow;
  20. static public Vector2 scrollOffset, newScrollOffset;
  21. static public bool setNewScrollOffset;
  22. static public float scale = 1;
  23. static public Vector2 scrollMax;
  24. static public bool tooltip;
  25. static public Rect rectTooltip;
  26. static public float tooltipStartTime;
  27. static public float tooltipTime;
  28. static public float labelHeight = 14;
  29. static public float mouseSensivity = 1;
  30. static public float mouseScrollWheelSensivity = 1;
  31. static public float outputBarTopHeight = 40;
  32. static public float outputBarHeightSpace = outputBarTopHeight + 2;
  33. static public float outputBarWidth = 5;
  34. static public float outputBarBottomHeight = 5;
  35. static public float layerGroupBarTopHeight = 30;
  36. static public float layerGroupBarWidth = 5;
  37. static public float layerGroupBarBottomHeight = 5;
  38. static public float layerBarTopHeight = 20;
  39. static public float layerBarWidth = 5;
  40. static public float layerBarBottomHeight = 5;
  41. static public float layerGroupHeight = 20;
  42. static public float layerGroupHeightSpace = layerGroupHeight + 2;
  43. // static public float nodeWidth = 75;
  44. //static public float nodeHeight = 120;
  45. static public float nodeWidthSpace = 20 + 3;
  46. static public float nodeHeightSpace = 20 + 3;
  47. static public float nodeBorderWidth = 3;
  48. static public Texture buttonLeft;
  49. static public Texture buttonRight;
  50. static public Texture buttonDown;
  51. static public Texture buttonUp;
  52. static public Texture enumBG_Start;
  53. static public Texture enumBG_Middle;
  54. static public Texture enumBG_End;
  55. static public Texture texFadeBar;
  56. static public Texture buttonMinus;
  57. static public Texture buttonPlus;
  58. static public Texture inActiveTexture, inActiveChildrenTexture, vertLineTexture;
  59. static public Texture[] outputButtons;
  60. static public Texture texShelfBackground1, texShelfBackGround2, texConnectionIndicator;
  61. static public Texture texShelfLinesConnectDown, texShelfLinesConnectUp, texShelfLinesHorizontal, texShelfLinesVertical;
  62. static public Texture texShelfStart, texShelfStartConnect, texShelfStartOutput, texShelfStartOutputCollapsed;
  63. static public Texture texShelfLayer, texShelfLayerStart1, texShelfLayerStart2, texShelfLayerCollapsed, texShelfLayerCollapsedStart1, texShelfLayerCollapsedStart2;
  64. static public Texture texCardHeader, texCardBody, texBracketHeader, texBracketBody, texButton, texInwardButton;
  65. static public Texture texLineConnectDown, texLineConnectUp, texLineFirstLayer, texLineHorizontal, texLineLayerStart1, texLineLayerStart2, texLineLayerCollapsedStart1, texLineVertical;
  66. static public Texture texBracketRight, texBracketLeft, texCardCounter, texAddFirstCard;
  67. static public Texture texOperandBG, texOperandAdd, texOperandSubtract, texOperandLerp, texOperandMultiply, texOperandDivide, texOperandDiff, texOperandAverage, texOperandMin, texOperandMax, texOperandEqual;
  68. static public Texture texSeparatorLeft, texSeparatorCenter, texSeparatorRight;
  69. static public Texture texEye, texEyeClosed, texFoldout, texLocked, texUnlocked, texPortal;
  70. static public Texture texDragIconVertical, texDragIconHorizontal, texSelectCard, texSelectCardHeader;
  71. static public TC_Settings settings;
  72. static public TC_GlobalSettings g;
  73. static public TC_ItemBehaviour selectedOpacityItem;
  74. static public TC_ItemBehaviour hoverItem, hoverItemOld;
  75. static public float editorSkinMulti;
  76. static public bool Init()
  77. {
  78. if (TC_Settings.instance != null)
  79. {
  80. settings = TC_Settings.instance;
  81. g = settings.global;
  82. }
  83. else return false;
  84. if (TC.installPath == "") return false;
  85. editorSkinMulti = EditorGUIUtility.isProSkin ? 1 : 0.35f;
  86. if (texPortal == null)
  87. {
  88. buttonMinus = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/Button_Minus.psd", typeof(Texture));
  89. buttonPlus = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/Button_Plus.psd", typeof(Texture));
  90. buttonLeft = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/arrow_left.png", typeof(Texture));
  91. buttonRight = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/arrow_right.png", typeof(Texture));
  92. buttonDown = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/arrow_bottom.png", typeof(Texture));
  93. buttonUp = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/arrow_top.png", typeof(Texture));
  94. enumBG_Start = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/EnumBG_Start.png", typeof(Texture));
  95. enumBG_Middle = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/EnumBG_Middle.png", typeof(Texture));
  96. enumBG_End = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/EnumBG_End.png", typeof(Texture));
  97. texFadeBar = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/FadeBar.psd", typeof(Texture));
  98. if (outputButtons == null) outputButtons = new Texture[6];
  99. outputButtons[0] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_heightmap.png", typeof(Texture));
  100. outputButtons[1] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_colormap.png", typeof(Texture));
  101. outputButtons[2] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_splatmap.png", typeof(Texture));
  102. outputButtons[3] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_tree.png", typeof(Texture));
  103. outputButtons[4] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_grass.png", typeof(Texture));
  104. outputButtons[5] = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/button_objects.png", typeof(Texture));
  105. inActiveTexture = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/InActivePreview.psd", typeof(Texture));
  106. inActiveChildrenTexture = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/InActiveChildrenPreview.psd", typeof(Texture));
  107. vertLineTexture = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/GradientLine2.psd", typeof(Texture));
  108. texCardBody = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Card_Body.png", typeof(Texture));
  109. texCardHeader = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Card_Header.png", typeof(Texture));
  110. texBracketHeader = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Bracket_Header.png", typeof(Texture));
  111. texBracketBody = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Bracket_Body.png", typeof(Texture));
  112. texBracketLeft = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Bracket_Left.png", typeof(Texture));
  113. texBracketRight = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Bracket_Right.png", typeof(Texture));
  114. texButton = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Button.png", typeof(Texture));
  115. texInwardButton = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/InwardButton.png", typeof(Texture));
  116. texOperandBG = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandBG.png", typeof(Texture));
  117. texOperandAdd = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandAdd.png", typeof(Texture));
  118. texOperandSubtract = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandSubtract.png", typeof(Texture));
  119. texOperandLerp = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandLerp.png", typeof(Texture));
  120. texOperandMultiply = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandMultiply.png", typeof(Texture));
  121. texOperandDivide = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandDivide.png", typeof(Texture));
  122. texOperandDiff = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandDiff.png", typeof(Texture));
  123. texOperandAverage = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandAverage.png", typeof(Texture));
  124. texOperandMin = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandMin.png", typeof(Texture));
  125. texOperandMax = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandMax.png", typeof(Texture));
  126. texOperandEqual = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/OperandEqual.png", typeof(Texture));
  127. texEye = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Eye.png", typeof(Texture));
  128. texEyeClosed = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/EyeClosed.png", typeof(Texture));
  129. texFoldout = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Foldout.png", typeof(Texture));
  130. texLocked = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Lock_Closed.png", typeof(Texture));
  131. texUnlocked = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Lock_Open.png", typeof(Texture));
  132. texPortal = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Portal.png", typeof(Texture));
  133. string shelfFolder = "Fixed/";
  134. // string shelfFolder = "";
  135. texShelfBackground1 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Background1.png", typeof(Texture));
  136. texShelfBackGround2 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Background2.png", typeof(Texture));
  137. texConnectionIndicator = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/ConnectionIndicator.png", typeof(Texture));
  138. texSeparatorLeft = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Separator_Left.png", typeof(Texture));
  139. texSeparatorCenter = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Separator_Center.png", typeof(Texture));
  140. texSeparatorRight = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Separator_Right.png", typeof(Texture));
  141. texCardCounter = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/CardCounter.png", typeof(Texture));
  142. texAddFirstCard = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/AddFirstCard.png", typeof(Texture));
  143. texShelfStart = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_TreeStart/" + shelfFolder + "Shelf_Start.png", typeof(Texture));
  144. texShelfStartConnect = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_TreeStart/" + shelfFolder + "Shelf_Start_Connect.png", typeof(Texture));
  145. texShelfStartOutput = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_TreeStart/" + shelfFolder + "Shelf_Start_FirstLayer.png", typeof(Texture));
  146. texShelfStartOutputCollapsed = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_TreeStart/" + shelfFolder + "Shelf_Start_FirstLayer_Collapsed.png", typeof(Texture));
  147. texShelfLayer = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_Layer.png", typeof(Texture));
  148. texShelfLayerStart1 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_Layer_Start1.png", typeof(Texture));
  149. texShelfLayerStart2 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_Layer_Start2.png", typeof(Texture));
  150. texShelfLayerCollapsed = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_LayerCollapsed.png", typeof(Texture));
  151. texShelfLayerCollapsedStart1 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_LayerCollapsed_Start1.png", typeof(Texture));
  152. texShelfLayerCollapsedStart2 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Layer/" + shelfFolder + "Shelf_LayerCollapsed_Start2.png", typeof(Texture));
  153. texShelfLinesConnectDown = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Lines/" + shelfFolder + "Shelf_Lines_ConnectDown.png", typeof(Texture));
  154. texShelfLinesConnectUp = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Lines/" + shelfFolder + "Shelf_Lines_ConnectUp.png", typeof(Texture));
  155. texShelfLinesHorizontal = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Lines/" + shelfFolder + "Shelf_Lines_Horizontal.png", typeof(Texture));
  156. texShelfLinesVertical = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Shelf/Shelf_Lines/" + shelfFolder + "Shelf_Lines_Vertical.png", typeof(Texture));
  157. texLineConnectDown = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_ConnectDown.png", typeof(Texture));
  158. texLineConnectUp = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_ConnectUp.png", typeof(Texture));
  159. texLineFirstLayer = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_FirstLayer.png", typeof(Texture));
  160. texLineHorizontal = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_Horizontal.png", typeof(Texture));
  161. texLineLayerStart1 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_Layer_Start1.png", typeof(Texture));
  162. texLineLayerStart2 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_Layer_Start2.png", typeof(Texture));
  163. texLineLayerCollapsedStart1 = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_LayerCollapsed_Start1.png", typeof(Texture));
  164. texLineVertical = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Lines/Line_Vertical.png", typeof(Texture));
  165. texDragIconVertical = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/DragIconVertical.png", typeof(Texture));
  166. texDragIconHorizontal = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/DragIconHorizontal.png", typeof(Texture));
  167. texSelectCard = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Select_Card.png", typeof(Texture));
  168. texSelectCardHeader = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Cards/Select_Card_Header.png", typeof(Texture));
  169. if (texCardHeader == null || texCardBody == null) return false;
  170. cardHeight = texCardHeader.height + texCardBody.height;
  171. nodeWidthHSpace = texCardBody.width + g.nodeHSpace;
  172. shelfOffsetY = (texShelfLayer.height - cardHeight) / 2;
  173. }
  174. return true;
  175. }
  176. static public float cardHeight;
  177. static public float shelfOffsetY;
  178. static public float nodeWidthHSpace;
  179. static public bool SelectionContainsItemBehaviour()
  180. {
  181. for (int i = 0; i < Selection.transforms.Length; i++) if (Selection.transforms[i].GetComponent<TC_ItemBehaviour>() != null) return true;
  182. return false;
  183. }
  184. static public float GetPosX(float offset)
  185. {
  186. float center = TC_NodeWindow.window.position.width / 2;
  187. offset += scrollOffset.x;
  188. return (scale * (offset - center)) + center;
  189. }
  190. static public Vector2 GetPositionScaled(Vector2 offset)
  191. {
  192. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  193. offset += scrollOffset;
  194. return (scale * (offset - center)) + center;
  195. }
  196. static public Rect GetRectScaled(Rect rect)
  197. {
  198. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  199. rect.x += scrollOffset.x;
  200. rect.y += scrollOffset.y;
  201. rect.x = (scale * (rect.x - center.x)) + center.x;
  202. rect.y = (scale * (rect.y - center.y)) + center.y;
  203. rect.width *= scale;
  204. rect.height *= scale;
  205. return rect;
  206. }
  207. static public Rect GetRectScaled(float x, float y, float width, float height)
  208. {
  209. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  210. x += scrollOffset.x;
  211. y += scrollOffset.y;
  212. x = (scale * (x - center.x)) + center.x;
  213. y = (scale * (y - center.y)) + center.y;
  214. width *= scale;
  215. height *= scale;
  216. return new Rect(x, y, width, height);
  217. }
  218. static public Rect GetRectScaled(float x, float y, Texture tex, bool invert = false)
  219. {
  220. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  221. x += scrollOffset.x;
  222. y += scrollOffset.y;
  223. x = (scale * (x - center.x)) + center.x;
  224. y = (scale * (y - center.y)) + center.y;
  225. float width = tex.width * scale;
  226. float height = tex.height * scale;
  227. if (!invert) return new Rect(x, y, width, height);
  228. else return new Rect(x + width, y, -width, height);
  229. }
  230. static public void DrawTexture(Rect rect, Texture tex, Color color)
  231. {
  232. GUI.color = color;
  233. GUI.DrawTexture(rect, tex);
  234. GUI.color = Color.white;
  235. }
  236. static public Rect DrawTextureScaled(Rect rect, Texture tex, Color color)
  237. {
  238. rect = GetRectScaled(rect);
  239. GUI.color = color;
  240. GUI.DrawTexture(rect, tex);
  241. GUI.color = Color.white;
  242. return rect;
  243. }
  244. static public Rect DrawTextureScaled(float x, float y, Texture tex, Color color, bool invert = false, StretchMode stretchHorizontal = StretchMode.None, StretchMode stretchVertical = StretchMode.None)
  245. {
  246. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  247. float width, height;
  248. if (stretchHorizontal == StretchMode.Screen) { x = 0; width = TC_NodeWindow.window.position.width; }
  249. else
  250. {
  251. x += scrollOffset.x;
  252. x = (scale * (x - center.x)) + center.x;
  253. width = tex.width * scale;
  254. if (stretchHorizontal == StretchMode.Left) { width += x; x = 0; }
  255. else if (stretchHorizontal == StretchMode.Right) { width = TC_NodeWindow.window.position.width - x; }
  256. }
  257. if (stretchVertical == StretchMode.Screen) { y = 0; height = TC_NodeWindow.window.position.height; }
  258. else
  259. {
  260. y += scrollOffset.y;
  261. y = (scale * (y - center.y)) + center.y;
  262. height = tex.height * scale;
  263. if (stretchVertical == StretchMode.Left) { height += y; y = 0; }
  264. else if (stretchVertical == StretchMode.Right) { height = TC_NodeWindow.window.position.height - y; }
  265. }
  266. Rect rect;
  267. if (!invert) rect = new Rect(x, y, width, height);
  268. else rect = new Rect(x + width, y, -width, height);
  269. // if (tex == null) return rect;
  270. GUI.color = color;
  271. GUI.DrawTexture(rect, tex);
  272. GUI.color = Color.white;
  273. return rect;
  274. }
  275. static public Rect DrawTextureScaled(float x, float y, float width, Texture tex, Color color, bool invert = false, StretchMode stretchVertical = StretchMode.None)
  276. {
  277. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  278. float height;
  279. x += scrollOffset.x;
  280. x = (scale * (x - center.x)) + center.x;
  281. width *= scale;
  282. if (stretchVertical == StretchMode.Screen) { y = 0; height = TC_NodeWindow.window.position.height; }
  283. else
  284. {
  285. y += scrollOffset.y;
  286. y = (scale * (y - center.y)) + center.y;
  287. height = tex.height * scale;
  288. if (stretchVertical == StretchMode.Left) { height += y; y = 0; }
  289. else if (stretchVertical == StretchMode.Right) { height = TC_NodeWindow.window.position.height - y; }
  290. }
  291. Rect rect;
  292. if (!invert) rect = new Rect(x, y, width, height);
  293. else rect = new Rect(x + width, y, -width, height);
  294. GUI.color = color;
  295. GUI.DrawTexture(rect, tex);
  296. GUI.color = Color.white;
  297. return rect;
  298. }
  299. static public Rect DrawTextureScaledV(float x, float y, float height, Texture tex, Color color, bool invert = false, StretchMode stretchHorizontal = StretchMode.None)
  300. {
  301. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  302. float width;
  303. if (stretchHorizontal == StretchMode.Screen) { x = 0; width = TC_NodeWindow.window.position.width; }
  304. else
  305. {
  306. x += scrollOffset.x;
  307. x = (scale * (x - center.x)) + center.x;
  308. width = tex.width * scale;
  309. if (stretchHorizontal == StretchMode.Left) { width += x; x = 0; }
  310. else if (stretchHorizontal == StretchMode.Right) { width = TC_NodeWindow.window.position.width - x; }
  311. }
  312. y += scrollOffset.y;
  313. y = (scale * (y - center.y)) + center.y;
  314. height *= scale;
  315. Rect rect;
  316. if (!invert) rect = new Rect(x, y, width, height);
  317. else rect = new Rect(x + width, y, -width, height);
  318. GUI.color = color;
  319. GUI.DrawTexture(rect, tex);
  320. GUI.color = Color.white;
  321. return rect;
  322. }
  323. static public Rect GetLeftRect(Rect rect)
  324. {
  325. Vector2 center = new Vector2(TC_NodeWindow.window.position.width / 2, TC_NodeWindow.window.position.height / 2);
  326. // rect.width += scrollOffset.x;
  327. rect.y += scrollOffset.y;
  328. rect.width = (scale * ((rect.width + scrollOffset.x) - center.x)) + center.x;
  329. rect.y = (scale * (rect.y - center.y)) + center.y;
  330. // rect.width *= scale;
  331. rect.height *= scale;
  332. return rect;
  333. }
  334. static public bool CullRect(Rect window, Rect rect)
  335. {
  336. if (window.Contains(new Vector2(rect.xMin, rect.yMin)) || window.Contains(new Vector2(rect.xMin, rect.yMax)) || window.Contains(new Vector2(rect.xMax, rect.yMin)) || window.Contains(new Vector2(rect.xMax, rect.yMax))) return false; else return true;
  337. }
  338. static public void DrawCenter(Color color, int length, int width)
  339. {
  340. GUI.color = color;
  341. GUI.DrawTexture(new Rect((TC_NodeWindow.window.position.width - length) / 2, (TC_NodeWindow.window.position.height - width) / 2, length, width), Texture2D.whiteTexture);
  342. GUI.DrawTexture(new Rect((TC_NodeWindow.window.position.width - width) / 2, (TC_NodeWindow.window.position.height - length) / 2, width, length), Texture2D.whiteTexture);
  343. GUI.color = Color.white;
  344. }
  345. static public Rect DrawRect(Rect rect, Color color, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign verTextAlign = VerTextAlign.Top)
  346. {
  347. Color colOld = GUI.color;
  348. GUI.color = color;
  349. rect = GetRectScaled(rect);
  350. AlignPosition(ref rect, horTextAlign, verTextAlign);
  351. // if (CullRect (windowRect,rect)) return;
  352. GUI.DrawTexture(rect, Texture2D.whiteTexture);
  353. GUI.color = colOld;
  354. return rect;
  355. }
  356. static public Rect DrawRect(Rect rect, Texture tex, Color color)
  357. {
  358. Color colOld = GUI.color;
  359. GUI.color = color;
  360. rect = GetRectScaled(rect);
  361. // if (CullRect (windowRect,rect)) return;
  362. GUI.DrawTexture(rect, tex);
  363. GUI.color = colOld;
  364. return rect;
  365. }
  366. static public void DrawLeftRect(Rect rect, Texture tex, Color color)
  367. {
  368. // rect = GetRect (new Rect(0,0,400,50));
  369. GUI.color = color;
  370. rect = GetLeftRect(rect);
  371. if (rect.width > TC_NodeWindow.window.position.width) rect.width = TC_NodeWindow.window.position.width;
  372. GUI.DrawTexture(rect, tex);
  373. }
  374. static public void DragDropNode(TC_ItemBehaviour item, Rect rectStartDrag, Rect rectDrop, Vector2 pos, bool isDragable = true, bool checkForPosDrop = true)
  375. {
  376. if (selectedOpacityItem != null) return;
  377. Vector2 mousePos = eventCurrent.mousePosition;
  378. if (item.GetType() == typeof(TC_LayerGroupResult)) isDragable = false;
  379. if (isDragable) {
  380. if (rectStartDrag.Contains(mousePos) && eventCurrent.button == 0)
  381. {
  382. if (eventCurrent.type == EventType.MouseDrag)
  383. {
  384. startDrag = true;
  385. //if (DragAndDrop.objectReferences.Length == 1)
  386. //{
  387. // if (DragAndDrop.objectReferences[0] == item.gameObject)
  388. // {
  389. // startDrag = false;
  390. // }
  391. //}
  392. if (DragAndDrop.objectReferences.Length == 0)
  393. {
  394. // Debug.Log("Drag " + item.name);
  395. if (Selection.activeGameObject == item.gameObject)
  396. {
  397. DragAndDrop.PrepareStartDrag();
  398. // DragAndDrop.activeControlID = item.gameObject.GetInstanceID();
  399. // DragAndDrop.SetGenericData("Node", item.gameObject);
  400. DragAndDrop.objectReferences = new Object[1] { item.gameObject };// { null };
  401. // DragAndDrop.SetGenericData("currentValue", item.gameObject);
  402. DragAndDrop.StartDrag(item.name);
  403. eventCurrent.Use();
  404. }
  405. }
  406. }
  407. }
  408. }
  409. if (rectDrop.Contains(mousePos) && eventCurrent.button == 0)
  410. {
  411. bool drop = eventCurrent.type == EventType.DragPerform;
  412. if (drop || eventCurrent.type == EventType.DragUpdated)
  413. {
  414. // Debug.Log("Accept Drag " + item.name);
  415. DragAndDrop.AcceptDrag();
  416. Object[] objs = DragAndDrop.objectReferences;
  417. for (int i = 0; i < objs.Length; i++)
  418. {
  419. Object obj = objs[i];
  420. if (obj.GetType() == typeof(Texture2D)) DropTexture(item, (Texture2D)obj);
  421. else if (obj.GetType() == typeof(GameObject))
  422. {
  423. TC_ItemBehaviour itemToDrop = ((GameObject)obj).GetComponent<TC_ItemBehaviour>();
  424. if (itemToDrop != null)
  425. {
  426. dropItemReceive = item;
  427. bool dropAccept = DropItem(item, itemToDrop, rectDrop, drop);
  428. if (dropAccept && !drop)
  429. {
  430. if (GetItemDropPosition(item, itemToDrop, rectDrop))
  431. {
  432. if (eventCurrent.alt) DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
  433. else DragAndDrop.visualMode = DragAndDropVisualMode.Move;
  434. }
  435. }
  436. }
  437. else DropObject(item, (GameObject)obj);
  438. }
  439. }
  440. }
  441. }
  442. else
  443. {
  444. if (checkForPosDrop) item.dropPosition = DropPosition.None;
  445. }
  446. if (item.dropPosition != DropPosition.None && checkForPosDrop) DrawItemDropPosition(item.dropPosition, pos);
  447. }
  448. static public void DrawItemDropPosition(DropPosition posDrop, Vector2 pos)
  449. {
  450. Color color;
  451. if (eventCurrent.shift) color = new Color(0, 1, 0, 0.75f);
  452. else color = new Color(1, 1, 1, 0.75f);
  453. if (posDrop == DropPosition.Top)
  454. DrawTexture(GetRectScaled(new Rect(pos.x + g.rect7.x, pos.y + g.rect7.y, texDragIconVertical.width / 2f, texDragIconVertical.height / 2f)), texDragIconVertical, color);
  455. else if (posDrop == DropPosition.Bottom)
  456. DrawCommand.Add(new Rect(pos.x + g.rect8.x, pos.y + g.rect8.y, texDragIconVertical.width / 2f, -texDragIconVertical.height / 2f), texDragIconVertical, color, 2);
  457. else if (posDrop == DropPosition.Right)
  458. DrawCommand.Add(new Rect(pos.x + g.rect5.x, pos.y + g.rect5.y, texDragIconHorizontal.width / 2f, texDragIconHorizontal.height / 2f), texDragIconHorizontal, color, 2);
  459. else if (posDrop == DropPosition.Left)
  460. DrawCommand.Add(new Rect(pos.x + g.rect6.x, pos.y + g.rect5.y, -texDragIconHorizontal.width / 2f, texDragIconHorizontal.height / 2f), texDragIconHorizontal, color, 2);
  461. }
  462. static public TC_ItemBehaviour GetPrevious(TC_ItemBehaviour item, bool isPrefab)
  463. {
  464. if (isPrefab) return null;
  465. if (item.parentItem == null) return null;
  466. int siblingIndex = item.t.GetSiblingIndex();
  467. if (siblingIndex <= 0) return null;
  468. // Debug.Log(siblingIndex + " " + (siblingIndex - 1)+ " "+item.parentItem.t.childCount);
  469. if (siblingIndex > item.parentItem.t.childCount) return null;
  470. return item.parentItem.t.GetChild(siblingIndex - 1).GetComponent<TC_ItemBehaviour>();
  471. }
  472. static public TC_ItemBehaviour GetNext(TC_ItemBehaviour item, bool isPrefab)
  473. {
  474. if (isPrefab) return null;
  475. if (item.transform.parent == null) return null;
  476. int siblingIndex = item.t.GetSiblingIndex();
  477. if (siblingIndex == item.parentItem.t.childCount - 1) return null;
  478. // Debug.Log(siblingIndex + " " + (siblingIndex + 1)+ " "+item.parentItem.t.childCount);
  479. return item.parentItem.t.GetChild(siblingIndex + 1).GetComponent<TC_ItemBehaviour>();
  480. }
  481. static public bool GetItemDropPosition(TC_ItemBehaviour itemReceive, TC_ItemBehaviour itemToDrop, Rect rectNode)
  482. {
  483. Vector2 mousePos = eventCurrent.mousePosition;
  484. bool clone = eventCurrent.alt;
  485. bool isPrefab = (PrefabUtility.GetPrefabType(itemToDrop) == PrefabType.Prefab);
  486. if (!itemReceive.nodeFoldout)
  487. {
  488. itemReceive.dropPosition = DropPosition.None;
  489. return false;
  490. }
  491. if (itemReceive.GetType() == typeof(TC_LayerGroupResult))
  492. {
  493. if (itemToDrop.GetType() == typeof(TC_LayerGroup) || itemToDrop.GetType() == typeof(TC_Layer))
  494. {
  495. itemReceive.dropPosition = DropPosition.Bottom;
  496. return true;
  497. }
  498. return false;
  499. }
  500. if (itemReceive.GetType() == typeof(TC_LayerGroup) || itemReceive.GetType() == typeof(TC_Layer))
  501. {
  502. TC_LayerGroup layerGroup = itemReceive as TC_LayerGroup;
  503. if (layerGroup != null)
  504. {
  505. if (layerGroup.level == 0) return false;
  506. }
  507. // Debug.Log(GetPrevious(itemToDrop).name + " " + itemReceive.name);
  508. if (mousePos.y < rectNode.y + ((cardHeight / 2) * scale))
  509. {
  510. // Debug.Log(GetPrevious(itemToDrop).name + " " + itemReceive.name);
  511. if (GetNext(itemToDrop, isPrefab) == itemReceive && !clone) { itemReceive.dropPosition = DropPosition.Bottom; }
  512. else itemReceive.dropPosition = DropPosition.Top;
  513. }
  514. else
  515. {
  516. if (GetPrevious(itemToDrop, isPrefab) == itemReceive && !clone) { itemReceive.dropPosition = DropPosition.Top; }
  517. else itemReceive.dropPosition = DropPosition.Bottom;
  518. }
  519. }
  520. else
  521. {
  522. bool nodeCondition = ((itemToDrop.GetType() == typeof(TC_Node) || itemToDrop.GetType() == typeof(TC_NodeGroup)) && itemReceive.GetType() == typeof(TC_NodeGroup));
  523. bool selectItemCondition = ((itemToDrop.GetType() == typeof(TC_SelectItem) || itemToDrop.GetType() == typeof(TC_SelectItemGroup)) && itemReceive.GetType() == typeof(TC_SelectItemGroup));
  524. if (nodeCondition || selectItemCondition)
  525. {
  526. if (itemReceive.t.childCount > 0 && !clone)
  527. {
  528. if (itemToDrop == itemReceive.t.GetChild(0).GetComponent<TC_ItemBehaviour>()) return false;
  529. }
  530. if (itemReceive.t.childCount == 0) return true;
  531. itemReceive.dropPosition = DropPosition.Left; return true;
  532. }
  533. if (mousePos.x < rectNode.x + ((texCardBody.width / 2) * scale))
  534. {
  535. if (GetPrevious(itemToDrop, isPrefab) == itemReceive && !clone) { itemReceive.dropPosition = DropPosition.Right; }
  536. else itemReceive.dropPosition = DropPosition.Left;
  537. }
  538. else
  539. {
  540. if (GetNext(itemToDrop, isPrefab) == itemReceive && !clone) { itemReceive.dropPosition = DropPosition.Left; }
  541. else itemReceive.dropPosition = DropPosition.Right;
  542. }
  543. }
  544. return true;
  545. }
  546. static public bool DropItem(TC_ItemBehaviour itemReceive, TC_ItemBehaviour itemToDrop, Rect rectDrop, bool drop)
  547. {
  548. if (itemReceive == itemToDrop) return false;
  549. bool isPrefab = (PrefabUtility.GetPrefabType(itemToDrop) == PrefabType.Prefab);
  550. if (itemToDrop.level == 0 && !isPrefab) return false;
  551. bool clone = eventCurrent.alt;
  552. if (itemToDrop.GetType() == typeof(TC_LayerGroup))
  553. {
  554. if (itemReceive.t.IsChildOf(itemToDrop.t)) return false;
  555. if (itemReceive.GetType() == typeof(TC_Layer))
  556. {
  557. if (drop) DropItemSameLevel(itemReceive, itemToDrop, clone);
  558. return true;
  559. }
  560. if (itemReceive.GetType() == typeof(TC_LayerGroup))
  561. {
  562. if (drop) DropItemSameLevel(itemReceive, itemToDrop, clone);
  563. return true;
  564. }
  565. if (itemReceive.GetType() == typeof(TC_LayerGroupResult))
  566. {
  567. if (drop) DropItemAsChild(itemReceive, itemToDrop, 0, clone);
  568. return true;
  569. }
  570. }
  571. else if (itemToDrop.GetType() == typeof(TC_Layer))
  572. {
  573. if (itemReceive.GetType() == typeof(TC_Layer) || itemReceive.GetType() == typeof(TC_LayerGroup) && itemReceive.level != 0)
  574. {
  575. if (drop) DropItemSameLevel(itemReceive, itemToDrop, clone);
  576. return true;
  577. }
  578. if (itemReceive.GetType() == typeof(TC_LayerGroupResult))
  579. {
  580. if (drop) DropItemAsChild(itemReceive, itemToDrop, 0, clone);
  581. return true;
  582. }
  583. }
  584. else if (itemToDrop.GetType() == typeof(TC_NodeGroup))
  585. {
  586. if (itemReceive.GetType() == typeof(TC_NodeGroup) || itemReceive.GetType() == typeof(TC_Node))
  587. {
  588. if (drop) DropGroup(itemReceive, itemToDrop, clone);
  589. return true;
  590. }
  591. else return false;
  592. }
  593. else if (itemToDrop.GetType() == typeof(TC_Node))
  594. {
  595. if (itemReceive.GetType() == typeof(TC_Node))
  596. {
  597. if (drop) DropItemSameLevel(itemReceive, itemToDrop, clone);
  598. return true;
  599. }
  600. if (itemReceive.GetType() == typeof(TC_NodeGroup))
  601. {
  602. if (drop) DropItemAsChild(itemReceive, itemToDrop, 0, clone);
  603. return true;
  604. }
  605. }
  606. else if (itemToDrop.GetType() == typeof(TC_SelectItemGroup))
  607. {
  608. if (itemReceive.GetType() == typeof(TC_SelectItemGroup) || itemReceive.GetType() == typeof(TC_SelectItem))
  609. {
  610. if (drop) DropGroup(itemReceive, itemToDrop, clone);
  611. return true;
  612. }
  613. else return false;
  614. }
  615. else if (itemToDrop.GetType() == typeof(TC_SelectItem))
  616. {
  617. if (itemReceive.GetType() == typeof(TC_SelectItem))
  618. {
  619. if (drop) DropItemSameLevel(itemReceive, itemToDrop, clone);
  620. return true;
  621. }
  622. if (itemReceive.GetType() == typeof(TC_SelectItemGroup))
  623. {
  624. if (drop) DropItemAsChild(itemReceive, itemToDrop, 0, clone);
  625. return true;
  626. }
  627. }
  628. return false;
  629. }
  630. static public void DropGroup(TC_ItemBehaviour itemReceive, TC_ItemBehaviour groupToDrop, bool clone)
  631. {
  632. TC_SelectItemGroup selectItemGroupReceive = itemReceive as TC_SelectItemGroup;
  633. TC_NodeGroup nodeGroupReceive = itemReceive as TC_NodeGroup;
  634. int startIndex;
  635. int indexOffset = 0;
  636. if (itemReceive.dropPosition == DropPosition.Right) { indexOffset = -1; }
  637. if (selectItemGroupReceive != null || nodeGroupReceive != null) startIndex = 0;
  638. else
  639. {
  640. startIndex = itemReceive.t.GetSiblingIndex() + 1;
  641. itemReceive = itemReceive.parentItem;
  642. }
  643. startIndex += indexOffset;
  644. int childCount = groupToDrop.t.childCount;
  645. for (int i = 0; i < childCount; i++)
  646. {
  647. Transform child;
  648. if (clone) child = groupToDrop.t.GetChild(childCount - i - 1);
  649. else child = groupToDrop.t.GetChild(groupToDrop.t.childCount - 1);
  650. TC_ItemBehaviour itemToDrop = child.GetComponent<TC_ItemBehaviour>();
  651. if (clone) itemToDrop = itemToDrop.Duplicate(itemReceive.transform);
  652. else itemToDrop.transform.parent = itemReceive.transform;
  653. itemToDrop.transform.SetSiblingIndex(startIndex);
  654. }
  655. }
  656. static public TC_ItemBehaviour DropItemSameLevel(TC_ItemBehaviour itemReceive, TC_ItemBehaviour itemToDrop, bool clone, bool checkForPrefab = true)
  657. {
  658. if (!clone && checkForPrefab)
  659. {
  660. if (PrefabUtility.GetPrefabType(itemToDrop) == PrefabType.Prefab) clone = true;
  661. }
  662. TC_SelectItemGroup selectItemGroupReceive = itemReceive as TC_SelectItemGroup;
  663. TC_SelectItem selectItemReceive = itemReceive as TC_SelectItem;
  664. // TC_SelectItemGroup selectItemGroupToDrop = itemToDrop as TC_SelectItemGroup;
  665. TC_SelectItem selectItemToDrop = itemToDrop as TC_SelectItem;
  666. bool restoreRanges = false;
  667. Vector2[] ranges = null;
  668. if (clone) itemToDrop = itemToDrop.Duplicate(itemReceive.t.parent);
  669. else
  670. {
  671. if (itemReceive.parentItem == itemToDrop.parentItem && selectItemReceive != null && selectItemToDrop != null)
  672. {
  673. ranges = selectItemReceive.parentItem.GetRanges();
  674. restoreRanges = true;
  675. }
  676. }
  677. Undo.SetTransformParent(itemToDrop.transform, itemReceive.transform.parent, "Drag and Drop "+itemToDrop.name);
  678. itemToDrop.t.SetAsLastSibling();
  679. int siblingIndex = itemReceive.t.GetSiblingIndex();
  680. if (itemReceive.dropPosition == DropPosition.Bottom) siblingIndex++;
  681. else if (itemReceive.dropPosition == DropPosition.Left) siblingIndex++;
  682. itemToDrop.t.SetSiblingIndex(siblingIndex);
  683. //if (!restoreRanges)
  684. //{
  685. // if (selectItemToDrop != null)
  686. // {
  687. // selectItemToDrop.parentItem.GetItems();
  688. // selectItemToDrop.range = selectItemToDrop.parentItem.GetInbetweenRange(itemToDrop.t.GetSiblingIndex());
  689. // }
  690. //}
  691. if (restoreRanges)
  692. {
  693. // selectItemReceive.parentItem.GetItems(false);
  694. TC_Area2D.current.terrainLayer.GetItem(selectItemReceive.outputId, true, false);
  695. selectItemReceive.parentItem.SetRanges(ranges);
  696. }
  697. else if (selectItemToDrop != null)
  698. {
  699. if (selectItemToDrop.parentItem != null) selectItemToDrop.parentItem.refreshRanges = true;
  700. }
  701. if (selectItemGroupReceive != null) selectItemGroupReceive.refreshRanges = true;
  702. if (selectItemReceive != null) selectItemReceive.parentItem.refreshRanges = true;
  703. TC.RefreshOutputReferences((itemReceive.outputId == itemToDrop.outputId) ? itemReceive.outputId : TC.allOutput);
  704. CheckDropInDifferentLevel(itemReceive, itemToDrop);
  705. TC.AutoGenerate();
  706. return itemToDrop;
  707. }
  708. static public void DropItemAsChild(TC_ItemBehaviour itemReceive, TC_ItemBehaviour itemToDrop, int startIndex, bool clone)
  709. {
  710. if (PrefabUtility.GetPrefabType(itemToDrop) == PrefabType.Prefab) clone = true;
  711. if (clone) itemToDrop = itemToDrop.Duplicate(null);
  712. Undo.SetTransformParent(itemToDrop.transform, itemReceive.transform, "Move " + itemToDrop.name);
  713. itemToDrop.transform.SetSiblingIndex(startIndex);
  714. TC.RefreshOutputReferences((itemReceive.outputId == itemToDrop.outputId) ? itemReceive.outputId : TC.allOutput);
  715. CheckDropInDifferentLevel(itemReceive, itemToDrop);
  716. TC.AutoGenerate();
  717. }
  718. static public void CheckDropInDifferentLevel(TC_ItemBehaviour itemReceive, TC_ItemBehaviour dropItem)
  719. {
  720. if (itemReceive.outputId != dropItem.outputId && itemReceive.outputId != TC.heightOutput)
  721. {
  722. TC_LayerGroup layerGroup = dropItem as TC_LayerGroup;
  723. TC_Layer layer = dropItem as TC_Layer;
  724. if (layerGroup != null) { layerGroup.outputId = itemReceive.outputId; TC_Area2D.current.terrainLayer.GetItem(layerGroup.outputId, true, false); }
  725. else if (layer != null) { layer.outputId = itemReceive.outputId; TC_Area2D.current.terrainLayer.GetItem(layer.outputId, true, false); }
  726. }
  727. }
  728. static public void DropTexture(TC_ItemBehaviour itemReceive, Texture2D texToDrop)
  729. {
  730. // Debug.Log("Drop Texture");
  731. TC_Node node = itemReceive as TC_Node;
  732. if (node != null)
  733. {
  734. if (eventCurrent.type == EventType.DragPerform)
  735. {
  736. node.inputKind = InputKind.File;
  737. node.inputFile = InputFile.RawImage;
  738. node.clamp = true;
  739. node.DropTextureEditor(texToDrop);
  740. Selection.activeTransform = node.t;
  741. }
  742. else DragAndDrop.visualMode = DragAndDropVisualMode.Move;
  743. }
  744. }
  745. static public void DropObject(TC_ItemBehaviour itemReceive, GameObject spawnGO)
  746. {
  747. TC_SelectItem selectItem = itemReceive as TC_SelectItem;
  748. if (selectItem != null && itemReceive.outputId == TC.objectOutput)
  749. {
  750. if (eventCurrent.type == EventType.DragPerform)
  751. {
  752. selectItem.spawnObject.go = spawnGO;
  753. selectItem.Refresh();
  754. Selection.activeTransform = selectItem.t;
  755. }
  756. else DragAndDrop.visualMode = DragAndDropVisualMode.Move;
  757. }
  758. }
  759. static public bool InScreenSpace(Rect rect)
  760. {
  761. // rect = GetRectScaled(rect);
  762. if (rect.xMax >= 0 && rect.yMax >= 0 && rect.xMin < TC_NodeWindow.window.position.width && rect.yMin < TC_NodeWindow.window.position.height) return true; else return false;
  763. }
  764. static public Rect DrawNode(TC_ItemBehaviour item, Vector2 pos, Color color, Color previewColor, ref bool isCulled, float activeMulti, bool nodeFoldout, bool drawMethod, bool resultNode = false, bool drawPreview = true)
  765. {
  766. TC_LayerGroup layerGroup = item as TC_LayerGroup;
  767. TC_LayerGroupResult groupResult = item as TC_LayerGroupResult;
  768. TC_Layer layer = item as TC_Layer;
  769. TC_NodeGroup nodeGroup = item as TC_NodeGroup;
  770. TC_Node node = item as TC_Node;
  771. TC_SelectItemGroup selectItemGroup = item as TC_SelectItemGroup;
  772. TC_SelectItem selectItem = item as TC_SelectItem;
  773. int mouseButton;
  774. if (!item.active) activeMulti *= 0.75f;
  775. Rect rectNode = GetRectScaled(pos.x, pos.y, texCardBody.width, nodeFoldout ? cardHeight : 32);
  776. if (!InScreenSpace(rectNode))
  777. {
  778. ++countDrawNodeCulled;
  779. isCulled = true; return rectNode;
  780. }
  781. ++countDrawNode;
  782. if (rectNode.Contains(eventCurrent.mousePosition)) hoverItem = item;
  783. if (Mathw.ArrayContains(Selection.transforms, item.t)) item.Repaint();
  784. // Rect nodeHeaderRect = GetRect(rect);
  785. // DrawRect(new Rect(rect.x, rect.y, rect.width, nodeHeaderHeight), new Color32(56, 56, 56, 255));
  786. DrawTextureScaled(pos.x, pos.y, texCardHeader, color * activeMulti);
  787. if (GetPositionScaled(pos).y > 0)
  788. {
  789. string text = item.t.name;
  790. if (selectItemGroup != null) text = TC.outputNames[item.outputId] + " Group";
  791. if (node != null)
  792. {
  793. if (node.inputKind == InputKind.File)
  794. {
  795. if (node.inputFile == InputFile.RawImage)
  796. {
  797. if (text == "Node" && node.stampTex != null) text = node.stampTex.name;
  798. }
  799. }
  800. }
  801. DrawText(new Vector2(pos.x + 2, pos.y + 3), Mathw.CutString(text, TC.nodeLabelLength), 20, Color.white * activeMulti, FontStyle.Normal, HorTextAlign.Left); // TODO: Optimize by caching name
  802. }
  803. // Rect previewRect = new Rect(rect.x + nodeBorderWidth, rect.y + previewOffsetY, rect.width - (nodeBorderWidth * 2), nodeWidth - (nodeBorderWidth * 2));
  804. Rect rectEye;
  805. if (layer != null || layerGroup != null) rectEye = new Rect(pos.x + 216, pos.y + 3, 24, 24);
  806. else rectEye = new Rect(pos.x + 239.2f, pos.y + 3, 24, 24);
  807. Rect rectEyeScaled = GetRectScaled(rectEye);
  808. bool drawEye = true;
  809. if (selectItemGroup != null || groupResult != null) drawEye = false;
  810. if (nodeGroup != null)
  811. {
  812. if (nodeGroup.type == NodeGroupType.Select) drawEye = false;
  813. }
  814. //if (node != null)
  815. //{
  816. // if (node.nodeType == NodeGroupType.Select)
  817. // {
  818. // TC_NodeGroup nodeGroupParent = (TC_NodeGroup)node.parentItem;
  819. // if (nodeGroupParent.firstActive != -1)
  820. // {
  821. // if (nodeGroupParent.totalActive <= 1 && nodeGroupParent.itemList[nodeGroupParent.firstActive].node == node) drawEye = false;
  822. // }
  823. // }
  824. //}
  825. //if (Selection.activeTransform == item.t)
  826. //{
  827. // newScrollOffset = pos;
  828. // setNewScrollOffset = true;
  829. //}
  830. if (drawEye)
  831. {
  832. mouseButton = Button(rectEye, item.visible ? texEye : texEyeClosed, true, item.visible && item.active ? new Color(1, 1, 1, 0.25f) : new Color(1, 0, 0, 0.65f), item.visible && item.active ? Color.white : Color.red, Color.white, true, false);
  833. if (mouseButton == 0)
  834. {
  835. item.visible = !item.visible;
  836. EditorUtility.SetDirty(item);
  837. if (selectItem != null) selectItem.parentItem.refreshRangeItem = selectItem;
  838. TC.RefreshOutputReferences(item.outputId, true);
  839. eventCurrent.Use();
  840. //Debug.Log("tes "+item.active);
  841. }
  842. }
  843. Rect rectExclude = rectEyeScaled;
  844. if (item.isPortalCount > 0)
  845. {
  846. rectEye.x -= 28;
  847. mouseButton = Button(rectEye, texPortal, true, item.isPortalCount > 1 ? Color.white : new Color(0.5f, 1, 0.6f), Color.white, Color.black, item.isPortalCount > 1 ? false : true);
  848. if (mouseButton == 0)
  849. {
  850. Selection.activeTransform = item.usedAsPortalList[0].t;
  851. Event.current.Use();
  852. }
  853. }
  854. if (item.portalNode != null)
  855. {
  856. rectEye.x -= 28;
  857. mouseButton = Button(rectEye, texPortal, true, new Color(1, 0.3f, 0.3f, 1), Color.white, Color.black, true);
  858. if (mouseButton == 0)
  859. {
  860. Selection.activeTransform = item.portalNode.t;
  861. Event.current.Use();
  862. }
  863. }
  864. if (selectItemGroup == null && selectItem == null && (item.lockTransform || item.lockPosParent || item.lockPosChildren))
  865. {
  866. Rect rectLocked = new Rect(rectEye.x - 23, rectEye.y + 1.7f, texLocked.width / 3.5f, texLocked.height / 3.5f);
  867. if (groupResult != null) rectLocked.x += 8;
  868. if (nodeGroup != null)
  869. {
  870. if (nodeGroup.type == NodeGroupType.Select) rectLocked.x += 30;
  871. }
  872. if (node != null)
  873. {
  874. if (item.lockTransform || item.lockPosParent) mouseButton = Button(rectLocked, texLocked, item.lockTransform, new Color(1, 0, 0, 0.5f), item.lockTransform ? new Color(1, 0, 0, 1) : Color.white, new Color(1, 1, 1, 0.25f));
  875. else mouseButton = -1;
  876. }
  877. else mouseButton = Button(rectLocked, item.lockPosParent || item.lockPosChildren ? texLocked : texUnlocked, item.lockPosChildren, new Color(1, 0, 0, 0.5f), item.lockPosChildren ? new Color(1, 0, 0, 1) : Color.white, new Color(1, 1, 1, 0.25f));
  878. if (mouseButton == 0)
  879. {
  880. if (node != null) item.lockTransform = !item.lockTransform;
  881. else
  882. {
  883. item.lockPosChildren = !item.lockPosChildren;
  884. item.SetLockChildrenPosition(false);
  885. }
  886. eventCurrent.Use();
  887. }
  888. }
  889. if (layerGroup != null || groupResult != null || layer != null) rectExclude = GetRectScaled(new Rect(pos.x + 245.1f, pos.y + 6.5f, 20, 20));
  890. mouseButton = ClickRect(rectNode, rectExclude);
  891. if (mouseButton == 0)
  892. {
  893. //if (eventCurrent.control && eventCurrent.clickCount == 2)
  894. //{
  895. // item.visible = item.active = !item.visible;
  896. // TC.AutoGenerate();
  897. //}
  898. //else
  899. //{
  900. if (eventCurrent.control)
  901. {
  902. if (Mathw.ArrayContains(Selection.transforms, item.t)) Selection.objects = Mathw.RemoveFromArray(Selection.objects, item.gameObject);
  903. else Selection.objects = Mathw.AddToArray(Selection.objects, item.gameObject);
  904. }
  905. else Selection.objects = new GameObject[] { item.gameObject };
  906. // TC_ProjectPreview.instance.SetPreview(item);
  907. //}
  908. }
  909. Rect rectPreview = GetRectScaled(pos.x + 7, pos.y + texCardHeader.height + 7, 256, 256);
  910. if (nodeFoldout)
  911. {
  912. DrawTextureScaled(pos.x, pos.y + texCardHeader.height, texCardBody, color * activeMulti);
  913. // DrawRect(previewRect, Color.white);
  914. if (drawPreview)
  915. {
  916. // Rect previewRect2 = GetRect(new Rect(previewRect.xMin + 0.5f, previewRect.yMin + 0.5f, previewRect.width - 1, previewRect.height - 1));
  917. GUI.color = previewColor;
  918. // GUI.DrawTexture(rectPreview, Texture2D.whiteTexture);
  919. Texture texPreview = null;
  920. if (item.outputId == TC.colorOutput && selectItem != null)
  921. {
  922. if (selectItem.texColor == null || selectItem.parentItem.itemList.Count != 1) texPreview = item.preview.tex; else texPreview = item.rtDisplay;
  923. }
  924. else
  925. {
  926. if (nodeGroup != null) texPreview = nodeGroup.rtColorPreview;
  927. else if (node != null)
  928. {
  929. TC_NodeGroup parent = (TC_NodeGroup)node.parentItem;
  930. if (parent.itemList.Count == 1) texPreview = ((TC_NodeGroup)node.parentItem).rtColorPreview;
  931. }
  932. if (texPreview == null)
  933. {
  934. if (item.rtDisplay != null) texPreview = item.rtDisplay;
  935. else if (item.rtPreview != null) texPreview = item.rtPreview;
  936. else if (item.preview.tex != null) texPreview = item.preview.tex;
  937. }
  938. }
  939. if (texPreview == null) texPreview = Texture2D.blackTexture;
  940. //if (selectItem != null && item.outputId == TC.grassOutput)
  941. //{
  942. // GUI.color = new Color(0, 0.5f, 0.25f, 1);
  943. // GUI.DrawTexture(rectPreview, Texture2D.whiteTexture);
  944. // GUI.color = Color.white;
  945. // GUI.DrawTexture(rectPreview, texPreview);
  946. //}
  947. //else
  948. EditorGUI.DrawPreviewTexture(rectPreview, texPreview);
  949. // PreviewEdit(item);
  950. }
  951. GUI.color = Color.white;
  952. if (item.outputId == TC.treeOutput || item.outputId == TC.objectOutput)
  953. {
  954. if (selectItem != null || layer != null || layerGroup != null || selectItemGroup != null)
  955. {
  956. Rect rectButton2 = new Rect(pos.x + 7.24f, pos.y + 306f, 254f, 30);
  957. DrawTextureScaled(rectButton2, texButton, color * (item.active ? 1 : 0.75f));
  958. int placed = 0;
  959. if (selectItem != null) placed = selectItem.placed;
  960. else if (layer != null) placed = layer.placed;
  961. else if (layerGroup != null) placed = layerGroup.placed;
  962. else if (selectItemGroup != null) placed = selectItemGroup.placed;
  963. DrawText(pos + new Vector2(12.24f, 308f), "Placed: " + placed, 21, Color.white * (item.active ? 1 : 0.75f));
  964. }
  965. }
  966. Rect rectSlider = new Rect(rectNode.x + 5, rectNode.y + texCardBody.width + 6, 37 * scale, 10 * scale);
  967. rectSlider.y += 12 * scale;
  968. rectSlider.height = 7f * scale;
  969. rectSlider.x += 23 * scale;
  970. rectSlider.width += 6 * scale;
  971. if (drawMethod)
  972. {
  973. if (layerGroup != null)
  974. {
  975. if (layerGroup.parentItem != null)
  976. {
  977. if (layerGroup.listIndex == ((TC_LayerGroupResult)layerGroup.parentItem).firstActive || !layerGroup.active) activeMulti *= 0.5f;
  978. }
  979. }
  980. else if (layer != null)
  981. {
  982. if (layer.parentItem != null)
  983. {
  984. if (layer.listIndex == ((TC_LayerGroupResult)layer.parentItem).firstActive || !layer.active) activeMulti *= 0.5f;
  985. }
  986. }
  987. else drawMethod = false;
  988. if (drawMethod) DrawMethod(item, pos + new Vector2(310, 187), false, color, activeMulti);
  989. }
  990. Rect rectButton = new Rect(pos.x + 7.24f, pos.y + 306f + 35, 254f, 30);
  991. if (GetRectScaled(rectButton).y > 0)
  992. {
  993. bool drawOpacity = true;
  994. if (layerGroup != null)
  995. {
  996. if (layerGroup.level == 0) drawOpacity = false;
  997. else if (layerGroup.method != Method.Lerp || layerGroup.listIndex == ((TC_LayerGroupResult)layerGroup.parentItem).firstActive) drawOpacity = false;
  998. }
  999. else if (layer != null)
  1000. {
  1001. if (layer.method != Method.Lerp) drawOpacity = false; // || layer.listIndex == ((TC_LayerGroupResult)layer.parentItem).firstActive) drawOpacity = false;
  1002. }
  1003. else if (groupResult != null) drawOpacity = false;
  1004. else if (nodeGroup != null) drawOpacity = false;
  1005. else if (selectItem != null || selectItemGroup != null)
  1006. {
  1007. if (item.outputId == TC.splatOutput || item.outputId == TC.grassOutput) drawOpacity = false;
  1008. if (item.outputId == TC.colorOutput)
  1009. {
  1010. if (selectItemGroup != null || selectItem != null) drawOpacity = false;
  1011. }
  1012. }
  1013. if (drawOpacity)
  1014. {
  1015. if (DrawOpacity(item, rectButton, color, activeMulti))
  1016. {
  1017. if (selectItem != null) selectItem.parentItem.CreateMixBuffer();
  1018. else if (selectItemGroup != null) selectItemGroup.CreateMixBuffer();
  1019. TC.repaintNodeWindow = true;
  1020. EditorUtility.SetDirty(item);
  1021. TC.AutoGenerate();
  1022. }
  1023. }
  1024. }
  1025. if (selectItem != null && item.outputId == TC.treeOutput) rectPreview.height -= 35 * scale;
  1026. DragDropNode(item, rectPreview, rectNode, pos);
  1027. }
  1028. if (Mathw.ArrayContains(Selection.transforms, item.t))
  1029. {
  1030. // Color colLerp = Color.Lerp(new Color(1, 1, 1, 1), new Color(1, 0, 0, 1), Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup * 1.5f)));
  1031. if (nodeFoldout) DrawCommand.Add(new Rect(pos.x - 4f, pos.y - 4f, texSelectCard.width - 2, texSelectCard.height - 2), texSelectCard, Color.white, 1);
  1032. else DrawCommand.Add(new Rect(pos.x - 4f, pos.y - 4f, texSelectCardHeader.width - 2, texSelectCardHeader.height - 2), texSelectCardHeader, Color.white, 1);
  1033. }
  1034. return rectPreview;
  1035. }
  1036. static public void DrawMethod(TC_ItemBehaviour item, Vector2 pos, bool equal, Color backgroundColor, float activeMulti)
  1037. {
  1038. DrawCommand.Add(pos, texOperandBG, backgroundColor * activeMulti, 2);
  1039. Texture texOperand = null;
  1040. if (item.GetType() == typeof(TC_LayerGroup) || item.GetType() == typeof(TC_Layer))
  1041. {
  1042. if (item.outputId == TC.treeOutput || item.outputId == TC.objectOutput)
  1043. {
  1044. if (item.method != Method.Lerp && item.method != Method.Max && item.method != Method.Min) item.method = Method.Lerp;
  1045. }
  1046. }
  1047. if (equal) texOperand = texOperandEqual;
  1048. else switch (item.method)
  1049. {
  1050. case Method.Add: texOperand = texOperandAdd; break;
  1051. case Method.Subtract: texOperand = texOperandSubtract; break;
  1052. case Method.Lerp: texOperand = texOperandLerp; break;
  1053. case Method.Multiply: texOperand = texOperandMultiply; break;
  1054. case Method.Divide: texOperand = texOperandDivide; break;
  1055. case Method.Difference: texOperand = texOperandDiff; break;
  1056. case Method.Average: texOperand = texOperandAverage; break;
  1057. case Method.Min: texOperand = texOperandMin; break;
  1058. case Method.Max: texOperand = texOperandMax; break;
  1059. }
  1060. if (texOperand != null)
  1061. {
  1062. DrawCommand.Add(pos, texOperand, Color.white * Mathf.Clamp01(activeMulti + 0.25f), 2);
  1063. if (!equal) DropDownMethodMenu(item, new Rect(pos.x, pos.y, texOperand.width, texOperand.height));
  1064. }
  1065. }
  1066. static public bool DrawOpacity(TC_ItemBehaviour item, Rect rect, Color color, float activeMulti)
  1067. {
  1068. DrawTextureScaled(rect, texInwardButton, (color + new Color(0.5f, 0.5f, 0.5f)) * activeMulti);
  1069. bool changed = false;
  1070. Vector2 click = ClickRectPercentage(GetRectScaled(rect));
  1071. bool isSelected = selectedOpacityItem == item;
  1072. if (selectedOpacityItem != null && !isSelected) click.x = -1;
  1073. if (mouseDownButton == 0)
  1074. {
  1075. if (Mathw.ArrayContains(Selection.transforms, item.t))
  1076. {
  1077. if (click.x == 0) selectedOpacityItem = item;
  1078. if (isSelected)
  1079. {
  1080. if (item.opacity != click.y) changed = true;
  1081. item.opacity = click.y;
  1082. }
  1083. }
  1084. }
  1085. else selectedOpacityItem = null;
  1086. rect.width *= item.opacity;
  1087. DrawTextureScaled(rect, texInwardButton, color * activeMulti);
  1088. Color fontColor = click.x == -2 || isSelected ? Color.white : new Color(1, 1, 1, 0.5f);
  1089. DrawText(new Vector2(rect.x + 5.02f, rect.y + 14.54f), "Opacity:", 21, Color.white, FontStyle.Normal, HorTextAlign.Left, VerTextAlign.Center);
  1090. DrawText(new Vector2(rect.x + 5.02f + 96.9f, rect.y + 14.54f), "◄►", 14, fontColor, FontStyle.Normal, HorTextAlign.Left, VerTextAlign.Center);
  1091. DrawText(new Vector2(rect.x + 5.02f + 241.97f, rect.y + 14.54f), (item.opacity * 100).ToString("F0") + "%", 21, Color.white, FontStyle.Normal, HorTextAlign.Right, VerTextAlign.Center);
  1092. return changed;
  1093. }
  1094. static public void DropDownMethodMenu(TC_ItemBehaviour item, Rect rect)
  1095. {
  1096. rect = GetRectScaled(rect);
  1097. if (ClickRect(rect) != 0) return;
  1098. GenericMenu menu = new GenericMenu();
  1099. string instanceID = item.GetInstanceID().ToString();
  1100. string methodName;
  1101. if ((item.outputId == TC.treeOutput || item.outputId == TC.objectOutput) && (item.GetType() == typeof(TC_LayerGroup) || item.GetType() == typeof(TC_Layer)))
  1102. {
  1103. menu.AddItem(new GUIContent("Lerp"), false, LeftClickMethodMenu, instanceID + ":" + "Lerp");
  1104. menu.AddItem(new GUIContent("Max"), false, LeftClickMethodMenu, instanceID + ":" + "Max");
  1105. menu.AddItem(new GUIContent("Min"), false, LeftClickMethodMenu, instanceID + ":" + "Min");
  1106. }
  1107. else
  1108. {
  1109. for (int i = 0; i < 9; i++)
  1110. {
  1111. methodName = ((Method)i).ToString();
  1112. menu.AddItem(new GUIContent(methodName), false, LeftClickMethodMenu, instanceID + ":" + methodName);
  1113. }
  1114. }
  1115. menu.ShowAsContext();
  1116. eventCurrent.Use();
  1117. }
  1118. static void LeftClickMethodMenu(object obj)
  1119. {
  1120. int instanceID;
  1121. string command = ObjectToCommandAndInstanceID(obj, out instanceID);
  1122. TC_ItemBehaviour item = EditorUtility.InstanceIDToObject(instanceID) as TC_ItemBehaviour;
  1123. Method oldMethod = item.method;
  1124. item.method = (Method)System.Enum.Parse(typeof(Method), command);
  1125. if (item.method != oldMethod)
  1126. {
  1127. EditorUtility.SetDirty(item);
  1128. TC.AutoGenerate();
  1129. }
  1130. }
  1131. static public string ObjectToCommandAndInstanceID(object obj, out int instanceID)
  1132. {
  1133. string command = obj.ToString();
  1134. int index = command.IndexOf(":");
  1135. int.TryParse(command.Substring(0, index), out instanceID);
  1136. return command.Substring(index + 1);
  1137. }
  1138. static public void DrawBracket(ref Vector2 pos, bool nodeFoldout, bool isRightBracket, Color color, ref int foldout, bool drawFoldoutButton, bool clickAbleFoldout)
  1139. {
  1140. TC_GlobalSettings g = TC_Settings.instance.global;
  1141. pos.x -= isRightBracket ? texBracketBody.width + g.nodeHSpace : texBracketBody.width + g.bracketHSpace;
  1142. DrawTextureScaled(pos.x, pos.y, texBracketHeader, color, !isRightBracket);
  1143. Rect rect;
  1144. if (isRightBracket) rect = new Rect(pos.x + 29.1f, pos.y + 3.52f, texBracketLeft.width - 5, texBracketLeft.height - 5);
  1145. else rect = new Rect(pos.x + 7.1f, pos.y + 3.52f, texBracketLeft.width - 5, texBracketRight.height - 5);
  1146. int mouseClick = Button(rect, (foldout < 2 ? !isRightBracket : isRightBracket) ? texBracketLeft : texBracketRight, foldout == 2, new Color(1, 1, 1, 0.25f), Color.white, new Color(1, 1, 1, 0.25f), clickAbleFoldout);
  1147. if (mouseClick == 0) {
  1148. if (foldout == 2) foldout = 0; else foldout = 2;
  1149. }
  1150. else if (mouseClick == 1) {
  1151. if (foldout == 2) foldout = 1; else foldout = 2;
  1152. }
  1153. if (nodeFoldout) DrawTextureScaled(pos.x, pos.y + texBracketHeader.height, texBracketBody, color, !isRightBracket);
  1154. pos.x -= isRightBracket ? g.bracketHSpace : 0;
  1155. // Debug.Log(pos.y);
  1156. if (-pos.x > scrollMax.x) scrollMax.x = -pos.x;
  1157. if (pos.y > scrollMax.y) scrollMax.y = -pos.y;
  1158. }
  1159. static public int Button(Rect rect, Texture tex, bool active, Color colNormal, Color colHover, Color colDisabled, bool clickAble = true, bool drawTextureCommand = false)
  1160. {
  1161. Rect rectScaled = GetRectScaled(rect);
  1162. if (!clickAble)
  1163. {
  1164. if (drawTextureCommand) DrawCommand.Add(rect, tex, colNormal, 2);
  1165. else DrawTexture(rectScaled, tex, colNormal);
  1166. return -1;
  1167. }
  1168. int mouseState = ClickRect(rectScaled);
  1169. Color color = mouseState == -2 ? colHover : active ? colNormal : colDisabled;
  1170. if (drawTextureCommand) DrawCommand.Add(rect, tex, color, 2);
  1171. else DrawTexture(rectScaled, tex, color);
  1172. return mouseState;
  1173. }
  1174. static public int DrawNodeCount(TC_ItemBehaviour item, ref Vector2 pos, int itemCount, bool nodeFoldout, ref int foldout, Color color, float scale = 1)
  1175. {
  1176. if (foldout == 2 && itemCount > 0) return -1;
  1177. pos.x -= foldout == 1 ? 10 : 20;
  1178. float posY = 0;
  1179. if (nodeFoldout) posY += (cardHeight / 2) - (texBracketHeader.height / 2);
  1180. else pos.x -= 20;
  1181. Rect rect = new Rect(pos.x - 38 , pos.y + posY - 32, texCardCounter.width * scale, texCardCounter.height * scale);
  1182. Rect rectScaled = GetRectScaled(rect);
  1183. int mouseClick = ClickRect(rectScaled);
  1184. DrawCommand.Add(rect, texCardCounter, color, 2);
  1185. if (foldout == 1) pos.x += 10;
  1186. if (itemCount == 0)
  1187. {
  1188. DrawCommand.Add(rect, texAddFirstCard, mouseClick == -2 ? Color.white : new Color(1, 1, 1, 0.25f), 2);
  1189. DragDropNode(item, rectScaled, rectScaled, pos, false, false);
  1190. }
  1191. else
  1192. {
  1193. DrawCommand.Add(new Vector2(rect.x + (50 * scale), rect.y + (50 * scale)), itemCount.ToString(), Mathf.RoundToInt(0.48f * rect.width), mouseClick == -2 ? Color.white : new Color(1, 1, 1, 0.35f), FontStyle.Normal, HorTextAlign.Center, VerTextAlign.Center);
  1194. }
  1195. if (mouseClick == 0) foldout = 2;
  1196. return mouseClick;
  1197. }
  1198. static public bool DrawButton(Rect rect, string text, int fontSize, bool bold, Color col, Color colBackground)
  1199. {
  1200. int oldFontSize = GUI.skin.button.fontSize;
  1201. FontStyle oldBold = GUI.skin.button.fontStyle;
  1202. Color colTextOld = GUI.skin.button.normal.textColor;
  1203. rect = GetRectScaled(rect);
  1204. if (bold) GUI.skin.button.fontStyle = FontStyle.Bold;
  1205. GUI.skin.button.fontSize = (int)(fontSize * scale);
  1206. GUI.skin.button.normal.textColor = col;
  1207. GUI.backgroundColor = colBackground;
  1208. bool clicked = GUI.Button(rect, text);
  1209. GUI.backgroundColor = Color.white;
  1210. GUI.skin.button.fontSize = oldFontSize;
  1211. GUI.skin.button.fontStyle = oldBold;
  1212. GUI.skin.button.normal.textColor = colTextOld;
  1213. return clicked;
  1214. }
  1215. static public Vector2 GetLabelSize(string label)
  1216. {
  1217. return GUI.skin.GetStyle("Label").CalcSize(new GUIContent(label));
  1218. }
  1219. static public void DrawText(Vector2 pos, string text, int fontSize, Color color, FontStyle fontStyle = FontStyle.Normal, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign verTextAlign = VerTextAlign.Top)
  1220. {
  1221. Color colorOld = GUI.color;
  1222. GUI.color = color;
  1223. int old_fontSize = GUI.skin.label.fontSize;
  1224. FontStyle old_fontStyle = GUI.skin.label.fontStyle;
  1225. Color colTextOld = GUI.skin.label.normal.textColor;
  1226. GUI.skin.label.fontSize = fontSize;
  1227. GUI.skin.label.fontStyle = fontStyle;
  1228. GUI.skin.label.normal.textColor = Color.white;
  1229. Vector2 size = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(text));
  1230. size.x += 7;
  1231. AlignPosition(ref pos, size, horTextAlign, verTextAlign);
  1232. pos = GetPositionScaled(pos);
  1233. Matrix4x4 oldMatrix = GUI.matrix;
  1234. GUIUtility.ScaleAroundPivot(new Vector2(scale, scale), new Vector2(pos.x, pos.y));
  1235. GUI.Label(new Rect(pos.x, pos.y, size.x, size.y), text);
  1236. GUI.matrix = oldMatrix;
  1237. GUI.skin.label.fontSize = old_fontSize;
  1238. GUI.skin.label.fontStyle = old_fontStyle;
  1239. GUI.color = colorOld;
  1240. GUI.skin.label.normal.textColor = colTextOld;
  1241. }
  1242. static public float DrawTextX(Vector2 pos, float rightMargin, float leftPos, string text, int fontSize, FontStyle fontStyle, Color color, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign verTextAlign = VerTextAlign.Top)
  1243. {
  1244. Color colorOld = GUI.color;
  1245. GUI.color = color;
  1246. int old_fontSize = GUI.skin.label.fontSize;
  1247. FontStyle old_fontStyle = GUI.skin.label.fontStyle;
  1248. GUI.skin.label.fontSize = Mathf.RoundToInt(fontSize * scale);
  1249. GUI.skin.label.fontStyle = fontStyle;
  1250. Vector2 size = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(text));
  1251. AlignPosition(ref pos, size, horTextAlign, verTextAlign);
  1252. Vector2 sPos = GetPositionScaled(new Vector2(pos.x, pos.y));
  1253. Rect sRect = new Rect(sPos.x, sPos.y, size.x, size.y);
  1254. rightMargin *= scale;
  1255. if (sRect.x + size.x + rightMargin > TC_NodeWindow.window.position.width) sRect.x = TC_NodeWindow.window.position.width - size.x - rightMargin;
  1256. float delta = sRect.x - GetPosX(leftPos);
  1257. if (delta < 0) sRect.x -= delta;
  1258. GUI.Label(sRect, text);
  1259. GUI.skin.label.fontSize = old_fontSize;
  1260. GUI.skin.label.fontStyle = old_fontStyle;
  1261. GUI.color = colorOld;
  1262. return (size.x / scale);
  1263. }
  1264. static public void DrawSlider(Vector2 startOffset, ref float value, float min, float max)
  1265. {
  1266. Vector2 sliderPos = GetPositionScaled(new Vector2(startOffset.x + 6, (startOffset.y + 84)));
  1267. GUIUtility.ScaleAroundPivot(new Vector2(scale / 1.5f, scale / 1.5f), new Vector2(sliderPos.x, sliderPos.y));
  1268. GUI.changed = false;
  1269. value = GUI.HorizontalSlider(new Rect(sliderPos.x, sliderPos.y, 93, 10), value, 0, max);
  1270. GUI.matrix = Matrix4x4.Scale(new Vector3(1, 1, 1));
  1271. }
  1272. static public void AlignPosition(ref Vector2 pos, Vector2 size, HorTextAlign horTextAlign, VerTextAlign verTextAlign)
  1273. {
  1274. if (horTextAlign == HorTextAlign.Center) pos.x -= size.x / 2;
  1275. else if (horTextAlign == HorTextAlign.Right) pos.x -= size.x;
  1276. if (verTextAlign == VerTextAlign.Center) pos.y -= size.y / 2;
  1277. else if (verTextAlign == VerTextAlign.Bottom) pos.y -= size.y;
  1278. }
  1279. static public void AlignPosition(ref Rect rect, HorTextAlign horTextAlign, VerTextAlign verTextAlign)
  1280. {
  1281. if (horTextAlign == HorTextAlign.Center) rect.x -= rect.width / 2;
  1282. else if (horTextAlign == HorTextAlign.Right) rect.x -= rect.width;
  1283. if (verTextAlign == VerTextAlign.Center) rect.y -= rect.height / 2;
  1284. else if (verTextAlign == VerTextAlign.Bottom) rect.y -= rect.height;
  1285. }
  1286. static public void DrawPopup(Rect rect, ref System.Enum popup, int fontSize, FontStyle fontStyle, Color color)
  1287. {
  1288. int fontSizeOld = EditorStyles.popup.fontSize;
  1289. FontStyle fontStyleOld = EditorStyles.popup.fontStyle;
  1290. // float fixedHeightOld = EditorStyles.popup.fixedHeight;
  1291. EditorStyles.label.fontSize = Mathf.RoundToInt(fontSize * scale);
  1292. EditorStyles.label.fontStyle = fontStyle;
  1293. // EditorStyles.popup.fixedHeight = rect.height;
  1294. // EditorStyles.popup.stretchHeight = true;
  1295. // EditorStyles.popup.CalcScreenSize(new Vector2(rect.width,rect.height));
  1296. GUI.color = color;
  1297. GUI.DrawTexture(new Rect(rect.x, rect.y, 4, rect.height), enumBG_Start);
  1298. GUI.DrawTexture(new Rect(rect.x + 4, rect.y, rect.width - 15, rect.height), enumBG_Middle);
  1299. GUI.DrawTexture(new Rect(rect.x + (rect.width - 11), rect.y, 11, rect.height), enumBG_End);
  1300. rect.x += 3 * scale;
  1301. rect.width -= 3 * scale;
  1302. GUI.changed = false;
  1303. popup = (Method)EditorGUI.EnumPopup(rect, "", popup, EditorStyles.label);
  1304. if (GUI.changed) TC.AutoGenerate();
  1305. // GUI.color = Color.red;
  1306. // GUI.DrawTexture (rect,tex);
  1307. EditorStyles.label.fontSize = fontSizeOld;
  1308. EditorStyles.label.fontStyle = fontStyleOld;
  1309. // EditorStyles.popup.fixedHeight = fixedHeightOld;
  1310. }
  1311. static public bool DrawButton(Rect rect, Texture texture, int mouseButton, Color color)
  1312. {
  1313. Rect sRect = GetRectScaled(rect);
  1314. Color colorOld = GUI.color;
  1315. GUI.color = color;
  1316. GUI.DrawTexture(sRect, texture);
  1317. GUI.color = colorOld;
  1318. return ClickRect(sRect, mouseButton);
  1319. }
  1320. static public bool DrawButtonX(Rect rect, float rightMargin, float leftPos, Texture texture, int mouseButton, Color color, HorTextAlign horTextAlign = HorTextAlign.Left, VerTextAlign verTextAlign = VerTextAlign.Top)
  1321. {
  1322. // Rect sRect = GetRect (rect);
  1323. // sRect = new Rect(rect.x*scale,sRect.y,sRect.width,sRect.height);
  1324. AlignPosition(ref rect, horTextAlign, verTextAlign);
  1325. Rect sRect = GetRectScaled(rect);
  1326. rightMargin *= scale;
  1327. if (sRect.x + rect.width + rightMargin > TC_NodeWindow.window.position.width) sRect.x = TC_NodeWindow.window.position.width - rect.width - rightMargin;
  1328. float delta = sRect.x - GetPosX(leftPos);
  1329. if (delta < 0) sRect.x -= delta;
  1330. Color colorOld = GUI.color;
  1331. GUI.color = color;
  1332. GUI.DrawTexture(sRect, texture);
  1333. GUI.color = colorOld;
  1334. return ClickRect(sRect, mouseButton);
  1335. }
  1336. static public void DrawBar(Rect topBar, Rect bottomBar, float barWidth, Color color)
  1337. {
  1338. // Header Bar
  1339. TD.DrawRect(topBar, TD.texFadeBar, color);
  1340. // Vertical Bar
  1341. TD.DrawRect(new Rect(topBar.xMax, topBar.y, barWidth, bottomBar.yMax - topBar.y), Texture2D.whiteTexture, color);
  1342. TD.DrawRect(bottomBar, TD.texFadeBar, color);
  1343. // Bottom Bar
  1344. }
  1345. static public bool ClickRect(Rect rect, int mouseButton)
  1346. {
  1347. // rect = GetRect (rect);
  1348. if (eventCurrent.type == EventType.MouseDown)
  1349. {
  1350. if (rect.Contains(eventCurrent.mousePosition) && eventCurrent.button == mouseButton) return true;
  1351. }
  1352. return false;
  1353. }
  1354. static public int ClickRect(Rect rect)
  1355. {
  1356. // rect = GetRect (rect);
  1357. if (rect.Contains(eventCurrent.mousePosition))
  1358. {
  1359. if (eventCurrent.type == EventType.MouseDown)
  1360. {
  1361. return eventCurrent.button;
  1362. }
  1363. return -2; // hover
  1364. }
  1365. return -1;
  1366. }
  1367. static public int ClickRect(Rect rect, Rect rectExclude)
  1368. {
  1369. // rect = GetRect (rect);
  1370. Vector2 mousePosition = eventCurrent.mousePosition;
  1371. if (rect.Contains(mousePosition) && !rectExclude.Contains(mousePosition))
  1372. {
  1373. if (eventCurrent.type == EventType.MouseDown)
  1374. {
  1375. return eventCurrent.button;
  1376. }
  1377. return -2; // hover
  1378. }
  1379. return -1;
  1380. }
  1381. static public Vector2 ClickRectPercentage(Rect rect)
  1382. {
  1383. if (rect.Contains(posClickMouseDown))
  1384. {
  1385. TC.repaintNodeWindow = true;
  1386. return new Vector2(eventCurrent.button, Mathf.Clamp01((eventCurrent.mousePosition.x - rect.x) / rect.width));
  1387. }
  1388. else if (rect.Contains(eventCurrent.mousePosition))
  1389. {
  1390. return new Vector2(-2, Mathf.Clamp01((eventCurrent.mousePosition.x - rect.x) / rect.width)); // hover
  1391. }
  1392. return new Vector2(-1, Mathf.Clamp01((eventCurrent.mousePosition.x - rect.x) / rect.width));
  1393. }
  1394. static public void DrawLabel(string label, int fontSize)
  1395. {
  1396. int fontSizeOld = EditorStyles.label.fontSize;
  1397. EditorStyles.boldLabel.fontSize = fontSize;
  1398. EditorGUILayout.LabelField(label, EditorStyles.boldLabel, GUILayout.Height(fontSize + 6));
  1399. EditorStyles.boldLabel.fontSize = fontSizeOld;
  1400. }
  1401. static public void DrawLabelWidthUnderline(string label, int fontSize, bool boldLabel = true)
  1402. {
  1403. int fontSizeOld = EditorStyles.label.fontSize;
  1404. EditorStyles.boldLabel.fontSize = fontSize;
  1405. EditorGUILayout.LabelField(label, boldLabel ? EditorStyles.boldLabel : EditorStyles.label, GUILayout.Height(fontSize + 6));
  1406. EditorStyles.boldLabel.fontSize = fontSizeOld;
  1407. Rect rect = GUILayoutUtility.GetLastRect();
  1408. GUI.color = Color.grey;
  1409. GUI.DrawTexture(new Rect(rect.x, rect.yMax, rect.width, 1), Texture2D.whiteTexture);
  1410. GUI.color = Color.white;
  1411. GUILayout.Space(5);
  1412. }
  1413. static public void PreviewEdit(TC_ItemBehaviour item)
  1414. {
  1415. Event key = eventCurrent;
  1416. if (key.type == EventType.MouseDrag)
  1417. {
  1418. if (key.button == 0)
  1419. {
  1420. Vector3 delta = Quaternion.Inverse(item.t.rotation) * new Vector3(key.delta.x * (1000 / 250), 0, -key.delta.y * (1000 / 250));
  1421. if (delta.x != 0 || delta.y != 0 || delta.z != 0)
  1422. {
  1423. item.t.position += item.t.TransformDirection(new Vector3(delta.x / item.t.lossyScale.x, 0, delta.z / item.t.lossyScale.z));
  1424. TC.AutoGenerate();
  1425. }
  1426. }
  1427. if (key.button == 1) item.t.Rotate(0, key.delta.x, 0);
  1428. // item.ResetOffset();
  1429. }
  1430. if (key.type == EventType.ScrollWheel)
  1431. {
  1432. Vector3 scale = item.t.localScale;
  1433. if (key.delta.y > 0) scale /= 1 + ((key.delta.y / 3) * 0.1f);
  1434. else scale *= 1 + ((-key.delta.y / 3) * 0.1f);
  1435. // if (scale.x == 0) scale.x = 0.000001f;
  1436. // if (scale.z == 0) scale.z = 0.000001f;
  1437. item.t.localScale = scale;
  1438. // item.ResetOffset();
  1439. TC_Reporter.Log("" + scale);
  1440. }
  1441. }
  1442. static public void DrawProperty(SerializedProperty property, GUIContent guiContent = null, float width = -1)
  1443. {
  1444. GUI.changed = false;
  1445. if (width == -1)
  1446. {
  1447. if (guiContent == null) EditorGUILayout.PropertyField(property);
  1448. else EditorGUILayout.PropertyField(property, guiContent);
  1449. }
  1450. else
  1451. {
  1452. if (guiContent == null) EditorGUILayout.PropertyField(property, GUILayout.Width(width));
  1453. else EditorGUILayout.PropertyField(property, guiContent, GUILayout.Width(width));
  1454. }
  1455. if (GUI.changed) TC.AutoGenerate();
  1456. }
  1457. static public void DrawPropertyArray(SerializedProperty property)
  1458. {
  1459. EditorGUILayout.BeginHorizontal();
  1460. GUILayout.Space(0);
  1461. Rect rect = GUILayoutUtility.GetLastRect();
  1462. property.isExpanded = EditorGUI.Foldout(new Rect(rect.x, rect.y + 3, 25, 18), property.isExpanded, "");
  1463. if (property.isExpanded) DrawLabelWidthUnderline(property.displayName, 12); else DrawLabel(property.displayName, 12);
  1464. EditorGUILayout.EndHorizontal();
  1465. if (property.isExpanded)
  1466. {
  1467. GUILayout.Space(5);
  1468. EditorGUILayout.BeginVertical("Box");
  1469. EditorGUI.indentLevel++;
  1470. property.arraySize = EditorGUILayout.IntField("Size", property.arraySize);
  1471. EditorGUI.indentLevel--;
  1472. EditorGUI.indentLevel++;
  1473. for (int i = 0; i < property.arraySize; i++)
  1474. {
  1475. SerializedProperty elementProperty = property.GetArrayElementAtIndex(i);
  1476. DrawProperty(elementProperty);
  1477. }
  1478. EditorGUI.indentLevel--;
  1479. EditorGUILayout.EndVertical();
  1480. }
  1481. }
  1482. static public SerializedProperty DrawArrayProperty(SerializedProperty arrayElement, string name)
  1483. {
  1484. SerializedProperty element = arrayElement.FindPropertyRelative(name);
  1485. if (element != null) EditorGUILayout.PropertyField(element);
  1486. return element;
  1487. }
  1488. static public void DrawSpacer(float space = 5)
  1489. {
  1490. GUILayout.Space(space);
  1491. EditorGUILayout.BeginHorizontal();
  1492. GUI.color = new Color(0.5f, 0.5f, 0.5f, 1);
  1493. GUILayout.Button("", GUILayout.Height(5));
  1494. EditorGUILayout.EndHorizontal();
  1495. GUILayout.Space(space);
  1496. GUI.color = Color.white;
  1497. }
  1498. static public void ClickOutputButton(TC_LayerGroup layerGroup)
  1499. {
  1500. if (eventCurrent.button == 0)
  1501. {
  1502. layerGroup.visible = !layerGroup.visible;
  1503. EditorUtility.SetDirty(layerGroup);
  1504. TC.RefreshOutputReferences(layerGroup.outputId, layerGroup.visible);
  1505. }
  1506. else
  1507. {
  1508. if (TC_Area2D.current == null) return;
  1509. bool visibleOld = layerGroup.visible;
  1510. layerGroup.visible = true;
  1511. // TC_Area2D.current.terrainLayer.GetItem(layerGroup.outputId);
  1512. TC_Generate.instance.Generate(false, layerGroup.outputId);
  1513. layerGroup.visible = visibleOld;
  1514. }
  1515. }
  1516. static public class MinMaxSlider
  1517. {
  1518. static public Texture sliderBaseMiddle;
  1519. static public Texture sliderBaseLeft;
  1520. static public Texture sliderBaseRight;
  1521. static public Texture sliderMiddle;
  1522. static public Texture sliderLeft;
  1523. static public Texture sliderRight;
  1524. static public bool changed = false;
  1525. static public bool mouseDown = false;
  1526. static public Vector2 mousePosOld;
  1527. static public Vector2 delta;
  1528. static public Vector2 vOld;
  1529. static public bool leftDown = false;
  1530. static public bool rightDown = false;
  1531. static public bool middleDown = false;
  1532. static public Vector2 Draw(Rect rect, Vector2 v, float min, float max, Vector2 clickOffset)
  1533. {
  1534. if (eventCurrent == null) return v;
  1535. changed = false;
  1536. rect.width -= 16.0f;
  1537. if (sliderBaseMiddle == null) LoadTextures();
  1538. // Debug.Log(key.mousePosition+", "+rect);
  1539. float range = max - min;
  1540. float scale = range / rect.width;
  1541. float vRange = v.y - v.x;
  1542. // Debug.Log(rect);
  1543. // Debug.Log(scale);
  1544. GUI.DrawTexture(new Rect(rect.x + 2, rect.y + (rect.height / 2), rect.width + 12, 5.0f), sliderBaseMiddle);
  1545. GUI.DrawTexture(new Rect(rect.x, rect.y + (rect.height / 2), 2.0f, 5.0f), sliderBaseLeft);
  1546. GUI.DrawTexture(new Rect((rect.x + rect.width) + 14, rect.y + (rect.height / 2), 2.0f, 5.0f), sliderBaseRight);
  1547. float startLeft = (((v.x - min) / range) * rect.width);
  1548. float startRight = (((v.y - min) / range) * rect.width);
  1549. Rect leftRect = new Rect(rect.x + startLeft, rect.y + (rect.height / 2) - 3, 8.0f, 11.0f);
  1550. Rect rightRect = new Rect(rect.x + startRight + 8, rect.y + (rect.height / 2) - 3, 8.0f, 11.0f);
  1551. Rect middleRect = new Rect(rect.x + startLeft + 8, rect.y + (rect.height / 2), (startRight - startLeft), 5.0f);
  1552. GUI.DrawTexture(middleRect, sliderMiddle);
  1553. GUI.DrawTexture(leftRect, sliderLeft);
  1554. GUI.DrawTexture(rightRect, sliderRight);
  1555. middleRect.y -= 5.0f;
  1556. middleRect.height += 10.0f;
  1557. if (eventCurrent.type == EventType.MouseDown)
  1558. {
  1559. if (leftRect.Contains(eventCurrent.mousePosition))
  1560. {
  1561. leftDown = true;
  1562. mousePosOld = eventCurrent.mousePosition;
  1563. vOld = v;
  1564. mouseDown = true;
  1565. }
  1566. else if (rightRect.Contains(eventCurrent.mousePosition))
  1567. {
  1568. rightDown = true;
  1569. mousePosOld = eventCurrent.mousePosition;
  1570. vOld = v;
  1571. mouseDown = true;
  1572. }
  1573. else if (middleRect.Contains(eventCurrent.mousePosition))
  1574. {
  1575. middleDown = true;
  1576. mousePosOld = eventCurrent.mousePosition;
  1577. vOld = v;
  1578. mouseDown = true;
  1579. }
  1580. }
  1581. if (eventCurrent.type == EventType.MouseUp)
  1582. {
  1583. mouseDown = false;
  1584. leftDown = false;
  1585. rightDown = false;
  1586. middleDown = false;
  1587. }
  1588. delta = eventCurrent.mousePosition - mousePosOld;
  1589. if (mouseDown)
  1590. {
  1591. if (leftDown)
  1592. {
  1593. leftRect.x -= clickOffset.x;
  1594. leftRect.width += clickOffset.x * 2;
  1595. leftRect.y -= clickOffset.y;
  1596. leftRect.height += clickOffset.y * 2;
  1597. if (leftRect.Contains(eventCurrent.mousePosition))
  1598. {
  1599. v.x = vOld.x + (delta.x * scale);
  1600. changed = true;
  1601. }
  1602. }
  1603. else if (rightDown)
  1604. {
  1605. rightRect.x -= clickOffset.x;
  1606. rightRect.width += clickOffset.x * 2;
  1607. rightRect.y -= clickOffset.y;
  1608. rightRect.height += clickOffset.y * 2;
  1609. if (rightRect.Contains(eventCurrent.mousePosition))
  1610. {
  1611. v.y = vOld.y + (delta.x * scale);
  1612. if (v.y < v.x) v.y = v.x;
  1613. changed = true;
  1614. }
  1615. }
  1616. if (middleDown)
  1617. {
  1618. middleRect.x -= clickOffset.x;
  1619. middleRect.width += clickOffset.x * 2;
  1620. middleRect.y -= clickOffset.y;
  1621. middleRect.height += clickOffset.y * 2;
  1622. if (middleRect.Contains(eventCurrent.mousePosition))
  1623. {
  1624. v = new Vector2(vOld.x + (delta.x * scale), vOld.y + (delta.x * scale));
  1625. if (v.x < min) { v.x = min; v.y = min + vRange; }
  1626. if (v.y > max) { v.y = max; v.x = max - vRange; }
  1627. changed = true;
  1628. }
  1629. }
  1630. }
  1631. v.y = Mathf.Clamp(v.y, min, max);
  1632. v.x = Mathf.Clamp(v.x, min, v.y);
  1633. return v;
  1634. }
  1635. static public void LoadTextures()
  1636. {
  1637. sliderBaseMiddle = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderBaseMiddle.psd", typeof(Texture));
  1638. sliderBaseLeft = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderBaseLeft.psd", typeof(Texture));
  1639. sliderBaseRight = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderBaseRight.psd", typeof(Texture));
  1640. sliderMiddle = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderMiddle.psd", typeof(Texture));
  1641. sliderLeft = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderLeft.psd", typeof(Texture));
  1642. sliderRight = (Texture)AssetDatabase.LoadAssetAtPath(TC.installPath + "/GUI/Buttons/SliderRight.psd", typeof(Texture));
  1643. }
  1644. }
  1645. }
  1646. [System.Serializable]
  1647. public class NodeDraw
  1648. {
  1649. // public Vector2 offset = new Vector2(0,0);
  1650. public bool selected = false;
  1651. }
  1652. [System.Serializable]
  1653. public class GroupNodeDraw
  1654. {
  1655. // public Vector2 offset = new Vector2(0,0);
  1656. public bool foldout = true;
  1657. public bool selected = false;
  1658. }
  1659. }