Ejemplo n.º 1
0
        private void VTAddCallbacks(VirtualTextureShaderProperty property)
        {
            // Draw Header
            m_VTReorderableList.drawHeaderCallback = (Rect rect) =>
            {
                int indent      = 14;
                var displayRect = new Rect(rect.x + indent, rect.y, (rect.width - indent) / 3, rect.height);
                EditorGUI.LabelField(displayRect, "Display Name");
                var referenceRect = new Rect((rect.x) + (rect.width - indent) / 3, rect.y, (rect.width - indent) / 3, rect.height);
                EditorGUI.LabelField(referenceRect, "Reference Name");
                var textureRect = new Rect((rect.x) + (rect.width - indent) / 3 * 2, rect.y, (rect.width - indent) / 3, rect.height);
                EditorGUI.LabelField(textureRect, "Texture Asset");
            };

            // Draw Element
            m_VTReorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                SerializableVirtualTextureLayer entry = ((SerializableVirtualTextureLayer)m_VTReorderableList.list[index]);
                EditorGUI.BeginChangeCheck();

                var layerName      = EditorGUI.DelayedTextField(new Rect(rect.x, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerName, EditorStyles.label);
                var layerRefName   = EditorGUI.DelayedTextField(new Rect((rect.x + rect.width) / 3, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerRefName, EditorStyles.label);
                var selectedObject = EditorGUI.ObjectField(new Rect((rect.x + rect.width) / 3 * 2, rect.y, rect.width / 3, EditorGUIUtility.singleLineHeight), entry.layerTexture.texture, typeof(Texture), false);

                SerializableTexture layerTexture = new SerializableTexture();
                layerTexture.texture = (Texture)selectedObject;

                if (EditorGUI.EndChangeCheck())
                {
                    //need to sanitize each layer with all existing properties
                    string oldLayerName = property.value.layers[index].layerName;
                    if (layerName != oldLayerName)
                    {
                        var otherPropertyNames = graphData.BuildPropertyDisplayNameList(property, oldLayerName);
                        layerName = GraphUtil.SanitizeName(otherPropertyNames, "{0} ({1})", layerName);
                    }

                    string oldLayerRefName = property.value.layers[index].layerRefName;
                    if (layerRefName != oldLayerRefName)
                    {
                        if (!string.IsNullOrEmpty(layerRefName))
                        {
                            string name = layerRefName.Trim();
                            if (!string.IsNullOrEmpty(layerRefName))
                            {
                                if (Regex.IsMatch(name, @"^\d+"))
                                {
                                    name = "_" + name;
                                }
                                name = Regex.Replace(name, @"(?:[^A-Za-z_0-9])|(?:\s)", "_");
                                var otherPropertyRefNames = graphData.BuildPropertyReferenceNameList(property, oldLayerRefName);
                                layerRefName = GraphUtil.SanitizeName(otherPropertyRefNames, "{0}_{1}", name);
                            }
                        }
                    }

                    property.value.layers[index] = new SerializableVirtualTextureLayer(layerName, layerRefName, layerTexture);

                    //DirtyNodes();
                    this._postChangeValueCallback(true);
                }
            };

            // Element height
            m_VTReorderableList.elementHeightCallback = (int indexer) =>
            {
                return(m_VTReorderableList.elementHeight);
            };

            // Can add
            m_VTReorderableList.onCanAddCallback = (ReorderableList list) =>
            {
                return(list.count < 4);
            };

            // Can remove
            m_VTReorderableList.onCanRemoveCallback = (ReorderableList list) =>
            {
                return(list.count > 1);
            };

            void AddEntryLamda(ReorderableList list) => VTAddEntry(list, property);
            void RemoveEntryLamda(ReorderableList list) => VTRemoveEntry(list, property);

            // Add callback delegates
            m_VTReorderableList.onSelectCallback  += VTSelectEntry;
            m_VTReorderableList.onAddCallback     += AddEntryLamda;
            m_VTReorderableList.onRemoveCallback  += RemoveEntryLamda;
            m_VTReorderableList.onReorderCallback += VTReorderEntries;
        }