
1.制作障碍系统 (1.制作几种类型的障碍物的预制体 ((*.编写障碍物基类,以下几种均继承自基类,含碰撞体,RememberY(生成障碍物时该有多大的Y) ((1.矮障碍,仅碰撞体 ((2.高障碍,仅碰撞体 ((3.可冲破障碍 (((1.除基本碰撞体外,额外包含一个触发器,比碰撞体先检测到马,同时获取马的x速度,大于阈值则给障碍做破碎,用马的力度决定破碎力,关闭碎块和马的碰撞 (((*.导入某2D破碎插件 ((4.人马分离障碍 (((WAIT,需要等待人马分离系统先搭建 (2.编写障碍物生成系统 ((1.每若干时间,生成一个随机一种障碍,若干的范围可控 (((1.设计协程,从预制体列表中随机出一种,并在计算好的位置实例化,随后等待范围内的若干时间,然后检查马的存活情况,若马仍存活,重新调用本协程 ((2.生成的位置:x在相机右侧若干不变距离,y根据障碍物的不同而不同,需要计算保存。 (3.编写障碍物消亡系统 ((1.每个障碍物和碎片都会在离开镜头后被删除
96 lines
3.2 KiB
C#
96 lines
3.2 KiB
C#
#pragma warning disable 0436
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using ClipperLib;
|
|
using Polygon = System.Collections.Generic.List<ClipperLib.IntPoint>;
|
|
using Polygons = System.Collections.Generic.List<System.Collections.Generic.List<ClipperLib.IntPoint>>;
|
|
using Delaunay;
|
|
|
|
public static class ClipperHelper {
|
|
private static float multiplier = 1000;
|
|
|
|
public static List<List<Vector2>> clip(List<Vector2> boundary, Triangle piece)
|
|
{
|
|
//create Boundary Polygon
|
|
Polygons boundaryPoly = createPolygons(boundary);
|
|
|
|
//create Polygon from the triangular piece
|
|
Polygons subjPoly = createPolygons(piece);
|
|
|
|
//clip triangular polygon against the boundary polygon
|
|
Polygons result = new Polygons();
|
|
//忽略warning
|
|
#pragma warning disable CS0436 // The variable 'result' is assigned but its value is never used
|
|
Clipper c = new Clipper();
|
|
c.AddPaths(subjPoly, PolyType.ptClip, true);
|
|
c.AddPaths(boundaryPoly, PolyType.ptSubject, true);
|
|
c.Execute(ClipType.ctIntersection, result, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
|
|
|
|
List<List<Vector2>> clippedPolygons = new List<List<Vector2>>();
|
|
|
|
foreach (Polygon poly in result)
|
|
{
|
|
List<Vector2> clippedPoly = new List<Vector2>();
|
|
foreach (IntPoint p in poly)
|
|
{
|
|
clippedPoly.Add(new Vector2(p.X, p.Y) / multiplier);
|
|
}
|
|
clippedPolygons.Add(clippedPoly);
|
|
|
|
}
|
|
return clippedPolygons;
|
|
|
|
}
|
|
public static List<List<Vector2>> clip(List<Vector2> boundary, List<Vector2> region)
|
|
{
|
|
Polygons boundaryPoly = createPolygons(boundary);
|
|
Polygons regionPoly = createPolygons(region);
|
|
|
|
//clip triangular polygon against the boundary polygon
|
|
Polygons result = new Polygons();
|
|
Clipper c = new Clipper();
|
|
c.AddPaths(regionPoly, PolyType.ptClip, true);
|
|
c.AddPaths(boundaryPoly, PolyType.ptSubject, true);
|
|
c.Execute(ClipType.ctIntersection, result, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
|
|
|
|
List<List<Vector2>> clippedPolygons = new List<List<Vector2>>();
|
|
|
|
foreach (Polygon poly in result)
|
|
{
|
|
List<Vector2> clippedPoly = new List<Vector2>();
|
|
foreach (IntPoint p in poly)
|
|
{
|
|
clippedPoly.Add(new Vector2(p.X, p.Y) / multiplier);
|
|
}
|
|
clippedPolygons.Add(clippedPoly);
|
|
|
|
}
|
|
return clippedPolygons;
|
|
}
|
|
|
|
private static Polygons createPolygons(List<Vector2> source)
|
|
{
|
|
Polygons poly = new Polygons(1);
|
|
poly.Add(new Polygon(source.Count));
|
|
foreach (Vector2 p in source)
|
|
{
|
|
poly[0].Add(new IntPoint(p.x * multiplier, p.y * multiplier));
|
|
}
|
|
|
|
return poly;
|
|
}
|
|
private static Polygons createPolygons(Triangle tri)
|
|
{
|
|
Polygons poly = new Polygons(1);
|
|
poly.Add(new Polygon(3));
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
poly[0].Add(new IntPoint(tri.sites[i].x * multiplier, tri.sites[i].y * multiplier));
|
|
}
|
|
|
|
return poly;
|
|
}
|
|
|
|
}
|