Unity Timeline Component Not being Referenced through Scripting - c#

I followed a tutorial to create a text custom track in Unity Timeline. I want to bind the track's key to a subtitle GameObject with TextMeshProUGUI through script. Basically, I am using the method below:
playableDirector.SetGenericBinding(track, subtitle);
This is the outcome in the timeline:
This is the outcome in the timeline, if I just drag the same object:
The component is not appearing in the first picture, why?
Here is another test I did after manually referencing:
var subtitle = playableDirector.GetGenericBinding(track);
playableDirector.ClearGenericBinding(track);
playableDirector.SetGenericBinding(track, subtitle);
Debug.Log(subtitle.GetType());

I was not feeding the TextMeshProUGUI component into the method directly because I was getting an error inside the script editor. But after reading, components are considered Objects, and there wasn't a reason for it not to work, so I ran the script and it worked even though there were was a red line. I don't know why this happened, but here is the solution:
var subtitle = Subtitle.subtitle; // I referenced the component and made it static
playableDirector = GetComponent<PlayableDirector>();
timeline = playableDirector.playableAsset as TimelineAsset;
good = timeline.GetRootTrack(1);
bad = timeline.GetRootTrack(2);
var goodTracks = good.GetChildTracks() as List<TrackAsset>;
var badTracks = bad.GetChildTracks() as List<TrackAsset>;
playableDirector.SetGenericBinding(goodTracks[0], subtitle);
playableDirector.SetGenericBinding(badTracks[0], subtitle);

Related

How to fix the scaling/positioning problem in helix3d models?

Problem:
I am trying to create and render detailed building models with helixtoolkit.wpf.sharpdx. And some part of the model (mostly detailed furnishing and piping structures inside the house) is mis-scaled and mis-positioned at the first sight.
I am new here, and don't have enough reputations to post images yet
1.first sight
2.lamps?
However, if I carefully move my viewpoint(camera?) into the house, and some of the inside structures start to show. After wondering around the entire inside space of the house, and pulling back my viewpoint to the outside world, the rendered scene seems perfect.
3.lamps!
4.correct scene
(The calculation and assembling process for the 3d model should be correct.)
Questions:
Is there any important step I'm missing?
Are there possible workarounds to ensure the scene is rendered correctly?
May I and should I try to "walk" the camera around programmatically to achieve the correctly rendered scene?
Hope that I've described my problem clear enough.
Any suggestion is helpful!
Model3DCollection collection; //pre-assembled data
ObservableElement3DCollection obCollection = new ObservableElement3DCollection();
foreach (var m3d in collection)
{
if (m3d is GeometryModel3D gm3D)
{
MeshGeometry3D meshGeometry3D = gm3D.Geometry as MeshGeometry3D;
HelixToolkit.Wpf.SharpDX.MeshGeometry3D meshGeometry = CastGeometry(meshGeometry3D);
var model = new MeshGeometryModel3D()
{
Material = CastMaterial(gm3D.Material),
Transform = m3d.Transform,
Geometry = meshGeometry,
CullMode = CullMode.Front
};
meshGeometry.UpdateOctree();
obCollection.Add(model);
}
}
OnPropertyChanged(nameof(obCollection));
//...
Are you using separate thread instead of UI thread to load your models?
Seems like the transforms are not getting updated.
Make sure following is running in UI thread:
var model = new MeshGeometryModel3D()
{
Material = CastMaterial(gm3D.Material),
Transform = m3d.Transform,
Geometry = meshGeometry,
CullMode = CullMode.Front
};
obCollection.Add(model);

How to recieve input from HTC Vive tracker into Unity?

I am attatching an HTC Vive tracker to a real life object to use that object in game. The tracker is found in the game itself and the movement and rotation are updated perfectly fine. But getting the input to work is the problem here. The Tracker its pins are connected correctly and the input can be seen working in the Input Debugger in the SteamVR Input Binding Tool.
I have tried to find any help on the internet but everything seems to be outdated. The controller themselves do work with the custom input function I have added but the tracker refuses to work. There are no errors at all. The code simply calls a shoot function to shoot a bullet out of a gun. The input is recieved by the controller, both of them, but the tracker which has the exact same settings as the controllers doesn't seem to work.
[SerializeField] private GunScript gunScript;
[SerializeField] private SteamVR_Action_Boolean input;
void Update()
{
if (input.stateDown)
{
gunScript.Shoot(gunScript.ShotTransform.rotation);
}
}
The current output does shoot the gun when using the trigger which is set in the Input Binding Tool when using a normal controller, but when pressing the trigger attatched to the tracker nothing happens, no errors either.
// on start
var allDevices = new List<InputDevice>();
InputDevices.GetDevices(allDevices);
InputDevice tracker = allDevices.FirstOrDefault(d => d.role == InputDeviceRole.HardwareTracker);
// on update
tracker.TryGetFeatureValue(CommonUsages.devicePosition, out var pos);
tracker.TryGetFeatureValue(CommonUsages.deviceRotation, out var rot);
// NOTE!!! pos and rot are in world position so you have to translate it to floor
SteamVR_Action_Boolean.stateDown is a shortcut to SteamVR_Input_Sources.Any
but as you can see in SteamVR_Input_Sources there is no entry for trackers at all so also Any will not get a tracker input.
There are a ton of tutorials for how to get controller input but I also couldn't find anything about getting button input for Vive Trackers. Apparently this is not intended ...
It makes sense though since the button is also the Trackers connection/power button ... it would probably not be a good idea to make the User press that button in order to trigger some actions.
In their HTC_Vive_Tracker Guidelines they point to
If you encounter problems in enabling VIVETracker(2018)on Unityor Unreal, refer to the following links:
For Unity 3D developers:
Downloadlink for the ViveInputUtility package: AssetStore or GitHub
Vive Input Utility source code repository:https://github.com/ViveSoftware/ViveInputUtility-Unity
Maybe there is something helpfull there though it seems this is also more for controllers etc. not for getting the Tracker's button input.

Microsoft.Office.Interop.Visio + AutoConnect + Arrow

I would like to know if there is a way to use AutoConnect from Microsoft.Office.Interop.Visio to connect two Shape and make it like the link between both have an arrow from the first to the second Shape.
If it is not possible to make this connection using AutoConnect, would you know another way to make the arrow connection to the two Shape?
The method I am trying to use is as follows:
private void Connect Drawings (IVisio.Shape shape1, IVisio.Shape shape2, IVisio.VisAutoConnectDir dir)
{
     shape1.AutoConnect (shape2, dir);
}
Visio Print
Thanks for clarifiying in the comments. The reason the arrow head isn't displaying is probably because the page has a 'No theme' theme set and the default for connectors under this scheme is not to show arrow heads. So you can either start off with a template or drawing with the desired theme set, or, set it in code as part of your drop.
Here's an example (using LINQPad):
void Main()
{
var vApp = MyExtensions.GetRunningVisio();
var vPag = vApp.ActivePage;
var shp1 = vPag.DrawRectangle(2,5,3,4.5);
var shp2 = vPag.DrawRectangle(4,7,5,6.5);
shp1.AutoConnect(shp2, Visio.VisAutoConnectDir.visAutoConnectDirRight);
//Assuming 'No theme' is set for the page, no arrow will
//be shown so change theme to see connector arrow
vPag.SetTheme("Office Theme");
}
If you're interested in some 'theme' related background reading I have a few posts on the subject starting with this one: http://visualsignals.typepad.co.uk/vislog/2013/04/using-themes-in-visio-2013.html

Disable/enable ARKit during runtime in Unity3d - C#

Iam working with Unity3d, using C# and the ARKit plugin (2.0 from Github)
In my current application iam using the ARKit for measuring distances. The tool iam creating needs this functionality only for this reason, so i was wondering how i could enable the ARKit, when the user needs the ruler and disable it, if not.
I want to avoid that there is some performance losing while the user is using a non ARKit Tool. Em i right if i would say, that the ARKit still works in the background, if you where initializing it once? Iam new on the ARKit thing, so i dont have an perfect overview of how to handle it.
To drop some Code lines makes no sence, its basically the plugin importet into the project, and my own script which depends on some functions - i didnt changed anything in the source code of the plugin. The measuring tool itself which i programmed works pretty well, but i could not determine how to activate and deactivate basically the ARKit.
Can someone help me out with this? When iam disabeling the GameObjects, the scripts are running at it seems to be a "dirty" method to avoid those functionallitys but i have to make it clean (for excample also the video map in the background needs to be disabled - and i guess those ARKit functions will not be paused or disabled, just because some scripts are disalbed, it seems the api still runs in the background because it lags when i do so)
If you need more informations, please let me know. Every help or suggestion would be very nice.
Thanks a lot!
The current ARKit API doesn't have a method to disable or enable it in Unity, during run-time at this point.
With than being said, Unity has its own function to enable and disable VR, AR or XR plugins. If ARKit is built correctly, this method should work. So, you might be able to disable/enable ARKit by setting XRSettings.enabled to false and enable it by setting it to true.
It's also a good idea to call XRSettings.LoadDeviceByName with an empty string, wait for frame, before setting XRSettings.enabled to false to disable it:
IEnumerator DisableAR()
{
XRSettings.LoadDeviceByName("");
yield return null;
XRSettings.enabled = false;
}
then call to disable:
StartCoroutine(DisableAR());
I guess I am answering a pretty old post. I found a way but I don't know if that is what you are expecting.
Like #Programmer told
The current ARKit API doesn't have a method to disable or enable it in Unity, during run-time at this point.
So the way that I used is incorporating Programmer's code along with that if you need the camera to render some skybox or solid color, I have done something like that in Non-AR mode by saving the current texture before changing it, as the live video is given as texture to the material and after saving that changed the texture to null and when you want to re-enable AR you set the textures back to the saved value and it gets loaded correctly.
bool ARMode;
bool isSupported;
Camera cam;
UnityARCameraManager ARCameraManager;
private Texture2D _videoTextureY;
private Texture2D _videoTextureCbCr;
private void Awake()
{
cam = Camera.main;
isSupported = FindObjectOfType<UnityARCameraManager>().sessionConfiguration.IsSupported;
ARMode = isSupported;
ARCameraManager = FindObjectOfType<UnityARCameraManager>();
}
void DisableAR()
{
XRSettings.enabled = false;
ARCameraManager.enabled = false;
_videoTextureY = (Texture2D)cam.GetComponent<UnityARVideo>().m_ClearMaterial.GetTexture("_textureY");
_videoTextureCbCr = (Texture2D)cam.GetComponent<UnityARVideo>().m_ClearMaterial.GetTexture("_textureCbCr");
cam.GetComponent<UnityARVideo>().m_ClearMaterial.SetTexture("_textureY", Texture2D.blackTexture);
cam.GetComponent<UnityARVideo>().m_ClearMaterial.SetTexture("_textureCbCr", Texture2D.blackTexture);
cam.clearFlags = CameraClearFlags.SolidColor;
cam.backgroundColor = Color.black;
cam.GetComponent<UnityARVideo>().enabled = false;
}
void EnableAR()
{
ARCameraManager.enabled = true;
XRSettings.enabled = true;
cam.clearFlags = CameraClearFlags.Depth;
cam.GetComponent<UnityARVideo>().m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
cam.GetComponent<UnityARVideo().m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
cam.GetComponent<UnityARVideo>().enabled = true;
}

C# XNA Loading in textures

I have having alot of issues loading in textures into my simple game. First off, I am able to load in a texture when im inside of "Game1.cs". However, I am currently trying to create a level. So I want to load in all the pictures in the Level class.
public Level(IServiceProvider _serviceProvider)
{
content = new ContentManager(_serviceProvider, "Content");
mNrOfTextures = 3;
mTextures[] = new Texture2D[mNrTextures];
mTextures[0] = Content.Load<Texture2D>("sky");
//And then more textures and other stuff..
}
But the program can never find the file sky. I dont really get any useful error messages and im moving away from any tutorials currently. Can anyone point me into the right direction?
Full path to file: C:\c++\ProjIV\ProjIV\ProjIVContent\
I personally just pass my ContentManager to my level class, instead of passing the service provider as others do.
In this case, you need to use your local content instance, not the static Content
mTextures[0] = content.Load<Texture2D>("sky");
EDIT: I see this did not work, can you attach a picture of your solution layout with the content?

Categories