Пример #1
0
        private void DrawTransitionFromPointToPoint(TransitionViewData transitionViewData, Vector2 point, Vector2 targetPoint, TransitionViewStyle style)
        {
            Color    transitionColor      = TransitionViewStyleUtil.GetColor(style);
            GUIStyle transitionArrowStyle = TransitionViewStyleUtil.GetArrowStyle(style);

            Vector2 offset = targetPoint - point;
            // ex. A ---> B    ==    Direction.RIGHT
            Direction offsetDirection = DirectionUtil.ConvertVector2(offset);

            // ex. (Direction.RIGHT).Vector2Value()   ==   Vector2(1.0f, 0.0f)
            Vector2 nodeTangent       = Vector2.Scale(offsetDirection.Vector2Value(), Vector2Util.Abs(offset) * kTransitionTangentMultiplier);
            Vector2 targetNodeTangent = -nodeTangent;

            Handles.DrawBezier(point,
                               targetPoint,
                               point + nodeTangent,
                               targetPoint + targetNodeTangent,
                               transitionColor,
                               null,
                               kTransitionLineWidth);

            Vector3[] bezierPoints = Handles.MakeBezierPoints(point,
                                                              targetPoint,
                                                              point + nodeTangent,
                                                              targetPoint + targetNodeTangent,
                                                              division: 40);

            int     midPointIndex   = Mathf.FloorToInt(bezierPoints.Length / 2.0f);
            Vector2 midPointTangent = bezierPoints[midPointIndex + 1] - bezierPoints[midPointIndex];

            Vector2 midPoint      = (point + targetPoint) / 2.0f;
            float   rotationAngle = Vector2.Angle(Vector2.right, midPointTangent);

            if (midPointTangent.y < 0.0f)
            {
                rotationAngle *= -1.0f;
            }

            GUIUtility.RotateAroundPivot(rotationAngle, midPoint);
            GUI.Box(RectUtil.MakeRect(midPoint, new Vector2(10.0f, 10.0f), pivot: new Vector2(0.5f, 0.5f)), "", transitionArrowStyle);
            GUIUtility.RotateAroundPivot(-rotationAngle, midPoint);
        }
Пример #2
0
        private Rect GetNodeRect(Node node)
        {
            NodeViewData viewData = this.GetViewDataForNode(node);

            return(RectUtil.MakeRect(viewData.position + this._panner.Position, kNodeSize, kNodePivot));
        }
        // PRAGMA MARK - Public Interface
        public RandomizedArenaBackdrop(GameObject container, GameObject arenaObject)
        {
            container_ = container;

            List <Rect> placedPlatforms = new List <Rect>();

            foreach (var backdropBlocker in arenaObject.GetComponentsInChildren <IBackdropBlocker>())
            {
                Vector3 position = (backdropBlocker as MonoBehaviour).transform.position;
                placedPlatforms.Add(RectUtil.MakeRect(new Vector2(position.x, position.z), new Vector2(backdropBlocker.Width + kHalfPadding, backdropBlocker.Height + kHalfPadding), pivot: new Vector2(0.5f, 0.5f)));
            }

            for (int i = 0; i < kFadedPlatformCount; i++)
            {
                bool placed = false;
                for (int j = 0; j < kMaxPlacementTries; j++)
                {
                    float x = UnityEngine.Random.Range(-kBackdropXRange, kBackdropXRange);
                    float z = UnityEngine.Random.Range(-kBackdropZRange / 2.0f, kBackdropZRange * 3.0f / 2.0f);

                    float width  = UnityEngine.Random.Range(kRandomPlatformWidthMin, kRandomPlatformWidthMax);
                    float height = UnityEngine.Random.Range(kRandomPlatformHeightMin, kRandomPlatformHeightMax);

                    Rect placementRect = RectUtil.MakeRect(new Vector2(x, z), new Vector2(width + kHalfPadding, height + kHalfPadding), pivot: new Vector2(0.5f, 0.5f));

                    bool intersects = false;
                    foreach (var placedRect in placedPlatforms)
                    {
                        if (placementRect.Overlaps(placedRect))
                        {
                            intersects = true;
                            break;
                        }
                    }

                    if (intersects)
                    {
                        continue;
                    }

                    float y = UnityEngine.Random.Range(kBackdropYMin, kBackdropYMax);

                    // because the further back the z is (towards -kBackdropZRange) the higher it appears
                    // to the camera, we want to make sure that the y is not too high
                    //
                    // when z is -kBackdropZRange, y is subtracted by kBackdropYZInfluence
                    float zPercentage = (z + (kBackdropZRange / 2.0f)) / (2.0f * kBackdropZRange);
                    y -= (1.0f - zPercentage) * kBackdropYZInfluence;


                    placedPlatforms.Add(placementRect);
                    GameObject instance = ObjectPoolManager.Create(GamePrefabs.Instance.BackdropPlatformPrefab, position: new Vector3(x, y, z), rotation: Quaternion.identity, parent: container_);
                    instance.transform.localScale = instance.transform.localScale.SetX(width).SetZ(height);

                    placed = true;
                    break;
                }

                // if failed to place container, don't try again
                if (!placed)
                {
                    break;
                }
            }

            transition_ = new Transition(container_).SetShuffledOrder(true);
            transition_.SetOffsetDelay(kAnimateTime / transition_.TransitionCount);

            transition_.AnimateIn();
        }