Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
tuseGameColor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shujianhe
tuseGameColor
Commits
48da5d96
Commit
48da5d96
authored
Aug 19, 2023
by
JiangWanZhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交代码
parent
7eafc103
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
406 additions
and
33 deletions
+406
-33
GameEditor.cs
Assets/Editor/GameEditor.cs
+2
-1
GameMgr.cs
Assets/GameMgr/GameMgr.cs
+8
-1
GameMgr.cs.meta
Assets/GameMgr/GameMgr.cs.meta
+1
-1
MainData.cs
Assets/GameMgr/MainData.cs
+61
-21
MaskItem.cs
Assets/GameMgr/MaskItem.cs
+4
-2
New Material.mat
Assets/GameMgr/New Material.mat
+59
-0
New Material.mat.meta
Assets/GameMgr/New Material.mat.meta
+8
-0
ResJsonData.cs
Assets/GameMgr/ResJsonData.cs
+2
-2
Test.shader
Assets/GameMgr/Test.shader
+98
-0
Test.shader.meta
Assets/GameMgr/Test.shader.meta
+11
-0
GameMgr.prefab
Assets/Resources/perfabs/GameMgr.prefab
+5
-4
gameScene.unity
Assets/Scenes/gameScene.unity
+1
-1
Event.meta
Assets/scripts/Event.meta
+8
-0
EventDispatcher.cs
Assets/scripts/Event/EventDispatcher.cs
+127
-0
EventDispatcher.cs.meta
Assets/scripts/Event/EventDispatcher.cs.meta
+11
-0
No files found.
Assets/Editor/GameEditor.cs
View file @
48da5d96
...
...
@@ -46,10 +46,11 @@ public class GameEditor
fs
.
Close
();
}
}
Color
[]
list
=
rd
.
png
.
GetPixels
(
0
);
for
(
int
i
=
0
;
i
<
list
.
Length
;
i
++)
{
if
(
list
[
i
].
a
<=
0.
3
5f
)
if
(
list
[
i
].
a
<=
0.5f
)
{
list
[
i
]
=
Color
.
white
;
}
...
...
Assets/GameMgr.cs
→
Assets/GameMgr
/GameMgr
.cs
View file @
48da5d96
...
...
@@ -12,6 +12,13 @@ public class GameMgr : MonoBehaviour
get
{
return
ins
;
}
}
private
void
Update
()
{
if
(
Input
.
GetKeyDown
(
KeyCode
.
A
))
{
FileUtility
.
Instance
.
SavePng
(
md
.
png
);
}
}
private
void
Start
()
{
ins
=
this
;
...
...
@@ -48,7 +55,7 @@ public class GameMgr : MonoBehaviour
public
void
Create
(
MainData
md
,
ExRoomDatas
erd
,
Vector3
v
)
{
MaskItem
temp
=
Get
();
temp
.
DoFun
(
md
,
erd
,
v
);
temp
.
FunDo
(
md
,
erd
,
v
);
}
}
Assets/GameMgr.cs.meta
→
Assets/GameMgr
/GameMgr
.cs.meta
View file @
48da5d96
fileFormatVersion: 2
guid:
f81887d3b2353d2409eed5d664c55605
guid:
00c42e96b0e14a340b4a514fc81d7ef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
...
...
Assets/GameMgr/MainData.cs
View file @
48da5d96
...
...
@@ -23,8 +23,6 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
public
RectTransform
rect
;
public
Stack
<
Vector2
>
stackVector2
=
new
Stack
<
Vector2
>();
void
Update
()
{
Scale
();
...
...
@@ -42,6 +40,17 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
imgjpg
.
GetComponent
<
RectTransform
>().
sizeDelta
=
new
Vector2
(
png
.
width
,
png
.
height
);
GoOn
();
}
private
void
TestColor
()
{
for
(
int
i
=
0
;
i
<
json
.
roomDatas
.
Count
;
i
++)
{
RoomDatas
rd
=
json
.
roomDatas
[
i
];
Vector2
v
=
new
Vector2
(
rd
.
px
,
rd
.
py
);
FunDo
(
v
);
}
}
public
void
GoOn
()
{
List
<
int
>
list
=
json
.
list
;
...
...
@@ -139,17 +148,10 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
if
(
f
<
0.5f
&&
d
<
10
)
{
Debug
.
Log
(
"点击:"
+
v
);
System
.
Diagnostics
.
Stopwatch
sw
=
new
System
.
Diagnostics
.
Stopwatch
();
sw
.
Start
();
UseGun
(
v
);
sw
.
Stop
();
Debug
.
Log
(
"耗时:"
+
sw
.
ElapsedMilliseconds
);
}
}
}
#
endregion
public
void
UseGun
(
Vector2
v
)
{
List
<
Vector2
>
list
=
new
List
<
Vector2
>();
...
...
@@ -157,7 +159,7 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
{
for
(
int
j
=
0
;
j
<
gunSize
;
j
++)
{
Vector2
temp
=
new
Vector2
(
v
.
x
+
i
-
gunSize
/
2
,
v
.
y
+
j
-
gunSize
/
2
);
Vector2
temp
=
new
Vector2
(
(
int
)
v
.
x
+
i
-
gunSize
/
2
,
(
int
)
v
.
y
+
j
-
gunSize
/
2
);
list
.
Add
(
temp
);
}
}
...
...
@@ -186,6 +188,8 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
v
.
y
=
v
.
y
+
png
.
height
/
2
;
return
OnClickPos
(
v
);
}
#
endregion
public
bool
OnClickPos
(
Vector2
v
)
{
...
...
@@ -204,37 +208,73 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
//Debug.Log("涂过了");
return
false
;
}
//System.Diagnostics.Stopwatch ts = new System.Diagnostics.Stopwatch();
//ts.Start();
FunDo
(
v
);
//ts.Stop();
//System.Diagnostics.Stopwatch dx = new System.Diagnostics.Stopwatch();
//dx.Start();
GameMgr
.
Ins
.
Create
(
this
,
erd
,
v
);
//dx.Stop();
for
(
int
i
=
0
;
i
<
erd
.
list
.
Count
;
i
++)
{
png
.
SetPixel
((
int
)
erd
.
list
[
i
].
x
,
(
int
)
erd
.
list
[
i
].
y
,
Color
.
clear
);
}
png
.
Apply
();
//Debug.Log("涂色耗时:" + ts.ElapsedMilliseconds + " 动效耗时:" + dx.ElapsedMilliseconds);
return
true
;
}
public
void
FunDo
(
Vector2
_v
)
{
V2
v2
=
new
V2
(
_v
);
Stack
<
V2
>
stackVector2
=
new
Stack
<
V2
>();
erd
=
new
ExRoomDatas
();
stackVector2
.
Push
(
_v
);
Vector2
[]
d
=
new
Vector2
[
4
]
{
new
Vector2
(
0
,
-
1
),
new
Vector2
(
0
,
1
),
new
Vector2
(-
1
,
0
),
new
Vector2
(
1
,
0
)
};
Vector2
v_1
;
Vector2
v_2
;
stackVector2
.
Push
(
v2
);
V2
[]
d
=
new
V2
[
8
]
{
new
V2
(
0
,
-
1
),
new
V2
(
0
,
1
),
new
V2
(-
1
,
0
),
new
V2
(
1
,
0
),
new
V2
(-
1
,
-
1
),
new
V2
(-
1
,
1
),
new
V2
(
1
,
-
1
),
new
V2
(
1
,
1
)
};
V2
v_1
;
V2
v_2
;
int
count
=
0
;
while
(
stackVector2
.
Count
>
0
)
{
v_1
=
stackVector2
.
Pop
();
erd
.
AddData
(
v_1
);
png
.
SetPixel
(
(
int
)
v_1
.
x
,
(
int
)
v_1
.
y
,
Color
.
white
);
png
.
SetPixel
(
v_1
.
x
,
v_1
.
y
,
Color
.
clear
);
for
(
int
i
=
0
;
i
<
d
.
Length
;
i
++)
{
v_2
=
v_1
+
d
[
i
];
if
(
v_2
.
x
>=
0
&&
v_2
.
x
<
png
.
width
&&
v_2
.
y
>=
0
&&
v_2
.
y
<
png
.
height
&&
png
.
GetPixel
((
int
)
v_2
.
x
,
(
int
)
v_2
.
y
)
==
Color
.
white
)
Color
c
=
png
.
GetPixel
(
v_2
.
x
,
v_2
.
y
);
if
(
v_2
.
x
>=
0
&&
v_2
.
x
<
png
.
width
&&
v_2
.
y
>=
0
&&
v_2
.
y
<
png
.
height
&&
c
==
Color
.
white
)
{
stackVector2
.
Push
(
v_2
);
}
}
count
++;
if
(
count
>
10000000
)
{
Debug
.
LogError
(
"死循环了!"
);
break
;
}
}
//Debug.Log("循环次数:" + count);
png
.
Apply
();
}
}
public
struct
V2
{
public
int
x
;
public
int
y
;
public
V2
(
int
_x
,
int
_y
)
{
x
=
_x
;
y
=
_y
;
}
public
V2
(
Vector2
v
)
{
x
=
(
int
)
v
.
x
;
y
=
(
int
)
v
.
y
;
}
public
static
V2
operator
+(
V2
a
,
V2
b
)
{
return
new
V2
(
a
.
x
+
b
.
x
,
a
.
y
+
b
.
y
);
}
}
\ No newline at end of file
Assets/GameMgr/MaskItem.cs
View file @
48da5d96
...
...
@@ -33,7 +33,7 @@ public class MaskItem : MonoBehaviour
}
}
internal
void
DoFun
(
MainData
md
,
ExRoomDatas
erd
,
Vector3
v
)
internal
void
FunDo
(
MainData
md
,
ExRoomDatas
erd
,
Vector3
v
)
{
//创建图片
Texture2D
te
=
new
Texture2D
((
int
)(
erd
.
size
.
z
-
erd
.
size
.
x
+
1
),
(
int
)(
erd
.
size
.
w
-
erd
.
size
.
y
+
1
),
TextureFormat
.
RGBA32
,
false
);
...
...
@@ -50,17 +50,19 @@ public class MaskItem : MonoBehaviour
te
.
Apply
();
Sprite
sp
=
Sprite
.
Create
(
te
,
new
Rect
(
0
,
0
,
te
.
width
,
te
.
height
),
Vector2
.
zero
);
SP
.
sprite
=
sp
;
SP
.
SetNativeSize
(
);
SP
.
GetComponent
<
RectTransform
>().
sizeDelta
=
new
Vector2
(
te
.
width
,
te
.
height
);
//坐标计算
Transform
p
=
Rect
.
parent
;
Rect
.
SetParent
(
md
.
imgpng
.
transform
);
Rect
.
localPosition
=
v
-
new
Vector3
(
md
.
png
.
width
/
2
,
md
.
png
.
height
/
2
);
Rect
.
SetParent
(
p
);
Rect
.
localScale
=
Vector2
.
one
;
SPRect
.
SetParent
(
md
.
imgpng
.
transform
);
SPRect
.
localPosition
=
new
Vector3
(
erd
.
size
.
x
+
(
erd
.
size
.
z
+
1
-
erd
.
size
.
x
)
/
2
-
(
md
.
png
.
width
+
1
)
/
2
,
erd
.
size
.
y
+
(
erd
.
size
.
w
+
1
-
erd
.
size
.
y
)
/
2
-
(
md
.
png
.
height
+
1
)
/
2
,
0
);
SPRect
.
SetParent
(
Rect
);
SPRect
.
localScale
=
Vector2
.
one
;
//初始处理
gameObject
.
SetActive
(
true
);
...
...
Assets/GameMgr/New Material.mat
0 → 100644
View file @
48da5d96
%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
:
New Material
m_Shader
:
{
fileID
:
4800000
,
guid
:
8c9f3075cc39cfe41b9409237c27c014
,
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
:
-
_AlphaTex
:
m_Texture
:
{
fileID
:
0
}
m_Scale
:
{
x
:
1
,
y
:
1
}
m_Offset
:
{
x
:
0
,
y
:
0
}
-
_MainTex
:
m_Texture
:
{
fileID
:
2800000
,
guid
:
5fa4e00fb3dd65d4d8a6b03a484b3161
,
type
:
3
}
m_Scale
:
{
x
:
1
,
y
:
1
}
m_Offset
:
{
x
:
0
,
y
:
0
}
-
_MaskTex
:
m_Texture
:
{
fileID
:
0
}
m_Scale
:
{
x
:
1
,
y
:
1
}
m_Offset
:
{
x
:
0
,
y
:
0
}
-
_NormalMap
:
m_Texture
:
{
fileID
:
0
}
m_Scale
:
{
x
:
1
,
y
:
1
}
m_Offset
:
{
x
:
0
,
y
:
0
}
-
_RegionTex
:
m_Texture
:
{
fileID
:
2800000
,
guid
:
c4a8d1f39b589d747ba0b9ecc99f8f5d
,
type
:
3
}
m_Scale
:
{
x
:
1
,
y
:
1
}
m_Offset
:
{
x
:
0
,
y
:
0
}
m_Ints
:
[]
m_Floats
:
-
_BlueRegionIntensity
:
2
-
_EnableExternalAlpha
:
0
-
_GreenRegionIntensity
:
0.1
-
_RedRegionIntensity
:
0.1
m_Colors
:
-
_BlueRegionCol
:
{
r
:
0
,
g
:
0
,
b
:
0
,
a
:
1
}
-
_Color
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
-
_Flip
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
-
_GreenRegionCol
:
{
r
:
0
,
g
:
0.93772507
,
b
:
1
,
a
:
0
}
-
_RedRegionCol
:
{
r
:
0.4339623
,
g
:
0
,
b
:
0
,
a
:
1
}
-
_RendererColor
:
{
r
:
1
,
g
:
1
,
b
:
1
,
a
:
1
}
m_BuildTextureStacks
:
[]
Assets/GameMgr/New Material.mat.meta
0 → 100644
View file @
48da5d96
fileFormatVersion: 2
guid: d42fb2947ce23de4b80fe5aded33009d
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
Assets/GameMgr/ResJsonData.cs
View file @
48da5d96
...
...
@@ -68,9 +68,9 @@ public class RoomGroupsData
public
class
ExRoomDatas
{
public
Vector4
size
=
-
Vector4
.
one
;
public
List
<
V
ector2
>
list
=
new
List
<
Vector
2
>();
public
List
<
V
2
>
list
=
new
List
<
V
2
>();
public
void
AddData
(
V
ector
2
v
)
public
void
AddData
(
V2
v
)
{
if
(
size
.
x
==
-
1
||
size
.
x
>
v
.
x
)
{
...
...
Assets/GameMgr/Test.shader
0 → 100644
View file @
48da5d96
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader
"Test"
{
Properties
{
_MainTex
(
"Texture"
,
2
D
)
=
"white"
{}
_RegionTex
(
"Region Texture"
,
2
D
)
=
"white"
{}
_RedRegionCol
(
"Region Red Color"
,
Color
)
=
(
1
,
1
,
1
,
1
)
_GreenRegionCol
(
"Region Green Color"
,
Color
)
=
(
1
,
1
,
1
,
1
)
_BlueRegionCol
(
"Region Blue Color"
,
Color
)
=
(
1
,
1
,
1
,
1
)
_RedRegionIntensity
(
"Red Region Intensity"
,
Range
(
0
.
1
,
2
.
0
))
=
1
.
0
_GreenRegionIntensity
(
"Green Region Intensity"
,
Range
(
0
.
1
,
2
.
0
))
=
1
.
0
_BlueRegionIntensity
(
"Blue Region Intensity"
,
Range
(
0
.
1
,
2
.
0
))
=
1
.
0
}
SubShader
{
//Tags { "RenderType"="Opaque" }
Tags
{
"Queue"
=
"Transparent"
"RenderType"
=
"Transparent"
}
Blend
SrcAlpha
OneMinusSrcAlpha
LOD
100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct
appdata
{
float4
vertex
:
POSITION
;
float2
uv
:
TEXCOORD0
;
};
struct
v2f
{
float2
uvMain
:
TEXCOORD0
;
float4
vertex
:
SV_POSITION
;
float2
uvRegion
:
TEXCOORD1
;
};
sampler2D
_MainTex
;
float4
_MainTex_ST
;
sampler2D
_RegionTex
;
float4
_RegionTex_ST
;
fixed4
_RedRegionCol
;
fixed4
_GreenRegionCol
;
fixed4
_BlueRegionCol
;
half
_RedRegionIntensity
;
half
_GreenRegionIntensity
;
half
_BlueRegionIntensity
;
//fixed _GreenRegionAlpha;
//const half IGNORE_GRAY = 0.05;
v2f
vert
(
appdata
v
)
{
v2f
o
;
o
.
vertex
=
UnityObjectToClipPos
(
v
.
vertex
);
o
.
uvMain
=
TRANSFORM_TEX
(
v
.
uv
,
_MainTex
);
o
.
uvRegion
=
TRANSFORM_TEX
(
v
.
uv
,
_RegionTex
);
return
o
;
}
fixed4
frag
(
v2f
i
)
:
SV_Target
{
// sample the texture
fixed4
baseCol
=
tex2D
(
_MainTex
,
i
.
uvMain
);
fixed4
adjCol
=
tex2D
(
_RegionTex
,
i
.
uvRegion
);
fixed3
tempCol
=
adjCol
.
r
*
_RedRegionCol
.
rgb
*
_RedRegionIntensity
+
adjCol
.
g
*
_GreenRegionCol
.
rgb
*
_GreenRegionIntensity
+
adjCol
.
b
*
_BlueRegionCol
.
rgb
*
_BlueRegionIntensity
+
adjCol
.
a
*
fixed3
(
1
,
1
,
1
);
fixed3
finishCol
=
baseCol
.
rgb
*
tempCol
;
return
fixed4
(
finishCol
,
baseCol
.
a
);
}
ENDCG
}
}
}
\ No newline at end of file
Assets/GameMgr/Test.shader.meta
0 → 100644
View file @
48da5d96
fileFormatVersion: 2
guid: 8c9f3075cc39cfe41b9409237c27c014
ShaderImporter:
externalObjects: {}
defaultTextures:
- _MainTex: {instanceID: 0}
- _RegionTex: {instanceID: 0}
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
Assets/Resources/perfabs/GameMgr.prefab
View file @
48da5d96
...
...
@@ -203,7 +203,8 @@ MonoBehaviour:
m_Script
:
{
fileID
:
11500000
,
guid
:
dfb345a38dec3ca46a0d72d6e32abaaa
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
erdList
:
[]
erd
:
size
:
{
x
:
-1
,
y
:
-1
,
z
:
-1
,
w
:
-1
}
png
:
{
fileID
:
0
}
jpg
:
{
fileID
:
0
}
json
:
...
...
@@ -424,7 +425,7 @@ GameObject:
serializedVersion
:
6
m_Component
:
-
component
:
{
fileID
:
2908597137679265870
}
-
component
:
{
fileID
:
59
01361275493166274
}
-
component
:
{
fileID
:
59
38029588001435437
}
m_Layer
:
5
m_Name
:
GameMgr
m_TagString
:
Untagged
...
...
@@ -454,7 +455,7 @@ RectTransform:
m_AnchoredPosition
:
{
x
:
0
,
y
:
0
}
m_SizeDelta
:
{
x
:
0
,
y
:
0
}
m_Pivot
:
{
x
:
0.5
,
y
:
0.5
}
---
!u!114
&59
01361275493166274
---
!u!114
&59
38029588001435437
MonoBehaviour
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
...
...
@@ -463,7 +464,7 @@ MonoBehaviour:
m_GameObject
:
{
fileID
:
6736099197143395873
}
m_Enabled
:
1
m_EditorHideFlags
:
0
m_Script
:
{
fileID
:
11500000
,
guid
:
f81887d3b2353d2409eed5d664c55605
,
type
:
3
}
m_Script
:
{
fileID
:
11500000
,
guid
:
00c42e96b0e14a340b4a514fc81d7ef4
,
type
:
3
}
m_Name
:
m_EditorClassIdentifier
:
md
:
{
fileID
:
4535739684591336511
}
...
...
Assets/Scenes/gameScene.unity
View file @
48da5d96
...
...
@@ -8307,7 +8307,7 @@ RectTransform:
m_GameObject
:
{
fileID
:
5167855741857576711
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_LocalScale
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_ConstrainProportionsScale
:
0
m_Children
:
-
{
fileID
:
1643100474
}
...
...
Assets/scripts/Event.meta
0 → 100644
View file @
48da5d96
fileFormatVersion: 2
guid: 6a9ab5ab8203c6246ada997e225e6792
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/scripts/Event/EventDispatcher.cs
0 → 100644
View file @
48da5d96
using
System.Collections.Generic
;
using
UnityEngine
;
using
System
;
public
class
ParamedEventDispatcher
<
T
>
{
private
Dictionary
<
string
,
Action
<
T
>>
mEventList
=
new
Dictionary
<
string
,
Action
<
T
>>();
public
void
RegisterEvent
(
string
name
,
Action
<
T
>
callback
,
bool
register
)
{
if
(
register
)
{
if
(!
mEventList
.
ContainsKey
(
name
))
mEventList
.
Add
(
name
,
callback
);
else
mEventList
[
name
]
+=
callback
;
}
else
mEventList
[
name
]
-=
callback
;
}
public
void
Dispatch
(
string
name
,
T
value
)
{
if
(
mEventList
.
TryGetValue
(
name
,
out
var
_callbackList
))
{
_callbackList
?.
Invoke
(
value
);
}
}
}
public
class
EventDispatcher
{
static
Dictionary
<
string
,
Action
>
mEventList
=
new
Dictionary
<
string
,
Action
>();
static
ParamedEventDispatcher
<
string
>
mStringEventDispatcher
=
new
ParamedEventDispatcher
<
string
>();
static
ParamedEventDispatcher
<
float
>
mFloatEventDispatcher
=
new
ParamedEventDispatcher
<
float
>();
static
ParamedEventDispatcher
<
Vector3
>
mVector3EventDispatcher
=
new
ParamedEventDispatcher
<
Vector3
>();
static
ParamedEventDispatcher
<
bool
>
mBoolEventDispatcher
=
new
ParamedEventDispatcher
<
bool
>();
static
ParamedEventDispatcher
<
long
>
mLongEventDispatcher
=
new
ParamedEventDispatcher
<
long
>();
/// <summary>
/// 注册事件
/// </summary>
/// <param name="name"></param>
/// <param name="callback"></param>
/// <param name="register"></param>
public
static
void
RegisterEvent
(
string
name
,
Action
callback
,
bool
register
)
{
if
(
register
)
{
if
(!
mEventList
.
ContainsKey
(
name
))
mEventList
.
Add
(
name
,
callback
);
else
mEventList
[
name
]
+=
callback
;
}
else
if
(
mEventList
.
ContainsKey
(
name
))
mEventList
[
name
]
-=
callback
;
}
/// <summary>
/// 发送事件
/// </summary>
/// <param name="name"></param>
public
static
void
Dispatch
(
string
name
)
{
if
(
mEventList
.
TryGetValue
(
name
,
out
var
_callbackList
))
{
_callbackList
?.
Invoke
();
}
}
/// <summary>
/// 注册事件、register true为注册 false为释放
/// </summary>
/// <param name="name"></param>
/// <param name="callback"></param>
/// <param name="register"></param>
public
static
void
RegisterEvent
(
string
name
,
Action
<
string
>
callback
,
bool
register
)
{
mStringEventDispatcher
.
RegisterEvent
(
name
,
callback
,
register
);
}
public
static
void
Dispatch
(
string
name
,
string
value
)
{
mStringEventDispatcher
.
Dispatch
(
name
,
value
);
Dispatch
(
name
);
}
public
static
void
RegisterEvent
(
string
name
,
Action
<
Vector3
>
callback
,
bool
register
)
{
mVector3EventDispatcher
.
RegisterEvent
(
name
,
callback
,
register
);
}
public
static
void
Dispatch
(
string
name
,
Vector3
value
)
{
mVector3EventDispatcher
.
Dispatch
(
name
,
value
);
Dispatch
(
name
);
}
public
static
void
RegisterEvent
(
string
name
,
Action
<
bool
>
callback
,
bool
register
)
{
mBoolEventDispatcher
.
RegisterEvent
(
name
,
callback
,
register
);
}
public
static
void
Dispatch
(
string
name
,
bool
value
)
{
mBoolEventDispatcher
.
Dispatch
(
name
,
value
);
Dispatch
(
name
);
}
public
static
void
RegisterEvent
(
string
name
,
Action
<
float
>
callback
,
bool
register
)
{
mFloatEventDispatcher
.
RegisterEvent
(
name
,
callback
,
register
);
}
public
static
void
Dispatch
(
string
name
,
float
value
)
{
mFloatEventDispatcher
.
Dispatch
(
name
,
value
);
Dispatch
(
name
);
}
public
static
void
RegisterEvent
(
string
name
,
Action
<
long
>
callback
,
bool
register
)
{
mLongEventDispatcher
.
RegisterEvent
(
name
,
callback
,
register
);
}
public
static
void
Dispatch
(
string
name
,
long
value
)
{
mLongEventDispatcher
.
Dispatch
(
name
,
value
);
Dispatch
(
name
);
}
}
\ No newline at end of file
Assets/scripts/Event/EventDispatcher.cs.meta
0 → 100644
View file @
48da5d96
fileFormatVersion: 2
guid: 524b75fe53cb59044a420be43651cde0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment