Пример #1
0
    void InstantiateCurCellGo()
    {
        if (mouseMode == MouseMode.CONTINUOUS)
        {
            GameObject connData = Resources.Load(MapSetting.MAP_CONNECT_TILE_FOLDER_NAME + curCellPrefabName.GetPathWidthoutExtension()) as GameObject;
            curCellGo = Instantiate(connData.GetComponent <MapConnection>().Default.Go);
        }
        else if (mouseMode == MouseMode.RANDIMIZE)
        {
            GameObject ranData = Resources.Load(MapSetting.MAP_RANDOM_TILE_FOLDER_NAME + curCellPrefabName.GetPathWidthoutExtension()) as GameObject;
            curCellGo = Instantiate(ranData.GetComponent <MapRandomList>().GoList[0]);
        }
        else
        {
            if (isPrefabOrPattern)
            {
                curCellGo = Instantiate(Resources.Load(MapSetting.MAP_REFAB_FOLDER_NAME + curCellPrefabName.GetPathWidthoutExtension())) as GameObject;
            }
            else
            {
                string patternName = Path.GetFileNameWithoutExtension(curCellPrefabName);
                mapPatternImporter.ImportPattern(patternName);
                curCellGo = mapPatternImporter.CreatePatternGameObject();
            }
        }

        curCellData = curCellGo.GetComponent <AssetCellData>();
        changeLayersRecursively(curCellGo.transform, MapSetting.IGNORE_RAY_CAST_LAYER_MASK);

        canBuildCube.transform.rotation    = curCellGo.transform.rotation;
        canNotBuildCube.transform.rotation = curCellGo.transform.rotation;
    }
Пример #2
0
    protected void DrawQuad(MapController mapController, AssetCellData cellData)
    {
        if (isPress)
        {
            Vector3 curMousePos = Input.mousePosition;

            //Get cell index
            int curXIndex = -1;
            int curZIndex = -1;
            MapUtility.CalCellIndexByMousePosition(curMousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref curXIndex, ref curZIndex);

            int lastXIndex = -1;
            int lastZIndex = -1;
            MapUtility.CalCellIndexByMousePosition(mousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref lastXIndex, ref lastZIndex);

            //Get cell position
            Vector3 curPos  = mapController.GetCellPosition(curXIndex, curZIndex);
            Vector3 lastPos = mapController.GetCellPosition(lastXIndex, lastZIndex);

            //Calulate squre ui's position
            Vector3 centerPos = (curPos + lastPos) * 0.5f;
            centerPos = new Vector3(centerPos.x, cellData.Size.y * 0.5f, centerPos.z + 0.1f);
            Vector3 len = (curPos - lastPos).AbsValue() + Vector3.one;
            len = new Vector3(len.x, cellData.Size.y, len.z);

            squareUI.transform.position   = centerPos;
            squareUI.transform.localScale = len;
            squareUI.SetActive(true);
        }
        else
        {
            squareUI.SetActive(false);
        }
    }
Пример #3
0
    static GameObject DrawMapObjectDataTopLeftCellPosition(MapObject mapObject, MapObject.ObjectData o, Vector3 topLeftCellPos, int xIndex, int zIndex, Transform parent = null)
    {
        Object obj = Resources.Load(o.PrefabName);

        if (obj != null)
        {
            GameObject go = GameObject.Instantiate(obj) as GameObject;
            go.name = go.name.Substring(0, go.name.LastIndexOf('('));
            AssetCellData assetData = go.GetComponent <AssetCellData>();
            assetData.Rotate(o.Rotation.eulerAngles.y);
            go.transform.parent        = parent;
            go.transform.localPosition = MapUtility.CalCellPosition(null, topLeftCellPos, xIndex, zIndex, assetData.Size);
            go.transform.localPosition = new Vector3(go.transform.localPosition.x, o.Height, go.transform.localPosition.z);
            go.transform.rotation      = o.Rotation;
            go.layer = LayerMask.NameToLayer("Map");

            o.Go              = go;
            assetData.MapObj  = mapObject;
            assetData.ObjData = o;

            return(go);
        }

        return(null);
    }
Пример #4
0
    public void BuildPattern(MapController mapController, int targetX, int targetZ, float height, Quaternion rotation, bool isObstacle)
    {
        if (mapData == null || mapObjectData == null)
        {
            return;
        }

        if (CanBuild(mapController.MapDataCollection, targetX, targetZ, height, rotation))
        {
            int oriXSize = (int)assetSize.x;
            int oriZSize = (int)assetSize.z;

            //旋轉
            int xSize = oriXSize;
            int zSize = oriZSize;
            Rotate(rotation.eulerAngles.y, ref xSize, ref zSize);

            int offsetX = targetX - (int)(xSize * 0.5f);
            int offsetZ = targetZ - (int)(zSize * 0.5f);

            IEnumerator mapObjItr = mapObjectData.GetObjectEnumerator();
            while (mapObjItr.MoveNext())
            {
                MapObject mo = mapObjItr.Current as MapObject;

                //計算x,z的值,要用還未旋轉的值去計算
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.IdToCoordinate(mo.Id, oriXSize, ref xIndex, ref zIndex); //get xIndex, zIndex from pattern coordinate

                int len = mo.ObjectDataList.Count;
                for (int i = 0; i < len; i++)
                {
                    MapObject.ObjectData objData  = mo.ObjectDataList[i];
                    GameObject           obj      = Resources.Load(objData.PrefabName) as GameObject;
                    AssetCellData        cellData = obj.GetComponent <AssetCellData>();

                    Rotate(rotation.eulerAngles.y, oriXSize, oriZSize, cellData.Size.z, ref xIndex, ref zIndex);
                    xIndex += offsetX; //translate to map coordinate
                    zIndex += offsetZ;

                    if (!isObstacle)
                    {
                        mapController.UpdateCellData(objData.PrefabName, xIndex, zIndex, height + objData.Height, cellData.Size, objData.Rotation * rotation);
                    }
                    else
                    {
                        mapController.UpdateCellData(objData.PrefabName, xIndex, zIndex, height + objData.Height, cellData.Size, objData.Rotation * rotation, UnitType.OBSTACLE);
                    }
                }
            }
        }
    }
Пример #5
0
    /// <summary>
    /// 清除cell資料
    /// </summary>
    /// <param name="assetCellData"></param>
    public void EraseCellData(AssetCellData assetCellData)
    {
        MapObject mapObject = assetCellData.MapObj;

        if (mapObject != null)
        {
            int xIndex = -1;
            int zIndex = -1;
            MapUtility.IdToCoordinate(mapObject.Id, MapSizeX, ref xIndex, ref zIndex);
            MapDataCollection.WriteCellData(xIndex, zIndex, assetCellData.Size, UnitType.NONE, assetCellData.ObjData.Height);
            MapObjectDataCollection.RemoveObjectData(mapObject.Id, assetCellData.ObjData);
        }
    }
Пример #6
0
    public GameObject CreatePatternGameObject()
    {
        if (mapData != null && mapObjectData != null)
        {
            GameObject o = new GameObject();
            o.name = FileName;
            DrawingMap.DrawCells(mapObjectData.GetObjectEnumerator(), (int)assetSize.x, (int)assetSize.z, Vector3.zero, o);
            AssetCellData cellData = o.AddComponent <AssetCellData>();
            cellData.Size   = assetSize;
            cellData.Center = new Vector3(0, assetSize.y * 0.5f, 0);
            return(o);
        }

        return(null);
    }
Пример #7
0
    public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList)
    {
        mapIndexList.Clear();
        base.Action(prefabName, cellGo, cellData, dataMode, isObstacle, mapIndexList);

        if (string.IsNullOrEmpty(prefabName))
        {
            return;
        }

        if (dataMode == DataMode.ERASE)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            isPress  = true;
            mousePos = Input.mousePosition;
        }

        if (isPress && Input.GetMouseButtonUp(0))
        {
            isPress = false;
            Vector3 curMousePos = Input.mousePosition;

            if (curMousePos != mousePos)
            {
                //Get cell index
                int curXIndex = -1;
                int curZIndex = -1;
                MapUtility.CalCellIndexByMousePosition(curMousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastLayer, ref curXIndex, ref curZIndex);

                int lastXIndex = -1;
                int lastZIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastLayer, ref lastXIndex, ref lastZIndex);

                if (curXIndex < lastXIndex)
                {
                    Swap(ref curXIndex, ref lastXIndex);
                }

                if (curZIndex < lastZIndex)
                {
                    Swap(ref curZIndex, ref lastZIndex);
                }

                if (isInTheMap(curXIndex, curZIndex, mapController) && isInTheMap(lastXIndex, lastZIndex, mapController))
                {
                    //calculate the number of the cells that we can build
                    int xCount = (int)((curXIndex - lastXIndex + 1) / cellData.Size.x);
                    int zCount = (int)((curZIndex - lastZIndex + 1) / cellData.Size.z);
                    if (xCount > 0 && zCount > 0)
                    {
                        //because the cell chosen by the mouse does not point to the center of the cell, so we need to calclute the index to the centero of the cell
                        int startXIndex = lastXIndex + ((int)Mathf.Abs(cellData.Size.x - 1));
                        int startZIndex = lastZIndex + ((int)Mathf.Abs(cellData.Size.z - 1));

                        for (int i = 0; i < xCount; i++)
                        {
                            int xIndex = startXIndex + i * (int)cellData.Size.x;
                            for (int j = 0; j < zCount; j++)
                            {
                                int   zIndex = startZIndex + j * (int)cellData.Size.z;
                                float yPos   = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cellData);

                                if (dataMode == DataMode.ADD)
                                {
                                    if (!string.IsNullOrEmpty(prefabName))
                                    {
                                        if (!isObstacle)
                                        {
                                            mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                                         cellData.Size, cellGo.transform.rotation);
                                        }
                                        else
                                        {
                                            mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                                         cellData.Size, cellGo.transform.rotation, UnitType.OBSTACLE);
                                        }
                                    }
                                    else
                                    {
                                        patternImporter.BuildPattern(mapController, xIndex, zIndex, yPos, cellGo.transform.rotation, isObstacle);
                                    }

                                    AddMapIndex(xIndex, zIndex, mapIndexList);
                                }
                                else if (dataMode == DataMode.CAN_MOVE || dataMode == DataMode.CAN_NOT_MOVE)
                                {
                                    bool canMove = dataMode == DataMode.CAN_MOVE ? true : false;
                                    if (mapController.SetCellMovable(xIndex, zIndex, canMove))
                                    {
                                        AddMapIndex(xIndex, zIndex, mapIndexList);
                                    }
                                }
                                else if (dataMode == DataMode.ADD_PLAYER || dataMode == DataMode.ERASE_PLAYER || dataMode == DataMode.ADD_ENEMY || dataMode == DataMode.ERASE_ENEMY)
                                {
                                    AddMapIndex(xIndex, zIndex, mapIndexList);
                                }
                            }
                        }
                    }
                }
            }
        }

        DrawQuad(mapController, cellData);
    }
Пример #8
0
    //cellGo -> default gameObject
    //prefabName -> Map Connection prefab
    public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList)
    {
        mapIndexList.Clear();
        base.Action(prefabName, cellGo, cellData, dataMode, isObstacle, mapIndexList);

        if (Input.GetMouseButton(0))
        {
            if (dataMode == DataMode.ADD)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    int id = MapUtility.CoordinateToId(xIndex, zIndex, mapController.MapSizeX);
                    if (!buildMapId.Contains(id))
                    {
                        if (!isPress)
                        {
                            if (totalBuildMapId.ContainsKey(id))
                            {
                                buildHeight = totalBuildMapId[id];
                            }
                            else
                            {
                                buildHeight = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cellData);
                            }
                        }

                        if (mapController.MapDataCollection.CanBuildOnTheMap(xIndex, zIndex, buildHeight, cellData.Size) || totalBuildMapId.ContainsKey(id))
                        {
                            buildMapId.Add(id);

                            //Draw dummy object
                            GameObject dummy = Object.Instantiate(dummyObject) as GameObject;
                            dummy.transform.parent = dummyParent.transform;
                            Vector3 pos = mapController.GetCellPosition(xIndex, zIndex);
                            dummy.transform.position = new Vector3(pos.x, buildHeight, pos.z);

                            isPress = true;
                        }
                    }
                }
            }
            else if (dataMode == DataMode.ERASE)
            {
                GameObject hitObject = MapUtility.GetRayCastMapObjectByMousePosition(rayCastLayer);
                if (hitObject != null)
                {
                    AssetCellData cd = hitObject.GetComponent <AssetCellData>();
                    mapController.EraseCellData(cd);
                    totalBuildMapId.Remove(cd.MapObj.Id);
                }
            }
        }
        else if (Input.GetMouseButtonUp(0) && isPress)
        {
            if (buildMapId.Count == 0)
            {
                return;
            }

            MapConnection mapConn = (Resources.Load(MapSetting.MAP_CONNECT_TILE_FOLDER_NAME + prefabName.GetPathWidthoutExtension()) as GameObject).GetComponent <MapConnection>();
            checkIfNeedReBuild(mapController);

            List <MapDir> neighBorList = new List <MapDir>();
            foreach (var item in buildMapId)
            {
                int curXIndex = -1;
                int curZIndex = -1;
                MapUtility.IdToCoordinate(item, mapController.MapSizeX, ref curXIndex, ref curZIndex);

                getNeighborDir(curXIndex, curZIndex, mapController, neighBorList);
                Quaternion rot = Quaternion.identity;
                string     p   = getPrefabName(neighBorList, cellGo, mapConn, ref rot);

                if (!isObstacle)
                {
                    mapController.UpdateCellData(p, curXIndex, curZIndex, buildHeight, cellData.Size, rot);
                }
                else
                {
                    mapController.UpdateCellData(p, curXIndex, curZIndex, buildHeight, cellData.Size, rot, UnitType.OBSTACLE);
                }
                AddMapIndex(curXIndex, curZIndex, mapIndexList);

                totalBuildMapId[item] = buildHeight;
            }

            buildMapId.Clear();
            isPress = false;
            for (int i = dummyParent.transform.childCount - 1; i >= 0; i--)
            {
                Object.Destroy(dummyParent.transform.GetChild(i).gameObject);
            }
        }
    }
Пример #9
0
 public virtual void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList)
 {
     return;
 }
Пример #10
0
    public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList)
    {
        mapIndexList.Clear();
        base.Action(prefabName, cellGo, cellData, dataMode, isObstacle, mapIndexList);
        if (Input.GetMouseButton(0))
        {
            if (dataMode == DataMode.ADD)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    int id = MapUtility.CoordinateToId(xIndex, zIndex, mapController.MapSizeX);
                    if (!buildMapId.Contains(id))
                    {
                        float yPos = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cellData);
                        if (mapController.MapDataCollection.CanBuildOnTheMap(xIndex, zIndex, yPos, cellData.Size))
                        {
                            if (!string.IsNullOrEmpty(prefabName))
                            {
                                if (!isObstacle)
                                {
                                    mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                                 cellData.Size, cellGo.transform.rotation);
                                }
                                else
                                {
                                    mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                                 cellData.Size, cellGo.transform.rotation, UnitType.OBSTACLE);
                                }
                            }
                            else
                            {
                                patternImporter.BuildPattern(mapController, xIndex, zIndex, yPos, cellGo.transform.rotation, isObstacle);
                            }

                            //Add id that the cell can not be builded
                            int leftX  = xIndex - ((int)Mathf.Abs(cellData.Size.x)) / 2;
                            int rightX = xIndex + ((int)Mathf.Abs(cellData.Size.x - 1)) / 2;
                            int downZ  = zIndex - ((int)Mathf.Abs(cellData.Size.z)) / 2;
                            int upZ    = zIndex + ((int)Mathf.Abs(cellData.Size.z - 1)) / 2;

                            for (int i = leftX; i <= rightX; i++)
                            {
                                for (int j = downZ; j <= upZ; j++)
                                {
                                    buildMapId.Add(MapUtility.CoordinateToId(i, j, mapController.MapSizeX));
                                }
                            }
                        }

                        AddMapIndex(xIndex, zIndex, mapIndexList);
                    }
                }
            }
            else if (dataMode == DataMode.ERASE)
            {
                GameObject hitObject = MapUtility.GetRayCastMapObjectByMousePosition(rayCastLayer);
                if (hitObject != null)
                {
                    mapController.EraseCellData(hitObject.GetComponent <AssetCellData>());
                }
            }
            else if (dataMode == DataMode.CAN_MOVE || (dataMode == DataMode.CAN_NOT_MOVE))
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    if (mapController.SetCellMovable(xIndex, zIndex, dataMode == DataMode.CAN_MOVE ? true : false))
                    {
                        AddMapIndex(xIndex, zIndex, mapIndexList);
                    }
                }
            }
            else if (dataMode == DataMode.ADD_PLAYER || dataMode == DataMode.ERASE_PLAYER || dataMode == DataMode.ADD_ENEMY || dataMode == DataMode.ERASE_ENEMY)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    AddMapIndex(xIndex, zIndex, mapIndexList);
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            buildMapId.Clear();
        }
    }
Пример #11
0
    /// <summary>
    /// 計算包含asset在內的cell(xIndex, zIndex)的高度,即cell目前最高 + asset的中心點高度
    /// </summary>
    /// <param name="mapData"></param>
    /// <param name="xIndex"></param>
    /// <param name="zIndex"></param>
    /// <param name="cellData"></param>
    /// <returns></returns>
    static public float CalCellHeightPosition(MapData mapData, int xIndex, int zIndex, AssetCellData cellData)
    {
        float cellHeight = mapData.GetCell(xIndex, zIndex).GetHeightest();

        return(cellHeight + cellData.Size.y * 0.5f - cellData.Center.y);
    }
Пример #12
0
    /// <summary>
    /// 計算包含asset在內的cell(xIndex, zIndex)的高度,即cell目前最高 + asset的中心點高度
    /// </summary>
    /// <param name="mapData"></param>
    /// <param name="xIndex"></param>
    /// <param name="zIndex"></param>
    /// <param name="cellData"></param>
    /// <param name="curPosition"></param>
    /// <returns></returns>
    static public Vector3 CalCellHeightPosition(MapData mapData, int xIndex, int zIndex, AssetCellData cellData, Vector3 curPosition)
    {
        float yPos = CalCellHeightPosition(mapData, xIndex, zIndex, cellData);

        return(new Vector3(curPosition.x, yPos, curPosition.z));
    }
Пример #13
0
    public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List<MapIndex> mapIndexList)
    {
        mapIndexList.Clear();

        if (string.IsNullOrEmpty(prefabName))
        {
            return;
        }

        if (dataMode == DataMode.ERASE)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            isPress = true;
            mousePos = Input.mousePosition;
        }

        if (isPress && Input.GetMouseButtonUp(0))
        {
            isPress = false;
            Vector3 curMousePos = Input.mousePosition;

            if (curMousePos != mousePos)
            {
                //Get cell index
                int curXIndex = -1;
                int curZIndex = -1;
                MapUtility.CalCellIndexByMousePosition(curMousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref curXIndex, ref curZIndex);

                int lastXIndex = -1;
                int lastZIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mousePos, mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref lastXIndex, ref lastZIndex);

                if (curXIndex < lastXIndex)
                {
                    Swap(ref curXIndex, ref lastXIndex);
                }

                if (curZIndex < lastZIndex)
                {
                    Swap(ref curZIndex, ref lastZIndex);
                }

                if (isInTheMap(curXIndex, curZIndex, mapController) && isInTheMap(lastXIndex, lastZIndex, mapController))
                {
                    List<GameObject> randomList = (Resources.Load(MapSetting.MAP_RANDOM_TILE_FOLDER_NAME + prefabName.GetPathWidthoutExtension()) as GameObject).GetComponent<MapRandomList>().GoList;
                    int randomCount = randomList.Count;
 
                    //calculate the number of the cells that we can build     
                    int xCount = (int)((curXIndex - lastXIndex + 1) / cellData.Size.x);
                    int zCount = (int)((curZIndex - lastZIndex + 1) / cellData.Size.z);
                    if (xCount > 0 && zCount > 0)
                    {
                        //because the cell chosen by the mouse does not point to the center of the cell, so we need to calclute the index to the centero of the cell 
                        int startXIndex = lastXIndex + ((int)Mathf.Abs(cellData.Size.x - 1));
                        int startZIndex = lastZIndex + ((int)Mathf.Abs(cellData.Size.z - 1));

                        for (int i = 0; i < xCount; i++)
                        {
                            int xIndex = startXIndex + i * (int)cellData.Size.x;
                            for (int j = 0; j < zCount; j++)
                            {
                                int zIndex = startZIndex + j * (int)cellData.Size.z;

                                int goIndex = Random.Range(0, randomCount);
                                AssetCellData cd = randomList[goIndex].GetComponent<AssetCellData>();
                                float yPos = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cd);

                                if (dataMode == DataMode.ADD)
                                {
                                    string p = getAssetPath(randomList[goIndex]);
                                    if (!isObstacle)
                                    {
                                        mapController.UpdateCellData(p, xIndex, zIndex, yPos, cd.Size, Quaternion.Euler(0f, Random.Range(0, 3) * 90f, 0f));
                                    }
                                    else
                                    {
                                        mapController.UpdateCellData(p, xIndex, zIndex, yPos, cd.Size, Quaternion.Euler(0f, Random.Range(0, 3) * 90f, 0f), UnitType.OBSTACLE);
                                    }
                                    AddMapIndex(xIndex, zIndex, mapIndexList);
                                }
                                else if (dataMode == DataMode.CAN_MOVE || dataMode == DataMode.CAN_NOT_MOVE)
                                {
                                    bool canMove = dataMode == DataMode.CAN_MOVE ? true : false;
                                    if (mapController.SetCellMovable(xIndex, zIndex, canMove))
                                    {
                                        AddMapIndex(xIndex, zIndex, mapIndexList);
                                    }
                                }
                                else if (dataMode == DataMode.ADD_PLAYER || dataMode == DataMode.ERASE_PLAYER || dataMode == DataMode.ADD_ENEMY || dataMode == DataMode.ERASE_ENEMY)
                                {
                                    AddMapIndex(xIndex, zIndex, mapIndexList);
                                }
                            }
                        }
                    }
                }
            }
        }

        DrawQuad(mapController, cellData);
    }
Пример #14
0
    public override void Action(string prefabName, GameObject cellGo, AssetCellData cellData, DataMode dataMode, bool isObstacle, List <MapIndex> mapIndexList)
    {
        mapIndexList.Clear();
        base.Action(prefabName, cellGo, cellData, dataMode, isObstacle, mapIndexList);
        if (Input.GetMouseButtonDown(0))
        {
            if (dataMode == DataMode.ADD)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    float yPos = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, cellData);

                    if (!string.IsNullOrEmpty(prefabName))
                    {
                        if (!isObstacle)
                        {
                            mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                         cellData.Size, cellGo.transform.rotation);
                        }
                        else
                        {
                            mapController.UpdateCellData(MapSetting.MAP_REFAB_FOLDER_NAME + prefabName.GetPathWidthoutExtension(), xIndex, zIndex, yPos,
                                                         cellData.Size, cellGo.transform.rotation, UnitType.OBSTACLE);
                        }
                    }
                    else
                    {
                        patternImporter.BuildPattern(mapController, xIndex, zIndex, yPos, cellGo.transform.rotation, isObstacle);
                    }

                    AddMapIndex(xIndex, zIndex, mapIndexList);
                }
            }
            else if (dataMode == DataMode.ERASE)
            {
                GameObject hitObject = MapUtility.GetRayCastMapObjectByMousePosition(rayCastLayer);
                if (hitObject != null)
                {
                    mapController.EraseCellData(hitObject.GetComponent <AssetCellData>());
                }
            }
            else if (dataMode == DataMode.CAN_MOVE || dataMode == DataMode.CAN_NOT_MOVE)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    if (mapController.SetCellMovable(xIndex, zIndex, dataMode == DataMode.CAN_MOVE ? true : false))
                    {
                        AddMapIndex(xIndex, zIndex, mapIndexList);
                    }
                }
            }
            else if (dataMode == DataMode.ADD_PLAYER || dataMode == DataMode.ERASE_PLAYER || dataMode == DataMode.ADD_ENEMY || dataMode == DataMode.ERASE_ENEMY)
            {
                int xIndex = -1;
                int zIndex = -1;
                MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ, rayCastMapLayer, ref xIndex, ref zIndex);
                if (xIndex >= 0 && zIndex >= 0)
                {
                    AddMapIndex(xIndex, zIndex, mapIndexList);
                }
            }
        }
    }