示例#1
0
        protected void ShowSelectedItem()
        {
            if (items == null)
            {
                return;
            }
            VoxelPlayUI ui = VoxelPlayUI.instance;

            if (ui != null)
            {
                if (_selectedItemIndex >= 0 && _selectedItemIndex < items.Count)
                {
                    ui.ShowSelectedItem(items[_selectedItemIndex]);
                }
                else
                {
                    ui.HideSelectedItem();
                }
            }
        }
示例#2
0
        public static void Init()
        {
            if (_instance != null)
            {
                return;
            }

            _instance = FindObjectOfType <VoxelPlayUI> ();
            if (_instance != null)
            {
                return;
            }

            VoxelPlayEnvironment env = VoxelPlayEnvironment.instance;

            if (env == null)
            {
                return;
            }

            if (env.UICanvasPrefab == null)
            {
                env.UICanvasPrefab = Resources.Load <GameObject> ("VoxelPlay/UI/Voxel Play UI Canvas");
                if (env.UICanvasPrefab == null)
                {
                    return;
                }
            }

            GameObject canvas = Instantiate <GameObject> (env.UICanvasPrefab);

            canvas.name = env.UICanvasPrefab.name;
            if (canvas == null)
            {
                return;
            }

            _instance = canvas.GetComponent <VoxelPlayUI> ();
        }
        public void Init(AfterInitCallback callback = null)
        {
            initialized          = false;
            sceneCam             = null;
            applicationIsPlaying = Application.isPlaying;
            tempChunks           = new List <VoxelChunk> ();
            tempColliders        = new Collider [1];
            InitMainThreading();

#if UNITY_ANDROID || UNITY_IOS
            isMobilePlatform = true;
#elif UNITY_WEBGL
            isMobilePlatform = false;
#if UNITY_EDITOR
            if (PlayerSettings.WebGL.memorySize < 2000)
            {
                PlayerSettings.WebGL.memorySize = 2000;
            }
#endif
#else
            isMobilePlatform = Application.isMobilePlatform;
#endif

#if UNITY_WEBGL
            effectiveMultithreadGeneration = false;
#else
            effectiveMultithreadGeneration = multiThreadGeneration;
#endif

#if !UNITY_EDITOR
            if (isMobilePlatform)
            {
                Application.lowMemory += Application_lowMemory;
            }
#endif

            // Init camera and Sun references
            if (cameraMain == null)
            {
                cameraMain = Camera.main;
                if (cameraMain == null)
                {
                    cameraMain = FindObjectOfType <Camera> ();
                }
                if (cameraMain == null)
                {
                    Debug.LogError("Voxel Play: No camera found!");
                    return;
                }
            }

            // Default distance anchor
            if (distanceAnchor == null && cameraMain != null)
            {
                distanceAnchor = cameraMain.transform;
            }

            // Cache player collider
            if (characterController == null)
            {
                characterController = FindObjectOfType <VoxelPlayCharacterControllerBase> ();
            }
            if (characterController != null)
            {
                characterControllerCollider = characterController.GetComponent <CharacterController> ();
                if (characterControllerCollider == null)
                {
                    characterControllerCollider = characterController.GetComponent <Collider> ();
                }
            }

#if UNITY_EDITOR
            if (cameraMain.actualRenderingPath != RenderingPath.Forward)
            {
                Debug.LogWarning("Voxel Play works better with Forward Rendering path.");
            }
            if (!isMobilePlatform && QualitySettings.antiAliasing < 2)
            {
                Debug.LogWarning("Voxel Play looks better with MSAA enabled (x2 minimum to enable crosshair).");
            }
#endif

            if (isMobilePlatform && applicationIsPlaying && adjustCameraFarClip)
            {
                cameraMain.farClipPlane = Mathf.Min(400, _visibleChunksDistance * CHUNK_SIZE);
            }
            VoxelPlayUI oldUISystem = GetComponent <VoxelPlayUI> ();
            if (oldUISystem != null)
            {
                DestroyImmediate(oldUISystem);
                oldUISystem = null;
            }

            // Default values
            if (crosshairPrefab == null)
            {
                crosshairPrefab = Resources.Load <GameObject> ("VoxelPlay/UI/crosshair");
            }
            if (crosshairTexture == null)
            {
                crosshairTexture = Resources.Load <Texture2D> ("VoxelPlay/UI/crosshairTexture");
            }


            // Input
            if (inputControllerPCPrefab == null)
            {
                inputControllerPCPrefab = Resources.Load <GameObject> ("VoxelPlay/InputControllers/PC/Voxel Play PC Input Controller");
            }
            if (inputControllerMobilePrefab == null)
            {
                inputControllerMobilePrefab = Resources.Load <GameObject> ("VoxelPlay/InputControllers/Mobile/Voxel Play Mobile Input Controller");
            }

            if (applicationIsPlaying)
            {
                // UI
                VoxelPlayUI.Init();
                // Init Input

                GameObject inputPrefab = null;
#if UNITY_EDITOR
                if (isMobilePlatform && previewTouchUIinEditor)
                {
                    inputPrefab = inputControllerMobilePrefab;
                }
                else
                {
                    inputPrefab = inputControllerPCPrefab;
                }
#else
                if (isMobilePlatform)
                {
                    inputPrefab = inputControllerMobilePrefab;
                }
                else
                {
                    inputPrefab = inputControllerPCPrefab;
                }
#endif

                if (inputPrefab != null)
                {
                    GameObject inputGO = Instantiate <GameObject> (inputPrefab);
                    inputGO.name      = inputPrefab.name;
                    inputGO.hideFlags = HideFlags.DontSave;
                    inputGO.SetActive(false);
                    input = inputGO.GetComponent <VoxelPlayInputController> ();
                }
            }

            stopWatch = new System.Diagnostics.Stopwatch();

#if UNITY_EDITOR
            lastInspectorUpdateTime = 0;
            lastCameraMoveTime      = 0;
#endif

            if (!enableBuildMode)
            {
                buildMode = false;
            }

            if (applicationIsPlaying || (!applicationIsPlaying && renderInEditor))
            {
                stopWatch.Start();
                if (cachedChunks == null || chunksPool == null)
                {
                    LoadWorldInt();
                    if (applicationIsPlaying)
                    {
                        StartCoroutine(WarmChunks(callback));
                    }
                    else
                    {
                        WarmChunksEditor(callback);
                    }
                }
            }
            else
            {
                UpdateAmbientProperties();
            }
        }