void UpdateApplyToSortingLayersArray(object layerSelectionDataObject) { LayerSelectionData layerSelectionData = (LayerSelectionData)layerSelectionDataObject; m_ApplyToSortingLayers.ClearArray(); for (int i = 0; i < m_ApplyToSortingLayersList.Count; ++i) { m_ApplyToSortingLayers.InsertArrayElementAtIndex(i); m_ApplyToSortingLayers.GetArrayElementAtIndex(i).intValue = m_ApplyToSortingLayersList[i]; } //AnalyticsTrackChanges(updateSelectionData.serializedObject); layerSelectionData.serializedObject.ApplyModifiedProperties(); if (layerSelectionData.targets is Light2D[]) { foreach (Light2D light in layerSelectionData.targets) { if (light != null && light.lightType == Light2D.LightType.Global) { light.ErrorIfDuplicateGlobalLight(); } } } }
public void OnTargetSortingLayers(SerializedObject serializedObject, Object[] targets, GUIContent labelContent, System.Action <SerializedObject> selectionChangedCallback) { Rect totalPosition = EditorGUILayout.GetControlRect(); GUIContent actualLabel = EditorGUI.BeginProperty(totalPosition, labelContent, m_ApplyToSortingLayers); Rect position = EditorGUI.PrefixLabel(totalPosition, actualLabel); m_ApplyToSortingLayersList.Clear(); int applyToSortingLayersSize = m_ApplyToSortingLayers.arraySize; for (int i = 0; i < applyToSortingLayersSize; ++i) { int layerID = m_ApplyToSortingLayers.GetArrayElementAtIndex(i).intValue; if (SortingLayer.IsValid(layerID)) { m_ApplyToSortingLayersList.Add(layerID); } } GUIContent selectedLayers; if (m_ApplyToSortingLayersList.Count == 1) { selectedLayers = new GUIContent(SortingLayer.IDToName(m_ApplyToSortingLayersList[0])); } else if (m_ApplyToSortingLayersList.Count == m_AllSortingLayers.Length) { selectedLayers = Styles.sortingLayerAll; } else if (m_ApplyToSortingLayersList.Count == 0) { selectedLayers = Styles.sortingLayerNone; } else { selectedLayers = Styles.sortingLayerMixed; } if (EditorGUI.DropdownButton(position, selectedLayers, FocusType.Keyboard, EditorStyles.popup)) { GenericMenu menu = new GenericMenu(); menu.allowDuplicateNames = true; LayerSelectionData layerSelectionData = new LayerSelectionData(serializedObject, 0, targets, selectionChangedCallback); menu.AddItem(Styles.sortingLayerNone, m_ApplyToSortingLayersList.Count == 0, OnNoSortingLayerSelected, layerSelectionData); menu.AddItem(Styles.sortingLayerAll, m_ApplyToSortingLayersList.Count == m_AllSortingLayers.Length, OnAllSortingLayersSelected, layerSelectionData); menu.AddSeparator(""); for (int i = 0; i < m_AllSortingLayers.Length; ++i) { var sortingLayer = m_AllSortingLayers[i]; layerSelectionData = new LayerSelectionData(serializedObject, sortingLayer.id, targets, selectionChangedCallback); menu.AddItem(m_AllSortingLayerNames[i], m_ApplyToSortingLayersList.Contains(sortingLayer.id), OnSortingLayerSelected, layerSelectionData); } menu.DropDown(position); } EditorGUI.EndProperty(); }
public void OnTargetSortingLayers(SerializedObject serializedObject, Object[] targets, GUIContent labelContent) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(labelContent); GUIContent selectedLayers; if (m_ApplyToSortingLayersList.Count == 1) { selectedLayers = new GUIContent(SortingLayer.IDToName(m_ApplyToSortingLayersList[0])); } else if (m_ApplyToSortingLayersList.Count == m_AllSortingLayers.Length) { selectedLayers = Styles.sortingLayerAll; } else if (m_ApplyToSortingLayersList.Count == 0) { selectedLayers = Styles.sortingLayerNone; } else { selectedLayers = Styles.sortingLayerMixed; } bool buttonDown = EditorGUILayout.DropdownButton(selectedLayers, FocusType.Keyboard, EditorStyles.popup); if (Event.current.type == EventType.Repaint) { m_SortingLayerDropdownRect = GUILayoutUtility.GetLastRect(); } if (buttonDown) { GenericMenu menu = new GenericMenu(); menu.allowDuplicateNames = true; LayerSelectionData layerSelectionData = new LayerSelectionData(serializedObject, 0, targets); menu.AddItem(Styles.sortingLayerNone, m_ApplyToSortingLayersList.Count == 0, OnNoSortingLayerSelected, layerSelectionData); menu.AddItem(Styles.sortingLayerAll, m_ApplyToSortingLayersList.Count == m_AllSortingLayers.Length, OnAllSortingLayersSelected, layerSelectionData); menu.AddSeparator(""); for (int i = 0; i < m_AllSortingLayers.Length; ++i) { var sortingLayer = m_AllSortingLayers[i]; layerSelectionData = new LayerSelectionData(serializedObject, sortingLayer.id, targets); menu.AddItem(m_AllSortingLayerNames[i], m_ApplyToSortingLayersList.Contains(sortingLayer.id), OnSortingLayerSelected, layerSelectionData); } menu.DropDown(m_SortingLayerDropdownRect); } EditorGUILayout.EndHorizontal(); }
void OnSortingLayerSelected(object layerSelectionDataObject) { LayerSelectionData layerSelectionData = (LayerSelectionData)layerSelectionDataObject; int layerID = (int)layerSelectionData.layerID; if (m_ApplyToSortingLayersList.Contains(layerID)) { m_ApplyToSortingLayersList.RemoveAll(id => id == layerID); } else { m_ApplyToSortingLayersList.Add(layerID); } UpdateApplyToSortingLayersArray(layerSelectionDataObject); }