Exemplo n.º 1
0
        private void OnValidate()
        {
            PlayerControllerTest playerControllerTest = GameObject.FindObjectOfType <PlayerControllerTest>();

            if (playerControllerTest)
            {
                AdjacentRoomCulling adjacentRoomCulling = playerControllerTest.head.gameObject.GetComponent <AdjacentRoomCulling>();
                if (!adjacentRoomCulling)
                {
                    adjacentRoomCulling = playerControllerTest.head.gameObject.AddComponent <AdjacentRoomCulling>();
                }
                adjacentRoomCulling.enabled = dungeonCullAdjacentRoom;
            }
        }
Exemplo n.º 2
0
        private void OnGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status)
        {
            if (status != GenerationStatus.Complete)
            {
                return;
            }

            SceneManager.MoveGameObjectToScene(generator.CurrentDungeon.gameObject, this.gameObject.scene);

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Seed: " + generator.ChosenSeed);
            stringBuilder.AppendLine("Generation time: " + generator.GenerationStats.TotalTime + " ms");
            stringBuilder.AppendLine("Main room count: " + generator.GenerationStats.MainPathRoomCount);
            stringBuilder.AppendLine("Branch room count: " + generator.GenerationStats.BranchPathRoomCount);
            stringBuilder.AppendLine("Total room count: " + generator.GenerationStats.TotalRoomCount);
            stringBuilder.AppendLine("Retry count: " + generator.GenerationStats.TotalRetries);
            Debug.Log(stringBuilder.ToString());

            GenerateNavMesh();

            PlayerSpawner playerSpawner = GameObject.FindObjectOfType <PlayerSpawner>();

            if (playerSpawner)
            {
                playerStart = playerSpawner.transform;
                PlayerControllerTest playerControllerTest = GameObject.FindObjectOfType <PlayerControllerTest>();
                if (playerControllerTest)
                {
                    playerControllerTest.transform.SetPositionAndRotation(playerStart.position, playerStart.rotation);
                    AdjacentRoomCulling adjacentRoomCulling = playerControllerTest.head.gameObject.GetComponent <AdjacentRoomCulling>();
                    if (!adjacentRoomCulling)
                    {
                        adjacentRoomCulling = playerControllerTest.head.gameObject.AddComponent <AdjacentRoomCulling>();
                    }
                    adjacentRoomCulling.enabled = dungeonCullAdjacentRoom;
                }
            }
            else
            {
                Debug.LogError("No player spawner found for dungeon!");
            }
        }
Exemplo n.º 3
0
        void Update()
        {
#if DUNGEN
            if (xrNode == XRNode.LeftHand)
            {
                if (device.TryGetFeatureValue(CommonUsages.primaryButton, out bool primaryPressed))
                {
                    if (primaryPressed)
                    {
                        if (!primaryPressState)
                        {
                            PlayerControllerTest       playerControllerTest = this.GetComponentInParent <PlayerControllerTest>();
                            DunGen.AdjacentRoomCulling adjacentRoomCulling  = playerControllerTest.head.gameObject.GetComponent <DunGen.AdjacentRoomCulling>();
                            adjacentRoomCulling.enabled = !adjacentRoomCulling.enabled;
                            primaryPressState           = true;
                        }
                    }
                    else
                    {
                        if (primaryPressState)
                        {
                            primaryPressState = false;
                        }
                    }
                }
                if (device.TryGetFeatureValue(CommonUsages.secondaryButton, out bool secondaryPressed))
                {
                    if (secondaryPressed)
                    {
                        if (!secondaryPressState)
                        {
                            Level level = GameObject.FindObjectOfType <Level>();
                            if (level && level.dungeonGenerator)
                            {
                                level.GenerateDungeon();
                            }
                            secondaryPressState = true;
                        }
                    }
                    else
                    {
                        if (secondaryPressState)
                        {
                            secondaryPressState = false;
                        }
                    }
                }
            }
#endif
            if (device.TryGetFeatureValue(CommonUsages.gripButton, out bool gripPressed))
            {
                if (gripPressed)
                {
                    if (!gripPressState)
                    {
                        if (!grabbedRb)
                        {
                            Collider[] colliders          = Physics.OverlapSphere(this.transform.position, 0.05f);
                            float      closestDistanceSqr = Mathf.Infinity;
                            Collider   nearestCollider    = null;
                            foreach (Collider collider in colliders)
                            {
                                if (collider.attachedRigidbody)
                                {
                                    float dSqrToTarget = (collider.ClosestPoint(this.transform.position) - this.transform.position).sqrMagnitude;
                                    if (dSqrToTarget < closestDistanceSqr)
                                    {
                                        closestDistanceSqr = dSqrToTarget;
                                        nearestCollider    = collider;
                                    }
                                }
                            }
                            if (nearestCollider)
                            {
                                if (nearestCollider.attachedRigidbody)
                                {
                                    //orgKinematic = nearestCollider.attachedRigidbody.isKinematic;
                                    grabbedRb  = nearestCollider.attachedRigidbody;
                                    fixedJoint = rb.gameObject.AddComponent <FixedJoint>();
                                    fixedJoint.connectedBody = grabbedRb;
                                    this.GetComponent <MeshRenderer>().enabled = false;
                                }
                            }
                        }
                        gripPressState = true;
                    }
                }
                else
                {
                    if (gripPressState)
                    {
                        if (grabbedRb)
                        {
                            if (fixedJoint)
                            {
                                Destroy(fixedJoint);
                            }
                            grabbedRb = null;
                            this.GetComponent <MeshRenderer>().enabled = true;
                        }
                        gripPressState = false;
                    }
                }
            }
        }