Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teleport condition TRNG-102 #40

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Editor/UI/MenuItems/TeleportMenuItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Innoactive.Creator.Core.Conditions;
using Innoactive.CreatorEditor.UI.StepInspector.Menu;

namespace Innoactive.CreatorEditor.UI.Conditions
{
/// <inheritdoc />
public class TeleportMenuItem : MenuItem<ICondition>
{
/// <inheritdoc />
public override string DisplayedName { get; } = "Teleport";

/// <inheritdoc />
public override ICondition GetNewItem()
{
return new TeleportCondition();
}
}
}

11 changes: 11 additions & 0 deletions Editor/UI/MenuItems/TeleportMenuItem.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions Runtime/Conditions/PositionalConditions/TeleportCondition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Runtime.Serialization;
using Innoactive.Creator.Core.Attributes;
using Innoactive.Creator.Core.Properties;
using Innoactive.Creator.Core.SceneObjects;
using Innoactive.Creator.Core.Utils;
using Innoactive.Creator.Core.Validation;

namespace Innoactive.Creator.Core.Conditions
{
/// <summary>
/// Condition which is completed when a teleportation action was executed into the referenced <see cref="ITeleportProperty"/>.
/// </summary>
[DataContract(IsReference = true)]
public class TeleportCondition : Condition<TeleportCondition.EntityData>
{
[DisplayName("Teleport")]
[DataContract(IsReference = true)]
public class EntityData : IConditionData
{
[DataMember]
[DisplayName("Teleport Point")]
#if CREATOR_PRO
[CheckForCollider]
#endif
tomwim marked this conversation as resolved.
Show resolved Hide resolved
public ScenePropertyReference<ITeleportProperty> TeleportPoint { get; set; }

/// <inheritdoc />
public bool IsCompleted { get; set; }

/// <inheritdoc />
[DataMember]
[HideInTrainingInspector]
public string Name { get; set; }

/// <inheritdoc />
public Metadata Metadata { get; set; }
}

public TeleportCondition() : this( "")
{
}

public TeleportCondition(ITeleportProperty teleportPoint, string name = null) : this(TrainingReferenceUtils.GetNameFrom(teleportPoint), name)
{
}

public TeleportCondition(string teleportPoint, string name = "Teleport")
{
Data.TeleportPoint = new ScenePropertyReference<ITeleportProperty>(teleportPoint);
Data.Name = name;
}

private class ActiveProcess : BaseActiveProcessOverCompletable<EntityData>
{
public ActiveProcess(EntityData data) : base(data)
{
}

/// <inheritdoc />
public override void Start()
{
base.Start();
Data.TeleportPoint.Value.Initialize();
}

/// <inheritdoc />
protected override bool CheckIfCompleted()
{
return Data.TeleportPoint.Value.WasUsedToTeleport;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having a set value, why dont we use events?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we do, the events set that property to true.
The flag is required to know that the event was fired.

}
}

private class EntityAutocompleter : Autocompleter<EntityData>
{
public EntityAutocompleter(EntityData data) : base(data)
{
}

/// <inheritdoc />
public override void Complete()
{
Data.TeleportPoint.Value.FastForwardTeleport();
}
}

/// <inheritdoc />
public override IProcess GetActiveProcess()
{
return new ActiveProcess(Data);
}

/// <inheritdoc />
protected override IAutocompleter GetAutocompleter()
{
return new EntityAutocompleter(Data);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Runtime/Properties/ITeleportProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Innoactive.Creator.Core.SceneObjects;

namespace Innoactive.Creator.Core.Properties
{
/// <summary>
/// Interface for <see cref="ISceneObjectProperty"/>s that can be used for teleport into.
/// </summary>
public interface ITeleportProperty : ISceneObjectProperty, ILockable
{
/// <summary>
/// Emitted when an 'XR Rig' gets teleported into this <see cref="ISceneObject"/>.
Gusinuhe marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
event EventHandler<EventArgs> Teleported;

/// <summary>
/// True if an XR Rig was teleported into this <see cref="ITeleportProperty"/>.
Gusinuhe marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
bool WasUsedToTeleport { get; }

/// <summary>
/// Sets <see cref="WasUsedToTeleport"/> to true.
/// </summary>
/// <remarks>
/// This method is called every time a <see cref="Conditions.TeleportCondition"/> is activate.
/// </remarks>
void Initialize();

/// <summary>
/// Instantaneously simulate that the object was used.
/// </summary>
void FastForwardTeleport();
}
}
11 changes: 11 additions & 0 deletions Runtime/Properties/ITeleportProperty.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.