/// <summary>
        /// Jumps to the specified segment within this episode
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="jump">Whether to teleport the player to the checkpoint</param>
        /// <param name="checkpointIndex">The checkpoint to jump to</param>
        public void Enter(StratusSegmentBehaviour segment, bool jump, int checkpointIndex = 0)
        {
            if (!Application.isPlaying)
            {
                return;
            }

            if (debugDisplay)
            {
                StratusDebug.Log($"Entering the segment {segment}, checkpoint {checkpointIndex}", this);
            }

            // Toggle the current segment on
            ToggleCurrentSegment();

            // Enter the segment
            currentSegmentIndex = GetSegmentIndex(segment);
            segment.Enter(mode == Mode.Suspended);

            // Now warp the player to it
            if (jump)
            {
                Jump(segment, checkpointIndex);
            }
        }
        /// <summary>
        /// Jumps the player character onto the segment's checkpoint
        /// </summary>
        /// <param name="segment"></param>
        /// <param name="checkpointIndex"></param>
        public void Jump(StratusSegmentBehaviour segment, int checkpointIndex = 0)
        {
            Vector3 position = segment.checkpoints[checkpointIndex].transform.position;

            switch (mechanism)
            {
            case JumpMechanism.Translate:
                var navigation = targetTransform.GetComponent <NavMeshAgent>();
                if (navigation != null)
                {
                    navigation.Warp(position);
                }
                else
                {
                    targetTransform.position = position;
                }
                break;

            case JumpMechanism.Callback:
                onJump?.Invoke(segment, checkpointIndex);
                break;

            case JumpMechanism.Event:
                StratusScene.Dispatch <JumpToSegmentEvent>(new JumpToSegmentEvent(segment, checkpointIndex, position)
                {
                    episode = this
                });
                break;

            default:
                break;
            }
        }
 protected override void OnReset()
 {
     segment = GetComponent <StratusSegmentBehaviour>();
     if (segment)
     {
         episode = segment.episode;
     }
 }
 bool ValidateSegment(StratusSegmentBehaviour segment)
 {
     return(this.segment == segment);
     //if (referenceType == ReferenceType.Label)
     //  return this.segmentLabel == segment.label;
     //else if (referenceType == ReferenceType.Reference)
     //  return this.segment = segment;
     //return false;
 }
        /// <summary>
        /// Sets the initial segment for this episode
        /// </summary>
        /// <param name="segment"></param>
        public void SetInitialSegment(StratusSegmentBehaviour initialSegment)
        {
            // Toggle the selected segment
            this.initialSegment = initialSegment;

            foreach (var segment in segments)
            {
                segment.episode = this;
            }
        }
 private void OnValidate()
 {
     debugTextColorHex = debugTextColor.ToHex();
     if (segments.Count == 1)
     {
         initialSegment = segments[0];
     }
     if (initialSegment)
     {
         SetInitialSegment(initialSegment);
     }
 }
        /// <summary>
        /// Enters the specified (by label) segment within this episode if its present
        /// </summary>
        /// <param name="label">The label for the segment</param>
        /// <param name="jump">Whether to teleport the player to the checkpoint</param>
        /// <param name="checkpointIndex"></param>
        public bool Enter(string label, bool jump, int checkpointIndex = 0)
        {
            if (!StratusSegmentBehaviour.available.ContainsKey(label))
            {
                StratusDebug.LogError($"The segment labeled {label} is not present at this time!", this);
                return(false);
            }

            StratusSegmentBehaviour segment = StratusSegmentBehaviour.available[label];

            Enter(segment, jump, checkpointIndex);
            return(true);
        }
Beispiel #8
0
        private void ShowSegment(StratusEpisodeBehaviour episode, StratusSegmentBehaviour segment)
        {
            //expanded = GUILayout.(expanded, ); //, expanded ? minimizeButtonContent : expandButtonContent);
            //if (segment.checkpoints.NotEmpty() && GUILayout.Button(expanded ? minimizeButtonContent : expandButtonContent, EditorStyles.toggle))
            //  segmentExpanded[segment] = !expanded;
            //GUILayout.EndHorizontal();


            // Show the checkpoints
            if (!segment.checkpoints.Empty() && segmentExpanded[segment])
            {
                GUILayout.BeginVertical();
                for (int i = 0; i < segment.checkpoints.Count; ++i)
                {
                    if (GUILayout.Button($"{segment.checkpoints[i].name}", EditorStyles.miniButton))
                    {
                        episode.Enter(segment, true, i);
                    }
                }
                GUILayout.EndVertical();
            }
        }
 public ExitedEvent(StratusSegmentBehaviour segment)
 {
     this.segment = segment;
 }
 public JumpToSegmentEvent(StratusSegmentBehaviour segment, int checkpointIndex, Vector3 position)
 {
     this.segment         = segment;
     this.checkpointIndex = checkpointIndex;
     this.position        = position;
 }
 /// <summary>
 /// Gets the index of a given segment, provided its part of this episode
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 public int GetSegmentIndex(StratusSegmentBehaviour segment)
 {
     return(segments.FindIndex(x => x == segment));
 }
 /// <summary>
 /// Exits this segment
 /// </summary>
 /// <param name="segment"></param>
 public void Exit(StratusSegmentBehaviour segment)
 {
     segment.Exit();
 }