Aimbot Enviroment very first

Basic environment include Multi scene, Reward Change, Visible chart, etc....
This commit is contained in:
2022-09-05 20:46:08 +09:00
parent aa337c5fc2
commit 2d404cfdf2
1552 changed files with 162551 additions and 0 deletions
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6e78d1d27fb8f42948af1c6050eb6a46
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,39 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XUGL
{
public static class SVG
{
public static bool yMirror = false;
public static void Test(VertexHelper vh)
{
//UGL.DrawSvgPath(vh, "path://M600,800 C625,700 725,700 750,800 S875,900 900,800");
//UGL.DrawSvgPath(vh, "path://M67.335,33.596L67.335,33.596c-0.002-1.39-1.153-3.183-3.328-4.218h-9.096v-2.07h5.371 c-4.939-2.07-11.199-4.141-14.89-4.141H19.72v12.421v5.176h38.373c4.033,0,8.457-1.035,9.142-5.176h-0.027 c0.076-0.367,0.129-0.751,0.129-1.165L67.335,33.596L67.335,33.596z M27.999,30.413h-3.105v-4.141h3.105V30.413z M35.245,30.413 h-3.104v-4.141h3.104V30.413z M42.491,30.413h-3.104v-4.141h3.104V30.413z M49.736,30.413h-3.104v-4.141h3.104V30.413z M14.544,40.764c1.143,0,2.07-0.927,2.07-2.07V35.59V25.237c0-1.145-0.928-2.07-2.07-2.07H-9.265c-1.143,0-2.068,0.926-2.068,2.07 v10.351v3.105c0,1.144,0.926,2.07,2.068,2.07H14.544L14.544,40.764z M8.333,26.272h3.105v4.141H8.333V26.272z M1.087,26.272h3.105 v4.141H1.087V26.272z M-6.159,26.272h3.105v4.141h-3.105V26.272z M-9.265,41.798h69.352v1.035H-9.265V41.798z");
//UGL.DrawSvgPath(vh, "path://M30.9,53.2C16.8,53.2,5.3,41.7,5.3,27.6S16.8,2,30.9,2C45,2,56.4,13.5,56.4,27.6S45,53.2,30.9,53.2z M30.9,3.5C17.6,3.5,6.8,14.4,6.8,27.6c0,13.3,10.8,24.1,24.101,24.1C44.2,51.7,55,40.9,55,27.6C54.9,14.4,44.1,3.5,30.9,3.5z M36.9,35.8c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H36c0.5,0,0.9,0.4,0.9,1V35.8z M27.8,35.8 c0,0.601-0.4,1-0.9,1h-1.3c-0.5,0-0.9-0.399-0.9-1V19.5c0-0.6,0.4-1,0.9-1H27c0.5,0,0.9,0.4,0.9,1L27.8,35.8L27.8,35.8z");
//人体
UGL.DrawSvgPath(vh, "path://M36.7,102.84c-1.17,2.54-2.99,4.98-3.39,7.63c-1.51,9.89-3.31,19.58-1.93,29.95 c0.95,7.15-2.91,14.82-3.57,22.35c-0.64,7.36-0.2,14.86,0.35,22.25c0.12,1.68,2.66,3.17,4.67,5.4c-0.6,0.82-1.5,2.22-2.58,3.48 c-0.96,1.12-1.96,2.35-3.21,3.04c-1.71,0.95-3.71,2.03-5.51,1.9c-1.18-0.08-3.04-2.13-3.16-3.43c-0.44-4.72,0-9.52-0.41-14.25 c-0.94-10.88-2.32-21.72-3.24-32.61c-0.49-5.84-1.63-12.01-0.35-17.54c3.39-14.56,2.8-28.84,0.36-43.4 c-2.71-16.16-1.06-32.4,0.54-48.59c0.91-9.22,4.62-17.36,8.53-25.57c1.32-2.77,1.88-6.84,0.87-9.62C21.89-3.77,18.09-11,14.7-18.38 c-0.56,0.1-1.13,0.21-1.69,0.31C10.17-11.52,6.29-5.2,4.71,1.65C2.05,13.21-4.42,22.3-11.43,31.28c-1.32,1.69-2.51,3.5-3.98,5.04 c-4.85,5.08-3.25,10.98-2.32,16.82c0.25,1.53,0.52,3.06,0.77,4.59c-0.53,0.22-1.07,0.43-1.6,0.65c-1.07-2.09-2.14-4.19-3.28-6.44 c-6.39,2.91-2.67,9.6-5.23,15.16c-1.61-3.31-2.77-5.68-3.93-8.06c0-0.33,0-0.67,0-1c6.96-16.08,14.63-31.9,20.68-48.31 C-5.24-4.07-2.03-18.55,2-32.73c0.36-1.27,0.75-2.53,0.98-3.82c1.36-7.75,4.19-10.23,11.88-10.38c1.76-0.04,3.52-0.21,5.76-0.35 c-0.55-3.95-1.21-7.3-1.45-10.68c-0.61-8.67,0.77-16.69,7.39-23.19c2.18-2.14,4.27-4.82,5.25-7.65c2.39-6.88,11.66-9,16.94-8.12 c5.92,0.99,12.15,7.93,12.16,14.12c0.01,9.89-5.19,17.26-12.24,23.68c-2.17,1.97-5.35,4.77-5.17,6.94c0.31,3.78,4.15,5.66,8.08,6.04 c1.82,0.18,3.7,0.37,5.49,0.1c5.62-0.85,8.8,2.17,10.85,6.73C73.38-27.19,78.46-14.9,84.2-2.91c1.52,3.17,4.52,5.91,7.41,8.09 c7.64,5.77,15.57,11.16,23.45,16.61c2.28,1.58,4.64,3.23,7.21,4.14c5.18,1.84,8.09,5.63,9.82,10.46c0.45,1.24,0.19,3.71-0.6,4.18 c-1.06,0.63-3.15,0.27-4.44-0.38c-7.05-3.54-12.84-8.88-19.14-13.5c-3.5-2.57-7.9-4-12.03-5.6c-9.44-3.66-17.73-8.42-22.5-18.09 c-2.43-4.94-6.09-9.27-9.69-14.61c-1.2,10.98-4.46,20.65,1.14,31.19c6.62,12.47,5.89,26.25,1.21,39.49 c-2.52,7.11-6.5,13.74-8.67,20.94c-1.91,6.33-2.2,13.15-3.23,19.75c-0.72,4.63-0.84,9.48-2.36,13.84 c-2.49,7.16-6.67,13.83-5.84,21.82c0.42,4.02,1.29,7.99,2.1,12.8c-3.74-0.49-7.47-0.4-10.67-1.66c-1.33-0.53-2.43-4.11-2.07-6.01 c1.86-9.94,3.89-19.69,0.07-29.74C34.55,108.63,36.19,105.52,36.7,102.84c1.25-8.45,2.51-16.89,3.71-24.9 c-0.83-0.58-0.85-0.59-0.87-0.61c-0.03,0.16-0.07,0.32-0.09,0.48C38.53,86.15,37.62,94.5,36.7,102.84z");
//UGL.DrawSvgPath(vh, "path://M29.902,23.275c1.86,0,3.368-1.506,3.368-3.365c0-1.859-1.508-3.365-3.368-3.365 c-1.857,0-3.365,1.506-3.365,3.365C26.537,21.769,28.045,23.275,29.902,23.275z M36.867,30.74c-1.666-0.467-3.799-1.6-4.732-4.199 c-0.932-2.6-3.131-2.998-4.797-2.998s-7.098,3.894-7.098,3.894c-1.133,1.001-2.1,6.502-0.967,6.769 c1.133,0.269,1.266-1.533,1.934-3.599c0.666-2.065,3.797-3.466,3.797-3.466s0.201,2.467-0.398,3.866 c-0.599,1.399-1.133,2.866-1.467,6.198s-1.6,3.665-3.799,6.266c-2.199,2.598-0.6,3.797,0.398,3.664 c1.002-0.133,5.865-5.598,6.398-6.998c0.533-1.397,0.668-3.732,0.668-3.732s0,0,2.199,1.867c2.199,1.865,2.332,4.6,2.998,7.73 s2.332,0.934,2.332-0.467c0-1.401,0.269-5.465-1-7.064c-1.265-1.6-3.73-3.465-3.73-5.265s1.199-3.732,1.199-3.732 c0.332,1.667,3.335,3.065,5.599,3.399C38.668,33.206,38.533,31.207,36.867,30.74z");
//钟表指针
//UGL.DrawSvgPath(vh, "path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z");
//钟表指针
//UGL.DrawSvgPath(vh, "path://M2.9,0.7L2.9,0.7c1.4,0,2.6,1.2,2.6,2.6v115c0,1.4-1.2,2.6-2.6,2.6l0,0c-1.4,0-2.6-1.2-2.6-2.6V3.3C0.3,1.9,1.4,0.7,2.9,0.7z");
}
public static void DrawPath(VertexHelper vh, string path)
{
var svgPath = SVGPath.Parse(path);
DrawPath(vh, svgPath);
}
public static void DrawPath(VertexHelper vh, SVGPath path)
{
path.Draw(vh);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cbe2b3aa282ad4cd9b469792fde7e092
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,202 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
namespace XUGL
{
public class SVGPath
{
private static Regex s_PathRegex = new Regex(@"(([a-z]|[A-Z])(\d|\.|,|-)*)");
private static Regex s_PathValueRegex = new Regex(@"(^[a-z]|[A-Z])\s*(-?\d+\.*\d*)*[\s|,|-]*(\d+\.*\d*)*");
private static Regex s_PathValueRegex2 = new Regex(@"(-?\d+\.?\d*)");
public bool mirrorY = true;
public List<SVGPathSeg> segs = new List<SVGPathSeg>();
public void AddSegment(SVGPathSeg seg)
{
segs.Add(seg);
}
public static SVGPath Parse(string path)
{
if (string.IsNullOrEmpty(path))
return new SVGPath();
if (path.StartsWith("path://"))
{
path = path.Substring(7);
}
path = path.Replace(' ', ',');
var mc = s_PathRegex.Matches(path);
var svgPath = new SVGPath();
foreach (var m in mc)
{
var key = m.ToString();
if (key.Equals("Z") || key.Equals("z"))
{
var seg = new SVGPathSeg(SVGPathSegType.Z);
seg.raw = key;
seg.relative = key.Equals("z");
svgPath.AddSegment(seg);
}
else
{
var type = s_PathValueRegex.Match(key).Groups[1].ToString().ToCharArray() [0];
var mc3 = s_PathValueRegex2.Matches(key);
SVGPathSeg seg = null;
switch (type)
{
case 'M':
case 'm':
seg = new SVGPathSeg(SVGPathSegType.M);
seg.relative = type == 'm';
break;
case 'L':
case 'l':
seg = new SVGPathSeg(SVGPathSegType.L);
seg.relative = type == 'l';
break;
case 'H':
case 'h':
seg = new SVGPathSeg(SVGPathSegType.H);
seg.relative = type == 'h';
break;
case 'V':
case 'v':
seg = new SVGPathSeg(SVGPathSegType.V);
seg.relative = type == 'v';
break;
case 'C':
case 'c':
seg = new SVGPathSeg(SVGPathSegType.C);
seg.relative = type == 'c';
break;
case 'S':
case 's':
seg = new SVGPathSeg(SVGPathSegType.S);
seg.relative = type == 's';
break;
case 'Q':
case 'q':
seg = new SVGPathSeg(SVGPathSegType.Q);
seg.relative = type == 'q';
break;
case 'T':
case 't':
seg = new SVGPathSeg(SVGPathSegType.T);
seg.relative = type == 't';
break;
case 'A':
case 'a':
seg = new SVGPathSeg(SVGPathSegType.A);
seg.relative = type == 'a';
break;
}
if (seg != null)
{
seg.raw = key;
foreach (var m3 in mc3)
{
// if (type == 'c' || type == 'C')
//Debug.LogError("\tmc3:" + type + "," + m3.ToString());
float p;
if (float.TryParse(m3.ToString(), out p))
seg.parameters.Add(p);
}
svgPath.AddSegment(seg);
}
}
}
// Debug.LogError(path);
// foreach (var cmd in svgPath.commands)
// {
// Debug.LogError(cmd.raw);
// }
return svgPath;
}
public void Draw(VertexHelper vh)
{
var sp = Vector2.zero;
var np = Vector2.zero;
var posList = new List<Vector3>();
var bezierList = new List<Vector3>();
var cp2 = Vector2.zero;
foreach (var seg in segs)
{
switch (seg.type)
{
case SVGPathSegType.M:
sp = np = seg.relative ? np + seg.p1 : seg.p1;
if (posList.Count > 0)
{
DrawPosList(vh, posList);
}
posList.Add(np);
break;
case SVGPathSegType.L:
np = seg.relative ? np + seg.p1 : seg.p1;
posList.Add(np);
break;
case SVGPathSegType.H:
np = seg.relative ? np + new Vector2(seg.value, 0) : new Vector2(seg.value, np.y);
posList.Add(np);
break;
case SVGPathSegType.V:
np = seg.relative ? np + new Vector2(0, seg.value) : new Vector2(np.x, seg.value);
posList.Add(np);
break;
case SVGPathSegType.C:
var cp1 = seg.relative ? np + seg.p1 : seg.p1;
cp2 = seg.relative ? np + seg.p2 : seg.p2;
var ep = seg.relative ? np + seg.p3 : seg.p3;
var dist = (int) Vector2.Distance(np, ep) * 2;
if (dist < 2) dist = 2;
UGLHelper.GetBezierList2(ref bezierList, np, ep, dist, cp1, cp2);
for (int n = 1; n < bezierList.Count; n++)
posList.Add(bezierList[n]);
np = ep;
break;
case SVGPathSegType.S:
cp1 = np + (np - cp2).normalized * Vector2.Distance(np, cp2);
var scp2 = seg.relative ? np + seg.p1 : seg.p1;
ep = seg.relative ? np + seg.p2 : seg.p2;
dist = (int) Vector2.Distance(np, ep) * 2;
if (dist < 2) dist = 2;
UGLHelper.GetBezierList2(ref bezierList, np, ep, dist, cp1, scp2);
for (int n = 1; n < bezierList.Count; n++)
posList.Add(bezierList[n]);
break;
case SVGPathSegType.Z:
posList.Add(sp);
DrawPosList(vh, posList);
break;
case SVGPathSegType.Q:
case SVGPathSegType.T:
case SVGPathSegType.A:
default:
Debug.LogError("unknow seg:" + seg.type);
break;
}
}
if (posList.Count > 0)
DrawPosList(vh, posList);
//UGL.DrawCricle(vh, sp, 1, Color.black);
}
private void DrawPosList(VertexHelper vh, List<Vector3> posList)
{
if (mirrorY)
{
for (int i = posList.Count - 1; i >= 0; i--)
{
var pos = posList[i];
posList[i] = new Vector3(pos.x, -pos.y);
}
}
UGL.DrawLine(vh, posList, 1f, Color.red, false);
posList.Clear();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c4119dc5490ec4f8bbcc67aa6eee024a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
namespace XUGL
{
public class SVGPathSeg
{
public SVGPathSegType type;
public bool relative;
public List<float> parameters = new List<float>();
public string raw;
public SVGPathSeg(SVGPathSegType type)
{
this.type = type;
}
public float value
{
get
{
if (type == SVGPathSegType.H)
return SVG.yMirror ? -parameters[0] : parameters[0];
else
return parameters[0];
}
}
public float x { get { return parameters[0]; } }
public float y { get { return SVG.yMirror ? -parameters[1] : parameters[1]; } }
public Vector2 p1 { get { return new Vector2(parameters[0], (SVG.yMirror ? -parameters[1] : parameters[1])); } }
public Vector2 p2 { get { return new Vector2(parameters[2], (SVG.yMirror ? -parameters[3] : parameters[3])); } }
public Vector2 p3 { get { return new Vector2(parameters[4], (SVG.yMirror ? -parameters[5] : parameters[5])); } }
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c97d44ceb28a471aa3d657f3984e6b1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,51 @@
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
namespace XUGL
{
public enum SVGPathSegType
{
/// <summary>
/// move to
/// </summary>
M,
/// <summary>
/// line to
/// </summary>
L,
/// <summary>
/// horizontal line to
/// </summary>
H,
/// <summary>
/// vertial line to
/// </summary>
V,
/// <summary>
/// curve to
/// </summary>
C,
/// <summary>
/// smooth curve to
/// </summary>
S,
/// <summary>
/// quadratic bezier curve
/// </summary>
Q,
/// <summary>
/// smooth quadratic bezier curve to
/// </summary>
T,
/// <summary>
/// elliptical Arc
/// </summary>
A,
/// <summary>
/// close path
/// </summary>
Z
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ebd7fe1a38c81433697bbe21c2e962ba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 463dc57c2fc1849379941a7facf8dc84
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace XUGL
{
[ExecuteInEditMode]
public class UGLExample : MaskableGraphic
{
private float m_Width = 800;
private float m_Height = 800;
private Vector3 m_Center = Vector3.zero;
private Vector3 m_LeftTopPos = Vector3.zero;
private Color32 m_BackgroundColor = new Color32(224, 224, 224, 255);
private Color32 m_DrawColor = new Color32(255, 132, 142, 255);
private float[] m_BorderRadius = new float[] { 5, 5, 10, 10 };
protected override void Awake()
{
base.Awake();
var rectTransform = GetComponent<RectTransform>();
rectTransform.sizeDelta = new Vector2(500, 500);
rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
rectTransform.pivot = new Vector2(0.5f, 0.5f);
m_Center = Vector3.zero;
m_LeftTopPos = new Vector3(-m_Width / 2, m_Height / 2);
}
protected override void OnPopulateMesh(VertexHelper vh)
{
Vector3 sp, cp, ep;
vh.Clear();
//背景边框
UGL.DrawSquare(vh, m_Center, m_Width / 2, m_BackgroundColor);
UGL.DrawBorder(vh, m_Center, m_Width, m_Height, 40, Color.green, Color.red, 0, m_BorderRadius, false, 1);
//点
UGL.DrawCricle(vh, m_LeftTopPos + new Vector3(20, -20), 10, m_DrawColor);
//直线
sp = new Vector3(m_LeftTopPos.x + 50, m_LeftTopPos.y - 20);
ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 20);
UGL.DrawLine(vh, sp, ep, 3, m_DrawColor);
//3点确定的折线
sp = new Vector3(m_LeftTopPos.x + 20, m_LeftTopPos.y - 100);
cp = new Vector3(m_LeftTopPos.x + 200, m_LeftTopPos.y - 40);
ep = new Vector3(m_LeftTopPos.x + 250, m_LeftTopPos.y - 80);
UGL.DrawLine(vh, sp, cp, ep, 5, m_DrawColor);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8a87ea5df031473da3eb5fb8f57e20a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,389 @@
using System.Collections.Generic;
using UnityEngine;
namespace XUGL
{
public static class UGLHelper
{
public static bool IsValueEqualsColor(Color32 color1, Color32 color2)
{
return color1.a == color2.a &&
color1.b == color2.b &&
color1.g == color2.g &&
color1.r == color2.r;
}
public static bool IsValueEqualsColor(Color color1, Color color2)
{
return color1.a == color2.a &&
color1.b == color2.b &&
color1.g == color2.g &&
color1.r == color2.r;
}
public static bool IsValueEqualsString(string str1, string str2)
{
if (str1 == null && str2 == null)
return true;
else if (str1 != null && str2 != null)
return str1.Equals(str2);
else return false;
}
public static bool IsValueEqualsVector2(Vector2 v1, Vector2 v2)
{
return v1.x == v2.x &&
v1.y == v2.y;
}
public static bool IsValueEqualsVector3(Vector3 v1, Vector3 v2)
{
return v1.x == v2.x &&
v1.y == v2.y &&
v1.z == v2.z;
}
public static bool IsValueEqualsVector3(Vector3 v1, Vector2 v2)
{
return v1.x == v2.x &&
v1.y == v2.y;
}
public static bool IsValueEqualsList<T>(List<T> list1, List<T> list2)
{
if (list1 == null || list2 == null)
return false;
if (list1.Count != list2.Count)
return false;
for (int i = 0; i < list1.Count; i++)
{
if (list1[i] == null && list2[i] == null)
{ }
else
{
if (list1[i] != null)
{
if (!list1[i].Equals(list2[i]))
return false;
}
else
{
if (!list2[i].Equals(list1[i]))
return false;
}
}
}
return true;
}
public static bool IsClearColor(Color32 color)
{
return color.a == 0 &&
color.b == 0 &&
color.g == 0 &&
color.r == 0;
}
public static bool IsClearColor(Color color)
{
return color.a == 0 &&
color.b == 0 &&
color.g == 0 &&
color.r == 0;
}
public static bool IsZeroVector(Vector3 pos)
{
return pos.x == 0 &&
pos.y == 0 &&
pos.z == 0;
}
public static Vector3 RotateRound(Vector3 position, Vector3 center, Vector3 axis, float angle)
{
Vector3 point = Quaternion.AngleAxis(angle, axis) * (position - center);
Vector3 resultVec3 = center + point;
return resultVec3;
}
public static void GetBezierList(ref List<Vector3> posList, Vector3 sp, Vector3 ep,
Vector3 lsp, Vector3 nep, float smoothness = 2f, float k = 2.0f)
{
float dist = Mathf.Abs(sp.x - ep.x);
Vector3 cp1, cp2;
var dir = (ep - sp).normalized;
var diff = dist / k;
if (lsp == sp)
{
cp1 = sp + dist / k * dir * 1;
cp1.y = sp.y;
cp1 = sp;
}
else
{
cp1 = sp + (ep - lsp).normalized * diff;
}
if (nep == ep) cp2 = ep;
else cp2 = ep - (nep - sp).normalized * diff;
dist = Vector3.Distance(sp, ep);
int segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness));
if (segment < 1) segment = (int) (dist / 0.5f);
if (segment < 4) segment = 4;
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
if (posList.Count < 2)
{
posList.Clear();
posList.Add(sp);
posList.Add(ep);
}
}
public static void GetBezierListVertical(ref List<Vector3> posList, Vector3 sp, Vector3 ep,
float smoothness = 2f, float k = 2.0f)
{
Vector3 dir = (ep - sp).normalized;
float dist = Vector3.Distance(sp, ep);
Vector3 cp1 = sp + dist / k * dir * 1;
Vector3 cp2 = sp + dist / k * dir * (k - 1);
cp1.x = sp.x;
cp2.x = ep.x;
int segment = (int) (dist / (smoothness <= 0 ? 2f : smoothness));
GetBezierList2(ref posList, sp, ep, segment, cp1, cp2);
if (posList.Count < 2)
{
posList.Clear();
posList.Add(sp);
posList.Add(ep);
}
}
public static List<Vector3> GetBezierList(Vector3 sp, Vector3 ep, int segment, Vector3 cp)
{
List<Vector3> list = new List<Vector3>();
for (int i = 0; i < segment; i++)
{
list.Add(GetBezier(i / (float) segment, sp, cp, ep));
}
list.Add(ep);
return list;
}
public static void GetBezierList2(ref List<Vector3> posList, Vector3 sp, Vector3 ep,
int segment, Vector3 cp, Vector3 cp2)
{
posList.Clear();
if (posList.Capacity < segment + 1)
{
posList.Capacity = segment + 1;
}
for (int i = 0; i < segment; i++)
{
posList.Add((GetBezier2(i / (float) segment, sp, cp, cp2, ep)));
}
posList.Add(ep);
}
public static Vector3 GetBezier(float t, Vector3 sp, Vector3 cp, Vector3 ep)
{
Vector3 aa = sp + (cp - sp) * t;
Vector3 bb = cp + (ep - cp) * t;
return aa + (bb - aa) * t;
}
public static Vector3 GetBezier2(float t, Vector3 sp, Vector3 p1, Vector3 p2, Vector3 ep)
{
t = Mathf.Clamp01(t);
var oneMinusT = 1f - t;
return oneMinusT * oneMinusT * oneMinusT * sp +
3f * oneMinusT * oneMinusT * t * p1 +
3f * oneMinusT * t * t * p2 +
t * t * t * ep;
}
public static Vector3 GetDire(float angle, bool isDegree = false)
{
angle = isDegree ? angle * Mathf.Deg2Rad : angle;
return new Vector3(Mathf.Sin(angle), Mathf.Cos(angle));
}
public static Vector3 GetVertialDire(Vector3 dire)
{
if (dire.x == 0)
return new Vector3(-1, 0, 0);
if (dire.y == 0)
return new Vector3(0, -1, 0);
else
return new Vector3(-dire.y / dire.x, 1, 0).normalized;
}
/// <summary>
/// 获得0-360的角度(12点钟方向为0度)
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
/// <returns></returns>
public static float GetAngle360(Vector2 from, Vector2 to)
{
float angle;
Vector3 cross = Vector3.Cross(from, to);
angle = Vector2.Angle(from, to);
angle = cross.z > 0 ? -angle : angle;
angle = (angle + 360) % 360;
return angle;
}
public static Vector3 GetPos(Vector3 center, float radius, float angle, bool isDegree = false)
{
angle = isDegree ? angle * Mathf.Deg2Rad : angle;
return new Vector3(center.x + radius * Mathf.Sin(angle),
center.y + radius * Mathf.Cos(angle));
}
/// <summary>
/// 获得两直线的交点
/// </summary>
/// <param name="p1">线段1起点</param>
/// <param name="p2">线段1终点</param>
/// <param name="p3">线段2起点</param>
/// <param name="p4">线段2终点</param>
/// <param name="intersection">相交点。当不想交时默认为 Vector3.zero </param>
/// <returns>相交则返回 true, 否则返回 false</returns>
public static bool GetIntersection(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, ref Vector3 intersection)
{
intersection = Vector3.zero;
var d = (p2.x - p1.x) * (p4.y - p3.y) - (p2.y - p1.y) * (p4.x - p3.x);
if (d == 0)
return false;
var u = ((p3.x - p1.x) * (p4.y - p3.y) - (p3.y - p1.y) * (p4.x - p3.x)) / d;
var v = ((p3.x - p1.x) * (p2.y - p1.y) - (p3.y - p1.y) * (p2.x - p1.x)) / d;
if (u < 0 || u > 1 || v < 0 || v > 1)
return false;
intersection.x = p1.x + u * (p2.x - p1.x);
intersection.y = p1.y + u * (p2.y - p1.y);
return true;
}
/// <summary>
/// 三个点画线段所需要的六个关键点
/// </summary>
/// <param name="lp">上一个点</param>
/// <param name="cp">当前点</param>
/// <param name="np">下一个点</param>
/// <param name="width">线段宽度</param>
/// <param name="ltp">上一个点的上角点</param>
/// <param name="lbp">上一个点的下角点</param>
/// <param name="ntp">下一个点的上角点</param>
/// <param name="nbp">下一个点的下角点</param>
/// <param name="itp">交汇点的上角点</param>
/// <param name="ibp">交汇点的下角点</param>
internal static void GetLinePoints(Vector3 lp, Vector3 cp, Vector3 np, float width,
ref Vector3 ltp, ref Vector3 lbp,
ref Vector3 ntp, ref Vector3 nbp,
ref Vector3 itp, ref Vector3 ibp,
ref Vector3 clp, ref Vector3 crp,
ref bool bitp, ref bool bibp, int debugIndex = 0)
{
var dir1 = (cp - lp).normalized;
var dir1v = Vector3.Cross(dir1, Vector3.forward).normalized * width;
ltp = lp - dir1v;
lbp = lp + dir1v;
if (debugIndex == 1 && cp == np)
{
ntp = np - dir1v;
nbp = np + dir1v;
clp = cp - dir1v;
crp = cp + dir1v;
return;
}
var dir2 = (cp - np).normalized;
var dir2v = Vector3.Cross(dir2, Vector3.back).normalized * width;
ntp = np - dir2v;
nbp = np + dir2v;
clp = cp - dir2v;
crp = cp + dir2v;
if (Vector3.Cross(dir1, dir2) == Vector3.zero && np != cp)
{
itp = ntp;
ibp = nbp;
return;
}
var ldist = (Vector3.Distance(cp, lp) + 1) * dir1;
var rdist = (Vector3.Distance(cp, np) + 1) * dir2;
bitp = true;
if (!UGLHelper.GetIntersection(ltp, ltp + ldist, ntp, ntp + rdist, ref itp))
{
itp = cp - dir1v;
clp = cp - dir1v;
crp = cp - dir2v;
bitp = false;
}
bibp = true;
if (!UGLHelper.GetIntersection(lbp, lbp + ldist, nbp, nbp + rdist, ref ibp))
{
ibp = cp + dir1v;
clp = cp + dir1v;
crp = cp + dir2v;
bibp = false;
}
if (bitp == false && bibp == false && cp == np)
{
ltp = cp - dir1v;
clp = cp + dir1v;
crp = cp + dir1v;
}
}
public static bool IsPointInTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 check)
{
var dire1 = check - p1;
var dire2 = check - p2;
var dire3 = check - p3;
var c1 = dire1.x * dire2.y - dire1.y * dire2.x;
var c2 = dire2.x * dire3.y - dire2.y * dire3.x;
var c3 = dire3.x * dire1.y - dire3.y * dire1.x;
return c1 * c2 >= 0 && c1 * c3 >= 0;
}
public static bool IsPointInPolygon(Vector3 p, List<Vector3> polyons)
{
if (polyons.Count == 0) return false;
var inside = false;
var j = polyons.Count - 1;
for (int i = 0; i < polyons.Count; j = i++)
{
var pi = polyons[i];
var pj = polyons[j];
if (((pi.y <= p.y && p.y < pj.y) || (pj.y <= p.y && p.y < pi.y)) &&
(p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y) + pi.x))
inside = !inside;
}
return inside;
}
public static bool IsPointInPolygon(Vector3 p, List<Vector2> polyons)
{
if (polyons.Count == 0) return false;
var inside = false;
var j = polyons.Count - 1;
for (int i = 0; i < polyons.Count; j = i++)
{
var pi = polyons[i];
var pj = polyons[j];
if (((pi.y <= p.y && p.y < pj.y) || (pj.y <= p.y && p.y < pi.y)) &&
(p.x < (pj.x - pi.x) * (p.y - pi.y) / (pj.y - pi.y) + pi.x))
inside = !inside;
}
return inside;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc77f59a050d547caa3de82f4a9abd99
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: