Here are the examples of the csharp api System.Collections.Generic.List.Add(UnityEngine.Vector3) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
218 Examples
19
Source : CutMesh.cs
with GNU Affero General Public License v3.0
from 3drepo
with GNU Affero General Public License v3.0
from 3drepo
private Mesh GetMesh(RepoForUnity.MeshLocation[] meshLocations)
{
List<Vector3> vertices = new List<Vector3>();
List<Vector3> normal = new List<Vector3>();
List<int> triangles = new List<int>();
foreach (var entry in meshLocations)
{
var go = GameObject.Find(entry.superMeshID);
var meshFilter = go.GetComponent<MeshFilter>();
var superMesh = meshFilter.mesh;
Dictionary<int, int> vIndexChange = new Dictionary<int, int>();
for (int i = 0; i < superMesh.uv2.Length; ++i)
{
if (superMesh.uv2[i].y == entry.index)
{
vIndexChange[i] = vertices.Count;
vertices.Add(superMesh.vertices[i]);
normal.Add(superMesh.normals[i]);
}
}
for (int i = 0; i < superMesh.triangles.Length; ++i)
{
var index = superMesh.triangles[i];
if (vIndexChange.ContainsKey(index))
{
triangles.Add(vIndexChange[index]);
}
}
}
var mesh = new Mesh();
mesh.vertices = vertices.ToArray();
mesh.normals = normal.ToArray();
mesh.triangles = triangles.ToArray();
return mesh;
}
19
Source : Bullet.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void FixedUpdate()
{
if ((this.phase == 2 || this.phase == 1) && this.leviMode)
{
this.spiralcount++;
if (this.spiralcount >= 60)
{
this.isdestroying = true;
this.RemoveMe();
return;
}
}
if (IN_GAME_MAIN_CAMERA.GameType == GameType.Single || BasePV.IsMine)
{
if (phase != 0)
{
return;
}
Checkreplacedan();
baseGT.position += (this.velocity * 50f + this.velocity2) * Time.fixedDeltaTime;
bool flag = false;
if (Physics.Linecast(nodes.Count > 1 ? nodes[this.nodes.Count - 2] : nodes[this.nodes.Count - 1], baseGT.position, out RaycastHit raycastHit, Layers.EnemyGroundNetwork.value))
{
bool flag3 = true;
Transform tf = raycastHit.collider.transform;
switch (tf.gameObject.layer)
{
case Layers.EnemyBoxN:
if (IN_GAME_MAIN_CAMERA.GameType == GameType.MultiPlayer)
{
BasePV.RPC("tieMeToOBJ", PhotonTargets.Others, new object[] { raycastHit.collider.transform.root.gameObject.GetPhotonView().viewID });
}
master.LastHook = this;
baseT.parent = tf;
break;
case Layers.GroundN:
master.LastHook = null;
if (FengGameManagerMKII.Level.Name.StartsWith("Custom-Anarchy"))
{
if (tf.gameObject.GetComponent<Anarchy.Custom.Scripts.ClippingObjectComponent>() != null)
{
baseT.parent = tf;
}
if (tf.gameObject.GetComponent<Anarchy.Custom.Scripts.TrapComponent>() != null)
{
isOnTrap = true;
var trap = tf.gameObject.GetComponent<Anarchy.Custom.Scripts.TrapComponent>();
if (trap.Type == Anarchy.Custom.Scripts.TrapType.Both || trap.Type == Anarchy.Custom.Scripts.TrapType.GasUsage)
{
master.GasMultiplier = trap.GasUsageMultiplier;
}
if(trap.Type == Anarchy.Custom.Scripts.TrapType.Both || trap.Type == Anarchy.Custom.Scripts.TrapType.Kill)
{
trapKillTimer = trap.KillTime;
}
}
}
break;
case Layers.NetworkObjectN:
if (!tf.gameObject.CompareTag("Player") || leviMode)
{
break;
}
if (IN_GAME_MAIN_CAMERA.GameType == GameType.MultiPlayer)
{
BasePV.RPC("tieMeToOBJ", PhotonTargets.Others, new object[] { tf.root.gameObject.GetPhotonView().viewID });
}
master.HookToHuman(tf.root.gameObject, baseT.position);
baseT.parent = tf;
master.LastHook = null;
break;
default:
flag3 = false;
break;
}
if (flag3)
{
if (master.State != HeroState.Grab)
{
master.Launch(raycastHit.point, this.left, this.leviMode);
}
baseT.position = raycastHit.point;
if (this.phase != 2)
{
this.phase = 1;
if (IN_GAME_MAIN_CAMERA.GameType == GameType.MultiPlayer)
{
BasePV.RPC("setPhase", PhotonTargets.Others, new object[] { 1 });
BasePV.RPC("tieMeTo", PhotonTargets.Others, new object[] { baseT.position });
}
if (this.leviMode)
{
this.GetSpiral(master.baseT.position, master.baseT.rotation.eulerAngles);
}
flag = true;
}
}
}
this.nodes.Add(new Vector3(baseGT.position.x, baseGT.position.y, baseGT.position.z));
if (flag)
{
return;
}
this.killTime2 += Time.fixedDeltaTime;
if (this.killTime2 > 0.8f)
{
this.phase = 4;
if (IN_GAME_MAIN_CAMERA.GameType == GameType.MultiPlayer)
{
BasePV.RPC("setPhase", PhotonTargets.Others, new object[] { 4 });
}
return;
}
return;
}
if (this.phase == 0)
{
baseGT.position += (this.velocity * 50f + this.velocity2) * Time.fixedDeltaTime;
nodes.Add(new Vector3(baseGT.position.x, baseGT.position.y, baseGT.position.z));
}
}
19
Source : Bullet.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private void GetSpiral(Vector3 masterposition, Vector3 masterrotation)
{
float num = 30f;
float num2 = 0.5f;
float num3 = 0.05f + (float)this.spiralcount * 0.03f;
float num5;
if (this.spiralcount < 5)
{
float num4 = Vector2.Distance(new Vector2(masterposition.x, masterposition.z), new Vector2(baseGT.position.x, baseGT.position.z));
num5 = num4;
}
else
{
num5 = 1.2f + (float)(60 - this.spiralcount) * 0.1f;
}
num2 -= (float)this.spiralcount * 0.06f;
float num6 = num5 / num;
float num7 = num3 / num;
float num8 = num7 * 2f * 3.14159274f;
num2 *= 6.28318548f;
this.spiralNodes = new List<Vector3>();
int num9 = 1;
while ((float)num9 <= num)
{
float num10 = (float)num9 * num6 * (1f + 0.05f * (float)num9);
float f = (float)num9 * num8 + num2 + 1.2566371f + masterrotation.y * 0.0173f;
float x = Mathf.Cos(f) * num10;
float z = -Mathf.Sin(f) * num10;
this.spiralNodes.Add(new Vector3(x, 0f, z));
num9++;
}
}
19
Source : Bullet.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
[RPC]
private void netLaunch(Vector3 newPosition)
{
this.nodes = new List<Vector3>();
this.nodes.Add(newPosition);
}
19
Source : Bullet.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void Launch(Vector3 v, Vector3 v2, string launcher_ref, bool isLeft, HERO hero, bool leviMode = false)
{
if (this.phase == 2)
{
return;
}
this.master = hero;
this.velocity = v;
float f = Mathf.Acos(Vector3.Dot(v.normalized, v2.normalized)) * 57.29578f;
if (Mathf.Abs(f) > 90f)
{
this.velocity2 = Vectors.zero;
}
else
{
this.velocity2 = Vector3.Project(v2, v);
}
switch (launcher_ref)
{
case "hookRefL1":
this.myRef = hero.hookRefL1;
break;
case "hookRefL2":
this.myRef = hero.hookRefL2;
break;
case "hookRefR1":
this.myRef = hero.hookRefR1;
break;
case "hookRefR2":
this.myRef = hero.hookRefR2;
break;
}
myRefT = myRef.transform;
this.nodes = new List<Vector3>();
this.nodes.Add(myRefT.position);
this.phase = 0;
this.leviMode = leviMode;
this.left = isLeft;
if (IN_GAME_MAIN_CAMERA.GameType != GameType.Single && BasePV.IsMine)
{
BasePV.RPC("myMasterIs", PhotonTargets.Others, new object[] { hero.BasePV.viewID, launcher_ref });
BasePV.RPC("setVelocityAndLeft", PhotonTargets.Others, new object[] { v, this.velocity2, this.left });
}
baseT.position = myRefT.position;
baseT.rotation = Quaternion.LookRotation(v.normalized);
}
19
Source : FengGameManagerMKII.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void SpawnPlayerAt(string id, string find = "")
{
if (!CustomLevel.logicLoaded || !CustomLevel.customLevelLoaded)
{
NotSpawnPlayer(id);
return;
}
myLastRespawnTag = find;
Vector3 pos;
var rot = Quaternion.idenreplacedy;
if (find != string.Empty)
{
var positions = GameObject.FindGameObjectsWithTag(find);
if (positions.Length > 0)
{
pos = positions[Random.Range(0, positions.Length)].transform.position;
}
else
{
pos = RespawnPositions.RandomHeroPos;
}
}
else if (IN_GAME_MAIN_CAMERA.GameMode == GameMode.PVP_CAPTURE)
{
pos = checkpoint.transform.position;
}
else if (RCManager.racingSpawnPointSet)
{
pos = RCManager.racingSpawnPoint;
rot = RCManager.racingSpawnPointRotation;
}
else if (Level.Name.StartsWith("Custom"))
{
var list = new List<Vector3>();
switch (PhotonNetwork.player.RCteam)
{
case 0:
for (var i = 0; i < 2; i++)
{
var type = i == 0 ? "C" : "M";
foreach (var vec in CustomLevel.spawnPositions["Player" + type])
{
list.Add(vec);
}
}
break;
case 1:
using (var enumerator = CustomLevel.spawnPositions["PlayerC"].GetEnumerator())
{
while (enumerator.MoveNext())
{
var vec2 = enumerator.Current;
list.Add(vec2);
}
}
break;
case 2:
using (var enumerator = CustomLevel.spawnPositions["PlayerM"].GetEnumerator())
{
while (enumerator.MoveNext())
{
var vec2 = enumerator.Current;
list.Add(vec2);
}
}
break;
default:
foreach (var vec3 in CustomLevel.spawnPositions["PlayerM"])
{
list.Add(vec3);
}
break;
}
if (list.Count > 0)
{
pos = list[Random.Range(0, list.Count)];
}
else
{
pos = RespawnPositions.RandomHeroPos;
}
}
else
{
pos = RespawnPositions.RandomHeroPos;
}
var component = IN_GAME_MAIN_CAMERA.MainCamera;
myLastHero = id.ToUpper();
if (IN_GAME_MAIN_CAMERA.GameType == GameType.Single)
{
if (IN_GAME_MAIN_CAMERA.singleCharacter == "replacedAN_EREN")
{
component.SetMainObject(
((GameObject)Instantiate(CacheResources.Load("replacedAN_EREN"), pos, Quaternion.idenreplacedy))
.GetComponent<replacedAN_EREN>());
}
else
{
component.SetMainObject(((GameObject)Instantiate(CacheResources.Load("AOTTG_HERO 1"), pos, rot))
.GetComponent<HERO>());
if (IN_GAME_MAIN_CAMERA.singleCharacter == "SET 1" || IN_GAME_MAIN_CAMERA.singleCharacter == "SET 2" ||
IN_GAME_MAIN_CAMERA.singleCharacter == "SET 3")
{
var heroCostume = CostumeConeveter.LocalDataToHeroCostume(IN_GAME_MAIN_CAMERA.singleCharacter);
heroCostume.Checkstat();
CostumeConeveter.HeroCostumeToLocalData(heroCostume, IN_GAME_MAIN_CAMERA.singleCharacter);
IN_GAME_MAIN_CAMERA.MainHERO.Setup.Init();
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume = heroCostume;
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume.stat = heroCostume.stat;
IN_GAME_MAIN_CAMERA.MainHERO.Setup.SetCharacterComponent();
IN_GAME_MAIN_CAMERA.MainHERO.SetStat();
IN_GAME_MAIN_CAMERA.MainHERO.SetSkillHudPosition();
}
else
{
for (var i = 0; i < HeroCostume.costume.Length; i++)
{
if (HeroCostume.costume[i].name.ToUpper() == IN_GAME_MAIN_CAMERA.singleCharacter.ToUpper())
{
var num = HeroCostume.costume[i].id + CheckBoxCostume.costumeSet - 1;
if (HeroCostume.costume[num].name != HeroCostume.costume[i].name)
{
num = HeroCostume.costume[i].id + 1;
}
IN_GAME_MAIN_CAMERA.MainHERO.Setup.Init();
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume = HeroCostume.costume[num];
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume.stat =
HeroStat.getInfo(HeroCostume.costume[num].name.ToUpper());
IN_GAME_MAIN_CAMERA.MainHERO.Setup.SetCharacterComponent();
IN_GAME_MAIN_CAMERA.MainHERO.SetStat();
IN_GAME_MAIN_CAMERA.MainHERO.SetSkillHudPosition();
break;
}
}
}
}
}
else
{
var hero = Pool.NetworkEnable("AOTTG_HERO 1", pos, Quaternion.idenreplacedy).GetComponent<HERO>();
component.SetMainObject(hero);
id = id.ToUpper();
if (id == "SET 1" || id == "SET 2" || id == "SET 3")
{
var heroCostume2 = CostumeConeveter.LocalDataToHeroCostume(id);
heroCostume2.Checkstat();
CostumeConeveter.HeroCostumeToLocalData(heroCostume2, id);
IN_GAME_MAIN_CAMERA.MainHERO.Setup.Init();
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume = heroCostume2;
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume.stat = heroCostume2.stat;
IN_GAME_MAIN_CAMERA.MainHERO.Setup.SetCharacterComponent();
IN_GAME_MAIN_CAMERA.MainHERO.SetStat();
IN_GAME_MAIN_CAMERA.MainHERO.SetSkillHudPosition();
}
else
{
for (var j = 0; j < HeroCostume.costume.Length; j++)
{
if (HeroCostume.costume[j].name.ToUpper() == id.ToUpper())
{
var num2 = HeroCostume.costume[j].id;
if (id.ToUpper() != "AHSS")
{
num2 += CheckBoxCostume.costumeSet - 1;
}
if (HeroCostume.costume[num2].name != HeroCostume.costume[j].name)
{
num2 = HeroCostume.costume[j].id + 1;
}
IN_GAME_MAIN_CAMERA.MainHERO.Setup.Init();
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume = HeroCostume.costume[num2];
IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume.stat =
HeroStat.getInfo(HeroCostume.costume[num2].name.ToUpper());
IN_GAME_MAIN_CAMERA.MainHERO.Setup.SetCharacterComponent();
IN_GAME_MAIN_CAMERA.MainHERO.SetStat();
IN_GAME_MAIN_CAMERA.MainHERO.SetSkillHudPosition();
break;
}
}
}
CostumeConeveter.HeroCostumeToPhotonData(IN_GAME_MAIN_CAMERA.MainHERO.Setup.myCostume,
PhotonNetwork.player);
if (IN_GAME_MAIN_CAMERA.GameMode == GameMode.PVP_CAPTURE)
{
IN_GAME_MAIN_CAMERA.MainT.position += new Vector3(Random.Range(-20, 20), 2f, Random.Range(-20, 20));
}
PhotonNetwork.player.Dead = false;
PhotonNetwork.player.Isreplacedan = false;
}
component.enabled = true;
IN_GAME_MAIN_CAMERA.MainCamera.setHUDposition();
IN_GAME_MAIN_CAMERA.SpecMov.disable = true;
IN_GAME_MAIN_CAMERA.Look.disable = true;
component.gameOver = false;
Screen.lockCursor = IN_GAME_MAIN_CAMERA.CameraMode >= CameraType.TPS;
Screen.showCursor = false;
ShowHUDInfoCenter(string.Empty);
}
19
Source : Bullet.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void update()
{
if (this.isdestroying)
{
return;
}
if (this.master == null)
{
this.RemoveMe();
return;
}
if (this.leviMode)
{
this.leviShootTime += Time.deltaTime;
if (this.leviShootTime > 0.4f)
{
this.phase = 2;
baseG.GetComponent<MeshRenderer>().enabled = false;
}
}
if (this.phase == 0)
{
this.SetLinePhase();
}
else if (this.phase == 1)
{
Vector3 a = baseT.position - myRefT.position;
Vector3 vector = baseT.position + myRefT.position;
Vector3 a2 = master.baseR.velocity;
float magnitude = a2.magnitude;
float magnitude2 = a.magnitude;
int num = (int)((magnitude2 + magnitude) / 5f);
num = Mathf.Clamp(num, 2, 6);
this.lineRenderer.SetVertexCount(num);
this.lineRenderer.SetPosition(0, myRefT.position);
int i = 1;
float num2 = Mathf.Pow(magnitude2, 0.3f);
while (i < num)
{
int num3 = num / 2;
float num4 = (float)Mathf.Abs(i - num3);
float num5 = ((float)num3 - num4) / (float)num3;
num5 = Mathf.Pow(num5, 0.5f);
float num6 = (num2 + magnitude) * 0.0015f * num5;
this.lineRenderer.SetPosition(i, new Vector3(UnityEngine.Random.Range(-num6, num6), UnityEngine.Random.Range(-num6, num6), UnityEngine.Random.Range(-num6, num6)) + myRefT.position + a * ((float)i / (float)num) - Vectors.up * num2 * 0.05f * num5 - a2 * 0.001f * num5 * num2);
i++;
}
this.lineRenderer.SetPosition(num - 1, baseT.position);
if(isOnTrap && trapKillTimer > 0f)
{
hookHoldTimer += Time.deltaTime;
if(hookHoldTimer > trapKillTimer)
{
if(master != null)
{
Anarchy.Abuse.Kill(PhotonNetwork.player, "Trap");
}
}
}
}
else if (this.phase == 2)
{
if (this.leviMode)
{
this.GetSpiral(master.baseT.position, master.baseT.rotation.eulerAngles);
Vector3 b = myRefT.position - spiralNodes[0];
this.lineRenderer.SetVertexCount((int)((float)this.spiralNodes.Count - (float)this.spiralcount * 0.5f));
int num7 = 0;
while ((float)num7 <= (float)(this.spiralNodes.Count - 1) - (float)this.spiralcount * 0.5f)
{
if (this.spiralcount < 5)
{
Vector3 position = spiralNodes[num7] + b;
float num8 = (float)(this.spiralNodes.Count - 1) - (float)this.spiralcount * 0.5f;
position = new Vector3(position.x, position.y * ((num8 - (float)num7) / num8) + baseGT.position.y * ((float)num7 / num8), position.z);
this.lineRenderer.SetPosition(num7, position);
}
else
{
this.lineRenderer.SetPosition(num7, spiralNodes[num7] + b);
}
num7++;
}
}
else
{
this.lineRenderer.SetVertexCount(2);
this.lineRenderer.SetPosition(0, baseT.position);
this.lineRenderer.SetPosition(1, myRefT.position);
this.killTime += Time.deltaTime * (Time.fixedDeltaTime * 10f);
this.lineRenderer.SetWidth(0.1f - this.killTime, 0.1f - this.killTime);
if (this.killTime > 0.1f)
{
this.RemoveMe();
return;
}
}
}
else if (this.phase == 4)
{
baseGT.position += this.velocity + (this.velocity2 * Time.deltaTime);
this.nodes.Add(new Vector3(baseGT.position.x, baseGT.position.y, baseGT.position.z));
Vector3 a3 = myRefT.position - nodes[0];
for (int j = 0; j <= this.nodes.Count - 1; j++)
{
this.lineRenderer.SetVertexCount(this.nodes.Count);
this.lineRenderer.SetPosition(j, nodes[j] + a3 * Mathf.Pow(0.5f, (float)j));
}
this.killTime2 += Time.deltaTime;
if (this.killTime2 > 0.8f)
{
this.killTime += Time.deltaTime * (Time.fixedDeltaTime * 10f);
this.lineRenderer.SetWidth(0.1f - this.killTime, 0.1f - this.killTime);
if (this.killTime > 0.1f)
{
this.RemoveMe();
return;
}
}
}
}
19
Source : NavToColliderEditor.cs
with MIT License
from akof1314
with MIT License
from akof1314
private void OnShowVerts()
{
Handles.color = Color.blue;
for (int i = 0; i < m_RegionVerts.Count; i++)
{
var vertex = m_RegionVerts[i];
if (m_SelectedVerts.Contains(vertex))
{
continue;
}
float pointHandleSize = HandleUtility.GetHandleSize(vertex) * 0.04f;
float pointPickSize = pointHandleSize * 0.7f;
if (Handles.Button(vertex, Quaternion.idenreplacedy, pointHandleSize, pointPickSize, Handles.DotHandleCap))
{
m_SelectedVerts.Add(vertex);
Repaint();
return;
}
}
Handles.color = Color.green;
foreach (var vertex in m_SelectedVerts)
{
float pointHandleSize = HandleUtility.GetHandleSize(vertex) * 0.04f;
float pointPickSize = pointHandleSize * 0.7f;
Handles.DotHandleCap(0, vertex, Quaternion.idenreplacedy, pointPickSize, EventType.repaint);
}
}
19
Source : NavToColliderEditor.cs
with MIT License
from akof1314
with MIT License
from akof1314
private void GenBoxCollider(bool xAxis = false)
{
if (m_SelectedVerts.Count <= 1)
{
return;
}
Transform tf = m_NavToCollider.transform;
GameObject go = new GameObject("Box Collider");
go.transform.SetParent(tf, false);
Undo.RegisterCreatedObjectUndo(go, "GenBoxCollider");
List<Vector3> vertList = new List<Vector3>();
foreach (var vertex in m_SelectedVerts)
{
vertList.Add(vertex);
}
Transform tf2 = go.transform;
// 三点先构建一个平面
if (vertList.Count >= 3)
{
Plane plane = new Plane(vertList[0], vertList[1], vertList[2]);
Quaternion rotation = Quaternion.FromToRotation(tf2.up, -plane.normal) * tf2.rotation;
tf2.rotation = rotation;
}
vertList.Clear();
foreach (var vertex in m_SelectedVerts)
{
vertList.Add(tf2.InverseTransformPoint(vertex));
}
Vector3 min = new Vector3(Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
Vector3 max = new Vector3(-Mathf.Infinity, -Mathf.Infinity, -Mathf.Infinity);
foreach (var vertex in vertList)
{
min.x = Mathf.Min(vertex.x, min.x);
min.y = Mathf.Min(vertex.y, min.y);
min.z = Mathf.Min(vertex.z, min.z);
max.x = Mathf.Max(vertex.x, max.x);
max.y = Mathf.Max(vertex.y, max.y);
max.z = Mathf.Max(vertex.z, max.z);
}
Vector3 size = max - min;
Vector3 center = (max + min) / 2;
BoxCollider bc = go.AddComponent<BoxCollider>();
bc.size = size;
bc.center = center;
m_Colliders.Add(bc);
m_SelectedVerts.Clear();
go.layer = colliderLayer;
}
19
Source : NavToColliderEditor.cs
with MIT License
from akof1314
with MIT License
from akof1314
private void ShowSelectedRegion()
{
Bounds bounds = new Bounds(regionCenter, regionSize);
m_RegionVerts.Clear();
foreach (var vertex in m_NavMeshTriangulation.vertices)
{
if (bounds.Contains(vertex))
{
m_RegionVerts.Add(vertex);
}
}
SceneView.RepaintAll();
}
19
Source : DanAgent.cs
with GNU General Public License v3.0
from Animal42069
with GNU General Public License v3.0
from Animal42069
internal Vector3 ConstrainDanToCollisionPoints(Vector3 danStart, Vector3 danEnd, float targetLength, ref bool constrainPointFound, List<CollisionPoint> collisionPoints, float clippingDepth, bool frontSide, bool anaTarget)
{
Vector3 adjustedDanEnd = danEnd;
if (constrainPointFound)
return adjustedDanEnd;
var constainPastNearSide = true;
var constainPastFarSide = false;
List<Vector3> collisionPointPositions = new List<Vector3>();
var firstPoint = true;
foreach (var collisionPoint in collisionPoints)
{
var offset = collisionPoint.info.offset;
if (firstPoint && (anaTarget == frontSide))
offset = 0;
if (frontSide == collisionPoint.info.inward)
collisionPointPositions.Add(collisionPoint.transform.position + (clippingDepth + offset) * collisionPoint.transform.forward);
else
collisionPointPositions.Add(collisionPoint.transform.position - (clippingDepth + offset) * collisionPoint.transform.forward);
firstPoint = false;
}
for (int index = 1; index < collisionPoints.Count; index++)
{
if (constrainPointFound)
break;
CollisionPoint nearPoint = collisionPoints[index - 1];
CollisionPoint farPoint = collisionPoints[index];
Vector3 nearVectorRight = nearPoint.transform.right;
Vector3 farVectorRight = farPoint.transform.right;
if (frontSide == nearPoint.info.inward)
nearVectorRight = -nearVectorRight;
if (frontSide == farPoint.info.inward)
farVectorRight = -farVectorRight;
TwistedPlane hPlane = new TwistedPlane(collisionPointPositions[index - 1], nearVectorRight, collisionPointPositions[index], farVectorRight);
if (index == collisionPoints.Count - 1)
constainPastFarSide = true;
adjustedDanEnd = hPlane.ConstrainLineToTwistedPlane(danStart, danEnd, targetLength, ref constainPastNearSide, constainPastFarSide, out constrainPointFound);
}
return adjustedDanEnd;
}
19
Source : DanAgent.cs
with GNU General Public License v3.0
from Animal42069
with GNU General Public License v3.0
from Animal42069
internal List<Vector3> AdjustDanPointsToTargets(Vector3 danLookTarget, Vector3 danEndTarget, float danLength, float danDistanceToTarget, out Vector3 bellyEnd)
{
List<Vector3> adjustedDanPoints = new List<Vector3>();
foreach (var point in m_danPoints.danPoints)
adjustedDanPoints.Add(point.transform.position);
Vector3 outsideVector = Vector3.Normalize(danLookTarget - adjustedDanPoints[0]);
Vector3 insideVector = Vector3.Normalize(danEndTarget - danLookTarget);
bool singleVector = false;
if (!m_bpDanPointsFound)
{
insideVector = outsideVector = Vector3.Normalize(danEndTarget - adjustedDanPoints[0]);
singleVector = true;
}
else if (MathHelpers.VectorsEqual(outsideVector, insideVector, 0.001f) || danLength <= danDistanceToTarget)
{
insideVector = outsideVector;
singleVector = true;
}
float danSegmentLength = danLength / (adjustedDanPoints.Count - 1);
float fullDanBellyLength = m_baseDanLength * (adjustedDanPoints.Count - 2) / (adjustedDanPoints.Count - 1);
for (int point = 1; point < adjustedDanPoints.Count; point++)
{
float outsideDistance = danDistanceToTarget - danSegmentLength * (point - 1);
if (singleVector || outsideDistance < 0.001)
{
adjustedDanPoints[point] = adjustedDanPoints[point - 1] + insideVector * danSegmentLength;
}
else if (outsideDistance < (danSegmentLength - 0.001))
{
double angleOutsideToInside = (double)MathHelpers.DegToRad(Vector3.Angle(outsideVector, -insideVector));
MathHelpers.SolveSSATriangle(danSegmentLength, outsideDistance, angleOutsideToInside, out double distanceAlongInside, out _, out _);
adjustedDanPoints[point] = danLookTarget + insideVector * (float)distanceAlongInside;
}
else
{
adjustedDanPoints[point] = adjustedDanPoints[point - 1] + outsideVector * danSegmentLength;
}
}
float fullInsideDistance = fullDanBellyLength - danDistanceToTarget;
if (singleVector || fullInsideDistance < 0.001)
bellyEnd = adjustedDanPoints[0] + outsideVector * fullDanBellyLength;
else
bellyEnd = danLookTarget + insideVector * fullInsideDistance;
return adjustedDanPoints;
}
19
Source : SteerPOIManager.cs
with GNU Lesser General Public License v3.0
from ApexGameTools
with GNU Lesser General Public License v3.0
from ApexGameTools
private void Awake()
{
_pois = new List<Vector3>();
foreach (var fc in GetComponentsInChildren<SteerFormationChanger>())
{
_pois.Add(fc.transform.position);
}
}
19
Source : Contactstester.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
void FixedUpdate ()
{
if (lpman.ContactListener.FixtureFixtureContacts !=null && lpman.ContactListener.FixtureFixtureContacts.Length >0)
{
foreach (LPContactFixFix ff in lpman.ContactListener.FixtureFixtureContacts)
{
fixfix.Add(ff);
Debug.Log("Fixture-Fixture Collision entered between Body# "+ff.BodyAIndex +" Fixture# "+ff.FixtureAIndex
+" and Body# "+ff.BodyBIndex +" Fixture# "+ ff.FixtureBIndex + "IsTouching = " + ff.IsTouching);
}
}
if (lpman.ContactListener.ParticleFixtureContacts !=null && lpman.ContactListener.ParticleFixtureContacts.Length >0)
{
foreach (LPContactPartFix pf in lpman.ContactListener.ParticleFixtureContacts)
{
partfix.Add(pf);
pfposes.Add (lpman.ParticleSystems[pf.ParticleSystemIndex].Particles[pf.ParticleIndex].Position);
Debug.Log("Particle-Fixture Collision entered between ParticleSystem# "+pf.ParticleSystemIndex +" Particle# "+pf.ParticleIndex
+" and Body# "+pf.BodyIndex +" Fixture# "+ pf.FixtureIndex);
}
}
if (lpman.ContactListener.ParticleParticleContacts !=null && lpman.ContactListener.ParticleParticleContacts.Length >0)
{
foreach (LPContactPartPart pp in lpman.ContactListener.ParticleParticleContacts)
{
partpart.Add(pp);
ppposes.Add (lpman.ParticleSystems[pp.ParticleSystemIndex].Particles[pp.ParticleAIndex].Position);
ppposes2.Add (lpman.ParticleSystems[pp.ParticleSystemIndex].Particles[pp.ParticleBIndex].Position);
Debug.Log("Particle-Particle Collision entered between ParticleSystem# "+pp.ParticleSystemIndex +" Particle# "+pp.ParticleAIndex
+" and Particle# "+pp.ParticleBIndex);
}
}
}
19
Source : LPCorporeal.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public virtual void DefinePoints(Vector3[] points)
{
if (this.GetType() == typeof(LPFixturePoly) || this.GetType() == typeof(LPParticleGroupPoly)
|| this.GetType() == typeof(LPFixtureChainShape))
{
pointsList = new List<Vector3>();
foreach(Vector3 point in points)
{
pointsList.Add(point);
}
}
}
19
Source : LPCorporeal.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public virtual void AddPoint(Vector3 pos)
{
pointsList.Add(transform.InverseTransformPoint(pos + transform.position));
}
19
Source : LPShapeTools.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public static List<Vector3> MakeEdgePoints()
{
List<Vector3> PointsList = new List<Vector3>();
PointsList.Add(new Vector3(-1,0));
PointsList.Add(new Vector3(1,0));
return PointsList;
}
19
Source : LPShapeTools.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public static List<Vector3> MakeBoxPoints(Vector2 Size)
{
List<Vector3> PointsList = new List<Vector3>();
int[,] pm = new int[,]
{
{-1,1}
,{-1,-1}
,{1,-1}
,{1,1}
};
for (int i = 0; i < 4; i++)
{
float xcoord = Size.x/2*pm[i,0];
float ycoord = Size.y/2*pm[i,1];
PointsList.Add(new Vector3(xcoord,ycoord));
}
return PointsList;
}
19
Source : LPShapeTools.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public static List<Vector3> makePolyPoints(int sides,float r)
{
List<Vector3> PointsList = new List<Vector3>();
if (sides < 3)
{
Debug.LogError("You tried to make a polygon shape with less than 3 sides, making one with 3 instead");
sides = 3;
}
if (sides > 8)
{
Debug.LogError("You tried to make a polygon shape with more than 8 sides, making one with 8 instead.");
sides = 8;
}
for (int i = 0; i < sides; i++)
{
PointsList.Add (new Vector3(r * Mathf.Cos(2 * Mathf.PI * (float)i / (float)sides), r * Mathf.Sin(2 * Mathf.PI * (float)i / (float)sides)));
}
return PointsList;
}
19
Source : ComplexThrowable.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void PhysicsAttach( Hand hand, GrabTypes startingGrabType )
{
PhysicsDetach( hand );
Rigidbody holdingBody = null;
Vector3 holdingPoint = Vector3.zero;
// The hand should grab onto the nearest rigid body
float closestDistance = float.MaxValue;
for ( int i = 0; i < rigidBodies.Count; i++ )
{
float distance = Vector3.Distance( rigidBodies[i].worldCenterOfMreplaced, hand.transform.position );
if ( distance < closestDistance )
{
holdingBody = rigidBodies[i];
closestDistance = distance;
}
}
// Couldn't grab onto a body
if ( holdingBody == null )
return;
// Create a fixed joint from the hand to the holding body
if ( attachMode == AttachMode.FixedJoint )
{
Rigidbody handRigidbody = Util.FindOrAddComponent<Rigidbody>( hand.gameObject );
handRigidbody.isKinematic = true;
FixedJoint handJoint = hand.gameObject.AddComponent<FixedJoint>();
handJoint.connectedBody = holdingBody;
}
// Don't let the hand interact with other things while it's holding us
hand.HoverLock( null );
// Affix this point
Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMreplaced;
offset = Mathf.Min( offset.magnitude, 1.0f ) * offset.normalized;
holdingPoint = holdingBody.transform.InverseTransformPoint( holdingBody.worldCenterOfMreplaced + offset );
hand.AttachObject( this.gameObject, startingGrabType, attachmentFlags );
// Update holding list
holdingHands.Add( hand );
holdingBodies.Add( holdingBody );
holdingPoints.Add( holdingPoint );
}
19
Source : PredictionLine.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
void Update() {
Vector3 pos = transform.position;
Vector3 vel = -transform.forward * 20;
List<Vector3> pointList = new List<Vector3>();
for (int i = 0; i < 20; i++) {
pointList.Add(pos);
vel += Vector3.down * 9.81f *0.1f;
pos += vel * 0.1f;
}
lr.positionCount = 20;
lr.SetPositions(pointList.ToArray());
}
19
Source : BowLocalManager.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void updatePredictionLine() {
if (!predictionLine.enabled) {
return;
}
Vector3 vel = aimDir * Mathf.Lerp(projectileVelMin, projectileVel, attackDrawPercentage);
float stepLength = 0.1f;
float stepSize = 20;
Vector3 pos = transform.position;
List<Vector3> pointList = new List<Vector3>();
for (int i = 0; i < stepSize; i++) {
pointList.Add(pos);
vel += Vector3.down * arrow.GetComponent<Projectile>().m_gravity * stepLength;
pos += vel * stepLength;
}
predictionLine.positionCount = 20;
predictionLine.SetPositions(pointList.ToArray());
}
19
Source : FishingManager.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void FixedUpdate() {
tickCounter++;
if (tickCounter < 5) {
return;
}
if (Pose.justUnsheathed) {
snapshots.Clear();
}
else {
snapshots.Add(fixedRodTop.transform.position);
}
if (snapshots.Count > MAX_SNAPSHOTS) {
snapshots.RemoveAt(0);
}
tickCounter = 0;
var inputSource = VHVRConfig.LeftHanded()
? SteamVR_Input_Sources.LeftHand
: SteamVR_Input_Sources.RightHand;
if (isFishing && fishingFloat.GetCatch() && (int) (Time.fixedTime * 10) % 2 >= 1) {
VRPlayer.rightHand.hapticAction.Execute(0, 0.001f, 150, 0.7f, inputSource);
}
}
19
Source : FistCollision.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void FixedUpdate() {
snapshots.Add(transform.localPosition);
if (snapshots.Count > MAX_SNAPSHOTS) {
snapshots.RemoveAt(0);
}
}
19
Source : ShieldManager.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void FixedUpdate() {
tickCounter++;
if (tickCounter < 5) {
return;
}
snapshots.Add(Player.m_localPlayer.transform.InverseTransformPoint(shieldHand.position));
if (snapshots.Count > MAX_SNAPSHOTS) {
snapshots.RemoveAt(0);
}
tickCounter = 0;
ParryCheck();
}
19
Source : SpearManager.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void FixedUpdate() {
tickCounter++;
if (tickCounter < 5) {
return;
}
snapshots.Add(Player.m_localPlayer.transform.InverseTransformPoint(mainHandTransform.position));
if (snapshots.Count > MAX_SNAPSHOTS) {
snapshots.RemoveAt(0);
}
tickCounter = 0;
if (!VHVRConfig.UseSpearDirectionGraphic()) {
return;
}
if (directionCooldown <= 0) {
directionCooldown = 0;
directionLine.enabled = false;
}
else if (!isThrowingStance) {
directionCooldown -= Time.deltaTime*5;
}
}
19
Source : SpearManager.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void UpdateDirectionLine(Vector3 pos1 ,Vector3 pos2)
{
if (!VHVRConfig.UseSpearDirectionGraphic()) {
return;
}
List<Vector3> pointList = new List<Vector3>();
pointList.Add(pos1);
pointList.Add(pos2);
directionLine.SetPositions(pointList.ToArray());
directionLine.enabled = true;
directionCooldown = totalCooldown;
}
19
Source : WeaponCollision.cs
with GNU General Public License v3.0
from brandonmousseau
with GNU General Public License v3.0
from brandonmousseau
private void FixedUpdate() {
if (!isCollisionAllowed()) {
return;
}
snapshots.Add(transform.localPosition);
snapshotsC.Add(GetHandPosition());
if (snapshots.Count > maxSnapshots) {
snapshots.RemoveAt(0);
}
if (snapshotsC.Count > maxSnapshots) {
snapshotsC.RemoveAt(0);
}
}
19
Source : Chunk.cs
with MIT License
from BrunoS3D
with MIT License
from BrunoS3D
private void DrawFace(Vector3 point, Vector3 offset1, Vector3 offset2, int block, int tileIndex, Color32 color, int meshIndex = 0) {
point += Vector3.forward;
int index = verts.Count;
verts.Add(point);
verts.Add(point + offset1);
verts.Add(point + offset2);
verts.Add(point + offset1 + offset2);
if (!tris.ContainsKey(meshIndex) || tris[meshIndex] == null) {
tris[meshIndex] = new List<int>();
}
tris[meshIndex].Add(index + 0);
tris[meshIndex].Add(index + 1);
tris[meshIndex].Add(index + 2);
tris[meshIndex].Add(index + 3);
tris[meshIndex].Add(index + 2);
tris[meshIndex].Add(index + 1);
for (int idx = 0; idx < 4; idx++) {
colors.Add(color);
}
float textSize = 0.25f;
float yCoord = World.currentWorld.blockDefs[block].tiles[tileIndex] / 4;
float xCoord = yCoord * 4 + World.currentWorld.blockDefs[block].tiles[tileIndex];
uv.Add(new Vector2(xCoord * textSize, yCoord * textSize));
uv.Add(new Vector2(xCoord * textSize + textSize, yCoord * textSize));
uv.Add(new Vector2(xCoord * textSize, yCoord * textSize + textSize));
uv.Add(new Vector2(xCoord * textSize + textSize, yCoord * textSize + textSize));
}
19
Source : CloudsChunk.cs
with MIT License
from BrunoS3D
with MIT License
from BrunoS3D
private void DrawFace(Vector3 point, Vector3 offset1, Vector3 offset2) {
point += Vector3.forward;
int index = verts.Count;
verts.Add(point);
verts.Add(point + offset1);
verts.Add(point + offset2);
verts.Add(point + offset1 + offset2);
tris.Add(index + 0);
tris.Add(index + 1);
tris.Add(index + 2);
tris.Add(index + 3);
tris.Add(index + 2);
tris.Add(index + 1);
}
19
Source : SpectrogramChunk.cs
with GNU General Public License v2.0
from Caeden117
with GNU General Public License v2.0
from Caeden117
private void ReCalculateMesh()
{
var mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
var verts = new List<Vector3>();
var triangles = new List<int>();
float xRange = 1;
var xSamples = Math.Min(50, localData[0].Length) - 1;
var zSamples = 299;
for (var l = 0; l < zSamples; l++)
{
var m = (localData.Length - 1) * l / zSamples;
var m2 = (localData.Length - 1) * (l + 1) / zSamples;
var currentVolumes = localData[m];
var previousVolumes = localData[m2];
var zBandValue = (float)m / (localData.Length - 1);
var zBandNextValue = (float)m2 / (localData.Length - 1);
for (var k = 0; k < xSamples; k++)
{
var i = (currentVolumes.Length - 1) * k / xSamples;
var i2 = (currentVolumes.Length - 1) * (k + 1) / xSamples;
// calculating x position
var x = (float)i / (currentVolumes.Length - 2) * xRange;
var xNext = (float)i2 / (currentVolumes.Length - 2) * xRange;
var volume = currentVolumes[i];
var voulumeNext = currentVolumes[i2];
// two volumes that was previous
var volumePrevious = previousVolumes[i];
var volumeNextPrevious = previousVolumes[i2];
if (volume > max) max = volume;
if (volume < min) min = volume;
if (m == 0)
GenerateFrontFace(x, xNext, volume, voulumeNext, verts, triangles, zBandValue);
// connection with previous band
// adding verst connecting this band with the next one
verts.Add(new Vector3(x, volume, zBandValue));
verts.Add(new Vector3(xNext, voulumeNext, zBandValue));
verts.Add(new Vector3(x, volumePrevious, zBandNextValue));
verts.Add(new Vector3(xNext, volumeNextPrevious, zBandNextValue));
var startPoint = verts.Count - 4;
// adding 2 triangles using this vertex
triangles.Add(startPoint + 0);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 3);
triangles.Add(startPoint + 1);
// left side
if (i == 0)
{
verts.Add(new Vector3(x, 0, zBandValue));
verts.Add(new Vector3(x, 0, zBandNextValue));
verts.Add(new Vector3(x, volume, zBandValue));
verts.Add(new Vector3(x, volumePrevious, zBandNextValue));
startPoint = verts.Count - 4;
// adding 2 triangles using this vertex
triangles.Add(startPoint + 0);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 3);
triangles.Add(startPoint + 2);
}
// right side
if (i == currentVolumes.Length - 2)
{
verts.Add(new Vector3(xNext, 0, zBandValue));
verts.Add(new Vector3(xNext, 0, zBandNextValue));
verts.Add(new Vector3(xNext, volume, zBandValue));
verts.Add(new Vector3(xNext, volumePrevious, zBandNextValue));
startPoint = verts.Count - 4;
// adding 2 triangles using this vertex
triangles.Add(startPoint + 0);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 3);
}
}
}
mesh.vertices = verts.ToArray();
mesh.triangles = triangles.ToArray();
if (waveform.WaveformType == 2)
{
// 3D color the mesh
var meshColors = new List<Color>(verts.Count);
foreach (var vertex in verts)
{
var lerp = Mathf.InverseLerp(min, max, vertex.y);
if (float.IsNaN(lerp)) lerp = 0;
meshColors.Add(waveform.SpectrogramHeightGradient.Evaluate(lerp));
}
mesh.colors = meshColors.ToArray();
}
else
{
// In 2d we have too much data to draw in the mesh so we have to render a texture to color space between vertexes
// Simplest UV ever
var uv = new Vector2[verts.Count];
for (var i = 0; i < verts.Count; i++)
{
var it = verts[i];
uv[i] = new Vector2(
Mathf.Clamp(it.z, 0.001f, 0.999f),
Mathf.Clamp(it.x, 0.001f, 0.999f)
);
}
mesh.uv = uv;
// apply texture to mesh
var customMaterial = new Material(Shader.Find("Shader Graphs/Spectrogram 2D"))
{
// wait why am i not setting this to the same render queue as lights, pepega
renderQueue = 2925
};
customMaterial.SetFloat("_Rotation", transform.rotation.eulerAngles.y);
customMaterial.SetTexture("_MainTex", texture);
GetComponent<MeshRenderer>().material = customMaterial;
}
mesh.RecalculateNormals();
}
19
Source : SpectrogramChunk.cs
with GNU General Public License v2.0
from Caeden117
with GNU General Public License v2.0
from Caeden117
private void GenerateFrontFace(float x, float xNext, float volume, float volumeNext, List<Vector3> verts,
List<int> triangles, float zBandValue)
{
verts.Add(new Vector3(x, 0, zBandValue));
verts.Add(new Vector3(x, volume, zBandValue));
verts.Add(new Vector3(xNext, 0, zBandValue));
verts.Add(new Vector3(xNext, volumeNext, zBandValue));
var startPoint = verts.Count - 4;
triangles.Add(startPoint + 0);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 2);
triangles.Add(startPoint + 1);
triangles.Add(startPoint + 3);
triangles.Add(startPoint + 2);
}
19
Source : CurveComponent.cs
with MIT License
from Caeden117
with MIT License
from Caeden117
public void UpdateCurvature()
{
if (cachedMesh == null || controller == null || HasCurvedThisFrame) return;
helper.PokeScreenSize();
var settings = controller.CurrentCurveSettings;
newVertices.Clear();
foreach (var v in cachedVertices)
{
newVertices.Add(helper.GetCurvedPosition(v, ref localToCanvasMatrix, ref canvasToLocalMatrix, settings));
}
cachedMesh.SetVertices(newVertices);
graphic.canvasRenderer.SetMesh(cachedMesh);
HasCurvedThisFrame = true;
}
19
Source : CurvedImage.cs
with MIT License
from Caeden117
with MIT License
from Caeden117
private int GetNewVertex4(Dictionary<uint, int> newVectices, List<Vector3> vertices, List<Vector2> uvs, int i1, int i2)
{
int newIndex = vertices.Count;
uint t1 = ((uint)i1 << 16) | (uint)i2;
uint t2 = ((uint)i2 << 16) | (uint)i1;
if (newVectices.ContainsKey(t2))
return newVectices[t2];
if (newVectices.ContainsKey(t1))
return newVectices[t1];
newVectices.Add(t1, newIndex);
vertices.Add((vertices[i1] + vertices[i2]) * 0.5f);
uvs.Add((uvs[i1] + uvs[i2]) * 0.5f);
return newIndex;
}
19
Source : CurvedTextMeshPro.cs
with MIT License
from Caeden117
with MIT License
from Caeden117
public void UpdateCurvature()
{
if (controller == null || HasCurvedThisFrame) return;
curvedHelper.PokeScreenSize();
modifiedVertices.Clear();
var settings = controller.CurrentCurveSettings;
foreach (var v in cachedVertices)
{
modifiedVertices.Add(curvedHelper.GetCurvedPosition(v, ref localToCanvasMatrix, ref canvasToLocalMatrix, settings));
}
m_mesh.SetVertices(modifiedVertices);
canvasRenderer.SetMesh(m_mesh);
HasCurvedThisFrame = true;
}
19
Source : ParticlePainter.cs
with MIT License
from codeyuan666
with MIT License
from codeyuan666
public void ARFrameUpdated(UnityARCamera camera)
{
Matrix4x4 matrix = new Matrix4x4();
matrix.SetColumn(3, camera.worldTransform.column3);
Vector3 currentPositon = UnityARMatrixOps.GetPosition(matrix) + (Camera.main.transform.forward * penDistance);
if (Vector3.Distance (currentPositon, previousPosition) > minDistanceThreshold) {
if (paintMode == 2) currentPaintVertices.Add (currentPositon);
frameUpdated = true;
previousPosition = currentPositon;
}
}
19
Source : BspToUnity.Displacements.cs
with MIT License
from cr4yz
with MIT License
from cr4yz
private GameObject GenerateDisplacement(int faceIndex, int dispInfoId, int modelId)
{
var face = _bsp.Faces[faceIndex];
var disp_verts = new List<UVector3>();
var UVs = new List<UVector2>();
var UV2s = new List<UVector2>();
var cols = new List<Color>();
var indices = new List<int>();
var normals = new List<UVector3>();
var texInfo = _bsp.TextureInfos[face.TexInfo];
var texData = _bsp.TextureData[texInfo.TexData];
_bsp.LightmapLayout.GetUvs(faceIndex, out SVector2 lmMin, out SVector2 lmSize);
var disp = _bsp.DisplacementManager[dispInfoId];
disp.GetCorners(out SVector3 c0, out SVector3 c1, out SVector3 c2, out SVector3 c3);
var texScale = new SVector2(1f / Math.Max(texData.Width, 1), 1f / Math.Max(texData.Height, 1));
var uv00 = GetUv(c0, texInfo.TextureUAxis, texInfo.TextureVAxis) * texScale;
var uv10 = GetUv(c3, texInfo.TextureUAxis, texInfo.TextureVAxis) * texScale;
var uv01 = GetUv(c1, texInfo.TextureUAxis, texInfo.TextureVAxis) * texScale;
var uv11 = GetUv(c2, texInfo.TextureUAxis, texInfo.TextureVAxis) * texScale;
var subDivMul = 1f / disp.Subdivisions;
for (var y = 0; y < disp.Subdivisions; ++y)
{
var v0 = (y + 0) * subDivMul;
var v1 = (y + 1) * subDivMul;
for (var x = 0; x < disp.Size; ++x)
{
var u = x * subDivMul;
var vert1 = disp.GetPosition(x, y + 0).ToUVector();
var uv1 = ((uv00 * (1f - u) + uv10 * u) * (1f - v0) + (uv01 * (1f - u) + uv11 * u) * v0).ToUVector();
var uv21 = (new SVector2(u, v0) * lmSize + lmMin).ToUVector();
var normal1 = disp.GetNormal(x, y + 0).ToUVector();
var color1 = new Color(disp.GetAlpha(x, y + 0) / 4f, 0, 0, 0);
disp_verts.Add(vert1);
UVs.Add(uv1);
UV2s.Add(uv21);
normals.Add(normal1);
cols.Add(color1);
var vert2 = disp.GetPosition(x, y + 1).ToUVector();
var uv2 = ((uv00 * (1f - u) + uv10 * u) * (1f - v1) + (uv01 * (1f - u) + uv11 * u) * v1).ToUVector();
var uv22 = (new SVector2(u, v1) * lmSize + lmMin).ToUVector();
var normal2 = disp.GetNormal(x, y + 1).ToUVector();
var color2 = new Color(disp.GetAlpha(x, y + 1) / 4f, 0, 0, 0);
disp_verts.Add(vert2);
UVs.Add(uv2);
UV2s.Add(uv22);
normals.Add(normal2);
cols.Add(color2);
if (x != disp.Size - 1)
{
var j = disp_verts.Count - 2;
indices.Add(j);
indices.Add(j + 1);
indices.Add(j + 2);
indices.Add(j + 3);
indices.Add(j + 2);
indices.Add(j + 1);
}
}
}
for (int i = 0; i < disp_verts.Count; i++)
{
disp_verts[i] *= _options.WorldScale;
}
GameObject faceObject = new GameObject("DispFace: " + modelId);
MeshRenderer mr = faceObject.AddComponent<MeshRenderer>();
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
mr.receiveShadows = true;
mr.lightmapIndex = _currentLightmap;
MeshFilter mf = faceObject.AddComponent<MeshFilter>();
mf.sharedMesh = new Mesh();
mf.sharedMesh.name = "DispFace " + modelId;
mf.sharedMesh.vertices = disp_verts.ToArray();
mf.sharedMesh.triangles = indices.ToArray();
mf.sharedMesh.uv = UVs.ToArray();
mf.sharedMesh.uv2 = UV2s.ToArray();
mf.sharedMesh.normals = normals.ToArray();
mf.sharedMesh.colors = cols.ToArray();
mf.sharedMesh.RecalculateTangents();
mf.sharedMesh.RecalculateBounds();
// todo: blend textures on vert R value
//mf.sharedMesh.colors = cols.ToArray();
faceObject.gameObject.AddComponent<MeshCollider>();
var texString = _bsp.GetTextureString(texData.NameStringTableId);
var materialPath = "materials/" + texString + ".vmt";
LoadMaterial(mr, materialPath);
return faceObject;
}
19
Source : BspUtils.cs
with MIT License
from cr4yz
with MIT License
from cr4yz
public static IEnumerable<UnityEngine.Vector3> GetVerticesFromPlanes(SourceUtils.ValveBsp.Plane[] planes)
{
var result = new List<UnityEngine.Vector3>();
var planesWrapper = new PlaneWrapper[planes.Length];
for (int i = 0; i < planes.Length; i++)
{
planesWrapper[i] = new PlaneWrapper()
{
Normal = planes[i].Normal,
Dist = planes[i].Dist
};
}
var numPlanes = planesWrapper.Length;
for (var i = 0; i < numPlanes; i++)
{
var N1 = planesWrapper[i];
for (var j = i + 1; j < numPlanes; j++)
{
var N2 = planesWrapper[j];
for (var k = j + 1; k < numPlanes; k++)
{
var N3 = planesWrapper[k];
//var n2n3 = N2.Normal.Cross(N3.Normal);
//var n3n1 = N3.Normal.Cross(N1.Normal);
//var n1n2 = N1.Normal.Cross(N2.Normal);
var n2n3 = new SourceUtils.Vector3(N2.Normal.Y * N3.Normal.Z - N2.Normal.Z * N3.Normal.Y, N2.Normal.Z * N3.Normal.X - N2.Normal.X * N3.Normal.Z, N2.Normal.X * N3.Normal.Y - N2.Normal.Y * N3.Normal.X);
var n3n1 = new SourceUtils.Vector3(N3.Normal.Y * N1.Normal.Z - N3.Normal.Z * N1.Normal.Y, N3.Normal.Z * N1.Normal.X - N3.Normal.X * N1.Normal.Z, N3.Normal.X * N1.Normal.Y - N3.Normal.Y * N1.Normal.X);
var n1n2 = new SourceUtils.Vector3(N1.Normal.Y * N2.Normal.Z - N1.Normal.Z * N2.Normal.Y, N1.Normal.Z * N2.Normal.X - N1.Normal.X * N2.Normal.Z, N1.Normal.X * N2.Normal.Y - N1.Normal.Y * N2.Normal.X);
if ((n2n3.LengthSquared > 0.0001) && (n3n1.LengthSquared > 0.0001) && (n1n2.LengthSquared > 0.0001))
{
var quotient = N1.Normal.X * n2n3.X + N1.Normal.Y * n2n3.Y + N1.Normal.Z * n2n3.Z;
//var quotient = N1.Normal.Dot(n2n3);
if (Math.Abs(quotient) > double.Epsilon)
{
quotient = -1.0f / quotient;
//n2n3 *= -N1.Dist;
//n3n1 *= -N2.Dist;
//n1n2 *= -N3.Dist;
n2n3.X *= -N1.Dist;
n2n3.Y *= -N1.Dist;
n2n3.Z *= -N1.Dist;
n3n1.X *= -N2.Dist;
n3n1.Y *= -N2.Dist;
n3n1.Z *= -N2.Dist;
n1n2.X *= -N3.Dist;
n1n2.Y *= -N3.Dist;
n1n2.Z *= -N3.Dist;
var potentialVertex = new SourceUtils.Vector3();
potentialVertex.X = (n2n3.X + n3n1.X + n1n2.X) * quotient;
potentialVertex.Y = (n2n3.Y + n3n1.Y + n1n2.Y) * quotient;
potentialVertex.Z = (n2n3.Z + n3n1.Z + n1n2.Z) * quotient;
//var potentialVertex = n2n3;
//potentialVertex += n3n1;
//potentialVertex += n1n2;
//potentialVertex *= quotient;
if (IsPointInsidePlanes(planesWrapper, potentialVertex, 0.01))
{
result.Add(new UnityEngine.Vector3(potentialVertex.X, potentialVertex.Z, potentialVertex.Y));
}
}
}
}
}
}
return result;
}
19
Source : LeanCircuit.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private void AddLine(Vector3 a, Vector3 b, Color color)
{
if (a != b)
{
var right = Vector3.Cross(a - b, Vector3.up).normalized * LineRadius;
var index = positions.Count;
positions.Add(a - right);
positions.Add(a + right);
positions.Add(b + right);
positions.Add(b - right);
colors.Add(color);
colors.Add(color);
colors.Add(color);
colors.Add(color);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
normals.Add(Vector3.up);
coords.Add(Vector2.zero);
coords.Add(Vector2.one);
coords.Add(Vector2.one);
coords.Add(Vector2.zero);
indices.Add(index + 2);
indices.Add(index + 1);
indices.Add(index );
indices.Add(index + 3);
indices.Add(index + 2);
indices.Add(index );
}
}
19
Source : LeanCircuit.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private void AddPoint(Vector3 a, float radius, Color color)
{
var index = positions.Count;
var count = 36;
var step = Mathf.PI * 2.0f / count;
for (var i = 0; i < count; i++)
{
var angle = i * step;
positions.Add(a + new Vector3(Mathf.Sin(angle) * radius, 0.0f, Mathf.Cos(angle) * radius));
colors.Add(color);
normals.Add(Vector3.up);
coords.Add(new Vector2(0.5f, 0.5f));
}
for (var i = 2; i < count; i++)
{
indices.Add(index );
indices.Add(index + i - 1);
indices.Add(index + i);
}
}
19
Source : LeanPath.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
public void SetLine(Vector3 a, Vector3 b)
{
if (Points == null)
{
Points = new List<Vector3>();
}
else
{
Points.Clear();
}
Points.Add(a);
Points.Add(b);
}
19
Source : PlayerPrefsExtensions.cs
with GNU General Public License v3.0
from Cytoid
with GNU General Public License v3.0
from Cytoid
private static void ConvertToVector3(List<Vector3> list, byte[] bytes)
{
list.Add(new Vector3(ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes), ConvertBytesToFloat(bytes)));
}
19
Source : SpatialUnderstandingCustomMesh.cs
with MIT License
from dag10
with MIT License
from dag10
public void AddTriangle(Vector3 point1, Vector3 point2, Vector3 point3)
{
// Currently spatial understanding in the native layer voxellizes the space
// into ~2000 voxels per cubic meter. Even in a degerate case we
// will use far fewer than 65000 vertices, this check should not fail
// unless the spatial understanding native layer is updated to have more
// voxels per cubic meter.
if (verts.Count < 65000)
{
tris.Add(verts.Count);
verts.Add(point1);
tris.Add(verts.Count);
verts.Add(point2);
tris.Add(verts.Count);
verts.Add(point3);
}
else
{
Debug.LogError("Mesh would have more vertices than Unity supports");
}
}
19
Source : PolygonManager.cs
with MIT License
from dag10
with MIT License
from dag10
public void AddPoint(GameObject LinePrefab, GameObject PointPrefab, GameObject TextPrefab)
{
var hitPoint = GazeManager.Instance.HitInfo.point;
var point = (GameObject)Instantiate(PointPrefab, hitPoint, Quaternion.idenreplacedy);
var newPoint = new Point
{
Position = hitPoint,
Root = point
};
if (CurrentPloygon.IsFinished)
{
CurrentPloygon = new Ploygon()
{
IsFinished = false,
Root = new GameObject(),
Points = new List<Vector3>()
};
CurrentPloygon.Points.Add(newPoint.Position);
newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
}
else
{
CurrentPloygon.Points.Add(newPoint.Position);
newPoint.Root.transform.parent = CurrentPloygon.Root.transform;
if (CurrentPloygon.Points.Count > 1)
{
var index = CurrentPloygon.Points.Count - 1;
var centerPos = (CurrentPloygon.Points[index] + CurrentPloygon.Points[index - 1]) * 0.5f;
var direction = CurrentPloygon.Points[index] - CurrentPloygon.Points[index - 1];
var distance = Vector3.Distance(CurrentPloygon.Points[index], CurrentPloygon.Points[index - 1]);
var line = (GameObject)Instantiate(LinePrefab, centerPos, Quaternion.LookRotation(direction));
line.transform.localScale = new Vector3(distance, 0.005f, 0.005f);
line.transform.Rotate(Vector3.down, 90f);
line.transform.parent = CurrentPloygon.Root.transform;
}
}
}
19
Source : ComplexThrowable.cs
with MIT License
from dag10
with MIT License
from dag10
private void PhysicsAttach( Hand hand )
{
PhysicsDetach( hand );
Rigidbody holdingBody = null;
Vector3 holdingPoint = Vector3.zero;
// The hand should grab onto the nearest rigid body
float closestDistance = float.MaxValue;
for ( int i = 0; i < rigidBodies.Count; i++ )
{
float distance = Vector3.Distance( rigidBodies[i].worldCenterOfMreplaced, hand.transform.position );
if ( distance < closestDistance )
{
holdingBody = rigidBodies[i];
closestDistance = distance;
}
}
// Couldn't grab onto a body
if ( holdingBody == null )
return;
// Create a fixed joint from the hand to the holding body
if ( attachMode == AttachMode.FixedJoint )
{
Rigidbody handRigidbody = Util.FindOrAddComponent<Rigidbody>( hand.gameObject );
handRigidbody.isKinematic = true;
FixedJoint handJoint = hand.gameObject.AddComponent<FixedJoint>();
handJoint.connectedBody = holdingBody;
}
// Don't let the hand interact with other things while it's holding us
hand.HoverLock( null );
// Affix this point
Vector3 offset = hand.transform.position - holdingBody.worldCenterOfMreplaced;
offset = Mathf.Min( offset.magnitude, 1.0f ) * offset.normalized;
holdingPoint = holdingBody.transform.InverseTransformPoint( holdingBody.worldCenterOfMreplaced + offset );
hand.AttachObject( this.gameObject, attachmentFlags );
// Update holding list
holdingHands.Add( hand );
holdingBodies.Add( holdingBody );
holdingPoints.Add( holdingPoint );
}
19
Source : DrawingUtils.cs
with MIT License
from Daimler
with MIT License
from Daimler
public static GameObject DrawLine2D(List<double> data)
{
List<Vector3> line = new List<Vector3>();
for (int i = 0; i < data.Count; i += 2)
{
Vector3 p = new Vector3((float)data[i], 0.005f, (float)data[i + 1]);
line.Add(p);
}
GameObject root = DrawLine(line, Color.red);
return root;
}
19
Source : DrawingUtils.cs
with MIT License
from Daimler
with MIT License
from Daimler
public static GameObject DrawLine3D(List<double> data)
{
List<Vector3> line = new List<Vector3>();
for (int i = 0; i < data.Count; i += 3)
{
Vector3 p = new Vector3((float)data[i], (float)data[i + 1], (float)data[i + 2]);
line.Add(p);
}
GameObject root = DrawLine(line, Color.red);
return root;
}
19
Source : SeqenceDraw.cs
with MIT License
from huailiang
with MIT License
from huailiang
public GameObject DrawCircleSolid(Vector3 center, Vector3 forward, float radius)
{
int pointAmount = 100;
float eachAngle = 360f / pointAmount;
center += new Vector3(0, 0.01f, 0);
List<Vector3> vertices = new List<Vector3>();
for (int i = 0; i < pointAmount; i++)
{
Vector3 pos = Quaternion.Euler(0f, eachAngle * i, 0f) * forward * radius + center;
vertices.Add(pos);
}
CreateMesh(vertices, "circle");
return sharedObj;
}
19
Source : SeqenceDraw.cs
with MIT License
from huailiang
with MIT License
from huailiang
public GameObject DrawRectangleSolid(Transform t, float length, float width)
{
List<Vector3> vertices = new List<Vector3>();
Vector3 center = t.position;
center += new Vector3(0, 0.01f, 0);
vertices.Add(center - t.right * width);
vertices.Add(center - t.right * width + t.forward * length);
vertices.Add(center + t.right * width + t.forward * length);
vertices.Add(center + t.right * width);
CreateMesh(vertices, "rect");
return sharedObj;
}
19
Source : SeqenceDraw.cs
with MIT License
from huailiang
with MIT License
from huailiang
public GameObject DrawSectorSolid(Transform t, float angle, float radius)
{
int pointAmmount = 100;
float eachAngle = angle / pointAmmount;
Vector3 forward = t.forward;
List<Vector3> vertices = new List<Vector3>();
Vector3 center = t.position;
center += new Vector3(0, 0.01f, 0);
vertices.Add(center);
for (int i = 0; i < pointAmmount; i++)
{
Vector3 pos = Quaternion.Euler(0f, -angle / 2 + eachAngle * (i - 1), 0f) * forward * radius + center;
vertices.Add(pos);
}
CreateMesh(vertices, "sector");
return sharedObj;
}
See More Examples