public void ReadFromString(ref uint index, ref string[] nodeParams) { try { int count = Convert.ToInt32(nodeParams[index++]); for (int i = 0; i < count; i++) { string locationValue = nodeParams[index++]; // REMOVE THIS TEST AFTER A COUPLE OF VERSIONS (curr v1.5.6 r02) if (locationValue.Equals("Bellow")) { locationValue = "Below"; } UsePassLocation location = (UsePassLocation)Enum.Parse(typeof(UsePassLocation), locationValue); string name = nodeParams[index++]; UsePassItem newItem = ScriptableObject.CreateInstance <UsePassItem>(); newItem.hideFlags = HideFlags.HideAndDontSave; newItem.Location = location; newItem.Value = name; m_items.Add(newItem); } } catch (Exception e) { Debug.LogException(e); } }
void DrawButtons() { EditorGUILayout.Separator(); // Add keyword if (GUILayout.Button(string.Empty, UIUtils.PlusStyle, GUILayout.Width(ShaderKeywordButtonLayoutWidth))) { UsePassItem newItem = ScriptableObject.CreateInstance <UsePassItem>(); newItem.hideFlags = HideFlags.HideAndDontSave; m_items.Add(newItem); EditorGUI.FocusTextInControl(null); m_isDirty = true; } //Remove keyword if (GUILayout.Button(string.Empty, UIUtils.MinusStyle, GUILayout.Width(ShaderKeywordButtonLayoutWidth))) { if (m_items.Count > 0) { UsePassItem itemToDelete = m_items[m_items.Count - 1]; m_items.RemoveAt(m_items.Count - 1); ScriptableObject.DestroyImmediate(itemToDelete); EditorGUI.FocusTextInControl(null); } m_isDirty = true; } }
public void ReadFromString(ref uint index, ref string[] nodeParams) { try { int count = Convert.ToInt32(nodeParams[index++]); for (int i = 0; i < count; i++) { UsePassLocation location = (UsePassLocation)Enum.Parse(typeof(UsePassLocation), nodeParams[index++]); string name = nodeParams[index++]; UsePassItem newItem = ScriptableObject.CreateInstance <UsePassItem>(); newItem.hideFlags = HideFlags.HideAndDontSave; newItem.Location = location; newItem.Value = name; m_items.Add(newItem); } } catch (Exception e) { Debug.LogException(e); } }
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; }