-
-
Save TigerHix/c549e984df0be34cfd6f8f50e741aab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
using Warudo.Core; | |
using Warudo.Core.Attributes; | |
using Warudo.Core.Utils; | |
using Warudo.Plugins.Core.Assets.Cinematography; | |
using Warudo.Plugins.Core.Assets.Mixins; | |
namespace Warudo.Plugins.Core.Assets.Utility { | |
[AssetType(Id = "a2c8e3e8-0556-471e-9247-ea41ba587d03", Title = "ANCHOR")] | |
public class AnchorAsset : GameObjectAsset { | |
[Mixin] | |
public Attachable Attachable; | |
protected override GameObject CreateGameObject() { | |
var gameObject = new GameObject($"Anchor {Name}"); | |
Attachable.Initialize(gameObject); | |
return gameObject; | |
} | |
[Trigger] | |
[Label("TELEPORT_TO_ACTIVE_CAMERA")] | |
public void TeleportToActiveCamera() { | |
if (CorePlugin.MainCameraAsset is not CameraAsset cameraAsset) { | |
throw new UserException("Unsupported camera asset type"); | |
} | |
Transform.Position = Attachable.Transform.InverseTransformPoint(cameraAsset.GameObject.transform.position); | |
Transform.RotationQuaternion = Quaternion.Inverse(Attachable.Transform.rotation) * cameraAsset.GameObject.transform.rotation; | |
BroadcastTransformOptimized(); | |
Transform?.ApplyAsLocalTransform(GameObject.transform); | |
DisableTransformGizmo(); | |
EnableTransformGizmo(); | |
} | |
private readonly Lazy<CorePlugin> corePlugin = new(() => Context.PluginManager.GetPlugin<CorePlugin>()); | |
protected CorePlugin CorePlugin => corePlugin.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment