PropertyNode.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEditor;
  7. namespace AmplifyShaderEditor
  8. {
  9. public enum PropertyType
  10. {
  11. Constant = 0,
  12. Property,
  13. InstancedProperty,
  14. Global
  15. }
  16. public enum VariableMode
  17. {
  18. Create = 0,
  19. Fetch
  20. }
  21. [Serializable]
  22. public class PropertyAttributes
  23. {
  24. public string Name;
  25. public string Attribute;
  26. public bool HasDeprecatedValue;
  27. public string DeprecatedValue;
  28. public PropertyAttributes( string name, string attribute , string deprecated = null )
  29. {
  30. Name = name;
  31. Attribute = attribute;
  32. DeprecatedValue = deprecated;
  33. HasDeprecatedValue = deprecated != null;
  34. }
  35. }
  36. [Serializable]
  37. public class PropertyNode : ParentNode
  38. {
  39. private const string LongNameEnder = "... )";
  40. protected int m_longNameSize = 200;
  41. //private const string InstancedPropertyWarning = "Instanced Property option shouldn't be used on official SRP templates as all property variables are already declared as instanced inside a CBuffer.\nPlease consider changing to Property option.";
  42. private const string TooltipFormatter = "{0}\n\nName: {1}\nValue: {2}";
  43. private const string InvalidAttributeFormatter = "Attribute {0} not found on node {1}. Please click on this message to select node and review its attributes section";
  44. protected string GlobalTypeWarningText = "Global variables must be set via a C# script using the Shader.SetGlobal{0}(...) method.\nPlease note that setting a global variable will affect all shaders which are using it.";
  45. private const string HybridInstancedStr = "Hybrid Instanced";
  46. private const string AutoRegisterStr = "Auto-Register";
  47. private const string IgnoreVarDeclarationStr = "Variable Mode";
  48. private const string IsPropertyStr = "Is Property";
  49. private const string PropertyNameStr = "Property Name";
  50. private const string PropertyInspectorStr = "Name";
  51. protected const string EnumsStr = "Enums";
  52. protected const string CustomAttrStr = "Custom Attributes";
  53. protected const string HeaderAttrStr = "Headers";
  54. protected const string ParameterTypeStr = "Type";
  55. private const string PropertyTextfieldControlName = "PropertyName";
  56. private const string PropertyInspTextfieldControlName = "PropertyInspectorName";
  57. private const string OrderIndexStr = "Order Index";
  58. protected const double MaxTimestamp = 2;
  59. private const double MaxPropertyTimestamp = 2;
  60. private const double MaxGlobalFetchTimestamp = 2;
  61. protected readonly string[] LabelToolbarTitle = { "Material", "Default" };
  62. protected readonly string[] EnumModesStr = { "Create Enums", "Use Engine Enum Class" };
  63. protected readonly int[] EnumModeIntValues = { 0, 1 };
  64. private const string FetchToCreateDuplicatesMsg = "Reverting property name from '{0}' to '{1}' as it is registered to another property node.";
  65. private const string FetchToCreateOnDuplicateNodeMsg = "Setting new property name '{0}' as '{1}' is registered to another property node.";
  66. private const string HeaderId = "Header";
  67. private const string EnumId = "Enum";
  68. [SerializeField]
  69. protected PropertyType m_currentParameterType;
  70. [SerializeField]
  71. private PropertyType m_lastParameterType;
  72. [SerializeField]
  73. protected string m_propertyName = string.Empty;
  74. [SerializeField]
  75. protected string m_propertyInspectorName = string.Empty;
  76. [SerializeField]
  77. protected string m_precisionString;
  78. protected bool m_drawPrecisionUI = true;
  79. [SerializeField]
  80. private int m_orderIndex = -1;
  81. [SerializeField]
  82. protected VariableMode m_variableMode = VariableMode.Create;
  83. [SerializeField]
  84. protected bool m_autoGlobalName = true;
  85. [SerializeField]
  86. protected bool m_hybridInstanced = false;
  87. [SerializeField]
  88. protected bool m_autoRegister = false;
  89. [SerializeField]
  90. protected bool m_registerPropertyOnInstancing = true;
  91. [SerializeField]
  92. private List<string> m_enumNames = new List<string>();
  93. [SerializeField]
  94. private List<int> m_enumValues = new List<int>();
  95. [SerializeField]
  96. private int m_enumCount = 0;
  97. [SerializeField]
  98. private int m_enumModeInt = 0;
  99. [SerializeField]
  100. private int m_customAttrCount = 0;
  101. [SerializeField]
  102. private List<string> m_customAttr = new List<string>();
  103. [SerializeField]
  104. private bool m_hasHeaders = false;
  105. [SerializeField]
  106. private List<string> m_headerAttributeValues = new List<string>();
  107. [SerializeField]
  108. private string m_enumClassName = string.Empty;
  109. private bool m_hasEnum = false;
  110. protected bool m_showTitleWhenNotEditing = true;
  111. private int m_orderIndexOffset = 0;
  112. protected bool m_drawAttributes = true;
  113. protected bool m_underscoredGlobal = false;
  114. protected bool m_globalDefaultBehavior = true;
  115. protected bool m_freeName;
  116. protected bool m_freeType;
  117. protected bool m_showVariableMode = false;
  118. protected bool m_propertyNameIsDirty;
  119. protected bool m_showAutoRegisterUI = true;
  120. protected bool m_showHybridInstancedUI = false;
  121. protected bool m_useVarSubtitle = false;
  122. protected bool m_propertyFromInspector;
  123. protected double m_propertyFromInspectorTimestamp;
  124. protected bool m_checkDuplicateProperty;
  125. protected double m_checkDuplicatePropertyTimestamp;
  126. protected double m_globalFetchTimestamp;
  127. protected bool m_delayedDirtyProperty;
  128. protected double m_delayedDirtyPropertyTimestamp;
  129. protected string m_defaultPropertyName;
  130. protected string m_oldName = string.Empty;
  131. private bool m_reRegisterName = false;
  132. protected bool m_allowPropertyDuplicates = false;
  133. //protected bool m_useCustomPrefix = false;
  134. protected string m_customPrefix = null;
  135. protected int m_propertyTab = 0;
  136. [SerializeField]
  137. private string m_uniqueName;
  138. // Property Attributes
  139. private const float ButtonLayoutWidth = 15;
  140. protected bool m_visibleAttribsFoldout;
  141. protected bool m_visibleEnumsFoldout;
  142. protected bool m_visibleCustomAttrFoldout;
  143. protected bool m_visibleHeaderAttrFoldout;
  144. protected List<PropertyAttributes> m_availableAttribs = new List<PropertyAttributes>();
  145. private string[] m_availableAttribsArr;
  146. [SerializeField]
  147. private bool[] m_selectedAttribsArr;
  148. [SerializeField]
  149. protected List<int> m_selectedAttribs = new List<int>();
  150. //Title editing
  151. protected bool m_isEditing;
  152. protected bool m_stopEditing;
  153. protected bool m_startEditing;
  154. protected double m_clickTime;
  155. protected double m_doubleClickTime = 0.3;
  156. private Rect m_titleClickArea;
  157. protected bool m_srpBatcherCompatible = false;
  158. protected bool m_excludeUniform = false;
  159. [SerializeField]
  160. private bool m_addGlobalToSRPBatcher = false;
  161. public PropertyNode() : base() { }
  162. public PropertyNode( int uniqueId, float x, float y, float width, float height ) : base( uniqueId, x, y, width, height ) { }
  163. protected override void CommonInit( int uniqueId )
  164. {
  165. base.CommonInit( uniqueId );
  166. m_textLabelWidth = 105;
  167. if( UIUtils.CurrentWindow != null && UIUtils.CurrentWindow.CurrentGraph != null )
  168. m_orderIndex = UIUtils.GetPropertyNodeAmount();
  169. m_currentParameterType = PropertyType.Constant;
  170. m_freeType = true;
  171. m_freeName = true;
  172. m_propertyNameIsDirty = true;
  173. m_customPrecision = true;
  174. m_availableAttribs.Add( new PropertyAttributes( "Hide in Inspector", "[HideInInspector]" ) );
  175. m_availableAttribs.Add( new PropertyAttributes( "HDR", "[HDR]" ) );
  176. m_availableAttribs.Add( new PropertyAttributes( "Gamma", "[Gamma]" ) );
  177. m_availableAttribs.Add( new PropertyAttributes( "Per Renderer Data", "[PerRendererData]" ) );
  178. m_availableAttribs.Add( new PropertyAttributes( "Header", "[Header]" ) );
  179. }
  180. public override void AfterCommonInit()
  181. {
  182. base.AfterCommonInit();
  183. if( PaddingTitleLeft == 0 && m_freeType )
  184. {
  185. PaddingTitleLeft = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
  186. if( PaddingTitleRight == 0 )
  187. PaddingTitleRight = Constants.PropertyPickerWidth + Constants.IconsLeftRightMargin;
  188. }
  189. m_hasLeftDropdown = m_freeType;
  190. }
  191. protected void BeginDelayedDirtyProperty()
  192. {
  193. m_delayedDirtyProperty = true;
  194. m_delayedDirtyPropertyTimestamp = EditorApplication.timeSinceStartup;
  195. }
  196. public void CheckDelayedDirtyProperty()
  197. {
  198. if( m_delayedDirtyProperty )
  199. {
  200. if( ( EditorApplication.timeSinceStartup - m_delayedDirtyPropertyTimestamp ) > MaxPropertyTimestamp )
  201. {
  202. m_delayedDirtyProperty = false;
  203. m_propertyNameIsDirty = true;
  204. m_sizeIsDirty = true;
  205. }
  206. }
  207. }
  208. public void BeginPropertyFromInspectorCheck()
  209. {
  210. m_propertyFromInspector = true;
  211. m_propertyFromInspectorTimestamp = EditorApplication.timeSinceStartup;
  212. }
  213. public virtual void CheckPropertyFromInspector( bool forceUpdate = false )
  214. {
  215. if( m_propertyFromInspector )
  216. {
  217. if( forceUpdate || ( EditorApplication.timeSinceStartup - m_propertyFromInspectorTimestamp ) > MaxTimestamp )
  218. {
  219. m_propertyFromInspector = false;
  220. bool autoGlobal = m_autoGlobalName || m_currentParameterType == PropertyType.Global;
  221. RegisterPropertyName( true, m_propertyInspectorName, autoGlobal, m_underscoredGlobal );
  222. m_propertyNameIsDirty = true;
  223. }
  224. }
  225. }
  226. public void CheckDuplicateProperty()
  227. {
  228. if( m_checkDuplicateProperty &&
  229. ( EditorApplication.timeSinceStartup - m_checkDuplicatePropertyTimestamp ) > MaxTimestamp )
  230. {
  231. m_checkDuplicateProperty = false;
  232. m_propertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, false );
  233. if( UIUtils.IsNumericName( m_propertyName ) )
  234. {
  235. UIUtils.ShowMessage( UniqueId, string.Format( "Invalid property name '{0}' as it cannot start with numbers. Reverting to last valid name '{1}'", m_propertyName, m_oldName ), MessageSeverity.Warning );
  236. m_propertyName = m_oldName;
  237. GUI.FocusControl( string.Empty );
  238. return;
  239. }
  240. if( !m_propertyName.Equals( m_oldName ) )
  241. {
  242. if( UIUtils.IsUniformNameAvailable( m_propertyName ) || m_allowPropertyDuplicates )
  243. {
  244. UIUtils.ReleaseUniformName( UniqueId, m_oldName );
  245. m_oldName = m_propertyName;
  246. m_propertyNameIsDirty = true;
  247. m_reRegisterName = false;
  248. UIUtils.RegisterUniformName( UniqueId, m_propertyName );
  249. OnPropertyNameChanged();
  250. }
  251. else
  252. {
  253. GUI.FocusControl( string.Empty );
  254. RegisterFirstAvailablePropertyName( true, true );
  255. UIUtils.ShowMessage( UniqueId, string.Format( "Property name '{0}' is already in use. Reverting to last valid name '{1}'", m_propertyName, m_oldName ) );
  256. }
  257. }
  258. }
  259. }
  260. protected override void OnUniqueIDAssigned()
  261. {
  262. if( m_variableMode == VariableMode.Create )
  263. RegisterFirstAvailablePropertyName( false );
  264. if( m_nodeAttribs != null )
  265. m_uniqueName = m_nodeAttribs.Name + UniqueId;
  266. UIUtils.RegisterRawPropertyNode( this );
  267. }
  268. public bool CheckLocalVariable( ref MasterNodeDataCollector dataCollector )
  269. {
  270. bool addToLocalValue = false;
  271. int count = 0;
  272. for( int i = 0; i < m_outputPorts.Count; i++ )
  273. {
  274. if( m_outputPorts[ i ].IsConnected )
  275. {
  276. if( m_outputPorts[ i ].ConnectionCount > 1 )
  277. {
  278. addToLocalValue = true;
  279. break;
  280. }
  281. count += 1;
  282. if( count > 1 )
  283. {
  284. addToLocalValue = true;
  285. break;
  286. }
  287. }
  288. }
  289. if( addToLocalValue )
  290. {
  291. ConfigureLocalVariable( ref dataCollector );
  292. }
  293. return addToLocalValue;
  294. }
  295. public virtual void ConfigureLocalVariable( ref MasterNodeDataCollector dataCollector ) { }
  296. public virtual void CopyDefaultsToMaterial() { }
  297. public override void SetupFromCastObject( UnityEngine.Object obj )
  298. {
  299. RegisterPropertyName( true, obj.name, true, m_underscoredGlobal );
  300. }
  301. public void ChangeParameterType( PropertyType parameterType )
  302. {
  303. UndoUtils.RegisterCompleteObjectUndo( m_containerGraph.ParentWindow, Constants.UndoChangePropertyTypeNodesId );
  304. UndoUtils.RegisterCompleteObjectUndo( m_containerGraph, Constants.UndoChangePropertyTypeNodesId );
  305. UndoUtils.RecordObject( this, Constants.UndoChangePropertyTypeNodesId );
  306. if( m_currentParameterType == PropertyType.Constant || m_currentParameterType == PropertyType.Global )
  307. {
  308. CopyDefaultsToMaterial();
  309. }
  310. if( parameterType == PropertyType.InstancedProperty )
  311. {
  312. //if( m_containerGraph.IsSRP )
  313. //{
  314. // UIUtils.ShowMessage( InstancedPropertyWarning,MessageSeverity.Warning );
  315. //}
  316. UIUtils.CurrentWindow.OutsideGraph.AddInstancePropertyCount();
  317. }
  318. else if( m_currentParameterType == PropertyType.InstancedProperty )
  319. {
  320. UIUtils.CurrentWindow.OutsideGraph.RemoveInstancePropertyCount();
  321. }
  322. if( ( parameterType == PropertyType.Property || parameterType == PropertyType.InstancedProperty )
  323. && m_currentParameterType != PropertyType.Property && m_currentParameterType != PropertyType.InstancedProperty )
  324. {
  325. UIUtils.RegisterPropertyNode( this );
  326. }
  327. if( ( parameterType != PropertyType.Property && parameterType != PropertyType.InstancedProperty )
  328. && ( m_currentParameterType == PropertyType.Property || m_currentParameterType == PropertyType.InstancedProperty ) )
  329. {
  330. UIUtils.UnregisterPropertyNode( this );
  331. }
  332. m_currentParameterType = parameterType;
  333. if( parameterType == PropertyType.Constant )
  334. {
  335. CurrentVariableMode = VariableMode.Create;
  336. }
  337. }
  338. void InitializeAttribsArray()
  339. {
  340. m_availableAttribsArr = new string[ m_availableAttribs.Count ];
  341. m_selectedAttribsArr = new bool[ m_availableAttribs.Count ];
  342. for( int i = 0; i < m_availableAttribsArr.Length; i++ )
  343. {
  344. m_availableAttribsArr[ i ] = m_availableAttribs[ i ].Name;
  345. m_selectedAttribsArr[ i ] = false;
  346. if( m_selectedAttribs.FindIndex( x => x == i ) > -1 )
  347. {
  348. m_selectedAttribsArr[ i ] = true;
  349. m_visibleAttribsFoldout = true;
  350. }
  351. }
  352. }
  353. protected virtual void OnAtrributesChanged() { CheckEnumAttribute(); CheckHeaderAttribute(); }
  354. void DrawAttributesAddRemoveButtons()
  355. {
  356. if( m_availableAttribsArr == null )
  357. {
  358. InitializeAttribsArray();
  359. }
  360. int attribCount = m_selectedAttribs.Count;
  361. // Add new port
  362. if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  363. {
  364. m_visibleAttribsFoldout = true;
  365. m_selectedAttribs.Add( 0 );
  366. OnAtrributesChanged();
  367. }
  368. //Remove port
  369. if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  370. {
  371. if( attribCount > 0 )
  372. {
  373. m_selectedAttribs.RemoveAt( attribCount - 1 );
  374. OnAtrributesChanged();
  375. }
  376. }
  377. }
  378. void CheckEnumAttribute()
  379. {
  380. m_hasEnum = false;
  381. foreach( var item in m_selectedAttribs )
  382. {
  383. if( m_availableAttribsArr[ item ].Equals( "Enum" ) )
  384. m_hasEnum = true;
  385. }
  386. }
  387. protected void CheckHeaderAttribute()
  388. {
  389. m_hasHeaders = false;
  390. foreach( var item in m_selectedAttribs )
  391. {
  392. if( m_availableAttribsArr[ item ].Equals( HeaderId ) )
  393. {
  394. m_hasHeaders = true;
  395. }
  396. }
  397. }
  398. void DrawEnumAddRemoveButtons()
  399. {
  400. // Add new port
  401. if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) && m_enumModeInt == 0 )
  402. {
  403. m_enumNames.Add( "Option" + ( m_enumValues.Count + 1 ) );
  404. m_enumValues.Add( m_enumValues.Count );
  405. m_enumCount++;
  406. m_visibleEnumsFoldout = true;
  407. }
  408. //Remove port
  409. if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) && m_enumModeInt == 0 )
  410. {
  411. if( m_enumNames.Count - 1 > -1 )
  412. {
  413. m_enumNames.RemoveAt( m_enumNames.Count - 1 );
  414. m_enumValues.RemoveAt( m_enumValues.Count - 1 );
  415. m_enumCount--;
  416. }
  417. }
  418. }
  419. protected void DrawEnums()
  420. {
  421. m_enumModeInt = EditorGUILayout.IntPopup( "Mode", m_enumModeInt, EnumModesStr, EnumModeIntValues );
  422. if( m_enumModeInt == 0 )
  423. {
  424. if( m_enumNames.Count == 0 )
  425. EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info );
  426. float cacheLabelSize = EditorGUIUtility.labelWidth;
  427. EditorGUIUtility.labelWidth = 50;
  428. for( int i = 0; i < m_enumNames.Count; i++ )
  429. {
  430. EditorGUI.BeginChangeCheck();
  431. EditorGUILayout.BeginHorizontal();
  432. m_enumNames[ i ] = EditorGUILayoutTextField( "Name", m_enumNames[ i ] );
  433. m_enumValues[ i ] = Mathf.Max( 0, EditorGUILayoutIntField( "Value", m_enumValues[ i ], GUILayout.Width( 100 ) ) );
  434. EditorGUILayout.EndHorizontal();
  435. if( EditorGUI.EndChangeCheck() )
  436. {
  437. m_enumNames[ i ] = UIUtils.RemoveInvalidEnumCharacters( m_enumNames[ i ] );
  438. if( string.IsNullOrEmpty( m_enumNames[ i ] ) )
  439. {
  440. m_enumNames[ i ] = "Option" + ( i + 1 );
  441. }
  442. }
  443. }
  444. EditorGUIUtility.labelWidth = cacheLabelSize;
  445. if( m_enumNames.Count > 0 )
  446. {
  447. EditorGUILayout.BeginHorizontal();
  448. GUILayout.Label( " " );
  449. DrawEnumAddRemoveButtons();
  450. EditorGUILayout.EndHorizontal();
  451. }
  452. }
  453. else
  454. {
  455. EditorGUILayout.BeginHorizontal();
  456. m_enumClassName = EditorGUILayoutTextField( "Class Name", m_enumClassName );
  457. if( GUILayout.Button( string.Empty, UIUtils.InspectorPopdropdownFallback, GUILayout.Width( 17 ), GUILayout.Height( 19 ) ) )
  458. {
  459. GenericMenu menu = new GenericMenu();
  460. AddMenuItem( menu, "UnityEngine.Rendering.CullMode" );
  461. AddMenuItem( menu, "UnityEngine.Rendering.ColorWriteMask" );
  462. AddMenuItem( menu, "UnityEngine.Rendering.CompareFunction" );
  463. AddMenuItem( menu, "UnityEngine.Rendering.StencilOp" );
  464. AddMenuItem( menu, "UnityEngine.Rendering.BlendMode" );
  465. AddMenuItem( menu, "UnityEngine.Rendering.BlendOp" );
  466. menu.ShowAsContext();
  467. }
  468. EditorGUILayout.EndHorizontal();
  469. }
  470. }
  471. private void AddMenuItem( GenericMenu menu, string newClass )
  472. {
  473. menu.AddItem( new GUIContent( newClass ), m_enumClassName.Equals( newClass ), OnSelection, newClass );
  474. }
  475. private void OnSelection( object newClass )
  476. {
  477. m_enumClassName = (string)newClass;
  478. }
  479. protected void DrawCustomAttrAddRemoveButtons()
  480. {
  481. // Add new port
  482. if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  483. {
  484. m_customAttr.Add( "" );
  485. m_customAttrCount++;
  486. //m_enumCount++;
  487. m_visibleCustomAttrFoldout = true;
  488. }
  489. //Remove port
  490. if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  491. {
  492. if( m_customAttr.Count - 1 > -1 )
  493. {
  494. m_customAttr.RemoveAt( m_customAttr.Count - 1 );
  495. m_customAttrCount--;
  496. }
  497. }
  498. }
  499. protected void DrawCustomAttributes()
  500. {
  501. for( int i = 0; i < m_customAttrCount; i++ )
  502. {
  503. EditorGUI.BeginChangeCheck();
  504. m_customAttr[ i ] = EditorGUILayoutTextField( "Attribute " + i, m_customAttr[ i ] );
  505. if( EditorGUI.EndChangeCheck() )
  506. {
  507. m_customAttr[ i ] = UIUtils.RemoveInvalidAttrCharacters( m_customAttr[ i ] );
  508. }
  509. }
  510. if( m_customAttrCount <= 0 )
  511. {
  512. EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info );
  513. return;
  514. }
  515. EditorGUILayout.BeginHorizontal();
  516. GUILayout.Label( " " );
  517. DrawCustomAttrAddRemoveButtons();
  518. EditorGUILayout.EndHorizontal();
  519. }
  520. protected void DrawHeaderAttrAddRemoveButtons()
  521. {
  522. // Add new port
  523. if( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  524. {
  525. m_headerAttributeValues.Add( "" );
  526. m_visibleHeaderAttrFoldout = true;
  527. }
  528. //Remove port
  529. if( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  530. {
  531. if( m_headerAttributeValues.Count > 0 )
  532. {
  533. m_headerAttributeValues.RemoveAt( m_headerAttributeValues.Count - 1 );
  534. }
  535. }
  536. }
  537. protected void DrawHeaderAttributes()
  538. {
  539. int count = m_headerAttributeValues.Count;
  540. for( int i = 0; i < count; i++ )
  541. {
  542. EditorGUI.BeginChangeCheck();
  543. m_headerAttributeValues[ i ] = EditorGUILayoutTextField( "Header " + i, m_headerAttributeValues[ i ] );
  544. if( EditorGUI.EndChangeCheck() )
  545. {
  546. m_headerAttributeValues[ i ] = UIUtils.RemoveHeaderAttrCharacters( m_headerAttributeValues[ i ] );
  547. }
  548. }
  549. if( count <= 0 )
  550. {
  551. EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info );
  552. return;
  553. }
  554. EditorGUILayout.BeginHorizontal();
  555. GUILayout.Label( " " );
  556. DrawHeaderAttrAddRemoveButtons();
  557. EditorGUILayout.EndHorizontal();
  558. }
  559. public virtual void DrawAttributes()
  560. {
  561. int attribCount = m_selectedAttribs.Count;
  562. EditorGUI.BeginChangeCheck();
  563. if( m_availableAttribsArr == null )
  564. {
  565. InitializeAttribsArray();
  566. }
  567. for( int i = 0; i < m_availableAttribsArr.Length; i++ )
  568. {
  569. m_selectedAttribsArr[ i ] = EditorGUILayoutToggleLeft( m_availableAttribsArr[ i ], m_selectedAttribsArr[ i ] );
  570. }
  571. if( EditorGUI.EndChangeCheck() )
  572. {
  573. m_selectedAttribs.Clear();
  574. for( int i = 0; i < m_selectedAttribsArr.Length; i++ )
  575. {
  576. if( m_selectedAttribsArr[ i ] )
  577. m_selectedAttribs.Add( i );
  578. }
  579. OnAtrributesChanged();
  580. }
  581. bool customAttr = EditorGUILayoutToggleLeft( "Custom", m_customAttrCount == 0 ? false : true );
  582. if( !customAttr )
  583. {
  584. m_customAttrCount = 0;
  585. }
  586. else if( customAttr && m_customAttrCount < 1 )
  587. {
  588. if( m_customAttr.Count == 0 )
  589. m_customAttr.Add( "" );
  590. m_customAttrCount = m_customAttr.Count;
  591. }
  592. //m_customAttrCount = EditorGUILayoutToggleLeft( "Custom Attribute", m_customAttrCount == 0 ? false : true ) == 0 ? false : true;
  593. //if( attribCount == 0 )
  594. //{
  595. // EditorGUILayout.HelpBox( "Your list is Empty!\nUse the plus button to add more.", MessageType.Info );
  596. //}
  597. //bool actionAllowed = true;
  598. //int deleteItem = -1;
  599. //for ( int i = 0; i < attribCount; i++ )
  600. //{
  601. // EditorGUI.BeginChangeCheck();
  602. // {
  603. // m_selectedAttribs[ i ] = EditorGUILayoutPopup( m_selectedAttribs[ i ], m_availableAttribsArr );
  604. // }
  605. // if ( EditorGUI.EndChangeCheck() )
  606. // {
  607. // OnAtrributesChanged();
  608. // }
  609. // EditorGUILayout.BeginHorizontal();
  610. // GUILayout.Label( " " );
  611. // // Add After
  612. // if ( GUILayout.Button( string.Empty, UIUtils.PlusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  613. // {
  614. // if ( actionAllowed )
  615. // {
  616. // m_selectedAttribs.Insert( i, m_selectedAttribs[ i ] );
  617. // actionAllowed = false;
  618. // OnAtrributesChanged();
  619. // }
  620. // }
  621. // // Remove Current
  622. // if ( GUILayout.Button( string.Empty, UIUtils.MinusStyle, GUILayout.Width( ButtonLayoutWidth ) ) )
  623. // {
  624. // if ( actionAllowed )
  625. // {
  626. // actionAllowed = false;
  627. // deleteItem = i;
  628. // }
  629. // }
  630. // EditorGUILayout.EndHorizontal();
  631. //}
  632. //if ( deleteItem > -1 )
  633. //{
  634. // m_selectedAttribs.RemoveAt( deleteItem );
  635. // OnAtrributesChanged();
  636. //}
  637. }
  638. public virtual void DrawMainPropertyBlock()
  639. {
  640. EditorGUILayout.BeginVertical();
  641. {
  642. if( m_freeType )
  643. {
  644. PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType );
  645. if( parameterType != m_currentParameterType )
  646. {
  647. ChangeParameterType( parameterType );
  648. BeginPropertyFromInspectorCheck();
  649. }
  650. }
  651. if( m_freeName )
  652. {
  653. switch( m_currentParameterType )
  654. {
  655. case PropertyType.Property:
  656. case PropertyType.InstancedProperty:
  657. {
  658. ShowPropertyInspectorNameGUI();
  659. ShowPropertyNameGUI( true );
  660. ShowVariableMode();
  661. ShowHybridInstanced();
  662. ShowAutoRegister();
  663. ShowPrecision();
  664. ShowToolbar();
  665. }
  666. break;
  667. case PropertyType.Global:
  668. {
  669. ShowPropertyInspectorNameGUI();
  670. ShowPropertyNameGUI( false );
  671. ShowVariableMode();
  672. ShowAutoRegister();
  673. ShowPrecision();
  674. ShowDefaults();
  675. }
  676. break;
  677. case PropertyType.Constant:
  678. {
  679. ShowPropertyInspectorNameGUI();
  680. ShowPrecision();
  681. ShowDefaults();
  682. }
  683. break;
  684. }
  685. }
  686. }
  687. EditorGUILayout.EndVertical();
  688. }
  689. public void DrawMainPropertyBlockNoPrecision()
  690. {
  691. EditorGUILayout.BeginVertical();
  692. {
  693. if( m_freeType )
  694. {
  695. PropertyType parameterType = (PropertyType)EditorGUILayoutEnumPopup( ParameterTypeStr, m_currentParameterType );
  696. if( parameterType != m_currentParameterType )
  697. {
  698. ChangeParameterType( parameterType );
  699. BeginPropertyFromInspectorCheck();
  700. }
  701. }
  702. if( m_freeName )
  703. {
  704. switch( m_currentParameterType )
  705. {
  706. case PropertyType.Property:
  707. case PropertyType.InstancedProperty:
  708. {
  709. ShowPropertyInspectorNameGUI();
  710. ShowPropertyNameGUI( true );
  711. ShowToolbar();
  712. }
  713. break;
  714. case PropertyType.Global:
  715. {
  716. ShowPropertyInspectorNameGUI();
  717. ShowPropertyNameGUI( false );
  718. ShowDefaults();
  719. }
  720. break;
  721. case PropertyType.Constant:
  722. {
  723. ShowPropertyInspectorNameGUI();
  724. ShowDefaults();
  725. }
  726. break;
  727. }
  728. }
  729. }
  730. EditorGUILayout.EndVertical();
  731. }
  732. public override void DrawProperties()
  733. {
  734. base.DrawProperties();
  735. if( m_freeType || m_freeName )
  736. {
  737. NodeUtils.DrawPropertyGroup( ref m_propertiesFoldout, Constants.ParameterLabelStr, DrawMainPropertyBlock );
  738. if( m_drawAttributes )
  739. NodeUtils.DrawPropertyGroup( ref m_visibleAttribsFoldout, Constants.AttributesLaberStr, DrawAttributes );
  740. if( m_hasEnum )
  741. {
  742. if( m_enumModeInt == 0 )
  743. NodeUtils.DrawPropertyGroup( ref m_visibleEnumsFoldout, EnumsStr, DrawEnums, DrawEnumAddRemoveButtons );
  744. else
  745. NodeUtils.DrawPropertyGroup( ref m_visibleEnumsFoldout, EnumsStr, DrawEnums );
  746. }
  747. if( m_drawAttributes )
  748. {
  749. if( m_hasHeaders )
  750. NodeUtils.DrawPropertyGroup( ref m_visibleHeaderAttrFoldout, HeaderAttrStr, DrawHeaderAttributes, DrawHeaderAttrAddRemoveButtons );
  751. if( m_customAttrCount > 0 )
  752. NodeUtils.DrawPropertyGroup( ref m_visibleCustomAttrFoldout, CustomAttrStr, DrawCustomAttributes, DrawCustomAttrAddRemoveButtons );
  753. }
  754. CheckPropertyFromInspector();
  755. }
  756. }
  757. public void ShowPrecision()
  758. {
  759. if( m_drawPrecisionUI )
  760. {
  761. bool guiEnabled = GUI.enabled;
  762. GUI.enabled = m_currentParameterType == PropertyType.Constant || m_variableMode == VariableMode.Create;
  763. EditorGUI.BeginChangeCheck();
  764. DrawPrecisionProperty();
  765. if( EditorGUI.EndChangeCheck() )
  766. m_precisionString = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
  767. GUI.enabled = guiEnabled;
  768. }
  769. }
  770. public void ShowToolbar()
  771. {
  772. //if ( !CanDrawMaterial )
  773. //{
  774. // ShowDefaults();
  775. // return;
  776. //}
  777. EditorGUILayout.BeginHorizontal();
  778. GUILayout.Space( 20 );
  779. m_propertyTab = GUILayout.Toolbar( m_propertyTab, LabelToolbarTitle );
  780. EditorGUILayout.EndHorizontal();
  781. switch( m_propertyTab )
  782. {
  783. default:
  784. case 0:
  785. {
  786. EditorGUI.BeginChangeCheck();
  787. DrawMaterialProperties();
  788. if( EditorGUI.EndChangeCheck() )
  789. {
  790. BeginDelayedDirtyProperty();
  791. }
  792. }
  793. break;
  794. case 1:
  795. {
  796. ShowDefaults();
  797. }
  798. break;
  799. }
  800. }
  801. public void ShowDefaults()
  802. {
  803. EditorGUI.BeginChangeCheck();
  804. DrawSubProperties();
  805. if( EditorGUI.EndChangeCheck() )
  806. {
  807. BeginDelayedDirtyProperty();
  808. }
  809. if( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior )
  810. {
  811. if( DebugConsoleWindow.DeveloperMode )
  812. {
  813. ShowGlobalValueButton();
  814. }
  815. EditorGUILayout.HelpBox( GlobalTypeWarningText, MessageType.Warning );
  816. }
  817. }
  818. public void ShowPropertyInspectorNameGUI()
  819. {
  820. EditorGUI.BeginChangeCheck();
  821. m_propertyInspectorName = EditorGUILayoutTextField( PropertyInspectorStr, m_propertyInspectorName );
  822. if( EditorGUI.EndChangeCheck() )
  823. {
  824. if( m_propertyInspectorName.Length > 0 )
  825. {
  826. BeginPropertyFromInspectorCheck();
  827. }
  828. }
  829. }
  830. public void ShowPropertyNameGUI( bool isProperty )
  831. {
  832. bool guiEnabledBuffer = GUI.enabled;
  833. if( isProperty )
  834. {
  835. EditorGUILayout.BeginHorizontal();
  836. GUI.enabled = !m_autoGlobalName;
  837. EditorGUI.BeginChangeCheck();
  838. m_propertyName = EditorGUILayoutTextField( PropertyNameStr, m_propertyName );
  839. if( EditorGUI.EndChangeCheck() )
  840. {
  841. //BeginPropertyFromInspectorCheck();
  842. m_checkDuplicateProperty = true;
  843. m_checkDuplicatePropertyTimestamp = EditorApplication.timeSinceStartup;
  844. }
  845. GUI.enabled = guiEnabledBuffer;
  846. EditorGUI.BeginChangeCheck();
  847. m_autoGlobalName = GUILayout.Toggle( m_autoGlobalName, ( m_autoGlobalName ? UIUtils.LockIconOpen : UIUtils.LockIconClosed ), "minibutton", GUILayout.Width( 22 ) );
  848. if( EditorGUI.EndChangeCheck() )
  849. {
  850. if( m_autoGlobalName )
  851. BeginPropertyFromInspectorCheck();
  852. }
  853. EditorGUILayout.EndHorizontal();
  854. }
  855. else
  856. {
  857. GUI.enabled = false;
  858. m_propertyName = EditorGUILayoutTextField( PropertyNameStr, m_propertyName );
  859. GUI.enabled = guiEnabledBuffer;
  860. }
  861. }
  862. public void ShowVariableMode()
  863. {
  864. if( m_showVariableMode || m_freeType )
  865. CurrentVariableMode = (VariableMode)EditorGUILayoutEnumPopup( IgnoreVarDeclarationStr, m_variableMode );
  866. }
  867. public void ShowHybridInstanced()
  868. {
  869. if( m_showHybridInstancedUI && CurrentParameterType == PropertyType.Property && ( m_containerGraph.IsSRP || m_containerGraph.CurrentShaderFunction != null ) )
  870. {
  871. m_hybridInstanced = EditorGUILayoutToggle( HybridInstancedStr, m_hybridInstanced );
  872. }
  873. }
  874. public void ShowAutoRegister()
  875. {
  876. if( m_showAutoRegisterUI && CurrentParameterType != PropertyType.Constant )
  877. {
  878. m_autoRegister = EditorGUILayoutToggle( AutoRegisterStr, m_autoRegister );
  879. }
  880. }
  881. public virtual string GetPropertyValStr() { return string.Empty; }
  882. public virtual string GetSubTitleVarNameFormatStr() { return Constants.SubTitleVarNameFormatStr; }
  883. public override bool OnClick( Vector2 currentMousePos2D )
  884. {
  885. bool singleClick = base.OnClick( currentMousePos2D );
  886. m_propertyTab = m_materialMode ? 0 : 1;
  887. return singleClick;
  888. }
  889. public override void OnNodeDoubleClicked( Vector2 currentMousePos2D )
  890. {
  891. if( currentMousePos2D.y - m_globalPosition.y > ( Constants.NODE_HEADER_HEIGHT + Constants.NODE_HEADER_EXTRA_HEIGHT ) * ContainerGraph.ParentWindow.CameraDrawInfo.InvertedZoom )
  892. {
  893. ContainerGraph.ParentWindow.ParametersWindow.IsMaximized = !ContainerGraph.ParentWindow.ParametersWindow.IsMaximized;
  894. }
  895. }
  896. public override void DrawTitle( Rect titlePos )
  897. {
  898. //base.DrawTitle( titlePos );
  899. }
  900. public override void Draw( DrawInfo drawInfo )
  901. {
  902. base.Draw( drawInfo );
  903. // Custom Editable Title
  904. if( ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
  905. {
  906. if( !m_isEditing && ( ( !ContainerGraph.ParentWindow.MouseInteracted && drawInfo.CurrentEventType == EventType.MouseDown && m_titleClickArea.Contains( drawInfo.MousePosition ) ) ) )
  907. {
  908. if( ( EditorApplication.timeSinceStartup - m_clickTime ) < m_doubleClickTime )
  909. m_startEditing = true;
  910. else
  911. GUI.FocusControl( null );
  912. m_clickTime = EditorApplication.timeSinceStartup;
  913. }
  914. else if( m_isEditing && ( ( drawInfo.CurrentEventType == EventType.MouseDown && !m_titleClickArea.Contains( drawInfo.MousePosition ) ) || !EditorGUIUtility.editingTextField ) )
  915. {
  916. m_stopEditing = true;
  917. }
  918. if( m_isEditing || m_startEditing )
  919. {
  920. EditorGUI.BeginChangeCheck();
  921. GUI.SetNextControlName( m_uniqueName );
  922. m_propertyInspectorName = EditorGUITextField( m_titleClickArea, string.Empty, m_propertyInspectorName, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
  923. if( EditorGUI.EndChangeCheck() )
  924. {
  925. SetClippedTitle( m_propertyInspectorName, m_longNameSize );
  926. m_sizeIsDirty = true;
  927. m_isDirty = true;
  928. if( m_propertyInspectorName.Length > 0 )
  929. {
  930. BeginPropertyFromInspectorCheck();
  931. }
  932. }
  933. if( m_startEditing )
  934. EditorGUI.FocusTextInControl( m_uniqueName );
  935. //if( m_stopEditing )
  936. // GUI.FocusControl( null );
  937. }
  938. if( drawInfo.CurrentEventType == EventType.Repaint )
  939. {
  940. if( m_startEditing )
  941. {
  942. m_startEditing = false;
  943. m_isEditing = true;
  944. }
  945. if( m_stopEditing )
  946. {
  947. m_stopEditing = false;
  948. m_isEditing = false;
  949. GUI.FocusControl( null );
  950. }
  951. }
  952. if( m_freeType )
  953. {
  954. if( m_dropdownEditing )
  955. {
  956. PropertyType parameterType = (PropertyType)EditorGUIEnumPopup( m_dropdownRect, m_currentParameterType, UIUtils.PropertyPopUp );
  957. if( parameterType != m_currentParameterType )
  958. {
  959. ChangeParameterType( parameterType );
  960. BeginPropertyFromInspectorCheck();
  961. DropdownEditing = false;
  962. }
  963. }
  964. }
  965. }
  966. }
  967. public override void OnNodeLayout( DrawInfo drawInfo )
  968. {
  969. //base.OnNodeLayout( drawInfo );
  970. if( m_reRegisterName )
  971. {
  972. m_reRegisterName = false;
  973. UIUtils.RegisterUniformName( UniqueId, m_propertyName );
  974. }
  975. CheckDelayedDirtyProperty();
  976. if( m_currentParameterType != m_lastParameterType || m_propertyNameIsDirty )
  977. {
  978. m_lastParameterType = m_currentParameterType;
  979. m_propertyNameIsDirty = false;
  980. OnDirtyProperty();
  981. if( m_currentParameterType != PropertyType.Constant )
  982. {
  983. SetClippedTitle( m_propertyInspectorName, m_longNameSize );
  984. //bool globalHandler = false;
  985. //if( globalHandler )
  986. //{
  987. string currValue = ( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior ) ? "<GLOBAL>" : GetPropertyValStr();
  988. SetClippedAdditionalTitle( string.Format( m_useVarSubtitle ? GetSubTitleVarNameFormatStr() : Constants.SubTitleValueFormatStr, currValue ), m_longNameSize, LongNameEnder );
  989. //}
  990. //else
  991. //{
  992. // if( m_currentParameterType == PropertyType.Global )
  993. // {
  994. // SetAdditonalTitleText( "Global" );
  995. // }
  996. // else
  997. // {
  998. // SetAdditonalTitleText( string.Format( m_useVarSubtitle ? GetSubTitleVarNameFormatStr() : Constants.SubTitleValueFormatStr, GetPropertyValStr() ) );
  999. // }
  1000. //}
  1001. }
  1002. else
  1003. {
  1004. SetClippedTitle( m_propertyInspectorName, m_longNameSize );
  1005. SetClippedAdditionalTitle( string.Format( Constants.SubTitleConstFormatStr, GetPropertyValStr() ), m_longNameSize, LongNameEnder );
  1006. }
  1007. }
  1008. CheckPropertyFromInspector();
  1009. CheckDuplicateProperty();
  1010. // RUN LAYOUT CHANGES AFTER TITLES CHANGE
  1011. base.OnNodeLayout( drawInfo );
  1012. m_titleClickArea = m_titlePos;
  1013. m_titleClickArea.height = Constants.NODE_HEADER_HEIGHT;
  1014. }
  1015. public override void OnNodeRepaint( DrawInfo drawInfo )
  1016. {
  1017. base.OnNodeRepaint( drawInfo );
  1018. if( !m_isVisible )
  1019. return;
  1020. // Fixed Title ( only renders when not editing )
  1021. if( m_showTitleWhenNotEditing && !m_isEditing && !m_startEditing && ContainerGraph.LodLevel <= ParentGraph.NodeLOD.LOD3 )
  1022. {
  1023. GUI.Label( m_titleClickArea, m_content, UIUtils.GetCustomStyle( CustomStyle.NodeTitle ) );
  1024. }
  1025. }
  1026. public void RegisterFirstAvailablePropertyName( bool releaseOldOne, bool appendIndexToCurrOne = false )
  1027. {
  1028. if( releaseOldOne )
  1029. UIUtils.ReleaseUniformName( UniqueId, m_oldName );
  1030. if( m_isNodeBeingCopied || appendIndexToCurrOne )
  1031. {
  1032. if( string.IsNullOrEmpty( m_propertyName ) )
  1033. return;
  1034. string newPropertyName = UIUtils.GetUniqueUniformName( m_propertyName );
  1035. if( newPropertyName != m_propertyName )
  1036. {
  1037. UIUtils.RegisterUniformName( UniqueId, newPropertyName );
  1038. m_propertyName = newPropertyName;
  1039. }
  1040. else
  1041. {
  1042. if( UIUtils.IsUniformNameAvailable( m_propertyName ) )
  1043. UIUtils.RegisterUniformName( UniqueId, m_propertyName );
  1044. else
  1045. UIUtils.GetFirstAvailableName( UniqueId, m_outputPorts[ 0 ].DataType, out m_propertyName, out m_propertyInspectorName, !string.IsNullOrEmpty( m_customPrefix ), m_customPrefix );
  1046. }
  1047. }
  1048. else
  1049. {
  1050. UIUtils.GetFirstAvailableName( UniqueId, m_outputPorts[ 0 ].DataType, out m_propertyName, out m_propertyInspectorName, !string.IsNullOrEmpty( m_customPrefix ), m_customPrefix );
  1051. }
  1052. m_oldName = m_propertyName;
  1053. m_propertyNameIsDirty = true;
  1054. m_reRegisterName = false;
  1055. OnPropertyNameChanged();
  1056. }
  1057. public void SetRawPropertyName( string name )
  1058. {
  1059. m_propertyName = name;
  1060. }
  1061. public void RegisterPropertyName( bool releaseOldOne, string newName, bool autoGlobal = true, bool forceUnderscore = false )
  1062. {
  1063. if( m_currentParameterType != PropertyType.Constant && m_variableMode == VariableMode.Fetch )
  1064. {
  1065. string localPropertyName = string.Empty;
  1066. if( autoGlobal )
  1067. localPropertyName = UIUtils.GeneratePropertyName( newName, m_currentParameterType, forceUnderscore );
  1068. else
  1069. {
  1070. localPropertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, forceUnderscore );
  1071. if( UIUtils.IsNumericName( localPropertyName ) )
  1072. {
  1073. m_propertyName = m_oldName;
  1074. }
  1075. }
  1076. m_propertyName = localPropertyName;
  1077. m_propertyInspectorName = newName;
  1078. m_propertyNameIsDirty = true;
  1079. m_reRegisterName = false;
  1080. OnPropertyNameChanged();
  1081. return;
  1082. }
  1083. string propertyName = string.Empty;
  1084. if( autoGlobal )
  1085. propertyName = UIUtils.GeneratePropertyName( newName, m_currentParameterType, forceUnderscore );
  1086. else
  1087. {
  1088. propertyName = UIUtils.GeneratePropertyName( m_propertyName, PropertyType.Global, forceUnderscore );
  1089. if( UIUtils.IsNumericName( propertyName ) )
  1090. {
  1091. m_propertyName = m_oldName;
  1092. }
  1093. }
  1094. if( m_propertyName.Equals( propertyName ) )
  1095. return;
  1096. if( UIUtils.IsUniformNameAvailable( propertyName ) || m_allowPropertyDuplicates )
  1097. {
  1098. if( releaseOldOne )
  1099. UIUtils.ReleaseUniformName( UniqueId, m_oldName );
  1100. m_oldName = propertyName;
  1101. m_propertyName = propertyName;
  1102. if( autoGlobal )
  1103. m_propertyInspectorName = newName;
  1104. m_propertyNameIsDirty = true;
  1105. m_reRegisterName = false;
  1106. UIUtils.RegisterUniformName( UniqueId, propertyName );
  1107. OnPropertyNameChanged();
  1108. }
  1109. else
  1110. {
  1111. GUI.FocusControl( string.Empty );
  1112. RegisterFirstAvailablePropertyName( releaseOldOne );
  1113. UIUtils.ShowMessage( UniqueId, string.Format( "Property name '{0}' is already in use. Reverting to last valid name '{1}'", propertyName, m_oldName ) );
  1114. }
  1115. }
  1116. protected string CreateLocalVarDec( string value )
  1117. {
  1118. return string.Format( Constants.PropertyLocalVarDec, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName, value );
  1119. }
  1120. public virtual void CheckIfAutoRegister( ref MasterNodeDataCollector dataCollector )
  1121. {
  1122. // Also testing inside shader function because node can be used indirectly over a custom expression and directly over a Function Output node
  1123. // That isn't being used externaly making it to not be registered ( since m_connStatus it set to Connected by being connected to an output node
  1124. if( CurrentParameterType != PropertyType.Constant && m_autoRegister && ( m_connStatus != NodeConnectionStatus.Connected || InsideShaderFunction ) )
  1125. {
  1126. RegisterProperty( ref dataCollector );
  1127. }
  1128. }
  1129. virtual protected void RegisterProperty( ref MasterNodeDataCollector dataCollector )
  1130. {
  1131. CheckPropertyFromInspector( true );
  1132. if( m_propertyName.Length == 0 )
  1133. {
  1134. RegisterFirstAvailablePropertyName( false );
  1135. }
  1136. switch( CurrentParameterType )
  1137. {
  1138. case PropertyType.Property:
  1139. {
  1140. //Debug.Log( this.GetInstanceID()+" "+ OrderIndex+" "+GetPropertyValue() );
  1141. dataCollector.AddToProperties( UniqueId, GetPropertyValue(), OrderIndex );
  1142. string dataType = string.Empty;
  1143. string dataName = string.Empty;
  1144. bool fullValue = false;
  1145. if( m_variableMode == VariableMode.Create && GetUniformData( out dataType, out dataName, ref fullValue ) )
  1146. {
  1147. if( fullValue )
  1148. {
  1149. dataCollector.AddToUniforms( UniqueId, dataName, m_srpBatcherCompatible );
  1150. }
  1151. else
  1152. {
  1153. dataCollector.AddToUniforms( UniqueId, dataType, dataName, m_srpBatcherCompatible, m_excludeUniform );
  1154. }
  1155. }
  1156. if( m_hybridInstanced && dataCollector.IsTemplate && dataCollector.IsSRP )
  1157. {
  1158. dataCollector.AddToDotsProperties( m_outputPorts[ 0 ].DataType, UniqueId, m_propertyName, OrderIndex, CurrentPrecisionType );
  1159. }
  1160. //dataCollector.AddToUniforms( m_uniqueId, GetUniformValue() );
  1161. }
  1162. break;
  1163. case PropertyType.InstancedProperty:
  1164. {
  1165. dataCollector.AddToPragmas( UniqueId, IOUtils.InstancedPropertiesHeader );
  1166. if( m_registerPropertyOnInstancing )
  1167. dataCollector.AddToProperties( UniqueId, GetPropertyValue(), OrderIndex );
  1168. dataCollector.AddToInstancedProperties( m_outputPorts[ 0 ].DataType, UniqueId, GetInstancedUniformValue( dataCollector.IsTemplate, dataCollector.IsSRP ), OrderIndex );
  1169. }
  1170. break;
  1171. case PropertyType.Global:
  1172. {
  1173. string dataType = string.Empty;
  1174. string dataName = string.Empty;
  1175. bool fullValue = false;
  1176. if( m_variableMode == VariableMode.Create && GetUniformData( out dataType, out dataName, ref fullValue ) )
  1177. {
  1178. if( fullValue )
  1179. {
  1180. dataCollector.AddToUniforms( UniqueId, dataName, m_addGlobalToSRPBatcher );
  1181. }
  1182. else
  1183. {
  1184. dataCollector.AddToUniforms( UniqueId, dataType, dataName, m_addGlobalToSRPBatcher, m_excludeUniform );
  1185. }
  1186. }
  1187. //dataCollector.AddToUniforms( m_uniqueId, GetUniformValue() );
  1188. }
  1189. break;
  1190. case PropertyType.Constant: break;
  1191. }
  1192. dataCollector.AddPropertyNode( this );
  1193. if( m_currentParameterType == PropertyType.InstancedProperty && !m_outputPorts[ 0 ].IsLocalValue( dataCollector.PortCategory ) )
  1194. {
  1195. string instancedVar = dataCollector.IsSRP ?
  1196. //m_propertyName :
  1197. string.Format( IOUtils.LWSRPInstancedPropertiesData, dataCollector.InstanceBlockName, m_propertyName ) :
  1198. string.Format( IOUtils.InstancedPropertiesData, m_propertyName );
  1199. bool insideSF = InsideShaderFunction;
  1200. ParentGraph cachedGraph = ContainerGraph.ParentWindow.CustomGraph;
  1201. if( insideSF )
  1202. ContainerGraph.ParentWindow.CustomGraph = this.ContainerGraph;
  1203. RegisterLocalVariable( 0, instancedVar, ref dataCollector, m_propertyName + "_Instance" );
  1204. if( insideSF )
  1205. ContainerGraph.ParentWindow.CustomGraph = cachedGraph;
  1206. }
  1207. }
  1208. public override string GenerateShaderForOutput( int outputId, ref MasterNodeDataCollector dataCollector, bool ignoreLocalvar )
  1209. {
  1210. RegisterProperty( ref dataCollector );
  1211. return string.Empty;
  1212. }
  1213. public override void Destroy()
  1214. {
  1215. base.Destroy();
  1216. UIUtils.UnregisterRawPropertyNode( this );
  1217. if( !string.IsNullOrEmpty( m_propertyName ) && UniqueId >= 0 )
  1218. UIUtils.ReleaseUniformName( UniqueId, m_propertyName );
  1219. if( m_currentParameterType == PropertyType.InstancedProperty )
  1220. {
  1221. UIUtils.CurrentWindow.OutsideGraph.RemoveInstancePropertyCount();
  1222. UIUtils.UnregisterPropertyNode( this );
  1223. }
  1224. if( m_currentParameterType == PropertyType.Property )
  1225. {
  1226. UIUtils.UnregisterPropertyNode( this );
  1227. }
  1228. if( m_availableAttribs != null )
  1229. m_availableAttribs.Clear();
  1230. m_availableAttribs = null;
  1231. }
  1232. private const string HeaderFormatStr = "[Header({0})]";
  1233. string BuildHeader()
  1234. {
  1235. string result = string.Empty;
  1236. for( int i = 0; i < m_headerAttributeValues.Count; i++ )
  1237. {
  1238. result += string.Format( HeaderFormatStr, m_headerAttributeValues[ i ] );
  1239. }
  1240. return result;
  1241. }
  1242. string BuildEnum()
  1243. {
  1244. string result = "[Enum(";
  1245. if( m_enumModeInt == 0 )
  1246. {
  1247. for( int i = 0; i < m_enumNames.Count; i++ )
  1248. {
  1249. result += m_enumNames[ i ] + "," + m_enumValues[ i ];
  1250. if( i + 1 < m_enumNames.Count )
  1251. result += ",";
  1252. }
  1253. }
  1254. else
  1255. {
  1256. result += m_enumClassName;
  1257. }
  1258. result += ")]";
  1259. return result;
  1260. }
  1261. public string PropertyAttributes
  1262. {
  1263. get
  1264. {
  1265. int attribCount = m_selectedAttribs.Count;
  1266. if( m_selectedAttribs.Count == 0 && m_customAttrCount == 0 )
  1267. return string.Empty;
  1268. string attribs = string.Empty;
  1269. for( int i = 0; i < attribCount; i++ )
  1270. {
  1271. if( m_availableAttribs[ m_selectedAttribs[ i ] ].Name.Equals( "Enum" ) )
  1272. attribs += BuildEnum();
  1273. else if( m_availableAttribs[ m_selectedAttribs[ i ] ].Name.Equals( HeaderId ) )
  1274. attribs += BuildHeader();
  1275. else
  1276. attribs += m_availableAttribs[ m_selectedAttribs[ i ] ].Attribute;
  1277. }
  1278. for( int i = 0; i < m_customAttrCount; i++ )
  1279. {
  1280. if( !string.IsNullOrEmpty( m_customAttr[ i ] ) )
  1281. attribs += "[" + m_customAttr[ i ] + "]";
  1282. }
  1283. return attribs;
  1284. }
  1285. }
  1286. public virtual void OnDirtyProperty() { }
  1287. public virtual void OnPropertyNameChanged() { UIUtils.UpdatePropertyDataNode( UniqueId, PropertyInspectorName ); }
  1288. public virtual void DrawSubProperties() { }
  1289. public virtual void DrawMaterialProperties() { }
  1290. public virtual string GetPropertyValue() { return string.Empty; }
  1291. public string GetInstancedUniformValue( bool isTemplate, bool isSRP )
  1292. {
  1293. if( isTemplate )
  1294. {
  1295. if( isSRP )
  1296. {
  1297. return string.Format( IOUtils.LWSRPInstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName );
  1298. //return GetUniformValue();
  1299. }
  1300. else
  1301. {
  1302. return string.Format( IOUtils.InstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName );
  1303. }
  1304. }
  1305. else
  1306. return string.Format( IOUtils.InstancedPropertiesElementTabs, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName );
  1307. }
  1308. public string GetInstancedUniformValue( bool isTemplate, bool isSRP, WirePortDataType dataType, string value )
  1309. {
  1310. if( isTemplate )
  1311. {
  1312. if( isSRP )
  1313. {
  1314. //return GetUniformValue( dataType, value );
  1315. return string.Format( IOUtils.LWSRPInstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value );
  1316. }
  1317. else
  1318. {
  1319. return string.Format( IOUtils.InstancedPropertiesElement, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value );
  1320. }
  1321. }
  1322. else
  1323. return string.Format( IOUtils.InstancedPropertiesElementTabs, UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value );
  1324. }
  1325. public virtual string GetUniformValue()
  1326. {
  1327. bool excludeUniformKeyword = ( m_currentParameterType == PropertyType.InstancedProperty ) ||
  1328. m_containerGraph.IsSRP;
  1329. int index = excludeUniformKeyword ? 1 : 0;
  1330. return string.Format( Constants.UniformDec[ index ], UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType ), m_propertyName );
  1331. }
  1332. public string GetUniformValue( WirePortDataType dataType, string value )
  1333. {
  1334. bool excludeUniformKeyword = ( m_currentParameterType == PropertyType.InstancedProperty ) ||
  1335. m_containerGraph.IsSRP;
  1336. int index = excludeUniformKeyword ? 1 : 0;
  1337. return string.Format( Constants.UniformDec[ index ], UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, dataType ), value );
  1338. }
  1339. public virtual bool GetUniformData( out string dataType, out string dataName, ref bool fullValue )
  1340. {
  1341. dataType = UIUtils.PrecisionWirePortToCgType( CurrentPrecisionType, m_outputPorts[ 0 ].DataType );
  1342. dataName = m_propertyName;
  1343. fullValue = false;
  1344. return true;
  1345. }
  1346. public PropertyType CurrentParameterType
  1347. {
  1348. get { return m_currentParameterType; }
  1349. set { m_currentParameterType = value; }
  1350. }
  1351. public override void WriteToString( ref string nodeInfo, ref string connectionsInfo )
  1352. {
  1353. base.WriteToString( ref nodeInfo, ref connectionsInfo );
  1354. IOUtils.AddFieldValueToString( ref nodeInfo, m_currentParameterType );
  1355. IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyName );
  1356. IOUtils.AddFieldValueToString( ref nodeInfo, m_propertyInspectorName );
  1357. IOUtils.AddFieldValueToString( ref nodeInfo, m_orderIndex );
  1358. int attribCount = m_selectedAttribs.Count;
  1359. IOUtils.AddFieldValueToString( ref nodeInfo, attribCount );
  1360. if( attribCount > 0 )
  1361. {
  1362. for( int i = 0; i < attribCount; i++ )
  1363. {
  1364. IOUtils.AddFieldValueToString( ref nodeInfo, m_availableAttribs[ m_selectedAttribs[ i ] ].Attribute );
  1365. }
  1366. }
  1367. IOUtils.AddFieldValueToString( ref nodeInfo, m_variableMode );
  1368. IOUtils.AddFieldValueToString( ref nodeInfo, m_autoGlobalName );
  1369. int headerCount = m_headerAttributeValues.Count;
  1370. IOUtils.AddFieldValueToString( ref nodeInfo, headerCount );
  1371. for( int i = 0; i < headerCount; i++ )
  1372. {
  1373. IOUtils.AddFieldValueToString( ref nodeInfo, m_headerAttributeValues[ i ] );
  1374. }
  1375. IOUtils.AddFieldValueToString( ref nodeInfo, m_enumCount );
  1376. for( int i = 0; i < m_enumCount; i++ )
  1377. {
  1378. IOUtils.AddFieldValueToString( ref nodeInfo, m_enumNames[ i ] );
  1379. IOUtils.AddFieldValueToString( ref nodeInfo, m_enumValues[ i ] );
  1380. }
  1381. IOUtils.AddFieldValueToString( ref nodeInfo, m_enumModeInt );
  1382. if( m_enumModeInt == 1 )
  1383. IOUtils.AddFieldValueToString( ref nodeInfo, m_enumClassName );
  1384. IOUtils.AddFieldValueToString( ref nodeInfo, m_autoRegister );
  1385. IOUtils.AddFieldValueToString( ref nodeInfo, m_customAttrCount );
  1386. if( m_customAttrCount > 0 )
  1387. {
  1388. for( int i = 0; i < m_customAttrCount; i++ )
  1389. {
  1390. IOUtils.AddFieldValueToString( ref nodeInfo, m_customAttr[ i ] );
  1391. }
  1392. }
  1393. IOUtils.AddFieldValueToString( ref nodeInfo, m_hybridInstanced );
  1394. }
  1395. int IdForAttrib( string name )
  1396. {
  1397. int attribCount = m_availableAttribs.Count;
  1398. for( int i = 0; i < attribCount; i++ )
  1399. {
  1400. if( m_availableAttribs[ i ].Attribute.Equals( name ) ||
  1401. (m_availableAttribs[ i ].HasDeprecatedValue && m_availableAttribs[ i ].DeprecatedValue.Equals( name ) ) )
  1402. return i;
  1403. }
  1404. return -1;
  1405. }
  1406. public override void ReadFromString( ref string[] nodeParams )
  1407. {
  1408. base.ReadFromString( ref nodeParams );
  1409. if( UIUtils.CurrentShaderVersion() < 2505 )
  1410. {
  1411. string property = GetCurrentParam( ref nodeParams );
  1412. m_currentParameterType = property.Equals( "Uniform" ) ? PropertyType.Global : (PropertyType)Enum.Parse( typeof( PropertyType ), property );
  1413. }
  1414. else
  1415. {
  1416. m_currentParameterType = (PropertyType)Enum.Parse( typeof( PropertyType ), GetCurrentParam( ref nodeParams ) );
  1417. }
  1418. if( m_currentParameterType == PropertyType.InstancedProperty )
  1419. {
  1420. UIUtils.CurrentWindow.OutsideGraph.AddInstancePropertyCount();
  1421. UIUtils.RegisterPropertyNode( this );
  1422. }
  1423. if( m_currentParameterType == PropertyType.Property )
  1424. {
  1425. UIUtils.RegisterPropertyNode( this );
  1426. }
  1427. m_propertyName = GetCurrentParam( ref nodeParams );
  1428. m_propertyInspectorName = GetCurrentParam( ref nodeParams );
  1429. if( UIUtils.CurrentShaderVersion() > 13 )
  1430. {
  1431. m_orderIndex = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1432. }
  1433. if( UIUtils.CurrentShaderVersion() > 4102 )
  1434. {
  1435. int attribAmount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1436. if( attribAmount > 0 )
  1437. {
  1438. for( int i = 0; i < attribAmount; i++ )
  1439. {
  1440. string attribute = GetCurrentParam( ref nodeParams );
  1441. int idForAttribute = IdForAttrib( attribute );
  1442. if( idForAttribute >= 0 )
  1443. {
  1444. m_selectedAttribs.Add( idForAttribute );
  1445. }
  1446. else
  1447. {
  1448. UIUtils.ShowMessage( UniqueId, string.Format( InvalidAttributeFormatter, attribute,m_propertyInspectorName ) , MessageSeverity.Warning );
  1449. }
  1450. }
  1451. m_visibleAttribsFoldout = true;
  1452. }
  1453. InitializeAttribsArray();
  1454. }
  1455. if( UIUtils.CurrentShaderVersion() > 14003 )
  1456. {
  1457. m_variableMode = (VariableMode)Enum.Parse( typeof( VariableMode ), GetCurrentParam( ref nodeParams ) );
  1458. }
  1459. if( UIUtils.CurrentShaderVersion() > 14201 )
  1460. {
  1461. m_autoGlobalName = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  1462. }
  1463. if( UIUtils.CurrentShaderVersion() > 18707 )
  1464. {
  1465. if( UIUtils.CurrentShaderVersion() == 18708 )
  1466. {
  1467. m_headerAttributeValues.Add( GetCurrentParam( ref nodeParams ) );
  1468. }
  1469. else
  1470. {
  1471. int headerCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1472. for( int i = 0; i < headerCount; i++ )
  1473. {
  1474. m_headerAttributeValues.Add( GetCurrentParam( ref nodeParams ) );
  1475. }
  1476. }
  1477. }
  1478. if( UIUtils.CurrentShaderVersion() > 14403 )
  1479. {
  1480. m_enumCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1481. for( int i = 0; i < m_enumCount; i++ )
  1482. {
  1483. m_enumNames.Add( GetCurrentParam( ref nodeParams ) );
  1484. m_enumValues.Add( Convert.ToInt32( GetCurrentParam( ref nodeParams ) ) );
  1485. }
  1486. }
  1487. if( UIUtils.CurrentShaderVersion() > 14501 )
  1488. {
  1489. m_enumModeInt = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1490. if( m_enumModeInt == 1 )
  1491. m_enumClassName = GetCurrentParam( ref nodeParams );
  1492. m_autoRegister = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  1493. m_customAttrCount = Convert.ToInt32( GetCurrentParam( ref nodeParams ) );
  1494. for( int i = 0; i < m_customAttrCount; i++ )
  1495. {
  1496. m_customAttr.Add( GetCurrentParam( ref nodeParams ) );
  1497. }
  1498. if( m_customAttrCount > 0 )
  1499. {
  1500. m_visibleCustomAttrFoldout = true;
  1501. m_visibleAttribsFoldout = true;
  1502. }
  1503. }
  1504. if( UIUtils.CurrentShaderVersion() > 18003 )
  1505. {
  1506. m_hybridInstanced = Convert.ToBoolean( GetCurrentParam( ref nodeParams ) );
  1507. }
  1508. CheckEnumAttribute();
  1509. CheckHeaderAttribute();
  1510. if( m_enumCount > 0 )
  1511. m_visibleEnumsFoldout = true;
  1512. m_propertyNameIsDirty = true;
  1513. m_reRegisterName = false;
  1514. if( !m_isNodeBeingCopied )
  1515. {
  1516. if( m_variableMode != VariableMode.Fetch || m_currentParameterType == PropertyType.Constant )
  1517. {
  1518. UIUtils.ReleaseUniformName( UniqueId, m_oldName );
  1519. UIUtils.RegisterUniformName( UniqueId, m_propertyName );
  1520. m_oldName = m_propertyName;
  1521. }
  1522. }
  1523. else
  1524. {
  1525. m_oldName = m_propertyName;
  1526. }
  1527. ReleaseRansomedProperty();
  1528. }
  1529. public virtual void ReleaseRansomedProperty()
  1530. {
  1531. if( m_variableMode == VariableMode.Fetch/* && m_autoGlobalName */)
  1532. {
  1533. //Fooling setter to have a different value
  1534. m_variableMode = VariableMode.Create;
  1535. CurrentVariableMode = VariableMode.Fetch;
  1536. }
  1537. }
  1538. void UpdateTooltip()
  1539. {
  1540. string currValue = string.Empty;
  1541. if( m_currentParameterType != PropertyType.Constant )
  1542. {
  1543. currValue = ( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior ) ? "<GLOBAL>" : GetPropertyValStr();
  1544. }
  1545. else
  1546. {
  1547. currValue = GetPropertyValStr();
  1548. }
  1549. m_tooltipText = string.Format( TooltipFormatter, m_nodeAttribs.Description, m_propertyInspectorName, currValue );
  1550. }
  1551. public override void SetClippedTitle( string newText, int maxSize = 170, string endString = "..." )
  1552. {
  1553. base.SetClippedTitle( newText, maxSize, endString );
  1554. UpdateTooltip();
  1555. }
  1556. public override void SetClippedAdditionalTitle( string newText, int maxSize = 170, string endString = "..." )
  1557. {
  1558. base.SetClippedAdditionalTitle( newText, maxSize, endString );
  1559. UpdateTooltip();
  1560. }
  1561. public override void OnEnable()
  1562. {
  1563. base.OnEnable();
  1564. m_reRegisterName = true;
  1565. }
  1566. public bool CanDrawMaterial { get { return m_materialMode && m_currentParameterType != PropertyType.Constant; } }
  1567. public int RawOrderIndex
  1568. {
  1569. get { return m_orderIndex; }
  1570. }
  1571. public int OrderIndex
  1572. {
  1573. get { return m_orderIndex + m_orderIndexOffset; }
  1574. set { m_orderIndex = value; }
  1575. }
  1576. public int OrderIndexOffset
  1577. {
  1578. get { return m_orderIndexOffset; }
  1579. set { m_orderIndexOffset = value; }
  1580. }
  1581. public VariableMode CurrentVariableMode
  1582. {
  1583. get { return m_variableMode; }
  1584. set
  1585. {
  1586. if( value != m_variableMode )
  1587. {
  1588. m_variableMode = value;
  1589. if( value == VariableMode.Fetch )
  1590. {
  1591. // Release ownership on name
  1592. if( UIUtils.CheckUniformNameOwner( m_oldName ) == UniqueId )
  1593. {
  1594. UIUtils.ReleaseUniformName( UniqueId , m_oldName );
  1595. }
  1596. m_oldName = m_propertyName;
  1597. }
  1598. else
  1599. {
  1600. if( !m_propertyName.Equals( m_oldName ) )
  1601. {
  1602. if( UIUtils.IsUniformNameAvailable( m_propertyName ) )
  1603. {
  1604. UIUtils.ReleaseUniformName( UniqueId, m_oldName );
  1605. UIUtils.RegisterUniformName( UniqueId, m_propertyName );
  1606. }
  1607. else
  1608. {
  1609. UIUtils.ShowMessage( UniqueId, string.Format( FetchToCreateDuplicatesMsg, m_propertyName, m_oldName ), MessageSeverity.Warning );
  1610. m_propertyName = m_oldName;
  1611. }
  1612. m_propertyNameIsDirty = true;
  1613. OnPropertyNameChanged();
  1614. }
  1615. else
  1616. {
  1617. if( UIUtils.IsUniformNameAvailable( m_propertyName ) )
  1618. {
  1619. UIUtils.RegisterUniformName( UniqueId , m_propertyName );
  1620. }
  1621. else if( UIUtils.CheckUniformNameOwner( m_propertyName ) != UniqueId )
  1622. {
  1623. string oldProperty = m_propertyName;
  1624. RegisterFirstAvailablePropertyName( false );
  1625. UIUtils.ShowMessage( UniqueId, string.Format( FetchToCreateOnDuplicateNodeMsg, m_propertyName, oldProperty ), MessageSeverity.Warning );
  1626. }
  1627. }
  1628. }
  1629. }
  1630. }
  1631. }
  1632. public string PropertyData( MasterNodePortCategory portCategory )
  1633. {
  1634. return ( m_currentParameterType == PropertyType.InstancedProperty ) ? m_outputPorts[ 0 ].LocalValue( portCategory ) : m_propertyName;
  1635. }
  1636. public override void OnNodeLogicUpdate( DrawInfo drawInfo )
  1637. {
  1638. base.OnNodeLogicUpdate( drawInfo );
  1639. if( m_currentParameterType == PropertyType.Global && m_globalDefaultBehavior && ( EditorApplication.timeSinceStartup - m_globalFetchTimestamp ) > MaxGlobalFetchTimestamp )
  1640. {
  1641. FetchGlobalValue();
  1642. m_globalFetchTimestamp = EditorApplication.timeSinceStartup;
  1643. }
  1644. }
  1645. public void ShowGlobalValueButton()
  1646. {
  1647. if( GUILayout.Button( "Set Global Value" ) )
  1648. {
  1649. SetGlobalValue();
  1650. }
  1651. }
  1652. public override bool CheckFindText( string text )
  1653. {
  1654. return base.CheckFindText( text ) ||
  1655. m_propertyName.IndexOf( text, StringComparison.CurrentCultureIgnoreCase ) >= 0 ||
  1656. m_propertyInspectorName.IndexOf( text, StringComparison.CurrentCultureIgnoreCase ) >= 0;
  1657. }
  1658. //This should only be used on template internal properties
  1659. public void PropertyNameFromTemplate( TemplateShaderPropertyData data )
  1660. {
  1661. m_propertyName = data.PropertyName;
  1662. m_propertyInspectorName = data.PropertyInspectorName;
  1663. }
  1664. public virtual void GeneratePPSInfo( ref string propertyDeclaration, ref string propertySet ) { }
  1665. public virtual void SetGlobalValue() { }
  1666. public virtual void FetchGlobalValue() { }
  1667. public virtual string PropertyName { get { return m_propertyName; } }
  1668. public virtual string PropertyInspectorName { get { return m_propertyInspectorName; } }
  1669. public bool FreeType { get { return m_freeType; } set { m_freeType = value; } }
  1670. public bool ReRegisterName { get { return m_reRegisterName; } set { m_reRegisterName = value; } }
  1671. public string CustomPrefix { get { return m_customPrefix; } set { m_customPrefix = value; } }
  1672. public override void RefreshOnUndo()
  1673. {
  1674. base.RefreshOnUndo();
  1675. BeginPropertyFromInspectorCheck();
  1676. }
  1677. public override string DataToArray { get { return PropertyInspectorName; } }
  1678. public bool RegisterPropertyOnInstancing { get { return m_registerPropertyOnInstancing; } set { m_registerPropertyOnInstancing = value; } }
  1679. public bool SrpBatcherCompatible { get { return m_srpBatcherCompatible; } }
  1680. public bool AddGlobalToSRPBatcher { get { return m_addGlobalToSRPBatcher; } set { m_addGlobalToSRPBatcher = value; } }
  1681. public bool AutoRegister { get { return m_autoRegister; } set { m_autoRegister = value; } }
  1682. }
  1683. }