Esempio n. 1
0
        static void Init()
        {
            Clear();

            MapBlockTool.Init();
            float cubeX = EditorPrefs.GetFloat("BlockCube X", 1f);
            float cubeY = EditorPrefs.GetFloat("BlockCube Y", 1);
            float cubeZ = EditorPrefs.GetFloat("BlockCube Z", 1.75f);

            _cubeSize   = new Vector3(cubeX, cubeY, cubeZ);
            _sceneSizeX = EditorPrefs.GetInt("BlockSceneSize X", 30);
            _sceneSizeZ = EditorPrefs.GetInt("BlockSceneSize Z", 30);


            string winPath = EditorUtiliTool.UnityPath2WinAbs(BlocksPrefabsDir);

            string[] dirPaths = Directory.GetDirectories(winPath);
            for (int i = 0; i < dirPaths.Length; i++)
            {
                string blockTypePath = dirPaths[i];
                if (string.IsNullOrEmpty(blockTypePath))
                {
                    continue;
                }
                string typeName = Path.GetFileName(blockTypePath);
                _blocksTypes.Add(typeName);
                string[] blockPaths = Directory.GetFiles(blockTypePath, "**.prefab", SearchOption.AllDirectories);

                _blockPathsDic.Add(typeName, blockPaths);
            }
            SetBlockMenuData();
        }
Esempio n. 2
0
        static void InitPathNode()
        {
            _pathNode.Clear();
            _blockObjsDic.Clear();
            GameObject sceneTree = GameObject.Find("/__Scene");

            _sceneTree = sceneTree == null ? new GameObject("__Scene").transform : sceneTree.transform;
            _sceneTree.transform.position = Origin;
            string        winPath = EditorUtiliTool.UnityPath2WinAbs(MapBlockWindow.BlocksPrefabsDir);
            List <string> dirs    = new List <string>(Directory.GetDirectories(winPath));

            for (int i = 0; i < dirs.Count; i++)
            {
                string     blockNodeName = Path.GetFileName(dirs[i]);
                string     nodePath      = string.Format("/{0}/{1}", _sceneTree.name, blockNodeName);
                GameObject nodeGo        = GameObject.Find(nodePath);
                Transform  nodeTran      = nodeGo == null ? new GameObject(blockNodeName).transform : nodeGo.transform;
                if (!_pathNode.ContainsKey(nodeTran.name))
                {
                    _pathNode.Add(nodeTran.name, nodeTran);
                }

                EditorUtiliTool.AddChildToP(_sceneTree, nodeTran);

                foreach (Transform child in nodeTran)
                {
                    int     x = 0, z = 0;
                    Vector3 worldPos = child.position;
                    CalcGridPos(worldPos, out x, out z);
                    Block block = new Block();
                    block.obj = child;
                    block.x   = x;
                    block.z   = z;
                    int instanceID = child.GetInstanceID();
                    _blockObjsDic.Add(instanceID, block);
                }
            }

            _gridPainter = _sceneTree.GetComponent <MapGridPainter>();
            if (_gridPainter == null)
            {
                _gridPainter = _sceneTree.gameObject.AddComponent <MapGridPainter>();
            }
            _gridPainter.enabled   = true;
            _gridPainter.hideFlags = HideFlags.DontSave;
        }