basic view func

master
wlt233 2 years ago
parent 9c22d6f86a
commit 16fdfe9fa4

@ -43,31 +43,36 @@ public class Main : MonoBehaviour
t++; t++;
} }
count = abNameList.Count; count = abNameList.Count;
var bundle = AssetBundle.LoadFromFile(abDir + '\\' +abNameList[idx % count]); LoadAb(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<WeaponController>();
//charm.AddComponent<MouseControlModel>();
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);
} }
void Update() 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<WeaponController>();
charm.AddComponent<MouseControlModel>();
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);
}
} }
} }

@ -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);
}
}

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

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

@ -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);
}
}
}

@ -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:

@ -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}

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

@ -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
}

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 379e267d1f4461b41a256e0cc40d4ce0
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

@ -124,6 +124,7 @@ GameObject:
- component: {fileID: 534669904} - component: {fileID: 534669904}
- component: {fileID: 534669903} - component: {fileID: 534669903}
- component: {fileID: 534669906} - component: {fileID: 534669906}
- component: {fileID: 534669907}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@ -149,7 +150,7 @@ Camera:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_ClearFlags: 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_projectionMatrixMode: 1
m_SensorSize: {x: 36, y: 24} m_SensorSize: {x: 36, y: 24}
m_LensShift: {x: 0, y: 0} m_LensShift: {x: 0, y: 0}
@ -207,3 +208,22 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0f380ef75cfc644449da67063fa2fc84, type: 3} m_Script: {fileID: 11500000, guid: 0f380ef75cfc644449da67063fa2fc84, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: 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

Loading…
Cancel
Save