diff --git a/Assets/Main.cs b/Assets/Main.cs index 1c8f0ad..7a46cac 100644 --- a/Assets/Main.cs +++ b/Assets/Main.cs @@ -43,31 +43,36 @@ public class Main : MonoBehaviour t++; } count = abNameList.Count; - var bundle = AssetBundle.LoadFromFile(abDir + '\\' +abNameList[idx % count]); - foreach (var name in bundle.GetAllAssetNames()) - { - Debug.Log(name); - charm = (GameObject)Instantiate(bundle.LoadAsset(name)); - charm.transform.localScale = new Vector3(100, 100, 100); - controller = charm.GetComponent(); - //charm.AddComponent(); - styleId.Clear(); - for (int i = 0; i < controller.weaponMaterialList.Length; i++) - { - styleId.Add(controller.weaponMaterialList[i].colorIndex); - } - effectId.Clear(); - for (int i = 0; i < controller.specialEffectList.Length; i++) - { - effectId.Add(controller.specialEffectList[i].id); - } - } - bundle.Unload(false); + LoadAb(abDir + '\\' +abNameList[idx % count]); + } void Update() { - + ; + } + + void LoadAb(string abPath) + { + var bundle = AssetBundle.LoadFromFile(abPath); + foreach (var name in bundle.GetAllAssetNames()) + { + Debug.Log(name); + charm = (GameObject)Instantiate(bundle.LoadAsset(name)); + } + charm.transform.localScale = new Vector3(100, 100, 100); + controller = charm.GetComponent(); + charm.AddComponent(); + styleId.Clear(); + for (int i = 0; i < controller.weaponMaterialList.Length; i++) + { + styleId.Add(controller.weaponMaterialList[i].colorIndex); + } + effectId.Clear(); + for (int i = 0; i < controller.specialEffectList.Length; i++) + { + effectId.Add(controller.specialEffectList[i].id); + } } } diff --git a/Assets/MouseControlModel.cs b/Assets/MouseControlModel.cs new file mode 100644 index 0000000..403d74a --- /dev/null +++ b/Assets/MouseControlModel.cs @@ -0,0 +1,75 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// modyified from https://blog.csdn.net/q764424567/article/details/90238382 2023.03.13 +public class MouseControlModel : MonoBehaviour +{ + + public int yMinLimit = -20; + public int yMaxLimit = 80; + + public float xSpeed = 250.0f; + public float ySpeed = 120.0f; + + private float x = 0.0f; + private float y = 0.0f; + + Vector3 previousPos; + bool isMouseDown = false; + + void Update() + { + if (Input.GetMouseButton(0)) + { + Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 30)); + if (!isMouseDown) + { + isMouseDown = true; + } + else + { + transform.position += (pos - previousPos); + } + previousPos = pos; + } + else if (Input.GetMouseButton(1)) + { + x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; + y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; + y = ClampAngle(y, yMinLimit, yMaxLimit); + Quaternion rotation = Quaternion.Euler(y, x, 0); + transform.rotation = rotation; + } + else if (Input.GetAxis("Mouse ScrollWheel") != 0) + { + if (Input.GetAxis("Mouse ScrollWheel") < 0) + { + if (Camera.main.fieldOfView <= 100) + Camera.main.fieldOfView += 2; + if (Camera.main.orthographicSize <= 20) + Camera.main.orthographicSize += 0.5F; + } + if (Input.GetAxis("Mouse ScrollWheel") > 0) + { + if (Camera.main.fieldOfView > 2) + Camera.main.fieldOfView -= 2; + if (Camera.main.orthographicSize >= 1) + Camera.main.orthographicSize -= 0.5F; + } + } + else + { + isMouseDown = false; + } + } + + static float ClampAngle(float angle, float min, float max) + { + if (angle < -360) + angle += 360; + if (angle > 360) + angle -= 360; + return Mathf.Clamp(angle, min, max); + } +} diff --git a/Assets/MouseControlModel.cs.meta b/Assets/MouseControlModel.cs.meta new file mode 100644 index 0000000..397eeb4 --- /dev/null +++ b/Assets/MouseControlModel.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b7c3446bdc3c052459f097578d7f9850 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Post.meta b/Assets/Post.meta new file mode 100644 index 0000000..c740436 --- /dev/null +++ b/Assets/Post.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f6bb3d86c5932a84baf4a458f2abaf25 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Post/BrightnessSaturationAndContrast.cs b/Assets/Post/BrightnessSaturationAndContrast.cs new file mode 100644 index 0000000..a2389a4 --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.cs @@ -0,0 +1,41 @@ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +// from https://blog.csdn.net/qq_41835314/article/details/127602308 2023.03.14 +[ExecuteInEditMode] +public class BrightnessSaturationAndContrast : MonoBehaviour +{ + public Shader briSatConShader; + public Material briSatConMaterial; + + [Range(0.0f, 3.0f)] + public float brightness = 1.0f; + + [Range(0.0f, 3.0f)] + public float saturation = 1.0f; + + [Range(0.0f, 3.0f)] + public float contrast = 1.0f; + + + + //运用 OnRenderImage(src, des) + void OnRenderImage(RenderTexture source, RenderTexture destination) + { + if (briSatConMaterial != null) + { + briSatConMaterial.SetFloat("_Brightness", brightness); + briSatConMaterial.SetFloat("_Saturation", saturation); + briSatConMaterial.SetFloat("_Contrast", contrast); + Graphics.Blit(source, destination, briSatConMaterial); + } + else + { + Debug.LogWarning("Please input your Material!"); + Graphics.Blit(source, destination); + } + + } +} diff --git a/Assets/Post/BrightnessSaturationAndContrast.cs.meta b/Assets/Post/BrightnessSaturationAndContrast.cs.meta new file mode 100644 index 0000000..acaceb7 --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 9ccd69a64c2d3154fa0e4f8d78cfdd43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: + - briSatConShader: {fileID: 4800000, guid: 379e267d1f4461b41a256e0cc40d4ce0, type: 3} + - briSatConMaterial: {fileID: 2100000, guid: 7090d388a697a64408c4ec0942dee7a8, type: 2} + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Post/BrightnessSaturationAndContrast.mat b/Assets/Post/BrightnessSaturationAndContrast.mat new file mode 100644 index 0000000..955636a --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.mat @@ -0,0 +1,80 @@ +%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: BrightnessSaturationAndContrast + m_Shader: {fileID: 4800000, guid: 379e267d1f4461b41a256e0cc40d4ce0, 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: 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} + m_Floats: + - _Brightness: 2 + - _BumpScale: 1 + - _Contrast: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 1 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _Saturation: 1 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/Assets/Post/BrightnessSaturationAndContrast.mat.meta b/Assets/Post/BrightnessSaturationAndContrast.mat.meta new file mode 100644 index 0000000..2b0dad6 --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7090d388a697a64408c4ec0942dee7a8 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Post/BrightnessSaturationAndContrast.shader b/Assets/Post/BrightnessSaturationAndContrast.shader new file mode 100644 index 0000000..f1745ae --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.shader @@ -0,0 +1,65 @@ +Shader "Custom/BrightnessSaturationAndContrast" +{ + Properties + { + _MainTex ("Base(RGB", 2D) = "white" {} + //从脚本传递更好,这里可以直接省略这些值的展示 + _Brightness ("Brightness", float) = 1 + _Saturation ("Saturation", float) = 1 + _Contrast ("Contrast", float) = 1 + } + SubShader + { + Pass + { + //关闭深度写入 + ZTest Always Cull Off Zwrite Off + + CGPROGRAM + + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + //properties + sampler2D _MainTex; + half _Brightness; + half _Saturation; + half _Contrast; + + struct v2f { + float4 pos : SV_POSITION; + half2 uv : TEXCOORD0; + }; + + //使用了内置的appdata_img结构体作为顶点着色器的输入 + v2f vert(appdata_img v) { + v2f o; + o.pos = UnityObjectToClipPos(v.vertex); + o.uv = v.texcoord; + return o; + } + + fixed4 frag(v2f i) : SV_Target { + //获得屏幕图像的采样 + fixed4 renderTex = tex2D(_MainTex, i.uv); + + //亮度 + fixed3 finalColor = renderTex.rgb * _Brightness; + + //饱和度 + fixed luminance = 0.2125 * renderTex.r + 0.7154 * renderTex.g + 0.0721 * renderTex.b; //计算该像素的亮度值 + fixed3 luminanceColor = fixed3(luminance, luminance, luminance); //创建饱和度为0的颜色 + finalColor = lerp(luminanceColor, finalColor, _Saturation); + + //contrast + fixed3 avgColor = fixed3(0.5, 0.5, 0.5); + finalColor = lerp(avgColor, finalColor, _Contrast); + + return fixed4(finalColor, renderTex.a); + } + ENDCG + } + } + FallBack Off +} \ No newline at end of file diff --git a/Assets/Post/BrightnessSaturationAndContrast.shader.meta b/Assets/Post/BrightnessSaturationAndContrast.shader.meta new file mode 100644 index 0000000..c919250 --- /dev/null +++ b/Assets/Post/BrightnessSaturationAndContrast.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 379e267d1f4461b41a256e0cc40d4ce0 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 6580c39..f315239 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -124,6 +124,7 @@ GameObject: - component: {fileID: 534669904} - component: {fileID: 534669903} - component: {fileID: 534669906} + - component: {fileID: 534669907} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -149,7 +150,7 @@ Camera: m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 2 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_BackGroundColor: {r: 0.2509804, g: 0.2509804, b: 0.2509804, a: 0} m_projectionMatrixMode: 1 m_SensorSize: {x: 36, y: 24} m_LensShift: {x: 0, y: 0} @@ -207,3 +208,22 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0f380ef75cfc644449da67063fa2fc84, type: 3} m_Name: m_EditorClassIdentifier: + styleId: + effectId: +--- !u!114 &534669907 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 534669902} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9ccd69a64c2d3154fa0e4f8d78cfdd43, type: 3} + m_Name: + m_EditorClassIdentifier: + briSatConShader: {fileID: 4800000, guid: 379e267d1f4461b41a256e0cc40d4ce0, type: 3} + briSatConMaterial: {fileID: 2100000, guid: 7090d388a697a64408c4ec0942dee7a8, type: 2} + brightness: 2 + saturation: 1 + contrast: 1