void OpenAsset(Object asset)
        {
            ResetUI();
            var shader = asset as Shader;

            if (shader != null)
            {
                OpenAsset(shader);
                Repaint();
                return;
            }
            var compute = asset as ComputeShader;

            if (compute != null)
            {
                OpenAsset(compute);
                Repaint();
                return;
            }
            var material = asset as Material;

            if (material != null)
            {
                OpenAsset(material);
                Repaint();
                return;
            }

            m_GUI = NOOPGUI;
            Repaint();
        }
        void OnEnable()
        {
            m_CurrentPlatform        = EditorUserBuildSettings.activeBuildTarget;
            m_AssetMetadata          = ShaderAnalysisUtils.LoadAssetMetadatasFor(m_CurrentPlatform);
            m_AssetMetadataReference = ShaderAnalysisUtils.LoadAssetMetadatasFor(m_CurrentPlatform, referenceFolder);

            if (m_SupportedPlatformNames == null)
            {
                m_SupportedPlatformNames = EditorShaderTools.SupportedBuildTargets.Select(s => s.ToString()).ToArray();
                m_SupportedPlatforms     = EditorShaderTools.SupportedBuildTargets.ToArray();
            }

            m_GUI = NOOPGUI;
            if (m_SelectedAsset != null && !m_SelectedAsset.Equals(null))
            {
                OpenAsset(m_SelectedAsset);
            }
            if (m_SelectedPlatformIndex >= 0 && m_SelectedPlatformIndex < m_SupportedPlatforms.Length)
            {
                m_CurrentPlatform = m_SupportedPlatforms[m_SelectedPlatformIndex];
                m_AssetMetadata   = ShaderAnalysisUtils.LoadAssetMetadatasFor(m_CurrentPlatform);
            }
            if (!string.IsNullOrEmpty(referenceSourceFolderPath) && Directory.Exists(referenceSourceFolderPath) && m_CurrentPlatform != BuildTarget.NoTarget)
            {
                m_AssetMetadataReference = ShaderAnalysisUtils.LoadAssetMetadatasFor(m_CurrentPlatform, referenceFolder);
            }
        }
示例#3
0
 /// <summary>
 /// Gets the height of the property.
 /// </summary>
 /// <returns>The property height.</returns>
 /// <param name="property">Property.</param>
 /// <param name="label">Label.</param>
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     // ensure property's decorator height is registered
     if (!decoratorHeights.ContainsKey(property.propertyPath))
     {
         decoratorHeights.Add(property.propertyPath, 0f);
     }
     decoratorHeights[property.propertyPath] = 0f;
     if (DrawerToUse != null)
     {
         return(DrawerToUse.GetPropertyHeight(property, label));
     }
     else
     {
         float result = EditorGUI.GetPropertyHeight(property, label, true);
         if (!property.IsArrayElement())
         {
             foreach (PropertyAttribute attr in fieldInfo.GetCustomAttributes <PropertyAttribute>())
             {
                 GUIDrawer drawer = SerializedPropertyX.GetGUIDrawer(fieldInfo, attr);
                 if (drawer is DecoratorDrawer)
                 {
                     float height = (drawer as DecoratorDrawer).GetHeight();
                     result -= height;
                     decoratorHeights[property.propertyPath] += height;
                 }
             }
         }
         return(result);
     }
 }
示例#4
0
        /// <summary>
        /// Gets the GUI drawer for the supplied field.
        /// </summary>
        /// <returns>The GUI drawer for the supplied field.</returns>
        /// <param name="field">Field.</param>
        /// <param name="propertyAttribute">
        /// Property attribute. If null, this method will return a default drawer for the field type, if one exists.
        /// </param>
        public static GUIDrawer GetGUIDrawer(FieldInfo field, PropertyAttribute propertyAttribute)
        {
            GUIDrawer result = null;

            if (field == null)
            {
                return(result);
            }
            System.Type fieldType = GetIListElementType(field.FieldType) ?? field.FieldType;
            List <Dictionary <System.Type, System.Type> > registrationTables =
                new List <Dictionary <System.Type, System.Type> >(
                    new Dictionary <System.Type, System.Type>[] { s_DecoratorsForEachType, s_DrawersForEachType }
                    );

            System.Type propertyAttributeType = propertyAttribute == null ? null : propertyAttribute.GetType();
            foreach (Dictionary <System.Type, System.Type> registrationTable in registrationTables)
            {
                // skip if there is no GUIDrawer for this type in the registration table
                if (
                    !(
                        registrationTable.ContainsKey(fieldType) ||
                        (propertyAttributeType != null && registrationTable.ContainsKey(propertyAttributeType))
                        )
                    )
                {
                    continue;
                }
                // instantiate the new GUIDrawer
                bool isTypeDrawer = registrationTable.ContainsKey(fieldType);
                if (isTypeDrawer && propertyAttributeType != null)
                {
                    isTypeDrawer = !registrationTable.ContainsKey(propertyAttributeType);
                }
                ConstructorInfo constructor = registrationTable[
                    isTypeDrawer ? fieldType : propertyAttributeType
                                              ].GetConstructor(new System.Type[0]);
                result = constructor.Invoke(null) as GUIDrawer;
                // configure the drawer's private fields
                if (result is PropertyDrawer)
                {
                    if (isTypeDrawer)
                    {
                        s_PropertyDrawerAttributeField.SetValue(result, null);
                    }
                    else
                    {
                        s_PropertyDrawerAttributeField.SetValue(result, propertyAttribute);
                    }
                    s_PropertyDrawerFieldInfoField.SetValue(result, field);
                }
                else if (result is GUIDrawer)
                {
                    s_DecoratorDrawerAttributeField.SetValue(result, propertyAttribute);
                }
            }
            return(result);
        }
示例#5
0
 public static void Draw(
     float x,
     ref float y,
     string str,
     float baseW   = 7f,
     float baseH   = 15f,
     bool isLeftUp = true)
 {
     GUIDrawer.Draw(ref x, ref y, str, baseW, baseH, true);
 }
		private void OnGUI() {
			
			GUI.enabled = !EditorApplication.isCompiling;

			if (FlowSystemEditorWindow.defaultSkin == null) FlowSystemEditorWindow.defaultSkin = Resources.Load("UI.Windows/Flow/Styles/Skin" + (EditorGUIUtility.isProSkin == true ? "Dark" : "Light")) as GUISkin;
			
			if (this.guiDrawer == null) this.guiDrawer = new GUIDrawer(this);
			if (this.guiSplash == null) this.guiSplash = new FlowSplash(this);
			if (this.zoomDrawer == null) this.zoomDrawer = new EditorZoomArea();

			if (this.guiSplash.Draw() == false) {

				return;

			}

			//var draw = !FlowSceneView.IsActive();
			
			//if (draw == true) {
			
			this.contentRect = this.position;
			this.contentRect.x = 0f;
			this.contentRect.y = 0f;
			this.contentRect.width = 10000f;
			this.contentRect.height = 10000f;
			this.contentRect.height -= scrollSize;

			var hasData = FlowSystem.HasData();
			if (hasData == true) {

				var oldEnabled = GUI.enabled;
				GUI.enabled = FlowSystem.HasData() && GUI.enabled;
				this.DrawToolbar();
				GUI.enabled = oldEnabled;
				
				this.DrawSettings(TOOLBAR_HEIGHT);
				
				IEnumerable<FlowWindow> windows = null;
				IEnumerable<FlowWindow> containers = null;
				if (hasData == true) {
					
					windows = FlowSystem.GetWindows();
					containers = FlowSystem.GetContainers();
					
				}
				
				this.scrollRect = this.position;
				this.scrollRect.x = SETTINGS_WIDTH;
				this.scrollRect.y = TOOLBAR_HEIGHT;
				this.scrollRect.width -= SETTINGS_WIDTH;
				this.scrollRect.height -= TOOLBAR_HEIGHT;
				
				var scrollPos = FlowSystem.GetScrollPosition();
				if (scrollPos.x > 0f || scrollPos.y > 0f) scrollPos = -new Vector2(this.contentRect.width * 0.5f - this.scrollRect.width * 0.5f, this.contentRect.height * 0.5f - this.scrollRect.height * 0.5f);
				//FlowSystem.SetScrollPosition(GUI.BeginScrollView(this.scrollRect, scrollPos, this.contentRect));
				{

					//this.zoomDrawer.SetZoom(FlowSystem.GetZoom());
					//FlowSystem.SetScrollPosition(this.zoomDrawer.SetRect(this.scrollRect, scrollPos));
					//FlowSystem.SetZoom(this.zoomDrawer.GetZoom());
					//FlowSystem.SetScrollPosition(this.zoomDrawer.GetOrigin());

					this.zoomDrawer.SetZoom(FlowSystem.GetZoom());
					FlowSystem.SetScrollPosition(this.zoomDrawer.Begin(this.scrollRect, scrollPos, this.contentRect));
					FlowSystem.SetZoom(this.zoomDrawer.GetZoom());
					{

						this.DrawBackground();

						if (hasData == true && windows != null) {
							
							this.tempAttaches.Clear();
							foreach (var window in windows) {

								var attaches = window.attachItems;
								foreach (var attachItem in attaches) {

									var attachId = attachItem.targetId;

									var curWindow = FlowSystem.GetWindow(attachId);
									if (curWindow.IsContainer() == true &&
									    curWindow.IsFunction() == false) continue;
									
									//if (this.IsVisible(window) == false) continue;

									if (curWindow.IsFunction() == true &&
									    curWindow.IsContainer() == true) {
										
										if (curWindow.functionRootId == window.id) {
											
											// Find entrance window
											var rootWindow = FlowSystem.GetWindow(curWindow.functionRootId);
											if (rootWindow != null) {
												
												// Draw entrance point
												this.guiDrawer.DrawNodeCurve(new Vector3(curWindow.rect.x + 6f, curWindow.rect.y + curWindow.rect.height * 0.5f + 25f, -10f),
												                   			 new Vector3(rootWindow.rect.x + rootWindow.rect.width * 0.5f, rootWindow.rect.y + rootWindow.rect.height * 0.5f, -10f),
												                   			 Color.yellow);
												
											}
											
										}
										
										if (curWindow.functionExitId == window.id) {
											
											// Draw exit point
											var exitWindow = FlowSystem.GetWindow(curWindow.functionExitId);
											if (exitWindow != null) {
												
												// Draw entrance point
												this.guiDrawer.DrawNodeCurve(new Vector3(exitWindow.rect.x + exitWindow.rect.width * 0.5f, exitWindow.rect.y + exitWindow.rect.height * 0.5f, -10f),
												                   			 new Vector3(curWindow.rect.x + curWindow.rect.width - 6f, curWindow.rect.y + curWindow.rect.height * 0.5f + 25f, -10f),
												                  			 Color.green);
												
											}
											
										}
										
									} else {
										
										var doubleSided = FlowSystem.AlreadyAttached(attachId, window.id);
										if (this.tempAttaches.Contains(attachId) == true && doubleSided == true) continue;
										
										this.guiDrawer.DrawNodeCurve(window, curWindow, doubleSided);

										// Draw Transition Chooser
										this.DrawTransitionChooser(attachItem, window, curWindow, doubleSided);

									}
									
								}
								
								this.tempAttaches.Add(window.id);
								
							}
							
							var oldColor = GUI.backgroundColor;
							
							this.bringFront.Clear();
							
							var selectionMain = -1;
							var selected = FlowSystem.GetSelected();
							
							this.BeginWindows();
							
							var containerPadding = new Vector4(50f, 100f, 50f, 50f);
							foreach (var container in containers) {
								
								if (this.IsVisible(container) == false) continue;

								var backColor = container.randomColor;
								backColor.a = 0.3f;
								GUI.backgroundColor = backColor;
								
								var rootContainer = container.GetContainer();
								if (rootContainer != null) {
									
									// If container has other container
									
								}
								
								var attaches = container.attachItems;
								if (attaches.Count == 0) {
									
									container.rect.width = 200f;
									container.rect.height = 200f;
									
								} else {
									
									var minX = float.MaxValue;
									var minY = float.MaxValue;
									var maxX = float.MinValue;
									var maxY = float.MinValue;
									foreach (var attachItem in attaches) {

										var attachId = attachItem.targetId;
										var window = FlowSystem.GetWindow(attachId);
										
										minX = Mathf.Min(minX, window.rect.xMin);
										minY = Mathf.Min(minY, window.rect.yMin);
										maxX = Mathf.Max(maxX, window.rect.xMax);
										maxY = Mathf.Max(maxY, window.rect.yMax);
										
									}
									
									container.rect.xMin = minX - containerPadding.x;
									container.rect.yMin = minY - containerPadding.y;
									container.rect.xMax = maxX + containerPadding.z;
									container.rect.yMax = maxY + containerPadding.w;
									
								}
								
								var style = container.GetEditorStyle(false);
								
								var rect = GUI.Window(container.id, container.rect, this.DrawNodeContainer, container.title, style);
								this.BringBackOrFront(container, containers);
								
								if (selectionMain == -1 || selectionMain == container.id) {
									
									var isMoving = (rect != container.rect);
									var newRect = FlowSystem.Grid(rect);
									if (newRect != container.rect && isMoving == true) {
										
										if (selected.Count > 0 && selected.Contains(container.id) == false) {
											
											// nothing to do
											
										} else {
											
											var delta = new Vector2(newRect.x - container.rect.x, newRect.y - container.rect.y);
											if (delta != Vector2.zero) {
												
												selected.Clear();
												if (selected.Contains(container.id) == false) selected.Add(container.id);
												
												container.rect = newRect;
												
												FlowSystem.MoveContainerOrWindow(container.id, delta);
												
												selectionMain = container.id;
												
											}
											
										}
										
									}
									
								}
								
							}
							GUI.backgroundColor = oldColor;
							
							foreach (var window in windows) {

								if (this.IsVisible(window) == false) continue;

								var title = string.Empty;
								if (window.IsSmall() == true) {
									
									title = window.title;
									
								} else {
									
									var size = this.GetWindowSize(window);
									
									window.rect.width = size.x;
									window.rect.height = size.y;
									
								}
								
								var isSelected = selected.Contains(window.id) || (selected.Count == 0 && this.focusedGUIWindow == window.id);
								var style = window.GetEditorStyle(isSelected);
								
								var rect = GUI.Window(window.id, window.rect, this.DrawNodeWindow, title, style);
								GUI.BringWindowToFront(window.id);

								GUI.Window(-window.id, new Rect(rect.x, rect.y + rect.height, rect.width, this.GetTagsHeight(window)), (id) => {

									this.DrawTags(FlowSystem.GetWindow(-id), true);

								}, string.Empty, GUIStyle.none);
								GUI.BringWindowToFront(-window.id);

								var isMoving = (rect != window.rect);
								
								if (selectionMain == -1 || selectionMain == window.id) {
									
									var newRect = FlowSystem.Grid(rect);
									if (newRect != window.rect && isMoving == true) {
										
										// If selected contains
										if (selected.Count > 0 && selected.Contains(window.id) == false) {
											
											// nothing to do
											
										} else {
											
											var delta = new Vector2(newRect.x - window.rect.x, newRect.y - window.rect.y);
											if (delta != Vector2.zero) {
												
												window.rect = newRect;
												
												// Move all selected windows
												foreach (var selectedId in selected) {
													
													if (selectedId != window.id) {
														
														FlowSystem.GetWindow(selectedId).Move(delta);
														
													}
													
												}
												
												selectionMain = window.id;
												
											}
											
										}
										
									}
									
								}
								
							}
							
							this.EndWindows();
							
							var defaultColor = GUI.color;
							//var selectedColor = new Color(0.8f, 0.8f, 1f, 1f);
							
							if (selectionMain >= 0 && FlowSystem.GetWindow(selectionMain).IsContainer() == true) FlowSystem.ResetSelection();
							
							GUI.color = defaultColor;
							
							FlowSystem.Save();
							
						}
						
						if (FlowSystem.GetZoom() >= 0.3f) {

							if (FlowSystem.GetData() != null && FlowSystem.GetData().flowWindowWithLayout == true) {
								
								foreach (var window in windows) {

									if (this.IsVisible(window) == false) continue;

									var components = window.attachedComponents;
									for (int i = 0; i < components.Count; ++i) {
										
										var component = components[i];
										this.guiDrawer.DrawComponentCurve(window, ref component, FlowSystem.GetWindow (component.targetWindowId));
										components[i] = component;
										
									}
									
								}
								
							}

						}

					}
					this.zoomDrawer.End();

				}
				//GUI.EndScrollView();

				this.DrawWaitForConnection();
				this.DrawTagsPopup();
				this.HandleEvents(TOOLBAR_HEIGHT);
				
				GUI.enabled = true;
				
				if (this.scrollingMouseAnimation != null && this.scrollingMouseAnimation.isAnimating == true || this.scrollingMouse == true) this.DrawMinimap();
				
			}
			
		}
		public override void Update() {
			
			if (FlowSystemEditorWindow.loading == true) {
				
				return;
				
			}
			
			if (FlowSystemEditorWindow.loaded == false) {
				
				FlowSystemEditorWindow.loading = true;
				
				EditorApplication.delayCall += () => {
					
					if (this.guiDrawer == null) this.guiDrawer = new GUIDrawer(this);
					if (this.guiSplash == null) this.guiSplash = new FlowSplash(this);

					// Cache
					ME.EditorUtilities.GetAssetsOfType<FlowData>();
					ME.EditorUtilities.GetPrefabsOfType<FlowWindowLayoutTemplate>();
					ME.EditorUtilities.GetPrefabsOfType<FlowLayoutWindowTypeTemplate>();
					ME.EditorUtilities.GetPrefabsOfType<WindowModule>(strongType: false);

					FlowSystemEditorWindow.loading = false;
					FlowSystemEditorWindow.loaded = true;
					
				};
				
				return;
				
			} else {
				
				CoreUtilities.LoadAddons();
				
			}
			
		}
 private void OnGUI()
 {
     GUIDrawer.DrawProperties(properties, drawer, new Rect(20, 10, 300, 20));
 }
 private void Start()
 {
     drawer = new GUIDrawer();
     drawer.onPropertyChanged += OnPropertyChanged;
     properties = Property.GetProperties(cube, PropertySourceType.FieldsAndProperties, true);
 }
 void OpenAsset(Material material)
 {
     m_GUI      = OnGUI_Material;
     m_Material = material;
 }
 void OpenAsset(ComputeShader compute)
 {
     m_GUI     = OnGUI_ComputeShader;
     m_Compute = compute;
 }
 void OpenAsset(Shader shader)
 {
     m_GUI    = OnGUI_Shader;
     m_Shader = shader;
 }
示例#13
0
        /// <summary>
        /// Draws properties in single line.
        /// </summary>
        /// <param name="pos"> The position. </param>
        /// <param name="props"> The properties. </param>
        /// <param name="weights"> The weight of each property. </param>
        /// <param name="draw"> The property drawer. </param>
        /// <exception cref="System.Exception">
        /// Unmatched number of properties and weight values.
        /// </exception>
        public static void DrawInline(Rect pos, SerializedProperty[] props, int[] weights, GUIDrawer draw = null)
        {
            if (props.Length != weights.Length)
            {
                throw new Exception("Unmatched number of properties and weight values.");
            }
            int sumWeights = weights.Sum();

            float unitWidth = pos.width / sumWeights;

            float[] widths = weights.Select(w => w * unitWidth).ToArray();
            draw = draw ?? EditorGUI.PropertyField;
            float posX = pos.x;

            // draw properties in single line
            for (int i = 0; i < props.Length; i++)
            {
                float height = EditorGUI.GetPropertyHeight(props[i]);

                draw(
                    new Rect(
                        posX,
                        pos.y + (pos.height - height) / 2,  // centered vertically
                        widths[i],
                        height),
                    props[i],
                    GUIContent.none);
                posX += widths[i];
            }
        }