void Awake()
        {
            Application.targetFrameRate = Globals.TargetClientFramerate;

            _editorIsInOfflineMode = true;

            _levelEditor = LevelEditor.Instance;

            _appState = AppState.Null;
        }
Exemplo n.º 2
0
        public void init(Vector3 chunkPos)
        {
            _chunkPos = chunkPos;

            _isVisible = false;

            _levelId = -1;

            _levelEditor  = LevelEditor.Instance;
            _assetFactory = AssetFactory.Instance;

            _quadrantFlags = new Dictionary <string, int> ();

            _worldProps = new Dictionary <GameObject, worldProp> ();

            _numCubes = 0;
        }
        //
        // CONSTRUCTOR
        //
        public EditorTool(int type)
        {
            _type = type;

            if (!_initialised)
            {
                _initialised = true;

                _levelEditor = LevelEditor.Instance;
                _curCam      = _levelEditor.editCam;
                _flycam      = FlyCam.Instance;

                _trfmAimTool       = _levelEditor.laserAim.transform;
                _trfmAimCenterCube = _levelEditor.laserAimCenterCube.transform;
                _trfmAimProp       = _levelEditor.propAim.transform;

                _rendererAimTool       = _trfmAimTool.GetComponent <Renderer> ();
                _rendererAimCenterCube = _trfmAimCenterCube.GetComponent <Renderer> ();
                _materialAimTool       = _rendererAimTool.material;

                // Experimental
                _matRailgunShape       = _rendererAimTool.material;
                _iSelectedRailgunShape = 0;

                _aUsedShaders       = new Dictionary <string, Shader> ();
                _goLastShaderChange = null;
                _aGoShaderChanged   = new List <GameObject> ();

                _goHitLast = null;
                _raycastedObjectHasChanged = false;

                _lastMouseWheelUpdate = 0;

                _mouseIsDown = false;

                _v3AimPos = new Vector3();
                //_chunkSizeHalved = VoxelUtils.CHUNK_SIZE * 0.5f;
            }
        }
        //
        private void createLevel(LevelFile levelFile)
        {
            if (levelFile.fileFormatVersion != Globals.levelSaveFormatVersion)
            {
                AppController.Instance.showPopup(PopupMode.Notification, "Warning", Globals.warningObsoleteFileFormat);
                return;
            }

            currentLevelId = levelFile.levelId;

            MainMenu.Instance.setLevelNameText(levelFile.levelName);
            lastLevelName = levelFile.levelName;

            LevelEditor      levelEditor  = LevelEditor.Instance;
            PropsManager     propsManager = PropsManager.Instance;
            VoxelsLevelChunk levelChunk   = levelEditor.curVoxelsLevelChunk;

            levelEditor.resetAll();

            Vector3 savedPos = new Vector3(levelFile.playerPosition.x, levelFile.playerPosition.y, levelFile.playerPosition.z);
            Vector3 savedRot = new Vector3(levelFile.playerEuler.x, levelFile.playerEuler.y, levelFile.playerEuler.z);

            levelChunk.setStartPos(savedPos, savedRot);
            FlyCam.Instance.setNewInitialPosition(savedPos, savedRot);
            FlyCam.Instance.reset();

            //GameObject goQuadrant;
            //Transform trfmContainer;
            //GameObject container;
            Vector3 pos = Vector3.zero;

            int   quadLen   = levelEditor.cubesPerQuadrant;
            float fRockSize = levelEditor.fRockSize;

            int i, len = levelFile.levelVoxelChunks.Count;

            Debug.Log("levelFile.levelVoxelChunks.Count: " + levelFile.levelVoxelChunks.Count);
            for (i = 0; i < len; ++i)
            {
                pos.x = (int)levelFile.levelVoxelChunks[i].position.x;
                pos.y = (int)levelFile.levelVoxelChunks[i].position.y;
                pos.z = (int)levelFile.levelVoxelChunks[i].position.z;

                VoxelUtils.VoxelChunk vc = levelEditor.curVoxelsLevelChunk.createVoxelChunk(
                    VoxelUtils.convertVector3ToVoxelVector3Int(pos),
                    (int)levelFile.levelVoxelChunks[i].size.x,
                    (int)levelFile.levelVoxelChunks[i].size.y,
                    (int)levelFile.levelVoxelChunks[i].size.z
                    );

                vc.materialIndex = levelFile.levelVoxelChunks [i].materialId;

                levelEditor.curVoxelsLevelChunk.aVoxelChunks.Add(vc);

                levelEditor.curVoxelsLevelChunk.setVoxelChunkMesh(vc);
            }

            MainMenu.Instance.setCubeCountText("Voxel Chunks: " + levelEditor.curVoxelsLevelChunk.aVoxelChunks.Count.ToString());

            if (levelFile.levelProps != null)
            {
                LevelProp  levelProp;
                GameObject goProp;
                Quaternion rotation = Quaternion.identity;
                propDef    prop;
                string     name;

                len = levelFile.levelProps.Count;
                for (i = 0; i < len; ++i)
                {
                    levelProp = levelFile.levelProps [i];

                    pos.x = levelProp.position.x;
                    pos.y = levelProp.position.y;
                    pos.z = levelProp.position.z;

                    prop = propsManager.getPropDefForId(levelProp.id);
                    if (prop.id != -1)
                    {
                        name   = prop.name + "_" + levelChunk.trfmProps.childCount;
                        goProp = propsManager.createProp(prop, pos, name, levelChunk.trfmProps, prop.useCollider, prop.useGravity);

                        rotation.w = levelProp.rotation.w;
                        rotation.x = levelProp.rotation.x;
                        rotation.y = levelProp.rotation.y;
                        rotation.z = levelProp.rotation.z;
                        goProp.transform.rotation = rotation;

                        levelChunk.addWorldProp(prop.id, goProp);
                    }
                }
            }
        }