17 ม.ค. 2556

Facebook UI มันชอบไปอยู่หลัง Unity Web Player

กรณีที่มันอยู่ในหน้า Web ของมันเองบางทีเจอบางทีก็ไม่เจอ Chrome , IE , Firefox ก็ผลออกมาไม่เหมือนกัน

แต่กรณีที่มันอยู่ใน Facebook Iframe ไอตัว Facebook UI ที่มันเด้งขึ้นมา มันนจะไปอยู่ข้างหลัง Unity Web Player ทันที
แบบนี้!


เพราะฉะนั้นถ้าเอามันมาไว้ข้างหน้าไม่ได้ ก็ ซ่อน Unity Web Player ซะเลย ระหว่างที่ แสดง Facebook UI

DIV Container ของ Unity Web Player

      

 <div class="content">
<div id="unityPlayer" name="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                        <img alt="Unity Web Player. Install now!" height="63" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" />
                    </a>
                </div>
</div>
</div>


สมมติจะ เรียก UI AppRequest
และ ระหว่าง ที่  แสดง UI ใช้ JQuery.hide() แต่ ถ้าใช้ method นี้ ตอน JQuery.show();  ตัว Unity Web Player จะโหลด Game ใหม่
เลขใช้แบบ แก้ Width,Height เป็น 0 แทน

ตอน Call Facebook UI  อันนี้เป็น script ใน web page ใช้ Application.ExternalCall() เอาจาก script ใน  Unity3d

    
function uiAppRequest( title, message ) {
 $('#unityPlayer').width(0);
 $('#unityPlayer').height(0);
 FB.ui(
  {
    method:  'apprequests',
                 message: message,
                 title:  title
      }, 
      function(response) {
       $('#unityPlayer').width(800);
   $('#unityPlayer').height(600);
       var unity = unityObject.getObjectById( "unityPlayer" );
       if (!response || response.error) {
        unity.SendMessage("Facebook", "onUiAppRequestFail", JSON.stringify( response ) );
      } else {
        unity.SendMessage("Facebook", "onUiAppRequestSuccessful", JSON.stringify( response ) );
      }     
   }
 );
}


Unity Web Player หายไป แล้ว Facebook UI แสดงแทน

อธิบาย 
- เมื่อ Unity3D เรียก Facebook UI ก็ให้  width = height = 0 เลย 
- และ Add Callback Function เมื่อ UI Completed ให้มีส่วนที่สั่งให้ Unity Web Player กลับมาแสดงอีกครั้ง

ไม่มีความคิดเห็น:

แสดงความคิดเห็น