コード例 #1
0
    bool GetItemMapInfo(int w, int h, out ItemMapInfo info)
    {
        if (!m_itemmapInfoIsInit[w, h])
        {
            if (!m_terrainInfoAsset.ItemInfoList[w * m_splitMap_X + h])
            {
                m_itemmapInfoIsInit[w, h] = true;
                info = null;
                return(false);
            }
            string name = string.Format(m_itemInfoName, w, h);
#if TILEMAP_TEST
            var itemInfo = AssetDatabase.LoadAssetAtPath <ItemMapInfo>(string.Format("{0}/{1}.asset", m_itemInfoPath, name));
            if (itemInfo != null)
            {
                itemInfo.Init();
                m_itemmapInfo[w, h] = itemInfo;
            }
            m_itemmapInfoIsInit[w, h] = true;
#else
            LoadManager.Instance.LoadAsset(m_itemInfoPath, name, "asset", typeof(ItemMapInfo), (data) =>
            {
                var itemInfo = data as ItemMapInfo;
                if (itemInfo != null)
                {
                    itemInfo.Init();
                    m_itemmapInfo[w, h] = itemInfo;
                }
                m_itemmapInfoIsInit[w, h] = true;
            }, false, false, false, m_fullPath);
#endif
        }
        info = m_itemmapInfo[w, h];
        return(m_terrainInfoAsset.ItemInfoList[w * m_splitMap_X + h]);
    }
コード例 #2
0
ファイル: ItemDropMgr.cs プロジェクト: shanghaichina/TSC
    void InistantDropItem(ItemMapInfo mapInfo, ItemType type)
    {
        float        offX     = Random.Range(-mapInfo.Width, mapInfo.Width);
        float        offY     = Random.Range(-mapInfo.Height, mapInfo.Height);
        GameObject   go       = Spawner((int)type, new Vector3(mapInfo.PosX + offX, 0, mapInfo.PosY + offY), ResourceType.RESOURCE_ITEM, GameMgr.Instance.ItemRoot);
        DropItemInfo dropInfo = Util.AddComponent <DropItemInfo>(go);

        dropInfo.ItemId = mapInfo.Index;
        dropInfo.InfoId = (int)type;
        dropInfo.Area   = mapInfo.Area;
        dropInfo.IsLock = false;
        //dropInfo.DropAI = DropAI.LATER;
        //Debug.LogError(mapInfo.Index +" "+type);
        EntityMgr.Instance.DropItemDic[dropInfo.ItemId] = dropInfo;
    }
コード例 #3
0
    void InistantDropItem(ItemMapInfo mapInfo, ItemType type)
    {
        //Debug.LogError("产生道具类型:" + type);
        float        offX     = Random.Range(-mapInfo.Width, mapInfo.Width);
        float        offY     = Random.Range(-mapInfo.Height, mapInfo.Height);
        GameObject   go       = Spawner((int)type, new Vector3(mapInfo.PosX + offX, 0, mapInfo.PosY + offY), ResourceType.RESOURCE_ITEM, GameMgr.Instance.ItemRoot);
        DropItemInfo dropInfo = Util.AddComponent <DropItemInfo>(go);

        dropInfo.ItemId = mapInfo.Index;
        dropInfo.InfoId = (int)type;
        dropInfo.Area   = mapInfo.Area;
        dropInfo.IsLock = false;
        if (TSCData.Instance.DropItemDic.ContainsKey(dropInfo.ItemId))
        {
            Despawner(ResourceType.RESOURCE_ITEM, TSCData.Instance.DropItemDic[dropInfo.ItemId]);
        }
        TSCData.Instance.DropItemDic[dropInfo.ItemId] = dropInfo;
    }
コード例 #4
0
    protected void CheckVisibleItem(int _pos_x, int _pos_z, int i, int j)
    {
        int id = _pos_x * 10000 + _pos_z;

        // if (m_hideItem.Contains(id))
        if (_pos_x >= m_map_W || _pos_x < 0 || _pos_z >= m_map_H || _pos_z < 0)
        {
            m_needVisibleItem[i, j].isShow = false;
            SetVisibleItemNUll(i, j);
            return;
        }
        if (m_hideItemList[_pos_x, _pos_z])
        {
            m_needVisibleItem[i, j].isShow = false;
            SetVisibleItemNUll(i, j);
            return;
        }
        int _index_x = _pos_x / m_tilemap_W;
        int _index_z = _pos_z / m_tilemap_H;

        ItemMapInfo _itemInfo      = null;
        bool        hasItemMapInfo = GetItemMapInfo(_index_x, _index_z, out _itemInfo);

        int map_index = _pos_z * m_map_W + _pos_x;

        //物件
        string itemName   = null;
        bool   hasItemObj = false;

        if (hasItemMapInfo)
        {
            hasItemObj = _itemInfo.itemInfoDic.TryGetValue(map_index, out itemName);
        }
        if (hasItemObj)
        {
            m_needVisibleItem[i, j].isShow   = true;
            m_needVisibleItem[i, j].itemName = itemName;
        }
        else
        {
            m_needVisibleItem[i, j].isShow = false;
            SetVisibleItemNUll(i, j);
        }
    }
コード例 #5
0
    static void ExportItemMap()
    {
        List <MapInfo> maps = new List <MapInfo>();

        for (int idx = 0; idx < EditorBuildSettings.scenes.Length; idx++)
        {
            EditorBuildSettingsScene s = EditorBuildSettings.scenes[idx];
            if (s.enabled)
            {
                //EditorSceneManager.OpenScene(s.path);
                MapInfo mapInfo = new MapInfo();
                mapInfo.Id = idx;
                if (null != mapInfo.ItemMapInfo)
                {
                    mapInfo.ItemMapInfo.Clear();
                }
                else
                {
                    mapInfo.ItemMapInfo = new List <ItemMapInfo>();
                }


                GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
                if (items.Length > 0)
                {
                    foreach (GameObject go in items)
                    {
                        Transform   t    = go.transform;
                        MapArea     area = MapArea.NONE;
                        DropMapArea a    = t.parent.GetComponent <DropMapArea>();
                        if (null != a)
                        {
                            area = a.mapArea;
                        }
                        Vector3     v = t.position;
                        float       w = t.localScale.x;
                        float       h = t.localScale.z;
                        ItemMapInfo m = new ItemMapInfo(ItemMapType.ITEM, area, v.x, v.z, w, h);
                        mapInfo.ItemMapInfo.Add(m);
                    }
                }

                GameObject[] points = GameObject.FindGameObjectsWithTag("Point");
                if (points.Length > 0)
                {
                    foreach (GameObject go in items)
                    {
                        Transform   t    = go.transform;
                        MapArea     area = MapArea.NONE;
                        DropMapArea a    = t.parent.GetComponent <DropMapArea>();
                        if (null != a)
                        {
                            area = a.mapArea;
                        }
                        Vector3     v = t.position;
                        float       w = t.localScale.x;
                        float       h = t.localScale.z;
                        ItemMapInfo m = new ItemMapInfo(ItemMapType.POINT, area, v.x, v.z, w, h);
                        mapInfo.ItemMapInfo.Add(m);
                    }
                }
                maps.Add(mapInfo);
            }
        }
        Util.Serialize <List <MapInfo> >(maps, AppConst.AppStreamingPath + "/" + AppConst.TextDir + "/map.bin");
        AssetDatabase.Refresh();
    }
コード例 #6
0
ファイル: ResourceExport.cs プロジェクト: k3498gg/TSC
    static void ExportItemMap()
    {
        List <MapInfo> maps = new List <MapInfo>();

        for (int idx = 0; idx < EditorBuildSettings.scenes.Length; idx++)
        {
            EditorBuildSettingsScene s = EditorBuildSettings.scenes[idx];
            if (s.enabled)
            {
                //EditorSceneManager.OpenScene(s.path);
                MapInfo mapInfo = new MapInfo();
                mapInfo.Id = idx;

                GameObject ground = GameObject.FindGameObjectWithTag("ground");
                Vector3    scale  = ground.transform.localScale;
                Vector3    bound  = ground.GetComponent <MeshFilter>().sharedMesh.bounds.extents;
                mapInfo.Width  = bound.x * scale.x;
                mapInfo.Height = bound.z * scale.z;

                if (null != mapInfo.ItemMapInfo)
                {
                    mapInfo.ItemMapInfo.Clear();
                }
                else
                {
                    mapInfo.ItemMapInfo = new List <ItemMapInfo>();
                }

                int          index = 0;
                GameObject[] items = GameObject.FindGameObjectsWithTag("Item");
                if (items.Length > 0)
                {
                    foreach (GameObject go in items)
                    {
                        Transform   t    = go.transform;
                        MapArea     area = MapArea.NONE;
                        DropMapArea a    = t.parent.GetComponent <DropMapArea>();
                        if (null != a)
                        {
                            area = a.mapArea;
                        }
                        Vector3     v = t.position;
                        float       w = t.localScale.x * 0.5f;
                        float       h = t.localScale.z * 0.5f;
                        ItemMapInfo m = new ItemMapInfo(ItemMapType.ITEM, area, v.x, v.z, w, h);
                        m.Index = index++;
                        mapInfo.ItemMapInfo.Add(m);
                    }
                }

                GameObject[] points = GameObject.FindGameObjectsWithTag("Point");
                if (points.Length > 0)
                {
                    foreach (GameObject go in points)
                    {
                        Transform   t    = go.transform;
                        MapArea     area = MapArea.NONE;
                        DropMapArea a    = t.parent.GetComponent <DropMapArea>();
                        if (null != a)
                        {
                            area = a.mapArea;
                        }
                        Vector3     v = t.position;
                        float       w = t.localScale.x * 0.5f;
                        float       h = t.localScale.z * 0.5f;
                        ItemMapInfo m = new ItemMapInfo(ItemMapType.POINT, area, v.x, v.z, w, h);
                        m.Index = index++;
                        mapInfo.ItemMapInfo.Add(m);
                    }
                }

                GameObject[] obstacles = GameObject.FindGameObjectsWithTag("Obstacle");
                if (obstacles.Length > 0)
                {
                    //foreach (GameObject go in obstacles)
                    for (int obi = 0; obi < obstacles.Length; obi++)
                    {
                        Transform    t     = obstacles[obi].transform;
                        ObstacleType otype = Util.GetComponent <ObstacleType>(obstacles[obi]);
                        Vector3      v     = t.position;
                        Obstacle     obs   = new Obstacle();
                        obs.Id      = obi + 1;
                        obs.PosX    = v.x;
                        obs.PosY    = v.z;
                        obs.Poshh   = v.y;
                        obs.Rotate  = t.localRotation.y;
                        obs.Width   = t.localScale.x;
                        obs.Height  = t.localScale.z;
                        obs.Hh      = t.localScale.y;
                        obs.ObsType = otype.obstacle_type;
                        mapInfo.Obstacles.Add(obs);
                    }
                }

                maps.Add(mapInfo);
            }
        }
        Util.Serialize <List <MapInfo> >(maps, AppConst.AppStreamingPath + "/" + AppConst.TextDir + "/map.bin");
        AssetDatabase.Refresh();
    }