Exemple #1
0
        public override void GetDepsFrom(object obj, GetDepsFromContext context)
        {
            base.GetDepsFrom(obj, context);
            if (obj == null)
            {
                return;
            }

            Material           o          = (Material)obj;
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(o.shader);
            }

            if (shaderInfo == null)
            {
                return;
            }

            for (int i = 0; i < shaderInfo.PropertyCount; ++i)
            {
                string name = shaderInfo.PropertyNames[i];
                RTShaderPropertyType type = shaderInfo.PropertyTypes[i];
                switch (type)
                {
                case RTShaderPropertyType.TexEnv:
                    AddDep(o.GetTexture(name), context);
                    break;
                }
            }
        }
Exemple #2
0
 protected virtual void AwakeOverride()
 {
     m_shaderUtil    = ShaderUtil;
     m_assetDB       = AssetDB;
     m_typeMap       = TypeMap;
     m_objectFactory = ObjectFactory;
     m_serializer    = Serializer;
     m_storage       = Storage;
     m_project       = Project;
 }
Exemple #3
0
        protected virtual void AwakeOverride()
        {
            if (gameObject.GetComponent <Dispatcher>() == null)
            {
                gameObject.AddComponent <Dispatcher>();
            }

            m_assetBundleLoader = AssetBundleLoader;
            m_assetDB           = AssetDB;
            m_shaderUtil        = ShaderUtil;
            m_typeMap           = TypeMap;
            m_objectFactory     = ObjectFactory;
            m_serializer        = Serializer;
            m_storage           = Storage;
            m_project           = Project;
        }
Exemple #4
0
        private void OnDestroy()
        {
            if (m_instance == this)
            {
                m_instance = null;
            }

            OnDestroyOverride();

            m_shaderUtil    = null;
            m_assetDB       = null;
            m_typeMap       = null;
            m_objectFactory = null;
            m_serializer    = null;
            m_storage       = null;
            m_project       = null;
        }
        public static MaterialPropertyDescriptor[] GetProperties(Material material)
        {
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(material.shader);
            }

            if (shaderInfo == null)
            {
                return(null);
            }

            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            if (shaderInfo != null)
            {
                for (int i = 0; i < shaderInfo.PropertyCount; ++i)
                {
                    bool isHidden = shaderInfo.IsHidden[i];
                    if (isHidden)
                    {
                        continue;
                    }

                    string propertyDescr = shaderInfo.PropertyDescriptions[i];
                    string propertyName  = shaderInfo.PropertyNames[i];
                    RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                    RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                    TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                    PropertyInfo     propertyInfo = GetPropertyInfo(propertyType, dim);

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    MaterialPropertyDescriptor propertyDescriptor = CreatePropertyDescriptor(material, propertyInfo, propertyDescr, propertyName, propertyType, dim, limits);
                    descriptors.Add(propertyDescriptor);
                }
            }
            return(descriptors.ToArray());
        }
Exemple #6
0
        public override void ReadFrom(object obj)
        {
            base.ReadFrom(obj);
            if (obj == null)
            {
                return;
            }

            Material o = (Material)obj;

            if (o.HasProperty("_MainTex"))
            {
                mainTextureOffset = o.mainTextureOffset;
                mainTextureScale  = o.mainTextureScale;
            }

            if (o.shader == null)
            {
                shader       = m_assetDB.NullID;
                m_shaderName = null;
                return;
            }

            shader       = m_assetDB.ToID(o.shader);
            m_shaderName = o.shader.name;

            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(o.shader);
            }
            if (shaderInfo == null)
            {
                return;
            }

            m_propertyNames  = new string[shaderInfo.PropertyCount];
            m_propertyTypes  = new RTShaderPropertyType[shaderInfo.PropertyCount];
            m_propertyValues = new PrimitiveContract[shaderInfo.PropertyCount];

            for (int i = 0; i < shaderInfo.PropertyCount; ++i)
            {
                string name = shaderInfo.PropertyNames[i];
                RTShaderPropertyType type = shaderInfo.PropertyTypes[i];
                m_propertyNames[i] = name;
                m_propertyTypes[i] = type;
                switch (type)
                {
                case RTShaderPropertyType.Color:
                    m_propertyValues[i] = PrimitiveContract.Create((PersistentColor)o.GetColor(name));
                    break;

                case RTShaderPropertyType.Float:
                    m_propertyValues[i] = PrimitiveContract.Create(o.GetFloat(name));
                    break;

                case RTShaderPropertyType.Range:
                    m_propertyValues[i] = PrimitiveContract.Create(o.GetFloat(name));
                    break;

                case RTShaderPropertyType.TexEnv:
                    Texture2D texture = (Texture2D)o.GetTexture(name);
                    if (texture == null)
                    {
                        m_propertyValues[i] = PrimitiveContract.Create(m_assetDB.NullID);
                    }
                    else
                    {
                        m_propertyValues[i] = PrimitiveContract.Create(m_assetDB.ToID(texture));
                    }
                    break;

                case RTShaderPropertyType.Vector:
                    m_propertyValues[i] = PrimitiveContract.Create((PersistentVector4)o.GetVector(name));
                    break;

                case RTShaderPropertyType.Unknown:
                    m_propertyValues[i] = null;
                    break;
                }
            }

            m_keywords = o.shaderKeywords;
        }
Exemple #7
0
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor, object converter)
        {
            RuntimeShaderInfo  shaderInfo = null;
            IRuntimeShaderUtil shaderUtil = IOC.Resolve <IRuntimeShaderUtil>();

            if (shaderUtil != null)
            {
                shaderInfo = shaderUtil.GetShaderInfo(editor.Material.shader);
            }


            if (shaderInfo == null)
            {
                return(null);
            }

            List <MaterialPropertyDescriptor> descriptors = new List <MaterialPropertyDescriptor>();

            if (shaderInfo != null)
            {
                for (int i = 0; i < shaderInfo.PropertyCount; ++i)
                {
                    bool isHidden = shaderInfo.IsHidden[i];
                    if (isHidden)
                    {
                        continue;
                    }

                    string propertyDescr = shaderInfo.PropertyDescriptions[i];
                    string propertyName  = shaderInfo.PropertyNames[i];
                    RTShaderPropertyType          propertyType = shaderInfo.PropertyTypes[i];
                    RuntimeShaderInfo.RangeLimits limits       = shaderInfo.PropertyRangeLimits[i];
                    TextureDimension dim          = shaderInfo.PropertyTexDims[i];
                    PropertyInfo     propertyInfo = null;
                    switch (propertyType)
                    {
                    case RTShaderPropertyType.Color:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color, "Color");
                        break;

                    case RTShaderPropertyType.Float:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.Range:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");
                        break;

                    case RTShaderPropertyType.TexEnv:
                        switch (dim)
                        {
                        case TextureDimension.Any:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture, "Texture");
                            break;

                        case TextureDimension.Cube:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Cubemap, "Cubemap");
                            break;

                        case TextureDimension.None:
                            propertyInfo = null;
                            break;

                        case TextureDimension.Tex2D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2D, "Texture2D");
                            break;

                        case TextureDimension.Tex2DArray:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture2DArray, "Texture2DArray");
                            break;

                        case TextureDimension.Tex3D:
                            propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture3D, "Texture3D");
                            break;

                        case TextureDimension.Unknown:
                            propertyInfo = null;
                            break;
                        }

                        break;

                    case RTShaderPropertyType.Vector:
                        propertyInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Vector, "Vector");
                        break;
                    }

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    MaterialPropertyDescriptor propertyDescriptor = new MaterialPropertyDescriptor(
                        editor.Material,
                        new MaterialPropertyAccessor(editor.Material, propertyName),
                        propertyDescr, propertyType, propertyInfo, limits, dim, null,
                        (accessorRef, newTarget) =>
                    {
                        MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
                        accessor.Material = newTarget as Material;
                    });
                    descriptors.Add(propertyDescriptor);
                }
            }

            return(descriptors.ToArray());
        }