private void StartFade(SceneDescription newScene, Fade fadeIn, Fade fadeOut, float delay = 0) { if (this.IsFading) { FlaiDebug.LogWarningWithTypeTag <SceneFader>("Can't start a new fade. There is already another fade in progress", this); return; } else if (this.IsFadeDelayRunning) { FlaiDebug.LogWarningWithTypeTag <SceneFader>("Can't start a new fade. There is already another fade pending (delay: " + _fadeDelay.Value + "}", this); return; } Ensure.NotNull(fadeIn, "'fadeIn' cannot be null. Use Fade.None instead"); Ensure.NotNull(fadeOut, "'fadeOut' cannot be null. Use Fade.None instead"); _fadeIn = fadeIn; _fadeOut = fadeOut; _newScene = newScene; _fadeDelay = (delay == 0) ? default(float?) : delay; if (!_fadeDelay.HasValue) { this.BeginFading(); } }
private void CreateTile(List <Vector3> vertices, List <int> triangles, List <Vector2> uvs, int x, int y, int tile, TilesetManager tilesetManager) { // coordinates start from top-left, remember vertices.Add(new Vector2f(x, y)); // TL vertices.Add(new Vector2f(x + 1, y)); // TR vertices.Add(new Vector2f(x, y + 1)); // BL vertices.Add(new Vector2f(x, y + 1)); // BL vertices.Add(new Vector2f(x + 1, y)); // TR vertices.Add(new Vector2f(x + 1, y + 1)); // BR for (int i = 0; i < 6; i++) { triangles.Add(triangles.Count); } Sprite sprite = TilemapSpriteManager.Instance.GetSprite(tilesetManager, tile); if (sprite == null) { FlaiDebug.LogErrorWithTypeTag <Tilemap>("Error - No Sprite found in TilemapSpriteManager"); return; } RectangleF uv = sprite.textureRect.ToRectangleF() * sprite.texture.texelSize; uvs.Add(uv.TopLeft); uvs.Add(uv.TopRight); uvs.Add(uv.BottomLeft); uvs.Add(uv.BottomLeft); uvs.Add(uv.TopRight); uvs.Add(uv.BottomRight); }
private static TilesetManager CreateTilesetManager(TmxData tmxData) { return(new TilesetManager(tmxData.TmxTilesets.Select(ts => { FlaiDebug.Log("!" + ts.ImageSize.Width + " " + ts.ImageSize.Height); Ensure.True(ts.TileSize.Width == ts.TileSize.Height); return new Tileset(ts.Name, ts.FirstGlobalTileID, ts.TileSize.Width, Path.GetFileNameWithoutExtension(ts.ImagePath), ts.ImageSize.Width, ts.ImageSize.Height); }).ToArray())); }
protected override void Awake() { var renderer = this.renderer; if (renderer == null) { FlaiDebug.LogWarningWithTypeTag <SortingOrderSetter>("Renderer is null"); } else { renderer.sortingOrder = this.SortingOrder; } }
private void FindMissingScripts() { GameObject[] gameObjects = Selection.gameObjects; bool any = false; foreach (GameObject gameObject in gameObjects) { this.FindMissingScriptsRecursive(gameObject, ref any); } if (!any) { FlaiDebug.Log("No missing scripts found!"); } }
private void DrawMethod(MethodInfo method, ShowInInspectorAttribute attribute) { if (method.ContainsGenericParameters || method.GetParameters().Length > 0) { FlaiDebug.LogWarningWithTypeTag <DefaultInspector>("Method '{0}' has parameters or generic parameters. It cannot be called", method.Name); return; } FlaiGUI.PushGuiEnabled(!attribute.IsReadOnly && (attribute.IsEditableWhenNotPlaying || Application.isPlaying)); if (GUILayout.Button(this.GetName(method.Name, attribute))) { method.Invoke(this.Target, null); } FlaiGUI.PopGuiEnabled(); }
public void OnMapUpdated() { Ensure.IsEditor(); this.GameObject.DestroyAllChildrenImmediate(); // if the map was removed, then no need to create a new map if (this.TmxAsset == null || this.Tilemaps == null || this.Tilemaps.Count == 0) { return; } if (this.TilemapPrefab == null) { FlaiDebug.LogErrorWithTypeTag <TilemapContainer>("TilemapPrefab is null - aborting!"); return; } foreach (TilemapData data in this.Tilemaps) { FlaiDebug.LogWithTypeTag <TilemapContainer>("Building a tilemap \"{2}\" ({0}x{1})", data.Width, data.Height, data.Name); GameObject tilemap = this.TilemapPrefab.Instantiate(); if (data.HasProperty("CreateColliders")) { bool value; if (bool.TryParse(data.GetProperty("CreateColliders"), out value)) { tilemap.Get <Tilemap>().CreateColliders = value; } } tilemap.name = data.Name.NullIfEmpty() ?? "Tilemap"; tilemap.SetParent(this.GameObject); tilemap.SetLayer("Tiles"); try { tilemap.Get <Tilemap>().CreateFrom(data, this.TmxAsset.TilesetManager); } catch { FlaiDebug.LogErrorWithTypeTag <TilemapContainer>("Error - Aborting"); throw; } this.TmxAsset.NeedsRefresh = false; } }
private Texture2D LoadTexture(string tileset) { tileset = tileset.Trim(); Texture2D texture; if (!_tilesetTextures.TryGetValue(tileset, out texture) || texture == null) { texture = Resources.Load <Texture2D>(tileset); _tilesetTextures.AddOrSetValue(tileset, texture); if (texture == null) { FlaiDebug.LogWarningWithTypeTag <TilemapSpriteManager>("Couldn't find tileset texture {0}", tileset); } } return(texture); }
private void DrawMapDataField() { TilemapContainer tilemap = this.Target; TmxAsset tmxAsset = (TmxAsset)EditorGUILayout.ObjectField("Map Data", tilemap.TmxAsset, typeof(TmxAsset), false); if (tilemap.TmxAsset != null && tmxAsset == null) { FlaiDebug.LogWithTypeTag <TilemapContainerInspector>("Map Data set null!"); } if (tilemap.TmxAsset != tmxAsset || (tilemap.TmxAsset != null && tilemap.TmxAsset.NeedsRefresh)) { tilemap.TmxAsset = tmxAsset; tilemap.OnMapUpdated(); EditorUtility.SetDirty(tilemap); } }
protected static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath) { if (importedAssets == null) { return; } foreach (string tilemapAsset in importedAssets.Where(asset => asset != null && asset.EndsWith(".tmx"))) { if (tilemapAsset == null) { continue; } const string TilemapPath = "Assets/Tile Maps/Maps/"; string fileName = Path.GetFileNameWithoutExtension(tilemapAsset); string finalPath = Path.Combine(TilemapPath, fileName) + ".asset"; // ensure that the directory exists Directory.CreateDirectory(TilemapPath); TmxAsset tmxAsset = TilemapLoader.LoadTilemap(tilemapAsset); TmxAsset previous = (TmxAsset)AssetDatabase.LoadAssetAtPath(finalPath, typeof(TmxAsset)); if (previous != null) { previous.CopyFrom(tmxAsset); FlaiDebug.LogWithTypeTag <TilemapImporter>("Tilemap {0} updated!", fileName); EditorUtility.SetDirty(previous); } else { AssetDatabase.CreateAsset(tmxAsset, finalPath); EditorUtility.SetDirty(tmxAsset); FlaiDebug.LogWithTypeTag <TilemapImporter>("Tilemap {0} imported succesfully!", fileName); } TilemapImporter.SaveTilemapFile(tilemapAsset); AssetDatabase.DeleteAsset(tilemapAsset); } AssetDatabase.Refresh(); AssetDatabase.SaveAssets(); }
public void Create() { if (this.TilemapData == null) { FlaiDebug.LogErrorWithTypeTag <Tilemap>("Error creating a Tilemap: TilemapData is null!"); return; } if (this.TilesetManager == null) { FlaiDebug.LogErrorWithTypeTag <Tilemap>("Error creating a Tilemap: TilesetManager is null!"); return; } try { this.CreateMesh(); } catch { FlaiDebug.LogErrorWithTypeTag <Tilemap>("Error Creating Mesh - aborting"); throw; } foreach (EdgeCollider2D collider in this.GetComponents <EdgeCollider2D>()) { Component.Destroy(collider); } if (this.CreateColliders) { try { this.CreateEdgeColliders(); } catch { FlaiDebug.LogErrorWithTypeTag <Tilemap>("Error Creating Colliders - aborting"); throw; } } }
protected override void Update() { float changeInUnitsScale = (this.Scale2D.Y - _previousScaleY) * _scaleMultiplier; float changeInUnitsPosition = (this.Position2D.Y - _previousPositionY); float changeInUnits = changeInUnitsScale + changeInUnitsPosition; _gameObjectsOnTop.RemoveWhere(go => go == null); _gameObjectsOnTop.RemoveWhere(go => !PhysicsHelper.Intersects(this.collider2D, go.collider2D, 0.2f)); foreach (GameObject other in _gameObjectsOnTop) { other.SetPosition2D(other.GetPosition2D() + Vector2f.UnitY * changeInUnits); } _previousScaleY = this.Scale.y; _previousPositionY = this.Position2D.Y; if (this.DrawDebug) { FlaiDebug.DrawRectangleOutlines(this.collider2D.GetBoundsHack()); } }