private void ShowWithUserAction(ActionString withUserString) { ActionCard.ActionType insideType = (ActionCard.ActionType)Enum.Parse(typeof(ActionCard.ActionType), withUserString.variables[0]); withUserString.variables[0] = EditorGUILayout.EnumPopup("InsideType", insideType).ToString(); ActionString moneyString = ActionString.FromString(withUserString.variables[1]); ActionString waitString = ActionString.FromString(withUserString.variables[2]); ActionString moveString = ActionString.FromString(withUserString.variables[3]); //Pomijamy indeks 4, bo jest to ActionType.WithUser switch (insideType) { case ActionCard.ActionType.Money: ShowMoneyAction(moneyString); break; case ActionCard.ActionType.Wait: ShowWaitAction(waitString); break; case ActionCard.ActionType.Move: ShowMoveAction(moveString); break; } withUserString.variables[1] = moneyString.ToString(); withUserString.variables[2] = waitString.ToString(); withUserString.variables[3] = moveString.ToString(); }
/// <summary> /// Tworzy obiekt Akcji na podstawie informacji zawartych w ActionStringu(Nazwa klasy + lista zmiennych) /// </summary> /// <param name="form">Obiekt przechowujący informacje o ActionCardzie</param> /// <returns></returns> public static ActionCard Create(ActionString form) { ActionCard card = null; switch (form.actionType) { case ActionType.Money: { MoneyAction.MoneyActor payer = (MoneyAction.MoneyActor)Enum.Parse(typeof(MoneyAction.MoneyActor), form.variables[0]); MoneyAction.MoneyActor receiver = (MoneyAction.MoneyActor)Enum.Parse(typeof(MoneyAction.MoneyActor), form.variables[1]); float value = float.Parse(form.variables[2]); card = new MoneyAction(payer, receiver, value); } break; case ActionType.Wait: { WaitAction.WaitActor target = (WaitAction.WaitActor)Enum.Parse(typeof(WaitAction.WaitActor), form.variables[0]); int rounds = int.Parse(form.variables[1]); card = new WaitAction(target, rounds); } break; case ActionType.Move: { MoveAction.Mode mode = (MoveAction.Mode)Enum.Parse(typeof(MoveAction.Mode), form.variables[0]); int byAmount = int.Parse(form.variables[1]); MoveAction.ToTarget toTarget = (MoveAction.ToTarget)Enum.Parse(typeof(MoveAction.ToTarget), form.variables[2]); int targetId = int.Parse(form.variables[3]); MoveAction.PlaceTypeTarget targetType = (MoveAction.PlaceTypeTarget)Enum.Parse(typeof(MoveAction.PlaceTypeTarget), form.variables[4]); MoveAction.MovementType movementType = (MoveAction.MovementType)Enum.Parse(typeof(MoveAction.MovementType), form.variables[5]); card = new MoveAction(mode, byAmount, toTarget, targetId, targetType, movementType); } break; case ActionType.WithUser: { ActionType insideType = (ActionType)Enum.Parse(typeof(ActionType), form.variables[0]); if (insideType != ActionType.WithUser) { ActionString insideActionString = ActionString.FromString(form.variables[(int)insideType + 1]); ActionCard insideAction = Create(insideActionString); card = new WithUserAction(insideAction); } else { Debug.LogError("Nie można zagnieżdzać typu WithUser w akcji typu WithUser"); } } break; case ActionType.Imprison: { card = new ImprisonAction(); } break; } return(card); }