GetPropertyName() private method

private GetPropertyName ( Shader s, int propertyIdx ) : string
s UnityEngine.Shader
propertyIdx int
return string
        internal override bool HasModified()
        {
            if (base.HasModified())
            {
                return(true);
            }
            ShaderImporter shaderImporter = this.target as ShaderImporter;

            if (shaderImporter == null)
            {
                return(false);
            }
            Shader shader = shaderImporter.GetShader();

            if (shader == null)
            {
                return(false);
            }
            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (int i = 0; i < propertyCount; i++)
            {
                string propertyName = ShaderUtil.GetPropertyName(shader, i);
                for (int j = 0; j < this.propertyNames.Count; j++)
                {
                    if (this.propertyNames[j] == propertyName && this.textures[j] != shaderImporter.GetDefaultTexture(propertyName))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#2
0
        private static int GetMaterialPropertyPopupHash(UnityEngine.Object[] objects)
        {
            int hash = 0;

            foreach (VideoPlayer vp in objects)
            {
                if (!vp)
                {
                    continue;
                }
                Renderer renderer = GetTargetRenderer(vp);
                if (!renderer)
                {
                    continue;
                }

                hash ^= vp.targetMaterialProperty.GetHashCode();
                foreach (Material material in renderer.sharedMaterials)
                {
                    if (!material)
                    {
                        continue;
                    }
                    hash ^= material.name.GetHashCode();
                    for (int i = 0, e = ShaderUtil.GetPropertyCount(material.shader); i < e; ++i)
                    {
                        if (ShaderUtil.GetPropertyType(material.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            hash ^= ShaderUtil.GetPropertyName(material.shader, i).GetHashCode();
                        }
                    }
                }
            }
            return(hash);
        }
        internal override void ResetValues()
        {
            base.ResetValues();
            this.propertyNames = new List <string>();
            this.displayNames  = new List <string>();
            this.textures      = new List <Texture>();
            this.dimensions    = new List <TextureDimension>();
            ShaderImporter shaderImporter = this.target as ShaderImporter;

            if (shaderImporter == null)
            {
                return;
            }
            Shader shader = shaderImporter.GetShader();

            if (shader == null)
            {
                return;
            }
            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (int i = 0; i < propertyCount; i++)
            {
                if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    string  propertyName        = ShaderUtil.GetPropertyName(shader, i);
                    string  propertyDescription = ShaderUtil.GetPropertyDescription(shader, i);
                    Texture defaultTexture      = shaderImporter.GetDefaultTexture(propertyName);
                    this.propertyNames.Add(propertyName);
                    this.displayNames.Add(propertyDescription);
                    this.textures.Add(defaultTexture);
                    this.dimensions.Add(ShaderUtil.GetTexDim(shader, i));
                }
            }
        }
        internal override bool HasModified()
        {
            if (base.HasModified())
            {
                return(true);
            }
            ShaderImporter target = this.target as ShaderImporter;

            if ((UnityEngine.Object)target == (UnityEngine.Object)null)
            {
                return(false);
            }
            Shader shader = target.GetShader();

            if ((UnityEngine.Object)shader == (UnityEngine.Object)null)
            {
                return(false);
            }
            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (int propertyIdx = 0; propertyIdx < propertyCount; ++propertyIdx)
            {
                string propertyName = ShaderUtil.GetPropertyName(shader, propertyIdx);
                for (int index = 0; index < this.propertyNames.Count; ++index)
                {
                    if (this.propertyNames[index] == propertyName && (UnityEngine.Object) this.textures[index] != (UnityEngine.Object)target.GetDefaultTexture(propertyName))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        internal override void ResetValues()
        {
            base.ResetValues();
            this.propertyNames = new List <string>();
            this.displayNames  = new List <string>();
            this.textures      = new List <Texture>();
            this.dimensions    = new List <ShaderUtil.ShaderPropertyTexDim>();
            ShaderImporter target = this.target as ShaderImporter;

            if ((UnityEngine.Object)target == (UnityEngine.Object)null)
            {
                return;
            }
            Shader shader = target.GetShader();

            if ((UnityEngine.Object)shader == (UnityEngine.Object)null)
            {
                return;
            }
            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (int propertyIdx = 0; propertyIdx < propertyCount; ++propertyIdx)
            {
                if (ShaderUtil.GetPropertyType(shader, propertyIdx) == ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    string  propertyName        = ShaderUtil.GetPropertyName(shader, propertyIdx);
                    string  propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIdx);
                    Texture defaultTexture      = target.GetDefaultTexture(propertyName);
                    this.propertyNames.Add(propertyName);
                    this.displayNames.Add(propertyDescription);
                    this.textures.Add(defaultTexture);
                    this.dimensions.Add(ShaderUtil.GetTexDim(shader, propertyIdx));
                }
            }
        }
示例#6
0
        private string GenerateMultiMaterialinformation()
        {
            if (targets.Count() > 1)
            {
                return("");
            }

            VideoPlayer vp = target as VideoPlayer;

            if (!vp)
            {
                return("");
            }

            Renderer renderer = GetTargetRenderer(vp);

            if (!renderer)
            {
                return("");
            }

            var sharedMaterials = renderer.sharedMaterials;

            if (sharedMaterials == null || sharedMaterials.Count() <= 1)
            {
                return("");
            }

            var targetMaterials = new List <string>();

            foreach (Material material in sharedMaterials)
            {
                if (!material)
                {
                    continue;
                }
                for (int i = 0, e = ShaderUtil.GetPropertyCount(material.shader); i < e; ++i)
                {
                    if ((ShaderUtil.GetPropertyType(material.shader, i) ==
                         ShaderUtil.ShaderPropertyType.TexEnv) &&
                        (ShaderUtil.GetPropertyName(material.shader, i) ==
                         m_TargetMaterialProperty.stringValue))
                    {
                        targetMaterials.Add(material.name);
                        break;
                    }
                }
            }

            if (targetMaterials.Count() == sharedMaterials.Count())
            {
                return(s_Styles.texPropInAllMaterialsHelp);
            }

            return(string.Format(
                       s_Styles.texPropInSomeMaterialsHelp,
                       targetMaterials.Count(), sharedMaterials.Count()) + ": " +
                   string.Join(", ", targetMaterials.ToArray()));
        }
        public override void OnGUI(Rect position, SerializedProperty prop, GUIContent content)
        {
            var att = (ShaderPropertyPopupAttribute)attribute;

            var directable = prop.serializedObject.targetObject as IDirectable;

            if (directable != null)
            {
                var actor = directable.actor;
                if (actor != null)
                {
                    var renderer = actor.GetComponent <Renderer>();
                    if (renderer != null)
                    {
                        var material = renderer.sharedMaterial;
                        if (material != null)
                        {
                            var shader  = material.shader;
                            var options = new List <string>();
                            for (var i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
                            {
                                if (ShaderUtil.IsShaderPropertyHidden(shader, i))
                                {
                                    continue;
                                }

                                if (att.propertyType != null)
                                {
                                    var type = ShaderUtil.GetPropertyType(shader, i);
                                    if (att.propertyType == typeof(Color) && type != ShaderUtil.ShaderPropertyType.Color)
                                    {
                                        continue;
                                    }
                                    if (att.propertyType == typeof(Texture) && type != ShaderUtil.ShaderPropertyType.TexEnv)
                                    {
                                        continue;
                                    }
                                    if (att.propertyType == typeof(float) && type != ShaderUtil.ShaderPropertyType.Float && type != ShaderUtil.ShaderPropertyType.Range)
                                    {
                                        continue;
                                    }
                                    if ((att.propertyType == typeof(Vector2) || att.propertyType == typeof(Vector4)) && type != ShaderUtil.ShaderPropertyType.Vector)
                                    {
                                        continue;
                                    }
                                }

                                options.Add(ShaderUtil.GetPropertyName(shader, i));
                            }

                            prop.stringValue = EditorTools.CleanPopup <string>(content.text, prop.stringValue, options);
                            return;
                        }
                    }
                }
            }

            prop.stringValue = EditorGUILayout.TextField(content.text, prop.stringValue);
        }
示例#8
0
        private static List <string> GetMaterialPropertyNames(UnityEngine.Object obj, bool multiSelect, out int selection, out bool invalidSelection)
        {
            selection        = -1;
            invalidSelection = true;
            List <string> list        = new List <string>();
            VideoPlayer   videoPlayer = obj as VideoPlayer;
            List <string> result;

            if (!videoPlayer)
            {
                result = list;
            }
            else
            {
                Renderer targetRenderer = VideoPlayerEditor.GetTargetRenderer(videoPlayer);
                if (!targetRenderer)
                {
                    result = list;
                }
                else
                {
                    Material[] sharedMaterials = targetRenderer.sharedMaterials;
                    for (int i = 0; i < sharedMaterials.Length; i++)
                    {
                        Material material = sharedMaterials[i];
                        if (material)
                        {
                            int j             = 0;
                            int propertyCount = ShaderUtil.GetPropertyCount(material.shader);
                            while (j < propertyCount)
                            {
                                if (ShaderUtil.GetPropertyType(material.shader, j) == ShaderUtil.ShaderPropertyType.TexEnv)
                                {
                                    string propertyName = ShaderUtil.GetPropertyName(material.shader, j);
                                    if (!list.Contains(propertyName))
                                    {
                                        list.Add(propertyName);
                                    }
                                }
                                j++;
                            }
                            selection        = list.IndexOf(videoPlayer.targetMaterialProperty);
                            invalidSelection = (selection < 0 && list.Count <string>() > 0);
                            if (invalidSelection && !multiSelect)
                            {
                                selection = list.Count <string>();
                                list.Add(videoPlayer.targetMaterialProperty);
                            }
                        }
                    }
                    result = list;
                }
            }
            return(result);
        }
        protected override void ResetValues()
        {
            base.ResetValues();

            m_Properties.Clear();

            var importer = target as ShaderImporter;

            if (importer == null)
            {
                return;
            }

            var shader = importer.GetShader();

            if (shader == null)
            {
                return;
            }

            var propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (var i = 0; i < propertyCount; i++)
            {
                if (ShaderUtil.GetPropertyType(shader, i) != ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    continue;
                }

                var propertyName = ShaderUtil.GetPropertyName(shader, i);
                var displayName  = ShaderUtil.GetPropertyDescription(shader, i); // might be empty
                var modifiable   = !ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i);

                Texture tex;
                if (!modifiable)
                {
                    tex = importer.GetNonModifiableTexture(propertyName);
                }
                else
                {
                    tex = importer.GetDefaultTexture(propertyName);
                }

                var temp = new TextureProp
                {
                    propertyName = propertyName,
                    texture      = tex,
                    dimension    = ShaderUtil.GetTexDim(shader, i),
                    displayName  = displayName,
                    modifiable   = modifiable
                };
                m_Properties.Add(temp);
            }
        }
        protected override void InitializeExtraDataInstance(Object extraTarget, int targetIndex)
        {
            var data = (ShaderProperties)extraTarget;

            data.CleanUp();

            var importer = targets[targetIndex] as ShaderImporter;

            if (importer == null)
            {
                return;
            }

            var shader = importer.GetShader();

            if (shader == null)
            {
                return;
            }

            var propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (var i = 0; i < propertyCount; i++)
            {
                if (ShaderUtil.GetPropertyType(shader, i) != ShaderUtil.ShaderPropertyType.TexEnv)
                {
                    continue;
                }

                var propertyName = ShaderUtil.GetPropertyName(shader, i);
                var displayName  = ShaderUtil.GetPropertyDescription(shader, i); // might be empty
                var modifiable   = !ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i);

                Texture tex;
                if (!modifiable)
                {
                    tex = importer.GetNonModifiableTexture(propertyName);
                }
                else
                {
                    tex = importer.GetDefaultTexture(propertyName);
                }

                var temp = new TextureProp
                {
                    propertyName = propertyName,
                    texture      = tex,
                    dimension    = ShaderUtil.GetTexDim(shader, i),
                    displayName  = displayName,
                    modifiable   = modifiable
                };
                data.m_Properties.Add(temp);
            }
        }
示例#11
0
        private static void ShowShaderProperties(Shader s)
        {
            GUILayout.Space(5f);
            GUILayout.Label("Properties:", EditorStyles.boldLabel, new GUILayoutOption[0]);
            int propertyCount = ShaderUtil.GetPropertyCount(s);

            for (int index = 0; index < propertyCount; ++index)
            {
                EditorGUILayout.LabelField(ShaderUtil.GetPropertyName(s, index), ShaderInspector.GetPropertyType(s, index) + ShaderUtil.GetPropertyDescription(s, index), new GUILayoutOption[0]);
            }
        }
示例#12
0
        private static void ShowShaderProperties(Shader s)
        {
            GUILayout.Space(kSpace);
            GUILayout.Label("Properties:", EditorStyles.boldLabel);
            int n = ShaderUtil.GetPropertyCount(s);

            for (int i = 0; i < n; ++i)
            {
                string pname = ShaderUtil.GetPropertyName(s, i);
                string pdesc = GetPropertyType(s, i) + ShaderUtil.GetPropertyDescription(s, i);
                EditorGUILayout.LabelField(pname, pdesc);
            }
        }
        private void ShowShaderProperties(Shader s)
        {
            GUILayout.Space(5f);
            GUILayout.Label("Properties:", EditorStyles.boldLabel, new GUILayoutOption[0]);
            int propertyCount = ShaderUtil.GetPropertyCount(s);

            for (int i = 0; i < propertyCount; i++)
            {
                string propertyName = ShaderUtil.GetPropertyName(s, i);
                string label        = GetPropertyType(s, i) + ShaderUtil.GetPropertyDescription(s, i);
                EditorGUILayout.LabelField(propertyName, label, new GUILayoutOption[0]);
            }
        }
示例#14
0
        void SynchronizeLayerProperties(int layerIndex)
        {
            Material material      = m_MaterialEditor.target as Material;
            Material layerMaterial = m_MaterialLayers[layerIndex];

            if (layerMaterial != null)
            {
                Shader layerShader   = layerMaterial.shader;
                int    propertyCount = ShaderUtil.GetPropertyCount(layerShader);
                for (int i = 0; i < propertyCount; ++i)
                {
                    string propertyName      = ShaderUtil.GetPropertyName(layerShader, i);
                    string layerPropertyName = propertyName + layerIndex;
                    if (material.HasProperty(layerPropertyName))
                    {
                        ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(layerShader, i);
                        switch (type)
                        {
                        case ShaderUtil.ShaderPropertyType.Color:
                        {
                            material.SetColor(layerPropertyName, layerMaterial.GetColor(propertyName));
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.Float:
                        case ShaderUtil.ShaderPropertyType.Range:
                        {
                            material.SetFloat(layerPropertyName, layerMaterial.GetFloat(propertyName));
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.Vector:
                        {
                            material.SetVector(layerPropertyName, layerMaterial.GetVector(propertyName));
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.TexEnv:
                        {
                            material.SetTexture(layerPropertyName, layerMaterial.GetTexture(propertyName));
                            break;
                        }
                        }
                    }
                }
            }
        }
        public override bool HasModified()
        {
            bool result;

            if (base.HasModified())
            {
                result = true;
            }
            else
            {
                ShaderImporter shaderImporter = base.target as ShaderImporter;
                if (shaderImporter == null)
                {
                    result = false;
                }
                else
                {
                    Shader shader = shaderImporter.GetShader();
                    if (shader == null)
                    {
                        result = false;
                    }
                    else
                    {
                        int propertyCount = ShaderUtil.GetPropertyCount(shader);
                        for (int i = 0; i < propertyCount; i++)
                        {
                            string propertyName = ShaderUtil.GetPropertyName(shader, i);
                            for (int j = 0; j < this.m_Properties.Count; j++)
                            {
                                if (this.m_Properties[j].propertyName == propertyName)
                                {
                                    Texture y = (!this.m_Properties[j].modifiable) ? shaderImporter.GetNonModifiableTexture(propertyName) : shaderImporter.GetDefaultTexture(propertyName);
                                    if (this.m_Properties[j].texture != y)
                                    {
                                        result = true;
                                        return(result);
                                    }
                                }
                            }
                        }
                        result = false;
                    }
                }
            }
            return(result);
        }
示例#16
0
        private static List <string> GetMaterialPropertyNames(UnityEngine.Object obj, bool multiSelect, out int selection, out bool invalidSelection)
        {
            selection        = -1;
            invalidSelection = true;
            List <string> properties = new List <string>();
            VideoPlayer   vp         = obj as VideoPlayer;

            if (!vp)
            {
                return(properties);
            }

            Renderer renderer = GetTargetRenderer(vp);

            if (!renderer)
            {
                return(properties);
            }

            foreach (Material material in renderer.sharedMaterials)
            {
                if (material)
                {
                    for (int i = 0, e = ShaderUtil.GetPropertyCount(material.shader); i < e; ++i)
                    {
                        if (ShaderUtil.GetPropertyType(material.shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            string propertyName = ShaderUtil.GetPropertyName(material.shader, i);
                            if (!properties.Contains(propertyName))
                            {
                                properties.Add(propertyName);
                            }
                        }
                    }
                    selection        = properties.IndexOf(vp.targetMaterialProperty);
                    invalidSelection = selection < 0 && properties.Count() > 0;
                    if (invalidSelection && !multiSelect)
                    {
                        selection = properties.Count();
                        properties.Add(vp.targetMaterialProperty);
                    }
                }
            }
            return(properties);
        }
        protected override void ResetValues()
        {
            base.ResetValues();
            this.m_Properties.Clear();
            ShaderImporter shaderImporter = base.target as ShaderImporter;

            if (!(shaderImporter == null))
            {
                Shader shader = shaderImporter.GetShader();
                if (!(shader == null))
                {
                    int propertyCount = ShaderUtil.GetPropertyCount(shader);
                    for (int i = 0; i < propertyCount; i++)
                    {
                        if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            string  propertyName        = ShaderUtil.GetPropertyName(shader, i);
                            string  propertyDescription = ShaderUtil.GetPropertyDescription(shader, i);
                            bool    flag = !ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i);
                            Texture texture;
                            if (!flag)
                            {
                                texture = shaderImporter.GetNonModifiableTexture(propertyName);
                            }
                            else
                            {
                                texture = shaderImporter.GetDefaultTexture(propertyName);
                            }
                            ShaderImporterInspector.TextureProp item = new ShaderImporterInspector.TextureProp
                            {
                                propertyName = propertyName,
                                texture      = texture,
                                dimension    = ShaderUtil.GetTexDim(shader, i),
                                displayName  = propertyDescription,
                                modifiable   = flag
                            };
                            this.m_Properties.Add(item);
                        }
                    }
                }
            }
        }
        public override bool HasModified()
        {
            if (base.HasModified())
            {
                return(true);
            }

            var importer = target as ShaderImporter;

            if (importer == null)
            {
                return(false);
            }

            var shader = importer.GetShader();

            if (shader == null)
            {
                return(false);
            }

            var propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (var i = 0; i < propertyCount; i++)
            {
                var propertyName = ShaderUtil.GetPropertyName(shader, i);
                for (var k = 0; k < m_Properties.Count; k++)
                {
                    if (m_Properties[k].propertyName == propertyName)
                    {
                        var tex = m_Properties[k].modifiable ? importer.GetDefaultTexture(propertyName) : importer.GetNonModifiableTexture(propertyName);
                        if (m_Properties[k].texture != tex)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
示例#19
0
        private static int GetMaterialPropertyPopupHash(UnityEngine.Object[] objects)
        {
            int num = 0;

            for (int i = 0; i < objects.Length; i++)
            {
                VideoPlayer videoPlayer = (VideoPlayer)objects[i];
                if (videoPlayer)
                {
                    Renderer targetRenderer = VideoPlayerEditor.GetTargetRenderer(videoPlayer);
                    if (targetRenderer)
                    {
                        num ^= videoPlayer.targetMaterialProperty.GetHashCode();
                        Material[] sharedMaterials = targetRenderer.sharedMaterials;
                        for (int j = 0; j < sharedMaterials.Length; j++)
                        {
                            Material material = sharedMaterials[j];
                            if (material)
                            {
                                num ^= material.name.GetHashCode();
                                int k             = 0;
                                int propertyCount = ShaderUtil.GetPropertyCount(material.shader);
                                while (k < propertyCount)
                                {
                                    if (ShaderUtil.GetPropertyType(material.shader, k) == ShaderUtil.ShaderPropertyType.TexEnv)
                                    {
                                        num ^= ShaderUtil.GetPropertyName(material.shader, k).GetHashCode();
                                    }
                                    k++;
                                }
                            }
                        }
                    }
                }
            }
            return(num);
        }
示例#20
0
        private string GenerateMultiMaterialinformation()
        {
            string result;

            if (base.targets.Count <UnityEngine.Object>() > 1)
            {
                result = "";
            }
            else
            {
                VideoPlayer videoPlayer = base.target as VideoPlayer;
                if (!videoPlayer)
                {
                    result = "";
                }
                else
                {
                    Renderer targetRenderer = VideoPlayerEditor.GetTargetRenderer(videoPlayer);
                    if (!targetRenderer)
                    {
                        result = "";
                    }
                    else
                    {
                        Material[] sharedMaterials = targetRenderer.sharedMaterials;
                        if (sharedMaterials == null || sharedMaterials.Count <Material>() <= 1)
                        {
                            result = "";
                        }
                        else
                        {
                            List <string> list  = new List <string>();
                            Material[]    array = sharedMaterials;
                            for (int i = 0; i < array.Length; i++)
                            {
                                Material material = array[i];
                                if (material)
                                {
                                    int j             = 0;
                                    int propertyCount = ShaderUtil.GetPropertyCount(material.shader);
                                    while (j < propertyCount)
                                    {
                                        if (ShaderUtil.GetPropertyType(material.shader, j) == ShaderUtil.ShaderPropertyType.TexEnv && ShaderUtil.GetPropertyName(material.shader, j) == this.m_TargetMaterialProperty.stringValue)
                                        {
                                            list.Add(material.name);
                                            break;
                                        }
                                        j++;
                                    }
                                }
                            }
                            if (list.Count <string>() == sharedMaterials.Count <Material>())
                            {
                                result = VideoPlayerEditor.s_Styles.texPropInAllMaterialsHelp;
                            }
                            else
                            {
                                result = string.Format(VideoPlayerEditor.s_Styles.texPropInSomeMaterialsHelp, list.Count <string>(), sharedMaterials.Count <Material>()) + ": " + string.Join(", ", list.ToArray());
                            }
                        }
                    }
                }
            }
            return(result);
        }