DESKTOP-FB72PO8\Administrator пре 4 месеци
родитељ
комит
322952181e

+ 43 - 0
Assets/Resources/MyShader_UIImageGray.mat

@@ -0,0 +1,43 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!21 &2100000
+Material:
+  serializedVersion: 8
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: MyShader_UIImageGray
+  m_Shader: {fileID: 4800000, guid: bd480dea67f139944b14ebd6f96e7e03, type: 3}
+  m_Parent: {fileID: 0}
+  m_ModifiedSerializedProperties: 0
+  m_ValidKeywords: []
+  m_InvalidKeywords: []
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_LockedProperties: 
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _MainTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Ints: []
+    m_Floats:
+    - _ColorMask: 15
+    - _GreyValue: 0
+    - _Stencil: 0
+    - _StencilComp: 8
+    - _StencilOp: 0
+    - _StencilReadMask: 255
+    - _StencilWriteMask: 255
+    - _UseUIAlphaClip: 0
+    m_Colors:
+    - _ClipRect: {r: -32767, g: -32767, b: 32767, a: 32767}
+    - _Color: {r: 0.8, g: 0.8, b: 0.8, a: 1}
+  m_BuildTextureStacks: []

+ 8 - 0
Assets/Resources/MyShader_UIImageGray.mat.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: DShNtC+kAHMyjwtgbgRaXT7R/33DLV6tmoTd5hLw18zD4MI7nAUTSxI=
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 125 - 0
Assets/Resources/UIImageGray.shader

@@ -0,0 +1,125 @@
+Shader "MyShader/UIImageGray"
+{
+    //修改Unity官方内置shader,UI-Default
+    Properties
+    {
+        // [PerRendererData] 
+        _MainTex ("Sprite Texture", 2D) = "white" {}
+        _Color ("Tint", Color) = (1,1,1,1)
+
+        _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
+     _ClipRect ("Clip Rect", Vector) = (-32767, -32767, 32767, 32767)
+        [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
+        _GreyValue("_GreyValue",range(0,1))=0
+    }
+
+    SubShader
+    {
+        Tags
+        {
+            "Queue"="Transparent"
+            "IgnoreProjector"="True"
+            "RenderType"="Transparent"
+            "PreviewType"="Plane"
+            "CanUseSpriteAtlas"="True"
+        }
+
+        Stencil
+        {
+            Ref [_Stencil]
+            Comp [_StencilComp]
+            Pass [_StencilOp]
+            ReadMask [_StencilReadMask]
+            WriteMask [_StencilWriteMask]
+        }
+
+        Cull Off
+        Lighting Off
+        ZWrite Off
+        ZTest [unity_GUIZTestMode]
+        Blend SrcAlpha OneMinusSrcAlpha
+        ColorMask [_ColorMask]
+
+        Pass
+        {
+            Name "Default"
+            CGPROGRAM
+            #pragma vertex vert
+            #pragma fragment frag
+            #pragma target 2.0
+
+            #include "UnityCG.cginc"
+            #include "UnityUI.cginc"
+
+            #pragma multi_compile __ UNITY_UI_CLIP_RECT
+            #pragma multi_compile __ UNITY_UI_ALPHACLIP
+
+            struct appdata_t
+            {
+                float4 vertex : POSITION;
+                float4 color : COLOR;
+                float2 texcoord : TEXCOORD0;
+                UNITY_VERTEX_INPUT_INSTANCE_ID
+            };
+
+            struct v2f
+            {
+                float4 vertex : SV_POSITION;
+                fixed4 color : COLOR;
+                float2 texcoord : TEXCOORD0;
+                float4 worldPosition : TEXCOORD1;
+                UNITY_VERTEX_OUTPUT_STEREO
+            };
+
+            sampler2D _MainTex;
+            fixed4 _Color;
+            fixed4 _TextureSampleAdd;
+            float4 _ClipRect;
+            float4 _MainTex_ST;
+            float _GreyValue;
+
+            v2f vert(appdata_t v)
+            {
+                v2f OUT;
+                UNITY_SETUP_INSTANCE_ID(v);
+                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
+                OUT.worldPosition = v.vertex;
+                OUT.vertex = UnityObjectToClipPos(v.vertex);
+
+                OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
+
+                OUT.color = v.color * _Color;
+                return OUT;
+            }
+
+            fixed4 frag(v2f IN) : SV_Target
+            {
+                half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
+              
+                #ifdef UNITY_UI_CLIP_RECT
+
+                #endif
+
+                #ifdef UNITY_UI_ALPHACLIP
+                clip (color.a - 0.001);
+                #endif
+
+                half gray = dot(color.rgb, fixed3(0.299, 0.587, 0.114)); //0.222, 0.707, 0.071
+                float3 graycolor = fixed3(gray, gray, gray);
+                  color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
+                color.rgb = graycolor*  color.a ;
+                
+                //color.rgb=lerp(color.rgb,graycolor,_GreyValue);
+
+                return color;
+            }
+            ENDCG
+        }
+    }
+}

+ 9 - 0
Assets/Resources/UIImageGray.shader.meta

@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: XCwY4y6oUn7bH/fxh5oS1Qo4Wqw5kXu6iCKHA/hboTnLmcVPUeRHOc0=
+ShaderImporter:
+  externalObjects: {}
+  defaultTextures: []
+  nonModifiableTextures: []
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 35 - 6
Assets/Scripts/Core/UI/Core/UIManager.cs

@@ -39,6 +39,8 @@ namespace Fort23.Mono
     {
         public static UIManager Instance { get; set; }
 
+        public readonly Material uiGray = new Material(Shader.Find("MyShader/UIImageGray"));
+
         // public RectTransform UIRootTransform;
         public Vector2 sizeDelta;
 
@@ -190,6 +192,37 @@ namespace Fort23.Mono
             }
         }
 
+        public void SetGray(GameObject gameObject, bool isGray, bool isChildGray = false)
+        {
+            if (isChildGray)
+            {
+                Graphic[] graphics = gameObject.transform.GetComponentsInChildren<Graphic>();
+                for (int i = 0; i < graphics.Length; i++)
+                {
+                    if (isGray)
+                    {
+                        graphics[i].material = uiGray;
+                    }
+                    else
+                    {
+                        graphics[i].material = graphics[i].defaultMaterial;
+                    }
+                }
+            }
+            else
+            {
+                Graphic graphic = gameObject.GetComponent<Graphic>();
+                if (isGray)
+                {
+                    graphic.material = uiGray;
+                }
+                else
+                {
+                    graphic.material = graphic.defaultMaterial;
+                }
+            }
+        }
+
         public void SetEventSystemEnable(bool value)
         {
             // current.isClose = !value;
@@ -384,8 +417,7 @@ namespace Fort23.Mono
                             NoFocusTopUIPanels.Add(uiPanel);
                         uiPanel.isActiveAnima = isActiveAnima;
                         await uiPanel.Open();
-
-
+                        
                         if (current != null)
                         {
                             // current.isClose = false;
@@ -444,7 +476,6 @@ namespace Fort23.Mono
             bool isFull = false;
             if (allPanel != null)
             {
-                
                 for (int i = 0; i < allPanel.Length; i++)
                 {
                     UIPanel panel = allPanel[i];
@@ -477,7 +508,7 @@ namespace Fort23.Mono
                 }
 
                 currDeapthGraphic = min;
-              
+
                 for (int i = 0; i < allPanel.Length; i++)
                 {
                     UIPanel panel = allPanel[i];
@@ -491,8 +522,6 @@ namespace Fort23.Mono
             }
 
 
-     
-
             RefreshFullEventData refreshFullEventData = RefreshFullEventData.Create();
             refreshFullEventData.isFullShow = isFull;
             EventManager.Instance.Dispatch(CustomEventType.RefreshFull, refreshFullEventData);

+ 39 - 5
Assets/Scripts/Core/UI/UTool/MyImage.cs

@@ -2,6 +2,7 @@ using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.Text;
+using Fort23.Mono;
 using Fort23.UTool;
 using UnityEngine.Experimental.Rendering;
 using UnityEngine.Serialization;
@@ -43,7 +44,7 @@ namespace UnityEngine.UI
         private UILoadSpriteHand _uiLoadSpriteHand;
 
         public System.Action onSpriteAlter;
-        
+
         protected override void Awake()
         {
             if (Application.isPlaying && isNotLoadDeftIcon)
@@ -56,6 +57,7 @@ namespace UnityEngine.UI
                 icon_name = _icon_name;
             }
         }
+
         protected override void OnDestroy()
         {
             if (_uiLoadSpriteHand != null)
@@ -63,8 +65,10 @@ namespace UnityEngine.UI
                 _uiLoadSpriteHand.ReleaseUI();
                 _uiLoadSpriteHand = null;
             }
+
             base.OnDestroy();
         }
+
         public void ReashUI()
         {
             if (CurrSpriteAtlas != null && !string.IsNullOrEmpty(_icon_name))
@@ -108,13 +112,12 @@ namespace UnityEngine.UI
                         else
                         {
                             SetSprite(loadSprite);
-                            
                         }
                     }
                 }
                 else
                 {
-                    SetSprite( loadSprite);
+                    SetSprite(loadSprite);
                 }
             }
             else if (!string.IsNullOrEmpty(_icon_name) && sprite == null)
@@ -137,7 +140,7 @@ namespace UnityEngine.UI
                         }
                         else
                         {
-                            SetSprite( sprite1.GetSprite());
+                            SetSprite(sprite1.GetSprite());
                         }
                     });
                 }
@@ -172,7 +175,7 @@ namespace UnityEngine.UI
                         _uiLoadSpriteHand = sprite1;
                         if (sprite1 == null)
                         {
-                            SetSprite( null);
+                            SetSprite(null);
                         }
                         else
                         {
@@ -192,10 +195,41 @@ namespace UnityEngine.UI
             }
         }
 
+        /// <summary>
+        /// 是否置灰
+        /// </summary>
+        public bool IsGray
+        {
+            get { return _isGray; }
+            set
+            {
+                if (!_isGray.Equals(value))
+                {
+                    _isGray = value;
+                    if (_isGray)
+                    {
+                        base.material = UIManager.Instance.uiGray;
+                    }
+                    else
+                    {
+                        if (base.material != null)
+                        {
+                            base.material = null;
+                        }
+
+                        base.material = defaultMaterial;
+                    }
+                }
+            }
+        }
+
+        private bool _isGray;
+
         public override void GraphicUpdateComplete()
         {
             SetPack();
         }
+
         private void SetPack()
         {
 #if UNITY_EDITOR

+ 7 - 13
Assets/Scripts/Core/UI/UTool/UtilTools.cs

@@ -13,7 +13,6 @@ using System.Runtime.Serialization.Formatters.Binary;
 using UnityEngine.Profiling;
 #endif
 using System.Security.Cryptography;
-
 using Fort23.UTool;
 
 namespace Utility
@@ -21,14 +20,13 @@ namespace Utility
     public static class UtilTools
     {
 #if !COMBAT_SERVER
-
-
         public static List<GameObject> allDontDestroyOnLoad = new List<GameObject>();
 #endif
         private static int m_seed = 0;
 
         private static StringBuilder sb;
 
+   
 
         public static long oneDay = 86400000;
 
@@ -123,7 +121,7 @@ namespace Utility
         //
         //     return a;
         // }
-        
+
         /// <summary>
         /// 获取描述文本
         /// </summary>
@@ -670,8 +668,8 @@ namespace Utility
                 }
             }
         }
-        
-        
+
+
         /// <summary>
         /// 时间(秒)转换位小时分钟秒
         /// </summary>
@@ -693,10 +691,11 @@ namespace Utility
             {
                 return $"{xiaoShi}小时";
             }
-            else if (tian >= 1 )
+            else if (tian >= 1)
             {
                 return $"{tian}天";
             }
+
             return "";
         }
 
@@ -843,11 +842,7 @@ namespace Utility
             return (long)timeSpan.TotalSeconds;
         }
 
-       
-        
-      
-      
-        
+
         public static T DeepCopy<T>(T obj)
         {
             using (var memoryStream = new MemoryStream())
@@ -858,7 +853,6 @@ namespace Utility
                 return (T)formatter.Deserialize(memoryStream);
             }
         }
-     
     }