public static IEnumerator SetShield(BaseGameObject obj, Transform transform, float time) { GameObject go = EGHelpers.CreateSprite(transform.position, (GameManager.Instance.GetGameLevel() as GameLevel).shield, "Shield"); var sprRender = go.GetComponent <SpriteRenderer>(); var bounds = sprRender.bounds; var size = bounds.size; go.transform.localScale = new Vector3(1f, 1f, 1f); go.transform.parent = transform; obj.IsShield = true; var ienumator = EGHelpers.SetGameObjectShield(obj, time); UnityEngine.Object.Destroy(go); obj.IsShield = false; return(ienumator); }
public bool Load(FullSerializer.fsData jsIsland) { var jsIslandData = jsIsland.AsDictionary; Id = (int)jsIslandData["id"].AsInt64; var islandPos = GameLevelJsonLoader.GetPos(jsIslandData["pos"]); var size = GameLevelJsonLoader.GetSize(jsIslandData["size"]); var resIndex = jsIslandData["res"].AsInt64; Pos = islandPos; Size = size; // back var sprite = _gameLevel.spriteLevelBack[(int)resIndex]; var backObj = EGHelpers.CreateSprite(Pos, sprite, "back_" + Id, _parentTransform, false); DebugLogger.WriteInfo("Island.Load sprite.rect = " + sprite.rect.ToString()); backObj.transform.localScale = new Vector3(Size.x * 100f / sprite.rect.width, Size.y * 100f / sprite.rect.height, 1f); var sprRender = backObj.GetComponent <SpriteRenderer>(); sprRender.sortingOrder = -2; if (jsIslandData.ContainsKey("backMesgColor")) { var sBackMesgColor = jsIslandData["backMesgColor"].AsString; float[] colors = sBackMesgColor.Split <float>(','); sprRender.color = new Color(colors[0], colors[1], colors[2]); } if (jsIslandData.ContainsKey("trees")) { var jsTreeList = jsIslandData["trees"].AsList; foreach (var jsTree in jsTreeList) { var jsTreeData = jsTree.AsDictionary; var treePos = GameLevelJsonLoader.GetPos(jsTreeData["pos"]); var treeObj = EGHelpers.CreateSpriteByScript <Tree>(islandPos + treePos, _gameLevel.spriteTree, "tree", _parentTransform, GameLevel.TerrainTagName); } } return(true); }
public bool Load(FullSerializer.fsData jsBridge) { var jsBridgeData = jsBridge.AsDictionary; int beginId = (int)jsBridgeData["begin"].AsInt64; int endId = (int)jsBridgeData["end"].AsInt64; var resIndex = jsBridgeData["res"].AsInt64; if (!jsBridgeData.ContainsKey("orientation")) { return(false); } int orientation = (int)jsBridgeData["orientation"].AsInt64; if (!jsBridgeData.ContainsKey("pos")) { return(false); } //Pos = GameLevelJsonLoader.GetPos(jsBridgeData["pos"]); float width = (float)jsBridgeData["w"].AsDouble; var beginIsland = _islandList.Find(it => it.Id == beginId); var endIsland = _islandList.Find(it => it.Id == endId); if (beginIsland == null || endIsland == null) { DebugLogger.WriteError("Bridge.LoadLevel island is not found"); return(false); } Pos = Vector2.zero; if (orientation == 0) { // мост будет горизонтально Rectangle rect = beginIsland.IslandRect; Rectangle rect2 = endIsland.IslandRect; if (rect.IntersectsWith(rect2)) { DebugLogger.WriteError("Bridge.LoadLevel islands is intersects"); return(false); } Pos.y = (float)jsBridgeData["pos"].AsDouble; Rectangle leftIslandRect; Rectangle rightIslandRect; Island leftIsland; Island rightIsland; if (rect.X < rect2.X) { leftIslandRect = rect; leftIsland = beginIsland; rightIslandRect = rect2; rightIsland = endIsland; } else { leftIslandRect = rect2; leftIsland = endIsland; rightIslandRect = rect; rightIsland = beginIsland; } Pos.x = (leftIsland.Pos.x + rightIsland.Pos.x) / 2; /*if (Pos.x > rightIsland.Pos.x || Pos.x < leftIsland.Pos.x) { * DebugLogger.WriteError("Bridge.LoadLevel horizontal bridge of islands is impossible create"); * return false; * }*/ leftIsland.Bridges.AddBridge(Island.Side.Right, this); rightIsland.Bridges.AddBridge(Island.Side.Left, this); Size = new Vector2(rightIslandRect.Left - leftIslandRect.Right, width); CreateVBorders(Pos, new Vector2(Size.x, Thickness)); } else { // мост будет вертикально Rectangle rect = beginIsland.IslandRect; Rectangle rect2 = endIsland.IslandRect; if (rect.IntersectsWith(rect2)) { DebugLogger.WriteError("Bridge.LoadLevel islands is intersects"); return(false); } Pos.x = (float)jsBridgeData["pos"].AsDouble; Rectangle topIslandRect; Rectangle bottomIslandRect; Island topIsland; Island bottomIsland; if (rect.Y > rect2.Y) { topIslandRect = rect; topIsland = beginIsland; bottomIslandRect = rect2; bottomIsland = endIsland; } else { topIslandRect = rect2; topIsland = endIsland; bottomIslandRect = rect; bottomIsland = beginIsland; } Pos.y = (topIsland.Pos.y + bottomIsland.Pos.y) / 2; /*if (Pos.y < bottomIsland.Pos.y || Pos.y > topIsland.Pos.y) { * DebugLogger.WriteError("Bridge.LoadLevel vertical bridge of islands is impossible create"); * return false; * }*/ topIsland.Bridges.AddBridge(Island.Side.Bottom, this); bottomIsland.Bridges.AddBridge(Island.Side.Top, this); Size = new Vector2(width, topIslandRect.Bottom - bottomIslandRect.Top); CreateHBorders(Pos, new Vector2(Thickness, Size.y)); } // back var sprite = _gameLevel.spriteLevelBack[(int)resIndex]; DebugLogger.WriteInfo("Bridge.LoadLevel Pos = {0}; Size = {1}", Pos.ToString(), Size.ToString()); var backObj = EGHelpers.CreateSprite(Pos, sprite, "bridgeback_" + Id, _parentTransform, false); backObj.transform.localScale = new Vector3(Size.x * 100f / sprite.rect.width, Size.y * 100f / sprite.rect.height, 1f); var sprRender = backObj.GetComponent <SpriteRenderer>(); sprRender.sortingOrder = -1; return(true); }