hovereffect

This commit is contained in:
2025-02-25 11:27:20 +09:00
parent 96f4549e7a
commit 5862f39d9c
6 changed files with 317 additions and 99 deletions

View File

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

View File

@@ -0,0 +1,137 @@
%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: Mat_HoverColor
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords:
- _ALPHAPREMULTIPLY_ON
- _SURFACE_TYPE_TRANSPARENT
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
disabledShaderPasses:
- DepthOnly
- SHADOWCASTER
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs:
- _BaseMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- _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: 0}
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}
- _SpecGlossMap:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_Lightmaps:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_LightmapsInd:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- unity_ShadowMasks:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _AlphaClip: 0
- _AlphaToMask: 0
- _Blend: 0
- _BlendModePreserveSpecular: 1
- _BumpScale: 1
- _ClearCoatMask: 0
- _ClearCoatSmoothness: 0
- _Cull: 2
- _Cutoff: 0.5
- _DetailAlbedoMapScale: 1
- _DetailNormalMapScale: 1
- _DstBlend: 10
- _DstBlendAlpha: 10
- _EnvironmentReflections: 1
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Smoothness: 0.5
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _Surface: 1
- _WorkflowMode: 1
- _ZWrite: 0
m_Colors:
- _BaseColor: {r: 0, g: 0, b: 1, a: 0.15}
- _Color: {r: 0, g: 0, b: 1, a: 0.1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
--- !u!114 &4916636463855548587
MonoBehaviour:
m_ObjectHideFlags: 11
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
m_Name:
m_EditorClassIdentifier:
version: 7

View File

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

View File

@@ -52,6 +52,7 @@ namespace CHN
foreach (var machine in machines)
{
machine.DeactivateTranslucent();
machine.StopFlash();
}
}
@@ -65,6 +66,10 @@ namespace CHN
{
machine.ActivateTranslucent();
}
else
{
machine.StartFlash();
}
}
}

View File

@@ -18,9 +18,11 @@ namespace CHN
public Vector3 centerPos;
Renderer[] renderers;
public List<Material> HoverMaterials = new List<Material>();
Dictionary<Renderer, Material[]> originMaterials = new();
public Material translucentMat;
Material hoverRedMat;
public override void AfterAwake()
{
@@ -29,9 +31,10 @@ namespace CHN
GetComponentInParent<Floor>().machines.Add(this);
centerPos = transform.GetMeshGroupCenter();
renderers = GetComponentsInChildren<Renderer>();
CachingOriginMat();
translucentMat = Resources.Load<Material>("MAT_Translucent");
hoverRedMat = Resources.Load<Material>("Mat_HoverColor");
CachingOriginMat();
}
void CachingOriginMat()
@@ -58,6 +61,20 @@ namespace CHN
}
}
public void StartFlash()
{
StartCoroutine(Flash());
}
public void StopFlash()
{
StopAllCoroutines();
foreach (var m in HoverMaterials)
{
m.color = new Color(m.color.r, m.color.g, m.color.b, 0f);
}
}
public void DeactivateTranslucent()
{
foreach (Renderer renderer in renderers)
@@ -65,6 +82,7 @@ namespace CHN
Material[] originMat = originMaterials[renderer];
renderer.sharedMaterials = originMat;
}
AddHoverMaterials();
}
public int GetMachineFloorIndex()
@@ -83,5 +101,47 @@ namespace CHN
return 0;
}
void AddHoverMaterials()
{
HoverMaterials.Clear();
foreach (var renderer in renderers)
{
var highlightMat = hoverRedMat;
List<Material> RendererMats = new List<Material>();
RendererMats.AddRange(renderer.sharedMaterials);
RendererMats.Add(highlightMat);
renderer.sharedMaterials = RendererMats.ToArray();
HoverMaterials.Add(highlightMat);
}
}
IEnumerator Flash()
{
float alpha = 0f;
float coeff = 0.05f;
while (true)
{
yield return new WaitForSeconds(0.05f);
foreach(var m in HoverMaterials)
{
m.color = new Color(m.color.r,m.color.g,m.color.b,alpha);
}
if (alpha > 0.5f)
{
alpha = 0.5f;
coeff = -coeff;
}
else if (alpha < 0f)
{
alpha = 0f;
coeff = -coeff;
}
else
{
alpha += coeff;
}
}
}
}
}