ToString() public method

public ToString ( ) : string
return string
Ejemplo n.º 1
0
        static public void CreateArray()
        {
            CacheSortingLayers();

            List <GameObject> GameObjects = new List <GameObject>();

            Self.m_TilemapSize = new IntVector2(0, 0);

            GameObjects.AddRange(GameObject.FindGameObjectsWithTag("GameTile").OrderBy(gameObject => GetSortingLayerOrder(gameObject.GetComponent <SpriteRenderer>().sortingLayerName)).ToList());

            int LowestX = 0, HighestX = 0;
            int LowestY = 0, HighestY = 0;

            foreach (GameObject gameObject in GameObjects)
            {
                Vector3 <int> ObjectGridPosition = new Vector3 <int>((int)GetGridPosition(gameObject.transform.position).x, (int)GetGridPosition(gameObject.transform.position).y, 0);

                if (ObjectGridPosition.x < LowestX)
                {
                    LowestX = ObjectGridPosition.x;
                }
                if (ObjectGridPosition.x > HighestX)
                {
                    HighestX = ObjectGridPosition.x;
                }

                if (ObjectGridPosition.y < LowestY)
                {
                    LowestY = ObjectGridPosition.y;
                }
                if (ObjectGridPosition.y > HighestY)
                {
                    HighestY = ObjectGridPosition.y;
                }
            }
            Self.m_TilemapOffset = new IntVector2(LowestX, LowestY);
            Self.m_TilemapSize   = new IntVector2(Math.Abs(HighestX - LowestX) + 1, Math.Abs(HighestY - LowestY) + 1);

            Self.m_Tiles = new Dictionary <string, List <GameObject> >();
            foreach (GameObject gameObject in GameObjects)
            {
                IntVector2 ArrayIndex = GetArrayIndex(gameObject);
                if (!Self.m_Tiles.ContainsKey(ArrayIndex.ToString()))
                {
                    Self.m_Tiles[ArrayIndex.ToString()] = new List <GameObject>();
                }

                Self.m_Tiles[ArrayIndex.ToString()].Add(gameObject);
            }
        }
Ejemplo n.º 2
0
        public ChunkBuilder GetBuilderAtPosition(IntVector2 worldPosition)
        {
            if (!_chunkBuildersByWorldPosition.TryGetValue(worldPosition, out var builder))
            {
                if (GameSaves.HasGameData(worldPosition.ToString() + "B"))
                {
                    builder = LoadBuilder(worldPosition);
                }
                else if (!GameSaves.HasGameData(worldPosition.ToString()))
                {
                    builder = AddBuilder(worldPosition);
                }
            }

            return(builder);
        }
 void sendEventOnResolutionChange(IntVector2 resolution, Vector2 scale)
 {
     Debug2.LogDebug("sendEventOnResolutionChange  resolution = " + resolution.ToString() + "   scale =" + scale);
     if (onResolutionChange != null)
     {
         onResolutionChange(resolution, scale);
     }
 }
Ejemplo n.º 4
0
 public void ChangeState(State state, IntVector2 block)
 {
     if (block.x < GRID_SIZE_X && block.y < GRID_SIZE_Y && grid[block.x, block.y] != null)
     {
         grid[block.x, block.y] = state;
     }
     else
     {
         Debug.LogError("Cannot change state because" + block.ToString() + " doesn't exist in grid");
     }
 }
Ejemplo n.º 5
0
    public override string ToString()
    {
        string result = "from " + originalPosition.ToString() + " to " + destinyPosition.ToString();

        if (hasCapturedAnEnemy())
        {
            result += " Capturing in " + this.capturedPiece.ToString();
        }

        return(result);
    }
Ejemplo n.º 6
0
        private ChunkBuilder LoadBuilder(IntVector2 worldPosition)
        {
            var serializedBuilder   = DataReader.Read(worldPosition.ToString() + "B", DataTypes.CurrentGame);
            var serializableBuilder = SerializableChunkBuilder.Deserialize(serializedBuilder);

            var chunkBuilder = serializableBuilder.ToObject();

            Register(chunkBuilder);

            return(chunkBuilder);
        }
Ejemplo n.º 7
0
        private Chunk LoadChunk(IntVector2 worldPosition)
        {
            var serializedChunk   = DataReader.Read(worldPosition.ToString(), DataTypes.CurrentGame);
            var serializableChunk = SerializableChunk.Deserialize(serializedChunk);

            var chunk = serializableChunk.ToObject();
            var chunkActivationCommand = new ChunkActivationCommand(chunk, serializableChunk.ReconstructCoroutine);

            _chunkActivationCommands.Enqueue(chunkActivationCommand);

            return(chunk);
        }
Ejemplo n.º 8
0
    public void SetBlockId(int blockId)
    {
        if (mBlockId == blockId)
        {
            return;
        }
        mBlockId = blockId;

        mBlockCoord     = MapDataManager.BlockIdToBlockCoord(mBlockId);
        mZeroCoord      = MapDataManager.BlockIdToBlockZeroTileCoord(mBlockId);
        gameObject.name = mBlockCoord.ToString();

        transform.localPosition = MapLayout.Instance.GetBlockPos(mBlockCoord.x, mBlockCoord.y);

        DestroyBackground();
        InitBackground();
        DestroyTiles();
        InitTiles();
    }
Ejemplo n.º 9
0
        private void CreateChunk(IntVector2 worldPosition)
        {
            if (GetNearestChunkPosition(worldPosition) != worldPosition)
            {
                throw new InvalidOperationException($"Chunk cannot be spawned at {worldPosition}.");
            }

            if (_chunksByWorldPosition.ContainsKey(worldPosition))
            {
                return;
            }
            else
            {
                Chunk chunk;

                if (GameSaves.HasGameData(worldPosition.ToString()))
                {
                    _log.Info($"Loading Chunk at {worldPosition}.");
                    chunk = LoadChunk(worldPosition);
                }
                else
                {
                    _log.Info($"Building Chunk at {worldPosition}.");
                    chunk = BuildChunk(worldPosition);
                }

                Register(chunk);

                if (_chunkConstructionCoroutine == null)
                {
                    _chunkConstructionCoroutine = StartCoroutine(ChunkConstructionCoroutine());
                }

                foreach (var direction in Directions.Cardinals)
                {
                    if (_chunkBuildersByWorldPosition.TryGetValue(worldPosition + direction, out var neighborBuilder))
                    {
                        _spaceArchitect.CheckForSpaces(neighborBuilder);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        int CreateEffect(CampType casterCampType, IntVector2 effectPos, short effectId, int targetUnitId, short effectAngler, short param1, short param2)
        {
            UnityEngine.Debug.Log("創建技能效果 " + casterCampType.ToString() + " " + effectPos.ToString() + " " + effectAngler + " " + param1 + " " + param2);
            GDSKit.SkillEffect effectConfig = GDSKit.SkillEffect.GetInstance(effectId);

            SkillEffectBase createEffect = null;

            switch ((SkillEffectType)effectConfig.type)
            {
            case SkillEffectType.ChgAttr:
                createEffect = new SkillAttrChgEffect();
                break;

            default:
                throw new System.NotImplementedException("未实现的技能效果类型 " + effectConfig.type);
            }
            mEffectDic[createEffect.iD] = createEffect;
            createEffect.SetInfo(effectConfig, effectPos, targetUnitId, effectAngler, param1, param2, casterCampType);
            createEffect.BeginWork();
            BattleFiled.Instance.OnCreateEffect(effectId, effectPos);
            return(createEffect.iD);
        }
Ejemplo n.º 11
0
 void FindPathOnGUI()
 {
     if (GUILayout.Button("选择起点"))
     {
         mState = FindPathState.SelectStart;
     }
     if (GUILayout.Button("选择终点"))
     {
         mState = FindPathState.SelectEnd;
     }
     if (MapDataManager.Instance.IsValidTileCoord(mFindPathStart.x, mFindPathStart.y) &&
         MapDataManager.Instance.IsValidTileCoord(mFindPathEnd.x, mFindPathEnd.y))
     {
         if (GUILayout.Button("寻路"))
         {
             mState = FindPathState.Finding;
             using (new PerformTimer("寻找路径")) {
                 List <IntVector2> findPathList = AStarManager.Instance.FindPath(mFindPathStart, mFindPathEnd);
                 if (null != findPathList)
                 {
                     System.Text.StringBuilder pathSb = new System.Text.StringBuilder();
                     for (int i = 0; i < findPathList.Count; ++i)
                     {
                         pathSb.Append(findPathList [i].ToString());
                         if (i != findPathList.Count - 1)
                         {
                             pathSb.Append("->");
                         }
                     }
                     ShowPath(findPathList);
                 }
                 else
                 {
                     Debug.LogError("未找到从 " + mFindPathStart.ToString() + " 到 " + mFindPathEnd.ToString() + " 的路径");
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
 void sendEventOnResolutionChange(IntVector2 resolution, Vector2 scale)
 {
     Debug2.LogDebug("sendEventOnResolutionChange  resolution = "+resolution.ToString()+"   scale ="+scale);
     if (onResolutionChange!=null)
         onResolutionChange(resolution,scale);
 }
Ejemplo n.º 13
0
    [Test] public void GetNeighbor()
    {
        int x = 0;
        int y = 0;
        int z = 0;

        for (int direction = 0; direction < 6; direction++)
        {
            IntVector2 expected = Grid.GetAxialDirection(direction);
            string     message  = string.Format("[4x3 Hexagon] Incorrect neighbor (@({0}, {1})  direction = {2})", x, z, direction);

            Assert.AreEqual(testHexagonGrid4x3.GetNeighbor(x, z, direction).ToString(), expected.ToString(), "GetNeighbor(x, y, direction)\n" + message);
            Assert.AreEqual(testHexagonGrid4x3.GetNeighbor(new IntVector2(x, z), direction).ToString(), expected.ToString(), "GetNeighbor((x, y), direction)\n" + message);
            Assert.AreEqual(testHexagonGrid4x3.GetNeighbor(x, y, z, direction).ToString(), expected.ToString(), "GetNeighbor(x, y, z, direction)\n" + message);
            Assert.AreEqual(testHexagonGrid4x3.GetNeighbor(new IntVector3(x, y, z), direction).ToString(), expected.ToString(), "GetNeighbor((x, y, z), direction)\n" + message);
        }
    }
Ejemplo n.º 14
0
    bool recursivePathFind(IntVector2 currentPos, IntVector2 endPos, List <IntVector2> path, List <IntVector2> bestPath)
    {
        if (currentPos == endPos)
        {
            if (path.Count < bestPath.Count)
            {
                bestPath = path;
            }
            return(true);
        }
        if (path.Count > 0 && bestPath.Count > 0 && path.Count >= bestPath.Count)
        {
            return(false);
        }
        if (path.Count > 0 && bestPath.Count > 0 && mTiles[currentPos.x][currentPos.y].distance >= path.Count)
        {
            return(false);
        }
        mTiles[currentPos.x][currentPos.y].distance = path.Count;
        Debug.Log("LOOKING FOR PATH " + currentPos.ToString() + " " + endPos.ToString());

        mTiles[currentPos.x][currentPos.y].gameObject.GetComponent <SpriteRenderer>().color = new Color(0, 0, 1);


        IntVector2 p   = new IntVector2(currentPos.x, currentPos.y);
        IntVector2 def = new IntVector2();

        p.x = currentPos.x - 1;
        p.y = currentPos.y;
        //Debug.Log("_______________________________________________________________________________");
        //Debug.Log("Current path is: ");
        //for(int i = 0; i < path.Count; ++i)
        //{
        //    Debug.Log(path[i]);
        //}
        Debug.Log("Checking left point " + p + " in grid. I can place: " + IsEmpty(p.x, p.y) + " And this does exist in the path already: " + IntVecListContains(path, p));
        if (IsEmpty(p.x, p.y) && IntVecListContains(path, p) == false)
        {
            Debug.Log("Left");
            //Debug.Log("CHECKING A THING");
            path.Add(p);
            if (recursivePathFind(new IntVector2(p.x, p.y), endPos, path, bestPath))
            {
                return(true);
            }
            path.RemoveAt(path.Count - 1);
        }

        p.x = currentPos.x;
        p.y = currentPos.y - 1;
        Debug.Log("Checking down point " + p + " in grid. I can place: " + IsEmpty(p.x, p.y) + " And this does exist in the path already: " + IntVecListContains(path, p));
        if (IsEmpty(p.x, p.y) && IntVecListContains(path, p) == false)
        {
            Debug.Log("down");
            //Debug.Log("CHECKING A THING");
            path.Add(p);
            if (recursivePathFind(p, endPos, path, bestPath))
            {
                return(true);
            }
            path.RemoveAt(path.Count - 1);
        }

        p.x = currentPos.x + 1;
        p.y = currentPos.y;
        Debug.Log("Checking right point " + p + " in grid. I can place: " + IsEmpty(p.x, p.y) + " And this does exist in the path already: " + IntVecListContains(path, p));
        if (IsEmpty(p.x, p.y) && IntVecListContains(path, p) == false)
        {
            Debug.Log("Right");
            //Debug.Log("CHECKING A THING");
            path.Add(p);
            if (recursivePathFind(p, endPos, path, bestPath))
            {
                return(true);
            }
            path.RemoveAt(path.Count - 1);
        }

        p.x = currentPos.x;
        p.y = currentPos.y + 1;
        Debug.Log("Checking up point " + p + " in grid. I can place: " + IsEmpty(p.x, p.y) + " And this does exist in the path already: " + IntVecListContains(path, p));
        if (IsEmpty(p.x, p.y) && IntVecListContains(path, p) == false)
        {
            Debug.Log("up");
            //Debug.Log("CHECKING A THING");
            path.Add(p);
            if (recursivePathFind(p, endPos, path, bestPath))
            {
                return(true);
            }
            path.RemoveAt(path.Count - 1);
        }
        return(false);
    }
Ejemplo n.º 15
0
        public Tile(Region region, TileState state, IntVector2 coord) : base($"{region.Name}, Tile {coord.ToString()}")
        {
            this.region = region;
            this.coord  = coord;

            _state = state;

            _view = new TileView(this, SpriteAtlasManager.Get(1));
            AddChild(_view);
        }