Exemple #1
0
        void Start()
        {
            rg = gameObject.GetComponent <RoadGenerator>();
            if (rg.Exit.Length < 8)
            {
                rg.RefreshExits();
            }

            SpawnNonVehicles();
            if (Random.value < spawnChance)
            {
                TrySpawn();
            }
        }
        void FixedUpdate()
        {
            if (Input.GetKey(KeyCode.Keypad0))
            {
                bCull = !bCull;
            }

            Transform playerTransform = checkpoint.FollowCamera.target.transform;

            //Debug.Log(checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>().Length + " 35:" + checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>()[35].gameObject.name);

            if (checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>().Length > 100 /*usually around 140, prevent checking until the map is up to size*/ && EmergencyFieldRemover == null && checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>()[35] as DisabledRoadGenerator != null /*35 is around a quarter, meaning grass at this position indicates a map with three quarters grass*/)
            {
                int i = RoadGenerator.Wrap0to7(Mathf.RoundToInt(playerTransform.rotation.eulerAngles.y / 45.0f));

                Vector3 player = RoundDownToGrid(playerTransform.position);
                hitTest.x = Mathf.FloorToInt(player.x / WorldTileManager.TILE_SIZE) + RoadGenerator.Xoffset(i) * 8;
                hitTest.z = Mathf.FloorToInt(player.z / WorldTileManager.TILE_SIZE) + RoadGenerator.Zoffset(i) * 8;
                //Debug.Log("Testing for a hit at grid "+hitTest.x+","+hitTest.z+"; World location "+hitTest.GetWorldPosition());
                WorldTile Hit = WorldTileManager.instance.GetTile(hitTest);

                if (!Hit)
                {
                    //Debug.Log("F****N FIELD, heading " + playerTransform.rotation.eulerAngles.y + "≈" + (RoadGenerator.Direction)i);

                    EmergencyFieldRemover = Instantiate(FourWay, hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent <RoadGenerator>().YOffset, 0), Quaternion.identity, checkpoint.RoadMapRoot.transform);
                    //Debug.Log("EFR: "+EmergencyFieldRemover.gameObject.name + " at " + (hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent<RoadGenerator>().YOffset, 0)));
                    WorldTileManager.instance.AddTile(EmergencyFieldRemover.GetComponent <WorldTile>());
                    EmergencyFieldRemover.transform.SetAsFirstSibling();
                    RoadGenerator newRG = EmergencyFieldRemover.GetComponent <RoadGenerator>();
                    newRG.CullingExempt = true;
                    newRG.RefreshExits();
                    //newRG.Extend(true);
                    //checkpoint.RoadMapRoot.BroadcastMessage("Extend", true);
                }
            }
            else if             // Emergency Field Remover has come within the invisible boundary lines (σ回ω・)σ
            ((EmergencyFieldRemover != null && Vector3.Distance(playerTransform.position, EmergencyFieldRemover.transform.position) < checkpoint.FollowCamera.CullDistance)
             ||                 // Emergency Field Remover is no longer in front of the player
             (EmergencyFieldRemover != null && Vector3.Dot(playerTransform.position - EmergencyFieldRemover.transform.position, playerTransform.forward) > 90))
            {
                EmergencyFieldRemover.GetComponent <RoadGenerator>().CullingExempt = false;
                EmergencyFieldRemover = null;
            }
        }