| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918 | 
							- // Amplify Shader Editor - Visual Shader Editing Tool
 
- // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using UnityEditor;
 
- using UnityEngine;
 
- namespace AmplifyShaderEditor
 
- {
 
- 	public enum PreviewLocation
 
- 	{
 
- 		Auto,
 
- 		TopCenter,
 
- 		BottomCenter,
 
- 		Left,
 
- 		Right
 
- 	}
 
- 	public enum NodeMessageType
 
- 	{
 
- 		Error,
 
- 		Warning,
 
- 		Info
 
- 	}
 
- 	[Serializable]
 
- 	public class ParentNode : UndoParentNode, ISerializationCallbackReceiver
 
- 	{
 
- 		protected readonly string[] PrecisionLabels = { "Float", "Half" };
 
- 		protected readonly string[] PrecisionLabelsExtra = { "Float", "Half", "Inherit" };
 
- 		private const double NodeClickTime = 0.2;
 
- 		protected GUIContent PrecisionContent = new GUIContent( "Precision", "Changes the precision of internal calculations, using lower types saves some performance\nDefault: Float" );
 
- 		private const int MoveCountBuffer = 3;// When testing for stopped movement we need to take Layout and Repaint into account for them not to interfere with tests
 
- 		private const float MinInsideBoxWidth = 20;
 
- 		private const float MinInsideBoxHeight = 10;
 
- 		private const string WikiLinkStr = "online reference";
 
- 		public delegate void OnNodeEvent( ParentNode node, bool testOnlySelected, InteractionMode interactionMode );
 
- 		public delegate void OnNodeGenericEvent( ParentNode node );
 
- 		public delegate void OnNodeReOrder( ParentNode node, int index );
 
- 		public delegate void DrawPropertySection();
 
- 		public delegate void OnSRPAction( int outputId, ref MasterNodeDataCollector dataCollector );
 
- 		[SerializeField]
 
- 		protected PrecisionType m_currentPrecisionType = PrecisionType.Inherit;
 
- 		[SerializeField]
 
- 		protected bool m_customPrecision = false;
 
- 		[SerializeField]
 
- 		protected InteractionMode m_defaultInteractionMode = InteractionMode.Other;
 
- 		public event OnNodeEvent OnNodeStoppedMovingEvent;
 
- 		public OnNodeGenericEvent OnNodeChangeSizeEvent;
 
- 		public OnNodeGenericEvent OnNodeDestroyedEvent;
 
- 		public event OnNodeReOrder OnNodeReOrderEvent;
 
- 		public OnSRPAction OnLightweightAction;
 
- 		public OnSRPAction OnHDAction;
 
- 		[SerializeField]
 
- 		private int m_uniqueId;
 
- 		[SerializeField]
 
- 		protected Rect m_position;
 
- 		[SerializeField]
 
- 		protected Rect m_unpreviewedPosition;
 
- 		[SerializeField]
 
- 		protected GUIContent m_content;
 
- 		[SerializeField]
 
- 		protected GUIContent m_additionalContent;
 
- 		[SerializeField]
 
- 		protected bool m_initialized;
 
- 		[SerializeField]
 
- 		protected NodeConnectionStatus m_connStatus;
 
- 		protected bool m_selfPowered = false;
 
- 		[SerializeField]
 
- 		protected int m_activeConnections;
 
- 		[SerializeField]
 
- 		protected System.Type m_activeType;
 
- 		[SerializeField]
 
- 		protected int m_activePort;
 
- 		[SerializeField]
 
- 		protected int m_activeNode;
 
- 		protected NodeRestrictions m_restrictions;
 
- 		[SerializeField]
 
- 		protected Color m_statusColor;
 
- 		[SerializeField]
 
- 		protected Rect m_propertyDrawPos;
 
- 		// Ports
 
- 		[SerializeField]
 
- 		protected List<InputPort> m_inputPorts = new List<InputPort>();
 
- 		protected Dictionary<int, InputPort> m_inputPortsDict = new Dictionary<int, InputPort>();
 
- 		[SerializeField]
 
- 		protected bool m_sortInputPorts = false;
 
- 		private List<InputPort> m_sortedInputPorts = new List<InputPort>();
 
- 		[SerializeField]
 
- 		protected List<OutputPort> m_outputPorts = new List<OutputPort>();		
 
- 		protected Dictionary<int, OutputPort> m_outputPortsDict = new Dictionary<int, OutputPort>();
 
- 		[SerializeField]
 
- 		protected bool m_sortOutputPorts = false;
 
- 		private List<OutputPort> m_sortedOutputPorts = new List<OutputPort>();
 
- 		// Positions
 
- 		[SerializeField]
 
- 		protected Rect m_globalPosition;
 
- 		[SerializeField]
 
- 		protected Rect m_headerPosition;
 
- 		//private Vector2 m_tooltipOffset;
 
- 		[SerializeField]
 
- 		protected bool m_sizeIsDirty = false;
 
- 		[SerializeField]
 
- 		protected Vector2 m_extraSize;
 
- 		[SerializeField]
 
- 		protected Vector2 m_insideSize;
 
- 		[SerializeField]
 
- 		protected float m_fontHeight;
 
- 		// Editor State save on Play Button
 
- 		[SerializeField]
 
- 		protected bool m_isDirty;
 
- 		[SerializeField]
 
- 		private int m_isMoving = 0;
 
- 		[SerializeField]
 
- 		private Rect m_lastPosition;
 
- 		// Live Shader Gen
 
- 		[SerializeField]
 
- 		private bool m_saveIsDirty;
 
- 		[SerializeField]
 
- 		protected bool m_requireMaterialUpdate = false;
 
- 		[SerializeField]
 
- 		protected int m_commentaryParent = -1;
 
- 		[SerializeField]
 
- 		protected int m_depth = -1;
 
- 		[SerializeField]
 
- 		protected bool m_materialMode = false;
 
- 		[SerializeField]
 
- 		protected bool m_showPreview = false;
 
- 		[SerializeField]
 
- 		protected int m_previewMaterialPassId = -1;
 
- 		
 
- 		protected bool m_useSquareNodeTitle = false;
 
- 		[SerializeField]
 
- 		protected bool m_continuousPreviewRefresh = false;
 
- 		private bool m_previewIsDirty = true;
 
- 		// Error Box Messages
 
- 		private Rect m_errorBox;
 
- 		private bool m_previousErrorMessage = false;
 
- 		protected bool m_showErrorMessage = false;
 
- 		protected NodeMessageType m_errorMessageTypeIsError = NodeMessageType.Error;
 
- 		protected string m_errorMessageTooltip = string.Empty;
 
- 		private GUIContent m_errorIcon = new GUIContent();
 
- 		private GUIContent m_errorMessage = new GUIContent();
 
- 		private GUIStyle m_errorCurrentStyle;
 
- 		private const string ErrorTitle = "ERROR";
 
- 		private const string WarningTitle = "WARNING";
 
- 		private const string InfoTitle = "INFO";
 
- 		// Drawing Node
 
- 		protected PreviewLocation m_selectedLocation = PreviewLocation.Auto;
 
- 		private int m_extraHeaderHeight = 0;
 
- 		protected bool m_isVisible;
 
- 		protected bool m_selected = false;
 
- 		protected bool m_rmbIgnore;
 
- 		protected GUIContent m_sizeContentAux;
 
- 		protected uint m_currentReadParamIdx = 1;
 
- 		protected bool m_reorderLocked = false;
 
- 		protected Rect m_cachedPos;
 
- 		protected Vector2 m_accumDelta = Vector2.zero;
 
- 		private bool m_isOnGrid = false;
 
- 		protected bool m_useInternalPortData = false;
 
- 		protected bool m_autoDrawInternalPortData = true;
 
- 		protected DrawOrder m_drawOrder = DrawOrder.Default;
 
- 		protected bool m_movingInFrame = false;
 
- 		protected float m_anchorAdjust = -1;
 
- 		protected Color m_headerColor;
 
- 		[SerializeField] // needs to be serialized because of Undo
 
- 		protected Color m_headerColorModifier = Color.white;
 
- 		protected bool m_infiniteLoopDetected = false;
 
- 		protected int m_textLabelWidth = -1;
 
- 		private bool m_linkVisibility = false;
 
- 		[SerializeField]
 
- 		protected bool m_hasTooltipLink = true;
 
- 		protected int m_category = 0;
 
- 		protected double m_lastTimeSelected;
 
- 		private double m_tooltipTimestamp;
 
- 		protected string m_tooltipText;
 
- 		protected Rect m_unscaledRemainingBox;
 
- 		protected Rect m_remainingBox;
 
- 		private int m_visibleInputs = 0;
 
- 		private int m_visibleOutputs = 0;
 
- 		private double m_doubleClickTimestamp;
 
- 		private const double DoubleClickTime = 0.25;
 
- 		protected bool m_canExpand = true;
 
- 		protected bool m_firstDraw = true;
 
- 		protected int m_matrixId = -1;
 
- 		private float m_paddingTitleLeft = 0;
 
- 		private float m_paddingTitleRight = 0;
 
- 		// Preview Fields
 
- 		private Material m_previewMaterial = null;
 
- 		private Shader m_previewShader = null;
 
- 		protected string m_previewShaderGUID = string.Empty;
 
- 		protected float m_marginPreviewLeft = 0;
 
- 		protected bool m_globalShowPreview = false;
 
- 		protected Rect m_unscaledPreviewRect;
 
- 		protected Rect m_previewRect;
 
- 		protected bool m_drawPreviewMaskButtons = true;
 
- 		private int m_channelNumber = 0;
 
- 		protected bool m_firstPreviewDraw = true;
 
- 		[SerializeField]
 
- 		protected bool m_drawPreview = true;
 
- 		protected bool m_drawPreviewExpander = true;
 
- 		private bool m_spherePreview = false;
 
- 		protected bool m_drawPreviewAsSphere = false;
 
- 		protected bool m_forceDrawPreviewAsPlane = false;
 
- 		private bool m_finishPreviewRender = false;
 
- 		private int m_cachedMainTexId = -1;
 
- 		private int m_cachedMaskTexId = -1;
 
- 		private int m_cachedPortsId = -1;
 
- 		private int m_cachedPortId = -1;
 
- 		private int m_cachedDrawSphereId = -1;
 
- 		private int m_cachedInvertedZoomId = -1;
 
- 		//private int m_cachedIsLinearId = -1;
 
- 		private bool[] m_previewChannels = { true, true, true, false };
 
- 		// Others
 
- 		protected bool m_hasSubtitle = false;
 
- 		protected bool m_showSubtitle = true;
 
- 		protected bool m_hasLeftDropdown = false;
 
- 		protected bool m_autoWrapProperties = false;
 
- 		protected bool m_internalDataFoldout = true;
 
- 		protected bool m_propertiesFoldout = true;
 
- 		protected bool m_repopulateDictionaries = true;
 
- 		protected Vector2 m_lastInputBottomRight = Vector2.zero;
 
- 		protected Vector2 m_lastOutputBottomLeft = Vector2.zero;
 
- 		private Vector4 m_portMask = Vector4.zero;
 
- 		private Vector2 m_auxVector2 = Vector4.zero;
 
- 		protected Rect m_auxRect;
 
- 		protected PreviewLocation m_autoLocation;
 
- 		protected Rect m_titlePos;
 
- 		protected Rect m_addTitlePos;
 
- 		protected Rect m_expandRect;
 
- 		protected Rect m_dropdownRect;
 
- 		protected Rect m_currInputPortPos;
 
- 		protected Rect m_currOutputPortPos;
 
- 		protected Color m_colorBuffer;
 
- 		[SerializeField]
 
- 		protected bool m_docking = false;
 
- 		[SerializeField]
 
- 		protected int m_visiblePorts = 0;
 
- 		protected int m_graphDepth = 0;
 
- 		protected int m_oldInputCount = -1;
 
- 		protected bool m_dropdownEditing = false;
 
- 		protected bool m_isNodeBeingCopied = false;
 
- 		protected string m_previousTitle = string.Empty;
 
- 		protected string m_previousAdditonalTitle = string.Empty;
 
- 		protected string m_previousAdditonalTitleFormat = string.Empty;
 
- 		private bool m_alive = true;
 
- 		private bool m_wasDeprecated = false;
 
- 		private double m_timedUpdateInitialValue;
 
- 		private double m_timedUpdateInterval;
 
- 		private bool m_fireTimedUpdateRequest = false;
 
- 		public ParentNode()
 
- 		{
 
- 			m_position = new Rect( 0, 0, 0, 0 );
 
- 			m_content = new GUIContent( GUIContent.none );
 
- 			m_additionalContent = new GUIContent( GUIContent.none );
 
- 			CommonInit( -1 );
 
- 		}
 
- 		public ParentNode( int uniqueId, float x, float y, float width, float height )
 
- 		{
 
- 			m_position = new Rect( x, y, width, height );
 
- 			m_content = new GUIContent( GUIContent.none );
 
- 			m_additionalContent = new GUIContent( GUIContent.none );
 
- 			CommonInit( uniqueId );
 
- 		}
 
- 		public virtual void OnEnable()
 
- 		{
 
- 			hideFlags = HideFlags.HideAndDontSave;
 
- 			RefreshUIHeaderColor();
 
- 			m_tooltipTimestamp = Time.realtimeSinceStartup;
 
- 			hideFlags = HideFlags.DontSave;
 
- 		}		
 
- 		public void RefreshUIHeaderColor()
 
- 		{
 
- 			// @diogo: handle special shader function case; this will have to do for now...
 
- 			var functionNode = this as FunctionNode;
 
- 			if ( functionNode != null && functionNode.Function != null )
 
- 			{				
 
- 				if ( functionNode.Function.Header == AmplifyShaderFunction.HeaderStyle.Custom )
 
- 				{
 
- 					m_headerColor = functionNode.Function.HeaderColor;
 
- 				}
 
- 				else if ( functionNode.Function.Header == AmplifyShaderFunction.HeaderStyle.Category )
 
- 				{
 
- 					m_headerColor = UIUtils.GetColorFromCategory( functionNode.Function.CustomNodeCategory );
 
- 				}
 
- 				else
 
- 				{
 
- 					m_headerColor = UIUtils.GetColorFromCategory( "Functions" );
 
- 				}
 
- 			}
 
- 			else if ( m_nodeAttribs != null )
 
- 			{
 
- 				if( UIUtils.HasColorCategory( m_nodeAttribs.Category ) )
 
- 				{
 
- 					m_headerColor = UIUtils.GetColorFromCategory( m_nodeAttribs.Category );
 
- 				}
 
- 				else
 
- 				{
 
- 					if( !string.IsNullOrEmpty( m_nodeAttribs.CustomCategoryColor ) )
 
- 					{
 
- 						m_headerColor = UIUtils.AddColorCategory( m_nodeAttribs.Category, m_nodeAttribs.CustomCategoryColor );
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		protected virtual void CommonInit( int uniqueId )
 
- 		{
 
- 			m_uniqueId = uniqueId;
 
- 			m_isOnGrid = false;
 
- 			ConnStatus = NodeConnectionStatus.Not_Connected;
 
- 			m_inputPorts = new List<InputPort>();
 
- 			m_inputPortsDict = new Dictionary<int, InputPort>();
 
- 			m_outputPorts = new List<OutputPort>();
 
- 			m_outputPortsDict = new Dictionary<int, OutputPort>();
 
- 			System.Reflection.MemberInfo info = this.GetType();
 
- 			m_nodeAttribs = info.GetCustomAttributes( typeof( NodeAttributes ), true ).FirstOrDefault() as NodeAttributes;
 
- 			if( m_nodeAttribs != null )
 
- 			{
 
- 				m_content.text = m_nodeAttribs.Name;
 
- 				//m_content.tooltip = m_nodeAttribs.Description;
 
- 				m_tooltipText = m_nodeAttribs.Description;
 
- 				m_selected = false;
 
- 			}
 
- 			m_sizeContentAux = new GUIContent();
 
- 			m_extraSize = new Vector2( 0, 0 );
 
- 			m_insideSize = new Vector2( 0, 0 );
 
- 			m_sizeIsDirty = true;
 
- 			m_initialized = true;
 
- 			m_restrictions = new NodeRestrictions();
 
- 			m_propertyDrawPos = new Rect();
 
- 		}
 
- 		public virtual void AfterCommonInit()
 
- 		{
 
- 			if( PreviewShader && !HasPreviewShader )
 
- 			{
 
- 				m_drawPreview = false;
 
- 				m_drawPreviewExpander = false;
 
- 				m_canExpand = false;
 
- 			}
 
- 			if( m_drawPreviewExpander || m_hasLeftDropdown )
 
- 			{
 
- 				m_paddingTitleRight += Constants.PreviewExpanderWidth + Constants.IconsLeftRightMargin;
 
- 				m_paddingTitleLeft = Constants.PreviewExpanderWidth + Constants.IconsLeftRightMargin;
 
- 			}
 
- 		}
 
- 		public virtual void Destroy()
 
- 		{
 
- 			m_alive = false;
 
- 			if( OnNodeDestroyedEvent != null )
 
- 			{
 
- 				OnNodeDestroyedEvent( this );
 
- 				OnNodeDestroyedEvent = null;
 
- 			}
 
- 			OnLightweightAction = null;
 
- 			OnHDAction = null;
 
- 			OnNodeStoppedMovingEvent = null;
 
- 			OnNodeChangeSizeEvent = null;
 
- 			OnNodeReOrderEvent = null;
 
- 			if( m_restrictions != null )
 
- 				m_restrictions.Destroy();
 
- 			m_restrictions = null;
 
- 			if( m_inputPorts != null )
 
- 			{
 
- 				int inputCount = m_inputPorts.Count;
 
- 				for( int i = 0; i < inputCount; i++ )
 
- 				{
 
- 					m_inputPorts[ i ].Destroy();
 
- 				}
 
- 				m_inputPorts.Clear();
 
- 				m_inputPorts = null;
 
- 			}
 
- 			if( m_outputPorts != null )
 
- 			{
 
- 				int outputCount = m_outputPorts.Count;
 
- 				for( int i = 0; i < outputCount; i++ )
 
- 				{
 
- 					m_outputPorts[ i ].Destroy();
 
- 				}
 
- 				m_outputPorts.Clear();
 
- 				m_outputPorts = null;
 
- 			}
 
- 			if( m_inputPortsDict != null )
 
- 				m_inputPortsDict.Clear();
 
- 			m_inputPortsDict = null;
 
- 			if( m_outputPortsDict != null )
 
- 				m_outputPortsDict.Clear();
 
- 			m_outputPortsDict = null;
 
- 			if( m_previewMaterial != null )
 
- 				DestroyImmediate( m_previewMaterial );
 
- 			m_previewMaterial = null;
 
- 			m_previewShader = null;
 
- 			//m_containerGraph = null;
 
- 		}
 
- 		public virtual void Move( Vector2 delta )
 
- 		{
 
- 			if( m_docking )
 
- 				return;
 
- 			Move( delta, false );
 
- 		}
 
- 		public virtual void Move( Vector2 delta, bool snap )
 
- 		{
 
- 			if( m_docking )
 
- 				return;
 
- 			if( m_isMoving == 0 )
 
- 			{
 
- 				m_cachedPos = m_position;
 
- 				m_accumDelta = Vector2.zero;
 
- 			}
 
- 			m_isMoving = MoveCountBuffer;
 
- 			m_accumDelta += delta;
 
- 			if( snap )
 
- 			{
 
- 				m_position.x = Mathf.Round( ( m_cachedPos.x + m_accumDelta.x ) / 16 ) * 16;
 
- 				m_position.y = Mathf.Round( ( m_cachedPos.y + m_accumDelta.y ) / 16 ) * 16;
 
- 			}
 
- 			else
 
- 			{
 
- 				m_position.x += delta.x;
 
- 				m_position.y += delta.y;
 
- 			}
 
- 			//if(Event.current.type == EventType.Layout)
 
- 			m_movingInFrame = true;
 
- 		}
 
- 		public virtual void UpdateMaterial( Material mat )
 
- 		{
 
- 			m_requireMaterialUpdate = false;
 
- 		}
 
- 		public virtual void SetMaterialMode( Material mat, bool fetchMaterialValues )
 
- 		{
 
- 			m_materialMode = ( mat != null );
 
- 		}
 
- 		public virtual bool UpdateShaderDefaults( ref Shader shader, ref TextureDefaultsDataColector defaultCol ) { return false; }
 
- 		public virtual void ForceUpdateFromMaterial( Material material ) { }
 
- 		public void SetSaveIsDirty()
 
- 		{
 
- 			if( m_connStatus == NodeConnectionStatus.Connected )
 
- 			{
 
- 				SaveIsDirty = true;
 
- 			}
 
- 		}
 
- 		public void ActivateNodeReordering( int index )
 
- 		{
 
- 			if( OnNodeReOrderEvent != null )
 
- 				OnNodeReOrderEvent( this, index );
 
- 		}
 
- 		void RecalculateInputPortIdx()
 
- 		{
 
- 			m_inputPortsDict.Clear();
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].IsConnected )
 
- 				{
 
- 					int nodeId = m_inputPorts[ i ].ExternalReferences[ 0 ].NodeId;
 
- 					int portId = m_inputPorts[ i ].ExternalReferences[ 0 ].PortId;
 
- 					ParentNode node = UIUtils.GetNode( nodeId );
 
- 					if( node != null )
 
- 					{
 
- 						OutputPort outputPort = node.GetOutputPortByUniqueId( portId );
 
- 						int outputCount = outputPort.ExternalReferences.Count;
 
- 						for( int j = 0; j < outputCount; j++ )
 
- 						{
 
- 							if( outputPort.ExternalReferences[ j ].NodeId == m_uniqueId &&
 
- 								outputPort.ExternalReferences[ j ].PortId == m_inputPorts[ i ].PortId )
 
- 							{
 
- 								outputPort.ExternalReferences[ j ].PortId = i;
 
- 							}
 
- 						}
 
- 					}
 
- 				}
 
- 				m_inputPorts[ i ].PortId = i;
 
- 				m_inputPortsDict.Add( i, m_inputPorts[ i ] );
 
- 			}
 
- 		}
 
- 		public void SwapInputPorts( int fromIdx, int toIdx )
 
- 		{
 
- 			InputPort port = m_inputPorts[ fromIdx ];
 
- 			//if( toIdx > fromIdx )
 
- 			//	toIdx--;
 
- 			m_inputPorts.Remove( port );
 
- 			m_inputPorts.Insert( toIdx, port );
 
- 			RecalculateInputPortIdx();
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		public void RemoveInputPort( int idx )
 
- 		{
 
- 			if( idx < m_inputPorts.Count )
 
- 			{
 
- 				m_inputPortsDict.Remove( m_inputPorts[ idx ].PortId );
 
- 				m_inputPorts.RemoveAt( idx );
 
- 				SetSaveIsDirty();
 
- 				m_sizeIsDirty = true;
 
- 			}
 
- 		}
 
- 		public void RemoveOutputPort( string name )
 
- 		{
 
- 			int count = m_outputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].Name.Equals( name ) )
 
- 				{
 
- 					if( m_outputPorts[ i ].IsConnected )
 
- 					{
 
- 						m_containerGraph.DeleteConnection( false, m_uniqueId, m_outputPorts[ i ].PortId, false, true );
 
- 						m_outputPortsDict.Remove( m_outputPorts[ i ].PortId );
 
- 						m_outputPorts.RemoveAt( i );
 
- 						SetSaveIsDirty();
 
- 						m_sizeIsDirty = true;
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		public void RemoveOutputPort( int idx, bool isArrayIndex = true )
 
- 		{
 
- 			if( isArrayIndex )
 
- 			{
 
- 				// idx represents a position on the output port array
 
- 				if( idx < m_outputPorts.Count )
 
- 				{
 
- 					if( m_outputPorts[ idx ].IsConnected )
 
- 					{
 
- 						m_containerGraph.DeleteConnection( false, m_uniqueId, m_outputPorts[ idx ].PortId, false, true );
 
- 					}
 
- 					m_outputPortsDict.Remove( m_outputPorts[ idx ].PortId );
 
- 					m_outputPorts.RemoveAt( idx );
 
- 					SetSaveIsDirty();
 
- 					m_sizeIsDirty = true;
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				// idx represents a port unique id
 
- 				int count = m_outputPorts.Count;
 
- 				int arrIdx = -1;
 
- 				for( int i = 0; i < count; i++ )
 
- 				{
 
- 					if( m_outputPorts[ i ].PortId == idx )
 
- 					{
 
- 						arrIdx = i;
 
- 						break;
 
- 					}
 
- 				}
 
- 				if( arrIdx >= 0 )
 
- 				{
 
- 					if( m_outputPorts[ arrIdx ].IsConnected )
 
- 					{
 
- 						m_containerGraph.DeleteConnection( false, m_uniqueId, idx, false, true );
 
- 					}
 
- 					m_outputPortsDict.Remove( idx );
 
- 					m_outputPorts.RemoveAt( arrIdx );
 
- 					SetSaveIsDirty();
 
- 					m_sizeIsDirty = true;
 
- 				}
 
- 			}
 
- 		}
 
- 		// Manually add Ports 
 
- 		public InputPort AddInputPort( WirePortDataType type, bool typeLocked, string name, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, int uniquePortId = -1 )
 
- 		{
 
- 			InputPort port = new InputPort( m_uniqueId, ( uniquePortId < 0 ? m_inputPorts.Count : uniquePortId ), type, name, typeLocked, ( orderId >= 0 ? orderId : m_inputPorts.Count ), category );
 
- 			m_inputPorts.Add( port );
 
- 			m_inputPortsDict.Add( port.PortId, port );
 
- 			SetSaveIsDirty();
 
- 			m_sizeIsDirty = true;
 
- 			return port;
 
- 		}
 
- 		public InputPort AddInputPort( WirePortDataType type, bool typeLocked, string name, string dataName, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, int uniquePortId = -1 )
 
- 		{
 
- 			InputPort port = new InputPort( m_uniqueId, ( uniquePortId < 0 ? m_inputPorts.Count : uniquePortId ), type, name, dataName, typeLocked, ( orderId >= 0 ? orderId : m_inputPorts.Count ), category );
 
- 			m_inputPorts.Add( port );
 
- 			m_inputPortsDict.Add( port.PortId, port );
 
- 			SetSaveIsDirty();
 
- 			m_sizeIsDirty = true;
 
- 			return port;
 
- 		}
 
- 		public InputPort AddInputPortAt( int idx, WirePortDataType type, bool typeLocked, string name, int orderId = -1, MasterNodePortCategory category = MasterNodePortCategory.Fragment, int uniquePortId = -1 )
 
- 		{
 
- 			InputPort port = new InputPort( m_uniqueId, ( uniquePortId < 0 ? m_inputPorts.Count : uniquePortId ), type, name, typeLocked, ( orderId >= 0 ? orderId : m_inputPorts.Count ), category );
 
- 			m_inputPorts.Insert( idx, port );
 
- 			m_inputPortsDict.Add( port.PortId, port );
 
- 			SetSaveIsDirty();
 
- 			m_sizeIsDirty = true;
 
- 			RecalculateInputPortIdx();
 
- 			return port;
 
- 		}
 
- 		public void AddOutputPort( WirePortDataType type, string name, int uniquePortId = -1 )
 
- 		{
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, ( uniquePortId < 0 ? m_outputPorts.Count : uniquePortId ), type, name ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			SetSaveIsDirty();
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		public void AddOutputPortAt( int idx, WirePortDataType type, string name, int uniquePortId = -1 )
 
- 		{
 
- 			OutputPort port = new OutputPort( this, m_uniqueId, ( uniquePortId < 0 ? m_outputPorts.Count : uniquePortId ), type, name );
 
- 			m_outputPorts.Insert( idx, port );
 
- 			m_outputPortsDict.Add( port.PortId, port );
 
- 			SetSaveIsDirty();
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		public void AddOutputVectorPorts( WirePortDataType type, string name )
 
- 		{
 
- 			m_sizeIsDirty = true;
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, type, name ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			switch( type )
 
- 			{
 
- 				case WirePortDataType.FLOAT2:
 
- 				{
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "X" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "Y" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 				}
 
- 				break;
 
- 				case WirePortDataType.FLOAT3:
 
- 				{
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "X" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "Y" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "Z" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 				}
 
- 				break;
 
- 				case WirePortDataType.FLOAT4:
 
- 				{
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "X" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "Y" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "Z" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 					m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "W" ) );
 
- 					m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 				}
 
- 				break;
 
- 			}
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		public void SetPreviewDirtyFromOutputs()
 
- 		{
 
- 			PreviewIsDirty = true;
 
- 		}
 
- 		public string GetOutputVectorItem( int vectorPortId, int currentPortId, string result )
 
- 		{
 
- 			if( m_outputPorts[ 0 ].DataType == WirePortDataType.COLOR )
 
- 			{
 
- 				switch( currentPortId - vectorPortId )
 
- 				{
 
- 					case 1: result += ".r"; break;
 
- 					case 2: result += ".g"; break;
 
- 					case 3: result += ".b"; break;
 
- 					case 4: result += ".a"; break;
 
- 					case 5: result += ".rgb"; break;
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				switch( currentPortId - vectorPortId )
 
- 				{
 
- 					case 1: result += ".x"; break;
 
- 					case 2: result += ".y"; break;
 
- 					case 3: result += ".z"; break;
 
- 					case 4: result += ".w"; break;
 
- 					case 5: result += ".xyz"; break;
 
- 				}
 
- 			}
 
- 			return result;
 
- 		}
 
- 		public void AddOutputColorPorts( string name = "RGBA", bool addAlpha = true, bool addRGB = false )
 
- 		{
 
- 			m_sizeIsDirty = true;
 
- 			// RGBA port
 
- 			int startOrderId = ( m_outputPorts.Count > 0 ) ? m_outputPorts[ m_outputPorts.Count - 1 ].OrderId : 0;
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, addAlpha ? WirePortDataType.COLOR : WirePortDataType.FLOAT3, name ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId;
 
- 			// Red port
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "R" ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].CustomColor = Color.red;
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId + 2;
 
- 			// Green port
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "G" ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].CustomColor = Color.green;
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId + 3;
 
- 			// Blue port
 
- 			m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "B" ) );
 
- 			m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].CustomColor = Color.blue;
 
- 			m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId + 4;
 
- 			if ( addAlpha )
 
- 			{
 
- 				// Alpha port
 
- 				m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT, "A" ) );
 
- 				m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 				m_outputPorts[ m_outputPorts.Count - 1 ].CustomColor = Color.white;
 
- 				m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId + 5;
 
- 			}
 
- 			if ( addRGB && addAlpha )
 
- 			{
 
- 				// RGB port (placed below RGBA)
 
- 				m_outputPorts.Add( new OutputPort( this, m_uniqueId, m_outputPorts.Count, WirePortDataType.FLOAT3, "RGB" ) );
 
- 				m_outputPortsDict.Add( m_outputPorts[ m_outputPorts.Count - 1 ].PortId, m_outputPorts[ m_outputPorts.Count - 1 ] );
 
- 				m_outputPorts[ m_outputPorts.Count - 1 ].OrderId = startOrderId + 1;
 
- 			}
 
- 		}
 
- 		public void ConvertFromVectorToColorPorts()
 
- 		{
 
- 			m_outputPorts[ 0 ].ChangeType( WirePortDataType.COLOR, false );
 
- 			m_outputPorts[ 1 ].Name = "R";
 
- 			m_outputPorts[ 1 ].CustomColor = Color.red;
 
- 			m_outputPorts[ 2 ].Name = "G";
 
- 			m_outputPorts[ 2 ].CustomColor = Color.green;
 
- 			m_outputPorts[ 3 ].Name = "B";
 
- 			m_outputPorts[ 3 ].CustomColor = Color.blue;
 
- 			m_outputPorts[ 4 ].Name = "A";
 
- 			m_outputPorts[ 4 ].CustomColor = Color.white;
 
- 		}
 
- 		public string GetOutputColorItem( int vectorPortId, int currentPortId, string result )
 
- 		{
 
- 			switch( currentPortId - vectorPortId )
 
- 			{
 
- 				case 1: result += ".r"; break;
 
- 				case 2: result += ".g"; break;
 
- 				case 3: result += ".b"; break;
 
- 				case 4: result += ".a"; break;
 
- 				case 5: result += ".rgb"; break;
 
- 			}
 
- 			return result;
 
- 		}
 
- 		public void ChangeOutputType( WirePortDataType type, bool invalidateConnections )
 
- 		{
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				m_outputPorts[ i ].ChangeType( type, invalidateConnections );
 
- 			}
 
- 		}
 
- 		public void ChangeInputType( WirePortDataType type, bool invalidateConnections )
 
- 		{
 
- 			int inputCount = m_inputPorts.Count;
 
- 			for( int i = 0; i < inputCount; i++ )
 
- 			{
 
- 				m_inputPorts[ i ].ChangeType( type, invalidateConnections );
 
- 			}
 
- 		}
 
- 		public void ChangeOutputProperties( int outputID, string newName, WirePortDataType newType, bool invalidateConnections = true )
 
- 		{
 
- 			if( outputID < m_outputPorts.Count )
 
- 			{
 
- 				m_outputPorts[ outputID ].ChangeProperties( newName, newType, invalidateConnections );
 
- 				IsDirty = true;
 
- 				m_sizeIsDirty = true;
 
- 				SetSaveIsDirty();
 
- 			}
 
- 		}
 
- 		public void ChangeOutputName( int outputArrayIdx, string newName )
 
- 		{
 
- 			if( outputArrayIdx < m_outputPorts.Count )
 
- 			{
 
- 				m_outputPorts[ outputArrayIdx ].Name = newName;
 
- 				IsDirty = true;
 
- 				m_sizeIsDirty = true;
 
- 			}
 
- 		}
 
- 		public InputPort CheckInputPortAt( Vector3 pos )
 
- 		{
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].InsideActiveArea( pos ) )
 
- 					return m_inputPorts[ i ];
 
- 			}
 
- 			return null;
 
- 		}
 
- 		public InputPort GetFirstInputPortOfType( WirePortDataType dataType, bool countObjectTypeAsValid )
 
- 		{
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( ( m_inputPorts[ i ].CheckValidType( dataType ) ) || ( countObjectTypeAsValid && m_inputPorts[ i ].DataType == WirePortDataType.OBJECT ) )
 
- 					return m_inputPorts[ i ];
 
- 			}
 
- 			return null;
 
- 		}
 
- 		public OutputPort CheckOutputPortAt( Vector3 pos )
 
- 		{
 
- 			int count = m_outputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].InsideActiveArea( pos ) )
 
- 					return m_outputPorts[ i ];
 
- 			}
 
- 			return null;
 
- 		}
 
- 		public OutputPort GetFirstOutputPortOfType( WirePortDataType dataType, bool checkForCasts )
 
- 		{
 
- 			int count = m_outputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( ( m_outputPorts[ i ].CheckValidType( dataType ) ) || ( checkForCasts && UIUtils.CanCast( dataType, m_outputPorts[ i ].DataType ) ) )
 
- 					return m_outputPorts[ i ];
 
- 			}
 
- 			return null;
 
- 		}
 
- 		virtual protected void ChangeSizeFinished() { m_firstPreviewDraw = true; /*MarkForPreviewUpdate();*/ }
 
- 		protected void ChangeSize()
 
- 		{
 
- 			m_cachedPos = m_position;
 
- 			//UIUtils.ResetMainSkin();
 
- 			Vector2 inSize = Vector2.zero;
 
- 			int inputCount = 0;
 
- 			int inputSize = m_inputPorts.Count;
 
- 			for( int i = 0; i < inputSize; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].Visible )
 
- 				{
 
- 					if( m_inputPorts[ i ].DirtyLabelSize || m_inputPorts[ i ].LabelSize == Vector2.zero )
 
- 					{
 
- 						m_inputPorts[ i ].DirtyLabelSize = false;
 
- 						m_sizeContentAux.text = m_inputPorts[ i ].Name;
 
- 						m_inputPorts[ i ].UnscaledLabelSize = UIUtils.UnZoomedInputPortStyle.CalcSize( m_sizeContentAux );
 
- 					}
 
- 					inSize.x = Mathf.Max( inSize.x, m_inputPorts[ i ].UnscaledLabelSize.x );
 
- 					inSize.y = Mathf.Max( inSize.y, m_inputPorts[ i ].UnscaledLabelSize.y );
 
- 					inputCount += 1;
 
- 				}
 
- 			}
 
- 			if( inSize.x > 0 )
 
- 				inSize.x += UIUtils.PortsSize.x + Constants.PORT_TO_LABEL_SPACE_X * 2;
 
- 			inSize.x += m_marginPreviewLeft;
 
- 			inSize.y = Mathf.Max( inSize.y, UIUtils.PortsSize.y );
 
- 			Vector2 outSize = Vector2.zero;
 
- 			int outputCount = 0;
 
- 			int outputSize = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputSize; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].Visible )
 
- 				{
 
- 					if( m_outputPorts[ i ].DirtyLabelSize || m_outputPorts[ i ].LabelSize == Vector2.zero )
 
- 					{
 
- 						m_outputPorts[ i ].DirtyLabelSize = false;
 
- 						m_sizeContentAux.text = m_outputPorts[ i ].Name;
 
- 						m_outputPorts[ i ].UnscaledLabelSize = UIUtils.UnZoomedOutputPortPortStyle.CalcSize( m_sizeContentAux );
 
- 					}
 
- 					outSize.x = Mathf.Max( outSize.x, m_outputPorts[ i ].UnscaledLabelSize.x );
 
- 					outSize.y = Mathf.Max( outSize.y, m_outputPorts[ i ].UnscaledLabelSize.y );
 
- 					outputCount += 1;
 
- 				}
 
- 			}
 
- 			if( outSize.x > 0 )
 
- 				outSize.x += UIUtils.PortsSize.x + Constants.PORT_TO_LABEL_SPACE_X * 2;
 
- 			outSize.y = Mathf.Max( outSize.y, UIUtils.PortsSize.y );
 
- 			if( m_additionalContent.text.Length > 0 )
 
- 			{
 
- 				m_extraHeaderHeight = (int)Constants.NODE_HEADER_EXTRA_HEIGHT;
 
- 				m_hasSubtitle = true && m_showSubtitle;
 
- 			}
 
- 			else
 
- 			{
 
- 				m_extraHeaderHeight = 0;
 
- 				m_hasSubtitle = false;
 
- 			}
 
- 			float headerWidth = Mathf.Max( UIUtils.UnZoomedNodeTitleStyle.CalcSize( m_content ).x + m_paddingTitleLeft + m_paddingTitleRight, UIUtils.UnZoomedPropertyValuesTitleStyle.CalcSize( m_additionalContent ).x + m_paddingTitleLeft + m_paddingTitleRight );
 
- 			m_position.width = Mathf.Max(headerWidth, Mathf.Max(MinInsideBoxWidth, m_insideSize.x) + inSize.x + outSize.x);/* + Constants.NODE_HEADER_LEFTRIGHT_MARGIN * 2;*/
 
- 			m_position.width = Mathf.Round(m_position.width / 32) * 32 + 32;
 
-             //m_position.width += m_extraSize.x;
 
-             m_fontHeight = Mathf.Max( inSize.y, outSize.y );
 
- 			m_position.height = Mathf.Max( inputCount, outputCount ) * ( m_fontHeight + Constants.INPUT_PORT_DELTA_Y );// + Constants.INPUT_PORT_DELTA_Y;
 
- 			m_position.height = Mathf.Max( m_position.height, Mathf.Max( MinInsideBoxHeight, m_insideSize.y ) );
 
- 			m_position.height += UIUtils.HeaderMaxHeight + /*m_extraHeaderHeight +*/ Constants.INPUT_PORT_DELTA_Y;// + m_extraSize.y;
 
- 			if( m_showErrorMessage )
 
- 				m_position.height += 24;
 
- 			m_unpreviewedPosition = m_position;
 
- 			//UIUtils.CurrentWindow.CameraDrawInfo.InvertedZoom = cachedZoom;
 
- 			if( OnNodeChangeSizeEvent != null )
 
- 			{
 
- 				OnNodeChangeSizeEvent( this );
 
- 			}
 
- 			ChangeSizeFinished();
 
- 		}
 
- 		public virtual void Reset() { }
 
- 		public virtual void OnOutputPortConnected( int portId, int otherNodeId, int otherPortId ) { }
 
- 		public virtual void OnInputPortConnected( int portId, int otherNodeId, int otherPortId, bool activateNode = true )
 
- 		{
 
- 			InputPort port = GetInputPortByUniqueId( portId );
 
- 			if( activateNode && m_connStatus == NodeConnectionStatus.Connected )
 
- 			{
 
- 				port.GetOutputNode().ActivateNode( m_activeNode, m_activePort, m_activeType );
 
- 			}
 
- 			PreviewIsDirty = true;
 
- 			OnNodeChange();
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		public virtual void OnInputPortDisconnected( int portId ) { PreviewIsDirty = true; OnNodeChange(); }
 
- 		public virtual void OnOutputPortDisconnected( int portId ) { }
 
- 		public virtual void OnNodeChange()
 
- 		{
 
- 			CheckSpherePreview();
 
- 			int count = m_outputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].IsConnected )
 
- 				{
 
- 					for( int f = 0; f < m_outputPorts[ i ].ExternalReferences.Count; f++ )
 
- 					{
 
- 						ContainerGraph.GetNode( m_outputPorts[ i ].ExternalReferences[ f ].NodeId ).OnNodeChange();
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		public virtual void ActivateNode( int signalGenNodeId, int signalGenPortId, System.Type signalGenNodeType )
 
- 		{
 
- 			if( m_selfPowered )
 
- 				return;
 
- 			ConnStatus = m_restrictions.GetRestiction( signalGenNodeType, signalGenPortId ) ? NodeConnectionStatus.Error : NodeConnectionStatus.Connected;
 
- 			m_activeConnections += 1;
 
- 			if( m_activeConnections == 1 )
 
- 			{
 
- 				m_activeType = signalGenNodeType;
 
- 				m_activeNode = signalGenNodeId;
 
- 				m_activePort = signalGenPortId;
 
- 				for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 				{
 
- 					if( m_inputPorts[ i ].IsConnected )
 
- 					{
 
- 						m_inputPorts[ i ].GetOutputNode().ActivateNode( signalGenNodeId, signalGenPortId, signalGenNodeType );
 
- 					}
 
- 				}
 
- 			}
 
- 			// saveisdirty might be needed, gonna leave this here for now
 
- 			// SetSaveIsDirty();
 
- 		}
 
- 		public virtual void DeactivateInputPortNode( int deactivatedPort, bool forceComplete )
 
- 		{
 
- 			GetInputPortByUniqueId( deactivatedPort ).GetOutputNode().DeactivateNode( deactivatedPort, false );
 
- 		}
 
- 		public virtual void DeactivateNode( int deactivatedPort, bool forceComplete )
 
- 		{
 
- 			if( m_selfPowered )
 
- 				return;
 
- 			// saveisdirty might be needed, gonna leave this here for now
 
- 			// SetSaveIsDirty();
 
- 			m_activeConnections -= 1;
 
- 			if( forceComplete || m_activeConnections <= 0 )
 
- 			{
 
- 				m_activeConnections = 0;
 
- 				ConnStatus = NodeConnectionStatus.Not_Connected;
 
- 				for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 				{
 
- 					if( m_inputPorts[ i ].IsConnected )
 
- 					{
 
- 						ParentNode node = m_inputPorts[ i ].GetOutputNode();
 
- 						if( node != null )
 
- 							node.DeactivateNode( deactivatedPort == -1 ? m_inputPorts[ i ].PortId : deactivatedPort, false );
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		public Rect GlobalToLocalPosition( DrawInfo drawInfo )
 
- 		{
 
- 			float width = m_globalPosition.width / drawInfo.InvertedZoom;
 
- 			float height = m_globalPosition.height / drawInfo.InvertedZoom;
 
- 			float x = m_globalPosition.x / drawInfo.InvertedZoom - drawInfo.CameraOffset.x;
 
- 			float y = m_globalPosition.y / drawInfo.InvertedZoom - drawInfo.CameraOffset.y;
 
- 			return new Rect( x, y, width, height );
 
- 		}
 
- 		protected void CalculatePositionAndVisibility( DrawInfo drawInfo )
 
- 		{
 
- 			//m_movingInFrame = false;
 
- 			m_globalPosition = m_position;
 
- 			m_globalPosition.x = drawInfo.InvertedZoom * ( m_globalPosition.x + drawInfo.CameraOffset.x );
 
- 			m_globalPosition.y = drawInfo.InvertedZoom * ( m_globalPosition.y + drawInfo.CameraOffset.y );
 
- 			m_globalPosition.width *= drawInfo.InvertedZoom;
 
- 			m_globalPosition.height *= drawInfo.InvertedZoom;
 
- 			m_isVisible = ( m_globalPosition.x + m_globalPosition.width > 0 ) &&
 
- 							( m_globalPosition.x < drawInfo.CameraArea.width ) &&
 
- 							( m_globalPosition.y + m_globalPosition.height > 0 ) &&
 
- 							( m_globalPosition.y < drawInfo.CameraArea.height );
 
- 			if( m_isMoving > 0 && drawInfo.CurrentEventType != EventType.MouseDrag )
 
- 			{
 
- 				float deltaX = Mathf.Abs( m_lastPosition.x - m_position.x );
 
- 				float deltaY = Mathf.Abs( m_lastPosition.y - m_position.y );
 
- 				if( deltaX < 0.01f && deltaY < 0.01f )
 
- 				{
 
- 					m_isMoving -= 1;
 
- 					if( m_isMoving == 0 )
 
- 					{
 
- 						OnSelfStoppedMovingEvent();
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					m_isMoving = MoveCountBuffer;
 
- 				}
 
- 				m_lastPosition = m_position;
 
- 			}
 
- 		}
 
- 		public void FireStoppedMovingEvent( bool testOnlySelected, InteractionMode interactionMode )
 
- 		{
 
- 			if( OnNodeStoppedMovingEvent != null )
 
- 				OnNodeStoppedMovingEvent( this, testOnlySelected, interactionMode );
 
- 		}
 
- 		public virtual void OnSelfStoppedMovingEvent()
 
- 		{
 
- 			FireStoppedMovingEvent( true, m_defaultInteractionMode );
 
- 		}
 
- 		protected void DrawPrecisionProperty( bool withInherit = true )
 
- 		{
 
- 			if( withInherit )
 
- 				m_currentPrecisionType = (PrecisionType)EditorGUILayoutPopup( PrecisionContent.text, (int)m_currentPrecisionType, PrecisionLabelsExtra );
 
- 			else
 
- 				m_currentPrecisionType = (PrecisionType)EditorGUILayoutPopup( PrecisionContent.text, (int)m_currentPrecisionType, PrecisionLabels );
 
- 		}
 
- 		public virtual void DrawTitle( Rect titlePos )
 
- 		{
 
- 			if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
 
- 			{
 
- 				GUI.Label( titlePos, m_content, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
 
- 			}
 
- 		}
 
- 		public virtual void DrawPreview( DrawInfo drawInfo, Rect rect )
 
- 		{
 
- 			//if ( !m_drawPreview )
 
- 			//	return;
 
- 			if( m_cachedDrawSphereId == -1 )
 
- 				m_cachedDrawSphereId = Shader.PropertyToID( "_DrawSphere" );
 
- 			if( m_cachedInvertedZoomId == -1 )
 
- 				m_cachedInvertedZoomId = Shader.PropertyToID( "_InvertedZoom" );
 
- 			m_channelNumber = 0;
 
- 			Vector4 mask = Vector4.one;
 
- 			if( m_outputPorts.Count > 0 )
 
- 			{
 
- 				switch( m_outputPorts[ 0 ].DataType )
 
- 				{
 
- 					case WirePortDataType.FLOAT:
 
- 					m_channelNumber = 1;
 
- 					mask.Set( 1, 1, 1, 0 );
 
- 					break;
 
- 					case WirePortDataType.FLOAT2:
 
- 					m_channelNumber = 2;
 
- 					mask.Set( m_previewChannels[ 0 ] ? 1 : 0, m_previewChannels[ 1 ] ? 1 : 0, 1, 0 );
 
- 					break;
 
- 					case WirePortDataType.COLOR:
 
- 					case WirePortDataType.FLOAT4:
 
- 					case WirePortDataType.SAMPLER1D:
 
- 					case WirePortDataType.SAMPLER2D:
 
- 					case WirePortDataType.SAMPLER3D:
 
- 					case WirePortDataType.SAMPLERCUBE:
 
- 					case WirePortDataType.SAMPLER2DARRAY:
 
- 					m_channelNumber = 4;
 
- 					mask.Set( m_previewChannels[ 0 ] ? 1 : 0, m_previewChannels[ 1 ] ? 1 : 0, m_previewChannels[ 2 ] ? 1 : 0, m_previewChannels[ 3 ] ? 1 : 0 );
 
- 					break;
 
- 					default:
 
- 					m_channelNumber = 3;
 
- 					mask.Set( m_previewChannels[ 0 ] ? 1 : 0, m_previewChannels[ 1 ] ? 1 : 0, m_previewChannels[ 2 ] ? 1 : 0, 0 );
 
- 					break;
 
- 				}
 
- 			}
 
- 			UIUtils.LinearMaterial.SetFloat( m_cachedDrawSphereId, ( SpherePreview ? 1 : 0 ) );
 
- 			UIUtils.LinearMaterial.SetFloat( m_cachedInvertedZoomId, drawInfo.InvertedZoom );
 
- 			UIUtils.LinearMaterial.SetVector( "_Mask", mask );
 
- 			bool cached = GL.sRGBWrite;
 
- 			GL.sRGBWrite = true;
 
- 			//EditorGUI.DrawPreviewTexture( rect, PreviewTexture, UIUtils.LinearMaterial );
 
- 			int pass = 0;
 
- 			if( SpherePreview )
 
- 			{
 
- 				if( mask.w == 1 )
 
- 					pass = 3;
 
- 				else
 
- 					pass = 1;
 
- 			}
 
- 			else if( mask.w == 1 )
 
- 				pass = 2;
 
- 			Graphics.DrawTexture( rect, PreviewTexture, UIUtils.LinearMaterial, pass );
 
- 			GL.sRGBWrite = cached;
 
- 			//Preview buttons
 
- 			if( m_drawPreviewMaskButtons )
 
- 				DrawPreviewMaskButtonsRepaint( drawInfo, rect );
 
- 		}
 
- 		protected void DrawPreviewMaskButtonsLayout( DrawInfo drawInfo, Rect rect )
 
- 		{
 
- 			if( rect.Contains( drawInfo.MousePosition ) && m_channelNumber > 1 && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 )
 
- 			{
 
- 				Rect buttonRect = rect;
 
- 				buttonRect.height = 14 * drawInfo.InvertedZoom;
 
- 				buttonRect.y = rect.yMax - buttonRect.height;
 
- 				buttonRect.width = 14 * drawInfo.InvertedZoom;
 
- 				if( m_channelNumber == 2 )
 
- 				{
 
- 					m_previewChannels[ 0 ] = GUI.Toggle( buttonRect, m_previewChannels[ 0 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 1 ] = GUI.Toggle( buttonRect, m_previewChannels[ 1 ], string.Empty, GUIStyle.none );
 
- 				}
 
- 				else if( m_channelNumber == 3 )
 
- 				{
 
- 					m_previewChannels[ 0 ] = GUI.Toggle( buttonRect, m_previewChannels[ 0 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 1 ] = GUI.Toggle( buttonRect, m_previewChannels[ 1 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 2 ] = GUI.Toggle( buttonRect, m_previewChannels[ 2 ], string.Empty, GUIStyle.none );
 
- 				}
 
- 				else if( m_channelNumber == 4 )
 
- 				{
 
- 					m_previewChannels[ 0 ] = GUI.Toggle( buttonRect, m_previewChannels[ 0 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 1 ] = GUI.Toggle( buttonRect, m_previewChannels[ 1 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 2 ] = GUI.Toggle( buttonRect, m_previewChannels[ 2 ], string.Empty, GUIStyle.none );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					m_previewChannels[ 3 ] = GUI.Toggle( buttonRect, m_previewChannels[ 3 ], string.Empty, GUIStyle.none );
 
- 				}
 
- 			}
 
- 		}
 
- 		protected void DrawPreviewMaskButtonsRepaint( DrawInfo drawInfo, Rect rect )
 
- 		{
 
- 			if( drawInfo.CurrentEventType == EventType.Repaint && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD2 && rect.Contains( drawInfo.MousePosition ) && m_channelNumber > 1 )
 
- 			{
 
- 				Rect buttonRect = rect;
 
- 				buttonRect.height = 14 * drawInfo.InvertedZoom;
 
- 				buttonRect.y = rect.yMax - buttonRect.height;
 
- 				buttonRect.width = 14 * drawInfo.InvertedZoom;
 
- 				if( m_channelNumber == 2 )
 
- 				{
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "R", false, false, m_previewChannels[ 0 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopRight.Draw( buttonRect, "G", false, false, m_previewChannels[ 1 ], false );
 
- 				}
 
- 				else if( m_channelNumber == 3 )
 
- 				{
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "R", false, false, m_previewChannels[ 0 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "G", false, false, m_previewChannels[ 1 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopRight.Draw( buttonRect, "B", false, false, m_previewChannels[ 2 ], false );
 
- 				}
 
- 				else if( m_channelNumber == 4 )
 
- 				{
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "R", false, false, m_previewChannels[ 0 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "G", false, false, m_previewChannels[ 1 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopMid.Draw( buttonRect, "B", false, false, m_previewChannels[ 2 ], false );
 
- 					buttonRect.x += 14 * drawInfo.InvertedZoom;
 
- 					UIUtils.MiniButtonTopRight.Draw( buttonRect, "A", false, false, m_previewChannels[ 3 ], false );
 
- 				}
 
- 			}
 
- 		}
 
- 		public void SetTimedUpdate( double timerInterval )
 
- 		{
 
- 			m_timedUpdateInitialValue = EditorApplication.timeSinceStartup;
 
- 			m_timedUpdateInterval = timerInterval;
 
- 			m_fireTimedUpdateRequest = true;
 
- 		}
 
- 		public virtual void FireTimedUpdate() { }
 
- 		/// <summary>
 
- 		/// 
 
- 		/// </summary>
 
- 		/// <param name="drawInfo"></param>
 
- 		public virtual void OnNodeLogicUpdate( DrawInfo drawInfo )
 
- 		{
 
- 			if( m_fireTimedUpdateRequest && ( EditorApplication.timeSinceStartup - m_timedUpdateInitialValue ) > m_timedUpdateInterval )
 
- 			{
 
- 				m_fireTimedUpdateRequest = false;
 
- 				FireTimedUpdate();
 
- 			}
 
- 			if( m_repopulateDictionaries )
 
- 			{
 
- 				m_repopulateDictionaries = false;
 
- 				m_inputPortsDict.Clear();
 
- 				int inputCount = m_inputPorts.Count;
 
- 				for( int i = 0; i < inputCount; i++ )
 
- 				{
 
- 					m_inputPortsDict.Add( m_inputPorts[ i ].PortId, m_inputPorts[ i ] );
 
- 				}
 
- 				m_outputPortsDict.Clear();
 
- 				int outputCount = m_outputPorts.Count;
 
- 				for( int i = 0; i < outputCount; i++ )
 
- 				{
 
- 					m_outputPortsDict.Add( m_outputPorts[ i ].PortId, m_outputPorts[ i ] );
 
- 				}
 
- 			}
 
- 		}
 
- 		private void UpdateSortedInputPorts()
 
- 		{
 
- 			if ( m_sortInputPorts )
 
- 			{
 
- 				m_sortedInputPorts.Clear();
 
- 				m_sortedInputPorts.AddRange( m_inputPorts );
 
- 				m_sortedInputPorts.Sort( ( x, y ) => x.OrderId.CompareTo( y.OrderId ) );
 
- 			}
 
- 			else
 
- 			{
 
- 				m_sortedInputPorts = m_inputPorts;
 
- 			}
 
- 		}
 
- 		private void UpdateSortedOutputPorts()
 
- 		{
 
- 			if ( m_sortOutputPorts )
 
- 			{
 
- 				m_sortedOutputPorts.Clear();
 
- 				m_sortedOutputPorts.AddRange( m_outputPorts );
 
- 				m_sortedOutputPorts.Sort( ( x, y ) => x.OrderId.CompareTo( y.OrderId ) );
 
- 			}
 
- 			else
 
- 			{
 
- 				m_sortedOutputPorts = m_outputPorts;
 
- 			}
 
- 			
 
- 		}
 
- 		/// <summary>
 
- 		/// This method should only be called to calculate layouts of elements to be draw later, only runs once per frame and before wires are drawn
 
- 		/// </summary>
 
- 		/// <param name="drawInfo"></param>
 
- 		public virtual void OnNodeLayout( DrawInfo drawInfo )
 
- 		{
 
- 			if( ContainerGraph.ChangedLightingModel )
 
- 			{
 
- 				m_sizeIsDirty = true;
 
- 				m_firstPreviewDraw = true;
 
- 			}
 
- 			if( m_firstDraw )
 
- 			{
 
- 				m_firstDraw = false;
 
- 				AfterCommonInit();
 
- 				OnNodeChange();
 
- 			}
 
- 			if( m_previousErrorMessage != m_showErrorMessage )
 
- 			{
 
- 				m_sizeIsDirty = true;
 
- 			}
 
- 			if( m_sizeIsDirty )
 
- 			{
 
- 				m_sizeIsDirty = false;
 
- 				ChangeSize();
 
- 				UpdateSortedInputPorts();
 
- 				UpdateSortedOutputPorts();
 
- 			}
 
- 			CalculatePositionAndVisibility( drawInfo );
 
- 			m_unscaledRemainingBox = m_position;
 
- 			m_remainingBox = m_globalPosition;
 
- 			m_lastInputBottomRight = m_position.position;
 
- 			m_lastOutputBottomLeft = m_position.position;
 
- 			m_lastOutputBottomLeft.x += m_position.width;
 
- 			m_visibleInputs = 0;
 
- 			m_visibleOutputs = 0;
 
- 			if( m_hasSubtitle )
 
- 				m_extraHeaderHeight = (int)Constants.NODE_HEADER_EXTRA_HEIGHT;
 
- 			else
 
- 				m_extraHeaderHeight = 0;
 
- 			m_lastInputBottomRight.y += UIUtils.HeaderMaxHeight + m_extraHeaderHeight;
 
- 			m_lastOutputBottomLeft.y += UIUtils.HeaderMaxHeight + m_extraHeaderHeight;
 
- 			m_unscaledRemainingBox.y += UIUtils.HeaderMaxHeight + m_extraHeaderHeight;
 
- 			if( m_isVisible )
 
- 			{
 
- 				// Header
 
- 				m_headerPosition = m_globalPosition;
 
- 				m_headerPosition.height = UIUtils.CurrentHeaderHeight + m_extraHeaderHeight * drawInfo.InvertedZoom;
 
- 				// Title
 
- 				m_titlePos = m_globalPosition;
 
- 				m_titlePos.height = m_headerPosition.height;
 
- 				if( m_hasSubtitle )
 
- 					m_titlePos.yMin += ( 2 * drawInfo.InvertedZoom );
 
- 				else
 
- 					m_titlePos.yMin += ( 8 * drawInfo.InvertedZoom );
 
- 				m_titlePos.width -= ( m_paddingTitleLeft + m_paddingTitleRight ) * drawInfo.InvertedZoom;
 
- 				m_titlePos.x += m_paddingTitleLeft * drawInfo.InvertedZoom;
 
- 				// Additional Title
 
- 				if( m_hasSubtitle )
 
- 				{
 
- 					m_addTitlePos = m_titlePos;
 
- 					m_addTitlePos.y = m_globalPosition.y;
 
- 					m_addTitlePos.yMin += ( 15 * drawInfo.InvertedZoom );
 
- 				}
 
- 				// Left Dropdown
 
- 				if( m_hasLeftDropdown && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 				{
 
- 					m_dropdownRect = m_headerPosition;
 
- 					m_dropdownRect.width = Constants.NodeButtonSizeX * drawInfo.InvertedZoom;
 
- 					m_dropdownRect.x = m_globalPosition.x + ( Constants.IconsLeftRightMargin + 1 ) * drawInfo.InvertedZoom;
 
- 					m_dropdownRect.height = Constants.NodeButtonSizeY * drawInfo.InvertedZoom;
 
- 					m_dropdownRect.y = m_globalPosition.y + m_headerPosition.height * 0.5f - 14 * drawInfo.InvertedZoom * 0.5f;
 
- 				}
 
- 				// Expander
 
- 				if( m_drawPreviewExpander && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 				{
 
- 					m_expandRect = m_globalPosition;
 
- 					m_expandRect.width = Constants.PreviewExpanderWidth * drawInfo.InvertedZoom;
 
- 					m_expandRect.x = m_globalPosition.x + m_globalPosition.width - ( Constants.IconsLeftRightMargin + Constants.PreviewExpanderWidth ) * drawInfo.InvertedZoom; //titlePos.x + titlePos.width;
 
- 					m_expandRect.height = Constants.PreviewExpanderHeight * drawInfo.InvertedZoom;
 
- 					m_expandRect.y = m_globalPosition.y + m_headerPosition.height * 0.5f - Constants.PreviewExpanderHeight * drawInfo.InvertedZoom * 0.5f;
 
- 				}
 
- 			}
 
- 			if( m_anchorAdjust < 0 )
 
- 			{
 
- 				m_anchorAdjust = UIUtils.GetCustomStyle( CustomStyle.PortEmptyIcon ).normal.background.width;
 
- 			}
 
- 			m_unscaledRemainingBox.y += Constants.INPUT_PORT_DELTA_Y;
 
- 			m_lastOutputBottomLeft.y += Constants.INPUT_PORT_DELTA_Y;
 
- 			m_lastInputBottomRight.y += Constants.INPUT_PORT_DELTA_Y;
 
- 			// Input Ports
 
- 			{
 
- 				m_currInputPortPos = m_globalPosition;
 
- 				m_currInputPortPos.width = drawInfo.InvertedZoom * UIUtils.PortsSize.x;
 
- 				m_currInputPortPos.height = drawInfo.InvertedZoom * UIUtils.PortsSize.y;
 
- 				m_currInputPortPos.x += drawInfo.InvertedZoom * Constants.PORT_INITIAL_X;
 
- 				m_currInputPortPos.y += drawInfo.InvertedZoom * Constants.PORT_INITIAL_Y + m_extraHeaderHeight * drawInfo.InvertedZoom;
 
- 				int inputCount = m_sortedInputPorts.Count;
 
- 				float initialX = m_lastInputBottomRight.x;
 
- 				for ( int i = 0; i < inputCount; i++ )
 
- 				{
 
- 					if( m_sortedInputPorts[ i ].Visible )
 
- 					{
 
- 						m_visibleInputs++;
 
- 						// Button
 
- 						m_sortedInputPorts[ i ].Position = m_currInputPortPos;
 
- 						// Label
 
- 						m_sortedInputPorts[ i ].LabelPosition = m_currInputPortPos;
 
- 						float deltaX = 1f * drawInfo.InvertedZoom * ( UIUtils.PortsSize.x + Constants.PORT_TO_LABEL_SPACE_X );
 
- 						m_auxRect = m_sortedInputPorts[ i ].LabelPosition;
 
- 						m_auxRect.x += deltaX;
 
- 						m_sortedInputPorts[ i ].LabelPosition = m_auxRect;
 
- 						//if( m_sortedInputPorts[ i ].DirtyLabelSize || m_sortedInputPorts[ i ].LabelSize == Vector2.zero )
 
- 						//{
 
- 						//	m_sortedInputPorts[ i ].DirtyLabelSize = false;
 
- 						//	m_sizeContentAux.text = m_sortedInputPorts[ i ].Name;
 
- 						//	m_sortedInputPorts[ i ].UnscaledLabelSize = UIUtils.UnZoomedInputPortStyle.CalcSize( m_sizeContentAux );
 
- 						//}
 
- 						m_sortedInputPorts[ i ].LabelSize = m_sortedInputPorts[ i ].UnscaledLabelSize * drawInfo.InvertedZoom;
 
- 						m_lastInputBottomRight.x = Mathf.Max( m_lastInputBottomRight.x, initialX + m_sortedInputPorts[ i ].UnscaledLabelSize.x + Constants.PORT_INITIAL_X + Constants.PORT_TO_LABEL_SPACE_X + UIUtils.PortsSize.x );
 
- 						if( !m_sortedInputPorts[ i ].Locked )
 
- 						{
 
- 							float overflow = 2;
 
- 							float scaledOverflow = 4 * drawInfo.InvertedZoom;
 
- 							m_auxRect = m_currInputPortPos;
 
- 							m_auxRect.yMin -= scaledOverflow + overflow;
 
- 							m_auxRect.yMax += scaledOverflow + overflow;
 
- 							m_auxRect.xMin -= Constants.PORT_INITIAL_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							if( m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid )
 
- 								m_auxRect.xMax += m_sortedInputPorts[ i ].LabelSize.x + Constants.PORT_TO_LABEL_SPACE_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							else
 
- 								m_auxRect.xMax += Constants.PORT_TO_LABEL_SPACE_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							m_sortedInputPorts[ i ].ActivePortArea = m_auxRect;
 
- 						}
 
- 						m_currInputPortPos.y += drawInfo.InvertedZoom * ( m_fontHeight + Constants.INPUT_PORT_DELTA_Y );
 
- 						//GUI.Label( m_sortedInputPorts[ i ].ActivePortArea, string.Empty, UIUtils.Box );
 
- 					}
 
- 				}
 
- 				if( m_visibleInputs > 0 )
 
- 					m_lastInputBottomRight.y += m_fontHeight * m_visibleInputs + Constants.INPUT_PORT_DELTA_Y * ( m_visibleInputs - 1 );
 
- 			}
 
- 			// Output Ports
 
- 			{
 
- 				m_currOutputPortPos = m_globalPosition;
 
- 				m_currOutputPortPos.width = drawInfo.InvertedZoom * UIUtils.PortsSize.x;
 
- 				m_currOutputPortPos.height = drawInfo.InvertedZoom * UIUtils.PortsSize.y;
 
- 				m_currOutputPortPos.x += ( m_globalPosition.width - drawInfo.InvertedZoom * ( Constants.PORT_INITIAL_X + m_anchorAdjust ) );
 
- 				m_currOutputPortPos.y += drawInfo.InvertedZoom * Constants.PORT_INITIAL_Y + m_extraHeaderHeight * drawInfo.InvertedZoom;
 
- 				float initialX = m_lastOutputBottomLeft.x;
 
- 				int outputCount = m_sortedOutputPorts.Count;
 
- 				for ( int i = 0; i < outputCount; i++ )
 
- 				{
 
- 					if( m_sortedOutputPorts[ i ].Visible )
 
- 					{
 
- 						m_visibleOutputs++;
 
- 						//Button
 
- 						m_sortedOutputPorts[ i ].Position = m_currOutputPortPos;
 
- 						// Label
 
- 						m_sortedOutputPorts[ i ].LabelPosition = m_currOutputPortPos;
 
- 						float deltaX = 1f * drawInfo.InvertedZoom * ( UIUtils.PortsSize.x + Constants.PORT_TO_LABEL_SPACE_X );
 
- 						m_auxRect = m_sortedOutputPorts[ i ].LabelPosition;
 
- 						m_auxRect.x -= deltaX;
 
- 						m_sortedOutputPorts[ i ].LabelPosition = m_auxRect;
 
- 						m_sortedOutputPorts[ i ].LabelSize = m_sortedOutputPorts[ i ].UnscaledLabelSize * drawInfo.InvertedZoom;
 
- 						m_lastOutputBottomLeft.x = Mathf.Min( m_lastOutputBottomLeft.x, initialX - m_sortedOutputPorts[ i ].UnscaledLabelSize.x - Constants.PORT_INITIAL_X - Constants.PORT_TO_LABEL_SPACE_X - UIUtils.PortsSize.x );
 
- 						if( !m_sortedOutputPorts[ i ].Locked )
 
- 						{
 
- 							float overflow = 2;
 
- 							float scaledOverflow = 4 * drawInfo.InvertedZoom;
 
- 							m_auxRect = m_currOutputPortPos;
 
- 							m_auxRect.yMin -= scaledOverflow + overflow;
 
- 							m_auxRect.yMax += scaledOverflow + overflow;
 
- 							if( m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid )
 
- 								m_auxRect.xMin -= m_sortedOutputPorts[ i ].LabelSize.x + Constants.PORT_TO_LABEL_SPACE_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							else
 
- 								m_auxRect.xMin -= Constants.PORT_TO_LABEL_SPACE_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							m_auxRect.xMax += Constants.PORT_INITIAL_X * drawInfo.InvertedZoom + scaledOverflow + overflow;
 
- 							m_sortedOutputPorts[ i ].ActivePortArea = m_auxRect;
 
- 						}
 
- 						m_currOutputPortPos.y += drawInfo.InvertedZoom * ( m_fontHeight + Constants.INPUT_PORT_DELTA_Y );
 
- 						//GUI.Label( m_sortedOutputPorts[ i ].ActivePortArea, string.Empty, UIUtils.Box );
 
- 					}
 
- 				}
 
- 				if( m_visibleOutputs > 0 )
 
- 					m_lastOutputBottomLeft.y += m_fontHeight * m_visibleOutputs + Constants.INPUT_PORT_DELTA_Y * ( m_visibleOutputs - 1 );
 
- 			}
 
- 			m_lastInputBottomRight.x += m_marginPreviewLeft;
 
- 			//Vector2 scaledLastOutputBottomLeft = ( m_lastOutputBottomLeft + drawInfo.CameraOffset ) * drawInfo.InvertedZoom;
 
- 			//GUI.Label( new Rect( scaledLastOutputBottomLeft, Vector2.one * 2 ), string.Empty, UIUtils.CurrentWindow.CustomStylesInstance.Box );
 
- 			m_unscaledRemainingBox.xMin = m_lastInputBottomRight.x;
 
- 			//m_unscaledRemainingBox.yMin = m_lastInputBottomRight.y;
 
- 			m_unscaledRemainingBox.xMax = m_lastOutputBottomLeft.x;
 
- 			m_unscaledRemainingBox.yMax = Mathf.Max( m_lastOutputBottomLeft.y, m_lastInputBottomRight.y );
 
- 			m_remainingBox.position = ( m_unscaledRemainingBox.position + drawInfo.CameraOffset ) * drawInfo.InvertedZoom;
 
- 			m_remainingBox.size = m_unscaledRemainingBox.size * drawInfo.InvertedZoom;
 
- 			//GUI.Label( m_remainingBox, string.Empty, UIUtils.Box );
 
- 			if( m_visibleInputs == 0 )
 
- 			{
 
- 				m_remainingBox.x += Constants.PORT_INITIAL_X * drawInfo.InvertedZoom;
 
- 				m_remainingBox.width -= Constants.PORT_INITIAL_X * drawInfo.InvertedZoom;
 
- 			}
 
- 			if( m_visibleOutputs == 0 )
 
- 			{
 
- 				m_remainingBox.width -= Constants.PORT_INITIAL_X * drawInfo.InvertedZoom;
 
- 			}
 
- 			if( ContainerGraph.ParentWindow.GlobalPreview != m_globalShowPreview )
 
- 			{
 
- 				m_globalShowPreview = ContainerGraph.ParentWindow.GlobalPreview;
 
- 				m_sizeIsDirty = true;
 
- 				ContainerGraph.ParentWindow.RequestRepaint();
 
- 			}
 
- 			// Generate Proper Preview Rect
 
- 			float marginAround = 10;
 
- 			float scaledMarginAround = marginAround * drawInfo.InvertedZoom;
 
- 			float previewSize = 128;
 
- 			PreviewLocation m_autoLocation = m_selectedLocation;
 
- 			if( m_selectedLocation == PreviewLocation.Auto )
 
- 			{
 
- 				if( m_visibleOutputs > m_visibleInputs )
 
- 				{
 
- 					m_autoLocation = PreviewLocation.Left;
 
- 				}
 
- 				else if( m_visibleOutputs < m_visibleInputs )
 
- 				{
 
- 					m_autoLocation = PreviewLocation.Right;
 
- 				}
 
- 				else if( m_unscaledRemainingBox.width > previewSize )
 
- 				{
 
- 					m_autoLocation = PreviewLocation.TopCenter;
 
- 				}
 
- 				else
 
- 				{
 
- 					m_autoLocation = PreviewLocation.BottomCenter;
 
- 				}
 
- 			}
 
- 			if( m_canExpand && ( m_showPreview || m_globalShowPreview ) )
 
- 			{
 
- 				if( m_autoLocation == PreviewLocation.TopCenter )
 
- 				{
 
- 					m_unscaledPreviewRect.y = m_unscaledRemainingBox.y;
 
- 					m_unscaledPreviewRect.x = m_unscaledRemainingBox.center.x - 0.5f * ( previewSize + 2 * marginAround );
 
- 				}
 
- 				else if( m_autoLocation == PreviewLocation.BottomCenter )
 
- 				{
 
- 					m_unscaledPreviewRect.y = Mathf.Max( m_lastOutputBottomLeft.y, m_lastInputBottomRight.y );
 
- 					m_unscaledPreviewRect.x = m_position.x + 0.5f * m_position.width - 0.5f * ( previewSize + 2 * marginAround );
 
- 				}
 
- 				else if( m_autoLocation == PreviewLocation.Left )
 
- 				{
 
- 					m_unscaledPreviewRect.y = m_lastInputBottomRight.y;
 
- 					m_unscaledPreviewRect.x = m_position.x;
 
- 				}
 
- 				else if( m_autoLocation == PreviewLocation.Right )
 
- 				{
 
- 					m_unscaledPreviewRect.y = m_lastOutputBottomLeft.y;
 
- 					m_unscaledPreviewRect.x = m_lastInputBottomRight.x;
 
- 				}
 
- 				if( m_autoLocation == PreviewLocation.BottomCenter )
 
- 					m_unscaledPreviewRect.height = previewSize + 2 * marginAround;
 
- 				else if( m_autoLocation == PreviewLocation.TopCenter )
 
- 					m_unscaledPreviewRect.height = previewSize + marginAround;
 
- 				else
 
- 					m_unscaledPreviewRect.height = previewSize + ( m_visibleInputs > 0 && m_visibleOutputs > 0 ? 2 * marginAround : marginAround );
 
- 				m_unscaledPreviewRect.width = previewSize + 2 * marginAround;
 
- 				m_previewRect = m_unscaledPreviewRect;
 
- 				m_previewRect.position = ( m_previewRect.position + drawInfo.CameraOffset ) * drawInfo.InvertedZoom;
 
- 				m_auxVector2.Set( previewSize * drawInfo.InvertedZoom, previewSize * drawInfo.InvertedZoom );
 
- 				m_previewRect.size = m_auxVector2;
 
- 				if( m_autoLocation == PreviewLocation.BottomCenter )
 
- 				{
 
- 					m_auxVector2.Set( m_previewRect.position.x + scaledMarginAround, m_previewRect.position.y + scaledMarginAround );
 
- 					m_previewRect.position = m_auxVector2;
 
- 				}
 
- 				else if( m_autoLocation == PreviewLocation.TopCenter )
 
- 				{
 
- 					m_auxVector2.Set( m_previewRect.position.x + scaledMarginAround, m_previewRect.position.y );
 
- 					m_previewRect.position = m_auxVector2;
 
- 				}
 
- 				else
 
- 				{
 
- 					m_previewRect.position += new Vector2( scaledMarginAround, ( m_visibleInputs > 0 && m_visibleOutputs > 0 ? scaledMarginAround : 0 ) );
 
- 				}
 
- 			}
 
- 			// Adjust node rect after preview
 
- 			if( m_firstPreviewDraw )
 
- 			{
 
- 				m_firstPreviewDraw = false;
 
- 				ContainerGraph.ParentWindow.RequestRepaint();
 
- 				if( m_canExpand && ( m_showPreview || m_globalShowPreview ) )
 
- 				{
 
- 					if( m_autoLocation == PreviewLocation.TopCenter )
 
- 					{
 
- 						float fillWidth = m_unscaledRemainingBox.width - m_unscaledPreviewRect.width;
 
- 						m_extraSize.x = Mathf.Max( -fillWidth, 0 );
 
- 						float fillHeight = m_position.yMax - m_unscaledPreviewRect.yMax;
 
- 						m_extraSize.y = Mathf.Max( -fillHeight, 0 );
 
- 					}
 
- 					if( m_autoLocation == PreviewLocation.BottomCenter )
 
- 					{
 
- 						float fillWidth = m_position.width - m_unscaledPreviewRect.width;
 
- 						m_extraSize.x = Mathf.Max( -fillWidth, 0 );
 
- 						float fillHeight = m_position.yMax - m_unscaledPreviewRect.yMax;
 
- 						m_extraSize.y = Mathf.Max( -fillHeight, 0 );
 
- 					}
 
- 					else if( m_autoLocation == PreviewLocation.Left )
 
- 					{
 
- 						float fillWidth = m_lastOutputBottomLeft.x - m_unscaledPreviewRect.xMax;
 
- 						m_extraSize.x = Mathf.Max( -fillWidth, 0 );
 
- 						float fillHeight = m_position.yMax - m_unscaledPreviewRect.yMax;
 
- 						m_extraSize.y = Mathf.Max( -fillHeight, 0 );
 
- 					}
 
- 					else if( m_autoLocation == PreviewLocation.Right )
 
- 					{
 
- 						float fillWidth = m_position.xMax - m_unscaledPreviewRect.xMax;
 
- 						m_extraSize.x = Mathf.Max( -fillWidth, 0 );
 
- 						float fillHeight = m_position.yMax - m_unscaledPreviewRect.yMax;
 
- 						m_extraSize.y = Mathf.Max( -fillHeight, 0 );
 
- 					}
 
- 					if( m_showErrorMessage )
 
- 						m_extraSize.y += 24;
 
- 				}
 
- 				else if( m_canExpand )
 
- 				{
 
- 					m_extraSize.y = 0;
 
- 					m_extraSize.x = 0;
 
- 				}
 
- 				m_position.width = m_unpreviewedPosition.width + m_extraSize.x;
 
- 				m_position.height = m_unpreviewedPosition.height + m_extraSize.y;
 
- 			}
 
- 			if( m_showErrorMessage )
 
- 			{
 
- 				m_errorBox = m_globalPosition;
 
- 				m_errorBox.y = ( m_globalPosition.yMax - 28 * drawInfo.InvertedZoom ) + 3 * drawInfo.InvertedZoom;
 
- 				m_errorBox.height = 25 * drawInfo.InvertedZoom;
 
- 			}
 
- 			m_previousErrorMessage = m_showErrorMessage;
 
- 		}
 
- 		/// <summary>
 
- 		/// This method should only be called to draw elements, runs once per frame and after wires are drawn
 
- 		/// </summary>
 
- 		/// <param name="drawInfo"></param>
 
- 		public virtual void OnNodeRepaint( DrawInfo drawInfo )
 
- 		{
 
- 			if( !m_isVisible )
 
- 				return;
 
- 			m_colorBuffer = GUI.color;
 
- 			// Background
 
- 			GUI.color = m_infiniteLoopDetected ? Constants.InfiniteLoopColor : Constants.NodeBodyColor;
 
- 			if( m_useSquareNodeTitle || ContainerGraph.LodLevel >= ParentGraph.NodeLOD.LOD2 )
 
- 				GUI.Label( m_globalPosition, string.Empty, UIUtils.NodeWindowOffSquare );
 
- 			else
 
- 				GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeWindowOff ) );
 
- 			// Header
 
- 			//GUI
 
- 			GUI.color = m_headerColor * m_headerColorModifier;
 
- 			if( m_useSquareNodeTitle || ContainerGraph.LodLevel >= ParentGraph.NodeLOD.LOD2 )
 
- 				GUI.Label( m_headerPosition, string.Empty, UIUtils.NodeHeaderSquare );
 
- 			else
 
- 				GUI.Label( m_headerPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeHeader ) );
 
- 			GUI.color = m_colorBuffer;
 
- 			// @diogo: shader function icon
 
- 			var functionNode = this as FunctionNode;
 
- 			if ( functionNode != null )
 
- 			{
 
- 				float scaledSize = FunctionNode.HeaderIconSize * drawInfo.InvertedZoom;
 
- 				GUI.DrawTexture( new Rect( m_globalPosition.x, m_globalPosition.y, scaledSize, scaledSize ), functionNode.HeaderIcon, ScaleMode.ScaleAndCrop, true );
 
- 			}			
 
- 			// Title
 
- 			DrawTitle( m_titlePos );
 
- 			// Additional Tile
 
- 			if( m_hasSubtitle && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
 
- 				GUI.Label( m_addTitlePos, m_additionalContent, UIUtils.GetCustomStyle( CustomStyle.PropertyValuesTitle ) );
 
- 			// Dropdown
 
- 			if( m_hasLeftDropdown && !m_dropdownEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 				GUI.Label( m_dropdownRect, string.Empty, UIUtils.PropertyPopUp );
 
- 			// Expander
 
- 			if( m_drawPreviewExpander && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 				GUI.Label( m_expandRect, string.Empty, ( m_showPreview ? UIUtils.PreviewCollapser : UIUtils.PreviewExpander ) );
 
- 			// Input Ports
 
- 			int inputCount = m_inputPorts.Count;
 
- 			for( int i = 0; i < inputCount; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].Visible )
 
- 				{
 
- 					// Input Port Icon
 
- 					if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 					{
 
- 						if( m_inputPorts[ i ].Locked )
 
- 							GUI.color = Constants.LockedPortColor;
 
- 						else if( ContainerGraph.ParentWindow.Options.ColoredPorts )
 
- 							GUI.color = UIUtils.GetColorForDataType( m_inputPorts[ i ].DataType, false, true );
 
- 						else
 
- 							GUI.color = m_inputPorts[ i ].HasCustomColor ? m_inputPorts[ i ].CustomColor : UIUtils.GetColorForDataType( m_inputPorts[ i ].DataType, true, true );
 
- 						GUIStyle style = m_inputPorts[ i ].IsConnected ? UIUtils.GetCustomStyle( CustomStyle.PortFullIcon ) : UIUtils.GetCustomStyle( CustomStyle.PortEmptyIcon );
 
- 						GUI.Label( m_inputPorts[ i ].Position, string.Empty, style );
 
- 						GUI.color = m_colorBuffer;
 
- 					}
 
- 					// Input Port Label
 
- 					if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
 
- 					{
 
- 						if( m_inputPorts[ i ].Locked )
 
- 						{
 
- 							GUI.color = Constants.PortLockedTextColor;
 
- 							GUI.Label( m_inputPorts[ i ].LabelPosition, m_inputPorts[ i ].Name, UIUtils.InputPortLabel );
 
- 							GUI.color = m_colorBuffer;
 
- 						}
 
- 						else
 
- 						{
 
- 							if( m_containerGraph.ParentWindow.GlobalShowInternalData && !m_inputPorts[ i ].IsConnected && UIUtils.InternalDataOnPort.fontSize > 1f && ( m_inputPorts[ i ].AutoDrawInternalData || ( m_autoDrawInternalPortData && m_useInternalPortData ) ) && m_inputPorts[ i ].DisplayInternalData.Length > 4 && ( ( m_inputPorts[ i ].DataType >= WirePortDataType.FLOAT && m_inputPorts[ i ].DataType <= WirePortDataType.INT ) || m_inputPorts[ i ].DataType == WirePortDataType.UINT ) )
 
- 							{
 
- 								GUI.color = Constants.NodeBodyColor/* * new Color( 1f, 1f, 1f, 0.75f )*/;
 
- 								Rect internalBox = m_inputPorts[ i ].LabelPosition;
 
- 								m_sizeContentAux.text = m_inputPorts[ i ].DisplayInternalData;
 
- 								Vector2 portText = UIUtils.InternalDataOnPort.CalcSize( m_sizeContentAux );
 
- 								internalBox.width = portText.x;
 
- 								internalBox.height = portText.y;
 
- 								internalBox.y = m_inputPorts[ i ].LabelPosition.center.y - internalBox.height * 0.5f;
 
- 								internalBox.x = GlobalPosition.x - internalBox.width - 4 * drawInfo.InvertedZoom - 1;
 
- 								Rect backBox = new Rect( internalBox );
 
- 								backBox.xMin -= 4 * drawInfo.InvertedZoom;
 
- 								backBox.xMax += 4 * drawInfo.InvertedZoom;
 
- 								backBox.yMin -= 2 * drawInfo.InvertedZoom;
 
- 								backBox.yMax += 2 * drawInfo.InvertedZoom;
 
- 								GUI.Label( backBox, string.Empty, UIUtils.InternalDataBackground );
 
- 								GUI.color *= new Color( 1f, 1f, 1f, 0.5f );
 
- 								GUI.Label( internalBox, m_sizeContentAux, UIUtils.InternalDataOnPort );
 
- 								GUI.color = m_colorBuffer;
 
- 							}
 
- 							GUI.Label( m_inputPorts[ i ].LabelPosition, m_inputPorts[ i ].Name, UIUtils.InputPortLabel );
 
- 						}
 
- 					}
 
- 				}
 
- 			}
 
- 			// Output Ports
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].Visible )
 
- 				{
 
- 					// Output Port Icon
 
- 					if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD4 )
 
- 					{
 
- 						if( m_outputPorts[ i ].Locked )
 
- 							GUI.color = Constants.LockedPortColor;
 
- 						else if( ContainerGraph.ParentWindow.Options.ColoredPorts )
 
- 							GUI.color = UIUtils.GetColorForDataType( m_outputPorts[ i ].DataType, false, false );
 
- 						else
 
- 							GUI.color = m_outputPorts[ i ].HasCustomColor ? m_outputPorts[ i ].CustomColor : UIUtils.GetColorForDataType( m_outputPorts[ i ].DataType, true, false );
 
- 						GUIStyle style = m_outputPorts[ i ].IsConnected ? UIUtils.GetCustomStyle( CustomStyle.PortFullIcon ) : UIUtils.GetCustomStyle( CustomStyle.PortEmptyIcon );
 
- 						GUI.Label( m_outputPorts[ i ].Position, string.Empty, style );
 
- 						GUI.color = m_colorBuffer;
 
- 					}
 
- 					// Output Port Label
 
- 					if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
 
- 					{
 
- 						if( m_outputPorts[ i ].Locked )
 
- 						{
 
- 							GUI.color = Constants.PortLockedTextColor;
 
- 							GUI.Label( m_outputPorts[ i ].LabelPosition, m_outputPorts[ i ].Name, UIUtils.OutputPortLabel );
 
- 							GUI.color = m_colorBuffer;
 
- 						}
 
- 						else
 
- 						{
 
- 							GUI.Label( m_outputPorts[ i ].LabelPosition, m_outputPorts[ i ].Name, UIUtils.OutputPortLabel );
 
- 						}
 
- 					}
 
- 				}
 
- 			}
 
- 			// Preview
 
- 			if( ( m_showPreview || m_globalShowPreview ) && m_drawPreview )
 
- 				DrawPreview( drawInfo, m_previewRect );
 
- 			// Error and Warning bottom message
 
- 			if( m_showErrorMessage )
 
- 			{
 
- 				GUI.color = new Color( 0.0f, 0.0f, 0.0f, 0.5f );
 
- 				GUI.Label( m_errorBox, string.Empty, UIUtils.Separator );
 
- 				GUI.color = m_colorBuffer;
 
- 				switch( m_errorMessageTypeIsError )
 
- 				{
 
- 					default:
 
- 					case NodeMessageType.Error:
 
- 					{
 
- 						m_errorMessage.text = ErrorTitle;
 
- 						m_errorIcon.image = UIUtils.SmallErrorIcon;
 
- 						m_errorCurrentStyle = UIUtils.BoldErrorStyle;
 
- 					}
 
- 					break;
 
- 					case NodeMessageType.Warning:
 
- 					{
 
- 						m_errorMessage.text = WarningTitle;
 
- 						m_errorIcon.image = UIUtils.SmallWarningIcon;
 
- 						m_errorCurrentStyle = UIUtils.BoldWarningStyle;
 
- 					}
 
- 					break;
 
- 					case NodeMessageType.Info:
 
- 					{
 
- 						m_errorMessage.text = InfoTitle;
 
- 						m_errorIcon.image = UIUtils.SmallInfoIcon;
 
- 						m_errorCurrentStyle = UIUtils.BoldInfoStyle;
 
- 					}
 
- 					break;
 
- 				}
 
- 				Rect textBox = m_errorBox;
 
- 				textBox.y += 1 * drawInfo.InvertedZoom;
 
- 				textBox.height = 24 * drawInfo.InvertedZoom;
 
- 				float textWidth = m_errorCurrentStyle.CalcSize( m_errorMessage ).x;
 
- 				GUI.Label( textBox, m_errorMessage, m_errorCurrentStyle );
 
- 				textBox.x -= textWidth * 0.5f + 12 * drawInfo.InvertedZoom;
 
- 				GUI.Label( textBox, m_errorIcon, m_errorCurrentStyle );
 
- 				textBox.x += textWidth + 24 * drawInfo.InvertedZoom;
 
- 				GUI.Label( textBox, m_errorIcon, m_errorCurrentStyle );
 
- 			}
 
- 			// Selection Box
 
- 			if( m_selected )
 
- 			{
 
- 				GUI.color = Constants.NodeSelectedColor;
 
- 				if( m_useSquareNodeTitle || ContainerGraph.LodLevel >= ParentGraph.NodeLOD.LOD2 )
 
- 					GUI.Label( m_globalPosition, string.Empty, UIUtils.NodeWindowOnSquare );
 
- 				else
 
- 					GUI.Label( m_globalPosition, string.Empty, UIUtils.GetCustomStyle( CustomStyle.NodeWindowOn ) );
 
- 				GUI.color = m_colorBuffer;
 
- 			}
 
- 			// Debug Visualizers
 
- 			//if( FinishPreviewRender || m_continuousPreviewRefresh )
 
- 			//{
 
- 			//	GUI.color = new Color( 0, 1, 0.5f, 1f );
 
- 			//	Rect r = m_globalPosition;
 
- 			//	r.width = 8;
 
- 			//	r.height = 8;
 
- 			//	r.x -= 5 * drawInfo.InvertedZoom;
 
- 			//	r.y -= 5 * drawInfo.InvertedZoom;
 
- 			//	GUI.Label( r, string.Empty, UIUtils.GetCustomStyle( CustomStyle.PortFullIcon ) );
 
- 			//	GUI.color = m_colorBuffer;
 
- 			//	FinishPreviewRender = false;
 
- 			//}
 
- 			//GUI.Label( m_remainingBox, string.Empty, UIUtils.Box );
 
- 		}
 
- 		public bool DropdownEditing { get { return m_dropdownEditing; } set { m_dropdownEditing = value; PreviewIsDirty = true; } }
 
- 		public void DisablePreview()
 
- 		{
 
- 			m_showPreview = false;
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		/// <summary>
 
- 		/// Handles gui controls, runs before node layout
 
- 		/// </summary>
 
- 		/// <param name="drawInfo"></param>
 
- 		public virtual void DrawGUIControls( DrawInfo drawInfo )
 
- 		{
 
- 			if( !m_initialized )
 
- 				return;
 
- 			if( !m_isVisible )
 
- 				return;
 
- 			if( drawInfo.CurrentEventType == EventType.MouseDown && drawInfo.LeftMouseButtonPressed )
 
- 			{
 
- 				if( m_expandRect.Contains( drawInfo.MousePosition ) )
 
- 				{
 
- 					m_showPreview = !m_showPreview;
 
- 					m_sizeIsDirty = true;
 
- 					ContainerGraph.ParentWindow.MouseInteracted = true;
 
- 				}
 
- 				if( m_hasLeftDropdown && m_dropdownRect.Contains( drawInfo.MousePosition ) )
 
- 				{
 
- 					m_dropdownEditing = true;
 
- 				}
 
- 				else if( m_dropdownEditing )
 
- 				{
 
- 					DropdownEditing = false;
 
- 				}
 
- 			}
 
- 			DrawGuiPorts( drawInfo );
 
- 		}
 
- 		//public static bool MyRepeatButton( DrawInfo drawInfo, Rect position, string text, GUIStyle style )
 
- 		//{
 
- 		//	if(/* drawInfo.CurrentEventType == EventType.MouseDown &&*/ position.Contains( drawInfo.MousePosition ) )
 
- 		//	{
 
- 		//		UIUtils.CurrentWindow.MouseInteracted = true;
 
- 		//		return true;
 
- 		//	}
 
- 		//	return false;
 
- 		//}
 
- 		public void DrawGuiPorts( DrawInfo drawInfo )
 
- 		{
 
- 			if( !m_initialized )
 
- 				return;
 
- 			if( !m_isVisible )
 
- 				return;
 
- 			if( drawInfo.CurrentEventType == EventType.MouseDown )
 
- 			{
 
- 				int inputCount = m_inputPorts.Count;
 
- 				int outputCount = m_outputPorts.Count;
 
- 				for( int i = 0; i < inputCount; i++ )
 
- 				{
 
- 					if( m_inputPorts[ i ].Visible && !m_inputPorts[ i ].Locked && m_isVisible && m_inputPorts[ i ].ActivePortArea.Contains( drawInfo.MousePosition ) && drawInfo.LeftMouseButtonPressed )
 
- 					{
 
- 						UIUtils.CurrentWindow.MouseInteracted = true;
 
- 						m_inputPorts[ i ].Click();
 
- 						// need to put the mouse button on a hot state so it will detect the Mouse Up event correctly on the Editor Window
 
- 						int controlID = GUIUtility.GetControlID( FocusType.Passive );
 
- 						//int controlID = GUIUtility.GetControlID( "repeatButton".GetHashCode(), FocusType.Passive, m_inputPorts[ i ].ActivePortArea );
 
- 						GUIUtility.hotControl = controlID;
 
- 						bool saveReference = true;
 
- 						if( m_inputPorts[ i ].IsConnected )
 
- 						{
 
- 							double doubleTapTime = EditorApplication.timeSinceStartup;
 
- 							bool doubleTap = ( doubleTapTime - m_doubleClickTimestamp ) < DoubleClickTime;
 
- 							m_doubleClickTimestamp = doubleTapTime;
 
- 							if( doubleTap )
 
- 							{
 
- 								m_containerGraph.DeleteConnection( true, UniqueId, m_inputPorts[ i ].PortId, true, true );
 
- 								Event.current.Use();
 
- 							}
 
- 							else
 
- 							//if ( AppyModifierToPort( _inputPorts[ i ], true ) )
 
- 							//{
 
- 							//saveReference = false;
 
- 							//}
 
- 							if( !ApplyModifierToPort( m_inputPorts[ i ], true ) )
 
- 							{
 
- 								UIUtils.ShowContextOnPick = false;
 
- 								PickInput( m_inputPorts[ i ] );
 
- 							}
 
- 							saveReference = false;
 
- 						}
 
- 						if( saveReference && !m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.IsValid )
 
- 						//if ( !modifierApplied && !UIUtils.InputPortReference.IsValid )
 
- 						{
 
- 							m_containerGraph.ParentWindow.WireReferenceUtils.SetInputReference( m_uniqueId, m_inputPorts[ i ].PortId, m_inputPorts[ i ].DataType, m_inputPorts[ i ].TypeLocked );
 
- 						}
 
- 						IsDirty = true;
 
- 						inputCount = m_inputPorts.Count;
 
- 					}
 
- 				}
 
- 				for( int i = 0; i < outputCount; i++ )
 
- 				{
 
- 					if( m_outputPorts[ i ].Visible && m_outputPorts[ i ].ActivePortArea.Contains( drawInfo.MousePosition ) && drawInfo.LeftMouseButtonPressed )
 
- 					{
 
- 						UIUtils.CurrentWindow.MouseInteracted = true;
 
- 						m_outputPorts[ i ].Click();
 
- 						// need to put the mouse button on a hot state so it will detect the Mouse Up event correctly on the Editor Window
 
- 						int controlID = GUIUtility.GetControlID( FocusType.Passive );
 
- 						//int controlID = GUIUtility.GetControlID( "aseRepeatButton".GetHashCode(), FocusType.Passive, m_outputPorts[ i ].ActivePortArea );
 
- 						GUIUtility.hotControl = controlID;
 
- 						bool saveReference = true;
 
- 						if( m_outputPorts[ i ].IsConnected )
 
- 						{
 
- 							if( ApplyModifierToPort( m_outputPorts[ i ], false ) )
 
- 							{
 
- 								saveReference = false;
 
- 							}
 
- 						}
 
- 						if( saveReference && !m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.IsValid )
 
- 						{
 
- 							m_containerGraph.ParentWindow.WireReferenceUtils.SetOutputReference( m_uniqueId, m_outputPorts[ i ].PortId, m_outputPorts[ i ].DataType, false );
 
- 						}
 
- 						IsDirty = true;
 
- 						outputCount = m_outputPorts.Count;
 
- 					}
 
- 				}
 
- 			}
 
- 			//Preview buttons
 
- 			if( m_drawPreviewMaskButtons && ( drawInfo.CurrentEventType == EventType.MouseDown || drawInfo.CurrentEventType == EventType.MouseUp ) )
 
- 				DrawPreviewMaskButtonsLayout( drawInfo, m_previewRect );
 
- 		}
 
- 		/// <summary>
 
- 		/// Can be used to draw an entire node, runs after wires
 
- 		/// </summary>
 
- 		/// <param name="drawInfo"></param>
 
- 		public virtual void Draw( DrawInfo drawInfo )
 
- 		{
 
- 			if( !m_initialized )
 
- 				return;
 
- 			if( drawInfo.CurrentEventType == EventType.Repaint )
 
- 				OnNodeRepaint( drawInfo );
 
- 		}
 
- 		public virtual void SetPreviewInputs()
 
- 		{
 
- 			if( !HasPreviewShader || !m_initialized )
 
- 				return;
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].IsConnected && m_inputPorts[ i ].InputNodeHasPreview( ContainerGraph ) )
 
- 				{
 
- 					m_inputPorts[ i ].SetPreviewInputTexture( ContainerGraph );
 
- 				}
 
- 				else
 
- 				{
 
- 					m_inputPorts[ i ].SetPreviewInputValue( ContainerGraph );
 
- 				}
 
- 			}
 
- 		}
 
- 		public bool SafeDraw( DrawInfo drawInfo )
 
- 		{
 
- 			EditorGUI.BeginChangeCheck();
 
- 			Draw( drawInfo );
 
- 			if( EditorGUI.EndChangeCheck() )
 
- 			{
 
- 				SaveIsDirty = true;
 
- 				return true;
 
- 			}
 
- 			return false;
 
- 		}
 
- 		public bool ShowTooltip( DrawInfo drawInfo )
 
- 		{
 
- 			if( string.IsNullOrEmpty( m_tooltipText ) )
 
- 				return false;
 
- 			if( m_globalPosition.Contains( drawInfo.MousePosition ) || m_linkVisibility )
 
- 			{
 
- 				if( m_tooltipTimestamp + 0.6f < Time.realtimeSinceStartup || m_linkVisibility )
 
- 				{
 
- 					bool errorTooltip = false;
 
- 					if( m_showErrorMessage && m_errorBox.Contains( drawInfo.MousePosition ) && !string.IsNullOrEmpty( m_errorMessageTooltip ) )
 
- 						errorTooltip = true;
 
- 					Rect globalTooltipPos = m_globalPosition;
 
- 					GUIContent temp = new GUIContent( errorTooltip ? m_errorMessageTooltip : m_tooltipText );
 
- 					UIUtils.TooltipBox.wordWrap = false;
 
- 					Vector2 optimal = UIUtils.TooltipBox.CalcSize( temp );
 
- 					if( optimal.x > 300f )
 
- 					{
 
- 						UIUtils.TooltipBox.wordWrap = true;
 
- 						optimal.x = 300f;
 
- 						optimal.y = UIUtils.TooltipBox.CalcHeight( temp, 300f );
 
- 					}
 
- 					globalTooltipPos.width = Mathf.Max( 120, optimal.x );
 
- 					globalTooltipPos.height = optimal.y;
 
- 					globalTooltipPos.center = m_globalPosition.center;
 
- 					if( !errorTooltip && m_hasTooltipLink )
 
- 						globalTooltipPos.height += 16;
 
- 					if( errorTooltip )
 
- 						globalTooltipPos.y = 10 + m_globalPosition.yMax;
 
- 					else
 
- 						globalTooltipPos.y = m_globalPosition.yMin - 10 - globalTooltipPos.height;
 
- 					if ( globalTooltipPos.x < 10 )
 
- 						globalTooltipPos.x = 10;
 
- 					if( globalTooltipPos.x + globalTooltipPos.width > Screen.width - 10 )
 
- 						globalTooltipPos.x = Screen.width - globalTooltipPos.width - 10;
 
- 					//UNCOMMENT this for auto adjust tooltip to the top window box
 
- 					//if( globalTooltipPos.y < 40 )
 
- 					//	globalTooltipPos.y = 40;
 
- 					if( errorTooltip && globalTooltipPos.y + globalTooltipPos.height > Screen.height - 32 )
 
- 						globalTooltipPos.y = Screen.height - 32 - globalTooltipPos.height;
 
- 					GUI.Label( globalTooltipPos, temp, UIUtils.TooltipBox );
 
- 					if( !errorTooltip && m_hasTooltipLink )
 
- 					{
 
- 						Rect link = globalTooltipPos;
 
- 						link.y = globalTooltipPos.yMax - 16;
 
- 						link.height = 16;
 
- 						link.width = 86;
 
- 						link.x = globalTooltipPos.center.x - 43;
 
- 						Rect hover = globalTooltipPos;
 
- 						hover.yMax += 15;// m_globalPosition.yMax;
 
- 						m_linkVisibility = hover.Contains( drawInfo.MousePosition );
 
- 						if( link.Contains( drawInfo.MousePosition ) )
 
- 						{
 
- 							if( drawInfo.CurrentEventType == EventType.MouseDown )
 
- 							{
 
- 								if( m_tooltipTimestamp + 1.25f < Time.realtimeSinceStartup )
 
- 								{
 
- 									Application.OpenURL( Attributes.NodeUrl );
 
- 								}
 
- 							}
 
- 							else
 
- 							{
 
- 								UIUtils.MainSkin.customStyles[ 52 ].Draw( link, WikiLinkStr, true, false, false, false );
 
- 							}
 
- 						}
 
- 						else
 
- 						{
 
- 							GUI.Label( link, WikiLinkStr, UIUtils.MainSkin.customStyles[ 52 ] );
 
- 						}
 
- 					}
 
- 					ContainerGraph.ParentWindow.RequestRepaint();
 
- 					return true;
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				if( !m_linkVisibility )
 
- 					m_tooltipTimestamp = Time.realtimeSinceStartup;
 
- 			}
 
- 			return false;
 
- 		}
 
- 		public virtual bool SafeDrawProperties()
 
- 		{
 
- 			EditorGUI.BeginChangeCheck();
 
- 			PreDrawProperties();
 
- 			if( m_autoWrapProperties )
 
- 			{
 
- 				NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, DrawProperties );
 
- 			}
 
- 			else
 
- 			{
 
- 				DrawProperties();
 
- 			}
 
- 			if( EditorGUI.EndChangeCheck() )
 
- 			{
 
- 				PreviewIsDirty = true;
 
- 				//UIUtils.RecordObject(this);
 
- 				//MarkForPreviewUpdate();
 
- 				return true;
 
- 			}
 
- 			return false;
 
- 		}
 
- 		public void PreDrawProperties()
 
- 		{
 
- 			if( m_useInternalPortData && m_autoDrawInternalPortData )
 
- 			{
 
- 				DrawInternalDataGroup();
 
- 			}
 
- 		}
 
- 		virtual public void DrawProperties() { }
 
- 		protected void DrawInternalDataGroup()
 
- 		{
 
- 			bool drawInternalDataUI = false;
 
- 			int inputCount = m_inputPorts.Count;
 
- 			if( inputCount > 0 )
 
- 			{
 
- 				for( int i = 0; i < inputCount; i++ )
 
- 				{
 
- 					if( m_inputPorts[ i ].Available && m_inputPorts[ i ].ValidInternalData && !m_inputPorts[ i ].IsConnected /*&& ( m_inputPorts[ i ].AutoDrawInternalData || ( m_autoDrawInternalPortData && m_useInternalPortData ) )*/  /*&& m_inputPorts[ i ].AutoDrawInternalData*/ )
 
- 					{
 
- 						drawInternalDataUI = true;
 
- 						break;
 
- 					}
 
- 				}
 
- 			}
 
- 			if( drawInternalDataUI )
 
- 				NodeUtils.DrawPropertyGroup( ref m_internalDataFoldout, Constants.InternalDataLabelStr, () =>
 
- 				{
 
- 					for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 					{
 
- 						if( m_inputPorts[ i ].ValidInternalData && !m_inputPorts[ i ].IsConnected && m_inputPorts[ i ].Visible /*&& m_inputPorts[ i ].AutoDrawInternalData*/ )
 
- 						{
 
- 							m_inputPorts[ i ].ShowInternalData( this );
 
- 						}
 
- 					}
 
- 				} );
 
- 		}
 
- 		protected void PickInput( InputPort port )
 
- 		{
 
- 			WireReference connection = port.GetConnection( 0 );
 
- 			OutputPort from = port.GetOutputConnection( 0 );
 
- 			m_containerGraph.ParentWindow.WireReferenceUtils.OutputPortReference.SetReference( from.NodeId, from.PortId, from.DataType, connection.TypeLocked );
 
- 			m_containerGraph.DeleteConnection( true, UniqueId, port.PortId, true, true );
 
- 			//TODO: check if not necessary
 
- 			Event.current.Use();
 
- 			IsDirty = true;
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		protected bool ApplyModifierToPort( WirePort port, bool isInput )
 
- 		{
 
- 			bool modifierApplied = false;
 
- 			switch( Event.current.modifiers )
 
- 			{
 
- 				case EventModifiers.Alt:
 
- 				{
 
- 					m_containerGraph.DeleteConnection( isInput, UniqueId, port.PortId, true, true );
 
- 					modifierApplied = true;
 
- 					m_containerGraph.ParentWindow.InvalidateAlt();
 
- 				}
 
- 				break;
 
- 				case EventModifiers.Control:
 
- 				{
 
- 					//WireReference connection = port.GetConnection( 0 );
 
- 					//if ( isInput )
 
- 					//{
 
- 					//	UIUtils.OutputPortReference.SetReference( connection.NodeId, connection.PortId, connection.DataType, connection.TypeLocked );
 
- 					//}
 
- 					//else
 
- 					//{
 
- 					//	UIUtils.InputPortReference.SetReference( connection.NodeId, connection.PortId, connection.DataType, connection.TypeLocked );
 
- 					//}
 
- 					//UIUtils.DeleteConnection( isInput, UniqueId, port.PortId, true );
 
- 					//modifierApplied = true;
 
- 					if( !isInput )
 
- 					{
 
- 						WireReference connection = port.GetConnection( 0 );
 
- 						m_containerGraph.ParentWindow.WireReferenceUtils.InputPortReference.SetReference( connection.NodeId, connection.PortId, connection.DataType, connection.TypeLocked );
 
- 						m_containerGraph.DeleteConnection( isInput, UniqueId, port.PortId, true, true );
 
- 						modifierApplied = true;
 
- 					}
 
- 				}
 
- 				break;
 
- 			}
 
- 			if( isInput )
 
- 				m_containerGraph.ParentWindow.WireReferenceUtils.SwitchPortReference.SetReference( port.NodeId, port.PortId, port.DataType, false ); //always save last connection
 
- 			else
 
- 				m_containerGraph.ParentWindow.WireReferenceUtils.SwitchPortReference.SetReference( -1, -1, WirePortDataType.OBJECT, false ); //invalidate connection
 
- 			if( modifierApplied )
 
- 			{
 
- 				Event.current.Use();
 
- 				IsDirty = true;
 
- 				SetSaveIsDirty();
 
- 			}
 
- 			return modifierApplied;
 
- 		}
 
- 		public void DeleteAllInputConnections( bool alsoDeletePorts , bool inhibitWireNodeAutoDel = false )
 
- 		{
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].IsConnected )
 
- 				{
 
- 					ParentNode connNode = null;
 
- 					if( inhibitWireNodeAutoDel )
 
- 					{
 
- 						connNode = m_inputPorts[ i ].GetOutputNode();
 
- 						connNode.Alive = false;
 
- 					}
 
- 					m_containerGraph.DeleteConnection( true, UniqueId, m_inputPorts[ i ].PortId, false, true );
 
- 					if( inhibitWireNodeAutoDel )
 
- 					{
 
- 						connNode.Alive = true;
 
- 					}
 
- 				}
 
- 			}
 
- 			if( alsoDeletePorts )
 
- 			{
 
- 				m_inputPorts.Clear();
 
- 				m_inputPortsDict.Clear();
 
- 			}
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		public void DeleteAllOutputConnections( bool alsoDeletePorts )
 
- 		{
 
- 			int count = m_outputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].IsConnected )
 
- 					m_containerGraph.DeleteConnection( false, UniqueId, m_outputPorts[ i ].PortId, false, true );
 
- 			}
 
- 			if( alsoDeletePorts )
 
- 			{
 
- 				m_outputPorts.Clear();
 
- 				m_outputPortsDict.Clear();
 
- 			}
 
- 			SetSaveIsDirty();
 
- 		}
 
- 		public void DeleteInputPortByArrayIdx( int arrayIdx )
 
- 		{
 
- 			if( arrayIdx >= m_inputPorts.Count )
 
- 				return;
 
- 			m_containerGraph.DeleteConnection( true, UniqueId, m_inputPorts[ arrayIdx ].PortId, false, true );
 
- 			m_inputPortsDict.Remove( m_inputPorts[ arrayIdx ].PortId );
 
- 			m_inputPorts.RemoveAt( arrayIdx );
 
- 			m_sizeIsDirty = true;
 
- 			SetSaveIsDirty();
 
- 			RecalculateInputPortIdx();
 
- 		}
 
- 		public void DeleteOutputPortByArrayIdx( int portIdx )
 
- 		{
 
- 			if( portIdx >= m_outputPorts.Count )
 
- 				return;
 
- 			m_containerGraph.DeleteConnection( false, UniqueId, m_outputPorts[ portIdx ].PortId, false, true );
 
- 			m_outputPortsDict.Remove( m_outputPorts[ portIdx ].PortId );
 
- 			m_outputPorts.RemoveAt( portIdx );
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		public InputPort GetInputPortByArrayId( int id )
 
- 		{
 
- 			if( id < m_inputPorts.Count )
 
- 				return m_inputPorts[ id ];
 
- 			return null;
 
- 		}
 
- 		public OutputPort GetOutputPortByArrayId( int id )
 
- 		{
 
- 			if( id < m_outputPorts.Count )
 
- 				return m_outputPorts[ id ];
 
- 			return null;
 
- 		}
 
- 		public InputPort GetInputPortByUniqueId( int id )
 
- 		{
 
- 			if( m_inputPortsDict.ContainsKey( id ) )
 
- 				return m_inputPortsDict[ id ];
 
- 			if( m_inputPortsDict.Count != m_inputPorts.Count )
 
- 				m_repopulateDictionaries = true;
 
- 			int inputCount = m_inputPorts.Count;
 
- 			for( int i = 0; i < inputCount; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].PortId == id )
 
- 				{
 
- 					return m_inputPorts[ i ];
 
- 				}
 
- 			}
 
- 			return null;
 
- 		}
 
- 		public InputPort GetInputPortByName( string name )
 
- 		{
 
- 			return InputPorts.Find( x => x.Name.Equals( name ) );
 
- 		}
 
- 		public InputPort GetInputPortByExternalLinkId( string internalDataName )
 
- 		{
 
- 			return InputPorts.Find( x => x.ExternalLinkId.Equals( internalDataName ) );
 
- 		}
 
- 		public OutputPort GetOutputPortByUniqueId( int id )
 
- 		{
 
- 			if( m_outputPortsDict.ContainsKey( id ) )
 
- 				return m_outputPortsDict[ id ];
 
- 			if( m_outputPortsDict.Count != m_outputPorts.Count )
 
- 				m_repopulateDictionaries = true;
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				if( m_outputPorts[ i ].PortId == id )
 
- 					return m_outputPorts[ i ];
 
- 			}
 
- 			return null;
 
- 		}
 
- 		public virtual void AfterDuplication(){}
 
- 		public override string ToString()
 
- 		{
 
- 			string dump = "";
 
- 			dump += ( "Type: " + GetType() );
 
- 			dump += ( " Unique Id: " + UniqueId + "\n" );
 
- 			dump += ( " Inputs: \n" );
 
- 			int inputCount = m_inputPorts.Count;
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int inputIdx = 0; inputIdx < inputCount; inputIdx++ )
 
- 			{
 
- 				dump += ( m_inputPorts[ inputIdx ] + "\n" );
 
- 			}
 
- 			dump += ( "Outputs: \n" );
 
- 			for( int outputIdx = 0; outputIdx < outputCount; outputIdx++ )
 
- 			{
 
- 				dump += ( m_outputPorts[ outputIdx ] + "\n" );
 
- 			}
 
- 			return dump;
 
- 		}
 
- 		public string GetValueFromOutputStr( int outputId, WirePortDataType inputPortType, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
 
- 		{
 
- 			if( ignoreLocalvar )
 
- 			{
 
- 				return GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
 
- 			}
 
- 			OutputPort outPort = GetOutputPortByUniqueId( outputId );
 
- 			if( outPort.IsLocalValue( dataCollector.PortCategory ) )
 
- 			{
 
- 				if( outPort.DataType != WirePortDataType.OBJECT && outPort.DataType != inputPortType )
 
- 				{
 
- 					return UIUtils.CastPortType( ref dataCollector, CurrentPrecisionType, null, outPort.DataType, inputPortType, outPort.LocalValue( dataCollector.PortCategory ) );
 
- 				}
 
- 				else
 
- 				{
 
- 					return outPort.LocalValue( dataCollector.PortCategory );
 
- 				}
 
- 			}
 
- 			string result = GenerateShaderForOutput( outputId, ref dataCollector, ignoreLocalvar );
 
- 			result = CreateOutputLocalVariable( outputId, result, ref dataCollector );
 
- 			if( outPort.DataType != WirePortDataType.OBJECT && outPort.DataType != inputPortType )
 
- 			{
 
- 				result = UIUtils.CastPortType( ref dataCollector, CurrentPrecisionType, null, outPort.DataType, inputPortType, result );
 
- 			}
 
- 			return result;
 
- 		}
 
- 		public virtual string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
 
- 		{
 
- 			if( dataCollector.IsSRP )
 
- 			{
 
- 				switch( dataCollector.CurrentSRPType )
 
- 				{
 
- 					case TemplateSRPType.HDRP: if(OnHDAction!=null) OnHDAction( outputId, ref dataCollector ); break;
 
- 					case TemplateSRPType.URP:if(OnLightweightAction != null) OnLightweightAction( outputId, ref dataCollector ); break;	
 
- 				}
 
- 			}
 
- 			return string.Empty;
 
- 		}
 
- 		public string GenerateValueInVertex( ref MasterNodeDataCollector dataCollector, WirePortDataType dataType, string dataValue, string dataName, bool createInterpolator )
 
- 		{
 
- 			if( !dataCollector.IsFragmentCategory )
 
- 				return dataValue;
 
- 			//TEMPLATES
 
- 			if( dataCollector.IsTemplate )
 
- 			{
 
- 				if( createInterpolator && dataCollector.TemplateDataCollectorInstance.HasCustomInterpolatedData( dataName ) )
 
- 					return dataName;
 
- 				MasterNodePortCategory category = dataCollector.PortCategory;
 
- 				dataCollector.PortCategory = MasterNodePortCategory.Vertex;
 
- 				dataCollector.PortCategory = category;
 
- 				if( createInterpolator )
 
- 				{
 
- 					dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( dataName, dataType, CurrentPrecisionType, dataValue );
 
- 				}
 
- 				else
 
- 				{
 
- 					dataCollector.AddToVertexLocalVariables( -1, CurrentPrecisionType, dataType, dataName, dataValue );
 
- 				}
 
- 				return dataName;
 
- 			}
 
- 			//SURFACE 
 
- 			{
 
- 				if( dataCollector.TesselationActive )
 
- 				{
 
- 					UIUtils.ShowMessage( UniqueId, "Unable to use Vertex to Frag when Tessellation is active" );
 
- 					return m_outputPorts[ 0 ].ErrorValue;
 
- 				}
 
- 				if( createInterpolator )
 
- 					dataCollector.AddToInput( UniqueId, dataName, dataType, CurrentPrecisionType );
 
- 				MasterNodePortCategory portCategory = dataCollector.PortCategory;
 
- 				dataCollector.PortCategory = MasterNodePortCategory.Vertex;
 
- 				if( createInterpolator )
 
- 				{
 
- 					dataCollector.AddLocalVariable( UniqueId, Constants.VertexShaderOutputStr + "." + dataName, dataValue + ";" );
 
- 				}
 
- 				else
 
- 				{
 
- 					dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, dataType, dataName, dataValue );
 
- 				}
 
- 				dataCollector.PortCategory = portCategory;
 
- 				return createInterpolator ? Constants.InputVarStr + "." + dataName : dataName;
 
- 			}
 
- 		}
 
- 		public string GenerateInputInVertex( ref MasterNodeDataCollector dataCollector , int inputPortUniqueId , string varName , bool createInterpolator , bool noInterpolationFlag = false , bool sampleFlag = false )
 
- 		{
 
- 			InputPort inputPort = GetInputPortByUniqueId( inputPortUniqueId );
 
- 			if( !dataCollector.IsFragmentCategory )
 
- 			{
 
- 				string value = inputPort.GeneratePortInstructions( ref dataCollector );
 
- 				dataCollector.AddLocalVariable( -1 , CurrentPrecisionType , inputPort.DataType , varName , value );
 
- 				return varName;
 
- 			}
 
- 			//TEMPLATES
 
- 			if( dataCollector.IsTemplate )
 
- 			{
 
- 				if( createInterpolator && dataCollector.TemplateDataCollectorInstance.HasCustomInterpolatedData( varName ) )
 
- 					return varName;
 
- 				MasterNodePortCategory category = dataCollector.PortCategory;
 
- 				dataCollector.PortCategory = MasterNodePortCategory.Vertex;
 
- 				//bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;
 
- 				//ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
 
- 				string data = inputPort.GeneratePortInstructions( ref dataCollector );
 
- 				dataCollector.PortCategory = category;
 
- 				//if( !dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables )
 
- 				//{
 
- 				//	dataCollector.AddVertexInstruction( dataCollector.VertexLocalVariablesFromList, UniqueId, false );
 
- 				//	dataCollector.ClearVertexLocalVariables();
 
- 				//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
 
- 				//}
 
- 				//ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Fragment );
 
- 				if( createInterpolator )
 
- 				{
 
- 					dataCollector.TemplateDataCollectorInstance.RegisterCustomInterpolatedData( varName, inputPort.DataType, CurrentPrecisionType, data,true,MasterNodePortCategory.Fragment,noInterpolationFlag,sampleFlag );
 
- 				}
 
- 				else
 
- 				{
 
- 					dataCollector.AddToVertexLocalVariables( -1, CurrentPrecisionType, inputPort.DataType, varName, data );
 
- 				}
 
- 				return varName;
 
- 			}
 
- 			//SURFACE 
 
- 			{
 
- 				if( dataCollector.TesselationActive )
 
- 				{
 
- 					UIUtils.ShowMessage( UniqueId, "Unable to use Vertex to Frag when Tessellation is active" );
 
- 					return m_outputPorts[ 0 ].ErrorValue;
 
- 				}
 
- 				if( createInterpolator )
 
- 					dataCollector.AddToInput( UniqueId, varName, inputPort.DataType, CurrentPrecisionType );
 
- 				MasterNodePortCategory portCategory = dataCollector.PortCategory;
 
- 				dataCollector.PortCategory = MasterNodePortCategory.Vertex;
 
- 				//bool dirtyVertexVarsBefore = dataCollector.DirtyVertexVariables;
 
- 				//ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
 
- 				string vertexVarValue = inputPort.GeneratePortInstructions( ref dataCollector );
 
- 				if( createInterpolator )
 
- 				{
 
- 					dataCollector.AddLocalVariable( UniqueId, Constants.VertexShaderOutputStr + "." + varName, vertexVarValue + ";" );
 
- 				}
 
- 				else
 
- 				{
 
- 					dataCollector.AddLocalVariable( UniqueId, CurrentPrecisionType, inputPort.DataType, varName, vertexVarValue );
 
- 				}
 
- 				dataCollector.PortCategory = portCategory;
 
- 				//if( !dirtyVertexVarsBefore && dataCollector.DirtyVertexVariables )
 
- 				//{
 
- 				//	dataCollector.AddVertexInstruction( dataCollector.VertexLocalVariables, UniqueId, false );
 
- 				//	dataCollector.ClearVertexLocalVariables();
 
- 				//	ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Vertex );
 
- 				//}
 
- 				//ContainerGraph.ResetNodesLocalVariablesIfNot( this, MasterNodePortCategory.Fragment );
 
- 				return createInterpolator ? Constants.InputVarStr + "." + varName : varName;
 
- 			}
 
- 		}
 
- 		protected virtual void OnUniqueIDAssigned() { }
 
- 		public string CreateOutputLocalVariable( int outputArrayId, string value, ref MasterNodeDataCollector dataCollector )
 
- 		{
 
- 			OutputPort port = GetOutputPortByUniqueId( outputArrayId );
 
- 			if( port.IsLocalValue( dataCollector.PortCategory ) )
 
- 				return port.LocalValue( dataCollector.PortCategory );
 
- 			if( port.ConnectionCount > 1 )
 
- 			{
 
- 				RegisterLocalVariable( outputArrayId, value, ref dataCollector );
 
- 				return port.LocalValue( dataCollector.PortCategory );
 
- 			}
 
- 			else
 
- 			{
 
- 				// revisit later (break to components case)
 
- 				port.SetLocalValue( value, dataCollector.PortCategory );
 
- 			}
 
- 			return value;
 
- 		}
 
- 		public void RegisterLocalVariable( int outputArrayId, string value, ref MasterNodeDataCollector dataCollector, string customName = null )
 
- 		{
 
- 			OutputPort port = GetOutputPortByUniqueId( outputArrayId );
 
- 			if( (int)port.DataType >= (int)( 1 << 10 ) || port.DataType == WirePortDataType.OBJECT ) //10 is the flag start of sampler types
 
- 			{
 
- 				port.SetLocalValue( value, dataCollector.PortCategory );
 
- 				return;
 
- 			}
 
- 			bool vertexMode = dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation;
 
- 			string localVar = port.ConfigOutputLocalValue( CurrentPrecisionType, value, customName, dataCollector.PortCategory );
 
- 			if( vertexMode )
 
- 			{
 
- 				dataCollector.AddToVertexLocalVariables( m_uniqueId, localVar );
 
- 			}
 
- 			else
 
- 			{
 
- 				dataCollector.AddToFragmentLocalVariables( m_uniqueId, localVar );
 
- 			}
 
- 		}
 
- 		public void InvalidateConnections()
 
- 		{
 
- 			int inputCount = m_inputPorts.Count;
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < inputCount; i++ )
 
- 			{
 
- 				m_inputPorts[ i ].InvalidateAllConnections();
 
- 			}
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				m_outputPorts[ i ].InvalidateAllConnections();
 
- 			}
 
- 		}
 
- 		public virtual bool OnClick( Vector2 currentMousePos2D )
 
- 		{
 
- 			bool singleClick = true;
 
- 			if( ( EditorApplication.timeSinceStartup - m_lastTimeSelected ) < NodeClickTime )
 
- 			{
 
- 				OnNodeDoubleClicked( currentMousePos2D );
 
- 				singleClick = false;
 
- 			}
 
- 			m_lastTimeSelected = EditorApplication.timeSinceStartup;
 
- 			return singleClick;
 
- 		}
 
- 		public virtual void OnNodeDoubleClicked( Vector2 currentMousePos2D )
 
- 		{
 
- 			ContainerGraph.ParentWindow.ParametersWindow.IsMaximized = !ContainerGraph.ParentWindow.ParametersWindow.IsMaximized;
 
- 		}
 
- 		public virtual void OnNodeSelected( bool value )
 
- 		{
 
- 			if( !value )
 
- 			{
 
- 				if( m_inputPorts != null )
 
- 				{
 
- 					int count = m_inputPorts.Count;
 
- 					for( int i = 0; i < count; i++ )
 
- 					{
 
- 						m_inputPorts[ i ].ResetEditing();
 
- 					}
 
- 				}
 
- 				if( m_outputPorts != null )
 
- 				{
 
- 					int count = m_outputPorts.Count;
 
- 					for( int i = 0; i < count; i++ )
 
- 					{
 
- 						m_outputPorts[ i ].ResetEditing();
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		public void ResetOutputLocals()
 
- 		{
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				m_outputPorts[ i ].ResetLocalValue();
 
- 			}
 
- 		}
 
- 		public void ResetOutputLocalsIfNot( MasterNodePortCategory category )
 
- 		{
 
- 			int outputCount = m_outputPorts.Count;
 
- 			for( int i = 0; i < outputCount; i++ )
 
- 			{
 
- 				//if( !m_outputPorts[ i ].IsLocalOnCategory( category ) )
 
- 				//	m_outputPorts[ i ].ResetLocalValue();
 
- 				m_outputPorts[ i ].ResetLocalValueIfNot( category );
 
- 			}
 
- 		}
 
- 		public virtual void Rewire() { }
 
- 		//public virtual List<int> NodeReferences { get { return null; } }
 
- 		public int UniqueId
 
- 		{
 
- 			get { return m_uniqueId; }
 
- 			set
 
- 			{
 
- 				m_uniqueId = value;
 
- 				int inputCount = m_inputPorts.Count;
 
- 				int outputCount = m_outputPorts.Count;
 
- 				for( int inputIdx = 0; inputIdx < inputCount; inputIdx++ )
 
- 				{
 
- 					m_inputPorts[ inputIdx ].NodeId = value;
 
- 				}
 
- 				for( int outputIdx = 0; outputIdx < outputCount; outputIdx++ )
 
- 				{
 
- 					m_outputPorts[ outputIdx ].NodeId = value;
 
- 				}
 
- 				OnUniqueIDAssigned();
 
- 			}
 
- 		}
 
- 		public void SetBaseUniqueId( int uniqueId, bool setOnPorts = false )
 
- 		{
 
- 			m_uniqueId = uniqueId;
 
- 			if( setOnPorts )
 
- 			{
 
- 				int inputCount = m_inputPorts.Count;
 
- 				int outputCount = m_outputPorts.Count;
 
- 				for( int inputIdx = 0; inputIdx < inputCount; inputIdx++ )
 
- 				{
 
- 					m_inputPorts[ inputIdx ].NodeId = uniqueId;
 
- 				}
 
- 				for( int outputIdx = 0; outputIdx < outputCount; outputIdx++ )
 
- 				{
 
- 					m_outputPorts[ outputIdx ].NodeId = uniqueId;
 
- 				}
 
- 			}
 
- 		}
 
- 		public string OutputId
 
- 		{
 
- 			get
 
- 			{
 
- 				if( ContainerGraph.GraphId > 0 )
 
- 					return UniqueId + "_g" + ContainerGraph.GraphId;
 
- 				else
 
- 					return UniqueId.ToString();
 
- 			}
 
- 		}
 
- 		public virtual Rect Position { get { return m_position; } }
 
- 		public Rect TruePosition { get { return m_position; } }
 
- 		public Vector2 CenterPosition { get { return new Vector2( m_position.x + m_position.width * 0.5f, m_position.y + m_position.height * 0.5f ); ; } }
 
- 		public Rect GlobalPosition { get { return m_globalPosition; } }
 
- 		public Vector2 Corner { get { return new Vector2( m_position.x + m_position.width, m_position.y + m_position.height ); } }
 
- 		public Vector2 Vec2Position
 
- 		{
 
- 			get { return new Vector2( m_position.x, m_position.y ); }
 
- 			set
 
- 			{
 
- 				m_position.x = value.x;
 
- 				m_position.y = value.y;
 
- 			}
 
- 		}
 
- 		public Vector3 Vec3Position
 
- 		{
 
- 			get { return new Vector3( m_position.x, m_position.y, 0f ); }
 
- 			set
 
- 			{
 
- 				m_position.x = value.x;
 
- 				m_position.y = value.y;
 
- 			}
 
- 		}
 
- 		public bool Selected
 
- 		{
 
- 			get { return m_selected; }
 
- 			set
 
- 			{
 
- 				m_infiniteLoopDetected = false;
 
- 				m_selected = value;
 
- 				OnNodeSelected( value );
 
- 			}
 
- 		}
 
- 		public List<InputPort> InputPorts { get { return m_inputPorts; } }
 
- 		public List<OutputPort> OutputPorts
 
- 		{
 
- 			get { return m_outputPorts; }
 
- 		}
 
- 		public bool IsConnected { get { return m_connStatus == NodeConnectionStatus.Connected; } }
 
- 		public NodeConnectionStatus ConnStatus
 
- 		{
 
- 			get { return m_connStatus; }
 
- 			set
 
- 			{
 
- 				if( m_selfPowered )
 
- 				{
 
- 					m_connStatus = NodeConnectionStatus.Connected;
 
- 				}
 
- 				else
 
- 				{
 
- 					m_connStatus = value;
 
- 				}
 
- 				switch( m_connStatus )
 
- 				{
 
- 					case NodeConnectionStatus.Island:
 
- 					case NodeConnectionStatus.Not_Connected: m_statusColor = Constants.NodeDefaultColor; break;
 
- 					case NodeConnectionStatus.Connected: m_statusColor = Constants.NodeConnectedColor; break;
 
- 					case NodeConnectionStatus.Error: m_statusColor = Constants.NodeErrorColor; break;
 
- 				}
 
- 			}
 
- 		}
 
- 		public bool SelfPowered
 
- 		{
 
- 			set
 
- 			{
 
- 				m_selfPowered = value;
 
- 				if( value )
 
- 				{
 
- 					ConnStatus = NodeConnectionStatus.Connected;
 
- 				}
 
- 			}
 
- 		}
 
- 		// This is also called when recording on Undo
 
- 		public virtual void OnBeforeSerialize() { }
 
- 		public virtual void OnAfterDeserialize()
 
- 		{
 
- 			m_selected = false;
 
- 			m_isOnGrid = false;
 
- 			for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 			{
 
- 				m_inputPorts[ i ].ResetWireReferenceStatus();
 
- 			}
 
- 			m_repopulateDictionaries = true;
 
- 			m_sizeIsDirty = true;
 
- 			m_previewIsDirty = true;
 
- 		}
 
- 		public virtual int InputIdFromDeprecated( int oldInputId ) { return oldInputId; }
 
- 		public virtual int OutputIdFromDeprecated( int oldOutputId ) { return oldOutputId; }
 
- 		public virtual void ReadFromDeprecated( ref string[] nodeParams, Type oldType = null ) { }
 
- 		//Inherited classes must call this base method in order to setup id and position
 
- 		public virtual void ReadFromString( ref string[] nodeParams )
 
- 		{
 
- 			ParentReadFromString( ref nodeParams );
 
- 		}
 
- 		public void ParentReadFromString( ref string[] nodeParams )
 
- 		{
 
- 			m_currentReadParamIdx = IOUtils.NodeTypeId + 1;
 
- 			UniqueId = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
 
- 			string[] posCoordinates = nodeParams[ m_currentReadParamIdx++ ].Split( IOUtils.VECTOR_SEPARATOR );
 
- 			m_position.x = Convert.ToSingle( posCoordinates[ 0 ] );
 
- 			m_position.y = Convert.ToSingle( posCoordinates[ 1 ] );
 
- 			if( UIUtils.CurrentShaderVersion() > 22 )
 
- 			{
 
- 				string val = GetCurrentParam( ref nodeParams );
 
- 				if( m_customPrecision )
 
- 				{
 
- 					if( val.Equals("Fixed") )
 
- 						m_currentPrecisionType = PrecisionType.Half;
 
- 					else
 
- 					m_currentPrecisionType = (PrecisionType)Enum.Parse( typeof( PrecisionType ), val );
 
- 				}
 
- 				else
 
- 				{
 
- 					m_currentPrecisionType = PrecisionType.Inherit;
 
- 				}
 
- 			}
 
- 			if( UIUtils.CurrentShaderVersion() > 5004 )
 
- 				m_showPreview = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
 
- 		}
 
- 		//should be called after ReadFromString
 
- 		public virtual void ReadInputDataFromString( ref string[] nodeParams )
 
- 		{
 
- 			int count = 0;
 
- 			if( UIUtils.CurrentShaderVersion() > 7003 )
 
- 			{
 
- 				try
 
- 				{
 
- 					count = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
 
- 				}
 
- 				catch( Exception e )
 
- 				{
 
- 					Debug.LogException( e );
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				count = ( m_oldInputCount < 0 ) ? m_inputPorts.Count : m_oldInputCount;
 
- 			}
 
- 			for( int i = 0; i < count && i < nodeParams.Length && m_currentReadParamIdx < nodeParams.Length; i++ )
 
- 			{
 
- 				if( UIUtils.CurrentShaderVersion() < 5003 )
 
- 				{
 
- 					int newId = VersionConvertInputPortId( i );
 
- 					if( UIUtils.CurrentShaderVersion() > 23 )
 
- 					{
 
- 						m_inputPorts[ newId ].DataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), nodeParams[ m_currentReadParamIdx++ ] );
 
- 					}
 
- 					m_inputPorts[ newId ].InternalData = nodeParams[ m_currentReadParamIdx++ ];
 
- 					if( m_inputPorts[ newId ].IsEditable && UIUtils.CurrentShaderVersion() >= 3100 && m_currentReadParamIdx < nodeParams.Length )
 
- 					{
 
- 						m_inputPorts[ newId ].Name = nodeParams[ m_currentReadParamIdx++ ];
 
- 					}
 
- 					m_inputPorts[ newId ].UpdatePreviewInternalData();
 
- 				}
 
- 				else
 
- 				{
 
- 					string portIdStr = nodeParams[ m_currentReadParamIdx++ ];
 
- 					int portId = -1;
 
- 					try
 
- 					{
 
- 						portId = Convert.ToInt32( portIdStr );
 
- 					}
 
- 					catch( Exception e )
 
- 					{
 
- 						Debug.LogException( e );
 
- 					}
 
- 					WirePortDataType DataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), nodeParams[ m_currentReadParamIdx++ ] );
 
- 					string InternalData = nodeParams[ m_currentReadParamIdx++ ];
 
- 					bool isEditable = Convert.ToBoolean( nodeParams[ m_currentReadParamIdx++ ] );
 
- 					string Name = string.Empty;
 
- 					if( isEditable && m_currentReadParamIdx < nodeParams.Length )
 
- 					{
 
- 						Name = nodeParams[ m_currentReadParamIdx++ ];
 
- 					}
 
- 					InputPort inputPort = GetInputPortByUniqueId( portId );
 
- 					if( inputPort != null )
 
- 					{
 
- 						if( UIUtils.IsValidType( DataType ) )
 
- 							inputPort.DataType = DataType;
 
- 						inputPort.InternalData = InternalData;
 
- 						if( !string.IsNullOrEmpty( Name ) )
 
- 						{
 
- 							inputPort.Name = Name;
 
- 						}
 
- 						inputPort.UpdatePreviewInternalData();
 
- 					}
 
- 				}
 
- 			}
 
- 		}
 
- 		public virtual void ReadOutputDataFromString( ref string[] nodeParams )
 
- 		{
 
- 			int count = 0;
 
- 			if( UIUtils.CurrentShaderVersion() > 7003 )
 
- 			{
 
- 				count = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] );
 
- 			}
 
- 			else
 
- 			{
 
- 				count = m_outputPorts.Count;
 
- 			}
 
- 			for( int i = 0; i < count && i < nodeParams.Length && m_currentReadParamIdx < nodeParams.Length; i++ )
 
- 			{
 
- 				try
 
- 				{
 
- 					WirePortDataType dataType = (WirePortDataType)Enum.Parse( typeof( WirePortDataType ), nodeParams[ m_currentReadParamIdx++ ] );
 
- 					int portId = -1;
 
- 					if( UIUtils.CurrentShaderVersion() > 13903 )
 
- 					{
 
- 						portId = Convert.ToInt32( nodeParams[ m_currentReadParamIdx++ ] ); ;
 
- 					}
 
- 					else
 
- 					{
 
- 						portId = i;
 
- 					}
 
- 					OutputPort port = GetOutputPortByUniqueId( portId );
 
- 					if( port != null && UIUtils.IsValidType( dataType ) )
 
- 					{
 
- 						port.DataType = dataType;
 
- 					}
 
- 					
 
- 				}
 
- 				catch( Exception e )
 
- 				{
 
- 					Debug.LogException( e );
 
- 				}
 
- 			}
 
- 		}
 
- 		public virtual void ReadAdditionalClipboardData( ref string[] nodeParams ) { }
 
- 		protected string GetCurrentParam( ref string[] nodeParams )
 
- 		{
 
- 			if( m_currentReadParamIdx < nodeParams.Length )
 
- 			{
 
- 				return nodeParams[ m_currentReadParamIdx++ ];
 
- 			}
 
- 			UIUtils.ShowMessage( UniqueId, "Invalid params number in node " + m_uniqueId + " of type " + GetType(), MessageSeverity.Error );
 
- 			return string.Empty;
 
- 		}
 
- 		protected string GetCurrentParam( int index, ref string[] nodeParams )
 
- 		{
 
- 			if( m_currentReadParamIdx < nodeParams.Length )
 
- 			{
 
- 				return nodeParams[ index ];
 
- 			}
 
- 			UIUtils.ShowMessage( UniqueId, "Invalid params number in node " + m_uniqueId + " of type " + GetType(), MessageSeverity.Error );
 
- 			return string.Empty;
 
- 		}
 
- 		public virtual void WriteToString( ref string nodeInfo, ref string connectionsInfo )
 
- 		{
 
- 			IOUtils.AddTypeToString( ref nodeInfo, IOUtils.NodeParam );
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, GetType() );
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, m_uniqueId );
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, ( m_position.x.ToString() + IOUtils.VECTOR_SEPARATOR + m_position.y.ToString() ) );
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, m_currentPrecisionType );
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, m_showPreview );
 
- 			for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 			{
 
- 				m_inputPorts[ i ].WriteToString( ref connectionsInfo );
 
- 			}
 
- 		}
 
- 		public virtual void WriteInputDataToString( ref string nodeInfo )
 
- 		{
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts.Count );
 
- 			for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 			{
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts[ i ].PortId );
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts[ i ].DataType );
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts[ i ].InternalData );
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts[ i ].IsEditable );
 
- 				if( m_inputPorts[ i ].IsEditable )
 
- 				{
 
- 					IOUtils.AddFieldValueToString( ref nodeInfo, m_inputPorts[ i ].Name );
 
- 				}
 
- 			}
 
- 		}
 
- 		public void WriteOutputDataToString( ref string nodeInfo )
 
- 		{
 
- 			IOUtils.AddFieldValueToString( ref nodeInfo, m_outputPorts.Count );
 
- 			for( int i = 0; i < m_outputPorts.Count; i++ )
 
- 			{
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_outputPorts[ i ].DataType );
 
- 				IOUtils.AddFieldValueToString( ref nodeInfo, m_outputPorts[ i ].PortId );
 
- 			}
 
- 		}
 
- 		public virtual void WriteAdditionalClipboardData( ref string nodeInfo ) { }
 
- 		public virtual string GetIncludes() { return string.Empty; }
 
- 		public virtual void OnObjectDropped( UnityEngine.Object obj ) { }
 
- 		public virtual void SetupFromCastObject( UnityEngine.Object obj ) { }
 
- 		public virtual bool OnNodeInteraction( ParentNode node ) { return false; }
 
- 		public virtual void OnConnectedOutputNodeChanges( int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) { }
 
- 		public virtual void OnConnectedInputNodeChanges( int portId, int otherNodeId, int otherPortId, string name, WirePortDataType type ) { }
 
- 		public Rect CachedPos { get { return m_cachedPos; } }
 
- 		public bool IsOnGrid
 
- 		{
 
- 			set { m_isOnGrid = value; }
 
- 			get { return m_isOnGrid; }
 
- 		}
 
- 		public uint CurrentReadParamIdx
 
- 		{
 
- 			get { return m_currentReadParamIdx++; }
 
- 			set { m_currentReadParamIdx = value; }
 
- 		}
 
- 		public Dictionary<string, InputPort> InputPortsDict
 
- 		{
 
- 			get
 
- 			{
 
- 				Dictionary<string, InputPort> dict = new Dictionary<string, InputPort>();
 
- 				for( int i = 0; i < m_inputPorts.Count; i++ )
 
- 				{
 
- 					dict.Add( m_inputPorts[ i ].Name, m_inputPorts[ i ] );
 
- 				}
 
- 				return dict;
 
- 			}
 
- 		}
 
- 		public bool IsDirty
 
- 		{
 
- 			set { m_isDirty = value && UIUtils.DirtyMask; }
 
- 			get
 
- 			{
 
- 				bool value = m_isDirty;
 
- 				m_isDirty = false;
 
- 				return value;
 
- 			}
 
- 		}
 
- 		public virtual void ResetNodeData()
 
- 		{
 
- 			m_category = 0;
 
- 			m_graphDepth = 0;
 
- 		}
 
- 		public virtual void PropagateNodeData( NodeData nodeData, ref MasterNodeDataCollector dataCollector )
 
- 		{
 
- 			UIUtils.SetCategoryInBitArray( ref m_category, nodeData.Category );
 
- 			nodeData.GraphDepth += 1;
 
- 			if( nodeData.GraphDepth > m_graphDepth )
 
- 			{
 
- 				m_graphDepth = nodeData.GraphDepth;
 
- 			}
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				if( m_inputPorts[ i ].IsConnected )
 
- 				{
 
- 					m_inputPorts[ i ].GetOutputNode().PropagateNodeData( nodeData, ref dataCollector );
 
- 				}
 
- 			}
 
- 		}
 
- 		
 
- 		public void SetTitleTextOnCallback( string compareTitle, Action<ParentNode, string> callback )
 
- 		{
 
- 			if( !m_previousTitle.Equals( compareTitle ) )
 
- 			{
 
- 				m_previousTitle = compareTitle;
 
- 				m_sizeIsDirty = true;
 
- 				callback( this, compareTitle );
 
- 			}
 
- 		}
 
- 		public void SetAdditonalTitleTextOnCallback( string compareTitle, Action<ParentNode, string> callback )
 
- 		{
 
- 			if( !m_previousAdditonalTitle.Equals( compareTitle ) )
 
- 			{
 
- 				m_previousAdditonalTitle = compareTitle;
 
- 				m_sizeIsDirty = true;
 
- 				callback( this, compareTitle );
 
- 			}
 
- 		}
 
- 		public void SetAdditonalTitleTextOnCallback( string compareTitle, string compareTitleFormat, Action<ParentNode, string> callback )
 
- 		{
 
- 			if ( !m_previousAdditonalTitle.Equals( compareTitle ) || !m_previousAdditonalTitleFormat.Equals( compareTitleFormat ))
 
- 			{
 
- 				m_previousAdditonalTitle = compareTitle;
 
- 				m_previousAdditonalTitleFormat = compareTitleFormat;
 
- 				m_sizeIsDirty = true;
 
- 				callback( this, compareTitle );
 
- 			}
 
- 		}
 
- 		public virtual void SetClippedTitle( string newText, int maxSize = 170, string endString = "..." )
 
- 		{
 
- 			m_content.text = GenerateClippedTitle( newText,maxSize,endString );
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		
 
- 		public virtual void SetClippedAdditionalTitle( string newText, int maxSize = 170, string endString = "..." )
 
- 		{
 
- 			m_additionalContent.text = GenerateClippedTitle( newText, maxSize, endString );
 
- 			m_sizeIsDirty = true;
 
- 		}
 
- 		public void SetTitleText( string newText )
 
- 		{
 
- 			if( !newText.Equals( m_content.text ) )
 
- 			{
 
- 				m_content.text = newText;
 
- 				m_sizeIsDirty = true;
 
- 			}
 
- 		}
 
- 		public void SetAdditonalTitleText( string newText )
 
- 		{
 
- 			if( !newText.Equals( m_additionalContent.text ) )
 
- 			{
 
- 				m_additionalContent.text = newText;
 
- 				m_sizeIsDirty = true;
 
- 			}
 
- 		}
 
- 		public string GenerateErrorValue( int outputIdx = 0 )
 
- 		{
 
- 			switch( m_outputPorts[ outputIdx ].DataType )
 
- 			{
 
- 				case WirePortDataType.FLOAT2:
 
- 				{
 
- 					return "(0).xx";
 
- 				}
 
- 				case WirePortDataType.FLOAT3:
 
- 				{
 
- 					return "(0).xxx";
 
- 				}
 
- 				case WirePortDataType.FLOAT4:
 
- 				case WirePortDataType.COLOR:
 
- 				{
 
- 					return "(0).xxxx";
 
- 				}
 
- 			}
 
- 			return "0";
 
- 		}
 
- 		//Methods created to take into account new ports added on nodes newer versions
 
- 		//This way we can convert connections from previous versions to newer ones and not brake shader graph
 
- 		public virtual int VersionConvertInputPortId( int portId ) { return portId; }
 
- 		public virtual int VersionConvertOutputPortId( int portId ) { return portId; }
 
- 		public virtual string DataToArray { get { return string.Empty; } }
 
- 		public bool SaveIsDirty
 
- 		{
 
- 			set { m_saveIsDirty = value && UIUtils.DirtyMask; }
 
- 			get
 
- 			{
 
- 				bool value = m_saveIsDirty;
 
- 				m_saveIsDirty = false;
 
- 				return value;
 
- 			}
 
- 		}
 
- 		public GUIContent TitleContent { get { return m_content; } }
 
- 		public GUIContent AdditonalTitleContent { get { return m_additionalContent; } }
 
- 		public bool IsVisible { get { return m_isVisible; } }
 
- 		public NodeAttributes Attributes { get { return m_nodeAttribs; } }
 
- 		public bool ReorderLocked { get { return m_reorderLocked; } }
 
- 		public bool RequireMaterialUpdate { get { return m_requireMaterialUpdate; } }
 
- 		public bool RMBIgnore { get { return m_rmbIgnore; } }
 
- 		public float TextLabelWidth { get { return m_textLabelWidth; } }
 
- 		public bool IsMoving { get { return m_isMoving > 0; } }
 
- 		public bool MovingInFrame { get { return m_movingInFrame; } set { m_movingInFrame = value; } }
 
- 		public bool SizeIsDirty { get { return m_sizeIsDirty; } set { m_sizeIsDirty = value; } }
 
- 		public int Category { get { return m_category; } }
 
- 		public int CommentaryParent
 
- 		{
 
- 			get { return m_commentaryParent; }
 
- 			set { m_commentaryParent = value; }
 
- 		}
 
- 		public int Depth
 
- 		{
 
- 			get { return m_depth; }
 
- 			set { m_depth = value; }
 
- 		}
 
- 		public int MatrixId
 
- 		{
 
- 			get { return m_matrixId; }
 
- 			set { m_matrixId = value; }
 
- 		}
 
- 		public float PaddingTitleRight
 
- 		{
 
- 			get { return m_paddingTitleRight; }
 
- 			set { m_paddingTitleRight += value; }
 
- 		}
 
- 		public float PaddingTitleLeft
 
- 		{
 
- 			get { return m_paddingTitleLeft; }
 
- 			set { m_paddingTitleLeft += value; }
 
- 		}
 
- 		public int CachedPortsId
 
- 		{
 
- 			get
 
- 			{
 
- 				return m_cachedPortsId;
 
- 			}
 
- 		}
 
- 		public virtual bool RecursivePreviewUpdate( Dictionary<string,bool> duplicatesDict = null )
 
- 		{
 
- 			if( duplicatesDict == null )
 
- 			{
 
- 				duplicatesDict = ContainerGraph.ParentWindow.VisitedChanged;
 
- 			}
 
- 			for( int i = 0; i < InputPorts.Count; i++ )
 
- 			{
 
- 				ParentNode outNode = null;
 
- 				if( InputPorts[ i ].ExternalReferences.Count > 0 )
 
- 				{
 
- 					outNode = ContainerGraph.GetNode( InputPorts[ i ].ExternalReferences[ 0 ].NodeId );
 
- 				}
 
- 				if( outNode != null )
 
- 				{
 
- 					if( !duplicatesDict.ContainsKey( outNode.OutputId ) )
 
- 					{
 
- 						bool result = outNode.RecursivePreviewUpdate();
 
- 						if( result )
 
- 							PreviewIsDirty = true;
 
- 					} else if( duplicatesDict[ outNode.OutputId ] )
 
- 					{
 
- 						PreviewIsDirty = true;
 
- 					}
 
- 				}
 
- 			}
 
- 			
 
- 			bool needsUpdate = PreviewIsDirty;
 
- 			RenderNodePreview();
 
- 			if( !duplicatesDict.ContainsKey( OutputId ) )
 
- 				duplicatesDict.Add( OutputId, needsUpdate );
 
- 			return needsUpdate;
 
- 		}
 
- 		public virtual void RenderNodePreview()
 
- 		{
 
- 			//Runs at least one time
 
- 			if( !HasPreviewShader || !m_initialized )
 
- 			{
 
- 				// nodes with no preview don't update at all
 
- 				PreviewIsDirty = false;
 
- 				return;
 
- 			}
 
- 			if( !PreviewIsDirty && !m_continuousPreviewRefresh )
 
- 				return;
 
- 			//Debug.Log( "PREVIEW " + this );
 
- 			SetPreviewInputs();
 
- 			if( m_cachedMainTexId == -1 )
 
- 				m_cachedMainTexId = Shader.PropertyToID( "_MainTex" );
 
- 			if( m_cachedMaskTexId == -1 )
 
- 				m_cachedMaskTexId = Shader.PropertyToID( "_MaskTex" );
 
- 			if( m_cachedPortsId == -1 )
 
- 				m_cachedPortsId = Shader.PropertyToID( "_Ports" );
 
- 			if( m_cachedPortId == -1 )
 
- 				m_cachedPortId = Shader.PropertyToID( "_Port" );
 
- 			if (!Preferences.User.DisablePreviews)
 
- 			{
 
- 				RenderTexture temp = RenderTexture.active;
 
- 				RenderTexture beforeMask = RenderTexture.GetTemporary(Constants.PreviewSize, Constants.PreviewSize, 0, Constants.PreviewFormat, RenderTextureReadWrite.Linear);
 
- 				int count = m_outputPorts.Count;
 
- 				for( int i = 0; i < count; i++ )
 
- 				{
 
- 					if ( i == 0 )
 
- 					{
 
- 						RenderTexture.active = beforeMask;
 
- 						if ( m_previewMaterialPassId < PreviewMaterial.passCount )
 
- 						{
 
- 							Graphics.Blit( null, beforeMask, PreviewMaterial, m_previewMaterialPassId );
 
- 						}
 
- 						m_portMask.Set( 0, 0, 0, 0 );
 
- 						switch( m_outputPorts[ i ].DataType )
 
- 						{
 
- 							case WirePortDataType.INT:
 
- 							case WirePortDataType.FLOAT:
 
- 							m_portMask.Set( 1, 1, 1, 1 );
 
- 							break;
 
- 							case WirePortDataType.FLOAT2:
 
- 							m_portMask.Set( 1, 1, 0, 0 );
 
- 							break;
 
- 							case WirePortDataType.FLOAT3:
 
- 							m_portMask.Set( 1, 1, 1, 0 );
 
- 							break;
 
- 							case WirePortDataType.COLOR:
 
- 							case WirePortDataType.FLOAT4:
 
- 							m_portMask.Set( 1, 1, 1, 1 );
 
- 							break;
 
- 							default:
 
- 							m_portMask.Set( 1, 1, 1, 1 );
 
- 							break;
 
- 						}
 
- 						if( m_outputPorts[ i ].DataType == WirePortDataType.FLOAT3x3 || m_outputPorts[ i ].DataType == WirePortDataType.FLOAT4x4 )
 
- 						{
 
- 							m_outputPorts[ i ].MaskingMaterial.SetTexture( m_cachedMainTexId, EditorGUIUtility.whiteTexture );
 
- 						}
 
- 						else
 
- 						{
 
- 							m_outputPorts[ i ].MaskingMaterial.SetTexture( m_cachedMainTexId, beforeMask );
 
- 						}
 
- 						m_outputPorts[ i ].MaskingMaterial.SetVector( m_cachedPortsId, m_portMask );
 
- 						RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture;
 
- 						Graphics.Blit( null , m_outputPorts[ i ].OutputPreviewTexture , m_outputPorts[ i ].MaskingMaterial , 0 );
 
- 					}
 
- 					else
 
- 					{
 
- 						m_outputPorts[ i ].MaskingMaterial.SetTexture( m_cachedMaskTexId , PreviewTexture );
 
- 						m_outputPorts[ i ].MaskingMaterial.SetFloat( m_cachedPortId , i );
 
- 						RenderTexture.active = m_outputPorts[ i ].OutputPreviewTexture;
 
- 						Graphics.Blit( null , m_outputPorts[ i ].OutputPreviewTexture , m_outputPorts[ i ].MaskingMaterial , 1 );
 
- 					}
 
- 				}
 
- 				RenderTexture.ReleaseTemporary(beforeMask);
 
- 				RenderTexture.active = temp;
 
- 			}
 
- 			PreviewIsDirty = m_continuousPreviewRefresh;
 
- 			FinishPreviewRender = true;
 
- 		}
 
- 		protected void ShowTab( NodeMessageType type, string tooltip )
 
- 		{
 
- 			m_showErrorMessage = true;
 
- 			m_errorMessageTypeIsError = type;
 
- 			m_errorMessageTooltip = tooltip;
 
- 		}
 
- 		protected void ShowTab()
 
- 		{
 
- 			m_showErrorMessage = true;
 
- 		}
 
- 		protected void HideTab()
 
- 		{
 
- 			m_showErrorMessage = false;
 
- 		}
 
- 		public virtual RenderTexture PreviewTexture
 
- 		{
 
- 			get
 
- 			{
 
- 				if( m_outputPorts.Count > 0 )
 
- 					return m_outputPorts[ 0 ].OutputPreviewTexture;
 
- 				else
 
- 					return null;
 
- 			}
 
- 		}
 
- 		public void FullWriteToString( ref string nodesInfo, ref string connectionsInfo )
 
- 		{
 
- 			WriteToString( ref nodesInfo, ref connectionsInfo );
 
- 			WriteInputDataToString( ref nodesInfo );
 
- 			WriteOutputDataToString( ref nodesInfo );
 
- 		}
 
- 		public void ClipboardFullWriteToString( ref string nodesInfo, ref string connectionsInfo )
 
- 		{
 
- 			FullWriteToString( ref nodesInfo, ref connectionsInfo );
 
- 			WriteAdditionalClipboardData( ref nodesInfo );
 
- 		}
 
- 		public void FullReadFromString( ref string[] parameters )
 
- 		{
 
- 			try
 
- 			{
 
- 				ReadFromString( ref parameters );
 
- 				ReadInputDataFromString( ref parameters );
 
- 				ReadOutputDataFromString( ref parameters );
 
- 			}
 
- 			catch( Exception e )
 
- 			{
 
- 				Debug.LogException( e );
 
- 			}
 
- 		}
 
- 		public void ClipboardFullReadFromString( ref string[] parameters )
 
- 		{
 
- 			try
 
- 			{
 
- 				FullReadFromString( ref parameters );
 
- 				ReadAdditionalClipboardData( ref parameters );
 
- 			}
 
- 			catch( Exception e )
 
- 			{
 
- 				Debug.LogException( e );
 
- 			}
 
- 		}
 
- 		public string GenerateClippedTitle( string original , int maxSize = 170, string endString = "..." )
 
- 		{
 
- 			if( UIUtils.UnZoomedNodeTitleStyle == null )
 
- 				return original;
 
- 			GUIContent content = new GUIContent( original );
 
- 			string finalTitle = string.Empty;
 
- 			bool addEllipsis = false;
 
- 			for( int i = 1; i <= original.Length; i++ )
 
- 			{
 
- 				content.text = original.Substring( 0, i );
 
- 				Vector2 titleSize = UIUtils.UnZoomedNodeTitleStyle.CalcSize( content );
 
- 				if( titleSize.x > maxSize )
 
- 				{
 
- 					addEllipsis = true;
 
- 					break;
 
- 				}
 
- 				else
 
- 				{
 
- 					finalTitle = content.text;
 
- 				}
 
- 			}
 
- 			if( addEllipsis )
 
- 				finalTitle += endString;
 
- 			return finalTitle;
 
- 		}
 
- 		public virtual void RefreshOnUndo() { }
 
- 		public virtual void CalculateCustomGraphDepth() { }
 
- 		public int GraphDepth { get { return m_graphDepth; } }
 
- 		public PrecisionType CurrentPrecisionType { get { return m_currentPrecisionType == PrecisionType.Inherit ? ContainerGraph.CurrentPrecision : m_currentPrecisionType; } }
 
- 		public Material PreviewMaterial
 
- 		{
 
- 			get
 
- 			{
 
- 				if( m_previewMaterial == null )
 
- 				{
 
- 					m_previewMaterial = new Material( PreviewShader );
 
- 				}
 
- 				return m_previewMaterial;
 
- 			}
 
- 		}
 
- 		public Shader PreviewShader
 
- 		{
 
- 			get
 
- 			{
 
- 				if( m_previewShader == null )
 
- 				{
 
- 					m_previewShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( m_previewShaderGUID ) );
 
- 				}
 
- 				if( m_previewShader == null )
 
- 				{
 
- 					m_previewShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "d9ca47581ac157145bff6f72ac5dd73e" ) ); //ranged float guid
 
- 				}
 
- 				if( m_previewShader == null )
 
- 					m_previewShader = Shader.Find( "Unlit/Colored Transparent" );
 
- 				return m_previewShader;
 
- 			}
 
- 		}
 
- 		public bool HasPreviewShader
 
- 		{
 
- 			get { return !string.IsNullOrEmpty( m_previewShaderGUID ); }
 
- 		}
 
- 		public void CheckSpherePreview()
 
- 		{
 
- 			bool oneIsSphere = false;
 
- 			if( m_drawPreviewAsSphere )
 
- 				oneIsSphere = true;
 
- 			int count = m_inputPorts.Count;
 
- 			for( int i = 0; i < count; i++ )
 
- 			{
 
- 				ParentNode node = null;
 
- 				if( m_inputPorts[ i ].ExternalReferences.Count > 0)
 
- 				{
 
- 					node = ContainerGraph.GetNode( m_inputPorts[ i ].ExternalReferences[ 0 ].NodeId );
 
- 				}
 
- 				if( node != null && node.SpherePreview )
 
- 					oneIsSphere = true;
 
- 			}
 
- 			if( m_forceDrawPreviewAsPlane )
 
- 				oneIsSphere = false;
 
- 			SpherePreview = oneIsSphere;
 
- 		}
 
- 		public bool SpherePreview
 
- 		{
 
- 			get { return m_spherePreview; }
 
- 			set { m_spherePreview = value; }
 
- 		}
 
- 		public bool ShowPreview
 
- 		{
 
- 			get { return m_showPreview; }
 
- 			set { m_showPreview = value; }
 
- 		}
 
- 		public int VisiblePorts
 
- 		{
 
- 			get { return m_visiblePorts; }
 
- 			set { m_visiblePorts = value; }
 
- 		}
 
- 		public bool Docking
 
- 		{
 
- 			get { return m_docking; }
 
- 			set { m_docking = value; }
 
- 		}
 
- 		public bool UseSquareNodeTitle
 
- 		{
 
- 			get { return m_useSquareNodeTitle; }
 
- 			set { m_useSquareNodeTitle = value; }
 
- 		}
 
- 		public bool InsideShaderFunction
 
- 		{
 
- 			get { return ContainerGraph != ContainerGraph.ParentWindow.CurrentGraph; }
 
- 		}
 
- 		public virtual void SetContainerGraph( ParentGraph newgraph )
 
- 		{
 
- 			m_containerGraph = newgraph;
 
- 		}
 
- 		public virtual void OnMasterNodeReplaced( MasterNode newMasterNode ) { PreviewIsDirty = true;  }
 
- 		public virtual void RefreshExternalReferences() { }
 
- 		public Rect DropdownRect { get { return m_dropdownRect; } }
 
- 		public virtual bool Contains( Vector2 pos ) { return m_globalPosition.Contains( pos ); }
 
- 		public virtual bool Contains( Vector3 pos ) { return m_globalPosition.Contains( pos ); }
 
- 		public bool IsNodeBeingCopied { get { return m_isNodeBeingCopied; } set { m_isNodeBeingCopied = value; } }
 
- 		public virtual WirePortDataType GetInputPortVisualDataTypeByArrayIdx( int portArrayIdx )
 
- 		{
 
- 			return m_inputPorts[ portArrayIdx ].DataType;
 
- 		}
 
- 		public virtual WirePortDataType GetOutputPortVisualDataTypeById( int portId )
 
- 		{
 
- 			return GetOutputPortByUniqueId( portId ).DataType;
 
- 		}
 
- 		public virtual bool CheckFindText( string text )
 
- 		{
 
- 			return TitleContent.text.IndexOf( text, StringComparison.CurrentCultureIgnoreCase ) >= 0;
 
- 		}
 
- 		public virtual ParentNode ExecuteStubCode(){ return this; }
 
- 		public virtual float HeightEstimate
 
- 		{
 
- 			get
 
- 			{
 
- 				float heightEstimate = 0;
 
- 				heightEstimate = 32 + Constants.INPUT_PORT_DELTA_Y;
 
- 				for( int i = 0; i < InputPorts.Count; i++ )
 
- 				{
 
- 					if( InputPorts[ i ].Visible )
 
- 						heightEstimate += 18 + Constants.INPUT_PORT_DELTA_Y;
 
- 				}
 
- 				return heightEstimate;
 
- 				// Magic number 18 represents m_fontHeight that might not be set yet
 
- 				//return Constants.NODE_HEADER_EXTRA_HEIGHT + Mathf.Max( 18 + m_inputPorts.Count, m_outputPorts.Count ) * Constants.INPUT_PORT_DELTA_Y;
 
- 			}
 
- 		}
 
- 		public bool WasDeprecated { get { return m_wasDeprecated; } set { m_wasDeprecated = value; } }
 
- 		public bool Alive { get { return m_alive;} set { m_alive = value; } }
 
- 		public string TypeName { get { if( m_nodeAttribs != null ) return m_nodeAttribs.Name;return GetType().ToString(); } }
 
- 		public bool PreviewIsDirty { set { m_previewIsDirty = value; } get { return m_previewIsDirty; } }
 
- 		protected bool FinishPreviewRender { get { return m_finishPreviewRender; } set { m_finishPreviewRender = value; } }
 
- 		public virtual bool IsStubNode { get { return false; } }
 
- 	}
 
- }
 
 
  |