Пример #1
0
        public void TryPushTurtle(Turtle turtle)
        {
            if (turtles.Count == 0)
            {
                turtle.transform.parent.GetComponent <Tower>().PopTurtle();
                turtle.transform.parent.GetComponent <Tower>().EnableTopTurtle();
                PushTurtle(turtle);
                turtles.Push(turtle);
                ExecuteEvents.ExecuteHierarchy <ITowerPushHandler>(gameObject, null, (x, y) => x.OnTurtlePushAccept());
                ExecuteEvents.ExecuteHierarchy <ITaskEventsHandler>(gameObject, null, (x, y) => x.OnTurtlePush());

                if (lastTower)
                {
                    ExecuteEvents.ExecuteHierarchy <ITaskEventsHandler>(gameObject, null, (x, y) => x.OnTurtlePushLastTower(this));
                }
            }
            else
            {
                if (Contains(turtle) || turtles.Peek().Weight <= turtle.Weight)
                {
                    ExecuteEvents.Execute <ITowerPushHandler>(turtle.gameObject, null, (x, y) => x.OnTurtlePushRefuse());
                }
                else
                {
                    turtle.transform.parent.GetComponent <Tower>().PopTurtle();
                    turtle.transform.parent.GetComponent <Tower>().EnableTopTurtle();
                    DisableTopTurtle();
                    PushTurtle(turtle);
                    turtles.Push(turtle);
                    ExecuteEvents.ExecuteHierarchy <ITowerPushHandler>(gameObject, null, (x, y) => x.OnTurtlePushAccept());
                    ExecuteEvents.ExecuteHierarchy <ITaskEventsHandler>(gameObject, null, (x, y) => x.OnTurtlePush());

                    if (lastTower)
                    {
                        ExecuteEvents.ExecuteHierarchy <ITaskEventsHandler>(gameObject, null, (x, y) => x.OnTurtlePushLastTower(this));
                    }
                }
            }
        }
Пример #2
0
        public void OnTurtlePushed(Turtle turtle)
        {
            float      maxY      = transform.position.y;
            GameObject maxObject = this.gameObject;

            foreach (var towerTurtle in GetComponentsInChildren <Turtle>())
            {
                if (towerTurtle == turtle)
                {
                    continue;
                }

                if (towerTurtle.transform.position.y + towerTurtle.GetComponent <Renderer>().bounds.size.y / 2 > maxY)
                {
                    maxY      = towerTurtle.transform.position.y + towerTurtle.GetComponent <Renderer>().bounds.size.y / 2;
                    maxObject = towerTurtle.gameObject;
                }
            }

            Vector3 newPosition = transform.position;

            if (gameObject != maxObject && turtle.gameObject != maxObject)
            {
                newPosition.y = maxObject.transform.position.y +
                                3 * (turtle.GetComponent <Renderer>().bounds.size.y +
                                     maxObject.GetComponent <Renderer>().bounds.size.y) / 10;
            }
            else
            {
                newPosition.y = transform.position.y +
                                3 * (turtle.GetComponent <Renderer>().bounds.size.y) / 8;
            }

            turtle.transform.parent   = transform;
            turtle.transform.position = newPosition;
        }
Пример #3
0
 void Awake()
 {
     turtle     = GetComponent <Turtle>();
     IsDragable = false;
 }
Пример #4
0
 public bool Contains(Turtle turtle)
 {
     return(turtles.Contains(turtle));
 }