Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            var other = obj as ShaderKunPacket;

            if (other == null)
            {
                return(false);
            }
            if (shaderKuns != null)
            {
                if (other.shaderKuns == null)
                {
                    return(false);
                }
                if (shaderKuns.Length != other.shaderKuns.Length)
                {
                    return(false);
                }
                for (var i = 0; i < shaderKuns.Length; i++)
                {
                    if (!ShaderKun.Equals(shaderKuns[i], other.shaderKuns[i]))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #2
0
 public override void Deserialize(BinaryReader binaryReader)
 {
     base.Deserialize(binaryReader);
     m_doubleSidedGI           = binaryReader.ReadBoolean();
     m_enableInstancing        = binaryReader.ReadBoolean();
     m_mainTexPropIdx          = binaryReader.ReadInt32();
     m_passCount               = binaryReader.ReadInt32();
     m_renderQueue             = binaryReader.ReadInt32();
     m_globalIlluminationFlags = (MaterialGlobalIlluminationFlags)binaryReader.ReadInt32();
     m_shader         = SerializerKun.DesirializeObject <ShaderKun>(binaryReader);
     m_shaderKeywords = SerializerKun.DesirializeStrings(binaryReader);
     m_propertys      = SerializerKun.DesirializeObjects <Property>(binaryReader);
 }
Example #3
0
        /// <summary>
        /// Deserialize
        /// </summary>
        /// <param name="binaryReader">BinaryReader</param>
        public virtual void Deserialize(BinaryReader binaryReader)
        {
            var len = binaryReader.ReadInt32();

            if (len != -1)
            {
                shaderKuns = new ShaderKun[len];
                for (var i = 0; i < len; i++)
                {
                    shaderKuns[i] = new ShaderKun();
                    shaderKuns[i].Deserialize(binaryReader);
                }
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bytes"></param>
        public void OnMessageEventPull(BinaryReader binaryReader)
        {
            GetAllShader();
            var shaderKuns = new ShaderKun[shaderDict.Count];
            var i          = 0;

            foreach (var shader in shaderDict.Values)
            {
                shaderKuns[i] = new ShaderKun(shader);
                i++;
            }
            var shaderKunPacket = new ShaderKunPacket();

            shaderKunPacket.shaderKuns = shaderKuns;
            UnityChoseKunPlayer.SendMessage <ShaderKunPacket>(UnityChoseKun.MessageID.ShaderPull, shaderKunPacket);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        public MaterialKun(UnityEngine.Object obj) : base(obj)
        {
            var material = obj as Material;

            if (material)
            {
                name = material.name;
#if false
                doubleSidedGI           = material.doubleSidedGI;
                globalIlluminationFlags = material.globalIlluminationFlags;
#endif
                enableInstancing = material.enableInstancing;
                passCount        = material.passCount;
                renderQueue      = material.renderQueue;
                shaderKeywords   = material.shaderKeywords;
                if (material.shader != null)
                {
                    shader = new ShaderKun(material.shader);
#if UNITY_2019_1_OR_NEWER
                    if (shader.GetPropertyCount() > 0)
                    {
                        propertys = new Property[shader.GetPropertyCount()];
                        for (var i = 0; i < shader.GetPropertyCount(); i++)
                        {
                            propertys[i]             = new Property();
                            propertys[i].flags       = shader.GetPropertyFlags(i);
                            propertys[i].type        = shader.GetPropertyType(i);
                            propertys[i].name        = shader.GetPropertyName(i);
                            propertys[i].nameId      = shader.GetPropertyNameId(i);
                            propertys[i].displayName = shader.GetPropertyDescription(i);
                            switch (propertys[i].type)
                            {
                            case UnityEngine.Rendering.ShaderPropertyType.Range:
                            {
                                propertys[i].rangeLimits = shader.GetPropertyRangeLimits(i);
                                propertys[i].floatValue  = material.GetFloat(propertys[i].nameId);
                            }
                            break;

                            case UnityEngine.Rendering.ShaderPropertyType.Texture:
                            {
                                var texture = material.GetTexture(propertys[i].nameId);
                                if (texture != null)
                                {
                                    propertys[i].textureValue = new TextureKun(texture);
                                }
                                propertys[i].textureDimension = shader.GetPropertyTextureDimension(i);
                                propertys[i].scale            = material.GetTextureScale(propertys[i].nameId);
                                propertys[i].offset           = material.GetTextureOffset(propertys[i].nameId);
                                if (propertys[i].name == "_MainTex")
                                {
                                    mainTexPrpoIdx = i;
                                }
                            }
                            break;

                            case UnityEngine.Rendering.ShaderPropertyType.Float:
                            {
                                propertys[i].floatValue = material.GetFloat(propertys[i].nameId);
                            }
                            break;

                            case UnityEngine.Rendering.ShaderPropertyType.Vector:
                            {
                                propertys[i].vectorValue = material.GetVector(propertys[i].nameId);
                            }
                            break;

                            case UnityEngine.Rendering.ShaderPropertyType.Color:
                            {
                                propertys[i].colorValue = material.GetColor(propertys[i].nameId);
                            }
                            break;
                            }
                        }
                    }
#endif
                }
                shaderKeywords = material.shaderKeywords;
            }
        }