LevelUp! Studio » Ziah https://blog.levelup.in.th Experience the new world. Fri, 26 May 2017 10:06:07 +0000 th hourly 1 http://wordpress.org/?v=3.8.1 [Unity] การเล่นวีดิโอใน Mobile App https://blog.levelup.in.th/2017/01/31/unity-playing-video-in-the-mobile-app/ https://blog.levelup.in.th/2017/01/31/unity-playing-video-in-the-mobile-app/#comments Tue, 31 Jan 2017 13:17:15 +0000 http://blog.levelup.in.th/?p=6078 การเล่นวีดิโอในแอ็พของเรานั้นถ้าเล่นแบบเต็มจอแล้วทำได้ไม่ยากเลยครับ เพียงใช้ฟังก์ชั่น Handheld.PlayFullScreenMovie ซึ่งรับพารามิเตอร์ 4 ตัว คือ

  • Path หรือ Url ของไฟล์วีดิโอของเรา *บังคับมี*
  • สีของ Background
  • แผงควบคุม
    จะมีให้เลือก 4 แบบ คือ

    • FullScreenMovieControlMode.Full โชว์แผงควบคุมทั้งหมด
    • FullScreenMovieControlMode.Minimal โชว์แผงควบคุมแบบน้อยที่สุด
    • FullScreenMovieControlMode.CancelOnInput ไม่โชว์แผงควบคุม และหยุดวีดิโอเมื่อแตะ
    • FullScreenMovieControlMode.Hidden ไม่โชว์แผงควบคุม
  • การปรับขนาด
    จะมีให้เลือก 4 แบบ คือ

    • FullScreenMovieScalingMode.None ไม่ทำการปรับขนาดใดๆ
    • FullScreenMovieScalingMode.AspectFit ปรับยึดอัตราส่วนเดิมโดยให้ด้านใดด้านหนึ่งของวีดิโอที่ยาวกว่าชิดขอบ
    • FullScreenMovieScalingMode.AspectFill ปรับยึดอัตราส่วนเดิมโดยให้ด้านใดด้านหนึ่งของวีดิโอที่สั้นกว่าชิดขอบ
    • FullScreenMovieScalingMode.Fill ปรับเต็มจอโดยไม่ยึดอัตราส่วนเดิม

ตัวอย่างเช่น
Handheld.PlayFullScreenMovie(ConfigGame.ImageUrl + “idol.mp4″, Color.black, FullScreenMovieControlMode.Full, FullScreenMovieScalingMode.AspectFit);

ผลลัพธ์ที่ได้



style="display:block"
data-ad-client="ca-pub-5841101416947980"
data-ad-slot="5395238750"
data-ad-format="auto">



style="display:block"
data-ad-client="ca-pub-5841101416947980"
data-ad-slot="8429430352"
data-ad-format="auto">



style="display:block"
data-ad-client="ca-pub-5841101416947980"
data-ad-slot="9906163557"
data-ad-format="auto">



style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-5841101416947980"
data-ad-slot="8289829557">



style="display:inline-block;width:468px;height:60px"
data-ad-client="ca-pub-5841101416947980"
data-ad-slot="9766562755">

]]>
https://blog.levelup.in.th/2017/01/31/unity-playing-video-in-the-mobile-app/feed/ 0
วิธีง่ายๆในการจัดกลุ่มตัวแปรใน Inspector https://blog.levelup.in.th/2017/01/26/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b9%83%e0%b8%99%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b8%81%e0%b8%a5%e0%b8%b8%e0%b9%88%e0%b8%a1/ https://blog.levelup.in.th/2017/01/26/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b9%83%e0%b8%99%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b8%81%e0%b8%a5%e0%b8%b8%e0%b9%88%e0%b8%a1/#comments Thu, 26 Jan 2017 09:06:00 +0000 http://blog.levelup.in.th/?p=6075 เมื่อเราต้องการจัดกลุ่มของตัวแปรปกติเราต้องไปยุ่งกับพวก UnityEngine.GUI GUILayout GUIStyle ซึ่งถ้าเราไม่อยากไปวุ่นวายก็มีวิธีง่ายๆโดยใช้การเขียน Class ของตัวแปร ที่มี [Serializable] เอาครับ

ตัวอย่างเช่น เราต้องการตัวแปร 4 ชุด ที่เก็บ GameObject ด้านในคล้ายๆกัน วิธีปกติก็จะได้โค็ดแบบนี้

public GameObject Border4;
public List Piece4;
public List NewPiece4;
public GameObject Border6;
public List Piece6;
public List NewPiece6;
public GameObject Border9;
public List Piece9;
public List NewPiece9;
public GameObject Border12;
public List Piece12;
public List NewPiece12;

ซึ่งหน้าตาใน Inspector จะออกมาแบบนี้ ดูยากมาก

ที่นี้ถ้าเราทำมันเป็น Class ใส่ [Serializable] เข้าไป โค็ดก็จะหน้าตาออกมาเป็นแบบนี้


public Image Image4;
public Image Image6;
public Image Image9;
public Image Image12;
[Serializable]
public class Image
{
public GameObject Border;
public List Piece;
public List NewPiece;
}

ซึ่งผลลัพธ์ที่ออกมาดูง่ายกว่าเดิมมากครับ

]]>
https://blog.levelup.in.th/2017/01/26/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%87%e0%b9%88%e0%b8%b2%e0%b8%a2%e0%b9%86%e0%b9%83%e0%b8%99%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%88%e0%b8%b1%e0%b8%94%e0%b8%81%e0%b8%a5%e0%b8%b8%e0%b9%88%e0%b8%a1/feed/ 0
การแก้ปัญหาการโหลดรูปโปรไฟล์ Facebook ใน iOS ไม่ได้เพราะติดการ Redirect https://blog.levelup.in.th/2016/11/30/fixing-loading-facebook-profile-picture-error-on-ios-cause-by-url-redirection/ https://blog.levelup.in.th/2016/11/30/fixing-loading-facebook-profile-picture-error-on-ios-cause-by-url-redirection/#comments Wed, 30 Nov 2016 14:25:43 +0000 http://blog.levelup.in.th/?p=6006 หลังจากที่อัพ iOS + XCode เวอร์ชั่นใหม่แล้ว ทำให้เกิดปัญหา
ซึ่งจาก Error แล้วเดาได้ว่าทาง iOS ไม่ยอมให้มีการโหลดรูปจาก url ที่มีการ redirect แล้ว
เลยมีวิธีแก้ไขดังนี้ครับ

โค้ดเดิม

IEnumerator LoadPictureWWW(string url)
{
WWW www = new WWW(url);
yield return www;
Material mat = new Material(Shader.Find("Unlit/Transparent Colored (AlphaClip)"));
mat.mainTexture = www.texture;
UITexture _uit = gameObject.GetComponent();
if (_uit == null)
{
Debug.Log("playerWWW == null");
gameObject.AddComponent();
}
this.GetComponent().material = mat;
}

ตามด้านบนวิธีเก่าจะโหลดไม่สำเร็จเพราะยิงไปแล้วโดน Redirect แต่ทาง iOS จะไม่ทำการ Redirect ต่อทำให้ www.texture ไม่ได้ค่าออกมา
วิธีการแก้ไขคือเราต้องยิง url ไปรอบนึงแล้วเอา Result มาดูค่า url ที่ได้จากการ redirect แล้วมาเพื่อยิงเองต่ออีกครั้งนึงดังนี้


public static IEnumerator _loadFacebookProfileImage (string userId, UITexture texture, int size)
{
string url = string.Format ("https://graph.facebook.com/{0}/picture?width={1}&height={1}&redirect=false", userId, size);
WWW www1 = new WWW (url);
yield return www1; //ทำการยิงครั้งแรก
if (string.IsNullOrEmpty (www1.error)) {
JSONNode result = JSON.Parse (www1.text) //แปลง return ที่ได้มาแล้วแกะข้อมูล;
string realUrl = result ["data"] ["url"]; //เอาข้อมูล data.url มาใช้ยิงอีกครั้ง
WWW www2 = new WWW (realUrl);
yield return www2; //ยิงครั้งที่สอง จะได้ข้อมูลรูปตามปกติ
Material mat = new Material (Resources.Load ("EmptyMaterial", typeof(Material)) as Material);
if (string.IsNullOrEmpty (www2.error))
mat.mainTexture = www2.texture;
else
Debug.LogError ("_loadFacebookProfileImage www2 Error: " + www2.error);
if(texture != null) texture.material = mat;
} else
Debug.LogError ("_loadFacebookProfileImage www1 Error: " + www1.error);
}

เพียงเท่านี้ก็ใช้ได้แล้วครับ

]]>
https://blog.levelup.in.th/2016/11/30/fixing-loading-facebook-profile-picture-error-on-ios-cause-by-url-redirection/feed/ 0
วิธีการแก้ไขปัญหา Unity ไม่รวม AndroidManifest บางตัวให้ https://blog.levelup.in.th/2016/10/31/how-to-fix-merging-androidmanifest-problem-in-unity/ https://blog.levelup.in.th/2016/10/31/how-to-fix-merging-androidmanifest-problem-in-unity/#comments Mon, 31 Oct 2016 13:33:13 +0000 http://blog.levelup.in.th/?p=5920

ในขั้นแรกขออธิบายวิธีการเช็ค AndroidManifest ตัวที่ใช้จริงกันก่อน เนื่องจากในโฟลเดอร์ Plugin > Android ของเราจะมีไฟล์ AndroidManifest.xml อยู่มากมาย ซึ่งตามปกติแล้ว Unity จะทำการรวมไฟล์พวกนี้ให้เป็นไฟล์เดียวไว้ใช้งานจริงบน Run time ซึ่งวิธีการเช็คก็คือ

  • ที่ File > Build Settings… ติ้กเลือก Google Android Project แล้วเลือกโฟลเดอร์

  • โฟลเดอร์ที่ได้ออกมาจะมี AndroidManifest.xml ตัวที่ใช้งานจริง ให้เปิดเช็คดูว่ามี  Tag  ครบตามที่มีทั้งหมดหรือไม่ หรือถ้ารันแล้วตัวไหนพังก็มาเช็คดูว่าขาดตัวไหนไปหรือเปล่า

ซึ่งหลังจากที่เราใช้ POKKT Unity SDK 4.1.1 เราก็ได้พบปัญหาดังกล่าวว่า AndroidManifest.xml ที่สร้างขึ้นมาไม่ยอมรวมเป็น AndroidManifest.xml ตัวหลัก ซึ่งวิธีแก้ไขก็ง่ายๆ Copy  Tag  ที่จำเป็นต้องใช้ แล้วนำไปฝากกับ AndroidManifest.xml ของ Plugin ตัวอื่นๆ ซึ่งจากที่เราทำเราได้เอา Tag ไปฝากไว้กับ Chartboost ซึ่งออกมาก็ได้ผลทีถูกต้อง

]]>
https://blog.levelup.in.th/2016/10/31/how-to-fix-merging-androidmanifest-problem-in-unity/feed/ 0
วิธีทำให้ปุ่มกดไม่ได้โดยที่ไม่เปลี่ยน Sprite เป็น Disabled https://blog.levelup.in.th/2016/09/29/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%97%e0%b8%b3%e0%b9%83%e0%b8%ab%e0%b9%89%e0%b8%9b%e0%b8%b8%e0%b9%88%e0%b8%a1%e0%b8%81%e0%b8%94%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%82/ https://blog.levelup.in.th/2016/09/29/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%97%e0%b8%b3%e0%b9%83%e0%b8%ab%e0%b9%89%e0%b8%9b%e0%b8%b8%e0%b9%88%e0%b8%a1%e0%b8%81%e0%b8%94%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%82/#comments Thu, 29 Sep 2016 13:28:46 +0000 http://blog.levelup.in.th/?p=5873

จากบนลงล่าง กดได้ / กดไม่ได้ / กดไม่ได้

จากรูปด้านบน ปกติแล้วปุ่ม UI Button จะมีอยู่ 3 State คือ Normal / Pressed / Disabled ทีนี้ปุ่มที่โชว์ขณะไม่มีแอคชั่นใดๆก็จะมองเห็นได้อยู่สองแบบคือ Normal กับ Disabled แต่โจทย์คือเราอยากได้แบบที่ 3 คือดูเหมือนปุ่มกดได้ (Normal) แต่ว่าจริงๆแล้วกดไม่ได้ เลยมีวิธีแก้โดยใช้โค๊ดดังนี้ฮะ

Set Sprite ไว้ตามปกติ สีขาว Normal / สีแดง Disabled


if (isLock) //ถ้าล็อค
{
buttonTrans.GetComponent<BoxCollider>().enabled = false; //ปิด BoxCollider
button.enabled = false; //Disable ตัวปุ่มไป โดยจะไม่ใช่ .isEnable ที่จะทำให้ปุ่มนั้นเปลี่ยน state เป็น Disabled
}
else //ถ้าปกติ
{
button.isEnabled = true; //เปลี่ยนกลับเป็น Normal
button.enabled = true; //Enable ตัวปุ่ม
buttonTrans.GetComponent<BoxCollider>().enabled = true; //เปิด BoxCollider
}

ตามโค๊ดด้านบนถ้าเรียง Order ผิดก็จะแสดงผลผิดได้ เพราะแค่ Hover ปุ่มก็จะทำการเช็ค State แล้ว แต่ Order ด้านบนสามารถทำให้ได้ผลลัพธ์ตรงตามความต้องการครับ

]]>
https://blog.levelup.in.th/2016/09/29/%e0%b8%a7%e0%b8%b4%e0%b8%98%e0%b8%b5%e0%b8%97%e0%b8%b3%e0%b9%83%e0%b8%ab%e0%b9%89%e0%b8%9b%e0%b8%b8%e0%b9%88%e0%b8%a1%e0%b8%81%e0%b8%94%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%82/feed/ 0