//
        // 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;

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

                //_goLastMaterialChanged = null;
                //_tempMaterial = null;

                _goHitLast = null;
                _raycastedObjectHasChanged = false;

                _lastMouseWheelUpdate = 0;

                _mouseIsDown = false;
            }
        }
        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;
        }
        public void init()
        {
            _levelEditor  = LevelEditor.Instance;
            _assetFactory = AssetFactory.Instance;

            //_iMinLevelCoord = -50;
            //_iMaxLevelCoord = 50;

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

            /*for (int x = _iMinLevelCoord; x <= _iMaxLevelCoord; ++x) {
             *      _quadrantFlags.Add(x, new Dictionary<int, Dictionary<int, int>> ());
             *      for (int y = _iMinLevelCoord; y <= _iMaxLevelCoord; ++y) {
             *              _quadrantFlags [x].Add(y, new Dictionary<int, int> ());
             *              for (int z = _iMinLevelCoord; z <= _iMaxLevelCoord; ++z) {
             *                      _quadrantFlags [x] [y].Add(z, 0);
             *              }
             *      }
             * }*/

            _visibleQuadrants           = new Dictionary <GameObject, bool> ();
            _aQuadrantChangedVisibility = new List <GameObject> ();

            _numCubes = 0;

            //_coroutineIsRunning = false;

            if (AppController.Instance.editorIsInOfflineMode)
            {
                TextAsset levelAsset = Resources.Load <TextAsset>("Data/Levels/Genesis");
                string    json       = levelAsset.text;
                LevelData.Instance.loadLevelFromJson(json);
            }
            else
            {
                LevelManager.Instance.loadLevelByIndex(0);
            }
        }
        //
        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;
            //World world = World.Instance;
            LevelChunk levelChunk = levelEditor.curLevelChunk;

            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.levelQuadrants.Count;

            for (i = 0; i < len; ++i)
            {
                pos.x = (int)levelFile.levelQuadrants[i].position.x;
                pos.y = (int)levelFile.levelQuadrants[i].position.y;
                pos.z = (int)levelFile.levelQuadrants[i].position.z;

                string quadrantId = (int)pos.x + "_" + (int)pos.y + "_" + (int)pos.z;
                goQuadrant = levelChunk.createQuadrant(pos, quadrantId);
                if (goQuadrant == null)
                {
                    continue;
                }

                trfmContainer = goQuadrant.transform.Find(Globals.cubesContainerName);
                if (trfmContainer == null)
                {
                    continue;
                }
                container = trfmContainer.gameObject;

                Transform  trfmCube;
                GameObject cube;
                //Vector3 pos2 = Vector3.zero;
                string   materialName;
                Material material;

                bool isEdge = false;
                int  j, len2 = levelFile.levelQuadrants [i].levelObjects.Count;
                for (j = 0; j < len2; ++j)
                {
                    trfmCube = trfmContainer.Find(j.ToString());
                    if (trfmCube == null)
                    {
                        continue;
                    }
                    cube = trfmCube.gameObject;

                    if (levelFile.levelQuadrants [i].levelObjects [j].isActive == 0)
                    {
                        cube.SetActive(false);
                        levelChunk.numCubes--;
                    }
                    else
                    {
                        /*if (levelFile.levelQuadrants [i].isEdge == 1) {
                         *      material = levelEditor.materialEdge;
                         *      isEdge = true;
                         * } else {*/
                        materialName = Globals.materials[levelFile.levelQuadrants [i].levelObjects [j].materialId];
                        material     = levelEditor.aDictMaterials [materialName];
                        isEdge       = false;
                        //}

                        levelChunk.setCube(cube, material, isEdge);
                    }
                }
            }

            Debug.Log("Level id " + levelFile.levelId.ToString() + " - quadrants: " + len.ToString());
            Debug.Log("Level id " + levelFile.levelId.ToString() + " - cubes: " + levelChunk.numCubes.ToString());
            MainMenu.Instance.setCubeCountText(levelChunk.numCubes);

            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);
                    }
                }
            }
        }