ParentGraph.cs 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System;
  6. using System.Linq;
  7. using System.Collections.Generic;
  8. namespace AmplifyShaderEditor
  9. {
  10. [Serializable]
  11. public class ParentGraph : ScriptableObject, ISerializationCallbackReceiver
  12. {
  13. private const int MasterNodeLODIncrement = 100;
  14. private const int MaxLodAmount = 9;
  15. public enum NodeLOD
  16. {
  17. LOD0,
  18. LOD1,
  19. LOD2,
  20. LOD3,
  21. LOD4,
  22. LOD5
  23. }
  24. [SerializeField]
  25. private bool m_samplingThroughMacros = false;
  26. private NodeLOD m_lodLevel = NodeLOD.LOD0;
  27. private GUIStyle nodeStyleOff;
  28. private GUIStyle nodeStyleOn;
  29. private GUIStyle nodeTitle;
  30. private GUIStyle commentaryBackground;
  31. public delegate void LODMasterNodesAdded( int lod );
  32. public event LODMasterNodesAdded OnLODMasterNodesAddedEvent;
  33. public delegate void EmptyGraphDetected( ParentGraph graph );
  34. public event EmptyGraphDetected OnEmptyGraphDetectedEvt;
  35. public delegate void NodeEvent( ParentNode node );
  36. public event NodeEvent OnNodeEvent = null;
  37. public event NodeEvent OnNodeRemovedEvent;
  38. public delegate void DuplicateEvent();
  39. public event DuplicateEvent OnDuplicateEvent;
  40. public event MasterNode.OnMaterialUpdated OnMaterialUpdatedEvent;
  41. public event MasterNode.OnMaterialUpdated OnShaderUpdatedEvent;
  42. private bool m_afterDeserializeFlag = true;
  43. private bool m_lateOptionsRefresh = false;
  44. private bool m_foundDuplicates = false;
  45. //[SerializeField]
  46. private AmplifyShaderEditorWindow m_parentWindow = null;
  47. [SerializeField]
  48. private int m_validNodeId;
  49. [SerializeField]
  50. private List<ParentNode> m_nodes = new List<ParentNode>();
  51. // Sampler Nodes registry
  52. [SerializeField]
  53. private UsageListSamplerNodes m_samplerNodes = new UsageListSamplerNodes();
  54. [SerializeField]
  55. private UsageListFloatIntNodes m_floatNodes = new UsageListFloatIntNodes();
  56. [SerializeField]
  57. private UsageListTexturePropertyNodes m_texturePropertyNodes = new UsageListTexturePropertyNodes();
  58. [SerializeField]
  59. private UsageListTextureArrayNodes m_textureArrayNodes = new UsageListTextureArrayNodes();
  60. [SerializeField]
  61. private UsageListPropertyNodes m_propertyNodes = new UsageListPropertyNodes();
  62. [SerializeField]
  63. private UsageListPropertyNodes m_rawPropertyNodes = new UsageListPropertyNodes();
  64. [SerializeField]
  65. private UsageListScreenColorNodes m_screenColorNodes = new UsageListScreenColorNodes();
  66. [SerializeField]
  67. private UsageListRegisterLocalVarNodes m_localVarNodes = new UsageListRegisterLocalVarNodes();
  68. [SerializeField]
  69. private UsageListGlobalArrayNodes m_globalArrayNodes = new UsageListGlobalArrayNodes();
  70. [SerializeField]
  71. private UsageListFunctionInputNodes m_functionInputNodes = new UsageListFunctionInputNodes();
  72. [SerializeField]
  73. private UsageListFunctionNodes m_functionNodes = new UsageListFunctionNodes();
  74. [SerializeField]
  75. private UsageListFunctionOutputNodes m_functionOutputNodes = new UsageListFunctionOutputNodes();
  76. [SerializeField]
  77. private UsageListFunctionSwitchNodes m_functionSwitchNodes = new UsageListFunctionSwitchNodes();
  78. [SerializeField]
  79. private UsageListFunctionSwitchCopyNodes m_functionSwitchCopyNodes = new UsageListFunctionSwitchCopyNodes();
  80. [SerializeField]
  81. private UsageListTemplateMultiPassMasterNodes m_multiPassMasterNodes = new UsageListTemplateMultiPassMasterNodes();
  82. [SerializeField]
  83. private List<UsageListTemplateMultiPassMasterNodes> m_lodMultiPassMasterNodes;
  84. [SerializeField]
  85. private UsageListCustomExpressionsOnFunctionMode m_customExpressionsOnFunctionMode = new UsageListCustomExpressionsOnFunctionMode();
  86. [SerializeField]
  87. private UsageListStaticSwitchNodes m_staticSwitchNodes = new UsageListStaticSwitchNodes();
  88. [SerializeField]
  89. private int m_masterNodeId = Constants.INVALID_NODE_ID;
  90. [SerializeField]
  91. private bool m_isDirty;
  92. [SerializeField]
  93. private bool m_saveIsDirty = false;
  94. [SerializeField]
  95. private int m_nodeClicked;
  96. [SerializeField]
  97. private int m_loadedShaderVersion;
  98. [SerializeField]
  99. private int m_instancePropertyCount = 0;
  100. [SerializeField]
  101. private int m_virtualTextureCount = 0;
  102. [SerializeField]
  103. private int m_graphId = 0;
  104. [SerializeField]
  105. private PrecisionType m_currentPrecision = PrecisionType.Float;
  106. [SerializeField]
  107. private NodeAvailability m_currentCanvasMode = NodeAvailability.SurfaceShader;
  108. [SerializeField]
  109. private TemplateSRPType m_currentSRPType = TemplateSRPType.BiRP;
  110. //private List<ParentNode> m_visibleNodes = new List<ParentNode>();
  111. private List<ParentNode> m_nodePreviewList = new List<ParentNode>();
  112. private Dictionary<int, ParentNode> m_nodesDict = new Dictionary<int, ParentNode>();
  113. [NonSerialized]
  114. private List<ParentNode> m_selectedNodes = new List<ParentNode>();
  115. [NonSerialized]
  116. private List<ParentNode> m_markedForDeletion = new List<ParentNode>();
  117. [SerializeField]
  118. private List<WireReference> m_highlightedWires = new List<WireReference>();
  119. private System.Type m_masterNodeDefaultType;
  120. [SerializeField]
  121. private List<PropertyNode> m_internalTemplateNodesList = new List<PropertyNode>();
  122. private Dictionary<int, PropertyNode> m_internalTemplateNodesDict = new Dictionary<int, PropertyNode>();
  123. private NodeGrid m_nodeGrid;
  124. private bool m_markedToDeSelect = false;
  125. private int m_markToSelect = -1;
  126. private bool m_markToReOrder = false;
  127. private bool m_hasUnConnectedNodes = false;
  128. private bool m_checkSelectedWireHighlights = false;
  129. // Bezier info
  130. [SerializeField]
  131. private List<WireBezierReference> m_bezierReferences;
  132. private const int MaxBezierReferences = 50;
  133. private int m_wireBezierCount = 0;
  134. protected int m_normalDependentCount = 0;
  135. private bool m_forceCategoryRefresh = false;
  136. [SerializeField]
  137. private bool m_forceRepositionCheck = false;
  138. private bool m_isLoading = false;
  139. private bool m_isDuplicating = false;
  140. private bool m_changedLightingModel = false;
  141. public void ResetEvents()
  142. {
  143. OnNodeEvent = null;
  144. OnMaterialUpdatedEvent = null;
  145. OnShaderUpdatedEvent = null;
  146. OnEmptyGraphDetectedEvt = null;
  147. OnNodeRemovedEvent = null;
  148. }
  149. public void Init()
  150. {
  151. UndoUtils.RegisterUndoRedoCallback( OnUndoRedoCallback );
  152. m_normalDependentCount = 0;
  153. m_nodes = new List<ParentNode>();
  154. m_samplerNodes = new UsageListSamplerNodes();
  155. m_samplerNodes.ContainerGraph = this;
  156. m_samplerNodes.ReorderOnChange = true;
  157. m_floatNodes = new UsageListFloatIntNodes();
  158. m_floatNodes.ContainerGraph = this;
  159. m_texturePropertyNodes = new UsageListTexturePropertyNodes();
  160. m_texturePropertyNodes.ContainerGraph = this;
  161. m_textureArrayNodes = new UsageListTextureArrayNodes();
  162. m_textureArrayNodes.ContainerGraph = this;
  163. m_textureArrayNodes.ReorderOnChange = true;
  164. m_propertyNodes = new UsageListPropertyNodes();
  165. m_propertyNodes.ContainerGraph = this;
  166. m_rawPropertyNodes = new UsageListPropertyNodes();
  167. m_rawPropertyNodes.ContainerGraph = this;
  168. m_customExpressionsOnFunctionMode = new UsageListCustomExpressionsOnFunctionMode();
  169. m_customExpressionsOnFunctionMode.ContainerGraph = this;
  170. m_staticSwitchNodes = new UsageListStaticSwitchNodes();
  171. m_staticSwitchNodes.ContainerGraph = this;
  172. m_staticSwitchNodes.ReorderOnChange = true;
  173. m_screenColorNodes = new UsageListScreenColorNodes();
  174. m_screenColorNodes.ContainerGraph = this;
  175. m_screenColorNodes.ReorderOnChange = true;
  176. m_localVarNodes = new UsageListRegisterLocalVarNodes();
  177. m_localVarNodes.ContainerGraph = this;
  178. m_localVarNodes.ReorderOnChange = true;
  179. m_globalArrayNodes = new UsageListGlobalArrayNodes();
  180. m_globalArrayNodes.ContainerGraph = this;
  181. m_functionInputNodes = new UsageListFunctionInputNodes();
  182. m_functionInputNodes.ContainerGraph = this;
  183. m_functionNodes = new UsageListFunctionNodes();
  184. m_functionNodes.ContainerGraph = this;
  185. m_functionOutputNodes = new UsageListFunctionOutputNodes();
  186. m_functionOutputNodes.ContainerGraph = this;
  187. m_functionSwitchNodes = new UsageListFunctionSwitchNodes();
  188. m_functionSwitchNodes.ContainerGraph = this;
  189. m_functionSwitchCopyNodes = new UsageListFunctionSwitchCopyNodes();
  190. m_functionSwitchCopyNodes.ContainerGraph = this;
  191. m_multiPassMasterNodes = new UsageListTemplateMultiPassMasterNodes();
  192. m_multiPassMasterNodes.ContainerGraph = this;
  193. m_lodMultiPassMasterNodes = new List<UsageListTemplateMultiPassMasterNodes>( MaxLodAmount );
  194. for( int i = 0; i < MaxLodAmount; i++ )
  195. {
  196. m_lodMultiPassMasterNodes.Add( new UsageListTemplateMultiPassMasterNodes() );
  197. }
  198. m_selectedNodes = new List<ParentNode>();
  199. m_markedForDeletion = new List<ParentNode>();
  200. m_highlightedWires = new List<WireReference>();
  201. m_validNodeId = 0;
  202. IsDirty = false;
  203. SaveIsDirty = false;
  204. m_masterNodeDefaultType = typeof( StandardSurfaceOutputNode );
  205. m_bezierReferences = new List<WireBezierReference>( MaxBezierReferences );
  206. for( int i = 0; i < MaxBezierReferences; i++ )
  207. {
  208. m_bezierReferences.Add( new WireBezierReference() );
  209. }
  210. }
  211. public void ActivatePreviews( bool value )
  212. {
  213. int count = m_nodes.Count;
  214. if( value )
  215. {
  216. for( int i = 0 ; i < count ; i++ )
  217. {
  218. m_nodes[ i ].PreviewIsDirty = true;
  219. }
  220. }
  221. else
  222. {
  223. //for( int i = 0 ; i < count ; i++ )
  224. //{
  225. // m_nodes[ i ].DisablePreview();
  226. //}
  227. }
  228. }
  229. private void OnUndoRedoCallback()
  230. {
  231. DeSelectAll();
  232. }
  233. private void OnEnable()
  234. {
  235. hideFlags = HideFlags.HideAndDontSave;
  236. m_nodeGrid = new NodeGrid();
  237. m_internalTemplateNodesDict = new Dictionary<int, PropertyNode>();
  238. m_nodesDict = new Dictionary<int, ParentNode>();
  239. nodeStyleOff = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOff );
  240. nodeStyleOn = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn );
  241. nodeTitle = UIUtils.GetCustomStyle( CustomStyle.NodeHeader );
  242. commentaryBackground = UIUtils.GetCustomStyle( CustomStyle.CommentaryBackground );
  243. }
  244. public void UpdateRegisters()
  245. {
  246. m_samplerNodes.UpdateNodeArr();
  247. m_propertyNodes.UpdateNodeArr();
  248. m_rawPropertyNodes.UpdateNodeArr();
  249. m_customExpressionsOnFunctionMode.UpdateNodeArr();
  250. m_staticSwitchNodes.UpdateNodeArr();
  251. m_functionInputNodes.UpdateNodeArr();
  252. m_functionNodes.UpdateNodeArr();
  253. m_functionOutputNodes.UpdateNodeArr();
  254. m_functionSwitchNodes.UpdateNodeArr();
  255. m_functionSwitchCopyNodes.UpdateNodeArr();
  256. m_multiPassMasterNodes.UpdateNodeArr();
  257. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  258. {
  259. m_lodMultiPassMasterNodes[ i ].UpdateNodeArr();
  260. }
  261. m_texturePropertyNodes.UpdateNodeArr();
  262. m_textureArrayNodes.UpdateNodeArr();
  263. m_screenColorNodes.UpdateNodeArr();
  264. m_localVarNodes.UpdateNodeArr();
  265. m_globalArrayNodes.UpdateNodeArr();
  266. }
  267. public int GetValidId()
  268. {
  269. return m_validNodeId++;
  270. }
  271. void UpdateIdFromNode( ParentNode node )
  272. {
  273. if( node.UniqueId >= m_validNodeId )
  274. {
  275. m_validNodeId = node.UniqueId + 1;
  276. }
  277. }
  278. public void ResetNodeConnStatus()
  279. {
  280. for( int i = 0; i < m_nodes.Count; i++ )
  281. {
  282. if( m_nodes[ i ].ConnStatus == NodeConnectionStatus.Connected )
  283. {
  284. m_nodes[ i ].ConnStatus = NodeConnectionStatus.Not_Connected;
  285. }
  286. }
  287. }
  288. public void CleanUnusedNodes()
  289. {
  290. List<ParentNode> unusedNodes = new List<ParentNode>();
  291. for( int i = 0; i < m_nodes.Count; i++ )
  292. {
  293. if( m_nodes[ i ].ConnStatus == NodeConnectionStatus.Not_Connected )
  294. {
  295. unusedNodes.Add( m_nodes[ i ] );
  296. }
  297. }
  298. for( int i = 0; i < unusedNodes.Count; i++ )
  299. {
  300. DestroyNode( unusedNodes[ i ] );
  301. }
  302. unusedNodes.Clear();
  303. unusedNodes = null;
  304. IsDirty = true;
  305. }
  306. // Destroy all nodes excluding Master Node
  307. public void ClearGraph()
  308. {
  309. List<ParentNode> list = new List<ParentNode>();
  310. int count = m_nodes.Count;
  311. for( int i = 0; i < count; i++ )
  312. {
  313. if( m_nodes[ i ].UniqueId != m_masterNodeId )
  314. {
  315. list.Add( m_nodes[ i ] );
  316. }
  317. }
  318. while( list.Count > 0 )
  319. {
  320. DestroyNode( list[ 0 ] );
  321. list.RemoveAt( 0 );
  322. }
  323. }
  324. public void CleanNodes()
  325. {
  326. for( int i = 0; i < m_nodes.Count; i++ )
  327. {
  328. if( m_nodes[ i ] != null )
  329. {
  330. UndoUtils.ClearUndo( m_nodes[ i ] );
  331. m_nodes[ i ].Destroy();
  332. GameObject.DestroyImmediate( m_nodes[ i ] );
  333. }
  334. }
  335. ClearInternalTemplateNodes();
  336. m_masterNodeId = Constants.INVALID_NODE_ID;
  337. m_validNodeId = 0;
  338. m_instancePropertyCount = 0;
  339. m_virtualTextureCount = 0;
  340. m_nodesDict.Clear();
  341. m_nodes.Clear();
  342. m_samplerNodes.Clear();
  343. m_propertyNodes.Clear();
  344. m_rawPropertyNodes.Clear();
  345. m_customExpressionsOnFunctionMode.Clear();
  346. m_staticSwitchNodes.Clear();
  347. m_functionInputNodes.Clear();
  348. m_functionNodes.Clear();
  349. m_functionOutputNodes.Clear();
  350. m_functionSwitchNodes.Clear();
  351. m_functionSwitchCopyNodes.Clear();
  352. m_multiPassMasterNodes.Clear();
  353. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  354. {
  355. m_lodMultiPassMasterNodes[ i ].Clear();
  356. }
  357. m_texturePropertyNodes.Clear();
  358. m_textureArrayNodes.Clear();
  359. m_screenColorNodes.Clear();
  360. m_localVarNodes.Clear();
  361. m_globalArrayNodes.Clear();
  362. m_selectedNodes.Clear();
  363. m_markedForDeletion.Clear();
  364. }
  365. public void ResetHighlightedWires()
  366. {
  367. for( int i = 0; i < m_highlightedWires.Count; i++ )
  368. {
  369. m_highlightedWires[ i ].WireStatus = WireStatus.Default;
  370. }
  371. m_highlightedWires.Clear();
  372. }
  373. public void HighlightWiresStartingNode( ParentNode node )
  374. {
  375. for( int outputIdx = 0; outputIdx < node.OutputPorts.Count; outputIdx++ )
  376. {
  377. for( int extIdx = 0; extIdx < node.OutputPorts[ outputIdx ].ExternalReferences.Count; extIdx++ )
  378. {
  379. WireReference wireRef = node.OutputPorts[ outputIdx ].ExternalReferences[ extIdx ];
  380. ParentNode nextNode = GetNode( wireRef.NodeId );
  381. if( nextNode && nextNode.ConnStatus == NodeConnectionStatus.Connected )
  382. {
  383. InputPort port = nextNode.GetInputPortByUniqueId( wireRef.PortId );
  384. if( port.ExternalReferences.Count == 0 || port.ExternalReferences[ 0 ].WireStatus == WireStatus.Highlighted )
  385. {
  386. // if even one wire is already highlighted then this tells us that this node was already been analysed
  387. return;
  388. }
  389. port.ExternalReferences[ 0 ].WireStatus = WireStatus.Highlighted;
  390. m_highlightedWires.Add( port.ExternalReferences[ 0 ] );
  391. HighlightWiresStartingNode( nextNode );
  392. }
  393. }
  394. }
  395. RegisterLocalVarNode regNode = node as RegisterLocalVarNode;
  396. if( (object)regNode != null )
  397. {
  398. int count = regNode.NodeReferences.Count;
  399. for( int i = 0; i < count; i++ )
  400. {
  401. HighlightWiresStartingNode( regNode.NodeReferences[ i ] );
  402. }
  403. }
  404. }
  405. void PropagateHighlightDeselection( ParentNode node, int portId = -1 )
  406. {
  407. if( portId > -1 )
  408. {
  409. InputPort port = node.GetInputPortByUniqueId( portId );
  410. port.ExternalReferences[ 0 ].WireStatus = WireStatus.Default;
  411. }
  412. if( node.Selected )
  413. return;
  414. for( int i = 0; i < node.InputPorts.Count; i++ )
  415. {
  416. if( node.InputPorts[ i ].ExternalReferences.Count > 0 && node.InputPorts[ i ].ExternalReferences[ 0 ].WireStatus == WireStatus.Highlighted )
  417. {
  418. // even though node is deselected, it receives wire highlight from a previous one
  419. return;
  420. }
  421. }
  422. for( int outputIdx = 0; outputIdx < node.OutputPorts.Count; outputIdx++ )
  423. {
  424. for( int extIdx = 0; extIdx < node.OutputPorts[ outputIdx ].ExternalReferences.Count; extIdx++ )
  425. {
  426. WireReference wireRef = node.OutputPorts[ outputIdx ].ExternalReferences[ extIdx ];
  427. ParentNode nextNode = GetNode( wireRef.NodeId );
  428. PropagateHighlightDeselection( nextNode, wireRef.PortId );
  429. }
  430. }
  431. RegisterLocalVarNode regNode = node as RegisterLocalVarNode;
  432. if( (object)regNode != null )
  433. {
  434. int count = regNode.NodeReferences.Count;
  435. for( int i = 0; i < count; i++ )
  436. {
  437. PropagateHighlightDeselection( regNode.NodeReferences[ i ], -1 );
  438. }
  439. }
  440. }
  441. public void ResetNodesData()
  442. {
  443. int count = m_nodes.Count;
  444. for( int i = 0; i < count; i++ )
  445. {
  446. m_nodes[ i ].ResetNodeData();
  447. }
  448. }
  449. public void FullCleanUndoStack()
  450. {
  451. UndoUtils.ClearUndo( this );
  452. int count = m_nodes.Count;
  453. for( int i = 0; i < count; i++ )
  454. {
  455. if( m_nodes[ i ] != null )
  456. {
  457. UndoUtils.ClearUndo( m_nodes[ i ] );
  458. }
  459. }
  460. }
  461. public void FullRegisterOnUndoStack()
  462. {
  463. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoRegisterFullGrapId );
  464. int count = m_nodes.Count;
  465. for( int i = 0; i < count; i++ )
  466. {
  467. if( m_nodes[ i ] != null )
  468. {
  469. UndoUtils.RegisterCompleteObjectUndo( m_nodes[ i ], Constants.UndoRegisterFullGrapId );
  470. }
  471. }
  472. }
  473. public void CheckPropertiesAutoRegister( ref MasterNodeDataCollector dataCollector )
  474. {
  475. List<PropertyNode> propertyNodesList = m_rawPropertyNodes.NodesList;
  476. int propertyCount = propertyNodesList.Count;
  477. for( int i = 0; i < propertyCount; i++ )
  478. {
  479. propertyNodesList[ i ].CheckIfAutoRegister( ref dataCollector );
  480. }
  481. propertyNodesList = null;
  482. List<GlobalArrayNode> globalArrayNodeList = m_globalArrayNodes.NodesList;
  483. int globalArrayCount = globalArrayNodeList.Count;
  484. for( int i = 0; i < globalArrayCount; i++ )
  485. {
  486. globalArrayNodeList[ i ].CheckIfAutoRegister( ref dataCollector );
  487. }
  488. globalArrayNodeList = null;
  489. //List<PropertyNode> propertyNodesList = m_propertyNodes.NodesList;
  490. //int propertyCount = propertyNodesList.Count;
  491. //for( int i = 0; i < propertyCount; i++ )
  492. //{
  493. // propertyNodesList[ i ].CheckIfAutoRegister( ref dataCollector );
  494. //}
  495. //propertyNodesList = null;
  496. //List<ScreenColorNode> screenColorNodes = m_screenColorNodes.NodesList;
  497. //int screenColorNodesCount = screenColorNodes.Count;
  498. //for( int i = 0; i < screenColorNodesCount; i++ )
  499. //{
  500. // screenColorNodes[ i ].CheckIfAutoRegister( ref dataCollector );
  501. //}
  502. //screenColorNodes = null;
  503. }
  504. public void SoftDestroy()
  505. {
  506. OnNodeRemovedEvent = null;
  507. m_masterNodeId = Constants.INVALID_NODE_ID;
  508. m_validNodeId = 0;
  509. m_nodeGrid.Destroy();
  510. //m_nodeGrid = null;
  511. ClearInternalTemplateNodes();
  512. for( int i = 0; i < m_nodes.Count; i++ )
  513. {
  514. if( m_nodes[ i ] != null )
  515. {
  516. m_nodes[ i ].Destroy();
  517. GameObject.DestroyImmediate( m_nodes[ i ] );
  518. }
  519. }
  520. m_instancePropertyCount = 0;
  521. m_nodes.Clear();
  522. //m_nodes = null;
  523. m_nodesDict.Clear();
  524. //m_nodesDict = null;
  525. m_samplerNodes.Clear();
  526. //m_samplerNodes = null;
  527. m_propertyNodes.Clear();
  528. m_rawPropertyNodes.Clear();
  529. //m_propertyNodes = null;
  530. m_customExpressionsOnFunctionMode.Clear();
  531. m_staticSwitchNodes.Clear();
  532. m_functionInputNodes.Clear();
  533. //m_functionInputNodes = null;
  534. m_functionNodes.Clear();
  535. //m_functionNodes = null;
  536. m_functionOutputNodes.Clear();
  537. //m_functionOutputNodes = null;
  538. m_functionSwitchNodes.Clear();
  539. //m_functionSwitchNodes = null;
  540. m_functionSwitchCopyNodes.Clear();
  541. //m_functionSwitchCopyNodes = null;
  542. m_texturePropertyNodes.Clear();
  543. //m_texturePropertyNodes = null;
  544. m_textureArrayNodes.Clear();
  545. //m_textureArrayNodes = null;
  546. m_screenColorNodes.Clear();
  547. //m_screenColorNodes = null;
  548. m_localVarNodes.Clear();
  549. //m_localVarNodes = null;
  550. m_globalArrayNodes.Clear();
  551. m_selectedNodes.Clear();
  552. //m_selectedNodes = null;
  553. m_markedForDeletion.Clear();
  554. //m_markedForDeletion = null;
  555. m_nodePreviewList.Clear();
  556. //m_nodePreviewList = null;
  557. IsDirty = true;
  558. OnNodeEvent = null;
  559. OnDuplicateEvent = null;
  560. //m_currentShaderFunction = null;
  561. OnMaterialUpdatedEvent = null;
  562. OnShaderUpdatedEvent = null;
  563. OnEmptyGraphDetectedEvt = null;
  564. nodeStyleOff = null;
  565. nodeStyleOn = null;
  566. nodeTitle = null;
  567. commentaryBackground = null;
  568. OnLODMasterNodesAddedEvent = null;
  569. }
  570. public void Destroy()
  571. {
  572. UndoUtils.UnregisterUndoRedoCallback( OnUndoRedoCallback );
  573. for( int i = 0; i < m_nodes.Count; i++ )
  574. {
  575. if( m_nodes[ i ] != null )
  576. {
  577. UndoUtils.ClearUndo( m_nodes[ i ] );
  578. m_nodes[ i ].Destroy();
  579. GameObject.DestroyImmediate( m_nodes[ i ] );
  580. }
  581. }
  582. //Must be before m_propertyNodes.Destroy();
  583. ClearInternalTemplateNodes();
  584. m_internalTemplateNodesDict = null;
  585. m_internalTemplateNodesList = null;
  586. OnNodeRemovedEvent = null;
  587. m_masterNodeId = Constants.INVALID_NODE_ID;
  588. m_validNodeId = 0;
  589. m_instancePropertyCount = 0;
  590. m_nodeGrid.Destroy();
  591. m_nodeGrid = null;
  592. m_nodes.Clear();
  593. m_nodes = null;
  594. m_samplerNodes.Destroy();
  595. m_samplerNodes = null;
  596. m_propertyNodes.Destroy();
  597. m_propertyNodes = null;
  598. m_rawPropertyNodes.Destroy();
  599. m_rawPropertyNodes = null;
  600. m_customExpressionsOnFunctionMode.Destroy();
  601. m_customExpressionsOnFunctionMode = null;
  602. m_staticSwitchNodes.Destroy();
  603. m_staticSwitchNodes = null;
  604. m_functionInputNodes.Destroy();
  605. m_functionInputNodes = null;
  606. m_functionNodes.Destroy();
  607. m_functionNodes = null;
  608. m_functionOutputNodes.Destroy();
  609. m_functionOutputNodes = null;
  610. m_functionSwitchNodes.Destroy();
  611. m_functionSwitchNodes = null;
  612. m_functionSwitchCopyNodes.Destroy();
  613. m_functionSwitchCopyNodes = null;
  614. m_multiPassMasterNodes.Destroy();
  615. m_multiPassMasterNodes = null;
  616. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  617. {
  618. m_lodMultiPassMasterNodes[ i ].Destroy();
  619. m_lodMultiPassMasterNodes[ i ] = null;
  620. }
  621. m_lodMultiPassMasterNodes.Clear();
  622. m_lodMultiPassMasterNodes = null;
  623. m_texturePropertyNodes.Destroy();
  624. m_texturePropertyNodes = null;
  625. m_textureArrayNodes.Destroy();
  626. m_textureArrayNodes = null;
  627. m_screenColorNodes.Destroy();
  628. m_screenColorNodes = null;
  629. m_localVarNodes.Destroy();
  630. m_localVarNodes = null;
  631. m_globalArrayNodes.Destroy();
  632. m_globalArrayNodes = null;
  633. m_selectedNodes.Clear();
  634. m_selectedNodes = null;
  635. m_markedForDeletion.Clear();
  636. m_markedForDeletion = null;
  637. m_nodesDict.Clear();
  638. m_nodesDict = null;
  639. m_nodePreviewList.Clear();
  640. m_nodePreviewList = null;
  641. IsDirty = true;
  642. OnNodeEvent = null;
  643. OnDuplicateEvent = null;
  644. //m_currentShaderFunction = null;
  645. OnMaterialUpdatedEvent = null;
  646. OnShaderUpdatedEvent = null;
  647. OnEmptyGraphDetectedEvt = null;
  648. nodeStyleOff = null;
  649. nodeStyleOn = null;
  650. nodeTitle = null;
  651. commentaryBackground = null;
  652. OnLODMasterNodesAddedEvent = null;
  653. }
  654. void OnNodeChangeSizeEvent( ParentNode node )
  655. {
  656. m_nodeGrid.RemoveNodeFromGrid( node, true );
  657. m_nodeGrid.AddNodeToGrid( node );
  658. }
  659. public void OnNodeFinishMoving( ParentNode node, bool testOnlySelected, InteractionMode interactionMode )
  660. {
  661. if( OnNodeEvent != null )
  662. {
  663. OnNodeEvent( node );
  664. SaveIsDirty = true;
  665. }
  666. m_nodeGrid.RemoveNodeFromGrid( node, true );
  667. m_nodeGrid.AddNodeToGrid( node );
  668. //if( testOnlySelected )
  669. //{
  670. // for( int i = m_visibleNodes.Count - 1; i > -1; i-- )
  671. // {
  672. // if( node.UniqueId != m_visibleNodes[ i ].UniqueId )
  673. // {
  674. // switch( interactionMode )
  675. // {
  676. // case InteractionMode.Target:
  677. // {
  678. // node.OnNodeInteraction( m_visibleNodes[ i ] );
  679. // }
  680. // break;
  681. // case InteractionMode.Other:
  682. // {
  683. // m_visibleNodes[ i ].OnNodeInteraction( node );
  684. // }
  685. // break;
  686. // case InteractionMode.Both:
  687. // {
  688. // node.OnNodeInteraction( m_visibleNodes[ i ] );
  689. // m_visibleNodes[ i ].OnNodeInteraction( node );
  690. // }
  691. // break;
  692. // }
  693. // }
  694. // }
  695. //}
  696. //else
  697. {
  698. for( int i = m_nodes.Count - 1; i > -1; i-- )
  699. {
  700. if( node.UniqueId != m_nodes[ i ].UniqueId )
  701. {
  702. switch( interactionMode )
  703. {
  704. case InteractionMode.Target:
  705. {
  706. node.OnNodeInteraction( m_nodes[ i ] );
  707. }
  708. break;
  709. case InteractionMode.Other:
  710. {
  711. m_nodes[ i ].OnNodeInteraction( node );
  712. }
  713. break;
  714. case InteractionMode.Both:
  715. {
  716. node.OnNodeInteraction( m_nodes[ i ] );
  717. m_nodes[ i ].OnNodeInteraction( node );
  718. }
  719. break;
  720. }
  721. }
  722. }
  723. }
  724. }
  725. public void OnNodeReOrderEvent( ParentNode node, int index )
  726. {
  727. if( node.Depth < index )
  728. {
  729. Debug.LogWarning( "Reorder canceled: This is a specific method for when reordering needs to be done and a its original index is higher than the new one" );
  730. }
  731. else
  732. {
  733. m_nodes.Remove( node );
  734. m_nodes.Insert( index, node );
  735. m_markToReOrder = true;
  736. }
  737. }
  738. public void AddNode( ParentNode node, bool updateId = false, bool addLast = true, bool registerUndo = true, bool fetchMaterialValues = true )
  739. {
  740. if( registerUndo )
  741. {
  742. UIUtils.MarkUndoAction();
  743. UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoCreateNodeId );
  744. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoCreateNodeId );
  745. UndoUtils.RegisterCreatedObjectUndo( node, Constants.UndoCreateNodeId );
  746. }
  747. if( OnNodeEvent != null )
  748. {
  749. OnNodeEvent( node );
  750. }
  751. if( updateId )
  752. {
  753. node.UniqueId = GetValidId();
  754. }
  755. else
  756. {
  757. UpdateIdFromNode( node );
  758. }
  759. if( addLast )
  760. {
  761. m_nodes.Add( node );
  762. node.Depth = m_nodes.Count;
  763. }
  764. else
  765. {
  766. m_nodes.Insert( 0, node );
  767. node.Depth = 0;
  768. }
  769. if( m_nodesDict.ContainsKey( node.UniqueId ) )
  770. {
  771. //m_nodesDict[ node.UniqueId ] = node;
  772. m_foundDuplicates = true;
  773. }
  774. else
  775. {
  776. m_nodesDict.Add( node.UniqueId, node );
  777. node.SetMaterialMode( CurrentMaterial, fetchMaterialValues );
  778. }
  779. m_nodeGrid.AddNodeToGrid( node );
  780. node.OnNodeChangeSizeEvent += OnNodeChangeSizeEvent;
  781. node.OnNodeReOrderEvent += OnNodeReOrderEvent;
  782. IsDirty = true;
  783. }
  784. public void CheckForDuplicates()
  785. {
  786. if( m_foundDuplicates )
  787. {
  788. Debug.LogWarning( "Found duplicates:" );
  789. m_foundDuplicates = false;
  790. m_nodesDict.Clear();
  791. int count = m_nodes.Count;
  792. for( int i = 0; i < count; i++ )
  793. {
  794. if( m_nodesDict.ContainsKey( m_nodes[ i ].UniqueId ) )
  795. {
  796. m_nodes[ i ].UniqueId = GetValidId();
  797. m_nodesDict.Add( m_nodes[ i ].UniqueId, m_nodes[ i ] );
  798. Debug.LogWarning( "Assigning new ID to " + m_nodes[ i ].TypeName );
  799. }
  800. else
  801. {
  802. m_nodesDict.Add( m_nodes[ i ].UniqueId, m_nodes[ i ] );
  803. }
  804. }
  805. }
  806. }
  807. public ParentNode GetClickedNode()
  808. {
  809. if( m_nodeClicked < 0 )
  810. return null;
  811. return GetNode( m_nodeClicked );
  812. }
  813. public PropertyNode GetInternalTemplateNode( int nodeId )
  814. {
  815. if( m_internalTemplateNodesDict.Count != m_internalTemplateNodesList.Count )
  816. {
  817. m_internalTemplateNodesDict.Clear();
  818. int count = m_internalTemplateNodesList.Count;
  819. for( int i = 0; i < m_internalTemplateNodesList.Count; i++ )
  820. {
  821. if( m_internalTemplateNodesList[ i ] != null )
  822. m_internalTemplateNodesDict.Add( m_internalTemplateNodesList[ i ].UniqueId, m_internalTemplateNodesList[ i ] );
  823. }
  824. }
  825. if( m_internalTemplateNodesDict.ContainsKey( nodeId ) )
  826. return m_internalTemplateNodesDict[ nodeId ];
  827. return null;
  828. }
  829. public PropertyNode GetInternalTemplateNode( string propertyName )
  830. {
  831. return m_internalTemplateNodesList.Find( ( x ) => x.PropertyName.Equals( propertyName ) );
  832. }
  833. public void AddInternalTemplateNode( TemplateShaderPropertyData data )
  834. {
  835. PropertyNode propertyNode = null;
  836. switch( data.PropertyDataType )
  837. {
  838. case WirePortDataType.FLOAT:
  839. propertyNode = CreateInstance<RangedFloatNode>(); break;
  840. case WirePortDataType.FLOAT4:
  841. propertyNode = CreateInstance<Vector4Node>();
  842. break;
  843. case WirePortDataType.COLOR:
  844. propertyNode = CreateInstance<ColorNode>();
  845. break;
  846. case WirePortDataType.INT:
  847. propertyNode = CreateInstance<IntNode>(); break;
  848. case WirePortDataType.SAMPLER1D:
  849. case WirePortDataType.SAMPLER2D:
  850. case WirePortDataType.SAMPLER3D:
  851. case WirePortDataType.SAMPLERCUBE:
  852. case WirePortDataType.SAMPLER2DARRAY:
  853. propertyNode = CreateInstance<SamplerNode>();
  854. break;
  855. default: return;
  856. }
  857. propertyNode.PropertyNameFromTemplate( data );
  858. // Create a negative unique Id to separate it from
  859. // the regular ids on the main nodes list
  860. // Its begins at -2 since -1 is used to detect invalid values
  861. int uniqueId = -( m_internalTemplateNodesList.Count + 2 );
  862. propertyNode.SetBaseUniqueId( uniqueId );
  863. //Register into Float/Int Nodes list to be available inline
  864. // Unique Id must be already set at this point to properly
  865. // create array
  866. if( data.PropertyDataType == WirePortDataType.FLOAT ||
  867. data.PropertyDataType == WirePortDataType.INT )
  868. m_floatNodes.AddNode( propertyNode );
  869. m_internalTemplateNodesList.Add( propertyNode );
  870. m_internalTemplateNodesDict.Add( uniqueId, propertyNode );
  871. }
  872. public void ClearInternalTemplateNodes()
  873. {
  874. if( m_internalTemplateNodesList != null )
  875. {
  876. int count = m_internalTemplateNodesList.Count;
  877. for( int i = 0; i < count; i++ )
  878. {
  879. m_internalTemplateNodesList[ i ].Destroy();
  880. GameObject.DestroyImmediate( m_internalTemplateNodesList[ i ] );
  881. }
  882. m_internalTemplateNodesList.Clear();
  883. m_internalTemplateNodesDict.Clear();
  884. }
  885. }
  886. public ParentNode GetNode( int nodeId )
  887. {
  888. if( m_nodesDict.Count != m_nodes.Count )
  889. {
  890. m_nodesDict.Clear();
  891. int count = m_nodes.Count;
  892. for( int i = 0; i < count; i++ )
  893. {
  894. if( m_nodes[ i ] != null && !m_nodesDict.ContainsKey( m_nodes[ i ].UniqueId ) )
  895. m_nodesDict.Add( m_nodes[ i ].UniqueId, m_nodes[ i ] );
  896. }
  897. }
  898. if( m_nodesDict.ContainsKey( nodeId ) )
  899. return m_nodesDict[ nodeId ];
  900. return null;
  901. }
  902. public void ForceReOrder()
  903. {
  904. // @diogo: replaced Sort() with OrderBy() for stable sorting
  905. m_nodes = m_nodes.OrderBy( s => s.Depth ).ToList();
  906. }
  907. public bool Draw( DrawInfo drawInfo )
  908. {
  909. MasterNode masterNode = GetNode( m_masterNodeId ) as MasterNode;
  910. if( m_forceCategoryRefresh && masterNode != null )
  911. {
  912. masterNode.RefreshAvailableCategories();
  913. m_forceCategoryRefresh = false;
  914. }
  915. SaveIsDirty = false;
  916. if( m_afterDeserializeFlag )
  917. {
  918. // this is now done after logic update... templates needs it this way
  919. //m_afterDeserializeFlag = false;
  920. CleanCorruptedNodes();
  921. if( m_nodes.Count == 0 )
  922. {
  923. //TODO: remove this temp from here
  924. NodeAvailability cachedCanvas = CurrentCanvasMode;
  925. ParentWindow.CreateNewGraph( "Empty" );
  926. CurrentCanvasMode = cachedCanvas;
  927. if( OnEmptyGraphDetectedEvt != null )
  928. {
  929. OnEmptyGraphDetectedEvt( this );
  930. SaveIsDirty = false;
  931. }
  932. else
  933. {
  934. SaveIsDirty = true;
  935. }
  936. }
  937. //for( int i = 0; i < m_nodes.Count; i++ )
  938. //{
  939. // m_nodes[ i ].SetContainerGraph( this );
  940. //}
  941. }
  942. if( drawInfo.CurrentEventType == EventType.Repaint )
  943. {
  944. if( m_markedToDeSelect )
  945. DeSelectAll();
  946. if( m_markToSelect > -1 )
  947. {
  948. AddToSelectedNodes( GetNode( m_markToSelect ) );
  949. m_markToSelect = -1;
  950. }
  951. if( m_markToReOrder )
  952. {
  953. m_markToReOrder = false;
  954. int nodesCount = m_nodes.Count;
  955. for( int i = 0; i < nodesCount; i++ )
  956. {
  957. m_nodes[ i ].Depth = i;
  958. }
  959. }
  960. }
  961. if( drawInfo.CurrentEventType == EventType.Repaint )
  962. {
  963. // Resizing Nods per LOD level
  964. NodeLOD newLevel = NodeLOD.LOD0;
  965. float referenceValue;
  966. if( drawInfo.InvertedZoom > 0.5f )
  967. {
  968. newLevel = NodeLOD.LOD0;
  969. referenceValue = 4;
  970. }
  971. else if( drawInfo.InvertedZoom > 0.25f )
  972. {
  973. newLevel = NodeLOD.LOD1;
  974. referenceValue = 2;
  975. }
  976. else if( drawInfo.InvertedZoom > 0.15f )
  977. {
  978. newLevel = NodeLOD.LOD2;
  979. referenceValue = 1;
  980. }
  981. else if( drawInfo.InvertedZoom > 0.1f )
  982. {
  983. newLevel = NodeLOD.LOD3;
  984. referenceValue = 0;
  985. }
  986. else if( drawInfo.InvertedZoom > 0.07f )
  987. {
  988. newLevel = NodeLOD.LOD4;
  989. referenceValue = 0;
  990. }
  991. else
  992. {
  993. newLevel = NodeLOD.LOD5;
  994. referenceValue = 0;
  995. }
  996. // Just a sanity check
  997. nodeStyleOff = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOff );
  998. nodeStyleOn = UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn );//= UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn );
  999. nodeTitle = UIUtils.GetCustomStyle( CustomStyle.NodeHeader );
  1000. commentaryBackground = UIUtils.GetCustomStyle( CustomStyle.CommentaryBackground );
  1001. if( newLevel != m_lodLevel || ( UIUtils.MainSkin != null && UIUtils.MainSkin.textField.border.left != referenceValue ) )
  1002. {
  1003. m_lodLevel = newLevel;
  1004. switch( m_lodLevel )
  1005. {
  1006. default:
  1007. case NodeLOD.LOD0:
  1008. {
  1009. UIUtils.MainSkin.textField.border = UIUtils.RectOffsetFour;
  1010. nodeStyleOff.border = UIUtils.RectOffsetSix;
  1011. UIUtils.NodeWindowOffSquare.border = UIUtils.RectOffsetFour;
  1012. nodeStyleOn.border = UIUtils.RectOffsetSix;
  1013. UIUtils.NodeWindowOnSquare.border = UIUtils.RectOffsetSix;
  1014. nodeTitle.border.left = 6;
  1015. nodeTitle.border.right = 6;
  1016. nodeTitle.border.top = 6;
  1017. nodeTitle.border.bottom = 4;
  1018. UIUtils.NodeHeaderSquare.border = UIUtils.RectOffsetFour;
  1019. commentaryBackground.border = UIUtils.RectOffsetSix;
  1020. }
  1021. break;
  1022. case NodeLOD.LOD1:
  1023. {
  1024. UIUtils.MainSkin.textField.border = UIUtils.RectOffsetTwo;
  1025. nodeStyleOff.border = UIUtils.RectOffsetFive;
  1026. UIUtils.NodeWindowOffSquare.border = UIUtils.RectOffsetFive;
  1027. nodeStyleOn.border = UIUtils.RectOffsetFive;
  1028. UIUtils.NodeWindowOnSquare.border = UIUtils.RectOffsetFour;
  1029. nodeTitle.border.left = 5;
  1030. nodeTitle.border.right = 5;
  1031. nodeTitle.border.top = 5;
  1032. nodeTitle.border.bottom = 2;
  1033. UIUtils.NodeHeaderSquare.border = UIUtils.RectOffsetThree;
  1034. commentaryBackground.border = UIUtils.RectOffsetFive;
  1035. }
  1036. break;
  1037. case NodeLOD.LOD2:
  1038. {
  1039. UIUtils.MainSkin.textField.border = UIUtils.RectOffsetOne;
  1040. nodeStyleOff.border.left = 2;
  1041. nodeStyleOff.border.right = 2;
  1042. nodeStyleOff.border.top = 2;
  1043. nodeStyleOff.border.bottom = 3;
  1044. UIUtils.NodeWindowOffSquare.border = UIUtils.RectOffsetThree;
  1045. nodeStyleOn.border.left = 4;
  1046. nodeStyleOn.border.right = 4;
  1047. nodeStyleOn.border.top = 4;
  1048. nodeStyleOn.border.bottom = 3;
  1049. UIUtils.NodeWindowOnSquare.border = UIUtils.RectOffsetThree;
  1050. nodeTitle.border = UIUtils.RectOffsetTwo;
  1051. UIUtils.NodeHeaderSquare.border = UIUtils.RectOffsetTwo;
  1052. commentaryBackground.border.left = 2;
  1053. commentaryBackground.border.right = 2;
  1054. commentaryBackground.border.top = 2;
  1055. commentaryBackground.border.bottom = 3;
  1056. }
  1057. break;
  1058. case NodeLOD.LOD3:
  1059. case NodeLOD.LOD4:
  1060. case NodeLOD.LOD5:
  1061. {
  1062. UIUtils.MainSkin.textField.border = UIUtils.RectOffsetZero;
  1063. nodeStyleOff.border.left = 1;
  1064. nodeStyleOff.border.right = 1;
  1065. nodeStyleOff.border.top = 1;
  1066. nodeStyleOff.border.bottom = 2;
  1067. UIUtils.NodeWindowOffSquare.border = UIUtils.RectOffsetTwo;
  1068. nodeStyleOn.border = UIUtils.RectOffsetTwo;
  1069. UIUtils.NodeWindowOnSquare.border = UIUtils.RectOffsetTwo;
  1070. nodeTitle.border = UIUtils.RectOffsetOne;
  1071. UIUtils.NodeHeaderSquare.border = UIUtils.RectOffsetOne;
  1072. commentaryBackground.border.left = 1;
  1073. commentaryBackground.border.right = 1;
  1074. commentaryBackground.border.top = 1;
  1075. commentaryBackground.border.bottom = 2;
  1076. }
  1077. break;
  1078. }
  1079. }
  1080. }
  1081. //m_visibleNodes.Clear();
  1082. //int nullCount = 0;
  1083. m_hasUnConnectedNodes = false;
  1084. bool repaint = false;
  1085. Material currentMaterial = masterNode != null ? masterNode.CurrentMaterial : null;
  1086. EditorGUI.BeginChangeCheck();
  1087. bool repaintMaterialInspector = false;
  1088. int nodeCount = m_nodes.Count;
  1089. for( int i = 0; i < nodeCount; i++ )
  1090. {
  1091. m_nodes[ i ].OnNodeLogicUpdate( drawInfo );
  1092. }
  1093. if( m_afterDeserializeFlag || m_lateOptionsRefresh )
  1094. {
  1095. m_afterDeserializeFlag = false;
  1096. m_lateOptionsRefresh = false;
  1097. if( CurrentCanvasMode == NodeAvailability.TemplateShader )
  1098. {
  1099. RefreshLinkedMasterNodes( true );
  1100. OnRefreshLinkedPortsComplete();
  1101. //If clipboard has cached nodes then a master node replacement will take place
  1102. //We need to re-cache master nodes to ensure applied options are correctly cached
  1103. //As first cache happens before that
  1104. if( m_parentWindow.ClipboardInstance.HasCachedMasterNodes )
  1105. {
  1106. m_parentWindow.ClipboardInstance.AddMultiPassNodesToClipboard( MultiPassMasterNodes.NodesList,true,-1 );
  1107. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  1108. {
  1109. if( m_lodMultiPassMasterNodes[ i ].Count > 0 )
  1110. m_parentWindow.ClipboardInstance.AddMultiPassNodesToClipboard( m_lodMultiPassMasterNodes[ i ].NodesList, false, i );
  1111. }
  1112. }
  1113. //RepositionTemplateNodes( CurrentMasterNode );
  1114. }
  1115. }
  1116. if( m_forceRepositionCheck )
  1117. {
  1118. RepositionTemplateNodes( CurrentMasterNode );
  1119. }
  1120. //for( int i = 0; i < m_functionNodes.NodesList.Count; i++ )
  1121. //{
  1122. // m_functionNodes.NodesList[ i ].LogicGraph();
  1123. //}
  1124. //for( int i = 0; i < UIUtils.FunctionSwitchCopyList().Count; i++ )
  1125. //{
  1126. // UIUtils.FunctionSwitchCopyList()[ i ].CheckReference();
  1127. //}
  1128. // Dont use nodeCount variable because node count can change in this loop???
  1129. nodeCount = m_nodes.Count;
  1130. ParentNode node = null;
  1131. for( int i = 0; i < nodeCount; i++ )
  1132. {
  1133. node = m_nodes[ i ];
  1134. if( !node.IsOnGrid )
  1135. {
  1136. m_nodeGrid.AddNodeToGrid( node );
  1137. }
  1138. node.MovingInFrame = false;
  1139. if( drawInfo.CurrentEventType == EventType.Repaint )
  1140. node.OnNodeLayout( drawInfo );
  1141. m_hasUnConnectedNodes = m_hasUnConnectedNodes ||
  1142. ( node.ConnStatus != NodeConnectionStatus.Connected && node.ConnStatus != NodeConnectionStatus.Island );
  1143. if( node.RequireMaterialUpdate && currentMaterial != null )
  1144. {
  1145. node.UpdateMaterial( currentMaterial );
  1146. repaintMaterialInspector = true;
  1147. }
  1148. //if( node.IsVisible )
  1149. // m_visibleNodes.Add( node );
  1150. IsDirty = ( m_isDirty || node.IsDirty );
  1151. SaveIsDirty = ( m_saveIsDirty || node.SaveIsDirty );
  1152. }
  1153. // Handles GUI controls
  1154. nodeCount = m_nodes.Count;
  1155. for( int i = nodeCount - 1; i >= 0; i-- )
  1156. //for ( int i = 0; i < nodeCount; i++ )
  1157. {
  1158. node = m_nodes[ i ];
  1159. bool restoreMouse = false;
  1160. if( drawInfo.CurrentEventType == EventType.MouseDown && m_nodeClicked > -1 && node.UniqueId != m_nodeClicked )
  1161. {
  1162. restoreMouse = true;
  1163. drawInfo.CurrentEventType = EventType.Ignore;
  1164. }
  1165. node.DrawGUIControls( drawInfo );
  1166. if( restoreMouse )
  1167. {
  1168. drawInfo.CurrentEventType = EventType.MouseDown;
  1169. }
  1170. }
  1171. // Draw connection wires
  1172. if( drawInfo.CurrentEventType == EventType.Repaint )
  1173. DrawWires( ParentWindow.WireTexture, drawInfo, ParentWindow.WindowContextPallete.IsActive, ParentWindow.WindowContextPallete.CurrentPosition );
  1174. // Master Draw
  1175. nodeCount = m_nodes.Count;
  1176. for( int i = 0; i < nodeCount; i++ )
  1177. {
  1178. node = m_nodes[ i ];
  1179. bool restoreMouse = false;
  1180. if( drawInfo.CurrentEventType == EventType.MouseDown && m_nodeClicked > -1 && node.UniqueId != m_nodeClicked )
  1181. {
  1182. restoreMouse = true;
  1183. drawInfo.CurrentEventType = EventType.Ignore;
  1184. }
  1185. node.Draw( drawInfo );
  1186. if( restoreMouse )
  1187. {
  1188. drawInfo.CurrentEventType = EventType.MouseDown;
  1189. }
  1190. }
  1191. // Draw Tooltip
  1192. if( drawInfo.CurrentEventType == EventType.Repaint || drawInfo.CurrentEventType == EventType.MouseDown )
  1193. {
  1194. nodeCount = m_nodes.Count;
  1195. for( int i = nodeCount - 1; i >= 0; i-- )
  1196. {
  1197. node = m_nodes[ i ];
  1198. if( node.IsVisible && !node.IsMoving )
  1199. {
  1200. bool showing = node.ShowTooltip( drawInfo );
  1201. if( showing )
  1202. break;
  1203. }
  1204. }
  1205. }
  1206. if( repaintMaterialInspector )
  1207. {
  1208. if( MaterialInspector.Instance != null )
  1209. {
  1210. MaterialInspector.Instance.Repaint();
  1211. }
  1212. }
  1213. if( m_checkSelectedWireHighlights )
  1214. {
  1215. m_checkSelectedWireHighlights = false;
  1216. ResetHighlightedWires();
  1217. for( int i = 0; i < m_selectedNodes.Count; i++ )
  1218. {
  1219. HighlightWiresStartingNode( m_selectedNodes[ i ] );
  1220. }
  1221. }
  1222. if( EditorGUI.EndChangeCheck() )
  1223. {
  1224. SaveIsDirty = true;
  1225. repaint = true;
  1226. }
  1227. if( drawInfo.CurrentEventType == EventType.Repaint )
  1228. {
  1229. // Revert LOD changes to LOD0 (only if it's different)
  1230. if( UIUtils.MainSkin.textField.border.left != 4 )
  1231. {
  1232. UIUtils.MainSkin.textField.border = UIUtils.RectOffsetFour;
  1233. nodeStyleOff.border = UIUtils.RectOffsetSix;
  1234. UIUtils.NodeWindowOffSquare.border = UIUtils.RectOffsetFour;
  1235. nodeStyleOn.border = UIUtils.RectOffsetSix;
  1236. UIUtils.NodeWindowOnSquare.border = UIUtils.RectOffsetSix;
  1237. nodeTitle.border.left = 6;
  1238. nodeTitle.border.right = 6;
  1239. nodeTitle.border.top = 6;
  1240. nodeTitle.border.bottom = 4;
  1241. UIUtils.NodeHeaderSquare.border = UIUtils.RectOffsetFour;
  1242. commentaryBackground.border = UIUtils.RectOffsetSix;
  1243. }
  1244. }
  1245. //if ( nullCount == m_nodes.Count )
  1246. // m_nodes.Clear();
  1247. ChangedLightingModel = false;
  1248. return repaint;
  1249. }
  1250. public bool UpdateMarkForDeletion()
  1251. {
  1252. if( m_markedForDeletion.Count != 0 )
  1253. {
  1254. DeleteMarkedForDeletionNodes();
  1255. return true;
  1256. }
  1257. return false;
  1258. }
  1259. public void DrawWires( Texture2D wireTex, DrawInfo drawInfo, bool contextPaletteActive, Vector3 contextPalettePos )
  1260. {
  1261. //Handles.BeginGUI();
  1262. //Debug.Log(GUI.depth);
  1263. // Draw connected node wires
  1264. m_wireBezierCount = 0;
  1265. for( int nodeIdx = 0; nodeIdx < m_nodes.Count; nodeIdx++ )
  1266. {
  1267. ParentNode node = m_nodes[ nodeIdx ];
  1268. if( (object)node == null )
  1269. return;
  1270. for( int inputPortIdx = 0; inputPortIdx < node.InputPorts.Count; inputPortIdx++ )
  1271. {
  1272. InputPort inputPort = node.InputPorts[ inputPortIdx ];
  1273. if( inputPort.ExternalReferences.Count > 0 && inputPort.Visible )
  1274. {
  1275. bool cleanInvalidConnections = false;
  1276. for( int wireIdx = 0; wireIdx < inputPort.ExternalReferences.Count; wireIdx++ )
  1277. {
  1278. WireReference reference = inputPort.ExternalReferences[ wireIdx ];
  1279. if( reference.NodeId != -1 && reference.PortId != -1 )
  1280. {
  1281. ParentNode outputNode = GetNode( reference.NodeId );
  1282. if( outputNode != null )
  1283. {
  1284. OutputPort outputPort = outputNode.GetOutputPortByUniqueId( reference.PortId );
  1285. Vector3 endPos = new Vector3( inputPort.Position.x, inputPort.Position.y );
  1286. Vector3 startPos = new Vector3( outputPort.Position.x, outputPort.Position.y );
  1287. float x = ( startPos.x < endPos.x ) ? startPos.x : endPos.x;
  1288. float y = ( startPos.y < endPos.y ) ? startPos.y : endPos.y;
  1289. float width = Mathf.Abs( startPos.x - endPos.x ) + outputPort.Position.width;
  1290. float height = Mathf.Abs( startPos.y - endPos.y ) + outputPort.Position.height;
  1291. Rect portsBoundingBox = new Rect( x, y, width, height );
  1292. bool isVisible = node.IsVisible || outputNode.IsVisible;
  1293. if( !isVisible )
  1294. {
  1295. isVisible = drawInfo.TransformedCameraArea.Overlaps( portsBoundingBox );
  1296. }
  1297. if( isVisible )
  1298. {
  1299. Rect bezierBB = DrawBezier( drawInfo.InvertedZoom, startPos, endPos, inputPort.DataType, outputPort.DataType, node.GetInputPortVisualDataTypeByArrayIdx( inputPortIdx ), outputNode.GetOutputPortVisualDataTypeById( reference.PortId ), reference.WireStatus, wireTex, node, outputNode );
  1300. bezierBB.x -= Constants.OUTSIDE_WIRE_MARGIN;
  1301. bezierBB.y -= Constants.OUTSIDE_WIRE_MARGIN;
  1302. bezierBB.width += Constants.OUTSIDE_WIRE_MARGIN * 2;
  1303. bezierBB.height += Constants.OUTSIDE_WIRE_MARGIN * 2;
  1304. if( m_wireBezierCount < m_bezierReferences.Count )
  1305. {
  1306. m_bezierReferences[ m_wireBezierCount ].UpdateInfo( ref bezierBB, inputPort.NodeId, inputPort.PortId, outputPort.NodeId, outputPort.PortId );
  1307. }
  1308. else
  1309. {
  1310. m_bezierReferences.Add( new WireBezierReference( ref bezierBB, inputPort.NodeId, inputPort.PortId, outputPort.NodeId, outputPort.PortId ) );
  1311. }
  1312. m_wireBezierCount++;
  1313. }
  1314. }
  1315. else
  1316. {
  1317. if( DebugConsoleWindow.DeveloperMode )
  1318. UIUtils.ShowMessage( "Detected Invalid connection from node " + node.UniqueId + " port " + inputPortIdx + " to Node " + reference.NodeId + " port " + reference.PortId, MessageSeverity.Error );
  1319. cleanInvalidConnections = true;
  1320. inputPort.ExternalReferences[ wireIdx ].Invalidate();
  1321. }
  1322. }
  1323. }
  1324. if( cleanInvalidConnections )
  1325. {
  1326. inputPort.RemoveInvalidConnections();
  1327. }
  1328. }
  1329. }
  1330. }
  1331. //Draw selected wire
  1332. if( m_parentWindow.WireReferenceUtils.ValidReferences() )
  1333. {
  1334. if( m_parentWindow.WireReferenceUtils.InputPortReference.IsValid )
  1335. {
  1336. InputPort inputPort = GetNode( m_parentWindow.WireReferenceUtils.InputPortReference.NodeId ).GetInputPortByUniqueId( m_parentWindow.WireReferenceUtils.InputPortReference.PortId );
  1337. Vector3 endPos = Vector3.zero;
  1338. if( m_parentWindow.WireReferenceUtils.SnapEnabled )
  1339. {
  1340. Vector2 pos = ( m_parentWindow.WireReferenceUtils.SnapPosition + drawInfo.CameraOffset ) * drawInfo.InvertedZoom;
  1341. endPos = new Vector3( pos.x, pos.y ) + UIUtils.ScaledPortsDelta;
  1342. }
  1343. else
  1344. {
  1345. endPos = contextPaletteActive ? contextPalettePos : new Vector3( Event.current.mousePosition.x, Event.current.mousePosition.y );
  1346. }
  1347. Vector3 startPos = new Vector3( inputPort.Position.x, inputPort.Position.y );
  1348. DrawBezier( drawInfo.InvertedZoom, endPos, startPos, inputPort.DataType, inputPort.DataType, inputPort.DataType, inputPort.DataType, WireStatus.Default, wireTex );
  1349. }
  1350. if( m_parentWindow.WireReferenceUtils.OutputPortReference.IsValid )
  1351. {
  1352. OutputPort outputPort = GetNode( m_parentWindow.WireReferenceUtils.OutputPortReference.NodeId ).GetOutputPortByUniqueId( m_parentWindow.WireReferenceUtils.OutputPortReference.PortId );
  1353. Vector3 endPos = Vector3.zero;
  1354. if( m_parentWindow.WireReferenceUtils.SnapEnabled )
  1355. {
  1356. Vector2 pos = ( m_parentWindow.WireReferenceUtils.SnapPosition + drawInfo.CameraOffset ) * drawInfo.InvertedZoom;
  1357. endPos = new Vector3( pos.x, pos.y ) + UIUtils.ScaledPortsDelta;
  1358. }
  1359. else
  1360. {
  1361. endPos = contextPaletteActive ? contextPalettePos : new Vector3( Event.current.mousePosition.x, Event.current.mousePosition.y );
  1362. }
  1363. Vector3 startPos = new Vector3( outputPort.Position.x, outputPort.Position.y );
  1364. DrawBezier( drawInfo.InvertedZoom, startPos, endPos, outputPort.DataType, outputPort.DataType, outputPort.DataType, outputPort.DataType, WireStatus.Default, wireTex );
  1365. }
  1366. }
  1367. //Handles.EndGUI();
  1368. }
  1369. Rect DrawBezier( float invertedZoom, Vector3 startPos, Vector3 endPos, WirePortDataType inputDataType, WirePortDataType outputDataType, WirePortDataType inputVisualDataType, WirePortDataType outputVisualDataType, WireStatus wireStatus, Texture2D wireTex, ParentNode inputNode = null, ParentNode outputNode = null )
  1370. {
  1371. startPos += UIUtils.ScaledPortsDelta;
  1372. endPos += UIUtils.ScaledPortsDelta;
  1373. // Calculate the 4 points for bezier taking into account wire nodes and their automatic tangents
  1374. float mag = ( endPos - startPos ).magnitude;
  1375. float resizedMag = Mathf.Min( mag * 0.66f, Constants.HORIZONTAL_TANGENT_SIZE * invertedZoom );
  1376. Vector3 startTangent = new Vector3( startPos.x + resizedMag, startPos.y );
  1377. Vector3 endTangent = new Vector3( endPos.x - resizedMag, endPos.y );
  1378. if( (object)inputNode != null && inputNode.GetType() == typeof( WireNode ) )
  1379. endTangent = endPos + ( ( inputNode as WireNode ).TangentDirection ) * mag * 0.33f;
  1380. if( (object)outputNode != null && outputNode.GetType() == typeof( WireNode ) )
  1381. startTangent = startPos - ( ( outputNode as WireNode ).TangentDirection ) * mag * 0.33f;
  1382. ///////////////Draw tangents
  1383. //Rect box1 = new Rect( new Vector2( startTangent.x, startTangent.y ), new Vector2( 10, 10 ) );
  1384. //box1.x -= box1.width * 0.5f;
  1385. //box1.y -= box1.height * 0.5f;
  1386. //GUI.Label( box1, string.Empty, UIUtils.Box );
  1387. //Rect box2 = new Rect( new Vector2( endTangent.x, endTangent.y ), new Vector2( 10, 10 ) );
  1388. //box2.x -= box2.width * 0.5f;
  1389. //box2.y -= box2.height * 0.5f;
  1390. //GUI.Label( box2, string.Empty, UIUtils.Box );
  1391. //m_auxRect.Set( 0, 0, UIUtils.CurrentWindow.position.width, UIUtils.CurrentWindow.position.height );
  1392. //GLDraw.BeginGroup( m_auxRect );
  1393. int ty = 1;
  1394. float wireThickness = 0;
  1395. if( ParentWindow.Options.MultiLinePorts )
  1396. {
  1397. GLDraw.MultiLine = true;
  1398. Shader.SetGlobalFloat( "_InvertedZoom", invertedZoom );
  1399. WirePortDataType smallest = ( (int)outputDataType < (int)inputDataType ? outputDataType : inputDataType );
  1400. smallest = ( (int)smallest < (int)outputVisualDataType ? smallest : outputVisualDataType );
  1401. smallest = ( (int)smallest < (int)inputVisualDataType ? smallest : inputVisualDataType );
  1402. switch( smallest )
  1403. {
  1404. case WirePortDataType.FLOAT2: ty = 2; break;
  1405. case WirePortDataType.FLOAT3: ty = 3; break;
  1406. case WirePortDataType.FLOAT4:
  1407. case WirePortDataType.COLOR:
  1408. {
  1409. ty = 4;
  1410. }
  1411. break;
  1412. default: ty = 1; break;
  1413. }
  1414. wireThickness = Mathf.Lerp( Constants.WIRE_WIDTH * ( ty * invertedZoom * -0.05f + 0.15f ), Constants.WIRE_WIDTH * ( ty * invertedZoom * 0.175f + 0.3f ), invertedZoom + 0.4f );
  1415. }
  1416. else
  1417. {
  1418. GLDraw.MultiLine = false;
  1419. wireThickness = Mathf.Lerp( Constants.WIRE_WIDTH * ( invertedZoom * -0.05f + 0.15f ), Constants.WIRE_WIDTH * ( invertedZoom * 0.175f + 0.3f ), invertedZoom + 0.4f );
  1420. }
  1421. Rect boundBox = new Rect();
  1422. int segments = 11;
  1423. if( LodLevel <= ParentGraph.NodeLOD.LOD4 )
  1424. segments = Mathf.Clamp( Mathf.FloorToInt( mag * 0.2f * invertedZoom ), 11, 35 );
  1425. else
  1426. segments = (int)( invertedZoom * 14.28f * 11 );
  1427. if( ParentWindow.Options.ColoredPorts && wireStatus != WireStatus.Highlighted )
  1428. boundBox = GLDraw.DrawBezier( startPos, startTangent, endPos, endTangent, UIUtils.GetColorForDataType( outputVisualDataType, false, false ), UIUtils.GetColorForDataType( inputVisualDataType, false, false ), wireThickness, segments, ty );
  1429. else
  1430. boundBox = GLDraw.DrawBezier( startPos, startTangent, endPos, endTangent, UIUtils.GetColorFromWireStatus( wireStatus ), wireThickness, segments, ty );
  1431. //GLDraw.EndGroup();
  1432. //GUI.Box( m_auxRect, string.Empty, UIUtils.CurrentWindow.CustomStylesInstance.Box );
  1433. //GUI.Box( boundBox, string.Empty, UIUtils.CurrentWindow.CustomStylesInstance.Box );
  1434. //if ( UIUtils.CurrentWindow.Options.ColoredPorts && wireStatus != WireStatus.Highlighted )
  1435. // Handles.DrawBezier( startPos, endPos, startTangent, endTangent, UIUtils.GetColorForDataType( outputDataType, false, false ), wireTex, wiresTickness );
  1436. //else
  1437. // Handles.DrawBezier( startPos, endPos, startTangent, endTangent, UIUtils.GetColorFromWireStatus( wireStatus ), wireTex, wiresTickness );
  1438. //Handles.DrawLine( startPos, startTangent );
  1439. //Handles.DrawLine( endPos, endTangent );
  1440. float extraBound = 30 * invertedZoom;
  1441. boundBox.xMin -= extraBound;
  1442. boundBox.xMax += extraBound;
  1443. boundBox.yMin -= extraBound;
  1444. boundBox.yMax += extraBound;
  1445. return boundBox;
  1446. }
  1447. public void DrawBezierBoundingBox()
  1448. {
  1449. for( int i = 0; i < m_wireBezierCount; i++ )
  1450. {
  1451. m_bezierReferences[ i ].DebugDraw();
  1452. }
  1453. }
  1454. public WireBezierReference GetWireBezierInPos( Vector2 position )
  1455. {
  1456. for( int i = 0; i < m_wireBezierCount; i++ )
  1457. {
  1458. if( m_bezierReferences[ i ].Contains( position ) )
  1459. return m_bezierReferences[ i ];
  1460. }
  1461. return null;
  1462. }
  1463. public List<WireBezierReference> GetWireBezierListInPos( Vector2 position )
  1464. {
  1465. List<WireBezierReference> list = new List<WireBezierReference>();
  1466. for( int i = 0; i < m_wireBezierCount; i++ )
  1467. {
  1468. if( m_bezierReferences[ i ].Contains( position ) )
  1469. list.Add( m_bezierReferences[ i ] );
  1470. }
  1471. return list;
  1472. }
  1473. public void MoveSelectedNodes( Vector2 delta, bool snap = false )
  1474. {
  1475. //bool validMovement = delta.magnitude > 0.001f;
  1476. //if ( validMovement )
  1477. //{
  1478. // UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoMoveNodesId );
  1479. // for ( int i = 0; i < m_selectedNodes.Count; i++ )
  1480. // {
  1481. // if ( !m_selectedNodes[ i ].MovingInFrame )
  1482. // {
  1483. // UndoUtils.RecordObject( m_selectedNodes[ i ], Constants.UndoMoveNodesId );
  1484. // m_selectedNodes[ i ].Move( delta, snap );
  1485. // }
  1486. // }
  1487. // IsDirty = true;
  1488. //}
  1489. bool performUndo = delta.magnitude > 0.01f;
  1490. if( performUndo )
  1491. {
  1492. UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoMoveNodesId );
  1493. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoMoveNodesId );
  1494. }
  1495. for( int i = 0; i < m_selectedNodes.Count; i++ )
  1496. {
  1497. if( !m_selectedNodes[ i ].MovingInFrame )
  1498. {
  1499. if( performUndo )
  1500. m_selectedNodes[ i ].RecordObject( Constants.UndoMoveNodesId );
  1501. m_selectedNodes[ i ].Move( delta, snap );
  1502. }
  1503. }
  1504. IsDirty = true;
  1505. }
  1506. public void SetConnection( int InNodeId, int InPortId, int OutNodeId, int OutPortId )
  1507. {
  1508. ParentNode inNode = GetNode( InNodeId );
  1509. ParentNode outNode = GetNode( OutNodeId );
  1510. InputPort inputPort = null;
  1511. OutputPort outputPort = null;
  1512. if( inNode != null && outNode != null )
  1513. {
  1514. inputPort = inNode.GetInputPortByUniqueId( InPortId );
  1515. outputPort = outNode.GetOutputPortByUniqueId( OutPortId );
  1516. if( inputPort != null && outputPort != null )
  1517. {
  1518. if( inputPort.IsConnectedTo( OutNodeId, OutPortId ) || outputPort.IsConnectedTo( InNodeId, InPortId ) )
  1519. {
  1520. if( DebugConsoleWindow.DeveloperMode )
  1521. UIUtils.ShowMessage( "Node/Port already connected " + InNodeId, MessageSeverity.Error );
  1522. return;
  1523. }
  1524. if( !inputPort.CheckValidType( outputPort.DataType ) )
  1525. {
  1526. if( DebugConsoleWindow.DeveloperMode )
  1527. UIUtils.ShowIncompatiblePortMessage( true, inNode, inputPort, outNode, outputPort );
  1528. return;
  1529. }
  1530. if( !outputPort.CheckValidType( inputPort.DataType ) )
  1531. {
  1532. if( DebugConsoleWindow.DeveloperMode )
  1533. UIUtils.ShowIncompatiblePortMessage( false, outNode, outputPort, inNode, inputPort );
  1534. return;
  1535. }
  1536. if( !inputPort.Available || !outputPort.Available )
  1537. {
  1538. if( DebugConsoleWindow.DeveloperMode )
  1539. UIUtils.ShowMessage( "Ports not available to connection", MessageSeverity.Warning );
  1540. return;
  1541. }
  1542. if( inputPort.ConnectTo( OutNodeId, OutPortId, outputPort.DataType, false ) )
  1543. {
  1544. inNode.OnInputPortConnected( InPortId, OutNodeId, OutPortId );
  1545. }
  1546. if( outputPort.ConnectTo( InNodeId, InPortId, inputPort.DataType, inputPort.TypeLocked ) )
  1547. {
  1548. outNode.OnOutputPortConnected( OutPortId, InNodeId, InPortId );
  1549. }
  1550. }
  1551. else if( (object)inputPort == null )
  1552. {
  1553. if( DebugConsoleWindow.DeveloperMode )
  1554. UIUtils.ShowMessage( "Input Port " + InPortId + " doesn't exist on node " + InNodeId, MessageSeverity.Error );
  1555. }
  1556. else
  1557. {
  1558. if( DebugConsoleWindow.DeveloperMode )
  1559. UIUtils.ShowMessage( "Output Port " + OutPortId + " doesn't exist on node " + OutNodeId, MessageSeverity.Error );
  1560. }
  1561. }
  1562. else if( (object)inNode == null )
  1563. {
  1564. if( DebugConsoleWindow.DeveloperMode )
  1565. UIUtils.ShowMessage( "Input node " + InNodeId + " doesn't exist", MessageSeverity.Error );
  1566. }
  1567. else
  1568. {
  1569. if( DebugConsoleWindow.DeveloperMode )
  1570. UIUtils.ShowMessage( "Output node " + OutNodeId + " doesn't exist", MessageSeverity.Error );
  1571. }
  1572. }
  1573. public void CreateConnection( int inNodeId, int inPortId, int outNodeId, int outPortId, bool registerUndo = true )
  1574. {
  1575. ParentNode outputNode = GetNode( outNodeId );
  1576. if( outputNode != null )
  1577. {
  1578. OutputPort outputPort = outputNode.GetOutputPortByUniqueId( outPortId );
  1579. if( outputPort != null )
  1580. {
  1581. ParentNode inputNode = GetNode( inNodeId );
  1582. InputPort inputPort = inputNode.GetInputPortByUniqueId( inPortId );
  1583. if( !inputPort.CheckValidType( outputPort.DataType ) )
  1584. {
  1585. UIUtils.ShowIncompatiblePortMessage( true, inputNode, inputPort, outputNode, outputPort );
  1586. return;
  1587. }
  1588. if( !outputPort.CheckValidType( inputPort.DataType ) )
  1589. {
  1590. UIUtils.ShowIncompatiblePortMessage( false, outputNode, outputPort, inputNode, inputPort );
  1591. return;
  1592. }
  1593. inputPort.DummyAdd( outputPort.NodeId, outputPort.PortId );
  1594. outputPort.DummyAdd( inNodeId, inPortId );
  1595. if( UIUtils.DetectNodeLoopsFrom( inputNode, new Dictionary<int, int>() ) )
  1596. {
  1597. inputPort.DummyRemove();
  1598. outputPort.DummyRemove();
  1599. m_parentWindow.WireReferenceUtils.InvalidateReferences();
  1600. UIUtils.ShowMessage( "Infinite Loop detected" );
  1601. Event.current.Use();
  1602. return;
  1603. }
  1604. inputPort.DummyRemove();
  1605. outputPort.DummyRemove();
  1606. if( inputPort.IsConnected )
  1607. {
  1608. DeleteConnection( true, inNodeId, inPortId, true, false, registerUndo );
  1609. }
  1610. //link output to input
  1611. if( outputPort.ConnectTo( inNodeId, inPortId, inputPort.DataType, inputPort.TypeLocked ) )
  1612. outputNode.OnOutputPortConnected( outputPort.PortId, inNodeId, inPortId );
  1613. //link input to output
  1614. if( inputPort.ConnectTo( outputPort.NodeId, outputPort.PortId, outputPort.DataType, inputPort.TypeLocked ) )
  1615. inputNode.OnInputPortConnected( inPortId, outputNode.UniqueId, outputPort.PortId );
  1616. MarkWireHighlights();
  1617. }
  1618. SaveIsDirty = true;
  1619. //ParentWindow.ShaderIsModified = true;
  1620. }
  1621. }
  1622. public void DeleteInvalidConnections()
  1623. {
  1624. int count = m_nodes.Count;
  1625. for( int nodeIdx = 0; nodeIdx < count; nodeIdx++ )
  1626. {
  1627. {
  1628. int inputCount = m_nodes[ nodeIdx ].InputPorts.Count;
  1629. for( int inputIdx = 0; inputIdx < inputCount; inputIdx++ )
  1630. {
  1631. if( !m_nodes[ nodeIdx ].InputPorts[ inputIdx ].Visible &&
  1632. m_nodes[ nodeIdx ].InputPorts[ inputIdx ].IsConnected &&
  1633. !m_nodes[ nodeIdx ].InputPorts[ inputIdx ].IsDummy )
  1634. {
  1635. DeleteConnection( true, m_nodes[ nodeIdx ].UniqueId, m_nodes[ nodeIdx ].InputPorts[ inputIdx ].PortId, true, true );
  1636. }
  1637. }
  1638. }
  1639. {
  1640. int outputCount = m_nodes[ nodeIdx ].OutputPorts.Count;
  1641. for( int outputIdx = 0; outputIdx < outputCount; outputIdx++ )
  1642. {
  1643. if( !m_nodes[ nodeIdx ].OutputPorts[ outputIdx ].Visible && m_nodes[ nodeIdx ].OutputPorts[ outputIdx ].IsConnected )
  1644. {
  1645. DeleteConnection( false, m_nodes[ nodeIdx ].UniqueId, m_nodes[ nodeIdx ].OutputPorts[ outputIdx ].PortId, true, true );
  1646. }
  1647. }
  1648. }
  1649. }
  1650. }
  1651. public void DeleteAllConnectionFromNode( int nodeId, bool registerOnLog, bool propagateCallback, bool registerUndo )
  1652. {
  1653. ParentNode node = GetNode( nodeId );
  1654. if( (object)node == null )
  1655. return;
  1656. DeleteAllConnectionFromNode( node, registerOnLog, propagateCallback, registerUndo );
  1657. }
  1658. public void DeleteAllConnectionFromNode( ParentNode node, bool registerOnLog, bool propagateCallback, bool registerUndo )
  1659. {
  1660. for( int i = 0; i < node.InputPorts.Count; i++ )
  1661. {
  1662. if( node.InputPorts[ i ].IsConnected )
  1663. DeleteConnection( true, node.UniqueId, node.InputPorts[ i ].PortId, registerOnLog, propagateCallback, registerUndo );
  1664. }
  1665. for( int i = 0; i < node.OutputPorts.Count; i++ )
  1666. {
  1667. if( node.OutputPorts[ i ].IsConnected )
  1668. DeleteConnection( false, node.UniqueId, node.OutputPorts[ i ].PortId, registerOnLog, propagateCallback, registerUndo );
  1669. }
  1670. }
  1671. public void DeleteConnection( bool isInput, int nodeId, int portId, bool registerOnLog, bool propagateCallback, bool registerUndo = true )
  1672. {
  1673. ParentNode node = GetNode( nodeId );
  1674. if( (object)node == null )
  1675. return;
  1676. if( registerUndo )
  1677. {
  1678. UIUtils.MarkUndoAction();
  1679. UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoDeleteConnectionId );
  1680. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoDeleteConnectionId );
  1681. node.RecordObject( Constants.UndoDeleteConnectionId );
  1682. }
  1683. if( isInput )
  1684. {
  1685. InputPort inputPort = node.GetInputPortByUniqueId( portId );
  1686. if( inputPort != null && inputPort.IsConnected )
  1687. {
  1688. if( node.ConnStatus == NodeConnectionStatus.Connected )
  1689. {
  1690. node.DeactivateInputPortNode( portId, false );
  1691. //inputPort.GetOutputNode().DeactivateNode( portId, false );
  1692. m_checkSelectedWireHighlights = true;
  1693. }
  1694. for( int i = 0; i < inputPort.ExternalReferences.Count; i++ )
  1695. {
  1696. WireReference inputReference = inputPort.ExternalReferences[ i ];
  1697. ParentNode outputNode = GetNode( inputReference.NodeId );
  1698. if( registerUndo )
  1699. outputNode.RecordObject( Constants.UndoDeleteConnectionId );
  1700. outputNode.GetOutputPortByUniqueId( inputReference.PortId ).InvalidateConnection( inputPort.NodeId, inputPort.PortId );
  1701. if( propagateCallback )
  1702. outputNode.OnOutputPortDisconnected( inputReference.PortId );
  1703. }
  1704. inputPort.InvalidateAllConnections();
  1705. if( propagateCallback )
  1706. node.OnInputPortDisconnected( portId );
  1707. }
  1708. }
  1709. else
  1710. {
  1711. OutputPort outputPort = node.GetOutputPortByUniqueId( portId );
  1712. if( outputPort != null && outputPort.IsConnected )
  1713. {
  1714. if( propagateCallback )
  1715. node.OnOutputPortDisconnected( portId );
  1716. for( int i = 0; i < outputPort.ExternalReferences.Count; i++ )
  1717. {
  1718. WireReference outputReference = outputPort.ExternalReferences[ i ];
  1719. ParentNode inputNode = GetNode( outputReference.NodeId );
  1720. if( registerUndo )
  1721. inputNode.RecordObject( Constants.UndoDeleteConnectionId );
  1722. if( inputNode.ConnStatus == NodeConnectionStatus.Connected )
  1723. {
  1724. node.DeactivateNode( portId, false );
  1725. m_checkSelectedWireHighlights = true;
  1726. }
  1727. inputNode.GetInputPortByUniqueId( outputReference.PortId ).InvalidateConnection( outputPort.NodeId, outputPort.PortId );
  1728. if( propagateCallback )
  1729. {
  1730. // Removing WireNodes fires this after the rewiring ( and the OnInputPortConnected callback ) which causes incorrect behaviors
  1731. // If is connected is true then we're on that case so we don't fire the OnInputPortDisconnected
  1732. if( !inputNode.GetInputPortByUniqueId( outputReference.PortId ).IsConnected )
  1733. inputNode.OnInputPortDisconnected( outputReference.PortId );
  1734. }
  1735. }
  1736. outputPort.InvalidateAllConnections();
  1737. }
  1738. }
  1739. IsDirty = true;
  1740. SaveIsDirty = true;
  1741. }
  1742. //public void DeleteSelectedNodes()
  1743. //{
  1744. // bool invalidateMasterNode = false;
  1745. // int count = m_selectedNodes.Count;
  1746. // for( int nodeIdx = 0; nodeIdx < count; nodeIdx++ )
  1747. // {
  1748. // ParentNode node = m_selectedNodes[ nodeIdx ];
  1749. // if( node.UniqueId == m_masterNodeId )
  1750. // {
  1751. // invalidateMasterNode = true;
  1752. // }
  1753. // else
  1754. // {
  1755. // DestroyNode( node );
  1756. // }
  1757. // }
  1758. // if( invalidateMasterNode )
  1759. // {
  1760. // CurrentOutputNode.Selected = false;
  1761. // }
  1762. // //Clear all references
  1763. // m_selectedNodes.Clear();
  1764. // IsDirty = true;
  1765. //}
  1766. public void DeleteNodesOnArray( ref ParentNode[] nodeArray )
  1767. {
  1768. bool invalidateMasterNode = false;
  1769. for( int nodeIdx = 0; nodeIdx < nodeArray.Length; nodeIdx++ )
  1770. {
  1771. ParentNode node = nodeArray[ nodeIdx ];
  1772. if( node.UniqueId == m_masterNodeId )
  1773. {
  1774. FunctionOutput fout = node as FunctionOutput;
  1775. if( fout != null )
  1776. {
  1777. for( int i = 0; i < m_nodes.Count; i++ )
  1778. {
  1779. FunctionOutput secondfout = m_nodes[ i ] as FunctionOutput;
  1780. if( secondfout != null && secondfout != fout )
  1781. {
  1782. secondfout.Function = fout.Function;
  1783. AssignMasterNode( secondfout, false );
  1784. DeselectNode( fout );
  1785. DestroyNode( fout );
  1786. break;
  1787. }
  1788. }
  1789. }
  1790. invalidateMasterNode = true;
  1791. }
  1792. else
  1793. {
  1794. DeselectNode( node );
  1795. DestroyNode( node );
  1796. }
  1797. nodeArray[ nodeIdx ] = null;
  1798. }
  1799. if( invalidateMasterNode && CurrentMasterNode != null )
  1800. {
  1801. CurrentMasterNode.Selected = false;
  1802. }
  1803. //Clear all references
  1804. nodeArray = null;
  1805. IsDirty = true;
  1806. }
  1807. public void MarkWireNodeSequence( WireNode node, bool isInput )
  1808. {
  1809. if( node == null )
  1810. {
  1811. return;
  1812. }
  1813. if( m_markedForDeletion.Contains( node ) )
  1814. return;
  1815. m_markedForDeletion.Add( node );
  1816. if( isInput && node.InputPorts[ 0 ].IsConnected )
  1817. {
  1818. MarkWireNodeSequence( GetNode( node.InputPorts[ 0 ].ExternalReferences[ 0 ].NodeId ) as WireNode, isInput );
  1819. }
  1820. else if( !isInput && node.OutputPorts[ 0 ].IsConnected )
  1821. {
  1822. MarkWireNodeSequence( GetNode( node.OutputPorts[ 0 ].ExternalReferences[ 0 ].NodeId ) as WireNode, isInput );
  1823. }
  1824. }
  1825. public void UndoableDeleteSelectedNodes( List<ParentNode> nodeList )
  1826. {
  1827. if( nodeList.Count == 0 )
  1828. return;
  1829. List<ParentNode> validNode = new List<ParentNode>();
  1830. for( int i = 0; i < nodeList.Count; i++ )
  1831. {
  1832. if( nodeList[ i ] != null && nodeList[ i ].UniqueId != m_masterNodeId )
  1833. {
  1834. validNode.Add( nodeList[ i ] );
  1835. }
  1836. }
  1837. UIUtils.ClearUndoHelper();
  1838. ParentNode[] selectedNodes = new ParentNode[ validNode.Count ];
  1839. for( int i = 0; i < selectedNodes.Length; i++ )
  1840. {
  1841. if( validNode[ i ] != null )
  1842. {
  1843. selectedNodes[ i ] = validNode[ i ];
  1844. UIUtils.CheckUndoNode( selectedNodes[ i ] );
  1845. }
  1846. }
  1847. //Check nodes connected to deleted nodes to preserve connections on undo
  1848. List<ParentNode> extraNodes = new List<ParentNode>();
  1849. for( int selectedNodeIdx = 0; selectedNodeIdx < selectedNodes.Length; selectedNodeIdx++ )
  1850. {
  1851. // Check inputs
  1852. if( selectedNodes[ selectedNodeIdx ] != null )
  1853. {
  1854. int inputIdxCount = selectedNodes[ selectedNodeIdx ].InputPorts.Count;
  1855. if( inputIdxCount > 0 )
  1856. {
  1857. for( int inputIdx = 0; inputIdx < inputIdxCount; inputIdx++ )
  1858. {
  1859. if( selectedNodes[ selectedNodeIdx ].InputPorts[ inputIdx ].IsConnected )
  1860. {
  1861. int nodeIdx = selectedNodes[ selectedNodeIdx ].InputPorts[ inputIdx ].ExternalReferences[ 0 ].NodeId;
  1862. if( nodeIdx > -1 )
  1863. {
  1864. ParentNode node = GetNode( nodeIdx );
  1865. if( node != null && UIUtils.CheckUndoNode( node ) )
  1866. {
  1867. extraNodes.Add( node );
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. // Check outputs
  1875. if( selectedNodes[ selectedNodeIdx ] != null )
  1876. {
  1877. int outputIdxCount = selectedNodes[ selectedNodeIdx ].OutputPorts.Count;
  1878. if( outputIdxCount > 0 )
  1879. {
  1880. for( int outputIdx = 0; outputIdx < outputIdxCount; outputIdx++ )
  1881. {
  1882. int inputIdxCount = selectedNodes[ selectedNodeIdx ].OutputPorts[ outputIdx ].ExternalReferences.Count;
  1883. if( inputIdxCount > 0 )
  1884. {
  1885. for( int inputIdx = 0; inputIdx < inputIdxCount; inputIdx++ )
  1886. {
  1887. int nodeIdx = selectedNodes[ selectedNodeIdx ].OutputPorts[ outputIdx ].ExternalReferences[ inputIdx ].NodeId;
  1888. if( nodeIdx > -1 )
  1889. {
  1890. ParentNode node = GetNode( nodeIdx );
  1891. if( UIUtils.CheckUndoNode( node ) )
  1892. {
  1893. extraNodes.Add( node );
  1894. }
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. UIUtils.ClearUndoHelper();
  1903. //Record deleted nodes
  1904. UIUtils.MarkUndoAction();
  1905. UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoDeleteNodeId );
  1906. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoDeleteNodeId );
  1907. UndoUtils.RecordObjects( selectedNodes, Constants.UndoDeleteNodeId );
  1908. UndoUtils.RecordObjects( extraNodes.ToArray(), Constants.UndoDeleteNodeId );
  1909. //Record deleting connections
  1910. for( int i = 0; i < selectedNodes.Length; i++ )
  1911. {
  1912. CurrentOutputNode.Selected = false;
  1913. selectedNodes[ i ].Alive = false;
  1914. DeleteAllConnectionFromNode( selectedNodes[ i ], false, true, true );
  1915. }
  1916. //Delete
  1917. DeleteNodesOnArray( ref selectedNodes );
  1918. extraNodes.Clear();
  1919. extraNodes = null;
  1920. EditorUtility.SetDirty( ParentWindow );
  1921. ParentWindow.ForceRepaint();
  1922. }
  1923. public void DeleteMarkedForDeletionNodes()
  1924. {
  1925. UndoableDeleteSelectedNodes( m_markedForDeletion );
  1926. m_markedForDeletion.Clear();
  1927. IsDirty = true;
  1928. //bool invalidateMasterNode = false;
  1929. //int count = m_markedForDeletion.Count;
  1930. //for ( int nodeIdx = 0; nodeIdx < count; nodeIdx++ )
  1931. //{
  1932. // ParentNode node = m_markedForDeletion[ nodeIdx ];
  1933. // if ( node.UniqueId == m_masterNodeId )
  1934. // {
  1935. // invalidateMasterNode = true;
  1936. // }
  1937. // else
  1938. // {
  1939. // if ( node.Selected )
  1940. // {
  1941. // m_selectedNodes.Remove( node );
  1942. // node.Selected = false;
  1943. // }
  1944. // DestroyNode( node );
  1945. // }
  1946. //}
  1947. //if ( invalidateMasterNode )
  1948. //{
  1949. // CurrentMasterNode.Selected = false;
  1950. //}
  1951. ////Clear all references
  1952. //m_markedForDeletion.Clear();
  1953. //IsDirty = true;
  1954. }
  1955. public void DestroyNode( int nodeId )
  1956. {
  1957. ParentNode node = GetNode( nodeId );
  1958. DestroyNode( node );
  1959. }
  1960. public void DestroyNode( ParentNode node, bool registerUndo = true, bool destroyMasterNode = false )
  1961. {
  1962. if( node == null )
  1963. {
  1964. UIUtils.ShowMessage( "Attempting to destroying a inexistant node ", MessageSeverity.Warning );
  1965. return;
  1966. }
  1967. if( node.ConnStatus == NodeConnectionStatus.Connected && !m_checkSelectedWireHighlights )
  1968. {
  1969. ResetHighlightedWires();
  1970. m_checkSelectedWireHighlights = true;
  1971. }
  1972. //TODO: check better placement of this code (reconnects wires from wire nodes)
  1973. //if ( node.GetType() == typeof( WireNode ) )
  1974. //{
  1975. // if ( node.InputPorts[ 0 ].ExternalReferences != null && node.InputPorts[ 0 ].ExternalReferences.Count > 0 )
  1976. // {
  1977. // WireReference backPort = node.InputPorts[ 0 ].ExternalReferences[ 0 ];
  1978. // for ( int i = 0; i < node.OutputPorts[ 0 ].ExternalReferences.Count; i++ )
  1979. // {
  1980. // UIUtils.CurrentWindow.ConnectInputToOutput( node.OutputPorts[ 0 ].ExternalReferences[ i ].NodeId, node.OutputPorts[ 0 ].ExternalReferences[ i ].PortId, backPort.NodeId, backPort.PortId );
  1981. // }
  1982. // }
  1983. //}
  1984. if( destroyMasterNode || ( node.UniqueId != m_masterNodeId && !( node is TemplateMultiPassMasterNode )/*!m_multiPassMasterNodes.HasNode( node.UniqueId )*/ ) )
  1985. {
  1986. m_nodeGrid.RemoveNodeFromGrid( node, false );
  1987. //Send Deactivation signal if active
  1988. if( node.ConnStatus == NodeConnectionStatus.Connected )
  1989. {
  1990. node.DeactivateNode( -1, true );
  1991. }
  1992. //Invalidate references
  1993. //Invalidate input references
  1994. for( int inputPortIdx = 0; inputPortIdx < node.InputPorts.Count; inputPortIdx++ )
  1995. {
  1996. InputPort inputPort = node.InputPorts[ inputPortIdx ];
  1997. if( inputPort.IsConnected )
  1998. {
  1999. for( int wireIdx = 0; wireIdx < inputPort.ExternalReferences.Count; wireIdx++ )
  2000. {
  2001. WireReference inputReference = inputPort.ExternalReferences[ wireIdx ];
  2002. ParentNode outputNode = GetNode( inputReference.NodeId );
  2003. outputNode.GetOutputPortByUniqueId( inputReference.PortId ).InvalidateConnection( inputPort.NodeId, inputPort.PortId );
  2004. outputNode.OnOutputPortDisconnected( inputReference.PortId );
  2005. }
  2006. inputPort.InvalidateAllConnections();
  2007. }
  2008. }
  2009. //Invalidate output reference
  2010. for( int outputPortIdx = 0; outputPortIdx < node.OutputPorts.Count; outputPortIdx++ )
  2011. {
  2012. OutputPort outputPort = node.OutputPorts[ outputPortIdx ];
  2013. if( outputPort.IsConnected )
  2014. {
  2015. for( int wireIdx = 0; wireIdx < outputPort.ExternalReferences.Count; wireIdx++ )
  2016. {
  2017. WireReference outputReference = outputPort.ExternalReferences[ wireIdx ];
  2018. ParentNode outnode = GetNode( outputReference.NodeId );
  2019. if( outnode != null )
  2020. {
  2021. outnode.GetInputPortByUniqueId( outputReference.PortId ).InvalidateConnection( outputPort.NodeId, outputPort.PortId );
  2022. outnode.OnInputPortDisconnected( outputReference.PortId );
  2023. }
  2024. }
  2025. outputPort.InvalidateAllConnections();
  2026. }
  2027. }
  2028. //Remove node from main list
  2029. //UndoUtils.RecordObject( node, "Destroying node " + ( node.Attributes != null? node.Attributes.Name: node.GetType().ToString() ) );
  2030. if( registerUndo )
  2031. {
  2032. UIUtils.MarkUndoAction();
  2033. UndoUtils.RegisterCompleteObjectUndo( ParentWindow, Constants.UndoDeleteNodeId );
  2034. UndoUtils.RegisterCompleteObjectUndo( this, Constants.UndoDeleteNodeId );
  2035. node.RecordObjectOnDestroy( Constants.UndoDeleteNodeId );
  2036. }
  2037. if( OnNodeRemovedEvent != null )
  2038. OnNodeRemovedEvent( node );
  2039. m_nodes.Remove( node );
  2040. m_nodesDict.Remove( node.UniqueId );
  2041. node.Destroy();
  2042. if ( registerUndo )
  2043. {
  2044. UndoUtils.DestroyObjectImmediate( node );
  2045. }
  2046. else
  2047. {
  2048. DestroyImmediate( node );
  2049. }
  2050. IsDirty = true;
  2051. m_markToReOrder = true;
  2052. }
  2053. //else if( node.UniqueId == m_masterNodeId && node.GetType() == typeof(FunctionOutput) )
  2054. //{
  2055. // Debug.Log( "Attempting to destroy a output node" );
  2056. // DeselectNode( node );
  2057. // UIUtils.ShowMessage( "Attempting to destroy a output node" );
  2058. //}
  2059. else
  2060. {
  2061. TemplateMultiPassMasterNode templateMasterNode = node as TemplateMultiPassMasterNode;
  2062. if( templateMasterNode != null && templateMasterNode.InvalidNode )
  2063. {
  2064. DestroyNode( node, false, true );
  2065. return;
  2066. }
  2067. DeselectNode( node );
  2068. UIUtils.ShowMessage( "Attempting to destroy a master node" );
  2069. }
  2070. }
  2071. void AddToSelectedNodes( ParentNode node )
  2072. {
  2073. node.Selected = true;
  2074. m_selectedNodes.Add( node );
  2075. node.OnNodeStoppedMovingEvent += OnNodeFinishMoving;
  2076. if( node.ConnStatus == NodeConnectionStatus.Connected )
  2077. {
  2078. HighlightWiresStartingNode( node );
  2079. }
  2080. }
  2081. void RemoveFromSelectedNodes( ParentNode node )
  2082. {
  2083. node.Selected = false;
  2084. m_selectedNodes.Remove( node );
  2085. node.OnNodeStoppedMovingEvent -= OnNodeFinishMoving;
  2086. }
  2087. public void SelectNode( ParentNode node, bool append, bool reorder )
  2088. {
  2089. if( node == null )
  2090. return;
  2091. if( append )
  2092. {
  2093. if( !m_selectedNodes.Contains( node ) )
  2094. {
  2095. AddToSelectedNodes( node );
  2096. }
  2097. }
  2098. else
  2099. {
  2100. DeSelectAll();
  2101. AddToSelectedNodes( node );
  2102. }
  2103. if( reorder && !node.ReorderLocked )
  2104. {
  2105. m_nodes.Remove( node );
  2106. m_nodes.Add( node );
  2107. m_markToReOrder = true;
  2108. }
  2109. }
  2110. public void MultipleSelection( Rect selectionArea, bool appendSelection = true )
  2111. {
  2112. if( !appendSelection )
  2113. {
  2114. for( int i = 0; i < m_nodes.Count; i++ )
  2115. {
  2116. if( selectionArea.Overlaps( m_nodes[ i ].Position, true ) )
  2117. {
  2118. RemoveFromSelectedNodes( m_nodes[ i ] );
  2119. }
  2120. }
  2121. m_markedToDeSelect = false;
  2122. ResetHighlightedWires();
  2123. }
  2124. else
  2125. {
  2126. for( int i = 0; i < m_nodes.Count; i++ )
  2127. {
  2128. if( !m_nodes[ i ].Selected && selectionArea.Overlaps( m_nodes[ i ].Position, true ) )
  2129. {
  2130. AddToSelectedNodes( m_nodes[ i ] );
  2131. }
  2132. }
  2133. }
  2134. // reorder nodes and highlight them
  2135. for( int i = 0; i < m_selectedNodes.Count; i++ )
  2136. {
  2137. if( !m_selectedNodes[ i ].ReorderLocked )
  2138. {
  2139. m_nodes.Remove( m_selectedNodes[ i ] );
  2140. m_nodes.Add( m_selectedNodes[ i ] );
  2141. m_markToReOrder = true;
  2142. if( m_selectedNodes[ i ].ConnStatus == NodeConnectionStatus.Connected )
  2143. {
  2144. HighlightWiresStartingNode( m_selectedNodes[ i ] );
  2145. }
  2146. }
  2147. }
  2148. }
  2149. public void SelectAll()
  2150. {
  2151. for( int i = 0; i < m_nodes.Count; i++ )
  2152. {
  2153. if( !m_nodes[ i ].Selected )
  2154. AddToSelectedNodes( m_nodes[ i ] );
  2155. }
  2156. }
  2157. public void SelectMasterNode()
  2158. {
  2159. if( m_masterNodeId != Constants.INVALID_NODE_ID )
  2160. {
  2161. SelectNode( CurrentMasterNode, false, false );
  2162. }
  2163. }
  2164. public void SelectOutputNode()
  2165. {
  2166. if( m_masterNodeId != Constants.INVALID_NODE_ID )
  2167. {
  2168. SelectNode( CurrentOutputNode, false, false );
  2169. }
  2170. }
  2171. public void DeselectNode( int nodeId )
  2172. {
  2173. ParentNode node = GetNode( nodeId );
  2174. if( node )
  2175. {
  2176. m_selectedNodes.Remove( node );
  2177. node.Selected = false;
  2178. }
  2179. }
  2180. public void DeselectNode( ParentNode node )
  2181. {
  2182. m_selectedNodes.Remove( node );
  2183. node.Selected = false;
  2184. PropagateHighlightDeselection( node );
  2185. }
  2186. public void DeSelectAll()
  2187. {
  2188. m_markedToDeSelect = false;
  2189. for( int i = 0; i < m_selectedNodes.Count; i++ )
  2190. {
  2191. m_selectedNodes[ i ].Selected = false;
  2192. m_selectedNodes[ i ].OnNodeStoppedMovingEvent -= OnNodeFinishMoving;
  2193. }
  2194. m_selectedNodes.Clear();
  2195. ResetHighlightedWires();
  2196. }
  2197. public void AssignMasterNode()
  2198. {
  2199. if( m_selectedNodes.Count == 1 )
  2200. {
  2201. OutputNode newOutputNode = m_selectedNodes[ 0 ] as OutputNode;
  2202. MasterNode newMasterNode = newOutputNode as MasterNode;
  2203. if( newOutputNode != null )
  2204. {
  2205. if( m_masterNodeId != Constants.INVALID_NODE_ID && m_masterNodeId != newOutputNode.UniqueId )
  2206. {
  2207. OutputNode oldOutputNode = GetNode( m_masterNodeId ) as OutputNode;
  2208. MasterNode oldMasterNode = oldOutputNode as MasterNode;
  2209. if( oldOutputNode != null )
  2210. {
  2211. oldOutputNode.IsMainOutputNode = false;
  2212. if( oldMasterNode != null )
  2213. {
  2214. oldMasterNode.ClearUpdateEvents();
  2215. }
  2216. }
  2217. }
  2218. m_masterNodeId = newOutputNode.UniqueId;
  2219. newOutputNode.IsMainOutputNode = true;
  2220. if( newMasterNode != null )
  2221. {
  2222. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  2223. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  2224. }
  2225. }
  2226. }
  2227. IsDirty = true;
  2228. }
  2229. public void AssignMasterNode( OutputNode node, bool onlyUpdateGraphId )
  2230. {
  2231. AssignMasterNode( node.UniqueId, onlyUpdateGraphId );
  2232. MasterNode masterNode = node as MasterNode;
  2233. if( masterNode != null )
  2234. {
  2235. masterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  2236. masterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  2237. }
  2238. }
  2239. public void AssignMasterNode( int nodeId, bool onlyUpdateGraphId )
  2240. {
  2241. if( nodeId < 0 || m_masterNodeId == nodeId )
  2242. return;
  2243. if( m_masterNodeId > Constants.INVALID_NODE_ID )
  2244. {
  2245. OutputNode oldOutputNode = ( GetNode( nodeId ) as OutputNode );
  2246. MasterNode oldMasterNode = oldOutputNode as MasterNode;
  2247. if( oldOutputNode != null )
  2248. {
  2249. oldOutputNode.IsMainOutputNode = false;
  2250. if( oldMasterNode != null )
  2251. {
  2252. oldMasterNode.ClearUpdateEvents();
  2253. }
  2254. }
  2255. }
  2256. if( onlyUpdateGraphId )
  2257. {
  2258. m_masterNodeId = nodeId;
  2259. }
  2260. else
  2261. {
  2262. OutputNode outputNode = ( GetNode( nodeId ) as OutputNode );
  2263. if( outputNode != null )
  2264. {
  2265. outputNode.IsMainOutputNode = true;
  2266. m_masterNodeId = nodeId;
  2267. }
  2268. }
  2269. IsDirty = true;
  2270. }
  2271. public void RefreshOnUndo()
  2272. {
  2273. if( m_nodes != null )
  2274. {
  2275. int count = m_nodes.Count;
  2276. for( int i = 0; i < count; i++ )
  2277. {
  2278. if( m_nodes[ i ] != null )
  2279. {
  2280. m_nodes[ i ].RefreshOnUndo();
  2281. }
  2282. }
  2283. }
  2284. }
  2285. public void DrawGrid( DrawInfo drawInfo )
  2286. {
  2287. m_nodeGrid.DrawGrid( drawInfo );
  2288. }
  2289. public float MaxNodeDist
  2290. {
  2291. get { return m_nodeGrid.MaxNodeDist; }
  2292. }
  2293. public List<ParentNode> GetNodesInGrid( Vector2 transformedMousePos )
  2294. {
  2295. return m_nodeGrid.GetNodesOn( transformedMousePos );
  2296. }
  2297. public void FireMasterNode( Shader selectedShader )
  2298. {
  2299. ( GetNode( m_masterNodeId ) as MasterNode ).Execute( selectedShader );
  2300. }
  2301. public Shader FireMasterNode( string pathname, bool isFullPath )
  2302. {
  2303. return ( GetNode( m_masterNodeId ) as MasterNode ).Execute( pathname, isFullPath );
  2304. }
  2305. private void ForceSignalPropagationOnMasterNodeInternal( UsageListTemplateMultiPassMasterNodes masterNodes )
  2306. {
  2307. int mpCount = masterNodes.Count;
  2308. for( int i = 0; i < mpCount; i++ )
  2309. {
  2310. masterNodes.NodesList[ i ].GenerateSignalPropagation();
  2311. }
  2312. }
  2313. public void ForceSignalPropagationOnMasterNode()
  2314. {
  2315. if( m_multiPassMasterNodes.Count > 0 )
  2316. {
  2317. ForceSignalPropagationOnMasterNodeInternal( m_multiPassMasterNodes );
  2318. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  2319. {
  2320. ForceSignalPropagationOnMasterNodeInternal( m_lodMultiPassMasterNodes[ i ] );
  2321. }
  2322. }
  2323. else if( CurrentOutputNode != null )
  2324. CurrentOutputNode.GenerateSignalPropagation();
  2325. List<FunctionOutput> allOutputs = m_functionOutputNodes.NodesList;
  2326. for( int i = 0; i < allOutputs.Count; i++ )
  2327. {
  2328. allOutputs[ i ].GenerateSignalPropagation();
  2329. }
  2330. //List<RegisterLocalVarNode> localVarNodes = m_localVarNodes.NodesList;
  2331. //int count = localVarNodes.Count;
  2332. //for( int i = 0; i < count; i++ )
  2333. //{
  2334. // localVarNodes[ i ].GenerateSignalPropagation();
  2335. //}
  2336. }
  2337. public void UpdateShaderOnMasterNode( Shader newShader )
  2338. {
  2339. MasterNode mainMasterNode = ( GetNode( m_masterNodeId ) as MasterNode );
  2340. if( mainMasterNode == null )
  2341. {
  2342. Debug.LogError( "No Master Node was detected. Aborting update!" );
  2343. return;
  2344. }
  2345. mainMasterNode.UpdateFromShader( newShader );
  2346. if( HasLODs )
  2347. {
  2348. int passIdx = ( (TemplateMultiPassMasterNode)mainMasterNode ).PassIdx;
  2349. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  2350. {
  2351. if( m_lodMultiPassMasterNodes.Count != 0 && m_lodMultiPassMasterNodes[ i ].NodesList.Count > 0 )
  2352. {
  2353. if( m_lodMultiPassMasterNodes[ i ].NodesList[ passIdx ] != null )
  2354. {
  2355. m_lodMultiPassMasterNodes[ i ].NodesList[ passIdx ].UpdateFromShader( newShader );
  2356. }
  2357. else
  2358. {
  2359. Debug.LogError( "Null master node detected. Aborting update!" );
  2360. return;
  2361. }
  2362. }
  2363. else break;
  2364. }
  2365. }
  2366. }
  2367. public void CopyValuesFromMaterial( Material material )
  2368. {
  2369. Material currMaterial = CurrentMaterial;
  2370. if( currMaterial == material )
  2371. {
  2372. for( int i = 0; i < m_nodes.Count; i++ )
  2373. {
  2374. m_nodes[ i ].ForceUpdateFromMaterial( material );
  2375. }
  2376. }
  2377. }
  2378. public void UpdateMaterialOnMasterNode( Material material )
  2379. {
  2380. MasterNode mainMasterNode = ( GetNode( m_masterNodeId ) as MasterNode );
  2381. mainMasterNode.UpdateMasterNodeMaterial( material );
  2382. if( HasLODs )
  2383. {
  2384. int passIdx = ( (TemplateMultiPassMasterNode)mainMasterNode ).PassIdx;
  2385. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  2386. {
  2387. if( m_lodMultiPassMasterNodes.Count != 0 && m_lodMultiPassMasterNodes[ i ].NodesList.Count > 0 )
  2388. {
  2389. m_lodMultiPassMasterNodes[ i ].NodesList[ passIdx ].UpdateMasterNodeMaterial( material );
  2390. }
  2391. else break;
  2392. }
  2393. }
  2394. }
  2395. public void UpdateMaterialOnPropertyNodes( Material material )
  2396. {
  2397. int propertyCount = m_propertyNodes.Count;
  2398. for(int i = 0;i< propertyCount;i++ )
  2399. {
  2400. m_propertyNodes.NodesList[i].UpdateMaterial( material );
  2401. }
  2402. }
  2403. public void SetMaterialModeOnGraph( Material mat, bool fetchMaterialValues = true )
  2404. {
  2405. for( int i = 0; i < m_nodes.Count; i++ )
  2406. {
  2407. m_nodes[ i ].SetMaterialMode( mat, fetchMaterialValues );
  2408. }
  2409. }
  2410. public ParentNode CheckNodeAt( Vector3 pos, bool checkForRMBIgnore = false )
  2411. {
  2412. ParentNode selectedNode = null;
  2413. // this is checked on the inverse order to give priority to nodes that are drawn on top ( last on the list )
  2414. for( int i = m_nodes.Count - 1; i > -1; i-- )
  2415. {
  2416. if( m_nodes[ i ].Contains( pos ) )
  2417. {
  2418. if( checkForRMBIgnore )
  2419. {
  2420. if( !m_nodes[ i ].RMBIgnore )
  2421. {
  2422. selectedNode = m_nodes[ i ];
  2423. break;
  2424. }
  2425. }
  2426. else
  2427. {
  2428. selectedNode = m_nodes[ i ];
  2429. break;
  2430. }
  2431. }
  2432. }
  2433. return selectedNode;
  2434. }
  2435. public void ResetNodesLocalVariables()
  2436. {
  2437. for( int i = 0; i < m_nodes.Count; i++ )
  2438. {
  2439. m_nodes[ i ].Reset();
  2440. m_nodes[ i ].ResetOutputLocals();
  2441. FunctionNode fnode = m_nodes[ i ] as FunctionNode;
  2442. if( fnode != null )
  2443. {
  2444. if( fnode.Function != null )
  2445. fnode.FunctionGraph.ResetNodesLocalVariables();
  2446. }
  2447. }
  2448. }
  2449. public void ResetNodesLocalVariablesIfNot( MasterNodePortCategory category )
  2450. {
  2451. for( int i = 0; i < m_nodes.Count; i++ )
  2452. {
  2453. m_nodes[ i ].Reset();
  2454. m_nodes[ i ].ResetOutputLocalsIfNot( category );
  2455. FunctionNode fnode = m_nodes[ i ] as FunctionNode;
  2456. if( fnode != null )
  2457. {
  2458. if( fnode.Function != null )
  2459. fnode.FunctionGraph.ResetNodesLocalVariablesIfNot( category );
  2460. }
  2461. }
  2462. }
  2463. public void ResetNodesLocalVariables( ParentNode node )
  2464. {
  2465. if( node is GetLocalVarNode )
  2466. {
  2467. GetLocalVarNode localVarNode = node as GetLocalVarNode;
  2468. if( localVarNode.CurrentSelected != null )
  2469. {
  2470. node = localVarNode.CurrentSelected;
  2471. }
  2472. }
  2473. node.Reset();
  2474. node.ResetOutputLocals();
  2475. int count = node.InputPorts.Count;
  2476. for( int i = 0; i < count; i++ )
  2477. {
  2478. if( node.InputPorts[ i ].IsConnected )
  2479. {
  2480. ResetNodesLocalVariables( m_nodesDict[ node.InputPorts[ i ].GetConnection().NodeId ] );
  2481. }
  2482. }
  2483. }
  2484. public void ResetNodesLocalVariablesIfNot( ParentNode node, MasterNodePortCategory category )
  2485. {
  2486. if( node is GetLocalVarNode )
  2487. {
  2488. GetLocalVarNode localVarNode = node as GetLocalVarNode;
  2489. if( localVarNode.CurrentSelected != null )
  2490. {
  2491. node = localVarNode.CurrentSelected;
  2492. }
  2493. }
  2494. node.Reset();
  2495. node.ResetOutputLocalsIfNot( category );
  2496. int count = node.InputPorts.Count;
  2497. for( int i = 0; i < count; i++ )
  2498. {
  2499. if( node.InputPorts[ i ].IsConnected )
  2500. {
  2501. ResetNodesLocalVariablesIfNot( m_nodesDict[ node.InputPorts[ i ].GetConnection().NodeId ], category );
  2502. }
  2503. }
  2504. }
  2505. public override string ToString()
  2506. {
  2507. string dump = ( "Parent Graph \n" );
  2508. for( int i = 0; i < m_nodes.Count; i++ )
  2509. {
  2510. dump += ( m_nodes[ i ] + "\n" );
  2511. }
  2512. return dump;
  2513. }
  2514. public void OrderNodesByGraphDepth()
  2515. {
  2516. if( CurrentMasterNode != null )
  2517. {
  2518. //CurrentMasterNode.SetupNodeCategories();
  2519. int count = m_nodes.Count;
  2520. for( int i = 0; i < count; i++ )
  2521. {
  2522. if( m_nodes[ i ].ConnStatus == NodeConnectionStatus.Island )
  2523. {
  2524. m_nodes[ i ].CalculateCustomGraphDepth();
  2525. }
  2526. }
  2527. }
  2528. else
  2529. {
  2530. //TODO: remove this dynamic list
  2531. List<OutputNode> allOutputs = new List<OutputNode>();
  2532. for( int i = 0; i < AllNodes.Count; i++ )
  2533. {
  2534. OutputNode temp = AllNodes[ i ] as OutputNode;
  2535. if( temp != null )
  2536. allOutputs.Add( temp );
  2537. }
  2538. for( int j = 0; j < allOutputs.Count; j++ )
  2539. {
  2540. allOutputs[ j ].SetupNodeCategories();
  2541. int count = m_nodes.Count;
  2542. for( int i = 0; i < count; i++ )
  2543. {
  2544. if( m_nodes[ i ].ConnStatus == NodeConnectionStatus.Island )
  2545. {
  2546. m_nodes[ i ].CalculateCustomGraphDepth();
  2547. }
  2548. }
  2549. }
  2550. }
  2551. // @diogo: replaced Sort() with OrderBy() for stable sorting
  2552. m_nodes = m_nodes.OrderByDescending( s => s.GraphDepth ).ToList();
  2553. }
  2554. public void WriteToString( ref string nodesInfo, ref string connectionsInfo )
  2555. {
  2556. for( int i = 0; i < m_nodes.Count; i++ )
  2557. {
  2558. m_nodes[ i ].FullWriteToString( ref nodesInfo, ref connectionsInfo );
  2559. IOUtils.AddLineTerminator( ref nodesInfo );
  2560. }
  2561. }
  2562. public void Reset()
  2563. {
  2564. SaveIsDirty = false;
  2565. IsDirty = false;
  2566. }
  2567. public void OnBeforeSerialize()
  2568. {
  2569. //DeSelectAll();
  2570. }
  2571. public void OnAfterDeserialize()
  2572. {
  2573. m_afterDeserializeFlag = true;
  2574. }
  2575. public void CleanCorruptedNodes()
  2576. {
  2577. for( int i = 0; i < m_nodes.Count; i++ )
  2578. {
  2579. if( (object)m_nodes[ i ] == null )
  2580. {
  2581. m_nodes.RemoveAt( i );
  2582. CleanCorruptedNodes();
  2583. }
  2584. }
  2585. }
  2586. public void OnDuplicateEventWrapper()
  2587. {
  2588. if( OnDuplicateEvent != null )
  2589. {
  2590. AmplifyShaderEditorWindow temp = UIUtils.CurrentWindow;
  2591. UIUtils.CurrentWindow = ParentWindow;
  2592. OnDuplicateEvent();
  2593. UIUtils.CurrentWindow = temp;
  2594. }
  2595. }
  2596. public ParentNode CreateNode( AmplifyShaderFunction shaderFunction, bool registerUndo, int nodeId = -1, bool addLast = true )
  2597. {
  2598. FunctionNode newNode = ScriptableObject.CreateInstance<FunctionNode>();
  2599. if( newNode )
  2600. {
  2601. newNode.ContainerGraph = this;
  2602. newNode.CommonInit( shaderFunction, nodeId );
  2603. newNode.UniqueId = nodeId;
  2604. AddNode( newNode, nodeId < 0, addLast, registerUndo );
  2605. }
  2606. return newNode;
  2607. }
  2608. public ParentNode CreateNode( AmplifyShaderFunction shaderFunction, bool registerUndo, Vector2 pos, int nodeId = -1, bool addLast = true )
  2609. {
  2610. ParentNode newNode = CreateNode( shaderFunction, registerUndo, nodeId, addLast );
  2611. if( newNode )
  2612. {
  2613. newNode.Vec2Position = pos;
  2614. }
  2615. return newNode;
  2616. }
  2617. public TemplateMultiPassMasterNode CreateMultipassMasterNode( int lodId, bool registerUndo, int nodeId = -1, bool addLast = true )
  2618. {
  2619. TemplateMultiPassMasterNode newNode = ScriptableObject.CreateInstance<TemplateMultiPassMasterNode>();
  2620. if( newNode )
  2621. {
  2622. newNode.LODIndex = lodId;
  2623. newNode.ContainerGraph = this;
  2624. if( newNode.IsStubNode )
  2625. {
  2626. TemplateMultiPassMasterNode stubNode = newNode.ExecuteStubCode() as TemplateMultiPassMasterNode;
  2627. ScriptableObject.DestroyImmediate( newNode, true );
  2628. newNode = stubNode;
  2629. }
  2630. else
  2631. {
  2632. newNode.UniqueId = nodeId;
  2633. AddNode( newNode, nodeId < 0, addLast, registerUndo );
  2634. }
  2635. }
  2636. return newNode;
  2637. }
  2638. public ParentNode CreateNode( System.Type type, bool registerUndo, int nodeId = -1, bool addLast = true )
  2639. {
  2640. ParentNode newNode = ScriptableObject.CreateInstance( type ) as ParentNode;
  2641. if( newNode )
  2642. {
  2643. newNode.ContainerGraph = this;
  2644. if( newNode.IsStubNode )
  2645. {
  2646. ParentNode stubNode = newNode.ExecuteStubCode();
  2647. ScriptableObject.DestroyImmediate( newNode, true );
  2648. newNode = stubNode;
  2649. }
  2650. else
  2651. {
  2652. newNode.UniqueId = nodeId;
  2653. AddNode( newNode, nodeId < 0, addLast, registerUndo );
  2654. }
  2655. }
  2656. return newNode;
  2657. }
  2658. public ParentNode CreateNode( System.Type type, bool registerUndo, Vector2 pos, int nodeId = -1, bool addLast = true )
  2659. {
  2660. ParentNode newNode = CreateNode( type, registerUndo, nodeId, addLast );
  2661. if( newNode )
  2662. {
  2663. newNode.Vec2Position = pos;
  2664. }
  2665. return newNode;
  2666. }
  2667. public void FireMasterNodeReplacedEvent()
  2668. {
  2669. MasterNode masterNode = CurrentMasterNode;
  2670. int count = m_nodes.Count;
  2671. for( int i = 0; i < count; i++ )
  2672. {
  2673. if( m_nodes[ i ].UniqueId != m_masterNodeId )
  2674. {
  2675. m_nodes[ i ].OnMasterNodeReplaced( masterNode );
  2676. }
  2677. }
  2678. }
  2679. //Used over shader functions to propagate signal into their graphs
  2680. public void FireMasterNodeReplacedEvent( MasterNode masterNode )
  2681. {
  2682. int count = m_nodes.Count;
  2683. for( int i = 0; i < count; i++ )
  2684. {
  2685. if( m_nodes[ i ].UniqueId != masterNode.UniqueId )
  2686. {
  2687. m_nodes[ i ].OnMasterNodeReplaced( masterNode );
  2688. }
  2689. }
  2690. }
  2691. public void CrossCheckTemplateNodes( TemplateDataParent templateData , List<TemplateMultiPassMasterNode> mpNodesList , int lodId )
  2692. {
  2693. /*Paulo*/
  2694. DeSelectAll();
  2695. TemplateMultiPassMasterNode newMasterNode = null;
  2696. Dictionary<string, TemplateReplaceHelper> nodesDict = new Dictionary<string, TemplateReplaceHelper>();
  2697. int mpNodeCount = mpNodesList.Count;
  2698. for( int i = 0; i < mpNodeCount; i++ )
  2699. {
  2700. string masterNodeId = mpNodesList[ i ].InvalidNode ? mpNodesList[ i ].OriginalPassName + "ASEInvalidMasterNode" + i : mpNodesList[ i ].OriginalPassName;
  2701. nodesDict.Add( masterNodeId, new TemplateReplaceHelper( mpNodesList[ i ] ) );
  2702. }
  2703. TemplateMultiPassMasterNode currMasterNode = GetNode( m_masterNodeId ) as TemplateMultiPassMasterNode;
  2704. TemplateMultiPass multipassData = templateData as TemplateMultiPass;
  2705. m_currentSRPType = multipassData.SubShaders[ 0 ].Modules.SRPType;
  2706. bool sortTemplatesNodes = false;
  2707. Vector2 currentPosition = currMasterNode.Vec2Position;
  2708. for( int subShaderIdx = 0; subShaderIdx < multipassData.SubShaders.Count; subShaderIdx++ )
  2709. {
  2710. for( int passIdx = 0; passIdx < multipassData.SubShaders[ subShaderIdx ].Passes.Count; passIdx++ )
  2711. {
  2712. string currPassName = multipassData.SubShaders[ subShaderIdx ].Passes[ passIdx ].PassNameContainer.Data;
  2713. if( nodesDict.ContainsKey( currPassName ) )
  2714. {
  2715. bool wasMainNode = nodesDict[ currPassName ].MasterNode.IsMainOutputNode;
  2716. currentPosition.y += nodesDict[ currPassName ].MasterNode.Position.height + 10;
  2717. nodesDict[ currPassName ].Used = true;
  2718. nodesDict[ currPassName ].MasterNode.SetTemplate( multipassData, false, false, subShaderIdx, passIdx, SetTemplateSource.NewShader );
  2719. if( wasMainNode && !nodesDict[ currPassName ].MasterNode.IsMainOutputNode )
  2720. {
  2721. nodesDict[ currPassName ].MasterNode.ReleaseResources();
  2722. }
  2723. else if( !wasMainNode && nodesDict[ currPassName ].MasterNode.IsMainOutputNode )
  2724. {
  2725. newMasterNode = nodesDict[ currPassName ].MasterNode;
  2726. }
  2727. }
  2728. else
  2729. {
  2730. sortTemplatesNodes = true;
  2731. TemplateMultiPassMasterNode masterNode = CreateMultipassMasterNode( lodId, false );
  2732. if( multipassData.SubShaders[ subShaderIdx ].Passes[ passIdx ].IsMainPass )
  2733. {
  2734. newMasterNode = masterNode;
  2735. currMasterNode.ReleaseResources();
  2736. }
  2737. masterNode.Vec2Position = currentPosition;
  2738. masterNode.SetTemplate( multipassData, true, true, subShaderIdx, passIdx, SetTemplateSource.NewShader );
  2739. //currentPosition.y += masterNode.HeightEstimate + 10;
  2740. }
  2741. }
  2742. }
  2743. foreach( KeyValuePair<string, TemplateReplaceHelper> kvp in nodesDict )
  2744. {
  2745. if( !kvp.Value.Used )
  2746. DestroyNode( kvp.Value.MasterNode, false, true );
  2747. }
  2748. nodesDict.Clear();
  2749. if( newMasterNode != null )
  2750. {
  2751. if( lodId == -1 )
  2752. {
  2753. m_masterNodeId = newMasterNode.UniqueId;
  2754. }
  2755. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  2756. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  2757. newMasterNode.IsMainOutputNode = true;
  2758. }
  2759. if( sortTemplatesNodes )
  2760. {
  2761. mpNodesList.Sort( ( x, y ) => ( x.PassIdx.CompareTo( y.PassIdx ) ) );
  2762. }
  2763. }
  2764. public void OnRefreshLinkedPortsComplete()
  2765. {
  2766. OnRefreshLinkedPortsCompleteInternal( m_multiPassMasterNodes );
  2767. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  2768. {
  2769. OnRefreshLinkedPortsCompleteInternal( m_lodMultiPassMasterNodes[ i ] );
  2770. }
  2771. }
  2772. private void OnRefreshLinkedPortsCompleteInternal( UsageListTemplateMultiPassMasterNodes masterNodes )
  2773. {
  2774. int mpCount = masterNodes.Count;
  2775. for( int i = 0; i < mpCount; i++ )
  2776. {
  2777. masterNodes.NodesList[ i ].OnRefreshLinkedPortsComplete();
  2778. }
  2779. }
  2780. public void RefreshLinkedMasterNodes( bool optionsUpdate = false )
  2781. {
  2782. if( DebugConsoleWindow.DeveloperMode )
  2783. Debug.Log( "Refresh linked master nodes" );
  2784. RefreshLinkedMasterNodesInternal( m_multiPassMasterNodes, optionsUpdate );
  2785. for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  2786. {
  2787. RefreshLinkedMasterNodesInternal( m_lodMultiPassMasterNodes[i], optionsUpdate );
  2788. }
  2789. }
  2790. private void RefreshLinkedMasterNodesInternal( UsageListTemplateMultiPassMasterNodes masterNodes, bool optionsUpdate )
  2791. {
  2792. int mpCount = masterNodes.Count;
  2793. if( mpCount > 1 )
  2794. {
  2795. Dictionary<string, List<InputPort>> registeredLinks = new Dictionary<string, List<InputPort>>();
  2796. for( int i = 0; i < mpCount; i++ )
  2797. {
  2798. CheckLinkedPorts( ref registeredLinks, masterNodes.NodesList[ mpCount - 1 - i ] );
  2799. }
  2800. foreach( KeyValuePair<string, List<InputPort>> kvp in registeredLinks )
  2801. {
  2802. int linkCount = kvp.Value.Count;
  2803. if( linkCount == 1 )
  2804. {
  2805. kvp.Value[ 0 ].Visible = true;
  2806. }
  2807. else
  2808. {
  2809. kvp.Value[ 0 ].Visible = true;
  2810. for( int i = 1; i < linkCount; i++ )
  2811. {
  2812. kvp.Value[ i ].SetExternalLink( kvp.Value[ 0 ].NodeId, kvp.Value[ 0 ].PortId );
  2813. kvp.Value[ i ].Visible = false;
  2814. }
  2815. }
  2816. kvp.Value.Clear();
  2817. }
  2818. registeredLinks.Clear();
  2819. registeredLinks = null;
  2820. }
  2821. masterNodes.NodesList.Sort( ( x, y ) => ( x.SubShaderIdx * 1000 + x.PassIdx ).CompareTo( y.SubShaderIdx * 1000 + y.PassIdx ) );
  2822. masterNodes.UpdateNodeArr();
  2823. m_parentWindow.TemplatesManagerInstance.ResetOptionsSetupData();
  2824. for( int i = 0; i < mpCount; i++ )
  2825. {
  2826. int visiblePorts = 0;
  2827. for( int j = 0; j < masterNodes.NodesList[ i ].InputPorts.Count; j++ )
  2828. {
  2829. if( masterNodes.NodesList[ i ].InputPorts[ j ].Visible )
  2830. {
  2831. visiblePorts++;
  2832. }
  2833. }
  2834. if( masterNodes.NodesList[ i ].VisiblePorts != visiblePorts )
  2835. {
  2836. masterNodes.NodesList[ i ].VisiblePorts = visiblePorts;
  2837. ForceRepositionCheck = true;
  2838. }
  2839. masterNodes.NodesList[ i ].Docking = visiblePorts <= 0;
  2840. if( optionsUpdate )
  2841. {
  2842. masterNodes.NodesList[ i ].ForceOptionsRefresh();
  2843. }
  2844. }
  2845. }
  2846. void CheckLinkedPorts( ref Dictionary<string, List<InputPort>> registeredLinks, TemplateMultiPassMasterNode masterNode )
  2847. {
  2848. if( masterNode.HasLinkPorts )
  2849. {
  2850. int inputCount = masterNode.InputPorts.Count;
  2851. for( int i = 0; i < inputCount; i++ )
  2852. {
  2853. if( !string.IsNullOrEmpty( masterNode.InputPorts[ i ].ExternalLinkId ) )
  2854. {
  2855. string linkId = masterNode.InputPorts[ i ].ExternalLinkId;
  2856. if( !registeredLinks.ContainsKey( masterNode.InputPorts[ i ].ExternalLinkId ) )
  2857. {
  2858. registeredLinks.Add( linkId, new List<InputPort>() );
  2859. }
  2860. if( masterNode.IsMainOutputNode )
  2861. {
  2862. registeredLinks[ linkId ].Insert( 0, masterNode.InputPorts[ i ] );
  2863. }
  2864. else
  2865. {
  2866. registeredLinks[ linkId ].Add( masterNode.InputPorts[ i ] );
  2867. }
  2868. }
  2869. else
  2870. {
  2871. masterNode.InputPorts[ i ].Visible = true;
  2872. }
  2873. }
  2874. }
  2875. else
  2876. {
  2877. int inputCount = masterNode.InputPorts.Count;
  2878. for( int i = 0; i < inputCount; i++ )
  2879. {
  2880. masterNode.InputPorts[ i ].Visible = true;
  2881. }
  2882. }
  2883. }
  2884. public MasterNode ReplaceMasterNode( AvailableShaderTypes newType, bool writeDefaultData = false, TemplateDataParent templateData = null )
  2885. {
  2886. DeSelectAll();
  2887. ResetNodeConnStatus();
  2888. MasterNode newMasterNode = null;
  2889. List<TemplateMultiPassMasterNode> nodesToDelete = null;
  2890. int mpNodeCount = m_multiPassMasterNodes.NodesList.Count;
  2891. if( mpNodeCount > 0 )
  2892. {
  2893. nodesToDelete = new List<TemplateMultiPassMasterNode>();
  2894. for( int i = 0; i < mpNodeCount; i++ )
  2895. {
  2896. if( m_multiPassMasterNodes.NodesList[ i ].UniqueId != m_masterNodeId )
  2897. {
  2898. nodesToDelete.Add( m_multiPassMasterNodes.NodesList[ i ] );
  2899. }
  2900. }
  2901. for( int lod = 0; lod < m_lodMultiPassMasterNodes.Count; lod++ )
  2902. {
  2903. int lodNodeCount = m_lodMultiPassMasterNodes[ lod ].Count;
  2904. for( int i = 0; i < lodNodeCount; i++ )
  2905. {
  2906. nodesToDelete.Add( m_lodMultiPassMasterNodes[ lod ].NodesList[ i ] );
  2907. }
  2908. }
  2909. }
  2910. MasterNode currMasterNode = GetNode( m_masterNodeId ) as MasterNode;
  2911. if( currMasterNode != null )
  2912. {
  2913. currMasterNode.ReleaseResources();
  2914. }
  2915. bool refreshLinkedMasterNodes = false;
  2916. switch( newType )
  2917. {
  2918. default:
  2919. case AvailableShaderTypes.SurfaceShader:
  2920. {
  2921. CurrentCanvasMode = NodeAvailability.SurfaceShader;
  2922. m_currentSRPType = TemplateSRPType.BiRP;
  2923. newMasterNode = CreateNode( typeof( StandardSurfaceOutputNode ), false ) as MasterNode;
  2924. }
  2925. break;
  2926. case AvailableShaderTypes.Template:
  2927. {
  2928. CurrentCanvasMode = NodeAvailability.TemplateShader;
  2929. if( templateData.TemplateType == TemplateDataType.LegacySinglePass )
  2930. {
  2931. newMasterNode = CreateNode( typeof( TemplateMasterNode ), false ) as MasterNode;
  2932. ( newMasterNode as TemplateMasterNode ).SetTemplate( templateData as TemplateData, writeDefaultData, false );
  2933. m_currentSRPType = TemplateSRPType.BiRP;
  2934. }
  2935. else
  2936. {
  2937. /*Paulo*/
  2938. TemplateMultiPass multipassData = templateData as TemplateMultiPass;
  2939. m_currentSRPType = multipassData.SubShaders[ 0 ].Modules.SRPType;
  2940. Vector2 currentPosition = currMasterNode.Vec2Position;
  2941. for( int subShaderIdx = 0; subShaderIdx < multipassData.SubShaders.Count; subShaderIdx++ )
  2942. {
  2943. for( int passIdx = 0; passIdx < multipassData.SubShaders[ subShaderIdx ].Passes.Count; passIdx++ )
  2944. {
  2945. TemplateMultiPassMasterNode masterNode = CreateNode( typeof( TemplateMultiPassMasterNode ), false ) as TemplateMultiPassMasterNode;
  2946. if( multipassData.SubShaders[ subShaderIdx ].Passes[ passIdx ].IsMainPass )
  2947. {
  2948. newMasterNode = masterNode;
  2949. ParentWindow.IsShaderFunctionWindow = false;
  2950. CurrentCanvasMode = NodeAvailability.TemplateShader;
  2951. }
  2952. masterNode.Vec2Position = currentPosition;
  2953. masterNode.SetTemplate( multipassData, true, true, subShaderIdx, passIdx, SetTemplateSource.NewShader );
  2954. //currentPosition.y += masterNode.HeightEstimate + 10;
  2955. }
  2956. }
  2957. refreshLinkedMasterNodes = true;
  2958. //RefreshLinkedMasterNodes();
  2959. }
  2960. }
  2961. break;
  2962. }
  2963. if( currMasterNode != null )
  2964. {
  2965. newMasterNode.CopyFrom( currMasterNode );
  2966. m_masterNodeId = -1;
  2967. DestroyNode( currMasterNode, false, true );
  2968. }
  2969. if( nodesToDelete != null )
  2970. {
  2971. for( int i = 0; i < nodesToDelete.Count; i++ )
  2972. {
  2973. DestroyNode( nodesToDelete[ i ], false, true );
  2974. }
  2975. nodesToDelete.Clear();
  2976. }
  2977. m_masterNodeId = newMasterNode.UniqueId;
  2978. if( refreshLinkedMasterNodes )
  2979. RefreshLinkedMasterNodes( true );
  2980. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  2981. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  2982. newMasterNode.IsMainOutputNode = true;
  2983. OnRefreshLinkedPortsComplete();
  2984. FullCleanUndoStack();
  2985. return newMasterNode;
  2986. }
  2987. private void RepositionTemplateNodes( MasterNode newMasterNode )
  2988. {
  2989. m_forceRepositionCheck = false;
  2990. int dockedElementsBefore = 0;
  2991. int dockedElementsAfter = 0;
  2992. int masterIndex = 0;
  2993. bool foundMaster = false;
  2994. for( int i = 0; i < MultiPassMasterNodes.Count; i++ )
  2995. {
  2996. if( MultiPassMasterNodes.NodesList[ i ].UniqueId == m_masterNodeId )
  2997. {
  2998. foundMaster = true;
  2999. masterIndex = i;
  3000. }
  3001. if( !MultiPassMasterNodes.NodesList[ i ].IsInvisible && MultiPassMasterNodes.NodesList[ i ].Docking )
  3002. {
  3003. if( foundMaster )
  3004. dockedElementsAfter++;
  3005. else
  3006. dockedElementsBefore++;
  3007. }
  3008. }
  3009. if( dockedElementsBefore > 0 )
  3010. {
  3011. newMasterNode.UseSquareNodeTitle = true;
  3012. }
  3013. for( int i = masterIndex - 1; i >= 0; i-- )
  3014. {
  3015. float forwardTracking = 0;
  3016. for( int j = i + 1; j <= masterIndex; j++ )
  3017. {
  3018. if( !MultiPassMasterNodes.NodesList[ i ].IsInvisible && !MultiPassMasterNodes.NodesList[ j ].Docking )
  3019. {
  3020. forwardTracking += MultiPassMasterNodes.NodesList[ j ].HeightEstimate + 10;
  3021. }
  3022. }
  3023. MasterNode node = MultiPassMasterNodes.NodesList[ i ];
  3024. node.Vec2Position = new Vector2( node.Vec2Position.x, newMasterNode.Position.y - forwardTracking - 33 * ( dockedElementsBefore ) );
  3025. }
  3026. for( int i = masterIndex + 1; i < MultiPassMasterNodes.Count; i++ )
  3027. {
  3028. if( MultiPassMasterNodes.NodesList[ i ].UniqueId == newMasterNode.UniqueId || MultiPassMasterNodes.NodesList[ i ].Docking )
  3029. continue;
  3030. float backTracking = 0;
  3031. for( int j = i - 1; j >= masterIndex; j-- )
  3032. {
  3033. if( !MultiPassMasterNodes.NodesList[ i ].IsInvisible && !MultiPassMasterNodes.NodesList[ j ].Docking )
  3034. {
  3035. backTracking += MultiPassMasterNodes.NodesList[ j ].HeightEstimate + 10;
  3036. }
  3037. }
  3038. MasterNode node = MultiPassMasterNodes.NodesList[ i ];
  3039. node.Vec2Position = new Vector2( node.Vec2Position.x, newMasterNode.Position.y + backTracking + 33 * ( dockedElementsAfter ) );
  3040. }
  3041. }
  3042. public void CreateNewEmpty( string name )
  3043. {
  3044. CleanNodes();
  3045. if( m_masterNodeDefaultType == null )
  3046. m_masterNodeDefaultType = typeof( StandardSurfaceOutputNode );
  3047. MasterNode newMasterNode = CreateNode( m_masterNodeDefaultType, false ) as MasterNode;
  3048. newMasterNode.SetName( name );
  3049. m_masterNodeId = newMasterNode.UniqueId;
  3050. ParentWindow.IsShaderFunctionWindow = false;
  3051. CurrentCanvasMode = NodeAvailability.SurfaceShader;
  3052. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  3053. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  3054. newMasterNode.IsMainOutputNode = true;
  3055. LoadedShaderVersion = VersionInfo.FullNumber;
  3056. }
  3057. public void CreateNewEmptyTemplate( string templateGUID )
  3058. {
  3059. CleanNodes();
  3060. TemplateDataParent templateData = m_parentWindow.TemplatesManagerInstance.GetTemplate( templateGUID );
  3061. if( templateData.TemplateType == TemplateDataType.LegacySinglePass )
  3062. {
  3063. TemplateMasterNode newMasterNode = CreateNode( typeof( TemplateMasterNode ), false ) as TemplateMasterNode;
  3064. m_masterNodeId = newMasterNode.UniqueId;
  3065. ParentWindow.IsShaderFunctionWindow = false;
  3066. CurrentCanvasMode = NodeAvailability.TemplateShader;
  3067. m_currentSRPType = TemplateSRPType.BiRP;
  3068. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  3069. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  3070. newMasterNode.IsMainOutputNode = true;
  3071. newMasterNode.SetTemplate( templateData as TemplateData, true, true );
  3072. }
  3073. else
  3074. {
  3075. /*Paulo*/
  3076. TemplateMultiPass multipassData = templateData as TemplateMultiPass;
  3077. m_currentSRPType = multipassData.SubShaders[ 0 ].Modules.SRPType;
  3078. Vector2 currentPosition = Vector2.zero;
  3079. for( int subShaderIdx = 0; subShaderIdx < multipassData.SubShaders.Count; subShaderIdx++ )
  3080. {
  3081. for( int passIdx = 0; passIdx < multipassData.SubShaders[ subShaderIdx ].Passes.Count; passIdx++ )
  3082. {
  3083. TemplateMultiPassMasterNode newMasterNode = CreateNode( typeof( TemplateMultiPassMasterNode ), false ) as TemplateMultiPassMasterNode;
  3084. if( multipassData.SubShaders[ subShaderIdx ].Passes[ passIdx ].IsMainPass )
  3085. {
  3086. m_masterNodeId = newMasterNode.UniqueId;
  3087. ParentWindow.IsShaderFunctionWindow = false;
  3088. CurrentCanvasMode = NodeAvailability.TemplateShader;
  3089. newMasterNode.OnMaterialUpdatedEvent += OnMaterialUpdatedEvent;
  3090. newMasterNode.OnShaderUpdatedEvent += OnShaderUpdatedEvent;
  3091. newMasterNode.IsMainOutputNode = true;
  3092. }
  3093. newMasterNode.Vec2Position = currentPosition;
  3094. newMasterNode.SetTemplate( multipassData, true, true, subShaderIdx, passIdx, SetTemplateSource.NewShader );
  3095. //currentPosition.y += newMasterNode.HeightEstimate + 10;
  3096. }
  3097. }
  3098. RefreshLinkedMasterNodes( false );
  3099. OnRefreshLinkedPortsComplete();
  3100. }
  3101. LoadedShaderVersion = VersionInfo.FullNumber;
  3102. }
  3103. public void CreateNewEmptyFunction( AmplifyShaderFunction shaderFunction )
  3104. {
  3105. CleanNodes();
  3106. FunctionOutput newOutputNode = CreateNode( typeof( FunctionOutput ), false ) as FunctionOutput;
  3107. m_masterNodeId = newOutputNode.UniqueId;
  3108. ParentWindow.IsShaderFunctionWindow = true;
  3109. CurrentCanvasMode = NodeAvailability.ShaderFunction;
  3110. newOutputNode.IsMainOutputNode = true;
  3111. }
  3112. public void ForceCategoryRefresh() { m_forceCategoryRefresh = true; }
  3113. public void RefreshExternalReferences()
  3114. {
  3115. int count = m_nodes.Count;
  3116. for( int i = 0; i < count; i++ )
  3117. {
  3118. m_nodes[ i ].RefreshExternalReferences();
  3119. }
  3120. }
  3121. public Vector2 SelectedNodesCentroid
  3122. {
  3123. get
  3124. {
  3125. if( m_selectedNodes.Count == 0 )
  3126. return Vector2.zero;
  3127. Vector2 pos = new Vector2( 0, 0 );
  3128. for( int i = 0; i < m_selectedNodes.Count; i++ )
  3129. {
  3130. pos += m_selectedNodes[ i ].Vec2Position;
  3131. }
  3132. pos /= m_selectedNodes.Count;
  3133. return pos;
  3134. }
  3135. }
  3136. public void AddVirtualTextureCount()
  3137. {
  3138. m_virtualTextureCount += 1;
  3139. }
  3140. public void RemoveVirtualTextureCount()
  3141. {
  3142. m_virtualTextureCount -= 1;
  3143. if( m_virtualTextureCount < 0 )
  3144. {
  3145. Debug.LogWarning( "Invalid virtual texture count" );
  3146. }
  3147. }
  3148. public bool HasVirtualTexture { get { return m_virtualTextureCount > 0; } }
  3149. public void AddInstancePropertyCount()
  3150. {
  3151. m_instancePropertyCount += 1;
  3152. // Debug.Log( "AddInstancePropertyCount "+this.GetInstanceID() + " " + m_instancePropertyCount );
  3153. }
  3154. public void RemoveInstancePropertyCount()
  3155. {
  3156. m_instancePropertyCount -= 1;
  3157. // Debug.Log( "RemoveInstancePropertyCount " + this.GetInstanceID() + " " + m_instancePropertyCount );
  3158. if( m_instancePropertyCount < 0 )
  3159. {
  3160. Debug.LogWarning( "Invalid property instance count" );
  3161. }
  3162. }
  3163. public int InstancePropertyCount { get { return m_instancePropertyCount; } set { m_instancePropertyCount = value; } }
  3164. public bool IsInstancedShader { get { return m_instancePropertyCount > 0; } }
  3165. public void AddNormalDependentCount() { m_normalDependentCount += 1; }
  3166. public void RemoveNormalDependentCount()
  3167. {
  3168. m_normalDependentCount -= 1;
  3169. if( m_normalDependentCount < 0 )
  3170. {
  3171. Debug.LogWarning( "Invalid normal dependentCount count" );
  3172. }
  3173. }
  3174. public void SetModeFromMasterNode()
  3175. {
  3176. MasterNode masterNode = CurrentMasterNode;
  3177. if( masterNode != null )
  3178. {
  3179. switch( masterNode.CurrentMasterNodeCategory )
  3180. {
  3181. default:
  3182. case AvailableShaderTypes.SurfaceShader:
  3183. {
  3184. if( masterNode is StandardSurfaceOutputNode )
  3185. CurrentCanvasMode = ParentWindow.CurrentNodeAvailability;
  3186. else
  3187. CurrentCanvasMode = NodeAvailability.SurfaceShader;
  3188. }
  3189. break;
  3190. case AvailableShaderTypes.Template:
  3191. {
  3192. CurrentCanvasMode = NodeAvailability.TemplateShader;
  3193. }
  3194. break;
  3195. }
  3196. }
  3197. else
  3198. {
  3199. CurrentCanvasMode = NodeAvailability.SurfaceShader;
  3200. }
  3201. }
  3202. public void MarkToDelete( ParentNode node )
  3203. {
  3204. m_markedForDeletion.Add( node );
  3205. }
  3206. public bool IsMasterNode( ParentNode node )
  3207. {
  3208. return ( node.UniqueId == m_masterNodeId ) ||
  3209. m_multiPassMasterNodes.HasNode( node.UniqueId );
  3210. }
  3211. public TemplateMultiPassMasterNode GetMainMasterNodeOfLOD( int lod )
  3212. {
  3213. if( lod == -1 )
  3214. return CurrentMasterNode as TemplateMultiPassMasterNode;
  3215. return m_lodMultiPassMasterNodes[ lod ].NodesList.Find( x => x.IsMainOutputNode );
  3216. }
  3217. public TemplateMultiPassMasterNode GetMasterNodeOfPass( string passName, int lod )
  3218. {
  3219. if( lod == -1 )
  3220. return m_multiPassMasterNodes.NodesList.Find( x => x.PassName.Equals( passName ) );
  3221. return m_lodMultiPassMasterNodes[lod].NodesList.Find( x => x.PassName.Equals( passName ) );
  3222. }
  3223. public void ForceMultiPassMasterNodesRefresh()
  3224. {
  3225. int mainOutputId = 0;
  3226. int count = m_multiPassMasterNodes.Count;
  3227. for( int i = 0; i < count; i++ )
  3228. {
  3229. m_multiPassMasterNodes.NodesList[ i ].ForceTemplateRefresh();
  3230. if( m_multiPassMasterNodes.NodesList[ i ].IsMainOutputNode )
  3231. mainOutputId = i;
  3232. }
  3233. int lodCount = m_lodMultiPassMasterNodes.Count;
  3234. for( int i = 0; i < lodCount; i++ )
  3235. {
  3236. if( m_lodMultiPassMasterNodes[ i ] != null )
  3237. {
  3238. count = m_lodMultiPassMasterNodes[ i ].Count;
  3239. for( int j = 0; j < count; j++ )
  3240. {
  3241. m_lodMultiPassMasterNodes[ i ].NodesList[ j ].ForceTemplateRefresh();
  3242. }
  3243. }
  3244. }
  3245. m_multiPassMasterNodes.NodesList[ mainOutputId ].CheckTemplateChanges();
  3246. }
  3247. public void SetLateOptionsRefresh()
  3248. {
  3249. m_lateOptionsRefresh = true;
  3250. }
  3251. public void CreateLodMasterNodes( TemplateMultiPass templateMultiPass,int index, Vector2 initialPosition )
  3252. {
  3253. for( int lod = 0; lod < m_lodMultiPassMasterNodes.Count; lod++ )
  3254. {
  3255. if( m_lodMultiPassMasterNodes[ lod ].Count == 0 )
  3256. {
  3257. TemplateMultiPassMasterNode reference = CurrentMasterNode as TemplateMultiPassMasterNode;
  3258. int shaderLod = -1;
  3259. if( lod == 0 )
  3260. {
  3261. shaderLod = reference.ShaderLOD - MasterNodeLODIncrement;
  3262. }
  3263. else
  3264. {
  3265. //index == -2 is when user clicks on +/- buttons over the foldout UI
  3266. if( index == -2 )
  3267. {
  3268. shaderLod = m_lodMultiPassMasterNodes[ lod - 1 ].NodesList[ reference.PassIdx ].ShaderLOD - MasterNodeLODIncrement;
  3269. }
  3270. //index == -1 is when user clicks on + button over the main lod master node
  3271. else if( index == -1 )
  3272. {
  3273. int mainShaderLOD = m_lodMultiPassMasterNodes[ 0 ].NodesList[ reference.PassIdx ].ShaderLOD;
  3274. shaderLod = ( reference.ShaderLOD + mainShaderLOD )/2;
  3275. }
  3276. else
  3277. {
  3278. if( m_lodMultiPassMasterNodes[ index ].Count > 0 )
  3279. {
  3280. if( m_lodMultiPassMasterNodes[ index + 1 ].Count > 0 )
  3281. {
  3282. shaderLod = (m_lodMultiPassMasterNodes[ index ].NodesList[ reference.PassIdx ].ShaderLOD +
  3283. m_lodMultiPassMasterNodes[ index + 1 ].NodesList[ reference.PassIdx ].ShaderLOD )/2;
  3284. }
  3285. else
  3286. {
  3287. shaderLod = m_lodMultiPassMasterNodes[ index ].NodesList[ reference.PassIdx ].ShaderLOD - MasterNodeLODIncrement;
  3288. }
  3289. }
  3290. }
  3291. }
  3292. int nodeId = 0;
  3293. TemplateMultiPassMasterNode mainMasterNode = null;
  3294. for( int subShaderIdx = 0; subShaderIdx < templateMultiPass.SubShaders.Count; subShaderIdx++ )
  3295. {
  3296. for( int passIdx = 0; passIdx < templateMultiPass.SubShaders[ subShaderIdx ].Passes.Count; passIdx++ )
  3297. {
  3298. TemplateMultiPassMasterNode masterNode = ScriptableObject.CreateInstance( typeof( TemplateMultiPassMasterNode ) ) as TemplateMultiPassMasterNode;
  3299. masterNode.LODIndex = lod;
  3300. masterNode.ContainerGraph = this;
  3301. masterNode.Vec2Position = initialPosition;
  3302. AddNode( masterNode, true );
  3303. masterNode.SetTemplate( templateMultiPass, true, true, subShaderIdx, passIdx, SetTemplateSource.NewShader );
  3304. masterNode.CopyOptionsFrom( m_multiPassMasterNodes.NodesList[ nodeId++ ] );
  3305. if( masterNode.IsMainOutputNode || ( subShaderIdx == 0 && passIdx == 0 ) )
  3306. {
  3307. masterNode.SetShaderLODValueAndLabel( shaderLod );
  3308. mainMasterNode = masterNode;
  3309. }
  3310. }
  3311. }
  3312. mainMasterNode.ForceOptionsRefresh();
  3313. SortLODMasterNodes();
  3314. if( OnLODMasterNodesAddedEvent != null )
  3315. {
  3316. OnLODMasterNodesAddedEvent( lod );
  3317. }
  3318. TemplateMultiPassMasterNode lodMainMasterNode = CurrentMasterNode as TemplateMultiPassMasterNode;
  3319. lodMainMasterNode.SetShaderLODValueAndLabel( lodMainMasterNode.ShaderLOD );
  3320. return;
  3321. }
  3322. }
  3323. }
  3324. public void DestroyLodMasterNodes( int index )
  3325. {
  3326. if( index < 0 )
  3327. {
  3328. for( int lod = m_lodMultiPassMasterNodes.Count - 1; lod >= 0; lod-- )
  3329. {
  3330. if( m_lodMultiPassMasterNodes[ lod ].Count > 0 )
  3331. {
  3332. while( m_lodMultiPassMasterNodes[ lod ].Count > 0 )
  3333. {
  3334. DestroyNode( m_lodMultiPassMasterNodes[ lod ].NodesList[ 0 ], false, true );
  3335. }
  3336. break;
  3337. }
  3338. }
  3339. }
  3340. else
  3341. {
  3342. while( m_lodMultiPassMasterNodes[ index ].Count > 0 )
  3343. {
  3344. DestroyNode( m_lodMultiPassMasterNodes[ index ].NodesList[ 0 ], false, true );
  3345. }
  3346. }
  3347. SortLODMasterNodes();
  3348. TemplateMultiPassMasterNode lodMainMasterNode = CurrentMasterNode as TemplateMultiPassMasterNode;
  3349. lodMainMasterNode.SetShaderLODValueAndLabel( lodMainMasterNode.ShaderLOD );
  3350. }
  3351. public void SortLODMasterNodes()
  3352. {
  3353. int idx = (CurrentMasterNode as TemplateMultiPassMasterNode).PassIdx;
  3354. m_lodMultiPassMasterNodes.Sort( ( x, y ) =>
  3355. {
  3356. if( x.Count > 0 )
  3357. {
  3358. if( y.Count > 0 )
  3359. {
  3360. return -x.NodesList[ idx ].ShaderLOD.CompareTo( y.NodesList[ idx ].ShaderLOD );
  3361. }
  3362. else
  3363. {
  3364. return -1;
  3365. }
  3366. }
  3367. else
  3368. {
  3369. if( y.Count > 0 )
  3370. {
  3371. return 1;
  3372. }
  3373. }
  3374. return 0;
  3375. });
  3376. for( int lodIdx = 0; lodIdx < m_lodMultiPassMasterNodes.Count; lodIdx++ )
  3377. {
  3378. for( int nodeIdx = 0; nodeIdx < m_lodMultiPassMasterNodes[ lodIdx ].Count; nodeIdx++ )
  3379. {
  3380. m_lodMultiPassMasterNodes[ lodIdx ].NodesList[ nodeIdx ].LODIndex = lodIdx;
  3381. }
  3382. }
  3383. }
  3384. public List<TemplateMultiPassMasterNode> GetMultiPassMasterNodes( int lod )
  3385. {
  3386. if( lod == -1 )
  3387. return m_multiPassMasterNodes.NodesList;
  3388. return m_lodMultiPassMasterNodes[ lod ].NodesList;
  3389. }
  3390. public bool IsNormalDependent { get { return m_normalDependentCount > 0; } }
  3391. public void MarkToDeselect() { m_markedToDeSelect = true; }
  3392. public void MarkToSelect( int nodeId ) { m_markToSelect = nodeId; }
  3393. public void MarkWireHighlights() { m_checkSelectedWireHighlights = true; }
  3394. public List<ParentNode> SelectedNodes { get { return m_selectedNodes; } }
  3395. public List<ParentNode> MarkedForDeletionNodes { get { return m_markedForDeletion; } }
  3396. public int CurrentMasterNodeId { get { return m_masterNodeId; } set { m_masterNodeId = value; } }
  3397. public Shader CurrentShader
  3398. {
  3399. get
  3400. {
  3401. MasterNode masterNode = GetNode( m_masterNodeId ) as MasterNode;
  3402. if( masterNode != null )
  3403. return masterNode.CurrentShader;
  3404. return null;
  3405. }
  3406. }
  3407. public Material CurrentMaterial
  3408. {
  3409. get
  3410. {
  3411. MasterNode masterNode = GetNode( m_masterNodeId ) as MasterNode;
  3412. if( masterNode != null )
  3413. return masterNode.CurrentMaterial;
  3414. return null;
  3415. }
  3416. }
  3417. public NodeAvailability CurrentCanvasMode { get { return m_currentCanvasMode; } set { m_currentCanvasMode = value; ParentWindow.LateRefreshAvailableNodes(); } }
  3418. public OutputNode CurrentOutputNode { get { return GetNode( m_masterNodeId ) as OutputNode; } }
  3419. public FunctionOutput CurrentFunctionOutput { get { return GetNode( m_masterNodeId ) as FunctionOutput; } }
  3420. public MasterNode CurrentMasterNode { get { return GetNode( m_masterNodeId ) as MasterNode; } }
  3421. public StandardSurfaceOutputNode CurrentStandardSurface { get { return GetNode( m_masterNodeId ) as StandardSurfaceOutputNode; } }
  3422. public List<ParentNode> AllNodes { get { return m_nodes; } }
  3423. public int NodeCount { get { return m_nodes.Count; } }
  3424. //public List<ParentNode> VisibleNodes { get { return m_visibleNodes; } }
  3425. public int NodeClicked
  3426. {
  3427. set { m_nodeClicked = value; }
  3428. get { return m_nodeClicked; }
  3429. }
  3430. public bool IsDirty
  3431. {
  3432. set { m_isDirty = value && UIUtils.DirtyMask; }
  3433. get
  3434. {
  3435. bool value = m_isDirty;
  3436. m_isDirty = false;
  3437. return value;
  3438. }
  3439. }
  3440. public bool SaveIsDirty
  3441. {
  3442. set { m_saveIsDirty = value && UIUtils.DirtyMask; }
  3443. get { return m_saveIsDirty; }
  3444. }
  3445. public int LoadedShaderVersion
  3446. {
  3447. get { return m_loadedShaderVersion; }
  3448. set { m_loadedShaderVersion = value; }
  3449. }
  3450. public AmplifyShaderFunction CurrentShaderFunction
  3451. {
  3452. get { if( CurrentFunctionOutput != null ) return CurrentFunctionOutput.Function; else return null; }
  3453. set { if( CurrentFunctionOutput != null ) CurrentFunctionOutput.Function = value; }
  3454. }
  3455. public bool HasUnConnectedNodes { get { return m_hasUnConnectedNodes; } }
  3456. public UsageListSamplerNodes SamplerNodes { get { return m_samplerNodes; } }
  3457. public UsageListFloatIntNodes FloatIntNodes { get { return m_floatNodes; } }
  3458. public UsageListTexturePropertyNodes TexturePropertyNodes { get { return m_texturePropertyNodes; } }
  3459. public UsageListTextureArrayNodes TextureArrayNodes { get { return m_textureArrayNodes; } }
  3460. public UsageListPropertyNodes PropertyNodes { get { return m_propertyNodes; } }
  3461. public UsageListPropertyNodes RawPropertyNodes { get { return m_rawPropertyNodes; } }
  3462. public UsageListCustomExpressionsOnFunctionMode CustomExpressionOnFunctionMode { get { return m_customExpressionsOnFunctionMode; } }
  3463. public UsageListStaticSwitchNodes StaticSwitchNodes { get { return m_staticSwitchNodes; } }
  3464. public UsageListScreenColorNodes ScreenColorNodes { get { return m_screenColorNodes; } }
  3465. public UsageListRegisterLocalVarNodes LocalVarNodes { get { return m_localVarNodes; } }
  3466. public UsageListGlobalArrayNodes GlobalArrayNodes { get { return m_globalArrayNodes; } }
  3467. public UsageListFunctionInputNodes FunctionInputNodes { get { return m_functionInputNodes; } }
  3468. public UsageListFunctionNodes FunctionNodes { get { return m_functionNodes; } }
  3469. public UsageListFunctionOutputNodes FunctionOutputNodes { get { return m_functionOutputNodes; } }
  3470. public UsageListFunctionSwitchNodes FunctionSwitchNodes { get { return m_functionSwitchNodes; } }
  3471. public UsageListFunctionSwitchCopyNodes FunctionSwitchCopyNodes { get { return m_functionSwitchCopyNodes; } }
  3472. public UsageListTemplateMultiPassMasterNodes MultiPassMasterNodes { get { return m_multiPassMasterNodes; } set { m_multiPassMasterNodes = value; } }
  3473. public List<UsageListTemplateMultiPassMasterNodes> LodMultiPassMasternodes { get { return m_lodMultiPassMasterNodes; } }
  3474. public PrecisionType CurrentPrecision
  3475. {
  3476. get { return m_currentPrecision; }
  3477. set { m_currentPrecision = value; }
  3478. }
  3479. public NodeLOD LodLevel
  3480. {
  3481. get { return m_lodLevel; }
  3482. }
  3483. public List<ParentNode> NodePreviewList { get { return m_nodePreviewList; } set { m_nodePreviewList = value; } }
  3484. public void SetGraphId( int id )
  3485. {
  3486. m_graphId = id;
  3487. }
  3488. public int GraphId
  3489. {
  3490. get { return m_graphId; }
  3491. }
  3492. public AmplifyShaderEditorWindow ParentWindow
  3493. {
  3494. get { return m_parentWindow; }
  3495. set { m_parentWindow = value; }
  3496. }
  3497. public bool ChangedLightingModel
  3498. {
  3499. get { return m_changedLightingModel; }
  3500. set { m_changedLightingModel = value; }
  3501. }
  3502. public bool ForceRepositionCheck
  3503. {
  3504. get { return m_forceRepositionCheck; }
  3505. set { m_forceRepositionCheck = value; }
  3506. }
  3507. public bool IsLoading { get { return m_isLoading; } set { m_isLoading = value; } }
  3508. public bool IsDuplicating { get { return m_isDuplicating; } set { m_isDuplicating = value; } }
  3509. public TemplateSRPType CurrentSRPType { get { return m_currentSRPType; }set { m_currentSRPType = value; } }
  3510. public bool IsSRP { get { return m_currentSRPType == TemplateSRPType.URP || m_currentSRPType == TemplateSRPType.HDRP; } }
  3511. public bool IsHDRP { get { return m_currentSRPType == TemplateSRPType.HDRP; } }
  3512. public bool IsLWRP { get { return m_currentSRPType == TemplateSRPType.URP; } }
  3513. public bool IsStandardSurface { get { return GetNode( m_masterNodeId ) is StandardSurfaceOutputNode; } }
  3514. public bool SamplingMacros {
  3515. get { return m_samplingThroughMacros; }
  3516. set { m_samplingThroughMacros = value; }
  3517. }
  3518. public bool HasLODs { get { return m_lodMultiPassMasterNodes[ 0 ].Count > 0; } }
  3519. //public bool HasLodMultiPassNodes
  3520. //{
  3521. // get
  3522. // {
  3523. // for( int i = 0; i < m_lodMultiPassMasterNodes.Count; i++ )
  3524. // {
  3525. // if( m_lodMultiPassMasterNodes[ i ].Count > 0 )
  3526. // return true;
  3527. // }
  3528. // return false;
  3529. // }
  3530. //}
  3531. }
  3532. }