public void Reconfigure(MapEvent parent, SuperTiled2Unity.Editor.TmxAssetImporter importer) { collider = parent.GetComponent <PolygonCollider2D>(); renderer = GetComponent <MeshRenderer>(); filter = GetComponent <MeshFilter>(); @event = parent.GetComponent <MapEvent>(); var props = parent.Properties; CustomProperty prop; if (props.TryGetCustomProperty(PropertyTileId, out prop)) { tileId = prop.GetValueAsInt(); } else { Debug.LogError("Bad ceiling " + parent); } if (props.TryGetCustomProperty(PropertyTileset, out prop)) { var tilesetName = prop.GetValueAsString(); var path = TilesetDirectory + "/" + tilesetName + ".png"; tilesetTexture = AssetDatabase.LoadAssetAtPath <Texture>(path); } else { Debug.LogError("Bad ceiling " + parent); } RecalculateUVs(); renderer.material = GameboyMaterialSettings.GetDefault().BackgroundMaterial; RecalculateMesh(importer); }
public LuaMapEvent(MapEvent mapEvent) { this.mapEvent = mapEvent; values = new Dictionary <string, DynValue>(); context = mapEvent.GetComponent <LuaComponent>().Context; luaValue = context.Marshal(this); context.lua.Globals["this"] = luaValue; }
public void Start() { @event.GetComponent <Dispatch>().RegisterListener(MapEvent.EventInteract, (object payload) => { OnInteract((AvatarEvent)payload); }); @event.ImpassabilityOverride = true; UpdateSprite(); }
public void SetSpriteByKey(string spriteName) { this.spriteName = spriteName; string controllerPath = "Animations/Charas/Instances/" + spriteName; RuntimeAnimatorController controller = Resources.Load <RuntimeAnimatorController>(controllerPath); GetComponent <Animator>().runtimeAnimatorController = controller; GetComponent <SpriteRenderer>().material = Resources.Load <Material>(DefaultMaterialPath); string spritePath = "Sprites/Charas/" + spriteName; Sprite[] sprites = Resources.LoadAll <Sprite>(spritePath); foreach (Sprite sprite in sprites) { if (sprite.name == spriteName + parentEvent.GetComponent <CharaEvent>().facing.DirectionName() + "Center") { GetComponent <SpriteRenderer>().sprite = sprite; break; } } }
public override void OnInspectorGUI() { MapEvent mapEvent = (MapEvent)target; if (GUI.changed) { mapEvent.SetScreenPositionToMatchTilePosition(); mapEvent.SetDepth(); } if (!mapEvent.GetComponent <CharaEvent>()) { if (GUILayout.Button("Add Chara Event")) { GameObject doll = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>(DollPath)); doll.name = mapEvent.name + " (doll)"; GameObjectUtility.SetParentAndAlign(doll, mapEvent.gameObject); CharaEvent chara = mapEvent.gameObject.AddComponent <CharaEvent>(); chara.doll = doll; mapEvent.passable = false; Undo.RegisterCreatedObjectUndo(mapEvent, "Create " + doll.name); Selection.activeObject = doll; // hardcode weirdness doll.transform.localPosition = new Vector3(Map.TileSizePx / 2, -Map.TileSizePx, 0.0f); } GUILayout.Space(25.0f); } Vector2Int newPosition = EditorGUILayout.Vector2IntField("Tiles position", mapEvent.location); if (newPosition != mapEvent.location) { mapEvent.SetLocation(newPosition); EditorUtility.SetDirty(mapEvent); } Vector2Int newSize = EditorGUILayout.Vector2IntField("Size", mapEvent.size); if (newSize != mapEvent.size) { mapEvent.SetSize(newSize); EditorUtility.SetDirty(mapEvent); } base.OnInspectorGUI(); }
// all meant to be called by proxy public void face(string directionName) { mapEvent.GetComponent <CharaEvent>().Facing = OrthoDirExtensions.Parse(directionName); }
public LuaMapEvent(MapEvent mapEvent) { this.mapEvent = mapEvent; this.context = mapEvent.GetComponent <LuaContext>(); }
public List <Vector2Int> FindPath(MapEvent actor, Vector2Int to, int maxPathLength) { if (ManhattanDistance(actor.GetComponent <MapEvent>().position, to) > maxPathLength) { return(null); } if (!actor.CanPassAt(to)) { return(null); } HashSet <Vector2Int> visited = new HashSet <Vector2Int>(); List <List <Vector2Int> > heads = new List <List <Vector2Int> >(); List <Vector2Int> firstHead = new List <Vector2Int>(); firstHead.Add(actor.GetComponent <MapEvent>().position); heads.Add(firstHead); while (heads.Count > 0) { heads.Sort(delegate(List <Vector2Int> pathA, List <Vector2Int> pathB) { int pathACost = pathA.Count + ManhattanDistance(pathA[pathA.Count - 1], to); int pathBCost = pathB.Count + ManhattanDistance(pathB[pathB.Count - 1], to); return(pathACost.CompareTo(pathBCost)); }); List <Vector2Int> head = heads[0]; heads.RemoveAt(0); Vector2Int at = head[head.Count - 1]; if (at == to) { // trim to remove the current location from the beginning return(head.GetRange(1, head.Count - 1)); } if (head.Count < maxPathLength) { foreach (OrthoDir dir in Enum.GetValues(typeof(OrthoDir))) { Vector2Int next = head[head.Count - 1]; // minor perf here, this is critical code switch (dir) { case OrthoDir.East: next.x += 1; break; case OrthoDir.North: next.y += 1; break; case OrthoDir.West: next.x -= 1; break; case OrthoDir.South: next.y -= 1; break; } if (!visited.Contains(next) && actor.CanPassAt(next) && (actor.GetComponent <CharaEvent>() == null || actor.CanPassAt(next)) && (actor.GetComponent <CharaEvent>() == null || actor.GetComponent <CharaEvent>().CanCrossTileGradient(at, next))) { List <Vector2Int> newHead = new List <Vector2Int>(head) { next }; heads.Add(newHead); visited.Add(next); } } } } return(null); }
public LuaMapEvent(MapEvent mapEvent) { this.mapEvent = mapEvent; context = mapEvent.GetComponent <LuaContext>(); luaValue = context.CreateObject(); }
public List <Vector2Int> FindPath(MapEvent actor, Vector2Int to, int maxPathLength) { if (Vector2.Distance(actor.GetComponent <MapEvent>().location, to) * Mathf.Sqrt(2) > maxPathLength) { return(null); } if (!IsChipPassableAt(layers[0], to)) { return(null); } HashSet <Vector2Int> visited = new HashSet <Vector2Int>(); List <List <Vector2Int> > heads = new List <List <Vector2Int> >(); List <Vector2Int> firstHead = new List <Vector2Int>(); firstHead.Add(actor.GetComponent <MapEvent>().location); heads.Add(firstHead); while (heads.Count > 0) { heads.Sort(delegate(List <Vector2Int> pathA, List <Vector2Int> pathB) { int pathACost = pathA.Count + ManhattanDistance(pathA[pathA.Count - 1], to); int pathBCost = pathB.Count + ManhattanDistance(pathB[pathB.Count - 1], to); return(pathACost.CompareTo(pathBCost)); }); List <Vector2Int> head = heads[0]; heads.RemoveAt(0); Vector2Int at = head[head.Count - 1]; if (at == to) { // trim to remove the current location from the beginning return(head.GetRange(1, head.Count - 1)); } if (head.Count < maxPathLength) { foreach (EightDir dir in Enum.GetValues(typeof(EightDir))) { Vector2Int next = head[head.Count - 1]; // minor perf here, this is critical code switch (dir) { case EightDir.N: next.y += 1; break; case EightDir.E: next.x += 1; break; case EightDir.S: next.y -= 1; break; case EightDir.W: next.x -= 1; break; case EightDir.NE: next.y += 1; next.x += 1; break; case EightDir.SE: next.y -= 1; next.x += 1; break; case EightDir.SW: next.y -= 1; next.x -= 1; break; case EightDir.NW: next.y += 1; next.x -= 1; break; } if (visited.Contains(next)) { continue; } if (next != to && !actor.CanPassAt(next)) { continue; } if (actor.GetComponent <BattleEvent>() != null && !actor.GetComponent <BattleEvent>().CanCrossTileGradient(at, next)) { continue; } if (next == to && Mathf.Abs(terrain.HeightAt(at) - terrain.HeightAt(to)) > BattleEvent.AttackHeightMax) { continue; } if (next != to && (GetEventAt <BattleEvent>(next) != null && GetEventAt <BattleEvent>(next).unit.IsDead())) { continue; } List <Vector2Int> newHead = new List <Vector2Int>(head) { next }; heads.Add(newHead); visited.Add(next); } } } return(null); }