How to disable Scrubbing in TVMLKit JS Player Class - swift

I am trying to stop users from scrubbing forward (skipping ads) in the TVMLKit Player class.
I have tried setting
player.interactiveOverlayDocument = null;
but the player still shows the Transport bar, and I am able to scrub forward.

Turns out to be quite easy.
On the MediaItem Class which the Player Class uses to load the video, there is an attribute interstitials that accepts an array of [starttiem, duration] values.
var singleVideo = new MediaItem(mediaType, videourl);
var videoInterstitials = [];
videoInterstitials.push({
starttime: 50,
duration: 30
});
singleVideo.interstitials = videoInterstitials;
var videoList = new Playlist();
videoList.push(singleVideo);
var player = new Player();
player.playlist = videoList;
player.play();

Related

Shooting bullets in Flame Forge2d

I'm playing around with Forge2d on Flutter Flame and created a Ninja which throws Kanuies (a character shooting bullets basically).
If I create Kanuies and the Ninja separately then add them separately to the game world, all will be fine. However, I want the Ninja class to be responsible for login for throwing the Kanui. So I was wondering what is the right way to add a bullet component to a character component in Forge2d.
In my current code, inside Ninja Class, if I call add(Kanui) there will be no graphics shown about Kanuie NOT even with debugMode=true .
However, if use addToParrent(Kanui) it will be fine again.
Below is the link to my code. Please have a look and suggest corrections.
I'll provide some snippets here as well.
https://github.com/bmd007/flame_playground/blob/154cc0a9a99cc4bd5732e8d0c94bfa38093b0298/lib/my_girl.dart#L134
Ninja Class:
class MyGirl extends BodyComponent {
late SpriteAnimationComponent component;
Queue<MyGirlKanui> kanuies = Queue<MyGirlKanui>();
#override
Future<void> onLoad() async {
await super.onLoad();
idleAnimation = await gameRef.loadSpriteAnimation("red_girl/idle_spriteSheet.png", idleAnimationData);
component = SpriteAnimationComponent()
..animation = idleAnimation
..size = Vector2.all(6)
..anchor = Anchor.center;
add(component);
kanuies.add(MyGirlKanui(initialPosition));
}
#override
Body createBody() {
final shape = PolygonShape()..setAsBoxXY(3, 3);
final fixtureDefinition = FixtureDef(shape, density: 2, restitution: 0.1, friction: 2);
final bodyDefinition = BodyDef(position: initialPosition, type: BodyType.dynamic)..fixedRotation = true;
return world.createBody(bodyDefinition)..createFixture(fixtureDefinition);
}
throwKanui() async {
if (kanuies.isNotEmpty) {
var kanui = kanuies.removeFirst();
// await parent?.add(kanui);
await add(kanui);
kanui.component.position = component.position;
kanui.body.linearVelocity.x = 30;
}
}
I call the throw method when a UI button is pressed.
In Forge2D you shouldn't add any bodies as children to other components.
You can add the HasGameRef<Forge2DGame> mixin to the component and then you can add the bullets directly to the game.
Also don't forget to put the body of the bullet to isBullet = true if the "bullet" is moving very fast, otherwise you could end up with tunneling (where the body passes through the object that it is supposed to hit).

Display Another Player's Scores

I made a simple multiplayer quiz game. At the end of the quiz I want to display the scores of both players. Is it possible to get PlayerPrefs value from another player?
I use Photon PUN.
Well yes sure it is!
You could send a simple request RPC like e.g.
// Pass in the actor number of the player you want to get the score from
public void GetScore(int playerId)
{
// Get the Player by ActorNumber
var targetPlayer = Player.Get(playerId);
// Get your own ID so the receiver of the request knows who to answer to
var ownId = PhotonNetwork.LocalPlayer.ActorNumber;
// Call the GetScoreRpc on the target player
// passing in your own ID so the target player knows who to answer to
photonView.RPC(nameof(GetScoreRpc), targetPlayer, ownId);
}
[PunRpc]
private void GetScoreRpc(int requesterId)
{
// Get the requester player via the ActorNumber
var requester = Player.Get(requesterId);
// Fetch your score from the player prefab
// -1 indicates that there was an error e.g. no score exists so far
// up to you how you deal with that case
var ownScore = PlayerPrefs.GetInt("Score", -1);
// Get your own ID so the receiver knows who answered him
var ownId = PhotonNetwork.LocalPlayer.ActorNumber;
// Call the OnReceivedPlayerScore on the player who originally sent the request
photonView.RPC(nameof(OnReceivedPlayerScore), ownId, ownScore);
}
[PunRpc]
private void OnReceivedPlayerScore(int playerId, int score)
{
// Get the answering player by ActorNumber
var player = Player.Get(playerId);
// Do whatever you want with the information you received e.g.
if(score < 0)
{
Debug.LogError($"Could not get score from player \"{player.NickName}\"!");
}
else
{
Debug.Log($"Player \"{player.NickName}\" has a score of {score}!");
}
}

Convert GameObject to image?

So I'm making a card game and want my users to be able to create custom cards and not only use them in the game but also be able to print them.
Currently, I'm stuck on converting the UI GameObject of the card into a single image.
The card GameObject has a template card background, several other images (resources, main image, etc), and multiple text boxes (title, type, and description). Then I want to take that card hierarchy and convert it to a single image.
I thought this would be a fairly simple task but it appears to be a non-trivial... Or am I being a melon here?
Good question !
A button calling Capture below upon press and some GameObject image to capture:
Code:
using System.IO;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public GameObject GameObject;
public void Capture()
{
var rectTransform = GameObject.GetComponent<RectTransform>();
var delta = rectTransform.sizeDelta;
var position = rectTransform.position;
var offset = new RectOffset((int) (delta.x / 2), (int) (delta.x / 2), (int) (delta.y / 2), (int) (delta.y / 2));
var rect = new Rect(position, Vector2.zero);
var add = offset.Add(rect);
var tex = new Texture2D((int) add.width, (int) add.height);
tex.ReadPixels(add, 0, 0);
var encodeToPNG = tex.EncodeToPNG();
File.WriteAllBytes("card.png", encodeToPNG);
DestroyImmediate(tex);
}
}
In short, get object rect on screen, copy pixels, voila!
Result:

MovieTexture won't play audio

I'm trying to dynamically load and play a video file. No matter what I do, I cannot seem to figure out why the audio does not play.
var www = new WWW("http://unity3d.com/files/docs/sample.ogg");
var movieTexture = www.movie;
var movieAudio = www.movie.audioClip;
while (!movieTexture.isReadyToPlay) yield return 0;
// Assign movie texture and audio
var videoAnimation = videoAnimationPrefab.GetComponent<VideoAnimation>();
var videoRenderer = videoAnimation.GetVideoRenderer();
var audioSource = videoAnimation.GetAudioSource();
videoRenderer.material.mainTexture = movieTexture;
audioSource.clip = movieAudio;
// Play the movie and sound
movieTexture.Play();
audioSource.Play();
// Double check audio is playing...
Debug.Log("Audio playing: " + audioSource.isPlaying);
Every time I receive Audio playing: False
I've also tried using a GUITexture using this as a guide, but no dice. There are no errors displayed in the console.
What am I doing wrong that makes the audio never work?
Thanks in advance for any help!
Changed to:
while (!movieTexture.isReadyToPlay) yield return 0;
var movieAudio = movieTexture.audioClip;
Even though AudioClip inherits from Object, a call to movieTexture.audioClip seems to return a copied version instead of returning a reference by value to the object. So at the time I was assigning it, it had not been created yet and had to wait until the movie was "Ready to Play" until fetching the audioClip.

Using leapmotion to control Unity3d interface

I understand that I can use leapmotion in game with Unity3D.
What I can't see any information on, is if I can use it to actual interact with assets, models etc as I build the game. For example revolving a game object around the x axis or zooming in or out of the view.
Is this possible?
Yes, it is possible, but requires some scripts that nobody has written yet (ASFAIK). Here is a VERY rough example that I worked up today since I've been curious about this question, too.
All it does is move, scale, and rotate a selected game object -- it doesn't try to do this in a good way -- it is a proof of concept only. To make it work you would have to do a sensible conversion of Leap coordinates and rotations to Unity values. To try it, put this script in a folder called "Editor", select a game object in the scene view and hold a key down while moving your hand above your Leap. As I said, none of these movements really work to edit an object, but you can see that it is possible with some sensible logic.
#CustomEditor (Transform)
class RotationHandleJS extends Editor {
var controller = new Leap.Controller();
var position;
var localScale;
var localRotation;
var active = false;
function OnSceneGUI () {
e = Event.current;
switch (e.type) {
case EventType.KeyDown:
position = target.transform.position;
localScale = target.transform.localScale;
localRotation = target.transform.localRotation;
active = true;
Debug.Log("editing");
break;
case EventType.KeyUp:
active = false;
target.transform.position = position;
target.transform.localScale = localScale;
EditorUtility.SetDirty (target);
break;
}
if(active){
frame = controller.Frame();
ten = controller.Frame(10);
scale = frame.ScaleFactor(ten);
translate = frame.Translation(ten);
target.transform.localScale = localScale + new Vector3(scale, scale, scale);
target.transform.position = position + new Vector3(translate.x, translate.y, translate.z);
leapRot = frame.RotationMatrix(ten);
quats = convertRotation(leapRot);
target.transform.localRotation = quats;
}
}
var LEAP_UP = new Leap.Vector(0, 1, 0);
var LEAP_FORWARD = new Leap.Vector(0, 0, -1);
var LEAP_ORIGIN = new Leap.Vector(0, 0, 0);
function convertRotation(matrix:Leap.Matrix) {
var up = matrix.TransformDirection(LEAP_UP);
var forward = matrix.TransformDirection(LEAP_FORWARD);
return Quaternion.LookRotation(new Vector3(forward.x, forward.y,forward.z), new Vector3(up.x, up.y, up.z));
}
}