private void Walk(DynValue eventLua, DynValue steps, DynValue directionLua, DynValue waitLua) { if (eventLua.Type == DataType.String) { var @event = Global.Instance().Maps.ActiveMap.GetEventNamed(eventLua.String); if (@event == null) { Debug.LogError("Couldn't find event " + eventLua.String); } else { var routine = @event.StepMultiRoutine(OrthoDirExtensions.Parse(directionLua.String), (int)steps.Number); if (!waitLua.IsNil() && waitLua.Boolean) { RunRoutineFromLua(routine); } else { @event.StartCoroutine(routine); } } } else { var function = eventLua.Table.Get("walk"); function.Function.Call(steps, directionLua, waitLua); } }
public void Populate(IDictionary <string, string> properties) { if (properties.ContainsKey(PropertyFacing)) { initialFacing = OrthoDirExtensions.Parse(properties[PropertyFacing]); facing = initialFacing; } if (properties.ContainsKey(PropertySprite)) { if (GetComponent <MapEvent3D>() != null) { doll = new GameObject("Doll"); doll.transform.parent = gameObject.transform; doll.transform.localPosition = new Vector3(0.5f, 0.0f, -0.5f); animator = doll.AddComponent <CharaAnimator>(); animator.parentEvent = GetComponent <MapEvent>(); } else { animator = gameObject.AddComponent <CharaAnimator>(); } animator.SetSpriteByKey(properties[PropertySprite]); animator.Populate(properties); } GetComponent <MapEvent>().Passable = false; }
private void TargetTeleport(DynValue mapName, DynValue targetEventName, DynValue facingLua, DynValue rawLua) { OrthoDir?facing = null; if (!facingLua.IsNil()) { facing = OrthoDirExtensions.Parse(facingLua.String); } var raw = rawLua.IsNil() ? false : rawLua.Boolean; RunRoutineFromLua(Global.Instance().Maps.TeleportRoutine(mapName.String, targetEventName.String, facing, raw)); }
private void PaintTileIfNeeded() { TacticsTerrainMesh terrain = (TacticsTerrainMesh)target; foreach (TerrainQuad quad in selectedQuads) { if (quad.normal.y > 0.0f) { int originX = (int)primarySelection.pos.x - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f); int originY = (int)primarySelection.pos.z - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f); Tile tile = TileForSelection((int)(quad.pos.x - originX), (int)(quad.pos.z - originY)); UpdateTile(quad, tile); } else { Tile tile; if (quad.normal.x != 0.0f) { int originX = (int)primarySelection.pos.z - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f); int originY = (int)primarySelection.pos.y - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f); tile = TileForSelection((int)(quad.pos.z - originX), (int)(quad.pos.y - originY)); } else { int originX = (int)primarySelection.pos.x - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.x) / 2.0f); int originY = (int)primarySelection.pos.y - Mathf.FloorToInt(Mathf.RoundToInt(selectionSize.y) / 2.0f); tile = TileForSelection((int)(quad.pos.x - originX), (int)(quad.pos.y - originY)); } if (wraparoundPaintMode) { foreach (OrthoDir dir in Enum.GetValues(typeof(OrthoDir))) { UpdateTile(quad, dir, tile); } } else { UpdateTile(quad, OrthoDirExtensions.DirectionOf3D(quad.normal), tile); } } } RepaintMesh(); primarySelection = GetSelectedQuad(); CaptureSelection(primarySelection); PrefabStage prefabStage = PrefabStageUtility.GetPrefabStage(terrain.gameObject); if (prefabStage != null) { EditorSceneManager.MarkSceneDirty(prefabStage.scene); } }
public void Populate(IDictionary <string, string> properties) { if (properties.ContainsKey(PropertyFacing)) { InitialFacing = OrthoDirExtensions.Parse(properties[PropertyFacing]); Facing = InitialFacing; } if (properties.ContainsKey(PropertySprite)) { gameObject.AddComponent <CharaAnimator>().Populate(properties[PropertySprite]); } GetComponent <MapEvent>().Passable = false; }
public IEnumerator PathToRoutine(IntVector2 location) { List <IntVector2> path = Parent.FindPath(this, location); if (path == null) { yield break; } foreach (IntVector2 target in path) { yield return(StartCoroutine(StepRoutine(OrthoDirExtensions.DirectionOf(target - GetComponent <MapEvent>().Position)))); } }
private OrthoDir DirectionRelativeToCamera() { MapCamera cam = Application.isPlaying ? Global.Instance().Maps.camera : FindObjectOfType <MapCamera>(); Vector3 ourScreen = cam.cam.WorldToScreenPoint(transform.position); Vector3 targetWorld = ((MapEvent3D)parent).TileToWorldCoords(parent.location + facing.XY()); targetWorld.y = parent.transform.position.y; Vector3 targetScreen = cam.cam.WorldToScreenPoint(targetWorld); Vector3 delta = targetScreen - ourScreen; return(OrthoDirExtensions.DirectionOf2D(new Vector2(delta.x, -delta.y))); }
private void Face(DynValue eventName, DynValue dir) { var @event = Global.Instance().Maps.ActiveMap.GetEventNamed(eventName.String); if (@event == null) { Debug.LogError("Couldn't find event " + eventName.String); } else { @event.GetComponent <CharaEvent>().Facing = OrthoDirExtensions.Parse(dir.String); } }
private void Teleport(DynValue mapName, DynValue x, DynValue y, DynValue facingLua, DynValue rawLua) { OrthoDir?facing = null; if (!facingLua.IsNil()) { facing = OrthoDirExtensions.Parse(facingLua.String); } var loc = new Vector2Int((int)x.Number, (int)y.Number); var raw = rawLua.IsNil() ? false : rawLua.Boolean; RunRoutineFromLua(Global.Instance().Maps.TeleportRoutine(mapName.String, loc, facing, raw)); }
private OrthoDir CalculateDirection() { OrthoDir normalDir = Parent().GetComponent <CharaEvent>().facing; MapCamera cam = Application.isPlaying ? Global.Instance().Maps.Camera : FindObjectOfType <MapCamera>(); if (!cam || !dynamicFacing) { return(normalDir); } Vector3 ourScreen = cam.GetCameraComponent().WorldToScreenPoint(parentEvent.transform.position); Vector3 targetWorld = MapEvent3D.TileToWorldCoords(parentEvent.positionXY + normalDir.XY()); Vector3 targetScreen = cam.GetCameraComponent().WorldToScreenPoint(targetWorld); Vector3 delta = targetScreen - ourScreen; return(OrthoDirExtensions.DirectionOf(new Vector2(delta.x, -delta.y))); }
public IEnumerator StepRoutine(OrthoDir dir) { if (Tracking) { yield break; } Tracking = true; MapEvent mapEvent = GetComponent <MapEvent>(); mapEvent.Position += dir.XY(); TargetPosition = mapEvent.PositionPx + Vector2.Scale(dir.PxXY(), Map.TileSizePx); Facing = OrthoDirExtensions.DirectionOfPx(TargetPosition - mapEvent.PositionPx); while (true) { mapEvent.PositionPx = Vector2.MoveTowards((mapEvent.PositionPx + movementSlop), TargetPosition, PixelsPerSecond * Time.deltaTime); movementSlop.Set(mapEvent.PositionPx.x - (float)Mathf.Floor(mapEvent.PositionPx.x), mapEvent.PositionPx.y - (float)Mathf.Floor(mapEvent.PositionPx.y)); mapEvent.PositionPx = mapEvent.PositionPx - movementSlop; if (Global.Instance().Maps.Camera.Target == GetComponent <MapEvent>()) { Global.Instance().Maps.Camera.ManualUpdate(); } if (mapEvent.PositionPx == TargetPosition) { Tracking = false; break; } else { yield return(null); } } }
public void cs_walk(string directionName, int count) { Global.Instance().Lua.RunRoutineFromLua(mapEvent.GetComponent <CharaEvent>().StepMultiRoutine(OrthoDirExtensions.Parse(directionName), count)); }
public void cs_step(string directionName) { context.RunRoutineFromLua(mapEvent.GetComponent <MapEvent>().StepRoutine(OrthoDirExtensions.Parse(directionName))); }
public void cs_walk(string directionName, int count) { context.RunRoutineFromLua(mapEvent.GetComponent <MapEvent>().StepMultiRoutine(OrthoDirExtensions.Parse(directionName), count)); }
public override void TmxAssetImported(TmxAssetImportedArgs args) { var map = args.ImportedSuperMap; var tsxMap = map.gameObject.AddComponent <TsxMap>(); tsxMap.grid = map.gameObject.GetComponentInChildren <Grid>(); var objectLayer = map.gameObject.GetComponentInChildren <SuperObjectLayer>(); if (objectLayer == null) { return; } tsxMap.objectLayer = objectLayer.gameObject.AddComponent <ObjectLayer>(); //foreach (var layer in tsxMap.layers) { // layer.GetComponent<TilemapRenderer>().material = materials.BackgroundMaterial; //} foreach (Transform child in objectLayer.transform) { if (child.GetComponent <SuperObject>() != null) { var tmxObject = child.GetComponent <SuperObject>(); child.gameObject.AddComponent <MapEvent2D>(); var mapEvent = child.gameObject.GetComponent <MapEvent2D>(); mapEvent.Size = new Vector2Int((int)tmxObject.m_Width / Map.PxPerTile, (int)tmxObject.m_Height / Map.PxPerTile); mapEvent.Properties = tmxObject.GetComponent <SuperCustomProperties>(); mapEvent.Position = new Vector2Int((int)tmxObject.m_X / Map.PxPerTile, (int)tmxObject.m_Y / Map.PxPerTile); var appearance = mapEvent.GetProperty(MapEvent.PropertyAppearance); if (appearance != null && appearance.Length > 0) { CharaEvent chara; Doll doll; if (mapEvent.GetComponent <FieldSpritesheetComponent>() == null) { mapEvent.gameObject.AddComponent <FieldSpritesheetComponent>(); } if (mapEvent.GetComponent <CharaEvent>() == null) { chara = mapEvent.gameObject.AddComponent <CharaEvent>(); var dollObject = (GameObject)PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath <GameObject>(DollPrefabPath)); doll = dollObject.GetComponent <Doll>(); // doll.Renderer.material = materials.ForegroundMaterial; doll.transform.SetParent(mapEvent.transform); chara.Doll = doll; } else { chara = mapEvent.GetComponent <CharaEvent>(); doll = chara.Doll; } doll.transform.localPosition = Vector3.zero; if (IndexDatabase.Instance().FieldSprites.GetDataOrNull(appearance) != null) { // it's a literal chara.SetAppearanceByTag(appearance); } else { // this should be okay... it's a lua string } var facing = mapEvent.GetProperty("face"); if (facing != null && facing.Length > 0) { chara.Facing = OrthoDirExtensions.Parse(facing); } } } } }
public OrthoDir DirTo(CellInfo cell) { return(OrthoDirExtensions.DirectionOf3D(new Vector2Int(cell.x - x, cell.y - y))); }
public override OrthoDir DirectionTo(Vector2Int position) { return(OrthoDirExtensions.DirectionOf2D(position - this.Position)); }
public void walk(string directionName, int count) { var context = Global.Instance().Maps.Lua; context.RunRoutineFromLua(mapEvent.StepMultiRoutine(OrthoDirExtensions.Parse(directionName), count)); }
private void Ladder(DynValue countLua, DynValue dirLua) { OrthoDir dir = OrthoDirExtensions.Parse(dirLua.String); RunRoutineFromLua(Global.Instance().Maps.Avatar.Event.LadderRoutine((int)countLua.Number, dir)); }
private void Diag(DynValue dirLua) { OrthoDir dir = OrthoDirExtensions.Parse(dirLua.String); RunRoutineFromLua(Global.Instance().Maps.Avatar.Event.DiagRoutine(dir)); }
public void FaceToward(IntVector2 pos) { facing = OrthoDirExtensions.DirectionOf(pos - GetComponent <MapEvent>().positionXY); }
public OrthoDir OrthoDirTo(MapEvent other) { return(OrthoDirExtensions.DirectionOf3D(location - other.location)); }
public void cs_step(string directionName) { Global.Instance().Lua.RunRoutineFromLua(mapEvent.GetComponent <CharaEvent>().StepRoutine(OrthoDirExtensions.Parse(directionName))); }
public void cs_step(string directionName) { var context = Global.Instance().Maps.Lua; context.RunRoutineFromLua(mapEvent.StepRoutine(OrthoDirExtensions.Parse(directionName))); }
// all meant to be called by proxy public void face(string directionName) { mapEvent.GetComponent <CharaEvent>().Facing = OrthoDirExtensions.Parse(directionName); }
public OrthoDir DirectionTo(MapEvent other) { return(OrthoDirExtensions.DirectionOf(other.PositionPx - PositionPx)); }