コード例 #1
0
 /// <summary>
 /// Sends an update to the adjacency connector one neigbouring object.
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="placedNeighbour"></param>
 public void UpdateSingleAdjacency(Direction dir, PlacedTileObject placedNeighbour)
 {
     if (adjacencyConnector != null)
     {
         adjacencyConnector.UpdateSingle(dir, placedNeighbour);
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates a new PlacedTileObject from a TileObjectSO at a given position and direction. Uses NetworkServer.Spawn() if a server is running.
        /// </summary>
        /// <param name="worldPosition"></param>
        /// <param name="origin"></param>
        /// <param name="dir"></param>
        /// <param name="tileObjectSO"></param>
        /// <returns></returns>
        public static PlacedTileObject Create(Vector3 worldPosition, Vector2Int origin, Direction dir, TileObjectSO tileObjectSO)
        {
            GameObject placedGameObject = EditorAndRuntime.InstantiatePrefab(tileObjectSO.prefab);

            placedGameObject.transform.SetPositionAndRotation(worldPosition, Quaternion.Euler(0, TileHelper.GetRotationAngle(dir), 0));

            // Alternative name is required for walls as they can occupy the same tile
            if (TileHelper.ContainsSubLayers(tileObjectSO.layer))
            {
                placedGameObject.name += "_" + TileHelper.GetDirectionIndex(dir);
            }

            PlacedTileObject placedObject = placedGameObject.GetComponent <PlacedTileObject>();

            if (placedObject == null)
            {
                placedObject = placedGameObject.AddComponent <PlacedTileObject>();
            }

            placedObject.Setup(tileObjectSO, origin, dir);

            if (NetworkServer.active)
            {
                if (!NetworkClient.prefabs.ContainsValue(placedGameObject))
                {
                    Debug.LogWarning("Prefab was not found in the Spawnable list. Please add it.");
                }
                NetworkServer.Spawn(placedGameObject);
            }
            return(placedObject);
        }
コード例 #3
0
 /// <summary>
 /// Sets a PlacedObject on the TileObject.
 /// </summary>
 /// <param name="placedObject"></param>
 /// <param name="subLayerIndex">Which sublayer to place the object</param>
 public void SetPlacedObject(PlacedTileObject placedObject, int subLayerIndex)
 {
     placedObjects[subLayerIndex] = placedObject;
     map.TriggerGridObjectChanged(x, y);
 }