示例#1
0
    //Shuijing CreateCrystal(PATileTerrain.PACrystalTile crystalTile, int level,PATileTerrain.TileElementType elementType)
    Shuijing CreateCrystal(int level, PATileTerrain.TileElementType elementType)
    {
        string preShuijingName = "";

        if (elementType == PATileTerrain.TileElementType.Fire)
        {
            preShuijingName = "v_";
        }
        else if (elementType == PATileTerrain.TileElementType.Wood)
        {
            preShuijingName = "w_";
        }
        string     shuijingPrefabName = preShuijingName + shuijingName + level.ToString();
        GameObject shuijingGo         = PoolManager.Pools["Shuijing"].Spawn(shuijingPrefabName).gameObject;

        GameUtility.SetLayerRecursive(shuijingGo.transform, toPlaceBuildingLayer);
        Shuijing shuijing = shuijingGo.GetComponent <Shuijing>();

        shuijing.level       = level;
        shuijing.elementType = elementType;
        shuijing.prefabName  = shuijingPrefabName;
        shuijing.Reset();
        //shuijing.SetSelectTag(true);

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));

        Physics.Raycast(ray, out hit, Mathf.Infinity, terrainChunkLayermask);
        shuijing.transform.position = hit.point;

        return(shuijing);
    }
示例#2
0
    Shuijing CreateCrystal(PATileTerrain.PATile tile, int level, PATileTerrain.TileElementType elementType)
    {
        PATileTerrain.PABuildingTile buildingTile = PATileTerrain.PABuildingTile.GetByTile(tileTerrain, tile);
        Shuijing shuijing = CreateCrystal(level, elementType);

        return(PlaceCrystal(shuijing, buildingTile));
    }
示例#3
0
    void EditCrystal()
    {
        if (!CheckEditCrystal())
        {
            return;
        }

        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3    pos;
        int        x, y;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, editCrystalLayerMask))
        {
            PATileTerrain tt          = tileTerrain.IsTerrain(hit.transform);
            Shuijing      hitShuijing = hit.transform.GetComponent <Shuijing>();
            if (tt != null)
            {
                if (toPlaceBuilding == null)
                {
                    SetSelectShuijing(null);
                    Messenger <PATileTerrain.PATile> .Broadcast(UIEvent.UIEvent_ShowSelectCrystal, null);
                }
                else
                {
                    pos = tileTerrain.transform.InverseTransformPoint(hit.point);
                    x   = (int)Mathf.Abs(pos.x / tileTerrain.tileSize);
                    y   = (int)Mathf.Abs(pos.z / tileTerrain.tileSize);
                    PATileTerrain.PATile         tile         = tileTerrain.GetTile(x, y);
                    PATileTerrain.PABuildingTile buildingTile = PATileTerrain.PABuildingTile.GetByTile(tileTerrain, tile);

                    Shuijing shuijing = toPlaceBuilding as Shuijing;
                    if (!CheckCrystalDistance(buildingTile.keyTile, shuijing))
                    {
                        Messenger.Broadcast(UIEvent.UIEvent_CrystalDistanceTip);
                        return;
                    }

                    PlaceCrystal(shuijing, buildingTile);
                    shuijing.SetSelectTag(false);
                    RepaintAllCrystals();
                    //PaintCrystal(shuijing);
                    toPlaceBuilding = null;
                    //SetSelectShuijing(shuijing);
                    Messenger.Broadcast(TerrainManagerEvent_PlaceBuilding);
                }
            }
            else if (hitShuijing != null && toPlaceBuilding == null)
            {
                SetSelectShuijing(hitShuijing);
                MoveCameraToPos(hitShuijing.transform, MoveToCrystalCallBack);
            }
            else
            {
                SetSelectShuijing(null);
            }
        }
    }
示例#4
0
 public void Reset()
 {
     ResetQtrTiles();
     specifiedIndex = -1;
     rotateType     = UVRotateType.None;
     element.Reset();
     decalTilesetIndex = -1;
     //distance = -1;
     affectShuijing = null;
 }
示例#5
0
    void RemoveCrystal(Shuijing shuijing)
    {
        if (shuijing == null)
        {
            return;
        }

        //tileTerrain.FillTerrain(defaultBrushType);
        shuijing.RemoveBelonging();
        PoolManager.Pools["Shuijing"].Despawn(shuijing.transform);
        tileTerrain.settings.RemoveCrystal(shuijing.tile.id);
        shuijing.tile.shuijing = null;
        shuijing.tile          = null;
        //RepaintAllCrystals();
    }
示例#6
0
 public void SetSelectShuijing(Shuijing shuijing)
 {
     if (selectShuijing != null)
     {
         selectShuijing.SetSelectTag(false);
     }
     selectShuijing = shuijing;
     if (selectShuijing != null)
     {
         selectShuijing.SetSelectTag(true);
     }
     else
     {
         Messenger.Broadcast(UIEvent.UIEvent_ShowCrystalOption);
     }
 }
示例#7
0
    public Shuijing PlaceCrystal(Shuijing shuijing, PATileTerrain.PABuildingTile buildingTile)
    {
        PATileTerrainChunk chunk = tileTerrain.GetChunk(buildingTile.keyTile.chunkId);

        shuijing.gameObject.transform.SetParent(chunk.settings.crystalGo.transform);
        shuijing.gameObject.transform.position = buildingTile.GetBuildingPos(tileTerrain);
        buildingTile.keyTile.shuijing          = shuijing;
        shuijing.tile = buildingTile.keyTile;
        GameUtility.SetLayerRecursive(shuijing.transform, buildingLayer);
        PATileTerrain.PACrystalBuilding crystalBuildingData = new PATileTerrain.PACrystalBuilding(
            buildingTile.keyTile.id, shuijing.level, shuijing.elementType, shuijing.prefabName, RandomManager.NewSeed());
        crystalBuildingData.shuijing = shuijing;
        tileTerrain.settings.AddCrystal(crystalBuildingData);

        return(shuijing);
    }
示例#8
0
    public void UpgradeSelectShuijing()
    {
        if (selectShuijing == null)
        {
            return;
        }
        PATileTerrain.PATile tile = selectShuijing.tile;
        int newLevel = selectShuijing.level + 1;

        PATileTerrain.TileElementType elementType = selectShuijing.elementType;
        RemoveCrystal(selectShuijing);
        Shuijing shuijing = CreateCrystal(tile, newLevel, elementType);

        //PaintCrystal(shuijing);
        RepaintAllCrystals();
        SetSelectShuijing(null);
    }
示例#9
0
    bool CheckCrystalDistance(PATileTerrain.PATile newTile, Shuijing shuijing)
    {
        float minDistance = GetMinDistanceOfCrystal();

        foreach (var crystal in tileTerrain.settings.crystals)
        {
            if (crystal.shuijing.elementType == shuijing.elementType)
            {
                continue;
            }

            PATileTerrain.PATile tile = tileTerrain.GetTile(crystal.id);
            float distance            = tile.Distance(newTile);
            if (distance < minDistance)
            {
                return(false);
            }
        }

        return(true);
    }
示例#10
0
    void PlaceNest(NestBuilding nest, PATileTerrain.PABuildingTile buildingTile)
    {
        Shuijing belongShuijing = buildingTile.keyTile.affectShuijing;

        if (belongShuijing == null)
        {
            return;
        }

        PATileTerrainChunk chunk = tileTerrain.GetChunk(buildingTile.keyTile.chunkId);

        nest.gameObject.transform.SetParent(chunk.settings.buildingsRoot.transform);
        nest.gameObject.transform.position = buildingTile.GetBuildingPos(tileTerrain);
        nest.tile = buildingTile.keyTile;
        //nest.belongShuijing = belongShuijing;
        GameUtility.SetLayerRecursive(nest.transform, buildingLayer);
        PATileTerrain.PABuilding buildingData = new PATileTerrain.PABuilding(
            buildingTile.keyTile.id, nest.elementType, nest.prefabName);
        tileTerrain.settings.GetCrystalBuilding(belongShuijing.tile.id).AddBuilding(buildingData);
        buildingData.belongShuijingId = belongShuijing.tile.id;
        belongShuijing.buildings.Add(nest.transform);
    }
示例#11
0
    void PaintElement(Shuijing shuijing, ref Dictionary <int, PATileTerrain.PATile> collectTiles)
    {
        shuijing.affectTiles.Clear();
        CrystalRangeConfigAsset.CrystalRangeConfig configData = null;
        foreach (var config in ConfigDataBase.instance.CrystalRangeConfigAsset.configs)
        {
            if (config.level == shuijing.level)
            {
                configData = config;
            }
        }

        if (configData == null)
        {
            return;
        }

        float   centerValue = configData.centerValue / 100f;
        float   atten       = configData.atten / 100f;
        int     rang        = 1;
        bool    outOfRange  = false;
        bool    hasValue    = false;
        Vector2 crystalPos  = new Vector2(shuijing.tile.x + 1, shuijing.tile.y + 1);

        CalTileElement(shuijing.tile, crystalPos, centerValue, atten, shuijing.elementType);
        if (!collectTiles.ContainsKey(shuijing.tile.id))
        {
            collectTiles.Add(shuijing.tile.id, shuijing.tile);
        }

        if (!shuijing.affectTiles.ContainsKey(shuijing.tile.id))
        {
            shuijing.affectTiles.Add(shuijing.tile.id, shuijing.tile);
        }
        shuijing.tile.affectShuijing = shuijing;
        while (true)
        {
            outOfRange = true;
            PATileTerrain.PATile[] tiles = tileTerrain.GetNeighboringTilesNxN(shuijing.tile, rang);
            rang += 2;
            foreach (var tile in tiles)
            {
                if (tile == null)
                {
                    continue;
                }
                hasValue = CalTileElement(tile, crystalPos, centerValue, atten, shuijing.elementType);
                if (hasValue)
                {
                    if (!collectTiles.ContainsKey(tile.id))
                    {
                        collectTiles.Add(tile.id, tile);
                    }
                    if (!shuijing.affectTiles.ContainsKey(tile.id))
                    {
                        shuijing.affectTiles.Add(tile.id, tile);
                    }
                    if (tile.affectShuijing == null)
                    {
                        tile.affectShuijing = shuijing;
                    }
                    outOfRange = false;
                }
            }
            if (outOfRange)
            {
                break;
            }
        }
    }