Example #1
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);
    }
Example #2
0
    /// <summary>
    /// 依照3d位置,取得此cell的3d位置
    /// </summary>
    /// <param name="xIndex"></param>
    /// <param name="zIndex"></param>
    /// <param name="assetSize"></param>
    /// <returns></returns>
    public Vector3 GetCellPosition(int xIndex, int zIndex, Vector3 assetSize)
    {
        if (xIndex < 0 || zIndex < 0 || xIndex >= MapSizeX || zIndex >= MapSizeZ)
        {
            return(Vector3.zero);
        }

        return(MapUtility.CalCellPosition(MapDataCollection, MapUtility.CalTopLeftCellPosition(CenterPosition, MapSizeX, MapSizeZ), xIndex, zIndex, assetSize));
    }
Example #3
0
    bool updateGoPosition(GameObject go, bool isForceUpdate)
    {
        int xIndex = -1;
        int zIndex = -1;

        MapUtility.CalCellIndexByMousePosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ,
                                               rayCastLayer, ref xIndex, ref zIndex);

        if ((xIndex >= 0 && zIndex >= 0 && xIndex < mapController.MapSizeX && zIndex < mapController.MapSizeZ &&
             (isForceUpdate || xIndex != curCellIndexX || zIndex != curCellIndexZ)))
        {
            go.transform.position = MapUtility.CalCellPosition(mapController.MapDataCollection,
                                                               MapUtility.CalTopLeftCellPosition(mapController.CenterPosition, mapController.MapSizeX, mapController.MapSizeZ),
                                                               xIndex, zIndex, curCellData.Size);
            go.transform.position = MapUtility.CalCellHeightPosition(mapController.MapDataCollection, xIndex, zIndex, curCellData, go.transform.position);
            curCellIndexX         = xIndex;
            curCellIndexZ         = zIndex;
            return(true);
        }

        return(false);
    }