コード例 #1
0
ファイル: MapCreate.cs プロジェクト: gangzi4494/bigmap
    public void CreateMap(MapIndex mapIndex)
    {
        string mapName = MapIndexConfig.GetMapNameByMapIndex(mapIndex);

        string mapPath = FolderMgr.GetMapPrefabPath();

        string mapFrefab = mapPath + "/" + mapName;

        Object obj = Resources.Load(mapFrefab);

        if (obj == null)
        {
            Debug.Log("path is " + mapFrefab);
            return;
        }

        GameObject instance = GameObject.Instantiate(obj) as GameObject;
    }
コード例 #2
0
ファイル: MapCreate.cs プロジェクト: gangzi4494/bigmap
    public void UpdateCreateMap(Vector3 pos)
    {
        //int targetChunkX = (int)(pos.x / width) + 1;
        //int targetChunkZ = (int)(pos.z / width) + 1;
        //是否需要   根据位置
        if (MapIndexConfig.IsneedCreateMapByPos(lastPos, pos) == false)
        {
            return;
        }
        //是否需要  根据

        // 1 需要的地图块
        MapIndex[] mapIndexs = MapIndexConfig.GetMap9(pos);

        /// 对比是否已经加载过了
        List <MapIndex> needMapIndexs = new List <MapIndex>();

        for (int i = 0; i < mapIndexs.Length; i++)
        {
            bool is_had = false;
            foreach (MapIndex mapIndex in list_had_mapindexs)
            {
                if (MapIndexConfig.CompareMapIndex(mapIndex, mapIndexs[i]) == true)
                {
                    is_had = true;
                }
            }

            if (is_had == false)
            {
                needMapIndexs.Add(mapIndexs[i]);
            }
        }

        ///

        foreach (MapIndex mapIndex in needMapIndexs)
        {
            CreateMap(mapIndex);
        }
        ///

        lastPos = pos;
    }
コード例 #3
0
ファイル: bigmap_editor.cs プロジェクト: gangzi4494/bigmap
    /**/

    static void ClassifyGameObject(GameObject obj)
    {
        Vector3 pos = obj.transform.position;

        //int targetChunkX = (int)(pos.x / MapConfig.width) + 1;
        //int targetChunkZ = (int)(pos.z / MapConfig.width) + 1;

        string chunkName = MapIndexConfig.GetMapName(pos);//  ChunkRootNamePrefix + string.Format("{0}_{1}", targetChunkX, targetChunkZ);


        GameObject chunkRoot = GameObject.Find(chunkName);

        if (chunkRoot == null)
        {
            chunkRoot = new GameObject(chunkName);
        }


        //复制层次关系到Chunk的节点下面
        GameObject        tempObj   = obj;
        List <GameObject> objs2Copy = new List <GameObject>();

        while (tempObj.transform.parent)
        {
            objs2Copy.Add(tempObj.transform.parent.gameObject);
            tempObj = tempObj.transform.parent.gameObject;
        }

        tempObj = chunkRoot;

        for (int i = objs2Copy.Count - 1; i > -1; --i)
        {
            GameObject targetObj = objs2Copy[i];

            // 对于符合Chunk命名规则的父节点不进行拷贝过程。
            if (targetObj.name.StartsWith(ChunkRootNamePrefix))
            {
                continue;
            }

            Transform parent = tempObj.transform.Find(targetObj.name);
            if (parent == null)
            {
                parent = new GameObject(targetObj.name).transform;
                //CopyComponents(targetObj, parent.gameObject);
                parent.parent = tempObj.transform;
                targetObj     = parent.gameObject;
            }
            tempObj = parent.gameObject;
        }

        Transform tempParent = obj.transform.parent;

        obj.transform.parent = tempObj.transform;

        // 移动完毕之后发现父节点没有孩子节点的情况下,向上遍历将无用节点删除。
        while (tempParent != null && tempParent.childCount == 0)
        {
            Transform temp = tempParent.parent;
            //EngineUtils.Destroy(tempParent.gameObject);
            tempParent = temp;
        }
    }