Esempio n. 1
0
        public TrackSnapData ShowGUI(DragTrack dragTrack, bool useAngles)
        {
            label = CustomGUILayout.TextField("Editor label:", label, string.Empty, "The region's label when displayed in Actions.");

            bool isEnabled = !isDisabled;

            isEnabled  = CustomGUILayout.Toggle("Is enabled?", isEnabled, string.Empty, "If True, the region is enabled");
            isDisabled = !isEnabled;

            positionAlong = CustomGUILayout.Slider("Centre " + ((useAngles) ? "angle" : "position:"), positionAlong, 0f, 1f, string.Empty, "How far along the track (as a decimal) the region lies.");

            width      = CustomGUILayout.Slider("Catchment size:", width, 0f, 1f, string.Empty, "How far apart from the snapping point (as a decimal of the track's length) the object can be for this to be enforced.");
            gizmoColor = CustomGUILayout.ColorField("Editor colour:", gizmoColor, string.Empty, "What colour to draw handles in the Scene with.");

            if (dragTrack.doSnapping)
            {
                if (dragTrack.actionListSource == ActionListSource.InScene)
                {
                    cutsceneOnSnap = (Cutscene)CustomGUILayout.ObjectField <Cutscene> ("Cutscene on snap:", cutsceneOnSnap, true, "", "An optional Cutscene to run when a Draggable object snaps to this region");
                }
                else if (dragTrack.actionListSource == ActionListSource.AssetFile)
                {
                    actionListAssetOnSnap = (ActionListAsset)CustomGUILayout.ObjectField <ActionListAsset> ("ActionList on snap:", actionListAssetOnSnap, false, "", "An optional ActionList asset to run when a Draggable object snaps to this region");
                }
            }

            if (dragTrack.TypeSupportsSnapConnections())
            {
                if (connections.Count == 0)
                {
                    TrackSnapConnection trackSnapConnection = new TrackSnapConnection();
                    connections.Add(trackSnapConnection);
                }

                for (int i = 0; i < connections.Count; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    connections[i] = connections[i].ShowGUI(dragTrack, i);
                    if (GUILayout.Button("+", GUILayout.MaxWidth(20f)))
                    {
                        Undo.RecordObject(dragTrack, "Add connection");
                        TrackSnapConnection trackSnapConnection = new TrackSnapConnection();
                        connections.Insert(i + 1, trackSnapConnection);
                        i = -1;
                        break;
                    }
                    if (connections.Count > 1 && GUILayout.Button("-", GUILayout.MaxWidth(20f)))
                    {
                        Undo.RecordObject(dragTrack, "Delete connection");
                        connections.RemoveAt(i);
                        i = -1;
                        break;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            return(this);
        }
Esempio n. 2
0
        public void EvaluateConnectionPoints(DragTrack track, Moveable_Drag draggable, Vector3 dragForce)
        {
            if (connections == null || !IsEnabled)
            {
                return;
            }

            float ownScore = 0f;

            switch (draggable.track.dragMovementCalculation)
            {
            case DragMovementCalculation.DragVector:
                ownScore = draggable.track.GetForceDotProduct(dragForce, draggable);
                break;

            case DragMovementCalculation.CursorPosition:
                Vector2 draggableScreenPosition = KickStarter.CameraMain.WorldToScreenPoint(draggable.Transform.position);
                if (Vector2.Distance(draggableScreenPosition, KickStarter.playerInput.GetMousePosition()) < 0.05f)
                {
                    return;
                }
                ownScore = draggable.track.GetMinDistanceToScreenPoint(KickStarter.playerInput.GetMousePosition());
                break;

            default:
                break;
            }

            TrackSnapConnection winningConnection = null;
            float winningScore         = ownScore;
            float winningScoreAbsolute = Mathf.Abs(winningScore);

            foreach (TrackSnapConnection connection in connections)
            {
                float connectionScore         = connection.EvaluateInputScore(draggable.track.dragMovementCalculation, draggable, dragForce);
                float connectionScoreAbsolute = Mathf.Abs(connectionScore);

                switch (draggable.track.dragMovementCalculation)
                {
                case DragMovementCalculation.DragVector:
                    if ((connectionScoreAbsolute > winningScoreAbsolute) || (connectionScoreAbsolute == winningScoreAbsolute && connectionScore > winningScore))
                    {
                        winningScoreAbsolute = connectionScoreAbsolute;
                        winningScore         = connectionScore;
                        winningConnection    = connection;
                    }
                    break;

                case DragMovementCalculation.CursorPosition:
                    if (connectionScore < winningScore)
                    {
                        winningScore      = connectionScore;
                        winningConnection = connection;
                    }
                    break;

                default:
                    break;
                }
            }

            if (winningScoreAbsolute > 0f && winningConnection != null && draggable.track == track)
            {
                winningConnection.MakeConnection(draggable);
            }
        }