Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Tiny Project And JavaScript

Discussion in 'Project Tiny' started by benghazalaothmane, Mar 30, 2019.

?

Tiny Project And JavaScript

  1. tinyproject

    5 vote(s)
    100.0%
  2. javascript

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. benghazalaothmane

    benghazalaothmane

    Joined:
    Dec 19, 2018
    Posts:
    1
    Hi EveryOne, I have a javascript file that help me to show fb instant ads...In c# I used to call those function with Application.ExternallCall(...).How can I call it in tiny project ...Request Int and ShowInt
    Code (JavaScript):
    1. <!DOCTYPE html>
    2. <html lang="en-us">
    3.  
    4.   <head>
    5.     <meta charset="utf-8">
    6.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    7.     <title>Unity WebGL Player | New Unity Project try</title>
    8.         <link rel="shortcut icon" href="TemplateData/favicon.ico">
    9.         <link rel="stylesheet" href="TemplateData/style.css">
    10.  
    11.     <script src="Build/UnityLoader.js"></script>
    12.    
    13.      <script src="https://connect.facebook.net/en_US/fbinstant.6.1.js"></script>
    14.  
    15.      <script>
    16.     var gameInstance;
    17.     var preloadedInterstitial;
    18.     var preloadedRewardedVideo;
    19.     UnityLoader.SystemInfo.mobile = false;
    20.  
    21.        
    22.  
    23.  
    24.     FBInstant.initializeAsync().then(function() {
    25.       gameInstance = UnityLoader.instantiate("gameContainer", "Build/Extry.json", {onProgress: UnityProgress});
    26.        });
    27.  
    28.        function GetPlayerName()
    29.        {
    30.                gameInstance.SendMessage('FBInstantObject','UpdateScore',FBInstant.player.getName());
    31.        }
    32.  
    33.  
    34.        function RequestTopScores(LBName,numb=10)
    35.        {
    36.                FBInstant
    37.               .getLeaderboardAsync(LBName)
    38.               .then(leaderboard => leaderboard.getEntriesAsync(numb, 0))
    39.               .then(entries => {
    40.               if(entries.length>0)
    41.               {
    42.               var rettt="";
    43.               for (var i = 0; i < entries.length; i++) {
    44.                       rettt=entries[i].getScore() + "|"+ entries[i].getPlayer().getName() + "|";
    45.                 }
    46.                   gameInstance.SendMessage('FBInstantObject','ReceiveScore',rettt);
    47.               }
    48.           }).catch(error => console.error(error));
    49.  
    50.        }
    51.  
    52.  
    53.        function RequestOwnScore(LBName)
    54.        {
    55.                FBInstant
    56.               .getLeaderboardAsync(LBName)
    57.               .then(leaderboard => leaderboard.getPlayerEntryAsync())
    58.               .then(entry => {
    59.  
    60.                   gameInstance.SendMessage('FBInstantObject','ReceiveOwnScore',entry.getScore());
    61.  
    62.           }).catch(error => console.error(error));
    63.  
    64.        }
    65.  
    66.  
    67.            function AddNewScore(LBName,score)
    68.         {
    69.             FBInstant
    70.                   .getLeaderboardAsync(LBName)
    71.                   .then(leaderboard => {
    72.                 return leaderboard.setScoreAsync(score,FBInstant.player.getName());
    73.               })
    74.           .    then(() => console.log('Score saved'))
    75.               .catch(error => console.error(error));
    76.  
    77.  
    78.         }
    79.  
    80.  
    81.  
    82.  
    83.  
    84.         function ReqInt(idd)
    85.         {
    86.             preloadedInterstitial = null;
    87.  
    88.             FBInstant.getInterstitialAdAsync(
    89.               idd, // Your Ad Placement Id
    90.             ).then(function(interstitial) {
    91.               // Load the Ad asynchronously
    92.                   preloadedInterstitial = interstitial;
    93.                   return preloadedInterstitial.loadAsync();
    94.             }).then(function() {
    95.                   gameInstance.SendMessage('FBInstantObject','INTLoaded');
    96.             }).catch(function(err){
    97.                   console.error('Interstitial failed to preload: ' + err.message);
    98.             });
    99.         }
    100.  
    101.  
    102.  
    103.         function ReqRwd(idd)
    104.         {
    105.             preloadedRewardedVideo = null;
    106.  
    107.             FBInstant.getRewardedVideoAsync(
    108.                   idd, // Your Ad Placement Id
    109.             ).then(function(rewarded) {
    110.                   // Load the Ad asynchronously
    111.                   preloadedRewardedVideo = rewarded;
    112.                   return preloadedRewardedVideo.loadAsync();
    113.             }).then(function() {
    114.                   gameInstance.SendMessage('FBInstantObject','RWDLoaded');
    115.             }).catch(function(err){
    116.                   console.error('Rewarded video failed to preload: ' + err.message);
    117.             });
    118.         }
    119.  
    120.  
    121.         function ShowInt(idd)
    122.         {
    123.             preloadedInterstitial.showAsync()
    124.             .then(function() {
    125.                   // Perform post-ad success operation
    126.                   gameInstance.SendMessage('FBInstantObject','INTshown');
    127.             })
    128. .            catch(function(e) {
    129.                   console.error(e.message);
    130.             });
    131.         }
    132.  
    133.  
    134.         function ShowRwd(idd)
    135.         {
    136.             preloadedRewardedVideo.showAsync()
    137.             .then(function() {
    138.                   // Perform post-ad success operation
    139.                   gameInstance.SendMessage('FBInstantObject','RWDshown');
    140.             })
    141.             .catch(function(e) {
    142.                   console.error(e.message);
    143.             });
    144.         }
    145.  
    146.  
    147.      </script>
    148.   </head>
    149.  
    150.   <body>
    151.       <script src="./fbLoader.js"></script>
    152.       <div class="webgl-content" style="width: 100%; height: 100%">
    153.           <div id="gameContainer" style="width: 100%; height:100%; margin: 0"></div>
    154.  
    155.       </div>
    156.   </body>
    157.  
    158. </html>
     
    FDMpro and leppryt like this.