Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Unity让梦想成为现实
SaoLei
提交
abd34006
S
SaoLei
项目概览
Unity让梦想成为现实
/
SaoLei
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SaoLei
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
abd34006
编写于
9月 27, 2021
作者:
Unity让梦想成为现实
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
GridHelper bug解决
上级
2057a6be
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
100603 addition
and
4314 deletion
+100603
-4314
Assets/Editor/MyEditor.cs
Assets/Editor/MyEditor.cs
+33
-0
Assets/Resources/GameConfig.asset
Assets/Resources/GameConfig.asset
+6
-6
Assets/Resources/Grid1.prefab
Assets/Resources/Grid1.prefab
+34378
-4278
Assets/Resources/Grid2.prefab
Assets/Resources/Grid2.prefab
+66110
-0
Assets/Resources/Grid2.prefab.meta
Assets/Resources/Grid2.prefab.meta
+7
-0
Assets/Scripts/GridHelper.cs
Assets/Scripts/GridHelper.cs
+3
-3
Assets/Scripts/Panel_Play.cs
Assets/Scripts/Panel_Play.cs
+66
-27
未找到文件。
Assets/Editor/MyEditor.cs
浏览文件 @
abd34006
...
@@ -3,6 +3,9 @@ using System.Collections.Generic;
...
@@ -3,6 +3,9 @@ using System.Collections.Generic;
using
UnityEngine
;
using
UnityEngine
;
using
UnityEditor
;
using
UnityEditor
;
using
UnityEngine.UI
;
using
UnityEngine.UI
;
using
System
;
using
Object
=
UnityEngine
.
Object
;
public
class
MyEditor
:
MonoBehaviour
public
class
MyEditor
:
MonoBehaviour
{
{
[
MenuItem
(
"Tools/SetNameBySprite"
)]
[
MenuItem
(
"Tools/SetNameBySprite"
)]
...
@@ -20,4 +23,34 @@ public class MyEditor : MonoBehaviour
...
@@ -20,4 +23,34 @@ public class MyEditor : MonoBehaviour
}
}
}
}
}
}
[
MenuItem
(
"Tools/MyWindow"
)]
static
void
OpenToolWindow
()
{
EditorWindow
.
GetWindow
<
MyWondow
>();
}
}
class
MyWondow
:
EditorWindow
{
string
findTypeName
=
""
;
private
void
OnGUI
()
{
findTypeName
=
EditorGUILayout
.
TextField
(
"组件类型:"
,
findTypeName
);
List
<
Object
>
list
=
new
List
<
Object
>();
if
(
GUILayout
.
Button
(
"根据组件查找子物体"
))
{
Debug
.
Log
(
Selection
.
activeGameObject
);
MonoBehaviour
[]
bhvs
=
(
Selection
.
activeObject
as
GameObject
).
GetComponentsInChildren
<
MonoBehaviour
>();
for
(
int
i
=
0
;
i
<
bhvs
.
Length
;
i
++)
{
string
type
=(
bhvs
[
i
].
GetType
().
Name
);
if
(
type
==
findTypeName
)
{
list
.
Add
(
bhvs
[
i
].
gameObject
);
}
}
Selection
.
objects
=
list
.
ToArray
();
}
}
}
}
Assets/Resources/GameConfig.asset
浏览文件 @
abd34006
...
@@ -14,14 +14,14 @@ MonoBehaviour:
...
@@ -14,14 +14,14 @@ MonoBehaviour:
m_EditorClassIdentifier
:
m_EditorClassIdentifier
:
levels
:
levels
:
-
grid
:
{
fileID
:
5905246775763589814
,
guid
:
e8d3b3d184ba6a549b53e4070e002383
,
type
:
3
}
-
grid
:
{
fileID
:
5905246775763589814
,
guid
:
e8d3b3d184ba6a549b53e4070e002383
,
type
:
3
}
bombCount
:
5
bombCount
:
9
r
:
9
r
:
9
c
:
9
c
:
9
-
grid
:
{
fileID
:
6272468980495940245
,
guid
:
c5139b7a1d02bd64692db09bfead94c7
,
type
:
3
}
-
grid
:
{
fileID
:
6272468980495940245
,
guid
:
c5139b7a1d02bd64692db09bfead94c7
,
type
:
3
}
bombCount
:
0
bombCount
:
18
r
:
16
r
:
16
c
:
16
c
:
16
-
grid
:
{
fileID
:
0
}
-
grid
:
{
fileID
:
6272468980495940245
,
guid
:
f5db5bb63fa770849b8d27d2a7e6dbbe
,
type
:
3
}
bombCount
:
0
bombCount
:
3
0
r
:
0
r
:
24
c
:
0
c
:
16
Assets/Resources/Grid1.prefab
浏览文件 @
abd34006
此差异已折叠。
点击以展开。
Assets/Resources/Grid2.prefab
0 → 100644
浏览文件 @
abd34006
此差异已折叠。
点击以展开。
Assets/Resources/Grid2.prefab.meta
0 → 100644
浏览文件 @
abd34006
fileFormatVersion: 2
guid: f5db5bb63fa770849b8d27d2a7e6dbbe
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/GridHelper.cs
浏览文件 @
abd34006
...
@@ -24,8 +24,8 @@ public class GridHelper
...
@@ -24,8 +24,8 @@ public class GridHelper
/// <param name="index">一维索引</param>
/// <param name="index">一维索引</param>
public
Rc
GetRc
(
int
index
)
public
Rc
GetRc
(
int
index
)
{
{
int
r
=
index
/
rowLength
;
//一维索引/行
长度得到行
int
r
=
index
/
columeLength
;
//一维索引/列
长度得到行
int
c
=
index
%
row
Length
;
int
c
=
index
%
colume
Length
;
return
new
Rc
(
r
,
c
);
return
new
Rc
(
r
,
c
);
}
}
...
@@ -39,7 +39,7 @@ public class GridHelper
...
@@ -39,7 +39,7 @@ public class GridHelper
//二位索引转一维索引
//二位索引转一维索引
public
int
GetIndex
(
int
r
,
int
c
)
//2,1 -> 9
public
int
GetIndex
(
int
r
,
int
c
)
//2,1 -> 9
{
{
return
r
*
row
Length
+
c
;
return
r
*
colume
Length
+
c
;
}
}
...
...
Assets/Scripts/Panel_Play.cs
浏览文件 @
abd34006
...
@@ -4,7 +4,8 @@ using System.Collections.Generic;
...
@@ -4,7 +4,8 @@ using System.Collections.Generic;
using
UnityEngine
;
using
UnityEngine
;
using
UnityEngine.UI
;
using
UnityEngine.UI
;
using
DG.Tweening
;
using
DG.Tweening
;
using
System
;
using
Random
=
UnityEngine
.
Random
;
public
class
Panel_Play
:
MonoBehaviour
public
class
Panel_Play
:
MonoBehaviour
{
{
Transform
grid
;
//格子,根据用户选择的等级动态加载
Transform
grid
;
//格子,根据用户选择的等级动态加载
...
@@ -22,20 +23,20 @@ public class Panel_Play : MonoBehaviour
...
@@ -22,20 +23,20 @@ public class Panel_Play : MonoBehaviour
//计时器 1秒刷新一次
//计时器 1秒刷新一次
IEnumerator
Timer
()
IEnumerator
Timer
()
{
{
startTime
=
Time
.
time
;
startTime
=
Time
.
time
;
while
(
true
)
while
(
true
)
{
{
yield
return
new
WaitForSeconds
(
1
);
yield
return
new
WaitForSeconds
(
1
);
float
time
=
(
Time
.
time
-
startTime
);
float
time
=
(
Time
.
time
-
startTime
);
int
minute
=
(
int
)
time
/
60
;
int
minute
=
(
int
)
time
/
60
;
int
sec
=
(
int
)
time
%
60
;
int
sec
=
(
int
)
time
%
60
;
text_Time
.
text
=
string
.
Format
(
"{0:00}:{1:00}"
,
minute
,
sec
);
text_Time
.
text
=
string
.
Format
(
"{0:00}:{1:00}"
,
minute
,
sec
);
}
}
}
}
private
int
CurrentTool
private
int
CurrentTool
{
{
...
@@ -53,8 +54,10 @@ public class Panel_Play : MonoBehaviour
...
@@ -53,8 +54,10 @@ public class Panel_Play : MonoBehaviour
}
}
//设置 剩余可标记数量
//设置 剩余可标记数量
public
int
FlagCount
{
get
=>
flagCount
;
public
int
FlagCount
set
{
get
=>
flagCount
;
set
{
{
flagCount
=
value
;
flagCount
=
value
;
text_bomgFlagCount
.
text
=
flagCount
.
ToString
();
text_bomgFlagCount
.
text
=
flagCount
.
ToString
();
...
@@ -68,7 +71,7 @@ public class Panel_Play : MonoBehaviour
...
@@ -68,7 +71,7 @@ public class Panel_Play : MonoBehaviour
if
(
Random
.
Range
(
0
,
3
)
!=
0
)
if
(
Random
.
Range
(
0
,
3
)
!=
0
)
{
{
item
.
GetComponent
<
Image
>().
DOFade
(
0
,
Random
.
Range
(
0f
,
1.5f
)).
From
().
SetEase
(
Ease
.
Linear
);
item
.
GetComponent
<
Image
>().
DOFade
(
0
,
Random
.
Range
(
0f
,
1.5f
)).
From
().
SetEase
(
Ease
.
Linear
);
}
}
}
}
}
}
...
@@ -85,24 +88,24 @@ public class Panel_Play : MonoBehaviour
...
@@ -85,24 +88,24 @@ public class Panel_Play : MonoBehaviour
cells
=
new
Cell
[
gameLevel
.
cellCount
];
cells
=
new
Cell
[
gameLevel
.
cellCount
];
for
(
int
i
=
0
;
i
<
grid
.
childCount
;
i
++)
for
(
int
i
=
0
;
i
<
grid
.
childCount
;
i
++)
{
{
cells
[
i
]
=
grid
.
GetChild
(
i
).
GetComponent
<
Cell
>();
cells
[
i
]
=
grid
.
GetChild
(
i
).
GetComponent
<
Cell
>();
}
}
//创建格子助手
//创建格子助手
gHelper
=
new
GridHelper
(
gameLevel
.
r
,
gameLevel
.
c
);
gHelper
=
new
GridHelper
(
gameLevel
.
r
,
gameLevel
.
c
);
//TODo随机定义雷格子 从所有格子中选出 ?个用来放雷
//TODo随机定义雷格子 从所有格子中选出 ?个用来放雷
List
<
Cell
>
cellsList
=
new
List
<
Cell
>();
List
<
Cell
>
cellsList
=
new
List
<
Cell
>();
cellsList
.
AddRange
(
cells
);
cellsList
.
AddRange
(
cells
);
for
(
int
i
=
0
;
i
<
gameLevel
.
bombCount
;
i
++)
for
(
int
i
=
0
;
i
<
gameLevel
.
bombCount
;
i
++)
{
{
int
index
=
Random
.
Range
(
0
,
cellsList
.
Count
);
int
index
=
UnityEngine
.
Random
.
Range
(
0
,
cellsList
.
Count
);
cellsList
[
index
].
isBomb
=
true
;
cellsList
[
index
].
isBomb
=
true
;
cellsList
.
RemoveAt
(
index
);
cellsList
.
RemoveAt
(
index
);
}
}
//给格子添加点击事件
//给格子添加点击事件
foreach
(
Cell
cell
in
cells
)
foreach
(
Cell
cell
in
cells
)
{
{
cell
.
onClick
.
AddListener
(()
=>
cell
.
onClick
.
AddListener
(()
=>
{
{
//标记开始开始计时
//标记开始开始计时
if
(!
started
)
if
(!
started
)
...
@@ -111,27 +114,63 @@ public class Panel_Play : MonoBehaviour
...
@@ -111,27 +114,63 @@ public class Panel_Play : MonoBehaviour
started
=
true
;
started
=
true
;
}
}
if
(
CurrentTool
==
-
1
)
if
(
CurrentTool
==
-
1
)
{
{
//开格子
//开格子
OpenCell
(
cell
);
OpenCell
(
cell
);
if
(
isGameEnd
())
//如果游戏结束
{
OnGameEnd
();
}
}
}
else
if
(
CurrentTool
==
0
)
else
if
(
CurrentTool
==
0
)
{
{
Flag
(
cell
);
Flag
(
cell
);
}
}
else
if
(
CurrentTool
==
1
)
else
if
(
CurrentTool
==
1
)
{
{
//未知
//未知
if
(
cell
.
State
!=
CellState
.
opened
)
if
(
cell
.
State
!=
CellState
.
opened
)
cell
.
State
=
cell
.
State
==
CellState
.
unknow
?
CellState
.
normal
:
CellState
.
unknow
;
cell
.
State
=
cell
.
State
==
CellState
.
unknow
?
CellState
.
normal
:
CellState
.
unknow
;
}
}
});
});
}
}
PlayCellAnimation
();
PlayCellAnimation
();
}
}
private
void
OnGameEnd
()
{
}
private
bool
isGameEnd
()
{
//所有的雷都被标记 //或者所有不是雷的都被打开
bool
allFlaged
=
true
;
bool
allOpend
=
true
;
for
(
int
i
=
0
;
i
<
cells
.
Length
;
i
++)
{
if
(
cells
[
i
].
isBomb
)
//是雷
{
if
(
cells
[
i
].
State
!=
CellState
.
flag
)
{
allFlaged
=
false
;
}
}
else
//不是雷
{
if
(
cells
[
i
].
State
!=
CellState
.
opened
)
{
allOpend
=
false
;
}
}
}
return
allFlaged
||
allOpend
;
}
//标记
//标记
private
void
Flag
(
Cell
cell
)
private
void
Flag
(
Cell
cell
)
{
{
...
@@ -152,11 +191,11 @@ public class Panel_Play : MonoBehaviour
...
@@ -152,11 +191,11 @@ public class Panel_Play : MonoBehaviour
private
void
OpenCell
(
Cell
cell
)
private
void
OpenCell
(
Cell
cell
)
{
{
if
(
cell
.
State
!=
CellState
.
normal
)
return
;
if
(
cell
.
State
!=
CellState
.
normal
)
return
;
if
(
cell
.
isBomb
)
if
(
cell
.
isBomb
)
{
{
//游戏结束
//
TOTO
游戏结束
//显示所的雷
//显示所的雷
for
(
int
i
=
0
;
i
<
cells
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
cells
.
Length
;
i
++)
{
{
...
@@ -169,12 +208,12 @@ public class Panel_Play : MonoBehaviour
...
@@ -169,12 +208,12 @@ public class Panel_Play : MonoBehaviour
}
}
else
else
{
{
int
bombNumber
=
0
;
int
bombNumber
=
0
;
//显示周围有几个雷
//显示周围有几个雷
for
(
int
i
=
0
;
i
<
Rc
.
AllDirections
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
Rc
.
AllDirections
.
Length
;
i
++)
{
{
int
dirIndex
;
int
dirIndex
;
bool
exist
=
gHelper
.
DirIndex
(
cell
.
transform
.
GetSiblingIndex
(),
Rc
.
AllDirections
[
i
],
out
dirIndex
);
bool
exist
=
gHelper
.
DirIndex
(
cell
.
transform
.
GetSiblingIndex
(),
Rc
.
AllDirections
[
i
],
out
dirIndex
);
if
(
exist
)
if
(
exist
)
{
{
if
(
cells
[
dirIndex
].
isBomb
)
if
(
cells
[
dirIndex
].
isBomb
)
...
@@ -185,14 +224,14 @@ public class Panel_Play : MonoBehaviour
...
@@ -185,14 +224,14 @@ public class Panel_Play : MonoBehaviour
}
}
//文字显示
//文字显示
string
text
=
bombNumber
.
ToString
();
string
text
=
bombNumber
.
ToString
();
cell
.
text
.
text
=
text
==
"0"
?
""
:
text
;
cell
.
text
.
text
=
text
==
"0"
?
""
:
text
;
cell
.
text
.
color
=
Color
.
black
;
cell
.
text
.
color
=
Color
.
black
;
//装为 已打开
//装为 已打开
cell
.
State
=
CellState
.
opened
;
cell
.
State
=
CellState
.
opened
;
//换个白色背景图
//换个白色背景图
cell
.
GetComponent
<
Image
>().
sprite
=
cellWhite
;
cell
.
GetComponent
<
Image
>().
sprite
=
cellWhite
;
if
(
bombNumber
==
0
)
if
(
bombNumber
==
0
)
{
{
//打开周围的所有格子
//打开周围的所有格子
for
(
int
i
=
0
;
i
<
Rc
.
AllDirections
.
Length
;
i
++)
for
(
int
i
=
0
;
i
<
Rc
.
AllDirections
.
Length
;
i
++)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录