public System.Enum DrawWidget(UndoParentNode owner, System.Enum selectedIndex) { if (m_editing) { EditorGUI.BeginChangeCheck(); System.Enum newValue = owner.EditorGUIEnumPopup(m_varRect, selectedIndex, UIUtils.PropertyPopUp); if (EditorGUI.EndChangeCheck()) { m_editing = false; } return(newValue); } return(selectedIndex); }
public override void Draw(UndoParentNode currOwner, bool style = true) { m_currOwner = currOwner; if (m_reordableList == null) { m_reordableList = new ReorderableList(m_additionalDirectives, typeof(AdditionalDirectiveContainer), true, false, false, false) { headerHeight = 0, footerHeight = 0, showDefaultBackground = false, elementHeightCallback = (index) => { if (m_additionalDirectives[index].Origin == AdditionalContainerOrigin.Native && m_nativeDirectivesFoldout) { return((m_nativeDirectives.Count + 1) * (EditorGUIUtility.singleLineHeight) + 5); } return(EditorGUIUtility.singleLineHeight + 5); }, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (m_additionalDirectives[index].Origin == AdditionalContainerOrigin.Native && m_nativeDirectivesFoldout) { rect.height = (m_nativeDirectives.Count + 1) * (EditorGUIUtility.singleLineHeight) + 5; } if (m_additionalDirectives[index] != null) { float labelWidthStyleAdjust = 0; if (style) { rect.xMin -= 10; labelWidthStyleAdjust = 15; } else { rect.xMin -= 1; } float popUpWidth = style ? 75 : 60f; float widthAdjust = m_additionalDirectives[index].LineType == AdditionalLineType.Include ? -14 : 0; Rect popupPos = new Rect(rect.x, rect.y, popUpWidth, EditorGUIUtility.singleLineHeight); Rect GUIDTogglePos = m_additionalDirectives[index].LineType == AdditionalLineType.Include ? new Rect(rect.x + rect.width - 3 * Constants.PlusMinusButtonLayoutWidth, rect.y, Constants.PlusMinusButtonLayoutWidth, Constants.PlusMinusButtonLayoutWidth) : new Rect(); Rect buttonPlusPos = new Rect(rect.x + rect.width - 2 * Constants.PlusMinusButtonLayoutWidth, rect.y - 2, Constants.PlusMinusButtonLayoutWidth, Constants.PlusMinusButtonLayoutWidth); Rect buttonMinusPos = new Rect(rect.x + rect.width - Constants.PlusMinusButtonLayoutWidth, rect.y - 2, Constants.PlusMinusButtonLayoutWidth, Constants.PlusMinusButtonLayoutWidth); float labelWidthBuffer = EditorGUIUtility.labelWidth; Rect labelPos = new Rect(rect.x + popupPos.width - labelWidthStyleAdjust, rect.y, labelWidthStyleAdjust + rect.width - popupPos.width - buttonPlusPos.width - buttonMinusPos.width + widthAdjust, EditorGUIUtility.singleLineHeight); if (m_additionalDirectives[index].Origin == AdditionalContainerOrigin.Native) { m_nativeRect = rect; m_nativeRect.xMin += 2; m_nativeRect.xMax -= 2; m_nativeRect.yMax -= 2; #if UNITY_2019_3_OR_NEWER EditorGUI.LabelField(m_nativeRect, NativeFoldoutStr); #else NodeUtils.DrawNestedPropertyGroup(ref m_nativeDirectivesFoldout, rect, NativeFoldoutStr, DrawNativeItemsRect, 4); #endif return; } m_additionalDirectives[index].LineType = (AdditionalLineType)m_currOwner.EditorGUIEnumPopup(popupPos, m_additionalDirectives[index].LineType); if (m_additionalDirectives[index].LineType == AdditionalLineType.Include) { if (m_additionalDirectives[index].GUIDToggle) { //if( m_additionalDirectives[ index ].LibObject == null && !string.IsNullOrEmpty( m_additionalDirectives[ index ].GUIDValue ) ) //{ // m_additionalDirectives[ index ].LibObject = AssetDatabase.LoadAssetAtPath<TextAsset>( AssetDatabase.GUIDToAssetPath( m_additionalDirectives[ index ].GUIDValue ) ); //} EditorGUI.BeginChangeCheck(); TextAsset obj = m_currOwner.EditorGUIObjectField(labelPos, m_additionalDirectives[index].LibObject, typeof(TextAsset), false) as TextAsset; if (EditorGUI.EndChangeCheck()) { string pathName = AssetDatabase.GetAssetPath(obj); string extension = Path.GetExtension(pathName); extension = extension.ToLower(); if (extension.Equals(".cginc") || extension.Equals(".hlsl")) { m_additionalDirectives[index].LibObject = obj; m_additionalDirectives[index].GUIDValue = AssetDatabase.AssetPathToGUID(pathName); } } } else { m_additionalDirectives[index].LineValue = m_currOwner.EditorGUITextField(labelPos, string.Empty, m_additionalDirectives[index].LineValue); } if (GUI.Button(GUIDTogglePos, m_additionalDirectives[index].GUIDToggle ? UIUtils.FloatIntIconOFF : UIUtils.FloatIntIconON, UIUtils.FloatIntPickerONOFF)) { m_additionalDirectives[index].GUIDToggle = !m_additionalDirectives[index].GUIDToggle; } } else { m_additionalDirectives[index].LineValue = m_currOwner.EditorGUITextField(labelPos, string.Empty, m_additionalDirectives[index].LineValue); } if (GUI.Button(buttonPlusPos, string.Empty, UIUtils.PlusStyle)) { m_actionType = ReordableAction.Add; m_actionIndex = index; } if (GUI.Button(buttonMinusPos, string.Empty, UIUtils.MinusStyle)) { m_actionType = ReordableAction.Remove; m_actionIndex = index; } } }, onReorderCallback = ( ReorderableList list ) => { UpdateNativeIndex(); } }; } if (m_actionType != ReordableAction.None) { switch (m_actionType) { case ReordableAction.Add: { AdditionalDirectiveContainer newItem = ScriptableObject.CreateInstance <AdditionalDirectiveContainer>(); newItem.hideFlags = HideFlags.HideAndDontSave; m_additionalDirectives.Insert(m_actionIndex + 1, newItem); } break; case ReordableAction.Remove: AdditionalDirectiveContainer itemToDelete = m_additionalDirectives[m_actionIndex]; m_additionalDirectives.RemoveAt(m_actionIndex); ScriptableObject.DestroyImmediate(itemToDelete); break; } m_isDirty = true; m_actionType = ReordableAction.None; EditorGUI.FocusTextInControl(null); } bool foldoutValue = currOwner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalDirectives; if (style) { NodeUtils.DrawPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } else { NodeUtils.DrawNestedPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } currOwner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalDirectives = foldoutValue; }
public void Draw(UndoParentNode owner, bool style = true) { if (m_owner == null) { m_owner = owner; } if (m_reordableList == null) { m_reordableList = new ReorderableList(m_items, typeof(UsePassItem), true, false, false, false) { headerHeight = 0, footerHeight = 0, showDefaultBackground = false, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (m_items[index] != null) { float labelWidthMultiplier; float popUpWidth; float shaderSelectorMultiplier; float buttonPlusPosMultiplier; if (style) { rect.x -= 10; labelWidthMultiplier = 0.9f; popUpWidth = 0.31f; shaderSelectorMultiplier = 1.01f; buttonPlusPosMultiplier = 0.78f; } else { rect.x -= 1; labelWidthMultiplier = 1.01f; popUpWidth = 0.25f; shaderSelectorMultiplier = 1.0f; buttonPlusPosMultiplier = 0.55f; } Rect popupPos = new Rect(rect.x, rect.y + 2, popUpWidth * rect.width, rect.height); Rect labelPos = new Rect(rect.x + popupPos.width * labelWidthMultiplier, rect.y, 0.59f * rect.width, rect.height); Rect shaderSelectorPos = new Rect(labelPos.x + labelPos.width * shaderSelectorMultiplier, rect.y, 15, rect.height); Rect buttonPlusPos = new Rect(shaderSelectorPos.x + shaderSelectorPos.width * buttonPlusPosMultiplier, rect.y, ShaderKeywordButtonLayoutWidth, rect.height); Rect buttonMinusPos = new Rect(buttonPlusPos.x + buttonPlusPos.width, rect.y, ShaderKeywordButtonLayoutWidth, rect.height); EditorGUI.BeginChangeCheck(); m_items[index].Location = (UsePassLocation)owner.EditorGUIEnumPopup(popupPos, m_items[index].Location); if (EditorGUI.EndChangeCheck() && m_items[index].Location == UsePassLocation.Below && m_owner != null && m_owner.ContainerGraph.CurrentCanvasMode == NodeAvailability.TemplateShader) { m_items[index].Location = UsePassLocation.Above; UIUtils.ShowMessage("Below option still not available on templates"); } m_items[index].Value = owner.EditorGUITextField(labelPos, string.Empty, m_items[index].Value); if (GUI.Button(shaderSelectorPos, string.Empty, UIUtils.InspectorPopdropdownFallback)) { EditorGUI.FocusTextInControl(null); GUI.FocusControl(null); m_currentUsePassIdx = index; DisplayShaderContext(owner, GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.popup)); } if (GUI.Button(buttonPlusPos, string.Empty, UIUtils.PlusStyle)) { m_actionType = ReordableAction.Add; m_actionIndex = index; } if (GUI.Button(buttonMinusPos, string.Empty, UIUtils.MinusStyle)) { m_actionType = ReordableAction.Remove; m_actionIndex = index; } } } }; } if (m_actionType != ReordableAction.None) { switch (m_actionType) { case ReordableAction.Add: UsePassItem newItem = ScriptableObject.CreateInstance <UsePassItem>(); newItem.hideFlags = HideFlags.HideAndDontSave; m_items.Insert(m_actionIndex + 1, newItem); break; case ReordableAction.Remove: UsePassItem itemToDelete = m_items[m_actionIndex]; m_items.RemoveAt(m_actionIndex); ScriptableObject.DestroyImmediate(itemToDelete); break; } m_isDirty = true; m_actionType = ReordableAction.None; EditorGUI.FocusTextInControl(null); } bool foldoutValue = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedUsePass; if (style) { NodeUtils.DrawPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } else { NodeUtils.DrawNestedPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedUsePass = foldoutValue; }
public override void Draw(UndoParentNode owner, bool style = true) { if (m_reordableList == null) { m_reordableList = new ReorderableList(m_additionalDirectives, typeof(AdditionalDirectiveContainer), true, false, false, false) { headerHeight = 0, footerHeight = 0, showDefaultBackground = false, drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { if (m_additionalDirectives[index] != null) { if (style) { rect.xMin -= 10; } else { rect.xMin -= 1; } float popUpWidth = style?75:65f; Rect popupPos = new Rect(rect.x, rect.y, popUpWidth, EditorGUIUtility.singleLineHeight); Rect buttonPlusPos = new Rect(rect.x + rect.width - 2 * Constants.PlusMinusButtonLayoutWidth, rect.y - 2, Constants.PlusMinusButtonLayoutWidth, Constants.PlusMinusButtonLayoutWidth); Rect buttonMinusPos = new Rect(rect.x + rect.width - Constants.PlusMinusButtonLayoutWidth, rect.y - 2, Constants.PlusMinusButtonLayoutWidth, Constants.PlusMinusButtonLayoutWidth); Rect labelPos = new Rect(rect.x + popupPos.width, rect.y, rect.width - popupPos.width - buttonPlusPos.width - buttonMinusPos.width, rect.height); labelPos.height = EditorGUIUtility.singleLineHeight; m_additionalDirectives[index].LineType = (AdditionalLineType)owner.EditorGUIEnumPopup(popupPos, m_additionalDirectives[index].LineType); m_additionalDirectives[index].LineValue = owner.EditorGUITextField(labelPos, string.Empty, m_additionalDirectives[index].LineValue); if (GUI.Button(buttonPlusPos, string.Empty, UIUtils.PlusStyle)) { m_actionType = ReordableAction.Add; m_actionIndex = index; } if (GUI.Button(buttonMinusPos, string.Empty, UIUtils.MinusStyle)) { m_actionType = ReordableAction.Remove; m_actionIndex = index; } } } }; } if (m_actionType != ReordableAction.None) { switch (m_actionType) { case ReordableAction.Add: AdditionalDirectiveContainer newItem = ScriptableObject.CreateInstance <AdditionalDirectiveContainer>(); newItem.hideFlags = HideFlags.HideAndDontSave; m_additionalDirectives.Insert(m_actionIndex + 1, newItem); break; case ReordableAction.Remove: AdditionalDirectiveContainer itemToDelete = m_additionalDirectives[m_actionIndex]; m_additionalDirectives.RemoveAt(m_actionIndex); ScriptableObject.DestroyImmediate(itemToDelete); break; } m_isDirty = true; m_actionType = ReordableAction.None; EditorGUI.FocusTextInControl(null); } bool foldoutValue = owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalDirectives; if (style) { NodeUtils.DrawPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } else { NodeUtils.DrawNestedPropertyGroup(ref foldoutValue, m_moduleName, DrawReordableList, DrawButtons); } owner.ContainerGraph.ParentWindow.InnerWindowVariables.ExpandedAdditionalDirectives = foldoutValue; }