GetMaterialRawRenderQueue() private method

private GetMaterialRawRenderQueue ( Material mat ) : int
mat UnityEngine.Material
return int
        // Do currently edited materials have different render queue values?
        private bool HasMultipleMixedQueueValues()
        {
            int queue = ShaderUtil.GetMaterialRawRenderQueue(targets[0] as Material);

            for (int i = 1; i < targets.Length; ++i)
            {
                if (queue != ShaderUtil.GetMaterialRawRenderQueue(targets[i] as Material))
                {
                    return(true);
                }
            }
            return(false);
        }
        // Field for editing render queue value, with an explicit rect
        public void RenderQueueField(Rect r)
        {
            var mixedValue = HasMultipleMixedQueueValues();

            EditorGUI.showMixedValue = mixedValue;

            var mat             = targets[0] as Material;
            int curRawQueue     = ShaderUtil.GetMaterialRawRenderQueue(mat);
            int curDisplayQueue = mat.renderQueue; // this gets final queue value used for rendering, taking shader's queue into account

            // Figure out if we're using one of common queues, or a custom one
            GUIContent[] queueNames  = null;
            int[]        queueValues = null;
            float        labelWidth;
            // If we use queue value that is not available, lets switch to the custom one
            bool useCustomQueue = Array.IndexOf(Styles.queueValues, curRawQueue) < 0;

            if (useCustomQueue)
            {
                // It is a big chance that we already have this custom queue value available
                bool updateNewCustomQueueValue = Array.IndexOf(Styles.customQueueNames, curRawQueue) < 0;
                if (updateNewCustomQueueValue)
                {
                    int    targetQueueIndex         = CalculateClosestQueueIndexToValue(curRawQueue);
                    string targetQueueName          = Styles.queueNames[targetQueueIndex].text;
                    int    targetQueueValueOverflow = curRawQueue - Styles.queueValues[targetQueueIndex];

                    string newQueueName = string.Format(
                        targetQueueValueOverflow > 0 ? "{0}+{1}" : "{0}{1}",
                        targetQueueName,
                        targetQueueValueOverflow);
                    Styles.customQueueNames[Styles.kCustomQueueIndex].text = newQueueName;
                    Styles.customQueueValues[Styles.kCustomQueueIndex]     = curRawQueue;
                }

                queueNames  = Styles.customQueueNames;
                queueValues = Styles.customQueueValues;
                labelWidth  = kCustomQueuePopupWidth;
            }
            else
            {
                queueNames  = Styles.queueNames;
                queueValues = Styles.queueValues;
                labelWidth  = kQueuePopupWidth;
            }

            // We want the custom queue number field to line up with thumbnails & other value fields
            // (on the right side), and common queues popup to be on the left of that.
            float oldLabelWidth = EditorGUIUtility.labelWidth;
            float oldFieldWidth = EditorGUIUtility.fieldWidth;

            SetDefaultGUIWidths();
            EditorGUIUtility.labelWidth -= labelWidth;
            Rect popupRect = r;

            popupRect.width -= EditorGUIUtility.fieldWidth + 2;
            Rect numberRect = r;

            numberRect.xMin = numberRect.xMax - EditorGUIUtility.fieldWidth;

            // Queues popup
            int curPopupValue = curRawQueue;
            int newPopupValue = EditorGUI.IntPopup(popupRect, Styles.queueLabel, curRawQueue, queueNames, queueValues);

            // Custom queue field
            int newDisplayQueue = EditorGUI.DelayedIntField(numberRect, curDisplayQueue);

            // If popup or custom field changed, set the new queue
            if (curPopupValue != newPopupValue || curDisplayQueue != newDisplayQueue)
            {
                RegisterPropertyChangeUndo("Render Queue");
                // Take the value from the number field,
                int newQueue = newDisplayQueue;
                // But if it's the popup that was changed
                if (newPopupValue != curPopupValue)
                {
                    newQueue = newPopupValue;
                }
                newQueue = Mathf.Clamp(newQueue, -1, 5000); // clamp to valid queue ranges
                // Change the material queues
                foreach (var m in targets)
                {
                    ((Material)m).renderQueue = newQueue;
                }
            }

            EditorGUIUtility.labelWidth = oldLabelWidth;
            EditorGUIUtility.fieldWidth = oldFieldWidth;
            EditorGUI.showMixedValue    = false;
        }