Exemplo n.º 1
0
 public void Init(Transform character, Transform camera, VoxelPlayInputController input)
 {
     m_CharacterTargetRot = character.localRotation;
     m_CameraTargetRot    = camera.localRotation;
     if (input != null)
     {
         m_Input = input;
     }
 }
Exemplo n.º 2
0
        void LateUpdate()
        {
            VoxelPlayInputController input = env.input;

            if (input == null || inventoryPlaceholder == null)
            {
                return;
            }
            if (input.anyKey)
            {
                if (env.enableConsole && Input.GetKeyDown(KeyCode.F1))
                {
                    ToggleConsoleVisibility(!console.activeSelf);
                }
                else if (env.enableDebugWindow && Input.GetKeyDown(KeyCode.F2))
                {
                    ToggleDebugWindow(!debug.activeSelf);
                }
                else if (Input.GetKeyDown(KeyCode.Escape))
                {
                    ToggleConsoleVisibility(false);
                    ToggleInventoryVisibility(false);
                }
                else if (env.enableInventory && input.GetButtonDown(InputButtonNames.Inventory))
                {
                    leftShiftPressed = false;
                    if (!inventoryPlaceholder.activeSelf)
                    {
                        ToggleInventoryVisibility(true);
                    }
                    else if (Input.GetKey(KeyCode.LeftShift))
                    {
                        InventoryPreviousPage();
                    }
                    else
                    {
                        InventoryNextPage();
                    }
                }
                else if (Input.GetKeyDown(KeyCode.UpArrow) && IsVisible)
                {
                    inputField.text = lastCommand;
                    inputField.MoveTextEnd(false);
                }
                else if (Input.GetKeyDown(KeyCode.F8))
                {
                    ToggleFPS();
                }
                else if (inventoryPlaceholder.activeSelf)
                {
                    if (Input.GetKeyDown(KeyCode.Alpha1))
                    {
                        SelectItemFromVisibleInventorySlot(0);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha2))
                    {
                        SelectItemFromVisibleInventorySlot(1);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha3))
                    {
                        SelectItemFromVisibleInventorySlot(2);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha4))
                    {
                        SelectItemFromVisibleInventorySlot(3);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha5))
                    {
                        SelectItemFromVisibleInventorySlot(4);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha6))
                    {
                        SelectItemFromVisibleInventorySlot(5);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha7))
                    {
                        SelectItemFromVisibleInventorySlot(6);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha8))
                    {
                        SelectItemFromVisibleInventorySlot(7);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha9))
                    {
                        SelectItemFromVisibleInventorySlot(8);
                    }
                    else if (Input.GetKeyDown(KeyCode.Alpha0))
                    {
                        SelectItemFromVisibleInventorySlot(9);
                    }
                }
            }

            if (inventoryPlaceholder.activeSelf)
            {
                CheckInventoryControlKeyHints(true);
            }

            if (debug.activeSelf)
            {
                UpdateDebugInfo();
            }

            if (fpsText.enabled)
            {
                UpdateFPSCounter();
            }
        }
        void Start()
        {
            base.Init();
            m_Camera = GetComponentInChildren <Camera> ();
            if (m_Camera != null)
            {
                if (env != null)
                {
                    env.cameraMain = m_Camera;
                }
                m_Camera.nearClipPlane   = 0.1f;               // good value for interacting with water
                m_OriginalCameraPosition = m_Camera.transform.localPosition;
                if (hasCharacterController)
                {
                    m_FovKick.Setup(m_Camera);
                    m_HeadBob.Setup(m_Camera, footStepInterval);
                }
            }
            m_Jumping = false;

            if (env == null || !env.applicationIsPlaying)
            {
                return;
            }

            InitUnderwaterEffect();

            ToggleCharacterController(false);
            input = env.input;

            if (hasCharacterController)
            {
                // Position character on ground
                if (!env.saveFileIsLoaded)
                {
                    if (startOnFlat && env.world != null)
                    {
                        float   minAltitude = env.world.terrainGenerator.maxHeight;
                        Vector3 flatPos     = transform.position;
                        Vector3 randomPos;
                        for (int k = 0; k < startOnFlatIterations; k++)
                        {
                            randomPos = Random.insideUnitSphere * 1000;
                            float alt = env.GetTerrainHeight(randomPos);
                            if (alt < minAltitude && alt >= env.waterLevel + 1)
                            {
                                minAltitude = alt;
                                randomPos.y = alt + characterHeight + 1;
                                flatPos     = randomPos;
                            }
                        }
                        transform.position = flatPos;
                    }
                }

                SetOrbitMode(orbitMode);
                mouseLook.Init(transform, m_Camera.transform, input);
            }

            InitCrosshair();

            if (!env.initialized)
            {
                env.OnInitialized += () => WaitForCurrentChunk();
            }
            else
            {
                WaitForCurrentChunk();
            }
        }
        void Start()
        {
            base.Init();

            m_Capsule = GetComponent <CapsuleCollider> ();
            if (m_Capsule != null)
            {
                m_CapsuleHeight = m_Capsule.height * transform.lossyScale.y;
                m_CapsuleCenter = m_Capsule.center;

                if (Application.isPlaying && !useThirdPartyController && m_Capsule.sharedMaterial == null)
                {
                    // ZeroFriction physic material is used to make easier climbing - however it's only used by this controller so if you're using other controllers do not touch the collider
                    PhysicMaterial mat = Resources.Load <PhysicMaterial> ("VoxelPlay/Materials/ZeroFriction");
                    m_Capsule.sharedMaterial = mat;
                }
            }

            m_Rigidbody = GetComponent <Rigidbody> ();
            if (m_Rigidbody != null)
            {
                m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
            }
            m_OrigGroundCheckDistance = m_GroundCheckDistance;
            m_Animator = GetComponentInChildren <Animator> ();

            // Try to assign our designed camera
            if (m_Camera == null)
            {
                m_Camera = Camera.main;
            }
            if (env != null && m_Camera != null)
            {
                env.cameraMain = m_Camera;
            }
            // If no camera assigned, get Voxel Play Environment available camera
            if (m_Camera == null)
            {
                m_Camera = env.cameraMain;
            }

            if (env == null || !env.applicationIsPlaying)
            {
                return;
            }

            ToggleCharacterController(false);

            // Position character on ground
            if (!env.saveFileIsLoaded)
            {
                if (startOnFlat && env.world != null)
                {
                    float   minAltitude = env.world.terrainGenerator.maxHeight;
                    Vector3 flatPos     = transform.position;
                    Vector3 randomPos;
                    for (int k = 0; k < startOnFlatIterations; k++)
                    {
                        randomPos = Random.insideUnitSphere * 1000;
                        float alt = env.GetTerrainHeight(randomPos);
                        if (alt < minAltitude && alt >= env.waterLevel + 1)
                        {
                            minAltitude = alt;
                            randomPos.y = alt + characterHeight * 0.5f + 0.1f;
                            flatPos     = randomPos;
                        }
                    }
                    transform.position = flatPos;
                }
            }

            input = env.input;

            cameraX = 0;
            cameraY = 35;
            UpdateCamera(false);

            InitCrosshair();

            if (!env.initialized)
            {
                env.OnInitialized += () => WaitForCurrentChunk();
            }
            else
            {
                WaitForCurrentChunk();
            }
        }