You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2752 lines
110 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.Collections.Generic;
  6. using System.IO;
  7. using System.Globalization;
  8. using System.Text.RegularExpressions;
  9. namespace AmplifyShaderEditor
  10. {
  11. public enum ASEColorSpace
  12. {
  13. Auto,
  14. Gamma,
  15. Linear
  16. }
  17. public enum SurfaceInputs
  18. {
  19. DEPTH = 0,
  20. UV_COORDS,
  21. UV2_COORDS,
  22. VIEW_DIR,
  23. COLOR,
  24. SCREEN_POS,
  25. WORLD_POS,
  26. WORLD_REFL,
  27. WORLD_NORMAL,
  28. VFACE,
  29. INTERNALDATA
  30. }
  31. public enum CustomStyle
  32. {
  33. NodeWindowOff = 0,
  34. NodeWindowOn,
  35. NodeTitle,
  36. NodeHeader,
  37. CommentaryHeader,
  38. ShaderLibraryTitle,
  39. ShaderLibraryAddToList,
  40. ShaderLibraryRemoveFromList,
  41. ShaderLibraryOpenListed,
  42. ShaderLibrarySelectionAsTemplate,
  43. ShaderLibraryItem,
  44. CommentaryTitle,
  45. PortEmptyIcon,
  46. PortFullIcon,
  47. InputPortlabel,
  48. OutputPortLabel,
  49. CommentaryResizeButton,
  50. CommentaryResizeButtonInv,
  51. CommentaryBackground,
  52. MinimizeButton,
  53. MaximizeButton,
  54. NodePropertiesTitle,
  55. ShaderModeTitle,
  56. MaterialModeTitle,
  57. ShaderNoMaterialModeTitle,
  58. PropertyValuesTitle,
  59. ShaderModeNoShader,
  60. MainCanvasTitle,
  61. ShaderBorder,
  62. MaterialBorder,
  63. SamplerTextureRef,
  64. SamplerTextureIcon,
  65. CustomExpressionAddItem,
  66. CustomExpressionRemoveItem,
  67. CustomExpressionSmallAddItem,
  68. CustomExpressionSmallRemoveItem,
  69. ResetToDefaultInspectorButton,
  70. SliderStyle,
  71. ObjectPicker,
  72. NodePropertyPicker,
  73. NodePreviewExpander,
  74. NodePreviewCollapser,
  75. SamplerButton,
  76. SamplerFrame,
  77. CommentarySuperTitle,
  78. MiniButtonTopLeft,
  79. MiniButtonTopMid,
  80. MiniButtonTopRight,
  81. ShaderFunctionBorder,
  82. ShaderFunctionMode,
  83. RightShaderMode,
  84. FlatBackground,
  85. DocumentationLink,
  86. GraphButtonIcon,
  87. GraphButton,
  88. NodeWindowOffSquare,
  89. NodeHeaderSquare,
  90. NodeWindowOnSquare
  91. }
  92. public enum MasterNodePortCategory
  93. {
  94. Vertex = 1 << 0,
  95. Fragment = 1 << 1,
  96. Tessellation = 1 << 2,
  97. Debug = 1 << 3
  98. }
  99. public enum PortGenType
  100. {
  101. NonCustomLighting,
  102. //Normal = 1 << 1,
  103. //Emission = 1 << 2,
  104. //Metallic = 1 << 3,
  105. //Specular = 1 << 4,
  106. CustomLighting
  107. }
  108. public struct NodeData
  109. {
  110. public MasterNodePortCategory Category;
  111. public int OrderIndex;
  112. public int GraphDepth;
  113. public NodeData( MasterNodePortCategory category )
  114. {
  115. Category = category;
  116. OrderIndex = 0;
  117. GraphDepth = -1;
  118. }
  119. }
  120. public struct NodeCastInfo
  121. {
  122. public int NodeId;
  123. public int PortId;
  124. public NodeCastInfo( int nodeId, int portId )
  125. {
  126. NodeId = nodeId;
  127. PortId = portId;
  128. }
  129. public override string ToString()
  130. {
  131. return NodeId.ToString() + PortId.ToString();
  132. }
  133. };
  134. public struct ButtonClickId
  135. {
  136. public const int LeftMouseButton = 0;
  137. public const int RightMouseButton = 1;
  138. public const int MiddleMouseButton = 2;
  139. }
  140. public enum ASESelectionMode
  141. {
  142. Shader = 0,
  143. Material,
  144. ShaderFunction
  145. }
  146. public enum DrawOrder
  147. {
  148. Background,
  149. Default
  150. }
  151. public enum NodeConnectionStatus
  152. {
  153. Not_Connected = 0,
  154. Connected,
  155. Error,
  156. Island
  157. }
  158. public enum InteractionMode
  159. {
  160. Target,
  161. Other,
  162. Both
  163. }
  164. public enum FunctionNodeCategories
  165. {
  166. Custom,
  167. CameraAndScreen,
  168. ConstantsAndProperties,
  169. Functions,
  170. ImageEffects,
  171. Light,
  172. LogicalOperators,
  173. MathOperators,
  174. MatrixOperators,
  175. Miscellaneous,
  176. ObjectTransform,
  177. SurfaceData,
  178. Textures,
  179. Time,
  180. TrignometryOperators,
  181. UVCoordinates,
  182. VectorOperators,
  183. VertexData
  184. }
  185. public enum TransformSpace
  186. {
  187. Object = 0,
  188. World,
  189. View,
  190. Clip,
  191. Tangent
  192. //Screen??
  193. }
  194. public class UIUtils
  195. {
  196. public static int SerializeHelperCounter = 0;
  197. public static bool IgnoreDeselectAll = false;
  198. public static bool DirtyMask = true;
  199. public static bool Initialized = false;
  200. public static float HeaderMaxHeight;
  201. public static float CurrentHeaderHeight;
  202. public static GUISkin MainSkin = null;
  203. public static GUIStyle PlusStyle;
  204. public static GUIStyle MinusStyle;
  205. public static GUIStyle RangedFloatSliderStyle;
  206. public static GUIStyle RangedFloatSliderThumbStyle;
  207. public static GUIStyle SwitchNodePopUp;
  208. public static GUIStyle PropertyPopUp;
  209. public static GUIStyle ObjectField;
  210. public static GUIStyle PreviewExpander;
  211. public static GUIStyle PreviewCollapser;
  212. public static GUIStyle ObjectFieldThumb;
  213. public static GUIStyle ObjectFieldThumbOverlay;
  214. public static GUIStyle InspectorPopdropdownStyle;
  215. public static GUIStyle InspectorPopdropdownFallback;
  216. public static GUIStyle BoldErrorStyle;
  217. public static GUIStyle BoldWarningStyle;
  218. public static GUIStyle BoldInfoStyle;
  219. public static GUIStyle Separator;
  220. public static GUIStyle ToolbarSearchTextfield;
  221. public static GUIStyle ToolbarSearchCancelButton;
  222. public static GUIStyle MiniButtonTopLeft;
  223. public static GUIStyle MiniButtonTopMid;
  224. public static GUIStyle MiniButtonTopRight;
  225. public static GUIStyle CommentaryTitle;
  226. public static GUIStyle InputPortLabel;
  227. public static GUIStyle OutputPortLabel;
  228. public static GUIStyle MiniObjectFieldThumbOverlay;
  229. public static GUIStyle MiniSamplerButton;
  230. public static GUIStyle NodeWindowOffSquare;
  231. public static GUIStyle NodeHeaderSquare;
  232. public static GUIStyle NodeWindowOnSquare;
  233. public static GUIStyle InternalDataOnPort;
  234. public static GUIStyle InternalDataBackground;
  235. public static GUIStyle GraphButtonIcon;
  236. public static GUIStyle GraphButton;
  237. public static GUIStyle GraphDropDown;
  238. public static GUIStyle EmptyStyle = new GUIStyle();
  239. public static GUIStyle TooltipBox;
  240. public static GUIStyle Box;
  241. public static GUIStyle Button;
  242. public static GUIStyle TextArea;
  243. public static GUIStyle Label;
  244. public static GUIStyle Toggle;
  245. public static GUIStyle Textfield;
  246. public static GUIStyle UnZoomedNodeTitleStyle;
  247. public static GUIStyle UnZoomedPropertyValuesTitleStyle;
  248. public static GUIStyle UnZoomedInputPortStyle;
  249. public static GUIStyle UnZoomedOutputPortPortStyle;
  250. // Node Property Menu items
  251. public static GUIStyle MenuItemToggleStyle;
  252. public static GUIStyle MenuItemEnableStyle;
  253. public static GUIStyle MenuItemBackgroundStyle;
  254. public static GUIStyle MenuItemToolbarStyle;
  255. public static GUIStyle MenuItemInspectorDropdownStyle;
  256. public static GUIStyle FloatIntPickerONOFF;
  257. public static bool UsingProSkin = false;
  258. public static Texture ShaderIcon { get { return EditorGUIUtility.IconContent( "Shader Icon" ).image; } }
  259. public static Texture MaterialIcon { get { return EditorGUIUtility.IconContent( "Material Icon" ).image; } }
  260. //50be8291f9514914aa55c66c49da67cf
  261. public static Texture ShaderFunctionIcon { get { return AssetDatabase.LoadAssetAtPath<Texture>( AssetDatabase.GUIDToAssetPath( "50be8291f9514914aa55c66c49da67cf" ) ); } }
  262. public static Texture2D WireNodeSelection = null;
  263. public static Texture2D SliderButton = null;
  264. public static Texture2D SmallErrorIcon = null;
  265. public static Texture2D SmallWarningIcon = null;
  266. public static Texture2D SmallInfoIcon = null;
  267. public static Texture2D CheckmarkIcon = null;
  268. public static Texture2D PopupIcon = null;
  269. public static Texture2D MasterNodeOnTexture = null;
  270. public static Texture2D MasterNodeOffTexture = null;
  271. public static Texture2D GPUInstancedOnTexture = null;
  272. public static Texture2D GPUInstancedOffTexture = null;
  273. public static GUIContent LockIconOpen = null;
  274. public static GUIContent LockIconClosed = null;
  275. public static GUIContent FloatIntIconON = null;
  276. public static GUIContent FloatIntIconOFF = null;
  277. public static bool ShowContextOnPick = true;
  278. private static AmplifyShaderEditorWindow m_currentWindow = null;
  279. public static AmplifyShaderEditorWindow CurrentWindow
  280. {
  281. get
  282. {
  283. if( m_currentWindow == null )
  284. {
  285. for( int i = 0; i < IOUtils.AllOpenedWindows.Count; i++ )
  286. {
  287. if( IOUtils.AllOpenedWindows[ i ] != null )
  288. {
  289. m_currentWindow = IOUtils.AllOpenedWindows[ i ];
  290. }
  291. else
  292. {
  293. //Debug.Log("No Window Found!");
  294. }
  295. }
  296. }
  297. return m_currentWindow;
  298. }
  299. set { m_currentWindow = value; }
  300. }
  301. public static Vector2 PortsSize;
  302. public static Vector3 PortsDelta;
  303. public static Vector3 ScaledPortsDelta;
  304. public static RectOffset RectOffsetZero;
  305. public static RectOffset RectOffsetOne;
  306. public static RectOffset RectOffsetTwo;
  307. public static RectOffset RectOffsetThree;
  308. public static RectOffset RectOffsetFour;
  309. public static RectOffset RectOffsetFive;
  310. public static RectOffset RectOffsetSix;
  311. public static Material LinearMaterial = null;
  312. public static Shader IntShader = null;
  313. public static Shader FloatShader = null;
  314. public static Shader Vector2Shader = null;
  315. public static Shader Vector3Shader = null;
  316. public static Shader Vector4Shader = null;
  317. public static Shader ColorShader = null;
  318. public static Shader Texture2DShader = null;
  319. public static Shader MaskingShader = null;
  320. public static bool InhibitMessages = false;
  321. private static int m_shaderIndentLevel = 0;
  322. private static string m_shaderIndentTabs = string.Empty;
  323. //Label Vars
  324. private static TextAnchor m_alignment;
  325. private static TextClipping m_clipping;
  326. private static bool m_wordWrap;
  327. private static int m_fontSize;
  328. private static Color m_fontColor;
  329. private static FontStyle m_fontStyle;
  330. private static string NumericNamePattern = @"^\d";
  331. private static System.Globalization.TextInfo m_textInfo;
  332. private static string m_latestOpenedFolder = string.Empty;
  333. private static Dictionary<int, UndoParentNode> m_undoHelper = new Dictionary<int, UndoParentNode>();
  334. private static Dictionary<string, int> AvailableKeywordsDict = new Dictionary<string, int>();
  335. public static readonly string[] AvailableKeywords =
  336. {
  337. "Custom",
  338. "ETC1_EXTERNAL_ALPHA",
  339. "PIXELSNAP_ON",
  340. "UNITY_PASS_FORWARDBASE",
  341. "UNITY_PASS_FORWARDADD",
  342. "UNITY_PASS_DEFERRED",
  343. "UNITY_PASS_SHADOWCASTER"
  344. };
  345. public static readonly string[] CategoryPresets =
  346. {
  347. "<Custom>",
  348. "Camera And Screen",
  349. "Constants And Properties",
  350. "Functions",
  351. "Image Effects",
  352. "Light",
  353. "Logical Operators",
  354. "Math Operators",
  355. "Matrix Operators",
  356. "Miscellaneous",
  357. "Object Transform",
  358. "Surface Data",
  359. "Textures",
  360. "Time",
  361. "Trignometry Operators",
  362. "UV Coordinates",
  363. "Vector Operators",
  364. "Vertex Data"
  365. };
  366. private static Dictionary<MasterNodePortCategory, int> m_portCategoryToArrayIdx = new Dictionary<MasterNodePortCategory, int>
  367. {
  368. { MasterNodePortCategory.Vertex,0},
  369. { MasterNodePortCategory.Tessellation,0},
  370. { MasterNodePortCategory.Fragment,1},
  371. { MasterNodePortCategory.Debug,1}
  372. };
  373. private static Dictionary<string, string> m_reservedPropertyNames = new Dictionary<string, string>
  374. {
  375. { "UNITY_MATRIX_MVP", string.Empty},
  376. { "UNITY_MATRIX_MV", string.Empty},
  377. { "UNITY_MATRIX_V", string.Empty},
  378. { "UNITY_MATRIX_P", string.Empty},
  379. { "UNITY_MATRIX_VP", string.Empty},
  380. { "UNITY_MATRIX_T_MV", string.Empty},
  381. { "UNITY_MATRIX_IT_MV", string.Empty},
  382. { "UNITY_MATRIX_TEXTURE0", string.Empty},
  383. { "UNITY_MATRIX_TEXTURE1", string.Empty},
  384. { "UNITY_MATRIX_TEXTURE2", string.Empty},
  385. { "UNITY_MATRIX_TEXTURE3", string.Empty},
  386. { "_Object2World", string.Empty},
  387. { "_WorldSpaceCameraPos", string.Empty},
  388. { "unity_Scale", string.Empty},
  389. { "_ModelLightColor", string.Empty},
  390. { "_SpecularLightColor", string.Empty},
  391. { "_ObjectSpaceLightPos", string.Empty},
  392. { "_Light2World", string.Empty},
  393. { "_World2Light", string.Empty},
  394. { "_Object2Light", string.Empty},
  395. { "_Time", string.Empty},
  396. { "_SinTime", string.Empty},
  397. { "_CosTime", string.Empty},
  398. { "unity_DeltaTime", string.Empty},
  399. { "_ProjectionParams", string.Empty},
  400. { "_ScreenParams", string.Empty}
  401. };
  402. private static Dictionary<string, string> m_exampleMaterialIDs = new Dictionary<string, string>()
  403. {
  404. //Community
  405. {"2Sided", "8ebbbf2c99a544ca780a2573ef1450fc" },
  406. {"DissolveBurn", "f144f2d7ff3daf349a2b7f0fd81ec8ac" },
  407. {"MourEnvironmentGradient", "b64adae401bc073408ac7bff0993c107" },
  408. {"ForceShield", "0119aa6226e2a4cfdb6c9a5ba9df7820" },
  409. {"HighlightAnimated", "3d232e7526f6e426cab994cbec1fc287" },
  410. {"Hologram", "b422c600f1c3941b8bc7e95db33476ad" },
  411. {"LowPolyWater", "0557703d3791a4286a62f8ee709d5bef"},
  412. //Official
  413. {"AnimatedFire", "63ea5eae6d954a14292033589d0d4275" },
  414. {"AnimatedFire-ShaderFunction", "9c6c9fcb82afe874a825a9e680e694b2" },
  415. {"BurnEffect", "0b019675a8064414b97862a02f644166" },
  416. {"CubemapReflections", "2c299f827334e9c459a60931aea62260" },
  417. {"DitheringFade", "610507217b7dcad4d97e6e03e9844171" },
  418. {"DoubleLayerCustomSurface", "846aec4914103104d99e9e31a217b548" },
  419. {"NormalExtrusion", "70a5800fbba039f46b438a2055bc6c71" },
  420. {"MatcapSample", "da8aaaf01fe8f2b46b2fbcb803bd7af4" },
  421. {"ParallaxMappingIterations", "a0cea9c3f318ac74d89cd09134aad000" },
  422. {"SandPOM", "905481dc696211145b88dc4bac2545f3" },
  423. {"ParallaxWindow", "63ad0e7afb1717b4e95adda8904ab0c3" },
  424. {"LocalPosCutoff", "fed8c9d33a691084c801573feeed5a62" },
  425. {"ImprovedReadFromAtlasTiled", "941b31b251ea8e74f9198d788a604c9b" },
  426. {"ReadFromAtlasTiled", "2d5537aa702f24645a1446dc3be92bbf" },
  427. {"ReflectRefractSoapBubble", "a844987c9f2e7334abaa34f12feda3b9" },
  428. {"RimLight", "e2d3a4d723cf1dc4eab1d919f3324dbc" },
  429. {"RefractedShadows", "11818aa28edbeb04098f3b395a5bfc1d" },
  430. {"TextureArray", "0f572993ab788a346aea45f2f797b7fa" },
  431. {"ObjectNormalRefraction", "f1a0a645876302547b608ce881c94e6d" },
  432. {"ShaderBallInterior", "e47ee174f55b6144b9c1a942bb23d82a" },
  433. {"ScreenSpaceCurvature", "2e794cb9b3900b043a37ba28cdc2f907" },
  434. {"ScreenSpaceDetail", "3a0163d12fede4d47a1f818a66a115de" },
  435. {"SimpleNoise", "cc167bc6c2063a14f84a5a77be541194" },
  436. {"SimpleBlur", "1d283ff911af20e429180bb15d023661" },
  437. {"SimpleGPUInstancing", "9d609a7c8d00c7c4c9bdcdcdba154b81" },
  438. {"SimpleLambert", "54b29030f7d7ffe4b84f2f215dede5ac" },
  439. {"SimpleRefraction", "58c94d2f48acdc049a53b4ca53d6d98a" },
  440. {"SimpleTexture", "9661085a7d249a54c95078ac8e7ff004" },
  441. {"SnowAccum", "e3bd639f50ae1a247823079047a8dc01" },
  442. {"StencilDiffuse01", "9f47f529fdeddd948a2d2722f73e6ac4" },
  443. {"StencilMask01", "6f870834077d59b44ac421c36f619d59" },
  444. {"StencilDiffuse02", "11cdb862d5ba68c4eae526765099305b" },
  445. {"StencilMask02", "344696733b065c646b18c1aa2eacfdb7" },
  446. {"StencilDiffuse03", "75e851f6c686a5f42ab900222b29355b" },
  447. {"StencilMask03", "c7b3018ad495c6b479f2e3f8564aa6dc" },
  448. {"SubstanceExample", "a515e243b476d7e4bb37eb9f82c87a12" },
  449. {"AnimatedRefraction", "e414af1524d258047bb6b82b8860062c" },
  450. {"Tessellation", "efb669a245f17384c88824d769d0087c" },
  451. {"Translucency", "842ba3dcdd461ea48bdcfcea316cbcc4" },
  452. {"Transmission", "1b21506b7afef734facfc42c596caa7b" },
  453. {"Transparency", "e323a62068140c2408d5601877e8de2c" },
  454. {"TriplanarProjection", "663d512de06d4e24db5205c679f394cb" },
  455. {"TwoSideWithFace", "c953c4b601ba78e4f870d24d038b67f6" },
  456. {"Ground", "48df9bdf7b922d94bb3167e6db39c943" },
  457. {"WaterSample", "288137d67ce790e41903020c572ab4d7" },
  458. {"WorldPosSlices", "013cc03f77f3d034692f902db8928787" }
  459. };
  460. private static Dictionary<TextureType, string> m_textureTypeToCgType = new Dictionary<TextureType, string>()
  461. {
  462. {TextureType.Texture1D, "sampler1D" },
  463. {TextureType.Texture2D, "sampler2D" },
  464. {TextureType.Texture3D, "sampler3D" },
  465. {TextureType.Cube , "samplerCUBE"},
  466. {TextureType.Texture2DArray, "sampler2D" },
  467. {TextureType.ProceduralTexture, "sampler2D" }
  468. };
  469. private static Dictionary<string, Color> m_nodeCategoryToColor = new Dictionary<string, Color>()
  470. {
  471. { "Master", new Color( 0.6f, 0.52f, 0.43f, 1.0f )},
  472. { "Default", new Color( 0.26f, 0.35f, 0.44f, 1.0f )},
  473. { "Vertex Data", new Color( 0.8f, 0.07f, 0.18f, 1.0f)},//new Color( 0.75f, 0.10f, 0.30f, 1.0f )},
  474. { "Math Operators", new Color( 0.26f, 0.35f, 0.44f, 1.0f )},//new Color( 0.10f, 0.27f, 0.45f, 1.0f) },
  475. { "Logical Operators", new Color( 0.0f, 0.55f, 0.45f, 1.0f)},//new Color( 0.11f, 0.28f, 0.47f, 1.0f) },
  476. { "Trigonometry Operators", new Color( 0.1f, 0.20f, 0.35f, 1.0f)},//new Color( 0.8f, 0.07f, 0.18f, 1.0f)},
  477. { "Image Effects", new Color( 0.5f, 0.2f, 0.90f, 1.0f)},//new Color( 0.12f, 0.47f, 0.88f, 1.0f)},
  478. { "Miscellaneous", new Color( 0.49f, 0.32f, 0.60f, 1.0f)},
  479. { "Camera And Screen", new Color( 0.75f, 0.10f, 0.30f, 1.0f )},//new Color( 0.17f, 0.22f, 0.07f, 1.0f) },
  480. { "Constants And Properties", new Color( 0.42f, 0.70f, 0.22f, 1.0f) },
  481. { "Surface Data", new Color( 0.92f, 0.73f, 0.03f, 1.0f)},
  482. { "Matrix Transform", new Color( 0.09f, 0.43f, 0.2f, 1.0f) },
  483. { "Time", new Color( 0.25f, 0.25f, 0.25f, 1.0f)},//new Color( 0.89f, 0.59f, 0.0f, 1.0f) },
  484. { "Functions", new Color( 1.00f, 0.4f, 0.0f, 1.0f) },
  485. { "Vector Operators", new Color( 0.22f, 0.20f, 0.45f, 1.0f)},
  486. { "Matrix Operators", new Color( 0.45f, 0.9f, 0.20f, 1.0f) },
  487. { "Light", new Color( 1.0f, 0.9f, 0.0f, 1.0f) },
  488. { "Textures", new Color( 0.15f, 0.40f, 0.8f, 1.0f)},
  489. { "Commentary", new Color( 0.7f, 0.7f, 0.7f, 1.0f)},
  490. { "UV Coordinates", new Color( 0.89f, 0.59f, 0.0f, 1.0f) },
  491. { "Object Transform", new Color( 0.15f, 0.4f, 0.49f, 1.0f)},
  492. { "Vertex Transform", new Color( 0.15f, 0.4f, 0.49f, 1.0f)}
  493. };
  494. private static Dictionary<ToolButtonType, List<string>> m_toolButtonTooltips = new Dictionary<ToolButtonType, List<string>>
  495. {
  496. { ToolButtonType.New, new List<string>() { "Create new shader." } },
  497. { ToolButtonType.Open, new List<string>() { "Open existing shader." } },
  498. { ToolButtonType.Save, new List<string>() { "No changes to save.", "Save current changes." } },
  499. { ToolButtonType.Library, new List<string>() { "Lists custom shader selection." } },
  500. { ToolButtonType.Options, new List<string>() { "Open Options menu." } },
  501. { ToolButtonType.Update, new List<string>() { "Open or create a new shader first.", "Click to enable to update current shader.", "Shader up-to-date." } },
  502. { ToolButtonType.Live, new List<string>() { "Open or create a new shader first.", "Click to enable live shader preview", "Click to enable live shader and material preview." , "Live preview active, click to disable." } },
  503. { ToolButtonType.CleanUnusedNodes, new List<string>() { "No unconnected nodes to clean.", "Remove all nodes not connected( directly or indirectly) to the master node." }},
  504. { ToolButtonType.Help, new List<string>() { "Show help window." } },
  505. { ToolButtonType.FocusOnMasterNode,new List<string>() { "Focus on active master node." } },
  506. { ToolButtonType.FocusOnSelection, new List<string>() { "Focus on selection fit to screen ( if none selected )." } }
  507. };
  508. private static Color[] m_dataTypeToColorMonoMode = { new Color( 0.5f, 0.5f, 0.5f, 1.0f ), Color.white };
  509. private static Dictionary<WirePortDataType, Color> m_dataTypeToColor = new Dictionary<WirePortDataType, Color>( new WirePortDataTypeComparer() )
  510. {
  511. { WirePortDataType.OBJECT, Color.white},
  512. { WirePortDataType.FLOAT, Color.gray},
  513. { WirePortDataType.FLOAT2, new Color(1f,1f,0f,1f)},
  514. { WirePortDataType.FLOAT3, new Color(0.5f,0.5f,1f,1f)},
  515. { WirePortDataType.FLOAT4, new Color(1f,0,1f,1f)},
  516. { WirePortDataType.FLOAT3x3, new Color(0.5f,1f,0.5f,1f)},
  517. { WirePortDataType.FLOAT4x4, new Color(0.5f,1f,0.5f,1f)},
  518. { WirePortDataType.COLOR, new Color(1f,0,1f,1f)},
  519. { WirePortDataType.INT, Color.gray},
  520. { WirePortDataType.SAMPLER1D, new Color(1f,0.5f,0f,1f)},
  521. { WirePortDataType.SAMPLER2D, new Color(1f,0.5f,0f,1f)},
  522. { WirePortDataType.SAMPLER3D, new Color(1f,0.5f,0f,1f)},
  523. { WirePortDataType.SAMPLERCUBE, new Color(1f,0.5f,0f,1f)}
  524. };
  525. private static Dictionary<WirePortDataType, string> m_dataTypeToName = new Dictionary<WirePortDataType, string>()
  526. {
  527. { WirePortDataType.OBJECT, "Generic Object"},
  528. { WirePortDataType.FLOAT, "Float"},
  529. { WirePortDataType.FLOAT2, "Vector2"},
  530. { WirePortDataType.FLOAT3, "Vector3"},
  531. { WirePortDataType.FLOAT4, "Vector4"},
  532. { WirePortDataType.FLOAT3x3, "3x3 Matrix"},
  533. { WirePortDataType.FLOAT4x4, "4x4 Matrix"},
  534. { WirePortDataType.COLOR, "Color"},
  535. { WirePortDataType.INT, "Int"},
  536. { WirePortDataType.SAMPLER1D, "Sampler1D"},
  537. { WirePortDataType.SAMPLER2D, "Sampler2D"},
  538. { WirePortDataType.SAMPLER3D, "Sampler3D"},
  539. { WirePortDataType.SAMPLERCUBE, "SamplerCUBE"}
  540. };
  541. private static Dictionary<SurfaceInputs, string> m_inputTypeDeclaration = new Dictionary<SurfaceInputs, string>()
  542. {
  543. { SurfaceInputs.DEPTH, "{0} Depth : SV_Depth"},
  544. { SurfaceInputs.UV_COORDS, "{0}2 uv"},// texture uv must have uv or uv2 followed by the texture name
  545. { SurfaceInputs.UV2_COORDS, "{0}2 uv2"},
  546. { SurfaceInputs.VIEW_DIR, "{0}3 viewDir"},
  547. { SurfaceInputs.COLOR, Constants.ColorInput},
  548. { SurfaceInputs.SCREEN_POS, "{0}4 screenPos"},
  549. { SurfaceInputs.WORLD_POS, "{0}3 worldPos"},
  550. { SurfaceInputs.WORLD_REFL, "{0}3 worldRefl"},
  551. { SurfaceInputs.WORLD_NORMAL,"{0}3 worldNormal"},
  552. { SurfaceInputs.VFACE, Constants.VFaceInput},
  553. { SurfaceInputs.INTERNALDATA, Constants.InternalData}
  554. };
  555. private static Dictionary<SurfaceInputs, string> m_inputTypeName = new Dictionary<SurfaceInputs, string>()
  556. {
  557. { SurfaceInputs.DEPTH, "Depth"},
  558. { SurfaceInputs.UV_COORDS, "uv"},// texture uv must have uv or uv2 followed by the texture name
  559. { SurfaceInputs.UV2_COORDS, "uv2"},
  560. { SurfaceInputs.VIEW_DIR, "viewDir"},
  561. { SurfaceInputs.COLOR, Constants.ColorVariable},
  562. { SurfaceInputs.SCREEN_POS, "screenPos"},
  563. { SurfaceInputs.WORLD_POS, "worldPos"},
  564. { SurfaceInputs.WORLD_REFL, "worldRefl"},
  565. { SurfaceInputs.WORLD_NORMAL, "worldNormal"},
  566. { SurfaceInputs.VFACE, Constants.VFaceVariable},
  567. };
  568. private static Dictionary<PrecisionType, string> m_precisionTypeToCg = new Dictionary<PrecisionType, string>()
  569. {
  570. {PrecisionType.Float, "float"},
  571. {PrecisionType.Half, "half"},
  572. {PrecisionType.Fixed, "half"}
  573. };
  574. private static Dictionary<VariableQualifiers, string> m_qualifierToCg = new Dictionary<VariableQualifiers, string>()
  575. {
  576. { VariableQualifiers.In, string.Empty},
  577. {VariableQualifiers.Out, "out"},
  578. {VariableQualifiers.InOut, "inout"}
  579. };
  580. private static Dictionary<WirePortDataType, string> m_precisionWirePortToCgType = new Dictionary<WirePortDataType, string>()
  581. {
  582. {WirePortDataType.FLOAT, "{0}"},
  583. {WirePortDataType.FLOAT2, "{0}2"},
  584. {WirePortDataType.FLOAT3, "{0}3"},
  585. {WirePortDataType.FLOAT4, "{0}4"},
  586. {WirePortDataType.FLOAT3x3, "{0}3x3"},
  587. {WirePortDataType.FLOAT4x4, "{0}4x4"},
  588. {WirePortDataType.COLOR, "{0}4"},
  589. {WirePortDataType.INT, "int"},
  590. {WirePortDataType.SAMPLER1D, "sampler1D"},
  591. {WirePortDataType.SAMPLER2D, "sampler2D"},
  592. {WirePortDataType.SAMPLER3D, "sampler3D"},
  593. {WirePortDataType.SAMPLERCUBE, "samplerCUBE"}
  594. };
  595. private static Dictionary<WirePortDataType, string> m_wirePortToCgType = new Dictionary<WirePortDataType, string>()
  596. {
  597. { WirePortDataType.FLOAT, "float"},
  598. {WirePortDataType.FLOAT2, "float2"},
  599. {WirePortDataType.FLOAT3, "float3"},
  600. {WirePortDataType.FLOAT4, "float4"},
  601. {WirePortDataType.FLOAT3x3, "float3x3"},
  602. {WirePortDataType.FLOAT4x4, "float4x4"},
  603. {WirePortDataType.COLOR, "float4"},
  604. {WirePortDataType.INT, "int"},
  605. {WirePortDataType.SAMPLER1D, "sampler1D"},
  606. {WirePortDataType.SAMPLER2D, "sampler2D"},
  607. {WirePortDataType.SAMPLER3D, "sampler3D"},
  608. {WirePortDataType.SAMPLERCUBE, "samplerCUBE"},
  609. {WirePortDataType.UINT, "uint"}
  610. };
  611. private static Dictionary<KeyCode, string> m_keycodeToString = new Dictionary<KeyCode, string>()
  612. {
  613. {KeyCode.Alpha0,"0" },
  614. {KeyCode.Alpha1,"1" },
  615. {KeyCode.Alpha2,"2" },
  616. {KeyCode.Alpha3,"3" },
  617. {KeyCode.Alpha4,"4" },
  618. {KeyCode.Alpha5,"5" },
  619. {KeyCode.Alpha6,"6" },
  620. {KeyCode.Alpha7,"7" },
  621. {KeyCode.Alpha8,"8" },
  622. {KeyCode.Alpha9,"9" }
  623. };
  624. private static Dictionary<WireStatus, Color> m_wireStatusToColor = new Dictionary<WireStatus, Color>()
  625. {
  626. { WireStatus.Default,new Color(0.7f,0.7f,0.7f,1.0f) },
  627. {WireStatus.Highlighted,Color.yellow },
  628. {WireStatus.Selected,Color.white}
  629. };
  630. private static Dictionary<WirePortDataType, string> m_autoSwizzle = new Dictionary<WirePortDataType, string>()
  631. {
  632. {WirePortDataType.FLOAT, ".x"},
  633. {WirePortDataType.FLOAT2, ".xy"},
  634. {WirePortDataType.FLOAT3, ".xyz"},
  635. {WirePortDataType.FLOAT4, ".xyzw"}
  636. };
  637. private static Dictionary<string, bool> m_unityNativeShaderPaths = new Dictionary<string, bool>
  638. {
  639. { "Resources/unity_builtin_extra", true },
  640. { "Library/unity default resources", true }
  641. };
  642. private static Dictionary<WirePortDataType, int> m_portPriority = new Dictionary<WirePortDataType, int>()
  643. {
  644. { WirePortDataType.OBJECT, 0},
  645. {WirePortDataType.SAMPLER1D, 0},
  646. {WirePortDataType.SAMPLER2D, 0},
  647. {WirePortDataType.SAMPLER3D, 0},
  648. {WirePortDataType.SAMPLERCUBE, 0},
  649. {WirePortDataType.FLOAT3x3, 1},
  650. {WirePortDataType.FLOAT4x4, 2},
  651. {WirePortDataType.INT, 3},
  652. {WirePortDataType.FLOAT, 4},
  653. {WirePortDataType.FLOAT2, 5},
  654. {WirePortDataType.FLOAT3, 6},
  655. {WirePortDataType.FLOAT4, 7},
  656. {WirePortDataType.COLOR, 7}
  657. };
  658. private static readonly string IncorrectInputConnectionErrorMsg = "Input Port {0} from node {1} has type {2}\nwhich is incompatible with connection of type {3} from port {4} on node {5}";
  659. private static readonly string IncorrectOutputConnectionErrorMsg = "Output Port {0} from node {1} has type {2}\nwhich is incompatible with connection of type {3} from port {4} on node {5}";
  660. private static readonly string NoVertexModeNodeWarning = "{0} is unable to generate code in vertex function";
  661. private static float SwitchFixedHeight;
  662. private static float SwitchFontSize;
  663. private static RectOffset SwitchNodeBorder;
  664. private static RectOffset SwitchNodeMargin;
  665. private static RectOffset SwitchNodeOverflow;
  666. private static RectOffset SwitchNodePadding;
  667. public static void ForceExampleShaderCompilation()
  668. {
  669. CurrentWindow.ForceMaterialsToUpdate( ref m_exampleMaterialIDs );
  670. }
  671. public static void Destroy()
  672. {
  673. if( IOUtils.AllOpenedWindows != null && IOUtils.AllOpenedWindows.Count > 0 )
  674. {
  675. return;
  676. }
  677. else
  678. {
  679. IOUtils.AllOpenedWindows.Clear();
  680. }
  681. Initialized = false;
  682. PlusStyle = null;
  683. MinusStyle = null;
  684. m_textInfo = null;
  685. RangedFloatSliderStyle = null;
  686. RangedFloatSliderThumbStyle = null;
  687. PropertyPopUp = null;
  688. ObjectField = null;
  689. PreviewExpander = null;
  690. PreviewCollapser = null;
  691. MenuItemToggleStyle = null;
  692. MenuItemEnableStyle = null;
  693. MenuItemBackgroundStyle = null;
  694. MenuItemToolbarStyle = null;
  695. MenuItemInspectorDropdownStyle = null;
  696. ObjectFieldThumb = null;
  697. ObjectFieldThumbOverlay = null;
  698. InspectorPopdropdownStyle = null;
  699. InspectorPopdropdownFallback = null;
  700. TooltipBox = null;
  701. UnZoomedNodeTitleStyle = null;
  702. UnZoomedPropertyValuesTitleStyle = null;
  703. UnZoomedInputPortStyle = null;
  704. UnZoomedOutputPortPortStyle = null;
  705. ToolbarSearchTextfield = null;
  706. ToolbarSearchCancelButton = null;
  707. FloatIntPickerONOFF = null;
  708. Box = null;
  709. Button = null;
  710. TextArea = null;
  711. Label = null;
  712. Toggle = null;
  713. Textfield = null;
  714. CommentaryTitle = null;
  715. InputPortLabel = null;
  716. OutputPortLabel = null;
  717. IntShader = null;
  718. FloatShader = null;
  719. Vector2Shader = null;
  720. Vector3Shader = null;
  721. Vector4Shader = null;
  722. ColorShader = null;
  723. Texture2DShader = null;
  724. MaskingShader = null;
  725. BoldErrorStyle = null;
  726. BoldWarningStyle = null;
  727. BoldInfoStyle = null;
  728. Separator = null;
  729. GraphButtonIcon = null;
  730. GraphButton = null;
  731. GraphDropDown = null;
  732. MiniButtonTopLeft = null;
  733. MiniButtonTopMid = null;
  734. MiniButtonTopRight = null;
  735. NodeWindowOffSquare = null;
  736. NodeHeaderSquare = null;
  737. NodeWindowOnSquare = null;
  738. InternalDataOnPort = null;
  739. InternalDataBackground = null;
  740. MiniObjectFieldThumbOverlay = null;
  741. MiniSamplerButton = null;
  742. Resources.UnloadAsset( SmallErrorIcon );
  743. SmallErrorIcon = null;
  744. Resources.UnloadAsset( SmallWarningIcon );
  745. SmallWarningIcon = null;
  746. Resources.UnloadAsset( SmallInfoIcon );
  747. SmallInfoIcon = null;
  748. LockIconOpen = null;
  749. LockIconClosed = null;
  750. FloatIntIconON = null;
  751. FloatIntIconOFF = null;
  752. Resources.UnloadAsset( CheckmarkIcon );
  753. CheckmarkIcon = null;
  754. Resources.UnloadAsset( PopupIcon );
  755. PopupIcon = null;
  756. Resources.UnloadAsset( MasterNodeOnTexture );
  757. MasterNodeOnTexture = null;
  758. Resources.UnloadAsset( MasterNodeOffTexture );
  759. MasterNodeOffTexture = null;
  760. Resources.UnloadAsset( GPUInstancedOnTexture );
  761. GPUInstancedOnTexture = null;
  762. Resources.UnloadAsset( GPUInstancedOffTexture );
  763. GPUInstancedOffTexture = null;
  764. MainSkin = null;
  765. if( LinearMaterial != null )
  766. GameObject.DestroyImmediate( LinearMaterial );
  767. LinearMaterial = null;
  768. if( m_undoHelper == null )
  769. {
  770. m_undoHelper.Clear();
  771. m_undoHelper = null;
  772. }
  773. ASEMaterialInspector.Instance = null;
  774. }
  775. public static void ResetMainSkin()
  776. {
  777. if( (object)MainSkin != null )
  778. {
  779. CurrentHeaderHeight = HeaderMaxHeight;
  780. ScaledPortsDelta = PortsDelta;
  781. MainSkin.textField.fontSize = (int)( Constants.TextFieldFontSize );
  782. MainSkin.label.fontSize = (int)( Constants.DefaultFontSize );
  783. MainSkin.customStyles[ (int)CustomStyle.NodeTitle ].fontSize = (int)( Constants.DefaultTitleFontSize );
  784. InputPortLabel.fontSize = (int)( Constants.DefaultFontSize );
  785. OutputPortLabel.fontSize = (int)( Constants.DefaultFontSize );
  786. CommentaryTitle.fontSize = (int)( Constants.DefaultFontSize );
  787. }
  788. }
  789. public static void InitMainSkin()
  790. {
  791. MainSkin = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( IOUtils.MainSkinGUID ), typeof( GUISkin ) ) as GUISkin;
  792. Initialized = true;
  793. Texture2D portTex = GetCustomStyle( CustomStyle.PortEmptyIcon ).normal.background;
  794. PortsSize = new Vector2( portTex.width, portTex.height );
  795. PortsDelta = new Vector3( 0.5f * PortsSize.x, 0.5f * PortsSize.y );
  796. HeaderMaxHeight = MainSkin.customStyles[ (int)CustomStyle.NodeHeader ].normal.background.height;
  797. RectOffsetZero = new RectOffset( 0, 0, 0, 0 );
  798. RectOffsetOne = new RectOffset( 1, 1, 1, 1 );
  799. RectOffsetTwo = new RectOffset( 2, 2, 2, 2 );
  800. RectOffsetThree = new RectOffset( 3, 3, 3, 3 );
  801. RectOffsetFour = new RectOffset( 4, 4, 4, 4 );
  802. RectOffsetFive = new RectOffset( 5, 5, 5, 5 );
  803. RectOffsetSix = new RectOffset( 6, 6, 6, 6 );
  804. PropertyPopUp = GetCustomStyle( CustomStyle.NodePropertyPicker );
  805. ObjectField = new GUIStyle( (GUIStyle)"ObjectField" );
  806. PreviewExpander = GetCustomStyle( CustomStyle.NodePreviewExpander );
  807. PreviewCollapser = GetCustomStyle( CustomStyle.NodePreviewCollapser );
  808. WireNodeSelection = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "bfe0b03d5d60cea4f9d4b2d1d121e592" ), typeof( Texture2D ) ) as Texture2D;
  809. SliderButton = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "dd563e33152bb6443b099b4139ceecb9" ), typeof( Texture2D ) ) as Texture2D;
  810. SmallErrorIcon = EditorGUIUtility.Load( "icons/d_console.erroricon.sml.png" ) as Texture2D;
  811. SmallWarningIcon = EditorGUIUtility.Load( "icons/d_console.warnicon.sml.png" ) as Texture2D;
  812. SmallInfoIcon = EditorGUIUtility.Load( "icons/d_console.infoicon.sml.png" ) as Texture2D;
  813. LockIconOpen = new GUIContent( EditorGUIUtility.IconContent( "LockIcon-On" ) );
  814. LockIconOpen.tooltip = "Click to unlock and customize the variable name";
  815. LockIconClosed = new GUIContent( EditorGUIUtility.IconContent( "LockIcon" ) );
  816. LockIconClosed.tooltip = "Click to lock and auto-generate the variable name";
  817. if( UsingProSkin )
  818. {
  819. FloatIntIconON = new GUIContent( EditorGUIUtility.IconContent( "CircularToggle_ON" ) );
  820. FloatIntIconOFF = new GUIContent( EditorGUIUtility.IconContent( "CircularToggle_OFF" ) );
  821. }
  822. else
  823. {
  824. FloatIntIconON = new GUIContent( ( AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "ac0860a6a77e29d4091ba790a17daa0f" ), typeof( Texture2D ) ) as Texture2D ) );
  825. FloatIntIconOFF = new GUIContent( ( AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "1aaca50d084b0bb43854f075ce2f302b" ), typeof( Texture2D ) ) as Texture2D ) );
  826. }
  827. CommentaryTitle = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.CommentaryTitle ] );
  828. InputPortLabel = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.InputPortlabel ] );
  829. OutputPortLabel = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.OutputPortLabel ] );
  830. CheckmarkIcon = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "e9c4642eaa083a54ab91406d8449e6ac" ), typeof( Texture2D ) ) as Texture2D;
  831. PopupIcon = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "d2384a227b4ac4943b73c8151393e502" ), typeof( Texture2D ) ) as Texture2D;
  832. BoldErrorStyle = new GUIStyle( (GUIStyle)"BoldLabel" );
  833. BoldErrorStyle.normal.textColor = Color.red;
  834. BoldErrorStyle.alignment = TextAnchor.MiddleCenter;
  835. BoldWarningStyle = new GUIStyle( (GUIStyle)"BoldLabel" );
  836. BoldWarningStyle.normal.textColor = Color.yellow;
  837. BoldWarningStyle.alignment = TextAnchor.MiddleCenter;
  838. BoldInfoStyle = new GUIStyle( (GUIStyle)"BoldLabel" );
  839. BoldInfoStyle.normal.textColor = Color.white;
  840. BoldInfoStyle.alignment = TextAnchor.MiddleCenter;
  841. Separator = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.FlatBackground ] );
  842. MiniButtonTopLeft = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.MiniButtonTopLeft ] );
  843. MiniButtonTopMid = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.MiniButtonTopMid ] );
  844. MiniButtonTopRight = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.MiniButtonTopRight ] );
  845. InternalDataOnPort = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.NodeTitle ] );
  846. InternalDataOnPort.fontSize = 8;
  847. InternalDataOnPort.fontStyle = FontStyle.BoldAndItalic;
  848. InternalDataBackground = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.NodeWindowOffSquare ] );
  849. InternalDataBackground.normal.background = AssetDatabase.LoadAssetAtPath( AssetDatabase.GUIDToAssetPath( "330fd0c8f074a3c4f8042114a61a73d9" ), typeof( Texture2D ) ) as Texture2D;
  850. InternalDataBackground.overflow = RectOffsetOne;
  851. MiniObjectFieldThumbOverlay = new GUIStyle( (GUIStyle)"ObjectFieldThumbOverlay" );
  852. MiniSamplerButton = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.SamplerButton ] );
  853. m_textInfo = new System.Globalization.CultureInfo( "en-US", false ).TextInfo;
  854. RangedFloatSliderStyle = new GUIStyle( GUI.skin.horizontalSlider );
  855. RangedFloatSliderThumbStyle = new GUIStyle( GUI.skin.horizontalSliderThumb );
  856. RangedFloatSliderThumbStyle.normal.background = SliderButton;
  857. RangedFloatSliderThumbStyle.active.background = null;
  858. RangedFloatSliderThumbStyle.hover.background = null;
  859. RangedFloatSliderThumbStyle.focused.background = null;
  860. SwitchNodePopUp = new GUIStyle( (GUIStyle)"Popup" );
  861. // RectOffset cannot be initiliazed on constructor
  862. SwitchNodeBorder = new RectOffset( 4, 15, 3, 3 );
  863. SwitchNodeMargin = new RectOffset( 4, 4, 3, 3 );
  864. SwitchNodeOverflow = new RectOffset( 0, 0, -1, 2 );
  865. SwitchNodePadding = new RectOffset( 6, 14, 2, 3 );
  866. SwitchFixedHeight = 18;
  867. SwitchFontSize = 10;
  868. GraphButtonIcon = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.GraphButtonIcon ] );
  869. GraphButton = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.GraphButton ] );
  870. GraphDropDown = new GUIStyle( MainSkin.customStyles[ (int)CustomStyle.GraphButton ] );
  871. GraphDropDown.padding.right = 20;
  872. Box = new GUIStyle( GUI.skin.box );
  873. Button = new GUIStyle( GUI.skin.button );
  874. TextArea = new GUIStyle( GUI.skin.textArea );
  875. Label = new GUIStyle( GUI.skin.label );
  876. Toggle = new GUIStyle( GUI.skin.toggle );
  877. Textfield = new GUIStyle( GUI.skin.textField );
  878. //ShaderIcon = EditorGUIUtility.IconContent( "Shader Icon" ).image;
  879. //MaterialIcon = EditorGUIUtility.IconContent( "Material Icon" ).image;
  880. NodeWindowOffSquare = GetCustomStyle( CustomStyle.NodeWindowOffSquare );
  881. NodeHeaderSquare = GetCustomStyle( CustomStyle.NodeHeaderSquare );
  882. NodeWindowOnSquare = GetCustomStyle( CustomStyle.NodeWindowOnSquare );
  883. UnZoomedNodeTitleStyle = new GUIStyle( GetCustomStyle( CustomStyle.NodeTitle ) );
  884. UnZoomedNodeTitleStyle.fontSize = 13;
  885. UnZoomedPropertyValuesTitleStyle = new GUIStyle( GetCustomStyle( CustomStyle.PropertyValuesTitle ) );
  886. UnZoomedPropertyValuesTitleStyle.fontSize = 11;
  887. UnZoomedInputPortStyle = new GUIStyle( InputPortLabel );
  888. UnZoomedInputPortStyle.fontSize = (int)Constants.DefaultFontSize;
  889. UnZoomedOutputPortPortStyle = new GUIStyle( OutputPortLabel );
  890. UnZoomedOutputPortPortStyle.fontSize = (int)Constants.DefaultFontSize;
  891. ObjectFieldThumb = new GUIStyle( (GUIStyle)"ObjectFieldThumb" );
  892. ObjectFieldThumbOverlay = new GUIStyle( (GUIStyle)"ObjectFieldThumbOverlay" );
  893. FloatIntPickerONOFF = new GUIStyle( "metimelabel" );
  894. FloatIntPickerONOFF.padding.left = -2;
  895. FloatIntPickerONOFF.margin = new RectOffset(0,2,2,2);
  896. TooltipBox = new GUIStyle( (GUIStyle)"Tooltip" );
  897. TooltipBox.richText = true;
  898. MasterNodeOnTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IOUtils.MasterNodeOnTextureGUID ) );
  899. MasterNodeOffTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IOUtils.MasterNodeOnTextureGUID ) );
  900. GPUInstancedOnTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IOUtils.GPUInstancedOnTextureGUID ) );
  901. GPUInstancedOffTexture = AssetDatabase.LoadAssetAtPath<Texture2D>( AssetDatabase.GUIDToAssetPath( IOUtils.GPUInstancedOffTextureGUID ) );
  902. CheckNullMaterials();
  903. UsingProSkin = EditorGUIUtility.isProSkin;
  904. FetchMenuItemStyles();
  905. }
  906. public static bool IsLoading
  907. {
  908. get { return CurrentWindow.OutsideGraph.IsLoading; }
  909. }
  910. public static void CheckNullMaterials()
  911. {
  912. if( LinearMaterial == null )
  913. {
  914. Shader linearShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "e90ef6ea05743b84baf9549874c52e47" ) ); //linear previews
  915. LinearMaterial = new Material( linearShader );
  916. }
  917. if( IntShader == null )
  918. IntShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "0f64d695b6ffacc469f2dd31432a232a" ) ); //int
  919. if( FloatShader == null )
  920. FloatShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "d9ca47581ac157145bff6f72ac5dd73e" ) ); //ranged float
  921. if( Vector2Shader == null )
  922. Vector2Shader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "88b4191eb06084d4da85d1dd2f984085" ) ); //vector2
  923. if( Vector3Shader == null )
  924. Vector3Shader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "8a44d38f06246bf48944b3f314bc7920" ) ); //vector3
  925. if( Vector4Shader == null )
  926. Vector4Shader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "aac241d0e47a5a84fbd2edcd640788dc" ) ); //vector4
  927. if( ColorShader == null )
  928. ColorShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "6cf365ccc7ae776488ae8960d6d134c3" ) ); //color node
  929. if( MaskingShader == null )
  930. MaskingShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "9c34f18ebe2be3e48b201b748c73dec0" ) ); //masking shader
  931. if( Texture2DShader == null )
  932. Texture2DShader = AssetDatabase.LoadAssetAtPath<Shader>( AssetDatabase.GUIDToAssetPath( "13bd295c44d04e1419f20f792d331e33" ) ); //texture2d shader
  933. }
  934. private static void FetchMenuItemStyles()
  935. {
  936. ObjectFieldThumb = new GUIStyle( (GUIStyle)"ObjectFieldThumb" );
  937. ObjectFieldThumbOverlay = new GUIStyle( (GUIStyle)"ObjectFieldThumbOverlay" );
  938. MenuItemToggleStyle = new GUIStyle( (GUIStyle)"foldout" );
  939. MenuItemEnableStyle = UsingProSkin ? new GUIStyle( (GUIStyle)"OL ToggleWhite" ) : new GUIStyle( (GUIStyle)"OL Toggle" );
  940. MenuItemBackgroundStyle = new GUIStyle( (GUIStyle)"TE NodeBackground" );
  941. MenuItemToolbarStyle = new GUIStyle( (GUIStyle)"toolbarbutton" ) { fixedHeight = 20 };
  942. MenuItemInspectorDropdownStyle = new GUIStyle( (GUIStyle)"toolbardropdown" ) { fixedHeight = 20 };
  943. MenuItemInspectorDropdownStyle.margin.bottom = 2;
  944. InspectorPopdropdownStyle = new GUIStyle( GUI.skin.GetStyle( "PopupCurveDropdown" ) );
  945. InspectorPopdropdownStyle.alignment = TextAnchor.MiddleRight;
  946. InspectorPopdropdownStyle.border.bottom = 16;
  947. InspectorPopdropdownFallback = new GUIStyle( InspectorPopdropdownStyle );
  948. InspectorPopdropdownFallback.overflow = new RectOffset( 0, -5, 0, 0 );
  949. PlusStyle = ( EditorGUIUtility.isProSkin ) ? new GUIStyle( GetCustomStyle( CustomStyle.CustomExpressionAddItem ) ) : new GUIStyle( (GUIStyle)"OL Plus" );
  950. PlusStyle.imagePosition = ImagePosition.ImageOnly;
  951. PlusStyle.overflow = new RectOffset( -2, 0, -4, 0 );
  952. MinusStyle = ( EditorGUIUtility.isProSkin ) ? new GUIStyle( GetCustomStyle( CustomStyle.CustomExpressionRemoveItem ) ) : new GUIStyle( (GUIStyle)"OL Minus" );
  953. MinusStyle.contentOffset = Vector2.zero;
  954. MinusStyle.imagePosition = ImagePosition.ImageOnly;
  955. MinusStyle.overflow = new RectOffset( -2, 0, -4, 0 );
  956. ToolbarSearchTextfield = new GUIStyle( (GUIStyle)"ToolbarSeachTextField" );
  957. ToolbarSearchCancelButton = new GUIStyle( (GUIStyle)"ToolbarSeachCancelButton" );
  958. }
  959. public static void UpdateMainSkin( DrawInfo drawInfo )
  960. {
  961. CurrentHeaderHeight = HeaderMaxHeight * drawInfo.InvertedZoom;
  962. ScaledPortsDelta = drawInfo.InvertedZoom * PortsDelta;
  963. MainSkin.textField.fontSize = (int)( Constants.TextFieldFontSize * drawInfo.InvertedZoom );
  964. MainSkin.label.fontSize = (int)( Constants.DefaultFontSize * drawInfo.InvertedZoom );
  965. MainSkin.customStyles[ (int)CustomStyle.NodeTitle ].fontSize = (int)( Constants.DefaultTitleFontSize * drawInfo.InvertedZoom );
  966. MainSkin.customStyles[ (int)CustomStyle.PropertyValuesTitle ].fontSize = (int)( Constants.PropertiesTitleFontSize * drawInfo.InvertedZoom );
  967. InputPortLabel.fontSize = (int)( Constants.DefaultFontSize * drawInfo.InvertedZoom );
  968. OutputPortLabel.fontSize = (int)( Constants.DefaultFontSize * drawInfo.InvertedZoom );
  969. CommentaryTitle.fontSize = (int)( Constants.DefaultFontSize * drawInfo.InvertedZoom );
  970. RangedFloatSliderStyle.fixedHeight = 18 * drawInfo.InvertedZoom;
  971. RangedFloatSliderThumbStyle.fixedHeight = 12 * drawInfo.InvertedZoom;
  972. RangedFloatSliderThumbStyle.fixedWidth = 10 * drawInfo.InvertedZoom;
  973. RangedFloatSliderThumbStyle.overflow.left = (int)( 1 * drawInfo.InvertedZoom );
  974. RangedFloatSliderThumbStyle.overflow.right = (int)( 1 * drawInfo.InvertedZoom );
  975. RangedFloatSliderThumbStyle.overflow.top = (int)( -4 * drawInfo.InvertedZoom );
  976. RangedFloatSliderThumbStyle.overflow.bottom = (int)( 4 * drawInfo.InvertedZoom );
  977. SwitchNodePopUp.fixedHeight = SwitchFixedHeight * drawInfo.InvertedZoom;
  978. SwitchNodePopUp.border.left = (int)( SwitchNodeBorder.left * drawInfo.InvertedZoom );
  979. SwitchNodePopUp.border.right = (int)( SwitchNodeBorder.right * drawInfo.InvertedZoom );
  980. SwitchNodePopUp.border.top = (int)( SwitchNodeBorder.top * drawInfo.InvertedZoom );
  981. SwitchNodePopUp.border.bottom = (int)( SwitchNodeBorder.bottom * drawInfo.InvertedZoom );
  982. SwitchNodePopUp.margin.left = (int)( SwitchNodeMargin.left * drawInfo.InvertedZoom );
  983. SwitchNodePopUp.margin.right = (int)( SwitchNodeMargin.right * drawInfo.InvertedZoom );
  984. SwitchNodePopUp.margin.top = (int)( SwitchNodeMargin.top * drawInfo.InvertedZoom );
  985. SwitchNodePopUp.margin.bottom = (int)( SwitchNodeMargin.bottom * drawInfo.InvertedZoom );
  986. SwitchNodePopUp.overflow.left = (int)( SwitchNodeOverflow.left * drawInfo.InvertedZoom );
  987. SwitchNodePopUp.overflow.right = (int)( SwitchNodeOverflow.right * drawInfo.InvertedZoom );
  988. SwitchNodePopUp.overflow.top = (int)( SwitchNodeOverflow.top * drawInfo.InvertedZoom );
  989. SwitchNodePopUp.overflow.bottom = (int)( SwitchNodeOverflow.bottom * drawInfo.InvertedZoom );
  990. SwitchNodePopUp.padding.left = (int)( SwitchNodePadding.left * drawInfo.InvertedZoom );
  991. SwitchNodePopUp.padding.right = (int)( SwitchNodePadding.right * drawInfo.InvertedZoom );
  992. SwitchNodePopUp.padding.top = (int)( SwitchNodePadding.top * drawInfo.InvertedZoom );
  993. SwitchNodePopUp.padding.bottom = (int)( SwitchNodePadding.bottom * drawInfo.InvertedZoom );
  994. SwitchNodePopUp.fontSize = (int)( SwitchFontSize * drawInfo.InvertedZoom );
  995. BoldErrorStyle.fontSize = (int)( 12 * drawInfo.InvertedZoom );
  996. BoldWarningStyle.fontSize = (int)( 12 * drawInfo.InvertedZoom );
  997. BoldInfoStyle.fontSize = (int)( 12 * drawInfo.InvertedZoom );
  998. PropertyPopUp.fixedHeight = Constants.PropertyPickerHeight * drawInfo.InvertedZoom;
  999. PropertyPopUp.fixedWidth = Constants.PropertyPickerWidth * drawInfo.InvertedZoom;
  1000. if( UsingProSkin != EditorGUIUtility.isProSkin )
  1001. {
  1002. UsingProSkin = EditorGUIUtility.isProSkin;
  1003. FetchMenuItemStyles();
  1004. }
  1005. GraphDropDown.padding.left = (int)( 2 * drawInfo.InvertedZoom + 2 );
  1006. GraphDropDown.padding.right = (int)( 20 * drawInfo.InvertedZoom );
  1007. GraphDropDown.fontSize = (int)( 10 * drawInfo.InvertedZoom );
  1008. PreviewExpander.fixedHeight = Constants.PreviewExpanderHeight * drawInfo.InvertedZoom;
  1009. PreviewExpander.fixedWidth = Constants.PreviewExpanderWidth * drawInfo.InvertedZoom;
  1010. PreviewCollapser.fixedHeight = Constants.PreviewExpanderHeight * drawInfo.InvertedZoom;
  1011. PreviewCollapser.fixedWidth = Constants.PreviewExpanderWidth * drawInfo.InvertedZoom;
  1012. MainSkin.customStyles[ (int)CustomStyle.SamplerButton ].fontSize = (int)( 9 * drawInfo.InvertedZoom );
  1013. ObjectFieldThumbOverlay.fontSize = (int)( 9 * drawInfo.InvertedZoom );
  1014. MiniButtonTopLeft.fontSize = (int)( 9 * drawInfo.InvertedZoom );
  1015. MiniButtonTopMid.fontSize = (int)( 9 * drawInfo.InvertedZoom );
  1016. MiniButtonTopRight.fontSize = (int)( 9 * drawInfo.InvertedZoom );
  1017. MiniObjectFieldThumbOverlay.fontSize = (int)( 7 * drawInfo.InvertedZoom );
  1018. MiniSamplerButton.fontSize = (int)( 8 * drawInfo.InvertedZoom );
  1019. InternalDataOnPort.fontSize = (int)( 8 * drawInfo.InvertedZoom );
  1020. CheckNullMaterials();
  1021. }
  1022. public static void CacheLabelVars()
  1023. {
  1024. m_alignment = GUI.skin.label.alignment;
  1025. m_clipping = GUI.skin.label.clipping;
  1026. m_wordWrap = GUI.skin.label.wordWrap;
  1027. m_fontSize = GUI.skin.label.fontSize;
  1028. m_fontStyle = GUI.skin.label.fontStyle;
  1029. m_fontColor = GUI.skin.label.normal.textColor;
  1030. }
  1031. public static void RestoreLabelVars()
  1032. {
  1033. GUI.skin.label.alignment = m_alignment;
  1034. GUI.skin.label.clipping = m_clipping;
  1035. GUI.skin.label.wordWrap = m_wordWrap;
  1036. GUI.skin.label.fontSize = m_fontSize;
  1037. GUI.skin.label.fontStyle = m_fontStyle;
  1038. GUI.skin.label.normal.textColor = m_fontColor;
  1039. }
  1040. public static string GetTooltipForToolButton( ToolButtonType toolButtonType, int state ) { return m_toolButtonTooltips[ toolButtonType ][ state ]; }
  1041. public static string KeyCodeToString( KeyCode keyCode )
  1042. {
  1043. if( m_keycodeToString.ContainsKey( keyCode ) )
  1044. return m_keycodeToString[ keyCode ];
  1045. return keyCode.ToString();
  1046. }
  1047. public static string TextureTypeToCgType( TextureType type ) { return m_textureTypeToCgType[ type ]; }
  1048. public static string QualifierToCg( VariableQualifiers qualifier )
  1049. {
  1050. return m_qualifierToCg[ qualifier ];
  1051. }
  1052. public static string WirePortToCgType( WirePortDataType type )
  1053. {
  1054. if( type == WirePortDataType.OBJECT )
  1055. return string.Empty;
  1056. return m_wirePortToCgType[ type ];
  1057. }
  1058. public static string FinalPrecisionWirePortToCgType( PrecisionType precisionType, WirePortDataType type )
  1059. {
  1060. PrecisionType finalPrecision = GetFinalPrecision( precisionType );
  1061. if( type == WirePortDataType.OBJECT )
  1062. return string.Empty;
  1063. if( type == WirePortDataType.INT )
  1064. return m_wirePortToCgType[ type ];
  1065. if( type == WirePortDataType.UINT )
  1066. return m_wirePortToCgType[ type ];
  1067. return string.Format( m_precisionWirePortToCgType[ type ], m_precisionTypeToCg[ finalPrecision ] );
  1068. }
  1069. public static string PrecisionWirePortToCgType( PrecisionType precisionType, WirePortDataType type )
  1070. {
  1071. if( type == WirePortDataType.OBJECT )
  1072. return string.Empty;
  1073. if( type == WirePortDataType.INT )
  1074. return m_wirePortToCgType[ type ];
  1075. if( type == WirePortDataType.UINT )
  1076. return m_wirePortToCgType[ type ];
  1077. return string.Format( m_precisionWirePortToCgType[ type ], m_precisionTypeToCg[ precisionType ] );
  1078. }
  1079. public static string GetAutoSwizzle( WirePortDataType type )
  1080. {
  1081. return m_autoSwizzle[ type ];
  1082. }
  1083. public static Color GetColorForDataType( WirePortDataType dataType, bool monochromeMode = true, bool isInput = true )
  1084. {
  1085. if( monochromeMode )
  1086. {
  1087. return isInput ? m_dataTypeToColorMonoMode[ 0 ] : m_dataTypeToColorMonoMode[ 1 ];
  1088. }
  1089. else
  1090. {
  1091. if ( m_dataTypeToColor.ContainsKey( dataType ) )
  1092. return m_dataTypeToColor[ dataType ];
  1093. }
  1094. return m_dataTypeToColor[ WirePortDataType.OBJECT ];
  1095. }
  1096. public static bool IsValidType( WirePortDataType type )
  1097. {
  1098. switch ( type )
  1099. {
  1100. case WirePortDataType.OBJECT:
  1101. case WirePortDataType.FLOAT:
  1102. case WirePortDataType.FLOAT2:
  1103. case WirePortDataType.FLOAT3:
  1104. case WirePortDataType.FLOAT4:
  1105. case WirePortDataType.FLOAT3x3:
  1106. case WirePortDataType.FLOAT4x4:
  1107. case WirePortDataType.COLOR:
  1108. case WirePortDataType.INT:
  1109. case WirePortDataType.SAMPLER1D:
  1110. case WirePortDataType.SAMPLER2D:
  1111. case WirePortDataType.SAMPLER3D:
  1112. case WirePortDataType.SAMPLERCUBE:
  1113. return true;
  1114. }
  1115. return false;
  1116. }
  1117. public static string GetNameForDataType( WirePortDataType dataType ) { return m_dataTypeToName[ dataType ]; }
  1118. public static string GetInputDeclarationFromType( PrecisionType precision, SurfaceInputs inputType )
  1119. {
  1120. string precisionStr = m_precisionTypeToCg[ precision ];
  1121. return string.Format( m_inputTypeDeclaration[ inputType ], precisionStr );
  1122. }
  1123. public static string GetInputValueFromType( SurfaceInputs inputType ) { return m_inputTypeName[ inputType ]; }
  1124. private static string CreateLocalValueName( PrecisionType precision, WirePortDataType dataType, string localOutputValue, string value ) { return string.Format( Constants.LocalValueDecWithoutIdent, PrecisionWirePortToCgType( precision, dataType ), localOutputValue, value ); }
  1125. public static string CastPortType( ref MasterNodeDataCollector dataCollector, PrecisionType nodePrecision, NodeCastInfo castInfo, object value, WirePortDataType oldType, WirePortDataType newType, string parameterName = null )
  1126. {
  1127. if( oldType == newType || newType == WirePortDataType.OBJECT )
  1128. {
  1129. return ( parameterName != null ) ? parameterName : value.ToString();
  1130. }
  1131. PrecisionType currentPrecision = GetFinalPrecision( nodePrecision );
  1132. string precisionStr = m_precisionTypeToCg[ currentPrecision ];
  1133. string newTypeStr = m_wirePortToCgType[ newType ];
  1134. newTypeStr = m_textInfo.ToTitleCase( newTypeStr );
  1135. int castId = ( dataCollector.PortCategory == MasterNodePortCategory.Vertex || dataCollector.PortCategory == MasterNodePortCategory.Tessellation ) ? dataCollector.AvailableVertexTempId : dataCollector.AvailableFragTempId;
  1136. string localVarName = "temp_cast_" + castId;//m_wirePortToCgType[ oldType ] + "To" + newTypeStr + "_" + castInfo.ToString();
  1137. string result = string.Empty;
  1138. bool useRealValue = ( parameterName == null );
  1139. switch( oldType )
  1140. {
  1141. case WirePortDataType.FLOAT:
  1142. {
  1143. switch( newType )
  1144. {
  1145. case WirePortDataType.OBJECT: result = useRealValue ? value.ToString() : parameterName; break;
  1146. case WirePortDataType.FLOAT2:
  1147. {
  1148. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, string.Format( Constants.CastHelper, ( ( useRealValue ) ? value.ToString() : parameterName ), "xx" ) );
  1149. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1150. result = localVarName;
  1151. }
  1152. break;
  1153. case WirePortDataType.FLOAT3:
  1154. {
  1155. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, string.Format( Constants.CastHelper, ( ( useRealValue ) ? value.ToString() : parameterName ), "xxx" ) );
  1156. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1157. result = localVarName;
  1158. }
  1159. break;
  1160. case WirePortDataType.COLOR:
  1161. {
  1162. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, string.Format( Constants.CastHelper, ( ( useRealValue ) ? value.ToString() : parameterName ), "xxxx" ) );
  1163. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1164. result = localVarName;
  1165. }
  1166. break;
  1167. case WirePortDataType.FLOAT4:
  1168. {
  1169. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, string.Format( Constants.CastHelper, ( ( useRealValue ) ? value.ToString() : parameterName ), "xxxx" ) );
  1170. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1171. result = localVarName;
  1172. }
  1173. break;
  1174. case WirePortDataType.FLOAT3x3:
  1175. {
  1176. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, ( ( useRealValue ) ? value.ToString() : parameterName ) );
  1177. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1178. result = localVarName;
  1179. }
  1180. break;
  1181. case WirePortDataType.FLOAT4x4:
  1182. {
  1183. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, ( ( useRealValue ) ? value.ToString() : parameterName ) );
  1184. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1185. result = localVarName;
  1186. }
  1187. break;
  1188. case WirePortDataType.INT:
  1189. {
  1190. result = ( useRealValue ) ? ( (int)value ).ToString() : "(int)" + parameterName;
  1191. }
  1192. break;
  1193. }
  1194. }
  1195. break;
  1196. case WirePortDataType.FLOAT2:
  1197. {
  1198. Vector2 vecVal = useRealValue ? (Vector2)value : Vector2.zero;
  1199. switch( newType )
  1200. {
  1201. case WirePortDataType.OBJECT: result = useRealValue ? precisionStr + "2( " + vecVal.x + " , " + vecVal.y + " )" : parameterName; break;
  1202. case WirePortDataType.FLOAT:
  1203. {
  1204. result = ( useRealValue ) ? vecVal.x.ToString() : parameterName + ".x";
  1205. }
  1206. break;
  1207. case WirePortDataType.FLOAT3:
  1208. {
  1209. result = ( useRealValue ) ? precisionStr + "3( " + vecVal.x + " , " + vecVal.y + " , " + " 0.0 )" : precisionStr + "3( " + parameterName + " , 0.0 )";
  1210. }
  1211. break;
  1212. case WirePortDataType.COLOR:
  1213. case WirePortDataType.FLOAT4:
  1214. {
  1215. result = ( useRealValue ) ? precisionStr + "4( " + vecVal.x + " , " + vecVal.y + " , " + " 0.0 , 0.0 )" : precisionStr + "4( " + parameterName + ", 0.0 , 0.0 )";
  1216. }
  1217. break;
  1218. }
  1219. }
  1220. break;
  1221. case WirePortDataType.FLOAT3:
  1222. {
  1223. Vector3 vecVal = useRealValue ? (Vector3)value : Vector3.zero;
  1224. switch( newType )
  1225. {
  1226. case WirePortDataType.OBJECT: result = useRealValue ? precisionStr + "3( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " )" : parameterName; break;
  1227. case WirePortDataType.FLOAT:
  1228. {
  1229. result = ( useRealValue ) ? vecVal.x.ToString() : parameterName + ".x";
  1230. }
  1231. break;
  1232. case WirePortDataType.FLOAT2:
  1233. {
  1234. result = ( useRealValue ) ? precisionStr + "2( " + vecVal.x + " , " + vecVal.y + " )" : parameterName + ".xy";
  1235. }
  1236. break;
  1237. case WirePortDataType.COLOR:
  1238. case WirePortDataType.FLOAT4:
  1239. {
  1240. result = ( useRealValue ) ? precisionStr + "4( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " , 0.0 )" : precisionStr + "4( " + parameterName + " , 0.0 )";
  1241. }
  1242. break;
  1243. //case WirePortDataType.FLOAT3x3:
  1244. //{
  1245. // if ( useRealValue )
  1246. // {
  1247. // result = precisionStr + "3x3( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " , " +
  1248. // vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " , " +
  1249. // vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " )";
  1250. // }
  1251. // else
  1252. // {
  1253. // string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, parameterName );
  1254. // CurrentDataCollector.AddToLocalVariables( portCategory, -1, localVal );
  1255. // result = precisionStr + "3x3( " + localVarName + ".x , " + localVarName + ".y , " + localVarName + ".x , " +
  1256. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".y , " +
  1257. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z )";
  1258. // }
  1259. //}
  1260. //break;
  1261. //case WirePortDataType.FLOAT4x4:
  1262. //{
  1263. // if ( useRealValue )
  1264. // {
  1265. // result = precisionStr + "4x4( " + vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , 0 , " +
  1266. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , 0 , " +
  1267. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , 0 , " +
  1268. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , 0 )";
  1269. // }
  1270. // else
  1271. // {
  1272. // string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, parameterName );
  1273. // CurrentDataCollector.AddToLocalVariables( portCategory, -1, localVal );
  1274. // result = precisionStr + "4x4( " + localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , 0 , " +
  1275. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , 0 , " +
  1276. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , 0 , " +
  1277. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , 0 )";
  1278. // }
  1279. //}
  1280. //break;
  1281. }
  1282. }
  1283. break;
  1284. case WirePortDataType.FLOAT4:
  1285. {
  1286. Vector4 vecVal = useRealValue ? (Vector4)value : Vector4.zero;
  1287. switch( newType )
  1288. {
  1289. case WirePortDataType.OBJECT: result = useRealValue ? precisionStr + "4( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " , " + vecVal.w + " )" : parameterName; break;
  1290. case WirePortDataType.FLOAT:
  1291. {
  1292. result = ( useRealValue ) ? vecVal.x.ToString() : parameterName + ".x";
  1293. }
  1294. break;
  1295. case WirePortDataType.FLOAT2:
  1296. {
  1297. result = ( useRealValue ) ? precisionStr + "2( " + vecVal.x + " , " + vecVal.y + " )" : parameterName + ".xy";
  1298. }
  1299. break;
  1300. case WirePortDataType.FLOAT3:
  1301. {
  1302. result = ( useRealValue ) ? precisionStr + "3( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " )" : parameterName + ".xyz";
  1303. }
  1304. break;
  1305. //case WirePortDataType.FLOAT4x4:
  1306. //{
  1307. // if ( useRealValue )
  1308. // {
  1309. // result = precisionStr + "4x4( " + vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , " + vecVal + ".w , " +
  1310. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , " + vecVal + ".w , " +
  1311. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , " + vecVal + ".w , " +
  1312. // vecVal + ".x , " + vecVal + ".y , " + vecVal + ".z , " + vecVal + ".w )";
  1313. // }
  1314. // else
  1315. // {
  1316. // string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, parameterName );
  1317. // CurrentDataCollector.AddToLocalVariables( portCategory, -1, localVal );
  1318. // result = precisionStr + "4x4( " + localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1319. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1320. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1321. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w )";
  1322. // }
  1323. //}
  1324. //break;
  1325. case WirePortDataType.COLOR:
  1326. {
  1327. result = useRealValue ? precisionStr + "4( " + vecVal.x + " , " + vecVal.y + " , " + vecVal.z + " , " + vecVal.w + " )" : parameterName;
  1328. }
  1329. break;
  1330. }
  1331. }
  1332. break;
  1333. case WirePortDataType.FLOAT3x3:
  1334. {
  1335. //Matrix4x4 matrixVal = useRealValue ? ( Matrix4x4 ) value : Matrix4x4.identity;
  1336. //switch ( newType )
  1337. //{
  1338. // case WirePortDataType.OBJECT:
  1339. // case WirePortDataType.FLOAT4x4:
  1340. // {
  1341. // result = ( useRealValue ) ? precisionStr + "4x4(" + matrixVal.m00 + " , " + matrixVal.m01 + " , " + matrixVal.m02 + " , " + matrixVal.m03 + " , " +
  1342. // matrixVal.m10 + " , " + matrixVal.m11 + " , " + matrixVal.m12 + " , " + matrixVal.m10 + " , " +
  1343. // matrixVal.m20 + " , " + matrixVal.m21 + " , " + matrixVal.m22 + " , " + matrixVal.m20 + " , " +
  1344. // matrixVal.m30 + " , " + matrixVal.m31 + " , " + matrixVal.m32 + " , " + matrixVal.m30 + " )" : precisionStr + "4x4(" + parameterName + ")";
  1345. // }
  1346. // break;
  1347. //}
  1348. }
  1349. break;
  1350. case WirePortDataType.FLOAT4x4:
  1351. {
  1352. Matrix4x4 matrixVal = useRealValue ? (Matrix4x4)value : Matrix4x4.identity;
  1353. switch( newType )
  1354. {
  1355. case WirePortDataType.OBJECT:
  1356. {
  1357. result = ( useRealValue ) ? precisionStr + "4x4(" + matrixVal.m00 + " , " + matrixVal.m01 + " , " + matrixVal.m02 + " , " + matrixVal.m03 + " , " +
  1358. matrixVal.m10 + " , " + matrixVal.m11 + " , " + matrixVal.m12 + " , " + matrixVal.m10 + " , " +
  1359. matrixVal.m20 + " , " + matrixVal.m21 + " , " + matrixVal.m22 + " , " + matrixVal.m20 + " , " +
  1360. matrixVal.m30 + " , " + matrixVal.m31 + " , " + matrixVal.m32 + " , " + matrixVal.m30 + " )" : parameterName;
  1361. }
  1362. break;
  1363. }
  1364. }
  1365. break;
  1366. case WirePortDataType.COLOR:
  1367. {
  1368. Color colorValue = ( useRealValue ) ? (Color)value : Color.black;
  1369. switch( newType )
  1370. {
  1371. case WirePortDataType.OBJECT: result = useRealValue ? precisionStr + "4( " + colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " )" : parameterName; break;
  1372. case WirePortDataType.FLOAT:
  1373. {
  1374. result = ( useRealValue ) ? colorValue.r.ToString() : parameterName + ".r";
  1375. }
  1376. break;
  1377. case WirePortDataType.FLOAT2:
  1378. {
  1379. result = ( useRealValue ) ? precisionStr + "2( " + colorValue.r + " , " + colorValue.g + " )" : parameterName + ".rg";
  1380. }
  1381. break;
  1382. case WirePortDataType.FLOAT3:
  1383. {
  1384. result = ( useRealValue ) ? precisionStr + "3( " + colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " )" : parameterName + ".rgb";
  1385. }
  1386. break;
  1387. case WirePortDataType.FLOAT4:
  1388. {
  1389. result = useRealValue ? precisionStr + "4( " + colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " )" : parameterName;
  1390. }
  1391. break;
  1392. //case WirePortDataType.FLOAT4x4:
  1393. //{
  1394. // if ( useRealValue )
  1395. // {
  1396. // result = precisionStr + "4x4( " + colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " , " +
  1397. // colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " , " +
  1398. // colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " , " +
  1399. // colorValue.r + " , " + colorValue.g + " , " + colorValue.b + " , " + colorValue.a + " )";
  1400. // }
  1401. // else
  1402. // {
  1403. // string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, parameterName );
  1404. // CurrentDataCollector.AddToLocalVariables( portCategory, -1, localVal );
  1405. // result = precisionStr + "4x4( " + localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1406. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1407. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w , " +
  1408. // localVarName + ".x , " + localVarName + ".y , " + localVarName + ".z , " + localVarName + ".w )";
  1409. // }
  1410. //}
  1411. //break;
  1412. }
  1413. }
  1414. break;
  1415. case WirePortDataType.INT:
  1416. {
  1417. switch( newType )
  1418. {
  1419. case WirePortDataType.OBJECT: result = useRealValue ? value.ToString() : parameterName; break;
  1420. case WirePortDataType.FLOAT2:
  1421. case WirePortDataType.FLOAT3:
  1422. case WirePortDataType.COLOR:
  1423. case WirePortDataType.FLOAT4:
  1424. {
  1425. string localVal = CreateLocalValueName( currentPrecision, newType, localVarName, ( ( useRealValue ) ? value.ToString() : parameterName ) );
  1426. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1427. result = localVarName;
  1428. }
  1429. break;
  1430. case WirePortDataType.FLOAT3x3:
  1431. {
  1432. string localVal = CreateLocalValueName( currentPrecision, oldType, localVarName, ( ( useRealValue ) ? value.ToString() : parameterName ) );
  1433. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1434. result = localVarName;
  1435. }
  1436. break;
  1437. case WirePortDataType.FLOAT4x4:
  1438. {
  1439. string localVal = CreateLocalValueName( currentPrecision, oldType, localVarName, ( ( useRealValue ) ? value.ToString() : parameterName ) );
  1440. dataCollector.AddToLocalVariables( dataCollector.PortCategory, -1, localVal );
  1441. result = localVarName;
  1442. }
  1443. break;
  1444. case WirePortDataType.FLOAT:
  1445. {
  1446. result = ( useRealValue ) ? ( (int)value ).ToString() : "(float)" + parameterName;
  1447. }
  1448. break;
  1449. }
  1450. }
  1451. break;
  1452. }
  1453. if( result.Equals( string.Empty ) )
  1454. {
  1455. result = "0";
  1456. string warningStr = string.Format( "Unable to cast from {0} to {1}. Generating dummy data ( {2} )", oldType, newType, result );
  1457. if( oldType == WirePortDataType.SAMPLER1D || oldType == WirePortDataType.SAMPLER2D || oldType == WirePortDataType.SAMPLER3D || oldType == WirePortDataType.SAMPLERCUBE )
  1458. {
  1459. warningStr = string.Format( "Unable to cast from {0} to {1}. You might want to use a Texture Sample node and connect it to the 'Tex' port. Generating dummy data ( {2} )", oldType, newType, result );
  1460. }
  1461. ShowMessage( warningStr, MessageSeverity.Warning );
  1462. }
  1463. return result;
  1464. }
  1465. public static bool CanCast( WirePortDataType from, WirePortDataType to )
  1466. {
  1467. if( from == WirePortDataType.OBJECT || to == WirePortDataType.OBJECT || from == to )
  1468. return true;
  1469. switch( from )
  1470. {
  1471. case WirePortDataType.FLOAT:
  1472. {
  1473. if( to == WirePortDataType.INT )
  1474. return true;
  1475. }
  1476. break;
  1477. case WirePortDataType.FLOAT2:
  1478. {
  1479. return false;
  1480. }
  1481. case WirePortDataType.FLOAT3:
  1482. {
  1483. if( to == WirePortDataType.COLOR ||
  1484. to == WirePortDataType.FLOAT4 )
  1485. return true;
  1486. }
  1487. break;
  1488. case WirePortDataType.FLOAT4:
  1489. {
  1490. if( to == WirePortDataType.FLOAT3 ||
  1491. to == WirePortDataType.COLOR )
  1492. return true;
  1493. }
  1494. break;
  1495. case WirePortDataType.FLOAT3x3:
  1496. {
  1497. if( to == WirePortDataType.FLOAT4x4 )
  1498. return true;
  1499. }
  1500. break;
  1501. case WirePortDataType.FLOAT4x4:
  1502. {
  1503. if( to == WirePortDataType.FLOAT3x3 )
  1504. return true;
  1505. }
  1506. break;
  1507. case WirePortDataType.COLOR:
  1508. {
  1509. if( to == WirePortDataType.FLOAT3 ||
  1510. to == WirePortDataType.FLOAT4 )
  1511. return true;
  1512. }
  1513. break;
  1514. case WirePortDataType.INT:
  1515. {
  1516. if( to == WirePortDataType.FLOAT )
  1517. return true;
  1518. }
  1519. break;
  1520. }
  1521. return false;
  1522. }
  1523. public static int GetChannelsAmount( WirePortDataType type )
  1524. {
  1525. switch( type )
  1526. {
  1527. case WirePortDataType.OBJECT: return 0;
  1528. case WirePortDataType.FLOAT: return 1;
  1529. case WirePortDataType.FLOAT2: return 2;
  1530. case WirePortDataType.FLOAT3: return 3;
  1531. case WirePortDataType.FLOAT4: return 4;
  1532. case WirePortDataType.FLOAT3x3: return 9;
  1533. case WirePortDataType.FLOAT4x4: return 16;
  1534. case WirePortDataType.COLOR: return 4;
  1535. case WirePortDataType.INT: return 1;
  1536. case WirePortDataType.UINT: return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. public static WirePortDataType GetWireTypeForChannelAmount( int channelAmount )
  1541. {
  1542. switch( channelAmount )
  1543. {
  1544. case 1: return WirePortDataType.FLOAT;
  1545. case 2: return WirePortDataType.FLOAT2;
  1546. case 3: return WirePortDataType.FLOAT3;
  1547. case 4: return WirePortDataType.FLOAT4;
  1548. case 9: return WirePortDataType.FLOAT3x3;
  1549. case 16: return WirePortDataType.FLOAT4x4;
  1550. }
  1551. return WirePortDataType.FLOAT;
  1552. }
  1553. public static string GenerateUniformName( bool excludeUniformKeword, WirePortDataType dataType, string dataName )
  1554. {
  1555. int index = excludeUniformKeword ? 1 : 0;
  1556. return string.Format( Constants.UniformDec[ index ], WirePortToCgType( dataType ), dataName );
  1557. }
  1558. public static string GenerateUniformName( bool excludeUniformKeword, string dataType, string dataName )
  1559. {
  1560. int index = excludeUniformKeword ? 1 : 0;
  1561. return string.Format( Constants.UniformDec[index], dataType, dataName );
  1562. }
  1563. public static string GeneratePropertyName( string name, PropertyType propertyType, bool forceUnderscore = false )
  1564. {
  1565. if( string.IsNullOrEmpty( name ) )
  1566. return name;
  1567. name = RemoveInvalidCharacters( name );
  1568. if( propertyType != PropertyType.Global || forceUnderscore )
  1569. {
  1570. if( name[ 0 ] != '_' )
  1571. {
  1572. name = '_' + name;
  1573. }
  1574. }
  1575. return name;
  1576. }
  1577. public static string UrlReplaceInvalidStrings( string originalString )
  1578. {
  1579. for( int i = 0; i < Constants.UrlReplacementStringValuesLen; i++ )
  1580. {
  1581. originalString = originalString.Replace( Constants.UrlReplacementStringValues[i,0], Constants.UrlReplacementStringValues[i,1] );
  1582. }
  1583. return originalString;
  1584. }
  1585. public static string ReplaceInvalidStrings( string originalString )
  1586. {
  1587. for(int i = 0; i< Constants.ReplacementStringValuesLen;i++ )
  1588. {
  1589. originalString = originalString.Replace( Constants.ReplacementStringValues[i,0], Constants.ReplacementStringValues[ i, 1 ] );
  1590. }
  1591. return originalString;
  1592. }
  1593. public static string RemoveWikiInvalidCharacters( string originalString )
  1594. {
  1595. for( int i = 0; i < Constants.WikiInvalidChars.Length; i++ )
  1596. {
  1597. originalString = originalString.Replace( Constants.WikiInvalidChars[ i ], string.Empty );
  1598. }
  1599. return originalString;
  1600. }
  1601. public static string RemoveInvalidEnumCharacters( string originalString )
  1602. {
  1603. for( int i = 0; i < Constants.EnumInvalidChars.Length; i++ )
  1604. {
  1605. originalString = originalString.Replace( Constants.EnumInvalidChars[ i ], string.Empty );
  1606. }
  1607. return originalString;
  1608. }
  1609. public static string RemoveInvalidAttrCharacters( string originalString )
  1610. {
  1611. for( int i = 0; i < Constants.AttrInvalidChars.Length; i++ )
  1612. {
  1613. originalString = originalString.Replace( Constants.AttrInvalidChars[ i ], string.Empty );
  1614. }
  1615. return originalString;
  1616. }
  1617. public static string RemoveInvalidCharacters( string originalString )
  1618. {
  1619. for( int i = 0; i < Constants.OverallInvalidChars.Length; i++ )
  1620. {
  1621. originalString = originalString.Replace( Constants.OverallInvalidChars[ i ], string.Empty );
  1622. }
  1623. return originalString;
  1624. }
  1625. public static string RemoveShaderInvalidCharacters( string originalString )
  1626. {
  1627. originalString = originalString.Replace( '\\', '/' );
  1628. for( int i = 0; i < Constants.ShaderInvalidChars.Length; i++ )
  1629. {
  1630. originalString = originalString.Replace( Constants.ShaderInvalidChars[ i ], string.Empty );
  1631. }
  1632. return originalString;
  1633. }
  1634. public static bool IsUnityNativeShader( Shader shader )
  1635. {
  1636. string pathName = AssetDatabase.GetAssetPath( shader );
  1637. if( pathName.Contains( "unity_builtin_extra") ||
  1638. pathName.Contains( "unity default resources" ))
  1639. return true;
  1640. return false;
  1641. }
  1642. public static bool IsUnityNativeShader( string path ) { return m_unityNativeShaderPaths.ContainsKey( path ); }
  1643. public static string GetComponentForPosition( int pos, WirePortDataType type, bool addDot = false )
  1644. {
  1645. string result = addDot ? "." : string.Empty;
  1646. switch( pos )
  1647. {
  1648. case 0:
  1649. {
  1650. return ( ( type == WirePortDataType.COLOR ) ? ( result + "r" ) : ( result + "x" ) );
  1651. }
  1652. case 1:
  1653. {
  1654. return ( ( type == WirePortDataType.COLOR ) ? ( result + "g" ) : ( result + "y" ) );
  1655. }
  1656. case 2:
  1657. {
  1658. return ( ( type == WirePortDataType.COLOR ) ? ( result + "b" ) : ( result + "z" ) );
  1659. }
  1660. case 3:
  1661. {
  1662. return ( ( type == WirePortDataType.COLOR ) ? ( result + "a" ) : ( result + "w" ) );
  1663. }
  1664. }
  1665. return string.Empty;
  1666. }
  1667. public static string InvalidParameter( ParentNode node )
  1668. {
  1669. ShowMessage( "Invalid entrance type on node" + node, MessageSeverity.Error );
  1670. return "0";
  1671. }
  1672. public static string NoConnection( ParentNode node )
  1673. {
  1674. ShowMessage( "No Input connection on node" + node, MessageSeverity.Error );
  1675. return "0";
  1676. }
  1677. public static string UnknownError( ParentNode node )
  1678. {
  1679. ShowMessage( "Unknown error on node" + node, MessageSeverity.Error );
  1680. return "0";
  1681. }
  1682. public static string GetTex2DProperty( string name, TexturePropertyValues defaultValue ) { return name + "(\"" + name + "\", 2D) = \"" + defaultValue + "\" {}"; }
  1683. public static string AddBrackets( string value ) { return "( " + value + " )"; }
  1684. public static Color GetColorFromWireStatus( WireStatus status ) { return m_wireStatusToColor[ status ]; }
  1685. public static bool HasColorCategory( string category ) { return m_nodeCategoryToColor.ContainsKey( category ); }
  1686. public static void AddColorCategory( string category, Color color )
  1687. {
  1688. m_nodeCategoryToColor.Add( category, color );
  1689. }
  1690. public static Color AddColorCategory( string category, string hexColor )
  1691. {
  1692. try
  1693. {
  1694. Color color = new Color();
  1695. ColorUtility.TryParseHtmlString( hexColor, out color );
  1696. m_nodeCategoryToColor.Add( category, color );
  1697. return color;
  1698. }
  1699. catch( System.Exception e )
  1700. {
  1701. Debug.LogException( e );
  1702. }
  1703. return m_nodeCategoryToColor[ "Default" ];
  1704. }
  1705. public static Color GetColorFromCategory( string category )
  1706. {
  1707. if( m_nodeCategoryToColor.ContainsKey( category ) )
  1708. return m_nodeCategoryToColor[ category ];
  1709. if(DebugConsoleWindow.DeveloperMode)
  1710. Debug.LogWarning( category + " category does not contain an associated color" );
  1711. return m_nodeCategoryToColor[ "Default" ];
  1712. }
  1713. public static string LatestOpenedFolder
  1714. {
  1715. get { return m_latestOpenedFolder; }
  1716. set { m_latestOpenedFolder = value; }
  1717. }
  1718. public static Shader CreateNewUnlit()
  1719. {
  1720. if( CurrentWindow == null )
  1721. return null;
  1722. string shaderName;
  1723. string pathName;
  1724. Shader newShader = null;
  1725. IOUtils.GetShaderName( out shaderName, out pathName, "MyUnlitShader", m_latestOpenedFolder );
  1726. if( !System.String.IsNullOrEmpty( shaderName ) && !System.String.IsNullOrEmpty( pathName ) )
  1727. {
  1728. CurrentWindow.CreateNewGraph( shaderName );
  1729. CurrentWindow.PreMadeShadersInstance.FlatColorSequence.Execute();
  1730. CurrentWindow.CurrentGraph.CurrentMasterNode.SetName( shaderName );
  1731. newShader = CurrentWindow.CurrentGraph.FireMasterNode( pathName, true );
  1732. AssetDatabase.Refresh();
  1733. }
  1734. return newShader;
  1735. }
  1736. public static Shader CreateNewEmpty( string customPath = null )
  1737. {
  1738. if( CurrentWindow == null )
  1739. return null;
  1740. string shaderName;
  1741. string pathName;
  1742. Shader newShader = null;
  1743. string path = AssetDatabase.GetAssetPath( Selection.activeObject );
  1744. if( path == "" )
  1745. {
  1746. path = "Assets";
  1747. }
  1748. else if( System.IO.Path.GetExtension( path ) != "" )
  1749. {
  1750. path = path.Replace( System.IO.Path.GetFileName( AssetDatabase.GetAssetPath( Selection.activeObject ) ), "" );
  1751. }
  1752. if( string.IsNullOrEmpty( customPath ) )
  1753. {
  1754. IOUtils.GetShaderName( out shaderName, out pathName, Constants.DefaultShaderName, m_latestOpenedFolder );
  1755. }
  1756. else
  1757. {
  1758. pathName = customPath;
  1759. shaderName = Constants.DefaultShaderName;
  1760. int indexOfAssets = pathName.IndexOf( "Assets" );
  1761. string uniquePath = ( indexOfAssets > 0 )? pathName.Remove( 0, indexOfAssets ) : pathName;
  1762. string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath( uniquePath + shaderName + ".shader" );
  1763. pathName = assetPathAndName;
  1764. shaderName = assetPathAndName.Remove( 0, assetPathAndName.IndexOf( shaderName ) );
  1765. shaderName = shaderName.Remove( shaderName.Length - 7 );
  1766. }
  1767. if( !System.String.IsNullOrEmpty( shaderName ) && !System.String.IsNullOrEmpty( pathName ) )
  1768. {
  1769. m_latestOpenedFolder = pathName;
  1770. CurrentWindow.titleContent.text = AmplifyShaderEditorWindow.GenerateTabTitle( shaderName );
  1771. CurrentWindow.titleContent.image = ShaderIcon;
  1772. CurrentWindow.CreateNewGraph( shaderName );
  1773. CurrentWindow.LastOpenedLocation = pathName;
  1774. CurrentWindow.CurrentGraph.CurrentMasterNode.SetName( shaderName );
  1775. newShader = CurrentWindow.CurrentGraph.FireMasterNode( pathName, true );
  1776. AssetDatabase.Refresh();
  1777. }
  1778. return newShader;
  1779. }
  1780. public static Shader CreateNewEmptyTemplate( string templateGUID, string customPath = null )
  1781. {
  1782. if( CurrentWindow == null )
  1783. return null;
  1784. string shaderName;
  1785. string pathName;
  1786. Shader newShader = null;
  1787. string path = AssetDatabase.GetAssetPath( Selection.activeObject );
  1788. if( path == "" )
  1789. {
  1790. path = "Assets";
  1791. }
  1792. else if( System.IO.Path.GetExtension( path ) != "" )
  1793. {
  1794. path = path.Replace( System.IO.Path.GetFileName( AssetDatabase.GetAssetPath( Selection.activeObject ) ), "" );
  1795. }
  1796. if( string.IsNullOrEmpty( customPath ) )
  1797. {
  1798. IOUtils.GetShaderName( out shaderName, out pathName, Constants.DefaultShaderName, m_latestOpenedFolder );
  1799. }
  1800. else
  1801. {
  1802. pathName = customPath;
  1803. shaderName = Constants.DefaultShaderName;
  1804. int indexOfAssets = pathName.IndexOf( "Assets" );
  1805. string uniquePath = ( indexOfAssets > 0 ) ? pathName.Remove( 0, indexOfAssets ) : pathName;
  1806. string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath( uniquePath + shaderName + ".shader" );
  1807. pathName = assetPathAndName;
  1808. shaderName = assetPathAndName.Remove( 0, assetPathAndName.IndexOf( shaderName ) );
  1809. shaderName = shaderName.Remove( shaderName.Length - 7 );
  1810. }
  1811. if( !System.String.IsNullOrEmpty( shaderName ) && !System.String.IsNullOrEmpty( pathName ) )
  1812. {
  1813. m_latestOpenedFolder = pathName;
  1814. CurrentWindow.titleContent.text = AmplifyShaderEditorWindow.GenerateTabTitle( shaderName );
  1815. CurrentWindow.titleContent.image = UIUtils.ShaderIcon;
  1816. CurrentWindow.CreateNewTemplateGraph( templateGUID );
  1817. CurrentWindow.CurrentGraph.CurrentMasterNode.SetName( shaderName );
  1818. newShader = CurrentWindow.CurrentGraph.FireMasterNode( pathName, true );
  1819. AssetDatabase.Refresh();
  1820. }
  1821. return newShader;
  1822. }
  1823. public static void SetDelayedMaterialMode( Material material )
  1824. {
  1825. if( CurrentWindow == null )
  1826. return;
  1827. CurrentWindow.SetDelayedMaterialMode( material );
  1828. }
  1829. public static void CreateEmptyFromInvalid( Shader shader )
  1830. {
  1831. if( CurrentWindow == null )
  1832. return;
  1833. CurrentWindow.CreateNewGraph( shader );
  1834. CurrentWindow.ForceRepaint();
  1835. }
  1836. public static void CreateEmptyFunction( AmplifyShaderFunction shaderFunction )
  1837. {
  1838. if( CurrentWindow == null )
  1839. return;
  1840. CurrentWindow.CreateNewFunctionGraph( shaderFunction );
  1841. CurrentWindow.SaveToDisk( false );
  1842. CurrentWindow.ForceRepaint();
  1843. }
  1844. public static void DrawFloat( UndoParentNode owner, ref Rect propertyDrawPos, ref float value, float newLabelWidth = 8 )
  1845. {
  1846. float labelWidth = EditorGUIUtility.labelWidth;
  1847. EditorGUIUtility.labelWidth = newLabelWidth;
  1848. value = owner.EditorGUIFloatField( propertyDrawPos, " ", value, UIUtils.MainSkin.textField );
  1849. EditorGUIUtility.labelWidth = labelWidth;
  1850. }
  1851. public static GUIStyle GetCustomStyle( CustomStyle style )
  1852. {
  1853. return ( Initialized ) ? MainSkin.customStyles[ (int)style ] : null;
  1854. }
  1855. public static void SetCustomStyle( CustomStyle style, GUIStyle guiStyle )
  1856. {
  1857. if( MainSkin != null )
  1858. MainSkin.customStyles[ (int)style ] = new GUIStyle( guiStyle );
  1859. }
  1860. public static void OpenFile()
  1861. {
  1862. if( CurrentWindow == null )
  1863. return;
  1864. string newShader = EditorUtility.OpenFilePanel( "Select Shader to open", m_latestOpenedFolder, "shader" );
  1865. if( !System.String.IsNullOrEmpty( newShader ) )
  1866. {
  1867. m_latestOpenedFolder = newShader.Substring( 0, newShader.LastIndexOf( '/' ) + 1 );
  1868. int relFilenameId = newShader.IndexOf( Application.dataPath );
  1869. if( relFilenameId > -1 )
  1870. {
  1871. string relFilename = newShader.Substring( relFilenameId + Application.dataPath.Length - 6 );// -6 need to also copy the assets/ part
  1872. CurrentWindow.LoadFromDisk( relFilename );
  1873. }
  1874. else
  1875. {
  1876. ShowMessage( "Can only load shaders\nfrom inside the projects folder", MessageSeverity.Error );
  1877. }
  1878. }
  1879. }
  1880. public static bool DetectNodeLoopsFrom( ParentNode node, Dictionary<int, int> currentNodes )
  1881. {
  1882. if( currentNodes.ContainsKey( node.UniqueId ) )
  1883. {
  1884. currentNodes.Clear();
  1885. currentNodes = null;
  1886. return true;
  1887. }
  1888. currentNodes.Add( node.UniqueId, 1 );
  1889. bool foundLoop = false;
  1890. for( int i = 0; i < node.InputPorts.Count; i++ )
  1891. {
  1892. if( node.InputPorts[ i ].IsConnected )
  1893. {
  1894. ParentNode newNode = node.InputPorts[ i ].GetOutputNode();
  1895. if( newNode.InputPorts.Count > 0 )
  1896. {
  1897. Dictionary<int, int> newDict = new Dictionary<int, int>();
  1898. foreach( KeyValuePair<int, int> entry in currentNodes )
  1899. {
  1900. newDict.Add( entry.Key, entry.Value );
  1901. }
  1902. foundLoop = foundLoop || DetectNodeLoopsFrom( newNode, newDict );
  1903. if( foundLoop )
  1904. break;
  1905. }
  1906. }
  1907. }
  1908. currentNodes.Clear();
  1909. currentNodes = null;
  1910. return foundLoop;
  1911. }
  1912. public static ParentNode CreateNode( System.Type type, bool registerUndo, Vector2 pos, int nodeId = -1, bool addLast = true )
  1913. {
  1914. if( CurrentWindow != null )
  1915. {
  1916. return CurrentWindow.CurrentGraph.CreateNode( type, registerUndo, pos, nodeId, addLast );
  1917. }
  1918. return null;
  1919. }
  1920. public static void DestroyNode( int nodeId )
  1921. {
  1922. if( CurrentWindow != null )
  1923. {
  1924. CurrentWindow.CurrentGraph.DestroyNode( nodeId );
  1925. }
  1926. }
  1927. public static void ShowMessage( string message, MessageSeverity severity = MessageSeverity.Normal, bool registerTimestamp = true )
  1928. {
  1929. if( CurrentWindow != null )
  1930. {
  1931. CurrentWindow.ShowMessage( message, severity, registerTimestamp );
  1932. }
  1933. }
  1934. public static ParentNode GetNode( int nodeId )
  1935. {
  1936. if( CurrentWindow != null )
  1937. {
  1938. return CurrentWindow.CurrentGraph.GetNode( nodeId );
  1939. }
  1940. return null;
  1941. }
  1942. public static PropertyNode GetInternalTemplateNode( int nodeId )
  1943. {
  1944. if( CurrentWindow != null )
  1945. {
  1946. return CurrentWindow.CurrentGraph.GetInternalTemplateNode( nodeId );
  1947. }
  1948. return null;
  1949. }
  1950. public static void DeleteConnection( bool isInput, int nodeId, int portId, bool registerOnLog, bool propagateCallback )
  1951. {
  1952. if( CurrentWindow != null )
  1953. {
  1954. CurrentWindow.DeleteConnection( isInput, nodeId, portId, registerOnLog, propagateCallback );
  1955. }
  1956. }
  1957. public static void ConnectInputToOutput( int inNodeId, int inPortId, int outNodeId, int outPortId )
  1958. {
  1959. if( CurrentWindow != null )
  1960. {
  1961. CurrentWindow.ConnectInputToOutput( inNodeId, inPortId, outNodeId, outPortId );
  1962. }
  1963. }
  1964. public static Shader CreateNewGraph( string name )
  1965. {
  1966. if( CurrentWindow != null )
  1967. {
  1968. return CurrentWindow.CreateNewGraph( name );
  1969. }
  1970. return null;
  1971. }
  1972. public static void SetConnection( int InNodeId, int InPortId, int OutNodeId, int OutPortId )
  1973. {
  1974. if( CurrentWindow != null )
  1975. {
  1976. CurrentWindow.CurrentGraph.SetConnection( InNodeId, InPortId, OutNodeId, OutPortId );
  1977. }
  1978. }
  1979. public static bool IsChannelAvailable( int channelId )
  1980. {
  1981. if( CurrentWindow != null )
  1982. {
  1983. return CurrentWindow.DuplicatePrevBufferInstance.IsChannelAvailable( channelId );
  1984. }
  1985. return false;
  1986. }
  1987. public static bool ReleaseUVChannel( int nodeId, int channelId )
  1988. {
  1989. if( CurrentWindow != null )
  1990. {
  1991. return CurrentWindow.DuplicatePrevBufferInstance.ReleaseUVChannel( nodeId, channelId );
  1992. }
  1993. return false;
  1994. }
  1995. public static bool RegisterUVChannel( int nodeId, int channelId, string name )
  1996. {
  1997. if( CurrentWindow != null )
  1998. {
  1999. return CurrentWindow.DuplicatePrevBufferInstance.RegisterUVChannel( nodeId, channelId, name );
  2000. }
  2001. return false;
  2002. }
  2003. public static void GetFirstAvailableName( int nodeId, WirePortDataType type, out string outProperty, out string outInspector, bool useCustomPrefix = false, string customPrefix = null )
  2004. {
  2005. outProperty = string.Empty;
  2006. outInspector = string.Empty;
  2007. if( CurrentWindow != null )
  2008. {
  2009. CurrentWindow.DuplicatePrevBufferInstance.GetFirstAvailableName( nodeId, type, out outProperty, out outInspector, useCustomPrefix, customPrefix );
  2010. }
  2011. }
  2012. public static bool IsNumericName( string name )
  2013. {
  2014. Match match = Regex.Match( name, NumericNamePattern );
  2015. if( match != null && match.Success )
  2016. return true;
  2017. return false;
  2018. }
  2019. public static bool CheckInvalidUniformName( string name )
  2020. {
  2021. if( m_reservedPropertyNames.ContainsKey( name ) )
  2022. {
  2023. ShowMessage( string.Format( Constants.ReservedPropertyNameStr, name ) );
  2024. return true;
  2025. }
  2026. if( IsNumericName( name ))
  2027. {
  2028. ShowMessage( string.Format( Constants.NumericPropertyNameStr, name ) );
  2029. return true;
  2030. }
  2031. return false;
  2032. }
  2033. public static bool RegisterUniformName( int nodeId, string name )
  2034. {
  2035. if( CheckInvalidUniformName( name ) )
  2036. {
  2037. return false;
  2038. }
  2039. if( CurrentWindow != null )
  2040. {
  2041. return CurrentWindow.DuplicatePrevBufferInstance.RegisterUniformName( nodeId, name );
  2042. }
  2043. return false;
  2044. }
  2045. public static bool ReleaseUniformName( int nodeId, string name )
  2046. {
  2047. if( CurrentWindow != null )
  2048. {
  2049. return CurrentWindow.DuplicatePrevBufferInstance.ReleaseUniformName( nodeId, name );
  2050. }
  2051. return false;
  2052. }
  2053. public static bool IsUniformNameAvailable( string name )
  2054. {
  2055. if( CheckInvalidUniformName( name ) )
  2056. {
  2057. return false;
  2058. }
  2059. if( CurrentWindow != null )
  2060. {
  2061. return CurrentWindow.DuplicatePrevBufferInstance.IsUniformNameAvailable( name );
  2062. }
  2063. return false;
  2064. }
  2065. public static int CheckUniformNameOwner( string name )
  2066. {
  2067. if( CurrentWindow != null )
  2068. {
  2069. return CurrentWindow.DuplicatePrevBufferInstance.CheckUniformNameOwner( name );
  2070. }
  2071. return -1;
  2072. }
  2073. public static bool RegisterLocalVariableName( int nodeId, string name )
  2074. {
  2075. if( CurrentWindow != null )
  2076. {
  2077. return CurrentWindow.DuplicatePrevBufferInstance.RegisterLocalVariableName( nodeId, name );
  2078. }
  2079. return false;
  2080. }
  2081. public static bool ReleaseLocalVariableName( int nodeId, string name )
  2082. {
  2083. if( CurrentWindow != null )
  2084. {
  2085. return CurrentWindow.DuplicatePrevBufferInstance.ReleaseLocalVariableName( nodeId, name );
  2086. }
  2087. return false;
  2088. }
  2089. public static bool IsLocalvariableNameAvailable( string name )
  2090. {
  2091. if( CurrentWindow != null )
  2092. {
  2093. return CurrentWindow.DuplicatePrevBufferInstance.IsLocalvariableNameAvailable( name );
  2094. }
  2095. return false;
  2096. }
  2097. public static string GetChannelName( int channelId )
  2098. {
  2099. if( CurrentWindow != null )
  2100. {
  2101. return CurrentWindow.DuplicatePrevBufferInstance.GetChannelName( channelId );
  2102. }
  2103. return string.Empty;
  2104. }
  2105. public static void SetChannelName( int channelId, string name )
  2106. {
  2107. if( CurrentWindow != null )
  2108. {
  2109. CurrentWindow.DuplicatePrevBufferInstance.SetChannelName( channelId, name );
  2110. }
  2111. }
  2112. public static int RegisterFirstAvailableChannel( int nodeId, string name )
  2113. {
  2114. if( CurrentWindow != null )
  2115. {
  2116. return CurrentWindow.DuplicatePrevBufferInstance.RegisterFirstAvailableChannel( nodeId, name );
  2117. }
  2118. return -1;
  2119. }
  2120. public static int PortCategorytoAttayIdx( MasterNodePortCategory category )
  2121. {
  2122. if( m_portCategoryToArrayIdx.ContainsKey( category ))
  2123. return m_portCategoryToArrayIdx[category];
  2124. return m_portCategoryToArrayIdx[ MasterNodePortCategory.Fragment ];
  2125. }
  2126. public static bool DisplayDialog( string shaderPath )
  2127. {
  2128. string value = System.String.Format( "Save changes to the shader {0} before closing?", shaderPath );
  2129. return EditorUtility.DisplayDialog( "Load selected", value, "Yes", "No" );
  2130. }
  2131. public static void ForceUpdateFromMaterial()
  2132. {
  2133. if( CurrentWindow != null )
  2134. {
  2135. // CurrentWindow.Focus();
  2136. CurrentWindow.ForceUpdateFromMaterial();
  2137. }
  2138. }
  2139. public static void MarkToRepaint() { if( CurrentWindow != null ) CurrentWindow.MarkToRepaint(); }
  2140. public static void RequestSave() { if( CurrentWindow != null ) CurrentWindow.RequestSave(); }
  2141. public static string FloatToString( float value )
  2142. {
  2143. string floatStr = value.ToString();
  2144. if( value % 1 == 0 )
  2145. {
  2146. floatStr += ".0";
  2147. }
  2148. return floatStr;
  2149. }
  2150. public static int CurrentShaderVersion()
  2151. {
  2152. if( CurrentWindow != null )
  2153. {
  2154. return CurrentWindow.CurrentGraph.LoadedShaderVersion;
  2155. }
  2156. return -1;
  2157. }
  2158. public static bool IsProperty( PropertyType type ) { return ( type == PropertyType.Property || type == PropertyType.InstancedProperty ); }
  2159. public static MasterNode CurrentMasterNode()
  2160. {
  2161. if( CurrentWindow != null )
  2162. {
  2163. return CurrentWindow.CurrentGraph.CurrentMasterNode;
  2164. }
  2165. return null;
  2166. }
  2167. public static void AddVirtualTextureCount() { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.AddVirtualTextureCount(); } }
  2168. public static bool HasVirtualTexture()
  2169. {
  2170. if( CurrentWindow != null )
  2171. {
  2172. return CurrentWindow.CurrentGraph.HasVirtualTexture;
  2173. }
  2174. return false;
  2175. }
  2176. public static void RemoveVirtualTextureCount() { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.RemoveVirtualTextureCount(); } }
  2177. //public static void AddInstancePropertyCount() { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.AddInstancePropertyCount(); } }
  2178. public static bool IsInstancedShader()
  2179. {
  2180. if( CurrentWindow != null )
  2181. {
  2182. return CurrentWindow.CurrentGraph.IsInstancedShader;
  2183. }
  2184. return false;
  2185. }
  2186. //public static void RemoveInstancePropertyCount() { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.RemoveInstancePropertyCount(); } }
  2187. //public static void AddNormalDependentCount() { if ( CurrentWindow != null ) { CurrentWindow.CurrentGraph.AddNormalDependentCount(); } }
  2188. //public static void RemoveNormalDependentCount() { if ( CurrentWindow != null ) { CurrentWindow.CurrentGraph.RemoveNormalDependentCount(); } }
  2189. //public static bool IsNormalDependent()
  2190. //{
  2191. // if ( CurrentWindow != null )
  2192. // {
  2193. // return CurrentWindow.CurrentGraph.IsNormalDependent;
  2194. // }
  2195. // return false;
  2196. //}
  2197. public static void CopyValuesFromMaterial( Material mat )
  2198. {
  2199. if( CurrentWindow != null && CurrentWindow.CurrentMaterial == mat )
  2200. {
  2201. CurrentWindow.CurrentGraph.CopyValuesFromMaterial( mat );
  2202. }
  2203. else
  2204. {
  2205. int aseWindowCount = IOUtils.AllOpenedWindows.Count;
  2206. for( int i = 0; i < aseWindowCount; i++ )
  2207. {
  2208. if( IOUtils.AllOpenedWindows[ i ] != m_currentWindow && IOUtils.AllOpenedWindows[ i ].CurrentMaterial == mat )
  2209. {
  2210. IOUtils.AllOpenedWindows[ i ].CurrentGraph.CopyValuesFromMaterial( mat );
  2211. break;
  2212. }
  2213. }
  2214. }
  2215. }
  2216. // Sampler Node
  2217. public static void RegisterSamplerNode( SamplerNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.SamplerNodes.AddNode( node ); } }
  2218. public static void UnregisterSamplerNode( SamplerNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.SamplerNodes.RemoveNode( node ); } }
  2219. public static string[] SamplerNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.SamplerNodes.NodesArr; } return null; }
  2220. public static SamplerNode GetSamplerNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.SamplerNodes.GetNode( idx ); } return null; }
  2221. public static void UpdateSamplerDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.SamplerNodes.UpdateDataOnNode( uniqueId, data ); } }
  2222. public static int GetSamplerNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.SamplerNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2223. public static int GetSamplerNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.SamplerNodes.NodesList.Count; } return -1; }
  2224. // Float Node
  2225. public static void RegisterFloatIntNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FloatIntNodes.AddNode( node ); } }
  2226. public static void UnregisterFloatIntNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FloatIntNodes.RemoveNode( node ); } }
  2227. public static string[] FloatIntNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatIntNodes.NodesArr; } return null; }
  2228. public static int[] FloatIntNodeIds() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatIntNodes.NodeIds; } return null; }
  2229. public static PropertyNode GetFloatIntNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatIntNodes.GetNode( idx ); } return null; }
  2230. public static void UpdateFloatIntDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FloatIntNodes.UpdateDataOnNode( uniqueId, data ); } }
  2231. public static int GetFloatIntNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatIntNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2232. public static int GetNodeIdByName( string name )
  2233. {
  2234. if( CurrentWindow != null )
  2235. {
  2236. UsageListFloatIntNodes list = CurrentWindow.CurrentGraph.FloatIntNodes;
  2237. int count = list.Count;
  2238. for( int i = 0; i < count; i++ )
  2239. {
  2240. if( list.NodesList[ i ].PropertyName.Equals( name ) )
  2241. return list.NodesList[ i ].UniqueId;
  2242. }
  2243. }
  2244. return -1;
  2245. }
  2246. public static PropertyNode GetFloatIntNodeByUniqueId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatIntNodes.GetNodeByUniqueId( uniqueId ); } return null; }
  2247. //public static int GetFloatNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FloatNodes.NodesList.Count; } return -1; }
  2248. // Texture Property
  2249. public static void RegisterTexturePropertyNode( TexturePropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TexturePropertyNodes.AddNode( node ); } }
  2250. public static void UnregisterTexturePropertyNode( TexturePropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TexturePropertyNodes.RemoveNode( node ); } }
  2251. public static string[] TexturePropertyNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TexturePropertyNodes.NodesArr; } return null; }
  2252. public static TexturePropertyNode GetTexturePropertyNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TexturePropertyNodes.GetNode( idx ); } return null; }
  2253. public static void UpdateTexturePropertyDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TexturePropertyNodes.UpdateDataOnNode( uniqueId, data ); } }
  2254. public static int GetTexturePropertyNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TexturePropertyNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2255. public static int GetTexturePropertyNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TexturePropertyNodes.NodesList.Count; } return -1; }
  2256. // Texture Array
  2257. public static void RegisterTextureArrayNode( TextureArrayNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TextureArrayNodes.AddNode( node ); } }
  2258. public static void UnregisterTextureArrayNode( TextureArrayNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TextureArrayNodes.RemoveNode( node ); } }
  2259. public static string[] TextureArrayNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TextureArrayNodes.NodesArr; } return null; }
  2260. public static TextureArrayNode GetTextureArrayNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TextureArrayNodes.GetNode( idx ); } return null; }
  2261. public static void UpdateTextureArrayDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.TextureArrayNodes.UpdateDataOnNode( uniqueId, data ); } }
  2262. public static int GetTextureArrayNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TextureArrayNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2263. public static int GetTextureArrayNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.TextureArrayNodes.NodesList.Count; } return -1; }
  2264. // Raw Property Node
  2265. public static void RegisterRawPropertyNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.OutsideGraph.RawPropertyNodes.AddNode( node ); } }
  2266. public static void UnregisterRawPropertyNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.OutsideGraph.RawPropertyNodes.RemoveNode( node ); } }
  2267. // Property Node
  2268. public static void RegisterPropertyNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.PropertyNodes.AddNode( node ); } }
  2269. public static void UnregisterPropertyNode( PropertyNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.PropertyNodes.RemoveNode( node ); } }
  2270. public static string[] PropertyNodeNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.NodesArr; } return null; }
  2271. public static PropertyNode GetPropertyNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.GetNode( idx ); } return null; }
  2272. public static PropertyNode GetPropertyNodeByUniqueId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.GetNodeByUniqueId( uniqueId ); } return null; }
  2273. public static void UpdatePropertyDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.PropertyNodes.UpdateDataOnNode( uniqueId, data ); } }
  2274. public static int GetPropertyNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2275. public static List<PropertyNode> PropertyNodesList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.NodesList; } return null; }
  2276. public static int GetPropertyNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.PropertyNodes.NodesList.Count; } return -1; }
  2277. // Function Inputs
  2278. public static void RegisterFunctionInputNode( FunctionInput node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionInputNodes.AddNode( node ); } }
  2279. public static void UnregisterFunctionInputNode( FunctionInput node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionInputNodes.RemoveNode( node ); } }
  2280. public static void UpdateFunctionInputData( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionInputNodes.UpdateDataOnNode( uniqueId, data ); } }
  2281. public static List<FunctionInput> FunctionInputList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionInputNodes.NodesList; } return null; }
  2282. // Function Nodes
  2283. public static void RegisterFunctionNode( FunctionNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionNodes.AddNode( node ); } }
  2284. public static void UnregisterFunctionNode( FunctionNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionNodes.RemoveNode( node ); } }
  2285. public static void UpdateFunctionData( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionNodes.UpdateDataOnNode( uniqueId, data ); } }
  2286. public static List<FunctionNode> FunctionList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionNodes.NodesList; } return null; }
  2287. // Function Outputs
  2288. public static void RegisterFunctionOutputNode( FunctionOutput node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionOutputNodes.AddNode( node ); } }
  2289. public static void UnregisterFunctionOutputNode( FunctionOutput node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionOutputNodes.RemoveNode( node ); } }
  2290. public static void UpdateFunctionOutputData( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionOutputNodes.UpdateDataOnNode( uniqueId, data ); } }
  2291. public static List<FunctionOutput> FunctionOutputList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionOutputNodes.NodesList; } return null; }
  2292. // Function Switches Copy
  2293. public static void RegisterFunctionSwitchCopyNode( FunctionSwitch node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchCopyNodes.AddNode( node ); } }
  2294. public static void UnregisterFunctionSwitchCopyNode( FunctionSwitch node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchCopyNodes.RemoveNode( node ); } }
  2295. public static void UpdateFunctionSwitchCopyData( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchCopyNodes.UpdateDataOnNode( uniqueId, data ); } }
  2296. public static List<FunctionSwitch> FunctionSwitchCopyList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionSwitchCopyNodes.NodesList; } return null; }
  2297. // Function Switches
  2298. public static void RegisterFunctionSwitchNode( FunctionSwitch node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchNodes.AddNode( node ); } }
  2299. public static void UnregisterFunctionSwitchNode( FunctionSwitch node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchNodes.RemoveNode( node ); } }
  2300. public static void UpdateFunctionSwitchData( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchNodes.UpdateDataOnNode( uniqueId, data ); } }
  2301. public static List<FunctionSwitch> FunctionSwitchList() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionSwitchNodes.NodesList; } return null; }
  2302. public static void UpdateFunctionSwitchArr() { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.FunctionSwitchNodes.UpdateNodeArr(); } }
  2303. public static string[] FunctionSwitchesNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionSwitchNodes.NodesArr; } return null; }
  2304. public static FunctionSwitch GetFunctionSwitchNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionSwitchNodes.GetNode( idx ); } return null; }
  2305. public static int GetFunctionSwitchNodeIndex( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.FunctionSwitchNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2306. // Screen Color Node
  2307. public static void RegisterScreenColorNode( ScreenColorNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.ScreenColorNodes.AddNode( node ); } }
  2308. public static void UnregisterScreenColorNode( ScreenColorNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.ScreenColorNodes.RemoveNode( node ); } }
  2309. public static string[] ScreenColorNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.ScreenColorNodes.NodesArr; } return null; }
  2310. public static ScreenColorNode GetScreenColorNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.ScreenColorNodes.GetNode( idx ); } return null; }
  2311. public static int GetScreenColorNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.ScreenColorNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2312. public static void UpdateScreenColorDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.ScreenColorNodes.UpdateDataOnNode( uniqueId, data ); } }
  2313. public static int GetScreenColorNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.ScreenColorNodes.NodesList.Count; } return -1; }
  2314. // Local Var Node
  2315. public static int RegisterLocalVarNode( RegisterLocalVarNode node ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.LocalVarNodes.AddNode( node ); } return -1; }
  2316. public static void UnregisterLocalVarNode( RegisterLocalVarNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.LocalVarNodes.RemoveNode( node ); } }
  2317. public static string[] LocalVarNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.LocalVarNodes.NodesArr; } return null; }
  2318. public static int LocalVarNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.LocalVarNodes.NodesList.Count; } return 0; }
  2319. public static int GetLocalVarNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.LocalVarNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2320. public static RegisterLocalVarNode GetLocalVarNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.LocalVarNodes.GetNode( idx ); } return null; }
  2321. public static void UpdateLocalVarDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.LocalVarNodes.UpdateDataOnNode( uniqueId, data ); } }
  2322. //Global Array
  2323. public static void RegisterGlobalArrayNode( GlobalArrayNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.GlobalArrayNodes.AddNode( node ); } }
  2324. public static void UnregisterGlobalArrayNode( GlobalArrayNode node ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.GlobalArrayNodes.RemoveNode( node ); } }
  2325. public static string[] GlobalArrayNodeArr() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.GlobalArrayNodes.NodesArr; } return null; }
  2326. public static GlobalArrayNode GetGlobalArrayNode( int idx ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.GlobalArrayNodes.GetNode( idx ); } return null; }
  2327. public static int GetGlobalArrayNodeRegisterId( int uniqueId ) { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.GlobalArrayNodes.GetNodeRegisterIdx( uniqueId ); } return -1; }
  2328. public static void UpdateGlobalArrayDataNode( int uniqueId, string data ) { if( CurrentWindow != null ) { CurrentWindow.CurrentGraph.GlobalArrayNodes.UpdateDataOnNode( uniqueId, data ); } }
  2329. public static int GetGlobalArrayNodeAmount() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.GlobalArrayNodes.NodesList.Count; } return -1; }
  2330. public static void FocusOnNode( ParentNode node, float zoom, bool selectNode ) { if( CurrentWindow != null ) { CurrentWindow.FocusOnNode( node, zoom, selectNode ); } }
  2331. public static PrecisionType CurrentPrecision() { if( CurrentWindow != null ) { return CurrentWindow.CurrentGraph.CurrentPrecision; } return PrecisionType.Float; }
  2332. public static string CurrentPrecisionCg() { if( CurrentWindow != null ) { return m_precisionTypeToCg[ CurrentWindow.CurrentGraph.CurrentPrecision ]; } return m_precisionTypeToCg[ PrecisionType.Float ]; }
  2333. public static PrecisionType GetFinalPrecision( PrecisionType precision )
  2334. {
  2335. if( CurrentWindow != null && CurrentWindow.CurrentGraph != null )
  2336. {
  2337. PrecisionType mainPrecision = CurrentWindow.CurrentGraph.CurrentPrecision;
  2338. if( (int)mainPrecision > (int)precision )
  2339. return mainPrecision;
  2340. }
  2341. return precision;
  2342. }
  2343. public static bool GetNodeAvailabilityInBitArray( int bitArray, NodeAvailability availability ) { return ( bitArray & (int)availability ) != 0; }
  2344. public static bool GetCategoryInBitArray( int bitArray, MasterNodePortCategory category ) { return ( bitArray & (int)category ) != 0; }
  2345. public static void SetCategoryInBitArray( ref int bitArray, MasterNodePortCategory category ) { bitArray = bitArray | (int)category; }
  2346. public static int GetPriority( WirePortDataType type ) { return m_portPriority[ type ]; }
  2347. public static void ShowIncompatiblePortMessage( bool fromInput, ParentNode inNode, WirePort inPort, ParentNode outNode, WirePort outPort )
  2348. {
  2349. string inPortName = inPort.Name.Equals( Constants.EmptyPortValue ) ? inPort.PortId.ToString() : inPort.Name;
  2350. string outPortName = outPort.Name.Equals( Constants.EmptyPortValue ) ? outPort.PortId.ToString() : outPort.Name;
  2351. ShowMessage( string.Format( ( fromInput ? IncorrectInputConnectionErrorMsg : IncorrectOutputConnectionErrorMsg ), inPortName, inNode.Attributes.Name, inPort.DataType, outPort.DataType, outPortName, outNode.Attributes.Name ) );
  2352. }
  2353. public static void ShowNoVertexModeNodeMessage( ParentNode node )
  2354. {
  2355. ShowMessage( string.Format( NoVertexModeNodeWarning, node.Attributes.Name ), MessageSeverity.Warning );
  2356. }
  2357. public static int TotalExampleMaterials { get { return m_exampleMaterialIDs.Count; } }
  2358. public static int ShaderIndentLevel
  2359. {
  2360. get { return m_shaderIndentLevel; }
  2361. set
  2362. {
  2363. m_shaderIndentLevel = Mathf.Max( value, 0 );
  2364. m_shaderIndentTabs = string.Empty;
  2365. for( int i = 0; i < m_shaderIndentLevel; i++ ) { m_shaderIndentTabs += "\t"; }
  2366. }
  2367. }
  2368. public static string ShaderIndentTabs { get { return m_shaderIndentTabs; } }
  2369. public static void AddLineToShaderBody( ref string ShaderBody, string line ) { ShaderBody += m_shaderIndentTabs + line; }
  2370. public static void AddMultiLineToShaderBody( ref string ShaderBody, string[] lines )
  2371. {
  2372. for( int i = 0; i < lines.Length; i++ )
  2373. {
  2374. ShaderBody += m_shaderIndentTabs + lines[ i ];
  2375. }
  2376. }
  2377. public static void ClearUndoHelper()
  2378. {
  2379. m_undoHelper.Clear();
  2380. }
  2381. public static bool CheckUndoNode( ParentNode node )
  2382. {
  2383. if( node == null )
  2384. return false;
  2385. if( m_undoHelper.ContainsKey( node.UniqueId ) )
  2386. {
  2387. return false;
  2388. }
  2389. m_undoHelper.Add( node.UniqueId, node );
  2390. EditorUtility.SetDirty( node );
  2391. return true;
  2392. }
  2393. public static void MarkUndoAction()
  2394. {
  2395. SerializeHelperCounter = 2;
  2396. }
  2397. public static bool SerializeFromUndo()
  2398. {
  2399. if( SerializeHelperCounter > 0 )
  2400. {
  2401. SerializeHelperCounter--;
  2402. return true;
  2403. }
  2404. return false;
  2405. }
  2406. public static int GetKeywordId( string keyword )
  2407. {
  2408. if( AvailableKeywordsDict.Count != AvailableKeywords.Length )
  2409. {
  2410. AvailableKeywordsDict.Clear();
  2411. for( int i = 1; i < AvailableKeywords.Length; i++ )
  2412. {
  2413. AvailableKeywordsDict.Add( AvailableKeywords[ i ], i );
  2414. }
  2415. }
  2416. if( AvailableKeywordsDict.ContainsKey( keyword ) )
  2417. {
  2418. return AvailableKeywordsDict[ keyword ];
  2419. }
  2420. return 0;
  2421. }
  2422. }
  2423. }