? ? ? ? 本组件仅实现A传送点到B传送的功能,是可以双向传送的,如果只要单向传送,可以另外改脚本实现;
先看效果:
unity组件传送点演示
1.传送组件shader是怎么写的:这种效果的实现方案
shader编辑器是这样的:
代码是这样的:
// Made with Amplify Shader Editor v1.9.1.5
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "INS/ChuangDian_CZ"
{
Properties
{
_Color("Color", Color) = (1,1,1,0)
_Texture("Texture", 2D) = "white" {}
_Desaturate("Desaturate", Range( 0 , 1)) = 0.5
_RuoHua("RuoHua", Range( 0 , 1)) = 1
_Metallic("Metallic", Range( 0 , 1)) = 0
_Smoothness("Smoothness", Range( 0 , 1)) = 0
[HideInInspector] _texcoord( "", 2D ) = "white" {}
[HideInInspector] __dirty( "", Int ) = 1
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" }
Cull Back
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard keepalpha addshadow fullforwardshadows
struct Input
{
float2 uv_texcoord;
};
uniform sampler2D _Texture;
uniform float4 _Texture_ST;
uniform float _Desaturate;
uniform float4 _Color;
uniform float _RuoHua;
uniform float _Metallic;
uniform float _Smoothness;
void surf( Input i , inout SurfaceOutputStandard o )
{
float2 uv_Texture = i.uv_texcoord * _Texture_ST.xy + _Texture_ST.zw;
float3 desaturateInitialColor9 = tex2D( _Texture, uv_Texture ).rgb;
float desaturateDot9 = dot( desaturateInitialColor9, float3( 0.299, 0.587, 0.114 ));
float3 desaturateVar9 = lerp( desaturateInitialColor9, desaturateDot9.xxx, _Desaturate );
float4 lerpResult15 = lerp( ( float4( desaturateVar9 , 0.0 ) * _Color ) , _Color , _RuoHua);
o.Albedo = lerpResult15.rgb;
o.Metallic = _Metallic;
o.Smoothness = _Smoothness;
o.Alpha = 1;
}
ENDCG
}
Fallback "Diffuse"
CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=19105
Node;AmplifyShaderEditor.DesaturateOpNode;9;-717.8729,-223.8029;Inherit;False;2;0;FLOAT3;0,0,0;False;1;FLOAT;0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.RangedFloatNode;4;-360.5876,42.01204;Inherit;False;Property;_Metallic;Metallic;4;0;Create;True;0;0;0;False;0;False;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;5;-360.6326,117.4722;Inherit;False;Property;_Smoothness;Smoothness;5;0;Create;True;0;0;0;False;0;False;0;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;66.00646,4.950484;Float;False;True;-1;2;ASEMaterialInspector;0;0;Standard;INS/ChuangDian_CZ;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;;0;False;;False;0;False;;0;False;;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;12;all;True;True;True;True;0;False;;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;2;15;10;25;False;0.5;True;0;0;False;;0;False;;0;0;False;;0;False;;0;False;;0;False;;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;True;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;;-1;0;False;;0;0;0;False;0.1;False;;0;False;;False;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;6;-475.0052,-181.1613;Inherit;False;2;2;0;FLOAT3;0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.ColorNode;3;-743.4476,-96.76402;Inherit;False;Property;_Color;Color;0;0;Create;True;0;0;0;False;0;False;1,1,1,0;0,0,0,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;8;-1069,-200.3001;Inherit;False;Property;_Desaturate;Desaturate;2;0;Create;True;0;0;0;False;0;False;0.5;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.LerpOp;15;-198.6593,-181.8569;Inherit;True;3;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;2;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.RangedFloatNode;16;-494.9561,-46.60926;Inherit;False;Property;_RuoHua;RuoHua;3;0;Create;True;0;0;0;False;0;False;1;0;0;1;0;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;2;-1135.341,-462.8333;Inherit;True;Property;_Texture;Texture;1;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
WireConnection;9;0;2;0
WireConnection;9;1;8;0
WireConnection;0;0;15;0
WireConnection;0;3;4;0
WireConnection;0;4;5;0
WireConnection;6;0;9;0
WireConnection;6;1;3;0
WireConnection;15;0;6;0
WireConnection;15;1;3;0
WireConnection;15;2;16;0
ASEEND*/
//CHKSM=58E752AB348EAA75CF5226F291024A24776642B6
2.实现传送功能,需要的节点和脚本:poinA和pointB 对应子节点中的两个sphere
3.传送过程中的效果表现,shader怎么写:也就是Dissolve材质球
代码是这样的:
// Made with Amplify Shader Editor v1.9.1.5
// Available at the Unity Asset Store - http://u3d.as/y3X
Shader "Dissolve"
{
Properties
{
_Albedo("Albedo", 2D) = "white" {}
_Normal("Normal", 2D) = "white" {}
_MetalAOSmooth("MetalAOSmooth", 2D) = "white" {}
_DissolveAmount("DissolveAmount", Float) = 0
_EmissColor("EmissColor", Color) = (0,0,0,0)
_EmissIntensity("EmissIntensity", Float) = 0
_DissolveRange("DissolveRange", Float) = 0
_NoiseTex("NoiseTex", 2D) = "white" {}
_T_Noise_dissolve("T_Noise_dissolve", 2D) = "white" {}
[HideInInspector] _texcoord( "", 2D ) = "white" {}
[HideInInspector] __dirty( "", Int ) = 1
}
SubShader
{
Tags{ "RenderType" = "Transparent" "Queue" = "Transparent+0" "IgnoreProjector" = "True" "IsEmissive" = "true" }
Cull Back
CGINCLUDE
#include "UnityShaderVariables.cginc"
#include "UnityPBSLighting.cginc"
#include "Lighting.cginc"
#pragma target 3.0
#ifdef UNITY_PASS_SHADOWCASTER
#undef INTERNAL_DATA
#undef WorldReflectionVector
#undef WorldNormalVector
#define INTERNAL_DATA half3 internalSurfaceTtoW0; half3 internalSurfaceTtoW1; half3 internalSurfaceTtoW2;
#define WorldReflectionVector(data,normal) reflect (data.worldRefl, half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal)))
#define WorldNormalVector(data,normal) half3(dot(data.internalSurfaceTtoW0,normal), dot(data.internalSurfaceTtoW1,normal), dot(data.internalSurfaceTtoW2,normal))
#endif
struct Input
{
float3 worldPos;
float2 uv_texcoord;
float3 worldNormal;
INTERNAL_DATA
};
uniform sampler2D _NoiseTex;
uniform float4 _NoiseTex_ST;
uniform float _DissolveAmount;
uniform sampler2D _Normal;
uniform float4 _Normal_ST;
uniform sampler2D _Albedo;
uniform float4 _Albedo_ST;
uniform float4 _EmissColor;
uniform sampler2D _T_Noise_dissolve;
uniform float _EmissIntensity;
uniform sampler2D _MetalAOSmooth;
uniform float4 _MetalAOSmooth_ST;
uniform float _DissolveRange;
void vertexDataFunc( inout appdata_full v, out Input o )
{
UNITY_INITIALIZE_OUTPUT( Input, o );
float3 ase_worldPos = mul( unity_ObjectToWorld, v.vertex );
float3 worldToObj1 = mul( unity_WorldToObject, float4( ase_worldPos, 1 ) ).xyz;
float2 uv_NoiseTex = v.texcoord * _NoiseTex_ST.xy + _NoiseTex_ST.zw;
float temp_output_35_0 = pow( tex2Dlod( _NoiseTex, float4( uv_NoiseTex, 0, 0.0) ).r , 2.0 );
float temp_output_11_0 = abs( 0.25 );
float temp_output_9_0 = ( -( worldToObj1.y + temp_output_35_0 ) - temp_output_11_0 );
float temp_output_8_0 = ( -( worldToObj1.y + temp_output_35_0 ) + temp_output_11_0 );
float smoothstepResult3 = smoothstep( temp_output_9_0 , temp_output_8_0 , _DissolveAmount);
v.vertex.xyz = ( ( smoothstepResult3 * float3(0,5,0) ) + worldToObj1 );
v.vertex.w = 1;
}
void surf( Input i , inout SurfaceOutputStandard o )
{
float2 uv_Normal = i.uv_texcoord * _Normal_ST.xy + _Normal_ST.zw;
o.Normal = UnpackNormal( tex2D( _Normal, uv_Normal ) );
float2 uv_Albedo = i.uv_texcoord * _Albedo_ST.xy + _Albedo_ST.zw;
o.Albedo = tex2D( _Albedo, uv_Albedo ).rgb;
float3 ase_worldNormal = WorldNormalVector( i, float3( 0, 0, 1 ) );
float3 ase_vertexNormal = mul( unity_WorldToObject, float4( ase_worldNormal, 0 ) );
ase_vertexNormal = normalize( ase_vertexNormal );
float3 objToView22 = mul( UNITY_MATRIX_MV, float4( ase_vertexNormal, 1 ) ).xyz;
float mulTime25 = _Time.y * -0.02;
float2 appendResult26 = (float2(0.0 , mulTime25));
float4 tex2DNode17 = tex2D( _T_Noise_dissolve, ( ( objToView22 * float3( 0.13,0.3,0 ) ) + float3( appendResult26 , 0.0 ) ).xy );
float3 ase_worldPos = i.worldPos;
float3 worldToObj1 = mul( unity_WorldToObject, float4( ase_worldPos, 1 ) ).xyz;
float2 uv_NoiseTex = i.uv_texcoord * _NoiseTex_ST.xy + _NoiseTex_ST.zw;
float temp_output_35_0 = pow( tex2D( _NoiseTex, uv_NoiseTex ).r , 2.0 );
float temp_output_11_0 = abs( 0.25 );
float temp_output_9_0 = ( -( worldToObj1.y + temp_output_35_0 ) - temp_output_11_0 );
float temp_output_8_0 = ( -( worldToObj1.y + temp_output_35_0 ) + temp_output_11_0 );
float smoothstepResult3 = smoothstep( temp_output_9_0 , temp_output_8_0 , _DissolveAmount);
o.Emission = ( ( ( ( _EmissColor * tex2DNode17 ) + _EmissColor ) * _EmissIntensity ) * smoothstepResult3 ).rgb;
float2 uv_MetalAOSmooth = i.uv_texcoord * _MetalAOSmooth_ST.xy + _MetalAOSmooth_ST.zw;
float4 tex2DNode48 = tex2D( _MetalAOSmooth, uv_MetalAOSmooth );
o.Metallic = tex2DNode48.r;
o.Smoothness = tex2DNode48.a;
o.Occlusion = tex2DNode48.g;
float smoothstepResult32 = smoothstep( temp_output_9_0 , temp_output_8_0 , ( _DissolveAmount - ( _DissolveRange * ( 1.0 - temp_output_35_0 ) ) ));
o.Alpha = saturate( ( ( 1.0 - smoothstepResult3 ) + ( ( 1.0 - smoothstepResult32 ) * tex2DNode17.r ) ) );
}
ENDCG
CGPROGRAM
#pragma surface surf Standard alpha:fade keepalpha fullforwardshadows vertex:vertexDataFunc
ENDCG
Pass
{
Name "ShadowCaster"
Tags{ "LightMode" = "ShadowCaster" }
ZWrite On
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#pragma multi_compile_shadowcaster
#pragma multi_compile UNITY_PASS_SHADOWCASTER
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
#include "HLSLSupport.cginc"
#if ( SHADER_API_D3D11 || SHADER_API_GLCORE || SHADER_API_GLES || SHADER_API_GLES3 || SHADER_API_METAL || SHADER_API_VULKAN )
#define CAN_SKIP_VPOS
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
sampler3D _DitherMaskLOD;
struct v2f
{
V2F_SHADOW_CASTER;
float2 customPack1 : TEXCOORD1;
float4 tSpace0 : TEXCOORD2;
float4 tSpace1 : TEXCOORD3;
float4 tSpace2 : TEXCOORD4;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert( appdata_full v )
{
v2f o;
UNITY_SETUP_INSTANCE_ID( v );
UNITY_INITIALIZE_OUTPUT( v2f, o );
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO( o );
UNITY_TRANSFER_INSTANCE_ID( v, o );
Input customInputData;
vertexDataFunc( v, customInputData );
float3 worldPos = mul( unity_ObjectToWorld, v.vertex ).xyz;
half3 worldNormal = UnityObjectToWorldNormal( v.normal );
half3 worldTangent = UnityObjectToWorldDir( v.tangent.xyz );
half tangentSign = v.tangent.w * unity_WorldTransformParams.w;
half3 worldBinormal = cross( worldNormal, worldTangent ) * tangentSign;
o.tSpace0 = float4( worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x );
o.tSpace1 = float4( worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y );
o.tSpace2 = float4( worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z );
o.customPack1.xy = customInputData.uv_texcoord;
o.customPack1.xy = v.texcoord;
TRANSFER_SHADOW_CASTER_NORMALOFFSET( o )
return o;
}
half4 frag( v2f IN
#if !defined( CAN_SKIP_VPOS )
, UNITY_VPOS_TYPE vpos : VPOS
#endif
) : SV_Target
{
UNITY_SETUP_INSTANCE_ID( IN );
Input surfIN;
UNITY_INITIALIZE_OUTPUT( Input, surfIN );
surfIN.uv_texcoord = IN.customPack1.xy;
float3 worldPos = float3( IN.tSpace0.w, IN.tSpace1.w, IN.tSpace2.w );
half3 worldViewDir = normalize( UnityWorldSpaceViewDir( worldPos ) );
surfIN.worldPos = worldPos;
surfIN.worldNormal = float3( IN.tSpace0.z, IN.tSpace1.z, IN.tSpace2.z );
surfIN.internalSurfaceTtoW0 = IN.tSpace0.xyz;
surfIN.internalSurfaceTtoW1 = IN.tSpace1.xyz;
surfIN.internalSurfaceTtoW2 = IN.tSpace2.xyz;
SurfaceOutputStandard o;
UNITY_INITIALIZE_OUTPUT( SurfaceOutputStandard, o )
surf( surfIN, o );
#if defined( CAN_SKIP_VPOS )
float2 vpos = IN.pos;
#endif
half alphaRef = tex3D( _DitherMaskLOD, float3( vpos.xy * 0.25, o.Alpha * 0.9375 ) ).a;
clip( alphaRef - 0.01 );
SHADOW_CASTER_FRAGMENT( IN )
}
ENDCG
}
}
Fallback "Diffuse"
CustomEditor "ASEMaterialInspector"
}
/*ASEBEGIN
Version=19105
Node;AmplifyShaderEditor.WorldPosInputsNode;2;-719.8619,7.13725;Inherit;False;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.NegateNode;5;-144.2999,34.52414;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;7;-261.0644,-14.90448;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.AbsOpNode;11;19.19641,135.7086;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;27;1218.962,-409.4442;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleAddOpNode;28;1401.362,-355.0442;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;COLOR;0,0,0,0;False;1;COLOR;0
Node;AmplifyShaderEditor.SimpleAddOpNode;23;817.2692,-805.6909;Inherit;False;2;2;0;FLOAT3;0,0,0;False;1;FLOAT2;0,0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.SimpleSubtractOpNode;9;172.3755,-95.52279;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;8;188.786,27.72242;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;29;1548.792,-398.8269;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.RangedFloatNode;30;1408.792,-531.8269;Inherit;False;Property;_EmissIntensity;EmissIntensity;5;0;Create;True;0;0;0;False;0;False;0;3.65;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SmoothstepOpNode;3;514.8207,-251.9341;Inherit;False;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;13;902.1608,175.2412;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT3;0,0,0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.TransformPositionNode;1;-531.0639,-25.44292;Inherit;False;World;Object;False;Fast;True;1;0;FLOAT3;0,0,0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.PowerNode;35;-316.6454,222.5346;Inherit;False;False;2;0;FLOAT;0;False;1;FLOAT;2;False;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;6;-731.2645,233.5954;Inherit;True;Property;_NoiseTex;NoiseTex;7;0;Create;True;0;0;0;False;0;False;-1;None;f8c46e1c2a15265408e41fa92886549b;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;10;-142.8036,145.7086;Inherit;False;Constant;_smooth;smooth;2;0;Create;True;0;0;0;False;0;False;0.25;0;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.Vector3Node;12;644.4524,173.591;Inherit;False;Constant;_Vector0;Vector 0;3;0;Create;True;0;0;0;False;0;False;0,5,0;0,0,0;0;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.SimpleAddOpNode;14;1220.6,88.76579;Inherit;False;2;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.SimpleSubtractOpNode;33;1055.637,-161.5284;Inherit;False;2;0;FLOAT;0;False;1;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;36;969.3151,6.091968;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.OneMinusNode;37;337.4388,220.0167;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.RangedFloatNode;34;659.8098,-33.82647;Inherit;False;Property;_DissolveRange;DissolveRange;6;0;Create;True;0;0;0;False;0;False;0;3.37;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;38;1929.468,-65.26013;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SmoothstepOpNode;32;1450.942,-63.80793;Inherit;False;3;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;1;False;1;FLOAT;0
Node;AmplifyShaderEditor.OneMinusNode;40;1801.102,-180.9123;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;16;1819.44,-304.5616;Inherit;False;2;2;0;COLOR;0,0,0,0;False;1;FLOAT;0;False;1;COLOR;0
Node;AmplifyShaderEditor.ColorNode;15;730.3444,-407.8557;Inherit;False;Property;_EmissColor;EmissColor;4;0;Create;True;0;0;0;False;0;False;0,0,0,0;0.2783018,0.6858239,1,0;True;0;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleMultiplyOpNode;20;672.7254,-807.2241;Inherit;False;2;2;0;FLOAT3;0,0,0;False;1;FLOAT3;0.13,0.3,0;False;1;FLOAT3;0
Node;AmplifyShaderEditor.NormalVertexDataNode;21;-48.33521,-877.1525;Inherit;False;0;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.TransformPositionNode;22;255.8536,-889.2006;Inherit;False;Object;View;False;Fast;True;1;0;FLOAT3;0,0,0;False;4;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3
Node;AmplifyShaderEditor.DynamicAppendNode;26;603.0665,-637.7112;Inherit;False;FLOAT2;4;0;FLOAT;0;False;1;FLOAT;0;False;2;FLOAT;0;False;3;FLOAT;0;False;1;FLOAT2;0
Node;AmplifyShaderEditor.SamplerNode;17;936.7515,-680.4985;Inherit;True;Property;_T_Noise_dissolve;T_Noise_dissolve;8;0;Create;True;0;0;0;False;0;False;-1;0cf9ad0ec82276849a36a6400e35dd4e;0cf9ad0ec82276849a36a6400e35dd4e;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SimpleTimeNode;25;373.3573,-618.2069;Inherit;False;1;0;FLOAT;-0.02;False;1;FLOAT;0
Node;AmplifyShaderEditor.OneMinusNode;31;1683.635,-36.73546;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SaturateNode;42;2179.549,-187.5133;Inherit;False;1;0;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.SimpleAddOpNode;39;2053.697,-145.9254;Inherit;False;2;2;0;FLOAT;0;False;1;FLOAT;0;False;1;FLOAT;0
Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;2844.106,-314.8162;Float;False;True;-1;2;ASEMaterialInspector;0;0;Standard;Dissolve;False;False;False;False;False;False;False;False;False;False;False;False;False;False;True;False;False;False;False;False;False;Back;1;False;;0;False;;False;0;False;;0;False;;False;0;Transparent;0.5;True;True;0;False;Transparent;;Transparent;All;12;all;True;True;True;True;0;False;;False;0;False;;255;False;;255;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;0;False;;False;2;15;10;25;False;0.5;True;2;5;False;;10;False;;0;0;False;;0;False;;0;False;;0;False;;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;True;Absolute;0;;-1;-1;-1;-1;0;False;0;0;False;;-1;0;False;;0;0;0;False;0.1;False;;0;False;;False;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0
Node;AmplifyShaderEditor.SamplerNode;48;2070.829,-502.1674;Inherit;True;Property;_MetalAOSmooth;MetalAOSmooth;2;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.SamplerNode;47;2349.744,-729.7792;Inherit;True;Property;_Normal;Normal;1;0;Create;True;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;True;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;FLOAT3;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
Node;AmplifyShaderEditor.RangedFloatNode;4;157.7782,-263.7874;Inherit;False;Property;_DissolveAmount;DissolveAmount;3;0;Create;True;0;0;0;False;0;False;0;0;0;0;0;1;FLOAT;0
Node;AmplifyShaderEditor.SamplerNode;45;2357.703,-935.7942;Inherit;True;Property;_Albedo;Albedo;0;0;Create;False;0;0;0;False;0;False;-1;None;None;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;8;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;6;FLOAT;0;False;7;SAMPLERSTATE;;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4
WireConnection;5;0;7;0
WireConnection;7;0;1;2
WireConnection;7;1;35;0
WireConnection;11;0;10;0
WireConnection;27;0;15;0
WireConnection;27;1;17;0
WireConnection;28;0;27;0
WireConnection;28;1;15;0
WireConnection;23;0;20;0
WireConnection;23;1;26;0
WireConnection;9;0;5;0
WireConnection;9;1;11;0
WireConnection;8;0;5;0
WireConnection;8;1;11;0
WireConnection;29;0;28;0
WireConnection;29;1;30;0
WireConnection;3;0;4;0
WireConnection;3;1;9;0
WireConnection;3;2;8;0
WireConnection;13;0;3;0
WireConnection;13;1;12;0
WireConnection;1;0;2;0
WireConnection;35;0;6;1
WireConnection;14;0;13;0
WireConnection;14;1;1;0
WireConnection;33;0;4;0
WireConnection;33;1;36;0
WireConnection;36;0;34;0
WireConnection;36;1;37;0
WireConnection;37;0;35;0
WireConnection;38;0;31;0
WireConnection;38;1;17;1
WireConnection;32;0;33;0
WireConnection;32;1;9;0
WireConnection;32;2;8;0
WireConnection;40;0;3;0
WireConnection;16;0;29;0
WireConnection;16;1;3;0
WireConnection;20;0;22;0
WireConnection;22;0;21;0
WireConnection;26;1;25;0
WireConnection;17;1;23;0
WireConnection;31;0;32;0
WireConnection;42;0;39;0
WireConnection;39;0;40;0
WireConnection;39;1;38;0
WireConnection;0;0;45;0
WireConnection;0;1;47;0
WireConnection;0;2;16;0
WireConnection;0;3;48;1
WireConnection;0;4;48;4
WireConnection;0;5;48;2
WireConnection;0;9;42;0
WireConnection;0;11;14;0
ASEEND*/
//CHKSM=598FD4007CD3F6F672F5FCA5BC8282E86A7E4D50
需要两张资源图片:
4.好了,一切准备就绪,就进入传送的逻辑代码:
using DG.Tweening;
using System;
using System.Collections;
using TMPro;
using UnityEngine;
public class TranslationCom : MonoBehaviour {
public Transform pointA;
public Transform pointB;
private bool canTeleport = true;
private float teleportDistance = 1f;
private Sequence sequence;
public Material material;
private GameObject cloneAvatar;
private bool isTeleporting = false;
void Start () {
//HudPanel.Instance.ShowText(pointA.gameObject,"进入传送阵",new Vector3(0,1f,0));
//HudPanel.Instance.ShowText(pointB.gameObject,"进入传送阵",new Vector3(0,1f,0));
}
void DoTranslation(Vector3 targetPosition) {
//PlayerController.Instance.transform.position = targetPosition;
StartCoroutine(waitShowTranslation(targetPosition));
}
IEnumerator waitShowTranslation(Vector3 targetPosition) {
float duration = 0.5f;
cloneAvatar = GameObject.Instantiate(PlayerController.Instance.animator.gameObject, PlayerController.Instance.transform);
cloneAvatar.transform.localPosition = PlayerController.Instance.animator.transform.localPosition;
cloneAvatar.transform.localRotation = PlayerController.Instance.animator.transform.localRotation;
EventManager.Instance.TriggerEvent(EventName.StartTranslation);
var renders = cloneAvatar.GetComponentsInChildren<Renderer>();
PlayerController.Instance.animator.gameObject.SetActive(false);
foreach (Renderer r in renders) {
var tex = r.material.GetTexture("baseColorTexture");
r.material = new Material(material);
r.material.SetTexture("_Albedo", tex);
}
isTeleporting = true;
yield return new WaitForSeconds(duration);
PlayerController.Instance.animator.gameObject.SetActive(true);
EventManager.Instance.TriggerEvent(EventName.EndTranslation);
PlayerController.Instance.transform.position = targetPosition;
isTeleporting = false;
GameObject.Destroy(cloneAvatar);
}
void UpadateTranslationShow() {
if (cloneAvatar) {
//Debug.Log("UpadateTranslationShow");
var renders = cloneAvatar.GetComponentsInChildren<Renderer>();
foreach (Renderer r in renders) {
r.material.SetFloat("_DissolveAmount",UnityEngine.Random.Range(0,1f));
}
}
}
void Update() {
if (PlayerData.Instance.State == (int)PlayerState.DRIVEING) {
return;
}
float distanceToA = Vector3.Distance(PlayerController.Instance.transform.position, pointA.position);
float distanceToB = Vector3.Distance(PlayerController.Instance.transform.position, pointB.position);
if (canTeleport && (distanceToA <= teleportDistance || distanceToB <= teleportDistance)) {
Transform targetPoint = distanceToA < distanceToB ? pointB : pointA;
float distanceToTarget = Vector3.Distance(PlayerController.Instance.transform.position, targetPoint.position);
if (distanceToTarget > teleportDistance) {
canTeleport = false;
DoTranslation(targetPoint.position);
}
}
else if (!canTeleport && distanceToA > teleportDistance && distanceToB > teleportDistance) {
canTeleport = true;
}
if (isTeleporting) {
UpadateTranslationShow();
}
}
}