Эх сурвалжийг харах

添加服装合成的渐变遮罩

leiyasi 1 жил өмнө
parent
commit
07e8ef2063

+ 22 - 0
GameClient/Assets/Game/HotUpdate/Assets/FGUICanvas.cs

@@ -0,0 +1,22 @@
+using System.Collections;
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace GFGGame
+{
+    /// <summary>
+    /// FGUI中添加UGUI,需要在Canvas上挂载该脚本调整位置
+    /// </summary>
+    public class FGUICanvas : MonoBehaviour
+    {
+        private RectTransform canvasRect;
+
+        private void Start()
+        {
+            // FGUI会自动修改Canvas的参数,需要调整一下位置
+            canvasRect = transform.GetComponent<RectTransform>();
+            canvasRect.pivot = Vector2.one * 0.5f;
+            canvasRect.anchoredPosition = Vector2.zero;
+        }
+    }
+}

+ 11 - 0
GameClient/Assets/Game/HotUpdate/Assets/FGUICanvas.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 15a9cc6dd7f4b9547a1b74da745cfd7a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 15 - 9
GameClient/Assets/Game/HotUpdate/FairyGUI/GenCode/ClothingSynthetic/UI_ClothingSyntheticUI.cs

@@ -8,10 +8,9 @@ namespace UI.ClothingSynthetic
     {
         public GComponent target;
         public GLoader m_loaBg;
-        public GButton m_btnBack;
-        public GButton m_btnHome;
-        public GComponent m_valueBar;
         public UI_Component1WithMask m_compHolder;
+        public GLoader m_loaBg2;
+        public GGraph m_loaBg2Pos;
         public GGraph m_posHelper;
         public UI_CompItemInfo m_compItemInfo;
         public GTextField m_txtSuitName;
@@ -20,6 +19,9 @@ namespace UI.ClothingSynthetic
         public GList m_listClothing;
         public GButton m_btnProduction;
         public GComponent m_comCostCurrency;
+        public GButton m_btnBack;
+        public GButton m_btnHome;
+        public GComponent m_valueBar;
         public Transition m_hide;
         public Transition m_show;
         public const string URL = "ui://4f294tdkj5391";
@@ -70,10 +72,9 @@ namespace UI.ClothingSynthetic
         private void Init(GComponent comp)
         {
             m_loaBg = (GLoader)comp.GetChild("loaBg");
-            m_btnBack = (GButton)comp.GetChild("btnBack");
-            m_btnHome = (GButton)comp.GetChild("btnHome");
-            m_valueBar = (GComponent)comp.GetChild("valueBar");
             m_compHolder = (UI_Component1WithMask)UI_Component1WithMask.Create(comp.GetChild("compHolder"));
+            m_loaBg2 = (GLoader)comp.GetChild("loaBg2");
+            m_loaBg2Pos = (GGraph)comp.GetChild("loaBg2Pos");
             m_posHelper = (GGraph)comp.GetChild("posHelper");
             m_compItemInfo = (UI_CompItemInfo)UI_CompItemInfo.Create(comp.GetChild("compItemInfo"));
             m_txtSuitName = (GTextField)comp.GetChild("txtSuitName");
@@ -82,17 +83,19 @@ namespace UI.ClothingSynthetic
             m_listClothing = (GList)comp.GetChild("listClothing");
             m_btnProduction = (GButton)comp.GetChild("btnProduction");
             m_comCostCurrency = (GComponent)comp.GetChild("comCostCurrency");
+            m_btnBack = (GButton)comp.GetChild("btnBack");
+            m_btnHome = (GButton)comp.GetChild("btnHome");
+            m_valueBar = (GComponent)comp.GetChild("valueBar");
             m_hide = comp.GetTransition("hide");
             m_show = comp.GetTransition("show");
         }
         public void Dispose(bool disposeTarget = false)
         {
             m_loaBg = null;
-            m_btnBack = null;
-            m_btnHome = null;
-            m_valueBar = null;
             m_compHolder.Dispose();
             m_compHolder = null;
+            m_loaBg2 = null;
+            m_loaBg2Pos = null;
             m_posHelper = null;
             m_compItemInfo.Dispose();
             m_compItemInfo = null;
@@ -102,6 +105,9 @@ namespace UI.ClothingSynthetic
             m_listClothing = null;
             m_btnProduction = null;
             m_comCostCurrency = null;
+            m_btnBack = null;
+            m_btnHome = null;
+            m_valueBar = null;
             m_hide = null;
             m_show = null;
             if(disposeTarget && target != null)

+ 8 - 0
GameClient/Assets/Game/HotUpdate/Utils/ResPathUtil.cs

@@ -9,6 +9,8 @@ namespace GFGGame
         public static readonly string UI_DIR_PATH = "Assets/ResIn/UI";
         public static readonly string UUI_DIR_PATH = "Assets/ResIn/UUI";
         public static readonly string PREFAB_DIR_PATH = "Assets/ResIn/Prefab";
+        public static readonly string MATERIAL_DIR_PATH = "Assets/ResIn/Material";
+
         public static readonly string LoginRes_DIR_PATH = "Assets/ResIn/LoginRes";
         public static readonly string TEXTURE_FIGHT_DIR_PATH = "Assets/ResIn/Fight";
         public static readonly string CONFIG_DIR_PATH = "Assets/Game/CSShare/Sqlite";
@@ -150,6 +152,12 @@ namespace GFGGame
         {
             return $"{PREFAB_DIR_PATH}/{res}.{extName}";
         }
+
+        public static string GetMaterialPath(string res, string extName = "mat")
+        {
+            return $"{MATERIAL_DIR_PATH}/{res}.{extName}";
+        }
+
         public static string GetLoginResPath(string res, string extName = "prefab")
         {
             return $"{LoginRes_DIR_PATH}/{res}.{extName}";

+ 37 - 2
GameClient/Assets/Game/HotUpdate/Views/ClothingSynthetic/ClothingSyntheticView.cs

@@ -6,6 +6,7 @@ using System;
 using ET;
 using System.Collections;
 using System.Threading.Tasks;
+using YooAsset;
 
 namespace GFGGame
 {
@@ -50,6 +51,7 @@ namespace GFGGame
 
         public override void Dispose()
         {
+            RemoveSoftMask();
             if (_valueBarController != null)
             {
                 _valueBarController.Dispose();
@@ -104,6 +106,8 @@ namespace GFGGame
             _ui.m_btnBack.onClick.Add(OnClickBtnBack);
             _ui.m_btnProduction.onClick.Add(OnClickBtnProcuction);
             _ui.m_btnHome.onClick.Add(OnClickBtnHome);
+            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
+
             UpdateMaskHeight();
 
         }
@@ -123,8 +127,7 @@ namespace GFGGame
                 _selectedItemId = (this.viewData as object[]).Length > 1 ? (int)(this.viewData as object[])[1] : 0;
             }
             _valueBarController.OnShown();
-            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
-
+            _ui.m_loaBg2.url = ResPathUtil.GetBgImgPath("hc_bj_1");
             UpdateClothingList(false);
 
             Timers.inst.AddUpdate(CheckGuide);
@@ -137,6 +140,7 @@ namespace GFGGame
             _ui.m_listMaterias.selectedIndex = 0;
             Timers.inst.Remove(CheckGuide);
             _dressUpObjUI.dressUpObj.TakeOffAll();
+
         }
         protected override void RemoveEventListener()
         {
@@ -212,6 +216,8 @@ namespace GFGGame
         private EaseType ease = EaseType.CubicOut;
         private void UpdateRole(bool tween)
         {
+            // 隐藏遮罩
+            _ui.m_loaBg2.visible = false;
             // 根据高度比例放大(越高越大)
             float rate = Screen.height * 1080f / 1920f / Screen.width;
             // 平板会比宽手机更宽,设定最小值防止缩小
@@ -246,11 +252,13 @@ namespace GFGGame
             }
             else if (Array.IndexOf(LOWER_BODY_Y_ARR, type) >= 0)
             {
+                _ui.m_loaBg2.visible = true;
                 _compMover.target.TweenMoveY(LOWER_BODY_Y + dy, duration).SetEase(ease);
                 _compMover.target.TweenScale(new Vector2(LOWER_BODY_SCALE * rate, LOWER_BODY_SCALE* rate), duration).SetEase(ease);
             }
             else if (Array.IndexOf(SHOES_Y_ARR, type) >= 0)
             {
+                _ui.m_loaBg2.visible = true;
                 _compMover.target.TweenMoveY(SHOES_Y + dy, duration).SetEase(ease);
                 _compMover.target.TweenScale(new Vector2(SHOES_SCALE * rate, SHOES_SCALE * rate), duration).SetEase(ease);
             }
@@ -475,6 +483,33 @@ namespace GFGGame
         {
             await Task.Delay(5);
             _ui.m_compHolder.m_mask.height = _ui.m_posHelper.height;
+            SetSoftMask();
+        }
+
+        /// <summary>
+        /// 创建二层渐变背景遮罩
+        /// </summary>
+        private void SetSoftMask()
+        {
+            var handle = YooAssets.LoadAssetSync<Material>(ResPathUtil.GetPrefabPath("ImageGradient", "mat"));
+            Material m = handle.AssetObject as Material;
+            _ui.m_loaBg2.material = m;
+            _ui.m_loaBg2.position = _ui.m_loaBg.position;
+            float startY = _ui.m_loaBg2Pos.position.y;
+            float endY = _ui.m_posHelper.position.y;
+            float rate = 1 - ((Mathf.Abs(startY - endY)) / _ui.m_loaBg2.height);
+            _ui.m_loaBg2.material.SetFloat("_MinHeight", rate - 0.01f);
+            _ui.m_loaBg2.material.SetFloat("_MaxHeight", rate - 0.03f);
+        }
+
+        private void RemoveSoftMask()
+        {
+            AssetReleaser assetReleaser = _ui.m_loaBg2.displayObject.gameObject.GetComponent<AssetReleaser>();
+            if (assetReleaser != null)
+            {
+                //必须立即销毁,不能改为Destroy代替
+                GameObject.DestroyImmediate(assetReleaser);
+            }
         }
     }
 }

+ 0 - 5
GameClient/Assets/Game/HotUpdate/Views/MainStory/StoryDialogView.cs

@@ -1041,11 +1041,6 @@ namespace GFGGame
             // 将RawImg放在FGUI上
             GoWrapper goWrapper = new GoWrapper(_selfHeadImgObj);
             _ui.m_dialogHead.m_compDressUp.m_holder.SetNativeObject(goWrapper);
-
-            // FGUI会自动修改Canvas的参数,需要调整一下位置
-            RectTransform canvas = _selfHeadImgObj.transform.GetComponent<RectTransform>();
-            canvas.pivot = Vector2.one * 0.5f;
-            canvas.anchoredPosition = Vector2.zero;
         }
 
         private void DestroyHeadImg()

+ 8 - 0
GameClient/Assets/ResIn/Material.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 003a7ea568804294c94a860b7ce88416
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 91 - 0
GameClient/Assets/ResIn/Prefab/ImageGradient.mat

@@ -0,0 +1,91 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: ImageGradient
+  m_Shader: {fileID: 4800000, guid: 663608077d984df4184f0d2bd1d93dc7, type: 3}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _BumpMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailAlbedoMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailMask:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _DetailNormalMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _EmissionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 2800000, guid: 138c1e1691abd90498ea64dc80147ee9, type: 3}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MetallicGlossMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _OcclusionMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _ParallaxMap:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - _AlphaBottom: 1
+    - _AlphaTop: 0
+    - _BlendDstFactor: 10
+    - _BlendSrcFactor: 5
+    - _BumpScale: 1
+    - _ColorMask: 15
+    - _Cutoff: 0.5
+    - _DetailNormalMapScale: 1
+    - _DstBlend: 0
+    - _GlossMapScale: 1
+    - _Glossiness: 0.5
+    - _GlossyReflections: 1
+    - _GradientHeight: 0.7
+    - _MaxHeight: 0.776
+    - _Metallic: 0
+    - _MinHeight: 0.82
+    - _Mode: 0
+    - _OcclusionStrength: 1
+    - _Parallax: 0.02
+    - _SmoothnessTextureChannel: 0
+    - _SpecularHighlights: 1
+    - _SrcBlend: 1
+    - _Stencil: 0
+    - _StencilComp: 8
+    - _StencilOp: 0
+    - _StencilReadMask: 255
+    - _StencilWriteMask: 255
+    - _UVSec: 0
+    - _ZWrite: 1
+    m_Colors:
+    - _Color: {r: 1, g: 1, b: 1, a: 1}
+    - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
+  m_BuildTextureStacks: []

+ 8 - 0
GameClient/Assets/ResIn/Prefab/ImageGradient.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 15688f2d6c5fcb6438aa5b1841360133
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 2100000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
GameClient/Assets/ResIn/Shader.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 89f89135da0cb2841a20865fca23466e
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 195 - 0
GameClient/Assets/ResIn/Shader/ImageGradient.shader

@@ -0,0 +1,195 @@
+// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
+// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
+
+Shader "FairyGUI/ImageGradient"
+{
+    Properties
+    {
+        _MainTex("Base (RGB), Alpha (A)", 2D) = "black" {}
+
+        _StencilComp("Stencil Comparison", Float) = 8
+        _Stencil("Stencil ID", Float) = 0
+        _StencilOp("Stencil Operation", Float) = 0
+        _StencilWriteMask("Stencil Write Mask", Float) = 255
+        _StencilReadMask("Stencil Read Mask", Float) = 255
+
+        _ColorMask("Color Mask", Float) = 15
+
+        _BlendSrcFactor("Blend SrcFactor", Float) = 5
+        _BlendDstFactor("Blend DstFactor", Float) = 10
+        _MinHeight("Minimum Height", Range(0, 1)) = 0.2
+        _MaxHeight("Maximum Height", Range(0, 1)) = 0.8
+            _AlphaTop("Top Alpha", Range(0, 1)) = 1
+        _AlphaBottom("Bottom Alpha", Range(0, 1)) = 0
+    }
+
+        SubShader
+        {
+            LOD 100
+
+            Tags
+            {
+                "Queue" = "Transparent"
+                "IgnoreProjector" = "True"
+                "RenderType" = "Transparent"
+            }
+
+            Stencil
+            {
+                Ref[_Stencil]
+                Comp[_StencilComp]
+                Pass[_StencilOp]
+                ReadMask[_StencilReadMask]
+                WriteMask[_StencilWriteMask]
+            }
+
+            Cull Off
+            Lighting Off
+            ZWrite Off
+            Fog { Mode Off }
+            Blend[_BlendSrcFactor][_BlendDstFactor], One One
+            ColorMask[_ColorMask]
+
+            Pass
+            {
+                CGPROGRAM
+                    #pragma multi_compile NOT_COMBINED COMBINED
+                    #pragma multi_compile NOT_GRAYED GRAYED COLOR_FILTER
+                    #pragma multi_compile NOT_CLIPPED CLIPPED SOFT_CLIPPED ALPHA_MASK
+                    #pragma vertex vert
+                    #pragma fragment frag
+
+                    #include "UnityCG.cginc"
+
+                    struct appdata_t
+                    {
+                        float4 vertex : POSITION;
+                        fixed4 color : COLOR;
+                        float4 texcoord : TEXCOORD0;
+                    };
+
+                    struct v2f
+                    {
+                        float4 vertex : SV_POSITION;
+                        fixed4 color : COLOR;
+                        float4 texcoord : TEXCOORD0;
+
+                        #ifdef CLIPPED
+                        float2 clipPos : TEXCOORD1;
+                        #endif
+
+                        #ifdef SOFT_CLIPPED
+                        float2 clipPos : TEXCOORD1;
+                        #endif
+                    };
+
+                    sampler2D _MainTex;
+
+                    #ifdef COMBINED
+                    sampler2D _AlphaTex;
+                    #endif
+
+                    CBUFFER_START(UnityPerMaterial)
+                    #ifdef CLIPPED
+                    float4 _ClipBox = float4(-2, -2, 0, 0);
+                    #endif
+
+                    #ifdef SOFT_CLIPPED
+                    float4 _ClipBox = float4(-2, -2, 0, 0);
+                    float4 _ClipSoftness = float4(0, 0, 0, 0);
+                    #endif
+                    CBUFFER_END
+
+                    #ifdef COLOR_FILTER
+                    float4x4 _ColorMatrix;
+                    float4 _ColorOffset;
+                    float _ColorOption = 0;
+                    #endif
+
+                    half _AlphaTop;
+                    half _AlphaBottom;
+                    half _MinHeight;
+                    half _MaxHeight;
+
+                    v2f vert(appdata_t v)
+                    {
+                        v2f o;
+                        o.vertex = UnityObjectToClipPos(v.vertex);
+                        o.texcoord = v.texcoord;
+                        #if !defined(UNITY_COLORSPACE_GAMMA) && (UNITY_VERSION >= 550)
+                        o.color.rgb = GammaToLinearSpace(v.color.rgb);
+                        o.color.a = v.color.a;
+                        #else
+                        o.color = v.color;
+                        #endif
+
+                        #ifdef CLIPPED
+                        o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
+                        #endif
+
+                        #ifdef SOFT_CLIPPED
+                        o.clipPos = mul(unity_ObjectToWorld, v.vertex).xy * _ClipBox.zw + _ClipBox.xy;
+                        #endif
+
+                        return o;
+                    }
+
+                    fixed4 frag(v2f i) : SV_Target
+                    {
+                        fixed4 col = tex2D(_MainTex, i.texcoord.xy / i.texcoord.w) * i.color;
+
+                        #ifdef COMBINED
+                        col.a *= tex2D(_AlphaTex, i.texcoord.xy / i.texcoord.w).g;
+                        #endif
+
+                        #ifdef GRAYED
+                        fixed grey = dot(col.rgb, fixed3(0.299, 0.587, 0.114));
+                        col.rgb = fixed3(grey, grey, grey);
+                        #endif
+
+                        #ifdef SOFT_CLIPPED
+                        float2 factor = float2(0,0);
+                        if (i.clipPos.x < 0)
+                            factor.x = (1.0 - abs(i.clipPos.x)) * _ClipSoftness.x;
+                        else
+                            factor.x = (1.0 - i.clipPos.x) * _ClipSoftness.z;
+                        if (i.clipPos.y < 0)
+                            factor.y = (1.0 - abs(i.clipPos.y)) * _ClipSoftness.w;
+                        else
+                            factor.y = (1.0 - i.clipPos.y) * _ClipSoftness.y;
+                        col.a *= clamp(min(factor.x, factor.y), 0.0, 1.0);
+                        #endif
+
+                        #ifdef CLIPPED
+                        float2 factor = abs(i.clipPos);
+                        col.a *= step(max(factor.x, factor.y), 1);
+                        #endif
+
+                        #ifdef COLOR_FILTER
+                        if (_ColorOption == 0)
+                        {
+                            fixed4 col2 = col;
+                            col2.r = dot(col, _ColorMatrix[0]) + _ColorOffset.x;
+                            col2.g = dot(col, _ColorMatrix[1]) + _ColorOffset.y;
+                            col2.b = dot(col, _ColorMatrix[2]) + _ColorOffset.z;
+                            col2.a = dot(col, _ColorMatrix[3]) + _ColorOffset.w;
+                            col = col2;
+                        }
+                        else //premultiply alpha
+                            col.rgb *= col.a;
+                        #endif
+
+                        #ifdef ALPHA_MASK
+                        clip(col.a - 0.001);
+                        #endif
+                        float minHeight = _MinHeight;
+                        float maxHeight = _MaxHeight;
+                        float t = i.texcoord.y;
+                        float alpha = smoothstep(minHeight, maxHeight, t) * (_AlphaTop - _AlphaBottom) + _AlphaBottom;
+                        col.a *= alpha;
+                        return col;
+                    }
+                ENDCG
+            }
+        }
+}

+ 10 - 0
GameClient/Assets/ResIn/Shader/ImageGradient.shader.meta

@@ -0,0 +1,10 @@
+fileFormatVersion: 2
+guid: 663608077d984df4184f0d2bd1d93dc7
+ShaderImporter:
+  externalObjects: {}
+  defaultTextures: []
+  nonModifiableTextures: []
+  preprocessorOverride: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
GameClient/Assets/ResIn/UI/ClothingSynthetic/ClothingSynthetic_fui.bytes