コード例 #1
0
ファイル: PlayersView.cs プロジェクト: christerk/FFBUnity
        private void Update(ViewObject <Player> p)
        {
            bool active = false;

            if (p.ModelObject.Coordinate != null && p.GameObject != null)
            {
                var state        = p.ModelObject.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.ModelObject.IsHome ? DugoutHome : DugoutAway;

                    Transform box = dugout.transform.GetChild(moveToDugout);
                    p.GameObject.transform.SetParent(box);

                    p.GameObject.transform.localPosition = Handler.ToDugoutCoordinates(p.ModelObject.Coordinate.Y);
                }
                else
                {
                    var squareCenter = Handler.FieldToWorldCoordinates(p.ModelObject.Coordinate.X, p.ModelObject.Coordinate.Y, 0f);

                    Vector3 zeroIntersect = GetIntersectPoint(squareCenter, 0.01f, Color.magenta);

                    var cameraAngle = Handler.MainCamera.transform.eulerAngles.x;
                    var cosAngle    = Mathf.Cos(Mathf.Deg2Rad * (-cameraAngle));

                    var pos = new Vector3(zeroIntersect.x, 0.1f + cosAngle * p.ModelObject.Position.IconHeight / 2, zeroIntersect.z);

                    //var backgroundObject = p.GameObject.transform.GetChild(0);
                    //backgroundObject.transform.localPosition = new Vector3(0f, 0.1f + cosAngle * Handler.IconHoverDistance, 0f);

                    p.GameObject.transform.localPosition = pos;
                    p.GameObject.transform.SetParent(Field.transform);
                }
                active = true;
            }

            if (p.GameObject != null)
            {
                p.GameObject.SetActive(active);
            }
        }
コード例 #2
0
        private void Update(ViewObject <Player> p)
        {
            bool active = false;

            if (p.ModelObject.Coordinate != null && p.GameObject != null)
            {
                var state        = p.ModelObject.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.ModelObject.IsHome ? DugoutHome : DugoutAway;

                    Transform box = dugout.transform.GetChild(moveToDugout);
                    p.GameObject.transform.SetParent(box);

                    p.GameObject.transform.localPosition = Handler.ToDugoutCoordinates(p.ModelObject.Coordinate.Y);
                }
                else
                {
                    var pos = Handler.FieldToWorldCoordinates(p.ModelObject.Coordinate.X, p.ModelObject.Coordinate.Y, 1);

                    p.GameObject.transform.localPosition = pos;
                    p.GameObject.transform.SetParent(Field.transform);
                }
                active = true;
            }

            if (p.GameObject != null)
            {
                p.GameObject.SetActive(active);
            }
        }
コード例 #3
0
        public List <ViewObject <T> > Refresh(IEnumerable <T> newObjects)
        {
            foreach (var o in Objects.Values)
            {
                o.Removed = true;
            }

            foreach (var o in newObjects)
            {
                if (Objects.ContainsKey(o.Key))
                {
                    Objects[o.Key].Removed = false;
                    Objects[o.Key].ModelObject.Refresh(o);
                }
                else
                {
                    var gameObject = Constructor(o);
                    var viewObject = new ViewObject <T>(o, gameObject);
                    Objects.Add(o.Key, viewObject);
                }
            }

            foreach (var o in Objects.Values)
            {
                if (o.Removed && o.GameObject != null)
                {
                    Destructor(o);
                    RemovedObjects.Add(o);
                }
                else
                {
                    Updater?.Invoke(o);
                }
            }

            foreach (var key in Objects.Values.Where(o => o.Removed).Select(o => o.ModelObject.Key).ToList())
            {
                Objects.Remove(key);
            }

            return(RemovedObjects);
        }
コード例 #4
0
ファイル: ViewObjectList.cs プロジェクト: christerk/FFBUnity
        public void Refresh(List <T> newObjects)
        {
            foreach (var o in Objects.Values)
            {
                o.Removed = true;
            }

            foreach (var o in newObjects)
            {
                if (Objects.ContainsKey(o.Key))
                {
                    Objects[o.Key].Removed = false;
                    Objects[o.Key].ModelObject.Set(o);
                }
                else
                {
                    var gameObject = Constructor(o);
                    var viewObject = new ViewObject <T>(o, gameObject);
                    Objects.Add(o.Key, viewObject);
                }
            }

            foreach (var o in Objects.Values)
            {
                if (o.Removed && o.GameObject != null)
                {
                    Destructor(o);
                    RemovedObjects.Add(o);
                }
                else
                {
                    Updater?.Invoke(o);
                }
            }

            foreach (var removedObject in RemovedObjects)
            {
                Objects.Remove(removedObject.Key);
            }
            RemovedObjects.Clear();
        }
コード例 #5
0
ファイル: PlayersView.cs プロジェクト: christerk/FFBUnity
 private void Destruct(ViewObject <Player> p)
 {
     GameObject.Destroy(p.GameObject);
 }