コード例 #1
0
ファイル: FieldHandler.cs プロジェクト: christerk/FFBUnity
    // Update is called once per frame
    private void Update()
    {
        Players.Refresh(FFB.Instance.Model.Players);
        PushbackSquares.Refresh(FFB.Instance.Model.PushbackSquares);
        TrackNumbers.Refresh(FFB.Instance.Model.TrackNumbers);

        var ball = FFB.Instance.Model.Ball;

        if (ball != null && ball.Coordinate != null)
        {
            bool isInPlayerHands = !ball.Moving && FFB.Instance.Model.GetPlayer(ball.Coordinate) != null;
            Ball.SetActive(true);

            Ball.transform.localScale = Vector3.one * (isInPlayerHands ? 0.5f : 1f);

            float translate = isInPlayerHands ? 36f : 0f;

            var ballPos = FieldToWorldCoordinates(ball.Coordinate.X, ball.Coordinate.Y, 3f);
            ballPos.x += translate;
            ballPos.y -= translate;
            Ball.transform.localPosition = ballPos;

            //var ballRenderer = Ball.GetComponentInChildren<SpriteRenderer>();
            //Color c = ballRenderer.color;
            //c.a = ball.InPlay ? 1f : 0.7f;
            //ballRenderer.color = c;
        }
        else
        {
            Ball.SetActive(false);
        }

        var actingPlayer = FFB.Instance.Model.GetPlayer(FFB.Instance.Model.ActingPlayer.PlayerId);
        var defender     = FFB.Instance.Model.GetPlayer(FFB.Instance.Model.DefenderId);

        if (actingPlayer != null)
        {
            if (actingPlayer.IsHome)
            {
                homeCardPlayer = actingPlayer;
                awayCardPlayer = HoverPlayer ?? defender;
            }
            else
            {
                homeCardPlayer = HoverPlayer ?? defender;
                awayCardPlayer = actingPlayer;
            }
        }
        else
        {
            homeCardPlayer = HoverPlayer != null && HoverPlayer.IsHome ? HoverPlayer : null;
            awayCardPlayer = HoverPlayer != null && !HoverPlayer.IsHome ? HoverPlayer : null;
        }

        PlayerCardHome.GetComponent <PlayerCardHandler>().SetPlayer(homeCardPlayer);
        PlayerCardAway.GetComponent <PlayerCardHandler>().SetPlayer(awayCardPlayer);
    }
コード例 #2
0
ファイル: FieldHandler.cs プロジェクト: garion30/FFBUnity
    // Update is called once per frame
    void Update()
    {
        var players = FFB.Instance.Model.GetPlayers();

        foreach (var p in players)
        {
            if (!Players.ContainsKey(p.Id))
            {
                GameObject obj     = Instantiate(PlayerIconPrefab);
                var        handler = obj.GetComponent <PlayerHandler>();
                obj.transform.SetParent(Field.transform);
                handler.Player = p;
                obj.name       = p.Id;

                var      child = obj.transform.GetChild(0).gameObject;
                Renderer s     = child.GetComponent <Renderer>();
                s.material.color = p.IsHome ? HomeColour : AwayColour;

                TMPro.TextMeshProUGUI text = obj.GetComponentInChildren <TMPro.TextMeshProUGUI>();
                text.text = p.Position?.AbstractLabel ?? "*";

                Players.Add(p.Id, obj);
            }

            if (p.Coordinate != null)
            {
                var state        = p.PlayerState;
                int moveToDugout = -1;
                if (state.IsReserve || state.IsExhausted || state.IsMissing)
                {
                    // Reserves box
                    moveToDugout = 0;
                }
                else if (state.IsKnockedOut)
                {
                    // KO Box
                    moveToDugout = 1;
                }
                else if (state.IsBadlyHurt || state.IsSeriousInjury || state.IsRip || state.IsBanned)
                {
                    // Cas Box
                    moveToDugout = 2;
                }

                if (moveToDugout >= 0)
                {
                    GameObject dugout = p.IsHome ? DugoutHome : DugoutAway;

                    Transform box   = dugout.transform.GetChild(moveToDugout);
                    int       index = box.childCount;
                    Players[p.Id].transform.SetParent(box);

                    Players[p.Id].transform.localPosition = ToDugoutCoordinates(p.Coordinate[1]);
                }
                else
                {
                    var pos = FieldToWorldCoordinates(p.Coordinate[0], p.Coordinate[1], 1);

                    Players[p.Id].transform.localPosition = pos;
                    Players[p.Id].transform.SetParent(Field.transform);
                }
                Players[p.Id].SetActive(true);
            }
            else
            {
                Players[p.Id].SetActive(false);
            }
        }

        var ball = FFB.Instance.Model.Ball;

        if (ball != null && ball.Coordinate != null)
        {
            Ball.SetActive(true);
            var ballPos = FieldToWorldCoordinates(ball.Coordinate[0], ball.Coordinate[1], 4);
            Ball.transform.localPosition = ballPos;
        }
        else
        {
            Ball.SetActive(false);
        }

        var pushbackSquares = FFB.Instance.Model.PushbackSquares.Values.ToList();

        PushbackSquares.Refresh(pushbackSquares);

        foreach (var s in pushbackSquares)
        {
            if (s != null && s.Coordinate != null && s.GameObject != null)
            {
                s.GameObject.transform.SetParent(Field.transform);
                s.GameObject.transform.localPosition = FieldToWorldCoordinates(s.Coordinate[0], s.Coordinate[1], 10);
            }
        }

        var trackNumbers = FFB.Instance.Model.TrackNumbers.Values.ToList();

        TrackNumbers.Refresh(trackNumbers);
        foreach (var s in trackNumbers)
        {
            if (s != null && s.Coordinate != null && s.GameObject != null)
            {
                s.GameObject.transform.SetParent(Field.transform);
                s.GameObject.transform.localPosition = FieldToWorldCoordinates(s.Coordinate[0], s.Coordinate[1], 10);
                s.LabelObject.SetText(s.Number.ToString());
            }
        }
    }
コード例 #3
0
ファイル: FieldHandler.cs プロジェクト: rlegendi/FFBUnity
    // Start is called before the first frame update
    private void Start()
    {
        FFB.Instance.OnReport += AddReport;

        FieldRect = Field.GetComponent <RectTransform>();

        foreach (var o in GameObject.FindGameObjectsWithTag("Clone"))
        {
            Destroy(o);
        }

        Ball = Instantiate(BallPrefab);
        Ball.transform.SetParent(Field.transform);

        Players = new PlayersView(this);

        PushbackSquares = new ViewObjectList <PushbackSquare>(s =>
        {
            GameObject obj = Instantiate(ArrowPrefab);
            var animator   = obj.GetComponent <Animator>();
            animator.SetTrigger(s.Direction);
            return(obj);
        },
                                                              s =>
        {
            if (s != null && s.ModelObject.Coordinate != null && s.GameObject != null)
            {
                s.GameObject.transform.SetParent(Field.transform);
                s.GameObject.transform.localPosition = FieldToWorldCoordinates(s.ModelObject.Coordinate.X, s.ModelObject.Coordinate.Y, 10);
            }
        },
                                                              s =>
        {
            var animator = s.GameObject.GetComponent <Animator>();
            animator.SetTrigger("FadeOut");
        });

        TrackNumbers = new ViewObjectList <TrackNumber>(t =>
        {
            GameObject obj = Instantiate(TrackNumberPrefab);
            t.LabelObject  = obj.GetComponentInChildren <TMPro.TextMeshPro>();
            return(obj);
        },
                                                        t =>
        {
            if (t != null && t.ModelObject.Coordinate != null && t.GameObject != null)
            {
                t.GameObject.transform.SetParent(Field.transform);
                t.GameObject.transform.localPosition = FieldToWorldCoordinates(t.ModelObject.Coordinate.X, t.ModelObject.Coordinate.Y, 10);
                t.ModelObject.LabelObject.SetText(t.ModelObject.Number.ToString());
            }
        },
                                                        t =>
        {
            Destroy(t.GameObject);
        });

        var players = FFB.Instance.Model.GetPlayers();

        Players.Refresh(players);

        if (FFB.Instance.Model.TeamHome != null)
        {
            HomeTeamText.text = FFB.Instance.Model.TeamHome.Name.ToUpper();
        }
        if (FFB.Instance.Model.TeamAway != null)
        {
            AwayTeamText.text = FFB.Instance.Model.TeamAway.Name.ToUpper();
        }
    }
コード例 #4
0
 // Update is called once per frame
 private void Update()
 {
     BlockDice.Refresh(FFB.Instance.Model.BlockDice);
 }