private void AddColliderBoundsToTarget(KeyValuePair <Transform, Collider> colliderByTransform)
 {
     if (colliderByTransform.Key != null)
     {
         BoundsExtensions.GetColliderBoundsPoints(colliderByTransform.Value, totalBoundsCorners, 0);
     }
 }
Exemple #2
0
        public void GetColliderBoundsPointsRelativeTo()
        {
            var relativeTo = new GameObject();

            relativeTo.transform.position = Vector3.forward;
            relativeTo.transform.rotation = Quaternion.identity;

            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0, relativeTo.transform);
            expectedPoints = new Vector3[] {
                new Vector3(-0.5f, -0.5f, -1.5f),
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, -1.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, -1.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, -1.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            relativeTo.transform.localScale = 0.5f * Vector3.one;
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0, relativeTo.transform);
            expectedPoints = new Vector3[] {
                new Vector3(-1f, -1f, -3f),
                new Vector3(-1f, -1f, -1f),
                new Vector3(-1f, 1f, -3f),
                new Vector3(-1f, 1f, -1f),
                new Vector3(1f, -1f, -3f),
                new Vector3(1f, -1f, -1f),
                new Vector3(1f, 1f, -3f),
                new Vector3(1f, 1f, -1f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());
        }
Exemple #3
0
        /// <inheritdoc />
        public void OnSourceDetected(SourceStateEventData eventData)
        {
            var hand = eventData.Controller;

            if (hand != null)
            {
                // If a hand does not contain joints, OnHandJointsUpdated will not be called the bounds should
                // be calculated based on the proxy visuals.
                bool handContainsJoints = (hand as IMixedRealityHand) != null;

                if (!handContainsJoints)
                {
                    var proxy = hand.Visualizer?.GameObjectProxy;

                    if (proxy != null)
                    {
                        var newBounds    = new Bounds(proxy.transform.position, Vector3.zero);
                        var boundsPoints = new List <Vector3>();
                        BoundsExtensions.GetRenderBoundsPoints(proxy, boundsPoints, 0);

                        foreach (var point in boundsPoints)
                        {
                            newBounds.Encapsulate(point);
                        }

                        Bounds[hand.ControllerHandedness] = newBounds;
                    }
                }
            }
        }
Exemple #4
0
        public static bool GenerateBoxSubMesh(CSGBrushSubMesh subMesh, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                return(false);
            }

            if (surfaceAssets.Length != 6 ||
                surfaceDescriptions.Length != 6)
            {
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            subMesh.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions);
            subMesh.HalfEdges = boxHalfEdges.ToArray();
            subMesh.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            return(true);
        }
Exemple #5
0
        public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceFlags surfaceFlags = SurfaceFlags.None)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                brushMeshAsset.Clear();
                return(false);
            }

            if (surfaceAssets.Length != 6)
            {
                brushMeshAsset.Clear();
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            brushMeshAsset.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceFlags);
            brushMeshAsset.HalfEdges = boxHalfEdges.ToArray();
            brushMeshAsset.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            brushMeshAsset.CalculatePlanes();
            brushMeshAsset.SetDirty();
            return(true);
        }
        protected override void UpdateGeneratorInternal()
        {
            if (surfaceAssets == null)
            {
                var defaultRenderMaterial  = CSGMaterialManager.DefaultWallMaterial;
                var defaultPhysicsMaterial = CSGMaterialManager.DefaultPhysicsMaterial;
                surfaceAssets = new CSGSurfaceAsset[6]
                {
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial),
                    CSGSurfaceAsset.CreateInstance(defaultRenderMaterial, defaultPhysicsMaterial)
                };
            }

            if (surfaceDescriptions == null ||
                surfaceDescriptions.Length != 6)
            {
                // TODO: make this independent on plane position somehow
                var surfaceFlags = CSGDefaults.SurfaceFlags;
                surfaceDescriptions = new SurfaceDescription[6]
                {
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    },
                    new SurfaceDescription {
                        UV0 = UVMatrix.centered, surfaceFlags = surfaceFlags, smoothingGroup = 0
                    }
                };
            }

            if (BoundsExtensions.IsValid(bounds.min, bounds.max))
            {
                BrushMeshAssetFactory.GenerateBoxAsset(brushMeshAsset, bounds, surfaceAssets, surfaceDescriptions);
            }
            else
            {
                brushMeshAsset.Clear();
            }
        }
Exemple #7
0
        public static Bounds GetBounds()
        {
            List <Bounds> levelBoundsInstances = new List <Bounds>();

            foreach (Renderer renderer in FindObjectsOfType <Renderer>())
            {
                if (renderer.GetComponent <OmitFromLevelMap>() == null)
                {
                    levelBoundsInstances.Add(renderer.bounds);
                }
            }
            return(BoundsExtensions.Combine(levelBoundsInstances.ToArray()));
        }
Exemple #8
0
        public void GetColliderBoundsPoints()
        {
            // SetUp
            expectedPoints = new Vector3[] {
                new Vector3(-0.5f, -0.5f, -0.5f),
                new Vector3(-0.5f, -0.5f, 0.5f),
                new Vector3(-0.5f, 0.5f, -0.5f),
                new Vector3(-0.5f, 0.5f, 0.5f),
                new Vector3(0.5f, -0.5f, -0.5f),
                new Vector3(0.5f, -0.5f, 0.5f),
                new Vector3(0.5f, 0.5f, -0.5f),
                new Vector3(0.5f, 0.5f, 0.5f),
            };

            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);

            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            cube.transform.localScale = Vector3.one * 2f;
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);
            expectedPoints = new Vector3[] {
                new Vector3(-1f, -1f, -1f),
                new Vector3(-1f, -1f, 1f),
                new Vector3(-1f, 1f, -1f),
                new Vector3(-1f, 1f, 1f),
                new Vector3(1f, -1f, -1f),
                new Vector3(1f, -1f, 1f),
                new Vector3(1f, 1f, -1f),
                new Vector3(1f, 1f, 1f),
            };
            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());

            boundsPoints.Clear();
            cube.transform.localScale = new Vector3(10, 1, 1);
            BoundsExtensions.GetColliderBoundsPoints(cube, boundsPoints, 0);

            expectedPoints = new Vector3[] {
                new Vector3(-5f, -0.5f, -0.5f),
                new Vector3(-5f, -0.5f, 0.5f),
                new Vector3(-5f, 0.5f, -0.5f),
                new Vector3(-5f, 0.5f, 0.5f),
                new Vector3(5f, -0.5f, -0.5f),
                new Vector3(5f, -0.5f, 0.5f),
                new Vector3(5f, 0.5f, -0.5f),
                new Vector3(5f, 0.5f, 0.5f),
            };

            Assert.AreEqual(expectedPoints, boundsPoints.ToArray());
        }
        private bool DiskLost()
        {
            if (((gameObject.AssumedWorldPosServer() - MatrixManager.MainStationMatrix.GameObject.AssumedWorldPosServer())
                 .magnitude < boundRadius))
            {
                return(false);
            }

            if (escapeShuttle != null && escapeShuttle.Status != EscapeShuttleStatus.DockedCentcom)
            {
                var matrixInfo = escapeShuttle.MatrixInfo;
                if (matrixInfo == null || BoundsExtensions.Contains(matrixInfo.LocalBounds, registerTile.WorldPositionServer))
                {
                    return(false);
                }
            }
            else
            {
                ItemSlot slot = pick.ItemSlot;
                if (slot == null)
                {
                    return(true);
                }

                RegisterPlayer player = slot.Player;
                if (player == null)
                {
                    return(true);
                }

                if (player.GetComponent <PlayerHealthV2>().IsDead)
                {
                    return(true);
                }

                var checkPlayer = PlayerList.Instance.Get(player.gameObject, true);
                if (checkPlayer.Equals(ConnectedPlayer.Invalid))
                {
                    return(true);
                }

                if (PlayerList.Instance.AntagPlayers.Contains(checkPlayer) == false)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #10
0
        public static bool GenerateBoxAsset(CSGBrushMeshAsset brushMeshAsset, UnityEngine.Vector3 min, UnityEngine.Vector3 max, CSGSurfaceAsset[] surfaceAssets, SurfaceDescription[] surfaceDescriptions)
        {
            if (!BoundsExtensions.IsValid(min, max))
            {
                brushMeshAsset.Clear();
                Debug.LogError("bounds is of an invalid size " + (max - min));
                return(false);
            }

            if (surfaceDescriptions == null || surfaceDescriptions.Length != 6)
            {
                brushMeshAsset.Clear();
                Debug.LogError("surfaceDescriptions needs to be an array of length 6");
                return(false);
            }

            if (surfaceAssets == null || surfaceAssets.Length != 6)
            {
                brushMeshAsset.Clear();
                Debug.LogError("surfaceAssets needs to be an array of length 6");
                return(false);
            }

            if (min.x > max.x)
            {
                float x = min.x; min.x = max.x; max.x = x;
            }
            if (min.y > max.y)
            {
                float y = min.y; min.y = max.y; max.y = y;
            }
            if (min.z > max.z)
            {
                float z = min.z; min.z = max.z; max.z = z;
            }

            brushMeshAsset.Polygons  = CreateBoxAssetPolygons(surfaceAssets, surfaceDescriptions);
            brushMeshAsset.HalfEdges = boxHalfEdges.ToArray();
            brushMeshAsset.Vertices  = BrushMeshFactory.CreateBoxVertices(min, max);
            brushMeshAsset.CalculatePlanes();
            brushMeshAsset.SetDirty();
            return(true);
        }
        public override void OnEventStartTimed()
        {
            var stationBounds = MatrixManager.MainStationMatrix.LocalBounds;

            float width  = 0.35f * (stationBounds.xMax - stationBounds.xMin);
            float height = 0.35f * (stationBounds.yMax - stationBounds.yMin);
            float minX   = Random.Range(stationBounds.xMin, stationBounds.xMax - width);
            float minY   = Random.Range(stationBounds.yMin, stationBounds.yMax - height);

            var region = new Bounds();

            region.SetMinMax(new Vector2(minX, minY), new Vector2(minX + width, minY + height));

            foreach (var light in FindObjectsOfType <LightSource>())
            {
                if (BoundsExtensions.Contains(region, light.gameObject.RegisterTile().WorldPositionServer))
                {
                    StartCoroutine(BreakLight(light));
                }
            }
        }
Exemple #12
0
 public virtual void Do()
 {
     if (trs == null)
     {
         throw new Exception(nameof(trs) + " is null");
     }
     Transform[] children = new Transform[trs.childCount];
     Vector3[]   points   = new Vector3[trs.childCount];
     for (int i = 0; i < trs.childCount; i++)
     {
         Transform child = trs.GetChild(i);
         points[i]   = child.position;
         children[i] = child;
     }
     trs.DetachChildren();
     trs.position = BoundsExtensions.FromPoints(points).center;
     for (int i = 0; i < children.Length; i++)
     {
         Transform child = children[i];
         child.SetParent(trs);
     }
 }
        void Start()
        {
            foreach (SnapPosition snapPosition in GetComponentsInChildren <SnapPosition>())
            {
                snapPosition.enabled = false;
            }
            if (autoSetWaypoints)
            {
                wayPointsParent = transform;
            }
            if (wayPointsParent != null)
            {
                wayPoints.AddRange(wayPointsParent.GetComponentsInChildren <Waypoint>());
            }
            foreach (Waypoint waypoint in wayPoints)
            {
                waypoint.transform.SetParent(null);
            }
            if (moveSpeed != 0)
            {
                if (GetComponent <LineRenderer>() == null)
                {
                    line = gameObject.AddComponent <LineRenderer>();
                }
                else
                {
                    line = GetComponent <LineRenderer>();
                }
                line.positionCount = wayPoints.Count + 1;
                line.SetPosition(0, transform.position);
                if (moveType == MoveType.Loop)
                {
                    int counter       = 1;
                    int waypointIndex = currentWaypoint;
                    while (true)
                    {
                        line.SetPosition(counter, wayPoints[waypointIndex].transform.position);
                        if (backTracking)
                        {
                            waypointIndex--;
                            if (waypointIndex == -1)
                            {
                                waypointIndex = wayPoints.Count - 1;
                            }
                        }
                        else
                        {
                            waypointIndex++;
                            if (waypointIndex == wayPoints.Count)
                            {
                                waypointIndex = 0;
                            }
                        }
                        if (waypointIndex == currentWaypoint)
                        {
                            break;
                        }
                        counter++;
                    }
                }
                else
                {
                    for (int i = 0; i < wayPoints.Count; i++)
                    {
                        line.SetPosition(i + 1, wayPoints[i].transform.position);
                    }
                }
                line.material         = path.material;
                line.startColor       = path.color;
                line.endColor         = path.color;
                line.startWidth       = path.width;
                line.endWidth         = path.width;
                line.sortingLayerName = path.sortingLayerName;
                line.sortingOrder     = Mathf.Clamp(path.sortingOrder, -32768, 32767);
            }
            if (rotateSpeed != 0)
            {
                for (int i = 0; i < wayPoints.Count; i++)
                {
                    Transform waypoint     = wayPoints[i].transform;
                    Transform nextWaypoint = null;
                    if ((i == wayPoints.Count - 1 && !backTracking) || (i == 0 && backTracking))
                    {
                        switch (moveType)
                        {
                        case MoveType.Once:
                            return;

                        case MoveType.Loop:
                            if (!backTracking)
                            {
                                nextWaypoint = wayPoints[0].transform;
                            }
                            else
                            {
                                nextWaypoint = wayPoints[wayPoints.Count - 1].transform;
                            }
                            break;

                        case MoveType.PingPong:
                            if (!backTracking)
                            {
                                nextWaypoint = wayPoints[i - 1].transform;
                            }
                            else
                            {
                                nextWaypoint = wayPoints[i + 1].transform;
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (!backTracking)
                        {
                            nextWaypoint = wayPoints[i + 1].transform;
                        }
                        else
                        {
                            nextWaypoint = wayPoints[i - 1].transform;
                        }
                    }
                    if (waypoint.eulerAngles.z != nextWaypoint.eulerAngles.z)
                    {
                        Transform     rotationViewer  = (Transform)Instantiate(rotationViewerPrefab);
                        List <Bounds> boundsInstances = new List <Bounds>();
                        foreach (SpriteRenderer renderer in GetComponentsInChildren <SpriteRenderer>())
                        {
                            boundsInstances.Add(renderer.bounds);
                        }
                        Bounds rotationBounds = BoundsExtensions.Combine(boundsInstances.ToArray());
                        rotationViewer.position = waypoint.position;
                        float greatestRadius = Mathf.Max(rotationBounds.extents.x, rotationBounds.extents.y);
                        foreach (Bounds bounds in boundsInstances)
                        {
                            Vector2 furthestPoint = bounds.min;
                            float   currentRadius = Vector2.Distance(rotationBounds.center, furthestPoint);
                            if (currentRadius > greatestRadius)
                            {
                                greatestRadius = currentRadius;
                            }
                            furthestPoint = bounds.max;
                            currentRadius = Vector2.Distance(rotationBounds.center, furthestPoint);
                            if (currentRadius > greatestRadius)
                            {
                                greatestRadius = currentRadius;
                            }
                            furthestPoint = new Vector2(bounds.min.x, bounds.max.y);
                            currentRadius = Vector2.Distance(rotationBounds.center, furthestPoint);
                            if (currentRadius > greatestRadius)
                            {
                                greatestRadius = currentRadius;
                            }
                            furthestPoint = new Vector2(bounds.max.x, bounds.min.y);
                            currentRadius = Vector2.Distance(rotationBounds.center, furthestPoint);
                            if (currentRadius > greatestRadius)
                            {
                                greatestRadius = currentRadius;
                            }
                        }
                        rotationViewer.localScale  = Vector2.one * ((greatestRadius + Vector2.Distance(rotationBounds.center, transform.position)) * 2);
                        rotationViewer.eulerAngles = waypoint.eulerAngles;
                        Scene currentScene = SceneManager.GetActiveScene();
                        for (int i2 = 0; i2 < SceneManager.sceneCount; i2++)
                        {
                            SceneManager.SetActiveScene(SceneManager.GetSceneAt(i2));
                            GameObject canvas = GameObject.Find("Canvas (World)");
                            if (canvas != null)
                            {
                                rotationViewer.SetParent(canvas.transform);
                                break;
                            }
                        }
                        SceneManager.SetActiveScene(currentScene);
                        rotationViewer.GetComponent <Image>().color = path.color;
                        float rotaAmount = Mathf.Abs(Mathf.DeltaAngle(waypoint.eulerAngles.z, nextWaypoint.eulerAngles.z));
                        if (MathfExtensions.RotationDirectionToAngle(waypoint.eulerAngles.z, nextWaypoint.eulerAngles.z) > 0 == backTracking)
                        {
                            rotationViewer.GetComponent <Image>().fillClockwise = false;
                        }
                        rotationViewer.GetComponent <Image>().fillAmount = 1f / (360f / rotaAmount);
                    }
                }
            }
        }