Example #1
0
        public void WriteMateFile(string infile, string outfilepath, TargetMaterial trgtMat)
        {
            bool onBuffer;

            using (var reader = new BinaryReader(GetStream(infile, out onBuffer), Encoding.UTF8)) {
                var header = reader.ReadString();
                if (onBuffer || reader.BaseStream.Position > 0)
                {
                    if (header == FileConst.HEAD_MATE)
                    {
                        WriteMateFile(reader, header, outfilepath, trgtMat);
                        return;
                    }
                    var msg = LogUtil.Error("正しいmateファイルではありません。ヘッダが不正です。", header, ", infile=", infile);
                    throw new ACCException(msg.ToString());
                }
            }

            // arc内のファイルがロードできない場合の回避策: Sybaris 0410向け対策. 一括読み込み
            using (var reader = new BinaryReader(new MemoryStream(FileUtilEx.Instance.LoadInternal(infile), false), Encoding.UTF8)) {
                string header = reader.ReadString(); // hader
                if (header == FileConst.HEAD_MATE)
                {
                    WriteMateFile(reader, header, outfilepath, trgtMat);
                }
                var msg = LogUtil.Error("正しいmateファイルではありません。ヘッダが不正です。", header, ", infile=", infile);
                throw new ACCException(msg.ToString());
            }
        }
        public void ResetByTexture(Texture2D originTexture)
        {
            if (mTargetTexture != null)
            {
                Texture2D.Destroy(mTargetTexture);
            }

            mTargetPixels       = originTexture.GetPixels32();
            mTargetOriginPixels = (Color32[])mTargetPixels.Clone();


            // target texture
            mTargetTexture = new Texture2D(originTexture.width, originTexture.height, TextureFormat.ARGB32, false);
            mTargetTexture.SetPixels32(mTargetPixels);
            mTargetTexture.Apply();
            TargetMaterial.SetTexture(mTargetMaterialProperty, mTargetTexture);

            if (mSortedCanvasLayers == null)
            {
                return;
            }

            for (int i = mSortedCanvasLayers.Count - 1; i >= 0; --i)
            {
                mSortedCanvasLayers [i].Reset();
            }
        }
Example #3
0
    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (TargetMaterial != null)
        {
            // 创建积累图像
            if (accumulationTexture == null || accumulationTexture.width != src.width || accumulationTexture.height != src.height)
            {
                DestroyImmediate(accumulationTexture);
                accumulationTexture           = new RenderTexture(src.width, src.height, 0);
                accumulationTexture.hideFlags = HideFlags.HideAndDontSave; // 变量不显示在Hierarchy中,也不会保存到场景
                Graphics.Blit(src, accumulationTexture);                   // 原始图像存入积累纹理
            }

            // 表明需要进行一个恢复操作。渲染恢复操作:发生在渲染到纹理,而该纹理有没有被提前情况或销毁情况下。
            accumulationTexture.MarkRestoreExpected();          // accumulationTexture就不需要提前清空了

            TargetMaterial.SetFloat("_BlurAmount", 1.0f - blurAmount);

            // 混合当前屏幕和之前存的混合图像
            Graphics.Blit(src, accumulationTexture, TargetMaterial);
            // 最后输出混合图像
            Graphics.Blit(accumulationTexture, dest);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
Example #4
0
    public void RenderToTexture(GameObject target, RenderTexture texture)
    {
        // 第一步:把渲染的物体渲染进纹理先
        additionalCamera.cullingMask   = 1;
        additionalCamera.targetTexture = texture;
        additionalCamera.targetTexture.Release();
        additionalCamera.Render();

        // 第二步:把这个纹理备份到_SceneTex
        temRT1 = RenderTexture.GetTemporary(texture.width, texture.height);
        Graphics.Blit(additionalCamera.targetTexture, temRT1);
        TargetMaterial.SetTexture("_SceneTex", temRT1);

        // 第三步:渲染物体的面积
        additionalCamera.cullingMask = 1 << LayerMask.NameToLayer("PostEffect");
        meshFilters = target.GetComponentsInChildren <MeshFilter>();
        for (int j = 0; j < meshFilters.Length; j++)
        {
            Graphics.DrawMesh(meshFilters[j].sharedMesh, meshFilters[j].transform.localToWorldMatrix, OccupiedMaterial, LayerMask.NameToLayer("PostEffect"), additionalCamera); // 描绘选中物体的所占面积
        }
        additionalCamera.Render();

        // 第四步:实现描边效果
        TargetMaterial.SetColor("_Color", outlineColor);
        TargetMaterial.SetInt("_Width", outlineWidth);
        TargetMaterial.SetInt("_Iterations", iterations);
        temRT2 = RenderTexture.GetTemporary(texture.width, texture.height);
        Graphics.Blit(additionalCamera.targetTexture, temRT2, TargetMaterial);
        Graphics.Blit(temRT2, additionalCamera.targetTexture);
    }
Example #5
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (TargetMaterial != null && drawOccupied != null && additionalCamera != null)
        {
            tempRT = RenderTexture.GetTemporary(source.width, source.height, 0);
            additionalCamera.targetTexture = tempRT;

            // 额外相机中使用shader,绘制出物体所占面积
            additionalCamera.RenderWithShader(drawOccupied, "");

            TargetMaterial.SetTexture("_SceneTex", source);
            TargetMaterial.SetColor("_Color", outlineColor);
            TargetMaterial.SetInt("_Width", outlineWidth);
            TargetMaterial.SetInt("_Iterations", iterations);

            // 使用描边混合材质实现描边效果
            Graphics.Blit(tempRT, destination, TargetMaterial);

            tempRT.Release();
        }
        else
        {
            Graphics.Blit(source, destination);
        }
    }
        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (TargetMaterial != null && drawOccupied != null && additionalCamera != null && targetsDic.Count != 0)
            {
                SetupAddtionalCamera();
                tempRT = RenderTexture.GetTemporary(source.width, source.height, 0);
                additionalCamera.targetTexture = tempRT;
                //---这种方法对于蒙皮动画无效,但是效率较高
                //foreach (var item in targetsDic.Values)
                //{
                //    foreach (var meshInfo in item)
                //    {
                //        for (int i = 0; i < meshInfo.Value.Count; i++)
                //        {
                //            for (int k = 0; k < meshInfo.Value[i].subMeshCount; k++)
                //            {
                //                Graphics.DrawMesh(meshInfo.Value[i], meshInfo.Key.localToWorldMatrix,
                //           OccupiedMaterial, GetLayer(layerMask), additionalCamera, k); // 描绘选中物体的所占面积
                //            }

                //        }
                //    }
                //}

                //设置层级
                foreach (var item in targetsDic.Values)
                {
                    foreach (var transInfo in item)
                    {
                        transInfo.Key.gameObject.layer = GetLayer(layerMask);
                    }
                }
                additionalCamera.SetReplacementShader(drawOccupied, "");
                additionalCamera.Render();  // 需要调用渲染函数,才能及时把描绘物体渲染到纹理中
                foreach (var item in targetsDic.Values)
                {
                    foreach (var transInfo in item)
                    {
                        transInfo.Key.gameObject.layer = transInfo.Value;
                    }
                }


                TargetMaterial.SetTexture("_SceneTex", source);
                TargetMaterial.SetColor("_Color", outlineColor);
                TargetMaterial.SetInt("_Width", outlineWidth);
                TargetMaterial.SetInt("_Iterations", iterations);
                TargetMaterial.SetFloat("_Gradient", gradient);
                Graphics.Blit(tempRT, TestRender);
                // 使用描边混合材质实现描边效果
                Graphics.Blit(tempRT, destination, TargetMaterial);
                additionalCamera.targetTexture = null;
                RenderTexture.ReleaseTemporary(tempRT);
            }
            else
            {
                Graphics.Blit(source, destination);
            }
        }
Example #7
0
    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (TargetMaterial != null)
        {
            Matrix4x4 frustumCorners = Matrix4x4.identity;

            float fov    = TargetCamera.fieldOfView;
            float near   = TargetCamera.nearClipPlane;
            float aspect = TargetCamera.aspect;

            float   halfHeight = near * Mathf.Tan(fov * 0.5f * Mathf.Deg2Rad);
            Vector3 toRight    = CameraTransform.right * halfHeight * aspect;
            Vector3 toTop      = CameraTransform.up * halfHeight;

            Vector3 topLeft = CameraTransform.forward * near + toTop - toRight;
            float   scale   = topLeft.magnitude / near;

            topLeft.Normalize();
            topLeft *= scale;

            Vector3 topRight = CameraTransform.forward * near + toRight + toTop;
            topRight.Normalize();
            topRight *= scale;

            Vector3 bottomLeft = CameraTransform.forward * near - toTop - toRight;
            bottomLeft.Normalize();
            bottomLeft *= scale;

            Vector3 bottomRight = CameraTransform.forward * near + toRight - toTop;
            bottomRight.Normalize();
            bottomRight *= scale;

            frustumCorners.SetRow(0, bottomLeft);
            frustumCorners.SetRow(1, bottomRight);
            frustumCorners.SetRow(2, topRight);
            frustumCorners.SetRow(3, topLeft);

            TargetMaterial.SetMatrix("_FrustumCornersRay", frustumCorners);

            TargetMaterial.SetFloat("_FogDensity", fogDensity);
            TargetMaterial.SetColor("_FogColor", fogColor);
            TargetMaterial.SetFloat("_FogStart", fogStart);
            TargetMaterial.SetFloat("_FogEnd", fogEnd);

            TargetMaterial.SetTexture("_NoiseTex", noiseTexture);
            TargetMaterial.SetFloat("_FogXSpeed", fogXSpeed);
            TargetMaterial.SetFloat("_FogYSpeed", fogYSpeed);
            TargetMaterial.SetFloat("_NoiseAmount", noiseAmount);
            Graphics.Blit(src, dest, TargetMaterial);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
        void InitTexture(int pWidth, int pHeight, Color pColor)
        {
            // pixels
            mTargetPixels = CocoData.CreateArray <Color32> (pWidth * pHeight, pColor);

            // target texture
            mTargetTexture = new Texture2D(pWidth, pHeight, TextureFormat.ARGB32, false);
            mTargetTexture.SetPixels32(mTargetPixels);
            mTargetTexture.Apply();
            TargetMaterial.SetTexture(mTargetMaterialProperty, mTargetTexture);
        }
Example #9
0
    public override void OnPreviewGUI(Rect r, GUIStyle background)
    {
        if (Application.isPlaying)
        {
            return;
        }

        TargetMeshRenderer.gameObject.SetActive(true);
        TargetMeshRenderer.gameObject.transform.localPosition = Vector3.zero;

        //Update the preview cam and the cam to render with
        Transform previewTransform = base.MoveCamera();

        if (previewTransform == null)
        {
            return;
        }
        EditorWindowPreviewCamera.transform.rotation = previewTransform.rotation;
        EditorWindowPreviewCamera.transform.position = previewTransform.position;
        if (MirroredPreview)
        {
            EditorWindowPreviewCamera.transform.rotation =
                MirrorTransformUtils.MirrorRotate(EditorWindowPreviewCamera.transform.rotation);

            MirrorTransformUtils.MirrorMoveTransform(EditorWindowPreviewCamera.transform);
        }

        EditorWindowWindowPreviewRenderer.enabled = true;
        RenderTexture rt = null;

        try {
            if (r.width > 0 && (int)r.height > 0)
            {
                rt = RenderTexture.GetTemporary((int)r.width, (int)r.height, 16);
                EditorWindowPreviewCamera.targetTexture = rt;
                TargetMaterial.SetTexture(Keywords.ShaderKeys.LeftEye, rt);
                TargetMaterial.SetVector(Keywords.ShaderKeys.LeftPos, new Vector4(0, 0, 1, 1));
                TargetMaterial.SetTexture(Keywords.ShaderKeys.RightEye, rt);
                TargetMaterial.SetVector(Keywords.ShaderKeys.RightPos, new Vector4(0, 0, 1, 1));
                EditorWindowPreviewCamera.Render();
                //EditorWindowPreviewCamera.Render();
                base.OnPreviewGUI_s(r, background);
            }
        }
        catch {
            //Unity silliness again
        }
        TargetMeshRenderer.gameObject.SetActive(false);
        if (rt != null)
        {
            RenderTexture.ReleaseTemporary(rt);
        }
        EditorWindowWindowPreviewRenderer.enabled = false;
    }
        // Token: 0x0600025E RID: 606 RVA: 0x000155E8 File Offset: 0x000137E8
        private void WriteTex(BinaryWriter writer, string propName, TargetMaterial tm, TargetTexture trgtTex)
        {
            this.Write(writer, new string[]
            {
                "tex"
            });
            this.Write(writer, new string[]
            {
                propName
            });
            string text = "tex2d";

            if (trgtTex == null || trgtTex.tex == null)
            {
                text = "null";
            }
            this.Write(writer, new string[]
            {
                text
            });
            string a;

            if ((a = text) != null)
            {
                if (!(a == "tex2d"))
                {
                    if (!(a == "null"))
                    {
                        if (!(a == "texRT"))
                        {
                            return;
                        }
                        writer.Write(string.Empty);
                        writer.Write(string.Empty);
                    }
                }
                else if (trgtTex.fileChanged || trgtTex.colorChanged)
                {
                    this.Write(writer, new string[]
                    {
                        trgtTex.EditFileNameNoExt()
                    });
                    this.Write(writer, new string[]
                    {
                        trgtTex.EditTxtPath()
                    });
                    this.Write(writer, tm.editedMat.material.GetTextureOffset(propName));
                    this.Write(writer, tm.editedMat.material.GetTextureScale(propName));
                    return;
                }
            }
        }
    public Color backgroundColor = Color.white; // 背景色

    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (TargetMaterial != null)
        {
            TargetMaterial.SetFloat("_EdgeOnly", edgesOnly);
            TargetMaterial.SetColor("_EdgeColor", edgeColor);
            TargetMaterial.SetColor("_BackgroundColor", backgroundColor);
            Graphics.Blit(src, dest, TargetMaterial);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
Example #12
0
 /// <summary>
 /// 抓取屏幕图像
 /// </summary>
 /// <param name="src">源</param>
 /// <param name="dest">目标</param>
 void OnRenderImage(RenderTexture src, RenderTexture dest)
 {
     if (TargetMaterial != null)
     {
         TargetMaterial.SetFloat("_Brightness", brightness);
         TargetMaterial.SetFloat("_Saturation", saturation);
         TargetMaterial.SetFloat("_Contrast", contrast);
         Graphics.Blit(src, dest, TargetMaterial);
     }
     else
     {
         Graphics.Blit(src, dest);
     }
 }
 [ImageEffectOpaque]     // 不透明物体渲染完后执行(不影响透明物体)
 void OnRenderImage(RenderTexture src, RenderTexture dest)
 {
     if (TargetMaterial != null)
     {
         TargetMaterial.SetFloat("_EdgeOnly", edgesOnly);
         TargetMaterial.SetColor("_EdgeColor", edgeColor);
         TargetMaterial.SetColor("_BackgroundColor", backgroundColor);
         TargetMaterial.SetFloat("_SampleDistance", sampleDistance);
         TargetMaterial.SetVector("_Sensitivity", new Vector4(sensitivityNormals, sensitivityDepth, 0.0f, 0.0f));
         Graphics.Blit(src, dest, TargetMaterial);
     }
     else
     {
         Graphics.Blit(src, dest);
     }
 }
Example #14
0
    private void Update()
    {
        if (isOpen && TargetMaterial != null && meshFilter != null)
        {
            if (Timer.Duration != blinkTime)
            {
                Timer.Reset(blinkTime);
            }

            // 颜色透明度变化:指定事件的周期,根据曲线变化透明度。
            TargetMaterial.SetColor("_Color", new Color(color.r, color.g, color.b, maxColorAlpha * blinkCurve.Evaluate(Mathf.PingPong(Timer.GetPercent() * 2F, 1))));

            for (int k = 0; k < meshFilter.sharedMesh.subMeshCount; k++)
            {
                Graphics.DrawMesh(meshFilter.sharedMesh, meshFilter.transform.localToWorldMatrix, TargetMaterial, 0, null, k);
            }
        }
    }
Example #15
0
    private void Update()
    {
        if (TargetMaterial != null && _endTime > Time.time)
        {
            _color.a = _alphaCurve.Evaluate((Time.time - _startTime) / (_durationTime));
            TargetMaterial.SetColor("_Color", _color);
            TargetMaterial.SetFloat("_Width", _width);

            if (_meshFilters == null)
            {
                _meshFilters = gameObject.GetComponentsInChildren <MeshFilter>();
            }
            for (int j = 0; j < _meshFilters.Length; j++)
            {
                Graphics.DrawMesh(_meshFilters[j].mesh, _meshFilters[j].transform.localToWorldMatrix, TargetMaterial, 0);   // 对选中物体再次渲染。
            }
        }
    }
Example #16
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (TargetMaterial != null && drawOccupied != null && additionalCamera != null && targets != null)
        {
            SetupAddtionalCamera();
            tempRT = RenderTexture.GetTemporary(source.width, source.height, 0);
            additionalCamera.targetTexture = tempRT;

            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i] == null)
                {
                    continue;
                }
                meshFilters = targets[i].GetComponentsInChildren <MeshFilter>();
                for (int j = 0; j < meshFilters.Length; j++)
                {
                    if ((MainCamera.cullingMask & (1 << meshFilters[j].gameObject.layer)) != 0) // 把主相机没渲染的也不加入渲染队列
                    {
                        for (int k = 0; k < meshFilters[j].sharedMesh.subMeshCount; k++)
                        {
                            Graphics.DrawMesh(meshFilters[j].sharedMesh, meshFilters[j].transform.localToWorldMatrix, OccupiedMaterial, LayerMask.NameToLayer("PostEffect"), additionalCamera, k); // 描绘选中物体的所占面积
                        }
                    }
                }
            }
            additionalCamera.Render();  // 需要调用渲染函数,才能及时把描绘物体渲染到纹理中

            TargetMaterial.SetTexture("_SceneTex", source);
            TargetMaterial.SetColor("_Color", outlineColor);
            TargetMaterial.SetInt("_Width", outlineWidth);
            TargetMaterial.SetInt("_Iterations", iterations);
            TargetMaterial.SetFloat("_Gradient", gradient);

            // 使用描边混合材质实现描边效果
            Graphics.Blit(tempRT, destination, TargetMaterial);

            tempRT.Release();
        }
        else
        {
            Graphics.Blit(source, destination);
        }
    }
Example #17
0
    public float luminanceThreshold = 0.6f;     // 亮度阈值(一般不超过1,开了HDR可以存更高精度)

    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (TargetMaterial != null)
        {
            TargetMaterial.SetFloat("_LuminanceThreshold", luminanceThreshold);

            int rtW = src.width / downSample;
            int rtH = src.height / downSample;

            RenderTexture buffer0 = RenderTexture.GetTemporary(rtW, rtH, 0);
            buffer0.filterMode = FilterMode.Bilinear;

            Graphics.Blit(src, buffer0, TargetMaterial, 0);               // 第一个Pass把较亮区域存到buffer0

            // 迭代高斯模糊
            for (int i = 0; i < iterations; i++)
            {
                TargetMaterial.SetFloat("_BlurSize", 1.0f + i * blurSpread);

                RenderTexture buffer1 = RenderTexture.GetTemporary(rtW, rtH, 0);

                Graphics.Blit(buffer0, buffer1, TargetMaterial, 1);       // 第二个Pass,高斯模糊

                RenderTexture.ReleaseTemporary(buffer0);
                buffer0 = buffer1;
                buffer1 = RenderTexture.GetTemporary(rtW, rtH, 0);

                Graphics.Blit(buffer0, buffer1, TargetMaterial, 2);       // 第三个Pass

                RenderTexture.ReleaseTemporary(buffer0);
                buffer0 = buffer1;
            }

            TargetMaterial.SetTexture("_Bloom", buffer0);                // 较亮区域存到_Bloom
            Graphics.Blit(src, dest, TargetMaterial, 3);                 // 第四个Pass最后混合

            RenderTexture.ReleaseTemporary(buffer0);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
Example #18
0
        void InitTexture()
        {
            Texture2D originTexture = (Texture2D)TargetMaterial.GetTexture(mTargetMaterialProperty);

            if (originTexture == null)
            {
                Debug.LogError(GetType() + "->InitTarget: target texture not found !");
                return;
            }

            // pixels
            mTargetPixels = originTexture.GetPixels32();

            // target texture
            mTargetTexture = new Texture2D(originTexture.width, originTexture.height, TextureFormat.ARGB32, false);
            mTargetTexture.SetPixels32(mTargetPixels);
            mTargetTexture.Apply();
            TargetMaterial.SetTexture(mTargetMaterialProperty, mTargetTexture);
        }
        // Token: 0x0600025B RID: 603 RVA: 0x000150B4 File Offset: 0x000132B4
        public void WriteMateFile(string infile, string outfilepath, TargetMaterial trgtMat)
        {
            bool flag;

            using (BinaryReader binaryReader = new BinaryReader(this.GetStream(infile, out flag), Encoding.UTF8))
            {
                string text = binaryReader.ReadString();
                if (flag || binaryReader.BaseStream.Position > 0L)
                {
                    if (text == FileConst.HEAD_MATE)
                    {
                        this.WriteMateFile(binaryReader, text, outfilepath, trgtMat);
                        return;
                    }
                    StringBuilder stringBuilder = LogUtil.Error(new object[]
                    {
                        "正しいmateファイルではありません。ヘッダが不正です。",
                        text,
                        ", infile=",
                        infile
                    });
                    throw new ACCException(stringBuilder.ToString());
                }
            }
            using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(FileUtilEx.Instance.LoadInternal(infile), false), Encoding.UTF8))
            {
                string text2 = binaryReader2.ReadString();
                if (text2 == FileConst.HEAD_MATE)
                {
                    this.WriteMateFile(binaryReader2, text2, outfilepath, trgtMat);
                }
                StringBuilder stringBuilder2 = LogUtil.Error(new object[]
                {
                    "正しいmateファイルではありません。ヘッダが不正です。",
                    text2,
                    ", infile=",
                    infile
                });
                throw new ACCException(stringBuilder2.ToString());
            }
        }
    // 也可以在OnPostRender()中更新
    private void Update()
    {
        if (TargetMaterial != null && targets != null)
        {
            TargetMaterial.SetFloat("_Width", width);
            TargetMaterial.SetColor("_Color", color);

            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i] == null)
                {
                    continue;
                }
                meshFilters = targets[i].GetComponentsInChildren <MeshFilter>();
                for (int j = 0; j < meshFilters.Length; j++)
                {
                    Graphics.DrawMesh(meshFilters[j].sharedMesh, meshFilters[j].transform.localToWorldMatrix, TargetMaterial, 0);   // 对选中物体再次渲染。
                }
            }
        }
    }
Example #21
0
    void OnRenderImage(RenderTexture src, RenderTexture dest)
    {
        if (TargetMaterial != null)
        {
            TargetMaterial.SetFloat("_BlurSize", blurSize);

            // 上一帧的矩阵
            TargetMaterial.SetMatrix("_PreviousViewProjectionMatrix", previousViewProjectionMatrix);

            // 投影矩阵 * 视角矩阵 ,用于给下一帧计算该帧时的位置
            Matrix4x4 currentViewProjectionMatrix = TargetCamera.projectionMatrix * TargetCamera.worldToCameraMatrix;
            // 矩阵取逆,用于计算该帧的位置
            Matrix4x4 currentViewProjectionInverseMatrix = currentViewProjectionMatrix.inverse;
            TargetMaterial.SetMatrix("_CurrentViewProjectionInverseMatrix", currentViewProjectionInverseMatrix);
            previousViewProjectionMatrix = currentViewProjectionMatrix;
            Graphics.Blit(src, dest, TargetMaterial);
        }
        else
        {
            Graphics.Blit(src, dest);
        }
    }
Example #22
0
        private void WriteTex(BinaryWriter writer, string propName, TargetMaterial tm, TargetTexture trgtTex)
        {
            Write(writer, "tex");
            Write(writer, propName);

            var sub = "tex2d";

            if (trgtTex == null || trgtTex.tex == null)
            {
                sub = "null";
            }
            Write(writer, sub);
            switch (sub)
            {
            case "tex2d":
                // カラー変更時にはファイル生成するため、ファイル名も変更が必要
                if (trgtTex.fileChanged || trgtTex.colorChanged)
                {
                    Write(writer, trgtTex.EditFileNameNoExt()); // 拡張子不要
                    //Write(writer, trgtTex.EditFileName());
                    Write(writer, trgtTex.EditTxtPath());

                    Write(writer, tm.editedMat.material.GetTextureOffset(propName));
                    Write(writer, tm.editedMat.material.GetTextureScale(propName));
                }
                break;

            case "null":
                break;

            case "texRT":            // texRTはない
                writer.Write(string.Empty);
                writer.Write(string.Empty);
                break;
            }
        }
Example #23
0
    private void Update()
    {
        if (TargetMaterial != null && targets != null)
        {
            TargetMaterial.SetFloat("_Width", width);
            TargetMaterial.SetColor("_Color", color);

            for (int i = 0; i < targets.Length; i++)
            {
                if (targets[i] == null)
                {
                    continue;
                }
                meshFilters = targets[i].GetComponentsInChildren <MeshFilter>();
                for (int j = 0; j < meshFilters.Length; j++)
                {
                    for (int k = 0; k < meshFilters[j].sharedMesh.subMeshCount; k++)    // 每个网格还有子网格
                    {
                        Graphics.DrawMesh(meshFilters[j].sharedMesh, meshFilters[j].transform.localToWorldMatrix, TargetMaterial, 0, MainCamera, k);
                    }
                }
            }
        }
    }
        void Update()
        {
            var pInfos = shaderValues.GetType().GetFields();

            foreach (var p in pInfos)
            {
                if (Attribute.IsDefined(p, typeof(ShaderValue)))
                {
                    if (p.FieldType == typeof(Color))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetColor(p.Name, (Color)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(Color[]))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetColorArray(p.Name, (Color[])p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(List <Color>))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetColorArray(p.Name, (List <Color>)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(float))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetFloat(p.Name, (float)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(float[]))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetFloatArray(p.Name, (float[])p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(List <float>))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetFloatArray(p.Name, (List <float>)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(int))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetInt(p.Name, (int)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(bool))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetInt(p.Name, (bool)p.GetValue(shaderValues) ? 1 : 0);
                        }
                    }
                    else if (p.FieldType == typeof(Matrix4x4))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetMatrix(p.Name, (Matrix4x4)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(Matrix4x4[]))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetMatrixArray(p.Name, (Matrix4x4[])p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(List <Matrix4x4>))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetMatrixArray(p.Name, (List <Matrix4x4>)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(string))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetOverrideTag(p.Name, (string)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(Texture2D))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetTexture(p.Name, (Texture2D)p.GetValue(shaderValues));
                        }

                        //a vector2 can be a vector, or a material offset or scale
                        //TODO: test this!
                    }
                    else if (p.FieldType == typeof(Vector2))
                    {
                        if (Attribute.IsDefined(p, typeof(TextureOffset)))
                        {
                            foreach (Material TargetMaterial in TargetMaterials)
                            {
                                TargetMaterial.SetTextureOffset(((TextureOffset)Attribute.GetCustomAttribute(p, typeof(TextureOffset))).Name, (Vector2)p.GetValue(shaderValues));
                            }
                        }
                        else if (Attribute.IsDefined(p, typeof(TextureScale)))
                        {
                            foreach (Material TargetMaterial in TargetMaterials)
                            {
                                TargetMaterial.SetTextureOffset(((TextureScale)Attribute.GetCustomAttribute(p, typeof(TextureScale))).Name, (Vector2)p.GetValue(shaderValues));
                            }
                        }
                        else
                        {
                            foreach (Material TargetMaterial in TargetMaterials)
                            {
                                TargetMaterial.SetVector(p.Name, (Vector2)p.GetValue(shaderValues));
                            }
                        }
                    }
                    else if (p.FieldType == typeof(Vector3))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetVector(p.Name, (Vector3)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(Vector4))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetVector(p.Name, (Vector4)p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(Vector4[]))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetVectorArray(p.Name, (Vector4[])p.GetValue(shaderValues));
                        }
                    }
                    else if (p.FieldType == typeof(List <Vector4>))
                    {
                        foreach (Material TargetMaterial in TargetMaterials)
                        {
                            TargetMaterial.SetVectorArray(p.Name, (List <Vector4>)p.GetValue(shaderValues));
                        }
                    }
                }
            }
        }
Example #25
0
        // modelファイル内のマテリアル情報を対象とした転送処理
        // .mateファイルのheader, version, name1は存在しない
        public void TransferMaterial(BinaryReader reader, BinaryWriter writer, TargetMaterial trgtMat, bool overwrite)
        {
            // マテリアル名
            reader.ReadString();
            writer.Write(trgtMat.editname);

            string shaderName1 = reader.ReadString();
            string shaderName2 = reader.ReadString();

            if (trgtMat.shaderChanged)
            {
                shaderName1 = trgtMat.ShaderNameOrDefault(shaderName1);
                shaderName2 = ShaderType.GetShader2(shaderName1);
            }
            writer.Write(shaderName1);
            writer.Write(shaderName2);

            //var matType = trgtMat.editedMat.type1;
            var shaderType = trgtMat.editedMat.type;
            var writed     = new HashSet <PropKey>();

            while (reader.PeekChar() != -1)
            {
                string type = reader.ReadString();
                //writer.Write(type);
                if (type == "end")
                {
                    break;
                }

                string propName = reader.ReadString();
                //shaderType.
                var shaderProp = shaderType.GetShaderProp(propName);
                if (shaderProp == null)
                {
                    // シェーダに対応していないプロパティは読み捨て
                    DiscardMateProp(reader, type);
                    continue;
                }

                if (!overwrite)
                {
                    // .mateからマテリアル変更で書き換えるため、そのまま転送
                    // ただし、model上に記述されたマテリアルで指定されたtexファイルは存在する必要あり
                    TransferMateProp(reader, writer, type, propName);
                }
                else
                {
                    switch (type)
                    {
                    case "tex":
                        // .mateによるマテリアル変更がないケースのみ書き換える
                        //
                        // texプロパティがある場合にのみ設定
                        TargetTexture trgtTex = null;
                        trgtMat.texDic.TryGetValue(shaderProp.key, out trgtTex);
                        if (trgtTex == null || trgtTex.tex == null || trgtTex.fileChanged || trgtTex.colorChanged)
                        {
                            // 変更がある場合にのみ書き換え (空のものはnull指定)
                            if (trgtTex != null)
                            {
                                trgtTex.worksuffix = trgtMat.worksuffix;
                            }
                            string srcfile = null;
                            TransferMateProp(reader, null, type, null, ref srcfile);
                            if (trgtTex != null)
                            {
                                trgtTex.workfilename = srcfile;
                            }

                            WriteTex(writer, propName, trgtMat, trgtTex);
                        }
                        else
                        {
                            // 変更がないものはそのまま転送
                            TransferMateProp(reader, writer, type, propName);
                        }
                        break;

                    case "col":
                    case "vec":
                        Write(writer, type, propName);
                        Write(writer, trgtMat.editedMat.material.GetColor(propName));

                        DiscardMateProp(reader, type);
                        break;

                    case "f":
                        Write(writer, type, propName);
                        Write(writer, trgtMat.editedMat.material.GetFloat(propName));

                        DiscardMateProp(reader, type);
                        break;
                    }
                }
                writed.Add(shaderProp.key);
            }

            // シェーダで設定されるプロパティ数が一致しない場合、不足propを追記

            if (shaderType.KeyCount() != writed.Count())
            {
                foreach (var texProp in shaderType.texProps)
                {
                    if (writed.Contains(texProp.key))
                    {
                        continue;
                    }

                    TargetTexture trgtTex = null;
                    trgtMat.texDic.TryGetValue(texProp.key, out trgtTex);
                    WriteTex(writer, texProp.keyName, trgtMat, trgtTex);
                }

                foreach (var prop in shaderType.colProps)
                {
                    if (writed.Contains(prop.key))
                    {
                        continue;
                    }

                    Write(writer, prop.type.ToString(), prop.keyName);
                    Write(writer, trgtMat.editedMat.material.GetColor(prop.propId));
                }

                foreach (var prop in shaderType.fProps)
                {
                    if (writed.Contains(prop.key))
                    {
                        continue;
                    }

                    Write(writer, prop.type.ToString(), prop.keyName);
                    Write(writer, trgtMat.editedMat.material.GetFloat(prop.propId));
                }
            }

            writer.Write("end");
        }
Example #26
0
        public void WriteMateFile(BinaryReader reader, string header, string outfilepath, TargetMaterial trgtMat)
        {
            using (var writer = new BinaryWriter(File.OpenWrite(outfilepath))) {
                writer.Write(header);              // ヘッダ (CM3D2_MATERIAL)
                writer.Write(reader.ReadInt32());  // バージョン
                writer.Write(reader.ReadString()); // マテリアル名1

                TransferMaterial(reader, writer, trgtMat, true);
            }
        }
        // Token: 0x0600025A RID: 602 RVA: 0x00014E14 File Offset: 0x00013014
        public bool TransferModel(BinaryReader reader, string header, BinaryWriter writer, SlotMaterials slotMat)
        {
            writer.Write(header);
            int num = reader.ReadInt32();

            writer.Write(num);
            writer.Write(reader.ReadString());
            writer.Write(reader.ReadString());
            int num2 = reader.ReadInt32();

            writer.Write(num2);
            for (int i = 0; i < num2; i++)
            {
                writer.Write(reader.ReadString());
                writer.Write(reader.ReadByte());
            }
            for (int j = 0; j < num2; j++)
            {
                int value = reader.ReadInt32();
                writer.Write(value);
            }
            for (int k = 0; k < num2; k++)
            {
                this.TransferVec(reader, writer, 7);
                if (num >= 2001)
                {
                    bool flag = reader.ReadBoolean();
                    writer.Write(flag);
                    if (flag)
                    {
                        this.TransferVec(reader, writer, 3);
                    }
                }
            }
            int num3 = reader.ReadInt32();
            int num4 = reader.ReadInt32();
            int num5 = reader.ReadInt32();

            writer.Write(num3);
            writer.Write(num4);
            writer.Write(num5);
            for (int l = 0; l < num5; l++)
            {
                writer.Write(reader.ReadString());
            }
            for (int m = 0; m < num5; m++)
            {
                this.TransferVec(reader, writer, 16);
            }
            for (int n = 0; n < num3; n++)
            {
                this.TransferVec(reader, writer, 8);
            }
            int num6 = reader.ReadInt32();

            writer.Write(num6);
            for (int num7 = 0; num7 < num6; num7++)
            {
                this.TransferVec4(reader, writer);
            }
            for (int num8 = 0; num8 < num3; num8++)
            {
                for (int num9 = 0; num9 < 4; num9++)
                {
                    writer.Write(reader.ReadUInt16());
                }
                this.TransferVec4(reader, writer);
            }
            for (int num10 = 0; num10 < num4; num10++)
            {
                int num11 = reader.ReadInt32();
                writer.Write(num11);
                for (int num12 = 0; num12 < num11; num12++)
                {
                    writer.Write(reader.ReadInt16());
                }
            }
            int num13 = reader.ReadInt32();

            writer.Write(num13);
            for (int num14 = 0; num14 < num13; num14++)
            {
                TargetMaterial targetMaterial = slotMat.Get(num14);
                this.TransferMaterial(reader, writer, targetMaterial, targetMaterial.onlyModel);
            }
            while (reader.PeekChar() != -1)
            {
                string text = reader.ReadString();
                writer.Write(text);
                if (text == "end")
                {
                    break;
                }
                if (!(text != "morph"))
                {
                    string value2 = reader.ReadString();
                    writer.Write(value2);
                    int num15 = reader.ReadInt32();
                    writer.Write(num15);
                    for (int num16 = 0; num16 < num15; num16++)
                    {
                        writer.Write(reader.ReadUInt16());
                        this.TransferVec(reader, writer, 6);
                    }
                }
            }
            return(true);
        }
 // Token: 0x0600025C RID: 604 RVA: 0x000151F4 File Offset: 0x000133F4
 public void WriteMateFile(BinaryReader reader, string header, string outfilepath, TargetMaterial trgtMat)
 {
     using (BinaryWriter binaryWriter = new BinaryWriter(File.OpenWrite(outfilepath)))
     {
         binaryWriter.Write(header);
         binaryWriter.Write(reader.ReadInt32());
         binaryWriter.Write(reader.ReadString());
         this.TransferMaterial(reader, binaryWriter, trgtMat, true);
     }
 }
        // Token: 0x0600025D RID: 605 RVA: 0x00015254 File Offset: 0x00013454
        public void TransferMaterial(BinaryReader reader, BinaryWriter writer, TargetMaterial trgtMat, bool overwrite)
        {
            reader.ReadString();
            writer.Write(trgtMat.editname);
            string text  = reader.ReadString();
            string value = reader.ReadString();

            if (trgtMat.shaderChanged)
            {
                text  = trgtMat.ShaderNameOrDefault(text);
                value = ShaderType.GetMateName(text);
            }
            writer.Write(text);
            writer.Write(value);
            ShaderType        type    = trgtMat.editedMat.type;
            HashSet <PropKey> hashSet = new HashSet <PropKey>();

            for (;;)
            {
                string text2 = reader.ReadString();
                if (text2 == "end")
                {
                    break;
                }
                string     text3      = reader.ReadString();
                ShaderProp shaderProp = type.GetShaderProp(text3);
                if (shaderProp == null)
                {
                    this.DiscardMateProp(reader, text2);
                }
                else
                {
                    string a;
                    if (!overwrite)
                    {
                        this.TransferMateProp(reader, writer, text2, text3);
                    }
                    else if ((a = text2) != null)
                    {
                        if (!(a == "tex"))
                        {
                            if (!(a == "col") && !(a == "vec"))
                            {
                                if (a == "f")
                                {
                                    this.Write(writer, new string[]
                                    {
                                        text2,
                                        text3
                                    });
                                    this.Write(writer, trgtMat.editedMat.material.GetFloat(text3));
                                    this.DiscardMateProp(reader, text2);
                                }
                            }
                            else
                            {
                                this.Write(writer, new string[]
                                {
                                    text2,
                                    text3
                                });
                                this.Write(writer, trgtMat.editedMat.material.GetColor(text3));
                                this.DiscardMateProp(reader, text2);
                            }
                        }
                        else
                        {
                            TargetTexture targetTexture;
                            trgtMat.texDic.TryGetValue(shaderProp.key, out targetTexture);
                            if (targetTexture == null || targetTexture.tex == null || targetTexture.fileChanged || targetTexture.colorChanged)
                            {
                                if (targetTexture != null)
                                {
                                    targetTexture.worksuffix = trgtMat.worksuffix;
                                }
                                string workfilename = null;
                                this.TransferMateProp(reader, null, text2, null, ref workfilename);
                                if (targetTexture != null)
                                {
                                    targetTexture.workfilename = workfilename;
                                }
                                this.WriteTex(writer, text3, trgtMat, targetTexture);
                            }
                            else
                            {
                                this.TransferMateProp(reader, writer, text2, text3);
                            }
                        }
                    }
                    hashSet.Add(shaderProp.key);
                }
            }
            if (type.KeyCount() != hashSet.Count)
            {
                foreach (ShaderPropTex shaderPropTex in type.texProps)
                {
                    if (!hashSet.Contains(shaderPropTex.key))
                    {
                        TargetTexture trgtTex;
                        trgtMat.texDic.TryGetValue(shaderPropTex.key, out trgtTex);
                        this.WriteTex(writer, shaderPropTex.keyName, trgtMat, trgtTex);
                    }
                }
                foreach (ShaderPropColor shaderPropColor in type.colProps)
                {
                    if (!hashSet.Contains(shaderPropColor.key))
                    {
                        this.Write(writer, new string[]
                        {
                            shaderPropColor.type.ToString(),
                            shaderPropColor.keyName
                        });
                        this.Write(writer, trgtMat.editedMat.material.GetColor(shaderPropColor.propId));
                    }
                }
                foreach (ShaderPropFloat shaderPropFloat in type.fProps)
                {
                    if (!hashSet.Contains(shaderPropFloat.key))
                    {
                        this.Write(writer, new string[]
                        {
                            shaderPropFloat.type.ToString(),
                            shaderPropFloat.keyName
                        });
                        this.Write(writer, trgtMat.editedMat.material.GetFloat(shaderPropFloat.propId));
                    }
                }
            }
            writer.Write("end");
        }
Example #30
0
        public bool SaveFiles(ACCMenu menu)
        {
            var outDir = fileUtil.GetACCDirectory(trgtMenu.editfile);

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            LogUtil.Debug("output path:", outDir);
            string filepath = Path.Combine(outDir, menu.EditFileName());

            // menu出力
            ACCMenu.WriteMenuFile(filepath, menu);

            var writeFiles = new HashSet <string>();

            // filterがあれば、適用しアイコンを変更
            string iconfilepath = Path.Combine(outDir, menu.EditIconFileName());

            writeFiles.Add(iconfilepath);
            string icontxt = settings.txtPrefixTex + iconfilepath;

            fileUtil.CopyTex(menu.icon, iconfilepath, icontxt, null);
            LogUtil.Debug("tex file:", iconfilepath);

            // model 出力 (additem)
            foreach (var pair in menu.itemFiles)
            {
                string infile = pair.Key;
                Item   item   = pair.Value;
                if (item.needUpdate)
                {
                    string filename = item.EditFileName();
                    if (HasAlreadyWritten(writeFiles, filename))
                    {
                        continue;
                    }

                    string modelfilepath = Path.Combine(outDir, filename);

                    // modelファイルのスロットのマテリアル/テクスチャ情報を抽出
                    SlotMaterials slotMat = menu.slotMaterials[item.slot];
                    // onlyModelでない場合はshader変更のみとしておく
                    // material slotとmatNoで特定
                    // texture  propName
                    // 必要に応じてtex出力
                    fileUtil.WriteModelFile(infile, modelfilepath, slotMat);
                    LogUtil.Debug("model file:", modelfilepath);
                }
            }

            // mate出力
            foreach (var tm in menu.slotMaterials.Values)
            {
                foreach (var trgtMat in tm.materials)
                {
                    // マテリアル変更が指定された場合 => TODO 切り替え可能とする場合:menuにマテリアル変更を追加する必要あり
                    if (!trgtMat.onlyModel)
                    {
                        var filename = trgtMat.EditFileName();
                        if (HasAlreadyWritten(writeFiles, filename))
                        {
                            continue;
                        }

                        string matefilepath = Path.Combine(outDir, filename);
                        fileUtil.WriteMateFile(trgtMat.filename, matefilepath, trgtMat);
                        LogUtil.Debug("mate file:", matefilepath);

                        if (trgtMat.needPmatChange)
                        {
                            var    name         = Path.GetFileNameWithoutExtension(filename);
                            var    pmatfile     = name + FileConst.EXT_PMAT;
                            string pmatfilepath = Path.Combine(outDir, pmatfile);
                            fileUtil.WritePmat(pmatfilepath, trgtMat.editname,
                                               trgtMat.RenderQueue(), trgtMat.ShaderName());
                            LogUtil.Debug("pmat file:", pmatfilepath);
                        }
                    }

                    // テクスチャ出力
                    foreach (var trgtTex in trgtMat.texDic.Values)
                    {
                        if (!trgtTex.needOutput)
                        {
                            continue;
                        }

                        var tex2d = trgtTex.tex as Texture2D;
                        if (tex2d == null)
                        {
                            LogUtil.Debug("tex is not Texture2D", trgtTex.editname);
                            continue;
                            // TODO RenderTexの場合は無理やりTexture2Dに変換も可能だが…
                        }
                        var texfilename = trgtTex.EditFileName();
                        if (HasAlreadyWritten(writeFiles, texfilename))
                        {
                            continue;
                        }

                        string texfilepath = Path.Combine(outDir, texfilename);
                        fileUtil.WriteTexFile(texfilepath, trgtTex.EditTxtPath(), tex2d.EncodeToPNG());
                        LogUtil.Debug("tex file:", texfilepath);
                    }
                }
            }

            // めくれ、ずらし用menuファイルの出力
            foreach (var res in menu.resFiles.Values)
            {
                // 各モデルファイルで出力が必要となるファイルについて、
                // 元が同名のファイルを参照している場合でも関係なく出力
                // 設定が違う場合もある上、editnameはすべて別名になるはず
                var filename = res.EditFileName();
                if (HasAlreadyWritten(writeFiles, filename))
                {
                    continue;
                }


                string menufilepath  = Path.Combine(outDir, filename);
                var    toCreateFiles = fileUtil.WriteMenuFile(res.filename, menufilepath, res);
                LogUtil.Debug("menu file:", menufilepath);

                foreach (var toCreate in toCreateFiles)
                {
                    // modelを出力
                    if (toCreate.item != null)
                    {
                        var filename0 = toCreate.replaced;
                        if (HasAlreadyWritten(writeFiles, filename0))
                        {
                            continue;
                        }

                        string        modelfilepath = Path.Combine(outDir, filename0);
                        SlotMaterials slotMat       = menu.slotMaterials[toCreate.item.slot];
                        // TODO リプレースが想定される情報であるかチェック
                        fileUtil.WriteModelFile(toCreate.source, modelfilepath, slotMat);

                        // .mate出力
                    }
                    else if (toCreate.material != null)
                    {
                        TargetMaterial trgtMat   = toCreate.material;
                        var            filename0 = toCreate.replaced;
                        if (HasAlreadyWritten(writeFiles, filename0))
                        {
                            continue;
                        }

                        // mate出力==別のtexファイルを出力する可能性有り
                        string matefilepath = Path.Combine(outDir, filename0);
                        fileUtil.WriteMateFile(toCreate.source, matefilepath, trgtMat);
                        // マテリアル名は上位と同じにして、同一pmatを使用する
                        //if (trgtMat.needPmatChange) {
                        //    var name = Path.GetFileNameWithoutExtension(filename);
                        //    var pmatfile = name + FileConst.EXT_PMAT;
                        //    string pmatfilepath = Path.Combine(outDir, pmatfile);
                        //    outUtil.WritePmat(pmatfilepath, trgtMat.editname,
                        //                      trgtMat.RenderQueue(), trgtMat.ShaderName());
                        //    LogUtil.DebugLog("pmatファイルを出力しました。", pmatfilepath);
                        //}

                        foreach (var tex in trgtMat.texDic.Values)
                        {
                            if (!tex.needOutput)
                            {
                                continue;
                            }

                            var tex2d = tex.tex as Texture2D;
                            if (tex2d == null)
                            {
                                LogUtil.Debug("tex is not 2D", tex.editname);
                                continue;
                            }
                            var texfilename = tex.EditFileName();
                            if (HasAlreadyWritten(writeFiles, texfilename))
                            {
                                continue;
                            }

                            // テクスチャをロードし、フィルタを適用
                            Texture2D loadedTex   = null;
                            Texture2D filteredTex = null;
                            if (!tex.fileChanged)   // texファイル変更済の場合はロードされたデータ済みから出力(そのままtex2dを使用)
                            {
                                string texfile = tex.workfilename + FileConst.EXT_TEXTURE;
                                if (!fileUtil.Exists(texfile))
                                {
                                    LogUtil.LogF("リソース参照で使用されているtexファイル({0})が見つかりません。texファイルを出力できません。", texfile);
                                    continue;
                                }
                                loadedTex = TexUtil.Instance.Load(texfile);
                                tex2d     = loadedTex;
                            }

                            if (tex.colorChanged)
                            {
                                filteredTex = ACCTexturesView.Filter(tex2d, tex.filter);
                                tex2d       = filteredTex;
                            }
                            string texfilepath = Path.Combine(outDir, texfilename);
                            fileUtil.WriteTexFile(texfilepath, tex.EditTxtPath(), tex2d.EncodeToPNG());
                            LogUtil.Debug("tex file:", texfilepath);

                            if (loadedTex != null)
                            {
                                UnityEngine.Object.DestroyImmediate(loadedTex);
                            }
                            if (filteredTex != null)
                            {
                                UnityEngine.Object.DestroyImmediate(filteredTex);
                            }
                        }
                    }
                }
            }
            return(true);
        }