Ejemplo n.º 1
0
        static void SetBlockMenuData()
        {
            if (_blocksTypes.Count == 0)
            {
                return;
            }

            string blockType = _blocksTypes[_blockMenuIndex];

            if (!_blocksDic.ContainsKey(blockType))
            {
                List <BlockItem> ls         = new List <BlockItem>();
                string[]         blockPaths = _blockPathsDic[blockType];
                for (int i = 0; i < blockPaths.Length; i++)
                {
                    string     path   = EditorUtiliTool.WinAbs2UnityPath(blockPaths[i]);
                    GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    BlockItem  item   = new BlockItem();
                    item.prefab  = prefab;
                    item.texture = GeneratePreview(prefab);
                    ls.Add(item);
                }
                _blockPage.AddRange(ls);
                _blocksDic.Add(blockType, ls);
            }
            else
            {
                _blockPage.AddRange(_blocksDic[blockType]);
            }
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
        static Transform CreateTransInNode(Transform prefab)
        {
            Transform node = GetNode();
            Transform obj  = PrefabUtility.InstantiatePrefab(prefab.transform) as Transform;

            EditorUtiliTool.AddChildToP(node, obj);
            return(obj);
        }
Ejemplo n.º 4
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;
        }