If you use the uGUI for making mobile UI Event, perhaps, Your code like below code.

* button script (Example): Mobile has just 3 events. Pressed, Exit from a button (Cancel), Deattached from a button (OK).

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class CommonButton : MonoBehaviour, IPointerDownHandler, IPointerExitHandler, IPointerClickHandler {

GameObject selectedObject;
 
//Process for Selected button
public void OnPointerDown(PointerEventData eventData) {
selectedObject = gameObject;
//Blah blah... something
}

//Process for cancel button
public void OnPointerExit(PointerEventData eventData) {
selectedObject = null;
//Blah blah... something
}

//Process for OK button
public void OnPointerClick(PointerEventData eventData) {
if (selectedObject != gameObject) return;
selectedObject = null;
//Blah blah... something
}
}


Normally, We attach this code @ each button object.
It is terrible for maintenance.

If someone wants to change some behavior, We should change all.

however, we could solve this problem by simple Inheritance.

1. Make a parents class for sharing.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class CommonButton : MonoBehaviour, IPointerDownHandler, IPointerExitHandler, IPointerClickHandler {

 GameObject selectedObject;

 public void OnPointerDown(PointerEventData eventData) {
 selectedObject = gameObject;
 PressedButton();
 }

 public void OnPointerExit(PointerEventData eventData) {
 selectedObject = null;
 CancelButton();
 }

 public void OnPointerClick(PointerEventData eventData) {
 if (selectedObject != gameObject) return;
 selectedObject = null;
 OKButton();
 }

 public virtual void PressedButton() { } //Virtual method is key point
 public virtual void CancelButton() { }
 public virtual void OKButton() { }
}


2. Make a child class for attaching to each button.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BehaviourRadioMenus : CommonButton {

 override public void PressedButton() {
 RevealDesc();
 }

 override public void CancelButton() {
 HideDesc();
 }

 override public void OKButton() {
 HideDesc();
 }

 void RevealDesc() {
 }

 void HideDesc() {
 }
}


Cheers!
2018/03/04 06:27 2018/03/04 06:27
I modified iTween for working  Fade/Color to the uGUI elements such as Text, Image, Textmesh.
and It will work Action<T> Lambda method.

iTween.ValueTo(gameObject, iTween.Hash(
    "from", 1f,
    "to", 0f,
    "time", 1f,
    "onupdate", (System.Action<object>)(x => { missedInfo.color = new Color(1f, 0f, 0f, (float)x); }),
    "oncomplete", (System.Action<object>)(x => missedInfo.gameObject.SetActive(true))
    ));


* Caution: If you didn't install the Textmesh pro, You could see the Error message on Unity3D


Enjoy~

2017/11/17 10:49 2017/11/17 10:49
TAG , ,
@Sun,

First, You should setup meta format in Unity Editor'setup
1.Open Editor setup
사용자 삽입 이미지
2. Change or Check "Version control mode" and "Asset Serialization mode" ("Visible Meta file", "Force Text")
사용자 삽입 이미지
3. Now close Unity3D and open the "Explorer" and Go your source's path. 
4. Remove not necessary folder and files (You need just 2 folders "Assets" and "ProjectSettings" (I just compress it. however, you can move these folders to other media)
사용자 삽입 이미지
* Please let me know what you block something.


2017/10/13 05:10 2017/10/13 05:10
TAG , ,
We had to meet Drawcall problem in Mobile game developing using unity 3D.
You should solve it by 2 combination way.

1. Make shard material.
2. Combine mesh.

I writing down about "Combine mesh"

1. Make next script as CombineChild on Unity3D

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(MeshFilter))]
[RequireComponent(typeof(MeshRenderer))]
public class CombineChild : MonoBehaviour
{
void Start()
{
Matrix4x4 thisTransform = transform.worldToLocalMatrix; 
MeshFilter[] meshFilters = GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length)
{
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = thisTransform * meshFilters[i].transform.localToWorldMatrix;
meshFilters[i].gameObject.SetActive(false);
i++;
}
transform.GetComponent<MeshFilter>().mesh = new Mesh();
transform.GetComponent<MeshFilter>().mesh.CombineMeshes(combine); //, true, true, true);

transform.GetComponent<MeshFilter>().mesh.RecalculateNormals();
transform.gameObject.SetActive(true);
}
}


2. and Please attach to parent gameobject.

Cheers
2017/10/10 02:42 2017/10/10 02:42

first time, Update the code in iTween.cs file

void CallBack(string callbackType){
if (tweenArguments.Contains(callbackType) && !tweenArguments.Contains("ischild")) {
//establish target:
GameObject target;
if (tweenArguments.Contains(callbackType+"target")) {
target=(GameObject)tweenArguments[callbackType+"target"];
}else{
target=gameObject; 
}

/// Start of update
if (tweenArguments[callbackType] is Action<object>)
{
((Action<object>)tweenArguments[callbackType]).Invoke((object)tweenArguments[callbackType + "params"]);
}
else
/// End of update


//throw an error if a string wasn't passed for callback:
if (tweenArguments[callbackType].GetType() == typeof(System.String)) {
target.SendMessage((string)tweenArguments[callbackType],(object)tweenArguments[callbackType+"params"],SendMessageOptions.DontRequireReceiver);
}else{
Debug.LogError("iTween Error: Callback method references must be passed as a String!");
Destroy (this);
}
}
}

Now, You could use the Action<T> delegate in iTween.


iTween.ValueTo(gameObject,
iTween.Hash(
"from", 1f,
"to", 0f,
"time", 1f,
"onupdate", (System.Action<object>)(x => { missedInfo.color = new Color(1f, 0f, 0f, (float)x); }),
"oncomplete", (System.Action<object>)(x => missedInfo.gameObject.SetActive(true))
)
);

 

 

2017/10/06 07:32 2017/10/06 07:32
I am curious why they made UI System complex.
anyway, If you get any event from Event system(on UI), you can choice 2 options.

1. Using EventTrigger 
=> In my thinking, It's so terrible idea.It needs so many manual tasks. So I skip it. 

2. Using EventSystem
=> It's simple. However, I am finding another solution. Because it's not automation by runtime script.

a. add using...
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;


b. inherit from interfaces
public class BehaviorButton : MonoBehaviour, IPointerEnterHandler {

}


c. add Method
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;

public class BehaviorButton : MonoBehaviour, IPointerEnterHandler {
    public void OnPointerEnter(PointerEventData eventData) 
    {
 
    }
}


You can find it on unity's manual. (https://docs.unity3d.com/Manual/SupportedEvents.html)

IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
IPointerExitHandler - OnPointerExit - Called when a pointer exits the object

IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)

IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object

IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values
IBeginDragHandler - OnBeginDrag - Called on the drag object when dragging is about to begin
IDragHandler - OnDrag - Called on the drag object when a drag is happening
IEndDragHandler - OnEndDrag - Called on the drag object when a drag finishes
IDropHandler - OnDrop - Called on the object where a drag finishes

IScrollHandler - OnScroll - Called when a mouse wheel scrolls

IUpdateSelectedHandler - OnUpdateSelected - Called on the selected object each tick

ISelectHandler - OnSelect - Called when the object becomes the selected object
IDeselectHandler - OnDeselect - Called on the selected object becomes deselected

IMoveHandler - OnMove - Called when a move event occurs (left, right, up, down, ect)

ISubmitHandler - OnSubmit - Called when the submit button is pressed
ICancelHandler - OnCancel - Called when the cancel button is pressed

* 영어 울렁증 가지고 계신분들께 죄송 -_-;; 
* 영어 연습겸 블로그에 영어로 작성중입니다.

2017/09/25 08:06 2017/09/25 08:06
* Prepare: Windows

1. Download Java JDK : http://www.oracle.com/technetwork/java ··· 151.html2. Install JDK
3. Open control panel
4. Open system path & Variable (Environment variable)
   a. search & run control panel.
   b. click System.
   c. click Advanced System setting.
5. create new system variable.
   a. JAVA_HOME: {Java JDK Path} (for example: D:\Program Files (x86)\Java\jdk1.8.0_25)
   b. CLASS_PATH: %JAVA_HOME%\lib
   c. PATH (just add new value): %JAVA_HOME%\bin
6. Download & Install Android Studio : https://developer.android.com/studio/index.html
7. Open Unity3d and Open Preferences
8. Click External Tool tab
9. Setup JDK / Android and NDK

Done

   

2017/09/13 17:28 2017/09/13 17:28
슈팅게임으로 만들었어요.

소스 다운로드
강의자료

요즘 집필중이라서 정신이 하나도 없습니다. 
부실한 자료지만 참고하시기 바랍니다.


2017/01/04 15:30 2017/01/04 15:30

많은 인디 개발자 또는 프로개발자 조차도 모바일 UX를 지키지 않고 그냥 개발하고 있어 안타깝더군요.

PC 마우스 UX의 경우는

- Hover In / Out
- Click
- Double Click 

이렇게 이벤트를 먹이지만, 

모바일의 경우는 
- Pressed 
- Unpressed 로

- Press 됐을때 버튼을 확대하고
- 만약 사용자가 버튼 영역을 벗어나서 손을 떼면 원상복귀되면서 명령이 취소됩니다.
- 만약 사용자가 버튼 영역을 벗어나지 않고 손을 떼면 원상복귀되면서 명령이 실행됩니다.

일전에 작성했던 이벤트 통합하기로 구현하였으니 참고하시고 다음 소스를 보시면 이해가 쉬우실거 같네요.

참고 링크 : http://www.wolfpack.pe.kr/909


먼저 버튼을 2개 만들어 놓으시고 이벤트 통합용 스크립트는 다음과 같습니다.

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class UIManager_Intro : MonoBehaviour {

    const float workTerm = 0.2f;

    public static UIManager_Intro instance;
    public void Awake()
    {
        UIManager_Intro.instance = this;
     }

     private void SetScaleUp(GameObject _obj, bool isPressed)
     {
         if (isPressed)
         {
             iTween.ScaleTo(_obj, new Vector3(1.1f, 1.1f, 1.1f), workTerm);
         }
         else
         { 
             iTween.ScaleTo(_obj, new Vector3(1f, 1f, 1f), workTerm);
         }
     }

     private bool DetectHoverSameObject(GameObject _obj)
     {
         RaycastHit hit;
         Ray ray = NGUITools.FindCameraForLayer(_obj.layer).ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit, Mathf.Infinity))
         {
             return (hit.collider.gameObject == _obj);
         }
         return false;
     }

     public void Button1_OnPress(GameObject _obj, bool isPressed)
     {
         SetScaleUp(_obj, isPressed);
         if (!isPressed && DetectHoverSameObject(_obj)) StartCoroutine(LoadingScene("usingAnchor"));
    }
 
    public void Button2_OnPress(GameObject _obj, bool isPressed)
     {
         SetScaleUp(_obj, isPressed);
         if (!isPressed && DetectHoverSameObject(_obj)) StartCoroutine(LoadingScene("inputField"));
     }

     IEnumerator LoadingScene(string _sceneName)
     {
         yield return new WaitForSeconds(workTerm);
         SceneManager.LoadScene(_sceneName);
     }
}


버튼1에만 우선 적용합니다. 스크립트는 다음과 같습니다. 
using UnityEngine;
using System.Collections;

public class Behavior_Button1 : MonoBehaviour {

    void Start () {
        UIEventListener.Get(gameObject).onPress += UIManager_Intro.instance.Button1_OnPress;
    }
}



결과 1. 마우스를 클릭하여 Press 시뮬레이팅
사용자 삽입 이미지
결과2. 취소 (드레그하여 다른곳에서 손 뗌)
사용자 삽입 이미지
결과 3. 명령실행 (원상복귀후 다른씬으로 이동)
사용자 삽입 이미지


2016/09/22 09:23 2016/09/22 09:23
간만에 유니티3D 관련 글을 쓰네요.

몇 번의 프로젝트에서 사용했던 티끌 같은 팁인데 많은 분들이 모르시는 것같아 소스 하나 남겨둡니다.

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

    // Use this for initialization
    IEnumerator Start () {

        //for Lambda
        StartCoroutine(ReturnValue( (x) => 
        {
            Debug.Log(x);
        } 
        ));

         //for local value
        int a = 0;
        yield return StartCoroutine(ReturnValue( (x) => 
        {
            a = x;
        }
        ));
        Debug.Log(a);
    }
 
    IEnumerator ReturnValue(System.Action<int> callback)
    {
        yield return null;
        callback(10);
    }
}


핵심은 Lambda 식으로 callback 함수를 구현하는 겁니다. =)
로컬 변수에 값을 할당할때는 반듯이 yield return 명령으로 Coroutine 함수가 종료되고나서 값이 할당됐는지 확인되어야 합니다. (그럼 코루틴 쓰는 의미가.. -_-;;)


2016/04/04 17:00 2016/04/04 17:00