Пример #1
0
        public static MaterialItem Create(Material material)
        {
            var item = new MaterialItem
            {
                Material = material
            };

#if UNITY_EDITOR
            var propNames = new List <string>();
            for (int i = 0; i < ShaderUtil.GetPropertyCount(material.shader); ++i)
            {
                var propType = ShaderUtil.GetPropertyType(material.shader, i);
                var name     = ShaderUtil.GetPropertyName(material.shader, i);

                switch (propType)
                {
                case ShaderUtil.ShaderPropertyType.Color:
                    // 色
                    item.PropMap.Add(name, new PropItem
                    {
                        PropertyType  = propType,
                        DefaultValues = material.GetColor(name),
                    });
                    propNames.Add(name);
                    break;

                case ShaderUtil.ShaderPropertyType.TexEnv:
                    // テクスチャ
                {
                    name += "_ST";
                    item.PropMap.Add(name, new PropItem
                        {
                            PropertyType  = propType,
                            DefaultValues = material.GetVector(name),
                        });
                    propNames.Add(name);
                }
                    // 縦横分離用
                    {
                        var st_name = name + "_S";
                        item.PropMap.Add(st_name, new PropItem
                        {
                            PropertyType  = propType,
                            DefaultValues = material.GetVector(name),
                        });
                        propNames.Add(st_name);
                    }
                    {
                        var st_name = name + "_T";
                        item.PropMap.Add(st_name, new PropItem
                        {
                            PropertyType  = propType,
                            DefaultValues = material.GetVector(name),
                        });
                        propNames.Add(st_name);
                    }
                    break;
                }
            }
            item.PropNames = propNames.ToArray();
#endif
            return(item);
        }
Пример #2
0
        private void Initialize(GameObject prefab)
        {
            //Debug.LogFormat("[PreviewSceneManager.Initialize] {0}", prefab);
            Prefab = prefab;

            var materialNames = new List <string>();
            var map           = new Dictionary <Material, Material>();
            Func <Material, Material> getOrCreateMaterial = src =>
            {
                if (src == null)
                {
                    return(null);
                }
                if (string.IsNullOrEmpty(src.name))
                {
                    return(null);                                // !
                }
                Material dst;
                if (!map.TryGetValue(src, out dst))
                {
                    dst = new Material(src);
                    map.Add(src, dst);

                    //Debug.LogFormat("add material {0}", src.name);
                    materialNames.Add(src.name);
                    m_materialMap.Add(src.name, MaterialItem.Create(dst));
                }
                return(dst);
            };

            m_meshes = transform.Traverse()
                       .Select(x => MeshPreviewItem.Create(x, transform, getOrCreateMaterial))
                       .Where(x => x != null)
                       .ToArray()
            ;
            MaterialNames = materialNames.ToArray();

            m_blendShapeMeshes = m_meshes
                                 .Where(x => x.SkinnedMeshRenderer != null &&
                                        x.SkinnedMeshRenderer.sharedMesh.blendShapeCount > 0)
                                 .ToArray();

            //Bake(values, materialValues);

            m_rendererPathList            = m_meshes.Select(x => x.Path).ToArray();
            m_skinnedMeshRendererPathList = m_meshes
                                            .Where(x => x.SkinnedMeshRenderer != null)
                                            .Select(x => x.Path)
                                            .ToArray();

            var animator = GetComponent <Animator>();

            if (animator != null)
            {
                var head = animator.GetBoneTransform(HumanBodyBones.Head);
                if (head != null)
                {
                    m_target = head;
                }
            }
        }