2016年7月29日 星期五

Unreal: Dynamic Material

since: 2016/07/29
update: 2016/07/29

reference:
1. // Introduction to Unreal Engine Part 8: Adding random assets by Rob Redman


A. 下載專案會用到的檔案:
      > 2150_tid_rock.zip.zip , 解壓縮後得到: rock.obj 檔案

-----------------------------------------------------------------------------------------------

B. 新增專案:
    1. 新增一個 BlankBlueprint 專案

    2. 匯入剛剛的 rock.obj 檔案

    3. > Import All

    4. 結果:

-----------------------------------------------------------------------------------------------

C. 新增給 Rock 使用的 Material:
     1. Add New > Material

     2. 取名為: DIFFUSE , 並雙擊滑鼠以開啟 Material Editor

     3. 新增一個: VectorParameter Node

     4. 取名為: Color(參數名稱), 並與 DIFFUSE Node 的 Base Color Pin 連接.

     5. 新增一個: Constant Node

     6. 並與 DIFFUSE Node 的 Roughness Pin 連接.

     7. 關閉 Material Editor , 雙擊 Rock , 並將其 asset 更改為剛剛的 DIFFUSE Material

-----------------------------------------------------------------------------------------------

D. 新增給 Rock 使用的 Blueprint:

    1. Add New > Blueprint Class

    2. > Actor

    3. 取名為 Rock_BP, 並雙擊滑鼠以開啟 Blueprint Editor 並切換到 Event Graph

    4. 接下來使用到雙螢幕:
        a. 點選 rock

        b. 將其拖拉到 Rock_BPComponents

        c. 結果:

    5. 將 Event BeginPlayCreate Dynamic Material Instance(rock) 連結

    6. 並將其 Source Material 設為 DIFFUSE

    7. 接著, 再將其連結  Set Vector Parameter Value Node:

    8. 連結如下, 並將 Parameter Name 設為 Color(DIFFUSE 裡設定的參數名稱)

    9. 最後, 新增 3 個 Random Float in Range Node 與 1 個 Make Vector Node 連結如下:

-----------------------------------------------------------------------------------------------

E. 回到場景
    1. 將 Rock_BP 拖拉多個到場景

    2. 執行關卡:

-----------------------------------------------------------------------------------------------

F. 產生灰階效果:
    1. 修改 Rock_BP 如下:


    2. 執行關卡:

2016年7月26日 星期二

iOS: Media Player

since: 2016/07/26
update: 2016/07/26

reference:
1. Swift Video Player using AVPlayerViewController

A. 新增專案:
1. iOS > Application > Single View Application > Next


     2. > Next > Create

-----------------------------------------------------------------------------------------------

B. 設定 iOS 支援的最小版本:
     專案 > General > Deployment Target: 8.0

-----------------------------------------------------------------------------------------------

C. 加入多媒體檔:
   1. > 將多媒體檔案拖拉到專案資料夾

    2. > 記得勾選 Copy items if needed
        > Finish

-----------------------------------------------------------------------------------------------

D. 將預設的 View Controller 嵌入到 Navigation Controller 裡:
    1.  > Main.storyboard > 點選右邊 View Controller
         > Editor > Embed In > Navigation Controller

   2. 結果如下:

-----------------------------------------------------------------------------------------------

E. 新增給 ViewController 轉場(segue) 使用的 AV Player ViewController
    1. 將 AVKit Player View Controller 拖拉到 Main.storyboard 裡.

    2. > 點選 ViewController > 按下 Ctrl + 滑鼠左鍵
        > 拖拉到 AV Player ViewController 放開
        > 選取 Manual Segue > Show

    3. 完成後, 右上方出現提示: 需要幫 Segue 設定 ID

    4. 幫此 Segue 設定 ID : seguePlayMedia  


-----------------------------------------------------------------------------------------------

F. 幫 View Controller 的 Navigation Item 設定 Title 名稱:
   
> 在此為: Media Player


-----------------------------------------------------------------------------------------------

G. 新增二個 Button:

     1. 在 View Controller 新增二個 Button: Play Local VideoPlay Local Audio

     2. 新增限制條件:
         > 水平置中

      > 固定寬高, 保持寬高比, 固定與下邊界或上邊界的距離

     > 結果:

-----------------------------------------------------------------------------------------------

H. 開啟 ViewController.swift 修改如下:
import UIKit

//@add #######################

import AVKit
import AVFoundation

//class ViewController: UIViewController {
//@update #######################

class ViewController: UIViewController, AVPlayerViewControllerDelegate {

    //@add #######################
    // url for playing video

    var mediaURL: NSURL!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }


    //@add #######################
    // action - play local video

    @IBAction func playLocalVideo(sender: UIButton) {
       
        // create video url form remote location (i.e. video stored at domain etc.)
        //self.mediaURL = NSURL(string: "http://download.prashantmangukiya.com/SwiftVideoPlayer-Data/Big_Buck_Bunny_Trailer.m4v")
       
        // create video url from local resource (i.e video stored within project folder)

        self.mediaURL = NSBundle.mainBundle().URLForResource("everest", withExtension: "mov")!
       
        // perform segue
        self.performSegueWithIdentifier("seguePlayMedia", sender: self)
    }
   
    //@add #######################
    // action - play Local Audio

    @IBAction func playLocalAudio(sender: UIButton) {
       
        // create audio url form local resource (i.e audio stored within project folder)
        self.mediaURL = NSBundle.mainBundle().URLForResource("popular", withExtension: "mp3")!
       
        // perform segue
        self.performSegueWithIdentifier("seguePlayMedia", sender: self)
    }
   
    //@add #######################
    // MARK: - Navigation function

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
       
        if segue.identifier == "seguePlayMedia" {
           
            // get destination view controller
            let destVc = segue.destinationViewController as! AVPlayerViewController
           
            // set player
            destVc.player = AVPlayer(URL: self.mediaURL)
           
            //@add #######################
            destVc.player?.play() // auto play
        }
    }
   
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}


-----------------------------------------------------------------------------------------------

I. 幫二個 Button 繫結事件:

   1. "Play Local Video" Button -> playLocalVideo IBAction func

   2. "Play Local Audio" Button -> playLocalAudio IBAction func

-----------------------------------------------------------------------------------------------

J. Main.storyboard 結果:


-----------------------------------------------------------------------------------------------

K. 執行程式:
    > 打開 App

      > 按下: Play Local Video

       > 按下: Play Local Audio