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
1fd7153d
Commit
1fd7153d
authored
Aug 18, 2023
by
Ever
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解析JSON赋值
parent
c38a2830
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
87 additions
and
32 deletions
+87
-32
GameEditor.cs
Assets/Editor/GameEditor.cs
+6
-2
Art.meta
Assets/GameMgr/Art.meta
+8
-0
Drive.cs
Assets/GameMgr/Drive.cs
+2
-2
ExMask.cs
Assets/GameMgr/ExMask.cs
+7
-7
ImageData.cs
Assets/GameMgr/ImageData.cs
+4
-1
MainData.cs
Assets/GameMgr/MainData.cs
+16
-18
ResJsonData.cs
Assets/GameMgr/ResJsonData.cs
+36
-2
Data.meta
Assets/Resources/Data.meta
+8
-0
No files found.
Assets/Editor/GameEditor.cs
View file @
1fd7153d
...
...
@@ -34,8 +34,12 @@ public class GameEditor
}
else
if
(
path
.
EndsWith
(
".json"
))
{
//AssetDatabase.LoadAssetAtPath<JsonData>(path);
//md.json = JsonMapper.ToObject(webRequest.downloadHandler.text);
FileStream
fs
=
new
FileStream
(
path
,
FileMode
.
Open
,
FileAccess
.
Read
,
FileShare
.
None
);
StreamReader
sr
=
new
StreamReader
(
fs
,
System
.
Text
.
Encoding
.
UTF8
);
string
str
=
sr
.
ReadToEnd
();
md
.
json
=
JsonUtility
.
FromJson
<
ResJsonData
>(
str
);
sr
.
Close
();
fs
.
Close
();
}
}
md
.
Init
();
...
...
Assets/GameMgr/Art.meta
0 → 100644
View file @
1fd7153d
fileFormatVersion: 2
guid: 3a461ffb57d2c3d4799b655b39f57c5c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/GameMgr/Drive.cs
View file @
1fd7153d
...
...
@@ -39,10 +39,10 @@ public class Drive : MonoBehaviour
poolList
.
Add
(
temp
);
}
}
public
void
Create
(
MainData
md
,
ImageSubData
is
d
,
Vector3
v
)
public
void
Create
(
MainData
md
,
RoomDatas
r
d
,
Vector3
v
)
{
ExMask
temp
=
Get
();
temp
.
DoFun
(
md
,
is
d
,
v
);
temp
.
DoFun
(
md
,
r
d
,
v
);
}
}
Assets/GameMgr/ExMask.cs
View file @
1fd7153d
...
...
@@ -33,19 +33,19 @@ public class ExMask : MonoBehaviour
}
}
internal
void
DoFun
(
MainData
md
,
ImageSubData
is
d
,
Vector3
v
)
internal
void
DoFun
(
MainData
md
,
RoomDatas
r
d
,
Vector3
v
)
{
//创建图片
Texture2D
te
=
new
Texture2D
((
int
)(
isd
.
size
.
z
-
isd
.
size
.
x
+
1
),
(
int
)(
isd
.
size
.
w
-
is
d
.
size
.
y
+
1
),
TextureFormat
.
RGBA32
,
false
);
Texture2D
te
=
new
Texture2D
((
int
)(
rd
.
size
.
z
-
rd
.
size
.
x
+
1
),
(
int
)(
rd
.
size
.
w
-
r
d
.
size
.
y
+
1
),
TextureFormat
.
RGBA32
,
false
);
Color
[]
colors
=
te
.
GetPixels
();
for
(
int
i
=
0
;
i
<
colors
.
Length
;
i
++)
{
colors
[
i
].
a
=
0f
;
}
te
.
SetPixels
(
colors
);
for
(
int
i
=
0
;
i
<
is
d
.
list
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
r
d
.
list
.
Count
;
i
++)
{
te
.
SetPixel
((
int
)(
isd
.
list
[
i
].
x
-
isd
.
size
.
x
),
(
int
)(
isd
.
list
[
i
].
y
-
is
d
.
size
.
y
),
Color
.
white
);
te
.
SetPixel
((
int
)(
rd
.
list
[
i
].
x
-
rd
.
size
.
x
),
(
int
)(
rd
.
list
[
i
].
y
-
r
d
.
size
.
y
),
Color
.
white
);
}
te
.
Apply
();
Sprite
sp
=
Sprite
.
Create
(
te
,
new
Rect
(
0
,
0
,
te
.
width
,
te
.
height
),
Vector2
.
zero
);
...
...
@@ -59,14 +59,14 @@ public class ExMask : MonoBehaviour
Rect
.
SetParent
(
p
);
SPRect
.
SetParent
(
md
.
png
.
transform
);
SPRect
.
localPosition
=
new
Vector3
(
isd
.
size
.
x
+
(
isd
.
size
.
z
+
1
-
isd
.
size
.
x
)
/
2
-
(
md
.
Te_png
.
width
+
1
)
/
2
,
isd
.
size
.
y
+
(
isd
.
size
.
w
+
1
-
is
d
.
size
.
y
)
/
2
-
(
md
.
Te_png
.
height
+
1
)
/
2
,
0
);
SPRect
.
localPosition
=
new
Vector3
(
rd
.
size
.
x
+
(
rd
.
size
.
z
+
1
-
rd
.
size
.
x
)
/
2
-
(
md
.
Te_png
.
width
+
1
)
/
2
,
rd
.
size
.
y
+
(
rd
.
size
.
w
+
1
-
r
d
.
size
.
y
)
/
2
-
(
md
.
Te_png
.
height
+
1
)
/
2
,
0
);
SPRect
.
SetParent
(
Rect
);
//初始处理
gameObject
.
SetActive
(
true
);
Rect
.
sizeDelta
=
Vector2
.
zero
;
float
a
=
Math
.
Max
(
isd
.
size
.
z
-
v
.
x
,
v
.
x
-
is
d
.
size
.
x
);
float
b
=
Math
.
Max
(
isd
.
size
.
w
-
v
.
y
,
v
.
y
-
is
d
.
size
.
y
);
float
a
=
Math
.
Max
(
rd
.
size
.
z
-
v
.
x
,
v
.
x
-
r
d
.
size
.
x
);
float
b
=
Math
.
Max
(
rd
.
size
.
w
-
v
.
y
,
v
.
y
-
r
d
.
size
.
y
);
IsUse
=
Math
.
Max
(
a
,
b
)
*
2
;
}
}
Assets/GameMgr/ImageData.cs
View file @
1fd7153d
...
...
@@ -14,9 +14,12 @@ public class ImageData
public
List
<
ImageSubData
>
AlllList
=
new
List
<
ImageSubData
>();
public
void
AddData
(
ImageSubData
isd
)
{
if
(
isd
.
list
.
Count
>
1
)
{
AlllList
.
Add
(
isd
);
}
}
}
[Serializable]
...
...
Assets/GameMgr/MainData.cs
View file @
1fd7153d
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
UnityEngine
;
using
UnityEngine.EventSystems
;
using
UnityEngine.UI
;
...
...
@@ -8,6 +9,7 @@ using UnityEngine.UI;
public
class
MainData
:
MonoBehaviour
,
IDragHandler
,
IEndDragHandler
,
IBeginDragHandler
{
public
static
int
GunSize
=
50
;
public
ImageData
data
=
new
ImageData
();
public
Texture2D
Te_png
;
...
...
@@ -64,34 +66,31 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
#
region
图片分区
public
void
Split
()
{
for
(
int
i
=
0
;
i
<
Te_png
.
width
;
i
++)
{
for
(
int
j
=
0
;
j
<
Te_png
.
height
;
j
++)
for
(
int
i
=
0
;
i
<
json
.
roomDatas
.
Count
;
i
++)
{
Vector2
v
=
new
Vector2
(
i
,
j
);
RoomDatas
temp
=
json
.
roomDatas
[
i
];
Vector2
v
=
new
Vector2
(
temp
.
px
,
temp
.
py
);
if
(
Te_png
.
GetPixel
((
int
)
v
.
x
,
(
int
)
v
.
y
).
a
<=
0f
)
{
FunDo
(
v
);
}
FunDo
(
v
,
temp
);
}
}
Te_png
.
Apply
();
}
private
Stack
<
Vector2
>
stackVector2
=
new
Stack
<
Vector2
>();
public
void
FunDo
(
Vector2
_v
)
public
void
FunDo
(
Vector2
_v
,
RoomDatas
temp
)
{
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
;
ImageSubData
temp
=
new
ImageSubData
();
while
(
stackVector2
.
Count
>
0
)
{
v_1
=
stackVector2
.
Pop
();
temp
.
AddData
(
v_1
);
Te_png
.
SetPixel
((
int
)
v_1
.
x
,
(
int
)
v_1
.
y
,
Color
.
white
);
for
(
int
i
=
0
;
i
<
4
;
i
++)
for
(
int
i
=
0
;
i
<
d
.
Length
;
i
++)
{
v_2
=
v_1
+
d
[
i
];
if
(
v_2
.
x
>=
0
&&
v_2
.
x
<
Te_png
.
width
&&
v_2
.
y
>=
0
&&
v_2
.
y
<
Te_png
.
height
&&
Te_png
.
GetPixel
((
int
)
v_2
.
x
,
(
int
)
v_2
.
y
).
a
<=
0f
)
...
...
@@ -100,7 +99,6 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
}
}
}
data
.
AddData
(
temp
);
}
#
endregion
...
...
@@ -241,27 +239,27 @@ public class MainData : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDrag
//Debug.Log("涂过了");
return
false
;
}
ImageSubData
is
d
=
null
;
RoomDatas
r
d
=
null
;
for
(
int
i
=
0
;
i
<
data
.
AlllList
.
Count
;
i
++)
{
if
(
data
.
AlllList
[
i
].
Contains
(
v
))
if
(
json
.
roomDatas
[
i
].
Contains
(
v
))
{
//Debug.Log("在第" + i + "组数据中");
isd
=
data
.
AlllList
[
i
];
rd
=
json
.
roomDatas
[
i
];
}
}
if
(
is
d
==
null
)
if
(
r
d
==
null
)
{
//Debug.Log("组数据为空");
return
false
;
}
Drive
.
Ins
.
Create
(
this
,
is
d
,
v
);
Drive
.
Ins
.
Create
(
this
,
r
d
,
v
);
for
(
int
i
=
0
;
i
<
is
d
.
list
.
Count
;
i
++)
for
(
int
i
=
0
;
i
<
r
d
.
list
.
Count
;
i
++)
{
Te_png
.
SetPixel
((
int
)
isd
.
list
[
i
].
x
,
(
int
)
is
d
.
list
[
i
].
y
,
Color
.
clear
);
Te_png
.
SetPixel
((
int
)
rd
.
list
[
i
].
x
,
(
int
)
r
d
.
list
[
i
].
y
,
Color
.
clear
);
}
Te_png
.
Apply
();
return
true
;
...
...
Assets/GameMgr/ResJsonData.cs
View file @
1fd7153d
...
...
@@ -3,13 +3,17 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
UnityEngine
;
[Serializable]
public
class
ResJsonData
{
public
List
<
int
>
list
=
new
List
<
int
>();
public
List
<
RoomDatas
>
roomDatas
=
new
List
<
RoomDatas
>();
public
List
<
RoomGroupsData
>
roomGroupsData
=
new
List
<
RoomGroupsData
>();
public
int
colorDiff
;
public
int
lineFactorDiff
;
public
int
size
;
...
...
@@ -27,6 +31,7 @@ public class ResJsonData
public
int
scaleNumWhenOver100
;
public
ExtraMetaData
extraMetaData
;
}
[Serializable]
public
class
ExtraMetaData
//后面再看为啥json序列化失败
{
...
...
@@ -34,6 +39,7 @@ public class ExtraMetaData //后面再看为啥json序列化失败
public
int
tuhei_size
;
}
[Serializable]
public
class
RoomDatas
{
public
int
id
;
...
...
@@ -46,7 +52,35 @@ public class RoomDatas
public
int
G
;
public
int
B
;
public
int
useAreaData
;
public
Vector4
size
=
-
Vector4
.
one
;
public
List
<
Vector2
>
list
=
new
List
<
Vector2
>();
public
void
AddData
(
Vector2
v
)
{
if
(
size
.
x
==
-
1
||
size
.
x
>
v
.
x
)
{
size
.
x
=
v
.
x
;
}
if
(
size
.
y
==
-
1
||
size
.
y
>
v
.
y
)
{
size
.
y
=
v
.
y
;
}
if
(
size
.
z
==
-
1
||
size
.
z
<
v
.
x
)
{
size
.
z
=
v
.
x
;
}
if
(
size
.
w
==
-
1
||
size
.
w
<
v
.
y
)
{
size
.
w
=
v
.
y
;
}
list
.
Add
(
v
);
}
public
bool
Contains
(
Vector2
v
)
{
return
list
.
Contains
(
v
);
}
}
[Serializable]
public
class
RoomGroupsData
{
public
int
id
;
...
...
Assets/Resources/Data.meta
0 → 100644
View file @
1fd7153d
fileFormatVersion: 2
guid: da5799bf52418e94fa8e8da3423f5d00
folderAsset: yes
DefaultImporter:
externalObjects: {}
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