블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2738)
Unity3D (817)
Script (91)
Extensions (14)
Effect (3)
NGUI (77)
UGUI (8)
Physics (2)
Shader (36)
Math (1)
Design Pattern (2)
Xml (1)
Tips (200)
Link (22)
World (1)
AssetBundle (25)
Mecanim (2)
Plugins (70)
Trouble Shooting (68)
Encrypt (7)
LightMap (4)
Shadow (4)
Editor (8)
Crash Report (3)
Utility (9)
UnityVS (2)
Facebook SDK (2)
iTween (3)
Font (11)
Ad (14)
Photon (2)
IAP (1)
Google (8)
Android (45)
iOS (41)
Programming (475)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
05-02 20:34


http://answers.unity3d.com/questions/55512/Does-AssetBundle-on-Android-work-well-.html     : Android Asset Bundle

 

다음과 같이 에디터 오퍼레이션으로  Assetbundle 을 만드는데...

BuildPipeline 에서 무조건  플랫폼을 정해 줘야 한다.

 

 


//#if !UNITY_ANDROID

using UnityEngine;
using UnityEditor;
public class ExportAssetBundles { 
    [MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]  
    static void ExportResource () { 
        // Bring up save panel 
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) {
            // Build the resource file from the active selection. 
            Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
            BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,BuildTarget.Android);   // 
            Selection.objects = selection;   
        } 
    } 
    [MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")] 
    static void ExportResourceNoTrack () {
        // Bring up save panel  
        string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
        if (path.Length != 0) { 
            // Build the resource file from the active selection. 
            BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path); 
        }  
    }
}
//#endif

 

 

 


        if (m_goPatchingScenePrefab.GetComponent<PatchingTesting>().m_nVersion < 2)
        {
            // Patching Update.......


           // WWW www = new WWW("http://192.168.0.40/ppp2.unity3d");

 

 

           WWW www =  WWW.LoadFromCacheOrDownload("http://192.168.0.40/ppp2.unity3d",2);
           

            //            www.uploadProgress

            /*while(!www.isDone)
            {


                        yield return 0;
            }
            */
            //  yeild retrun www.;


            yield return www;

 

 


            Debug.Log("Down Load Done!!");
            //    Instantiate(www.assetBundle.mainAsset);
            m_bDownloaded = true;
            //        Instantiate(www.assetBundle.mainAsset);

            //    www.assetBundle.LoadAll();


            m_goPatchingScenePrefab = (GameObject)www.assetBundle.Load("PatchingContests");

 

 

        }
       


            Instantiate(m_goPatchingScenePrefab);

 

 

 

 

IIS  설정 후....

 

1.  MIME 에 ~.unity3d를 추가 해야 한다.

2. crossdomain.xml 이 최 상위에 있어야 하는데...이건 만들어야 한다.

 

 

 

 

내용은...

 

인데....자세한 설명은

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*"/>
</cross-domain-policy>
 

 

http://docs.unity3d.com/Documentation/Manual/SecuritySandbox.html

 

이곳에 있다.



[출처] Assetbundle 을 이용한 업데이트 시스템|작성자 timyman


반응형
Posted by blueasa
, |

Unity Singleton

Unity3D/Script / 2013. 3. 11. 10:58

Example :

GameMaster.cs

public class GameMaster : MonoSingleton< GameMaster >
{
    public int difficulty = 0;
    public override void Init(){ difficulty = 5; }
}

OtherClass.cs

You forgot a "using UnityEngine;" fixed. :P

using UnityEngine;
public class OtherClass: MonoBehaviour
{
    void Start(){ print( GameMaster.instance.difficulty ); } // 5
}

The code :

using UnityEngine;
public abstract class MonoSingleton<T> : MonoBehaviour where T : MonoSingleton<T>
{
    private static T m_Instance = null;
    public static T instance
    {
        get
        {
            // Instance requiered for the first time, we look for it
            if( m_Instance == null )
            {
                m_Instance = GameObject.FindObjectOfType(typeof(T)) as T;
 
                // Object not found, we create a temporary one
                if( m_Instance == null )
                {
                    Debug.LogWarning("No instance of " + typeof(T).ToString() + ", a temporary one is created.");
                    m_Instance = new GameObject("Temp Instance of " + typeof(T).ToString(), typeof(T)).GetComponent<T>();
 
                    // Problem during the creation, this should not happen
                    if( m_Instance == null )
                    {
                        Debug.LogError("Problem during the creation of " + typeof(T).ToString());
                    }
                }
                m_Instance.Init();
            }
            return m_Instance;
        }
    }
    // If no other monobehaviour request the instance in an awake function
    // executing before this one, no need to search the object.
    private void Awake()
    {
        if( m_Instance == null )
        {
            m_Instance = this as T;
            m_Instance.Init();
        }
    }
 
    // This function is called when the instance is used the first time
    // Put all the initializations you need here, as you would do in Awake
    public virtual void Init(){}
 
    // Make sure the instance isn't referenced anymore when the user quit, just in case.
    private void OnApplicationQuit()
    {
        m_Instance = null;
    }
}


출처 : http://wiki.unity3d.com/index.php/Singleton

반응형
Posted by blueasa
, |

NavMeshAgent.updatePosition = false;    // 포지션 업데이트 할 지..

NavMeshAgent.updateRotation = false;    // 로테이션 업데이트 할 지..


NavMesh를 쓰는 데, 파괴 가능한 오브젝트를 설치해야 되는데..


오브젝트와 충돌해서 지나가진 못하고, 파괴는 가능하게 하려니 오브젝트가 캐릭터에 의해 밀려다녀서 방법을 찾아보던 중..


NavMeshAngent에 포지션 업데이트 여부 셋팅 변수가 있다.


쓰자.. ㅡ_ㅡ;

반응형
Posted by blueasa
, |

  1. #pragma warning disable 0168 // variable declared but not used.
  2. #pragma warning disable 0219 // variable assigned but not used.
  3. #pragma warning disable 0414 // private field assigned but not used.


출처 : http://answers.unity3d.com/questions/21796/disable-warning-messages.html

반응형
Posted by blueasa
, |

1. 우선 새로 보여질 카메라를 하나 만든다.

2. 새 카메라의 Depth는 메인 카메라의 Depth보다 낮아야 된다.(같거나 높으면 메인 창에서도 새 카메라를 사용해버림)

3. 아래에서 m_strQuaterViewerName 은 카메라 오브젝트 이름이다. 임의로 집어넣게 만들어 놨음..

4. QuarterViewer.cs 스크립트는 Project 탭의 Editor 폴더 하위에 들어가야 한다.(에디트 시 사용될 스크립트라서..)


P.s. 예제에서는 RenderTextureFormat.ARGB32를 썼는데 Depth 문제가 있어서 RenderTextureFormat.Depth 로 고쳤다.


1 using UnityEngine; 2 using UnityEditor; 3 4 public class QuarterViewer : EditorWindow 5 { 6 private static EditorWindow editorWindow; 7 8 private string m_strQuaterViewerName; 9 private Camera m_camQuaterViewer; 10 private RenderTexture m_RenderTexture; 11 12 [MenuItem("Camera/Quarter Viewer")] 13 static void Init() 14 { 15 editorWindow = GetWindow(typeof(QuarterViewer)); 16 editorWindow.autoRepaintOnSceneChange = true; 17 editorWindow.Show(); 18 } 19 public void Awake() 20 { 21 m_RenderTexture = new RenderTexture((int)position.width, 22 (int)position.height, 23 (int)RenderTextureFormat.Depth); 24 25 m_strQuaterViewerName = "Camera - QuarterViewer"; 26 if (GameObject.Find(m_strQuaterViewerName)) 27 { 28 m_camQuaterViewer = GameObject.Find(m_strQuaterViewerName).GetComponent<Camera>(); 29 if (null == m_camQuaterViewer) 30 { 31 Debug.Log("Can't Find 'Camera - QuarterView'"); 32 } 33 } 34 } 35 public void Update() 36 { 37 if (null != m_camQuaterViewer && null != m_RenderTexture) 38 { 39 m_camQuaterViewer.targetTexture = m_RenderTexture; 40 m_camQuaterViewer.Render(); 41 m_camQuaterViewer.targetTexture = null; 42 43 if (m_RenderTexture.width != position.width || 44 m_RenderTexture.height != position.height) 45 { 46 m_RenderTexture = new RenderTexture((int)position.width, 47 (int)position.height, 48 (int)RenderTextureFormat.Depth); 49 } 50 } 51 } 52 void OnGUI() 53 { 54 if (null != m_camQuaterViewer && null != m_RenderTexture) 55 { 56 GUI.DrawTexture(new Rect(0.0f, 0.0f, position.width, position.height), m_RenderTexture); 57 } 58 59 } 60 }


[참조]

http://blueasa.tistory.com/943

http://docs.unity3d.com/Documentation/ScriptReference/EditorWindow-autoRepaintOnSceneChange.html

http://docs.unity3d.com/Documentation/ScriptReference/RenderTextureFormat.html


반응형
Posted by blueasa
, |

You can create a window in your gui with Gui.Windowhttp://unity3d.com/support/documentation/ScriptReference/GUI.Window.html?from=EditorWindow

Have the window you just made contain a RenderTexture.http://unity3d.com/support/documentation/Components/class-RenderTexture.html


http://unity3d.com/support/documentation/ScriptReference/EditorWindow-autoRepaintOnSceneChange




출처 : http://answers.unity3d.com/questions/33858/how-to-create-an-editor-screenview-like-camera-pre.html




반응형
Posted by blueasa
, |

1 if(Input.GetAxis("Mouse ScrollWheel") < 0) 2 { 3 // Zoom In 4 } 5 6 if(Input.GetAxis("Mouse ScrollWheel") > 0) 7 { 8 // Zoom Out 9 }




참조 : http://devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=14508&sca=UNITY&sfl=wr_subject%7C%7Cwr_content&stx=%EB%A7%88%EC%9A%B0%EC%8A%A4+%ED%9C%A0&sop=and&currentId=44

반응형
Posted by blueasa
, |

[사용 함수]

Camera.WorldToViewportPoint()

Camera.ViewportToWorldpoint()


1 public void pushObjectBackInFrustum(Transform obj) 2 { 3 Vector3 pos = Camera.main.WorldToViewportPoint(obj.position); 4 5 if(pos.x < 0f) 6 pos.x = 0f; 7 8 if(pos.x > 1f) 9 pos.x = 1f; 10 11 if(pos.y < 0f) 12 pos.y = 0f; 13 14 if(pos.y > 1f) 15 pos.y = 1f; 16 17 obj.position = Camera.main.ViewportToWorldPoint(pos); 18 }



참조 : http://forum.unity3d.com/threads/7069-Keeping-things-inside-the-camera-frustum

반응형
Posted by blueasa
, |

Well, just take the example from the GUI slider reference and from Animation.Sample and you're done.

  1. private var hSliderValue : float = 0.0;
  2. private var myAnimation : AnimationState;
  3.  
  4. function Start(){
  5. myAnimation = animation["MyClip"];
  6. }
  7.  
  8. function LateUpdate() {
  9. myAnimation.time = hSliderValue;
  10. myAnimation.enabled = true;
  11.  
  12. animation.Sample();
  13. myAnimation.enabled = false;
  14. }
  15.  
  16. function OnGUI() {
  17. hSliderValue = GUILayout.HorizontalSlider (hSliderValue, 0.0, myAnimation.length,GUILayout.Width(100.0f));
  18. }



출처 : http://answers.unity3d.com/questions/59406/using-gui-slider-to-control-animation-on-object.html

반응형

'Unity3D > Script' 카테고리의 다른 글

마우스 휠 스크롤 확인  (0) 2013.01.31
오브젝트 카메라 프러스텀 안에 가두기  (0) 2013.01.29
InGame Button  (0) 2012.12.14
InvokeRepeating  (0) 2012.12.07
DisplayWizard(에디터로 쓸모가 많을 듯 한..)  (0) 2012.12.04
Posted by blueasa
, |

InGame Button

Unity3D/Script / 2012. 12. 14. 22:27
추가 : 내가 잘못 쓰는지는 모르겠지만, 게임 내 어디에 있냐에 따라서 클릭이 되고 안되고 해서..좀 더 알아봐야 될 것 같다..

Button

Author: Jonathan Czeck (aarku)

Contents

 [hide

Description

This script uses a GUITexture and Unity mouse events to implement a regular push button that behaves properly like Mac OS X.

Warning: As of Unity 3.0.0, this script does not work on iOS devices, as OnMouseUp functions and the like do not work on iOS devices. Use the iPhone compatible version further below.

Usage

Attach this script to a GUITexture object. Add a ButtonPressed function to the object pointed to by the messageevariable to catch when the button has been pressed. (You can change the name of the function by changing themessage variable.)

JavaScript - Button.js

 var normalTexture : Texture;
 var hoverTexture : Texture;
 var pressedTexture : Texture;
 var messagee : GameObject;
 var message = "ButtonPressed";
 
 private var state = 0;
 private var myGUITexture : GUITexture;
 
 myGUITexture = GetComponent(GUITexture); 
 
 function OnMouseEnter()
 {
    state++;
    if (state == 1)
        myGUITexture.texture = hoverTexture;
 }
 
 function OnMouseDown()
 {
    state++;
    if (state == 2)
        myGUITexture.texture = pressedTexture;
 }
 
 function OnMouseUp()
 {
    if (state == 2)
    {
        state--;
        if (messagee)
            messagee.SendMessage(message, gameObject);
    }
    else
    {
        state --;
        if (state < 0)
            state = 0;
    }
    myGUITexture.texture = normalTexture;
 }
 
 function OnMouseExit()
 {
    if (state > 0)
        state--;
    if (state == 0)
        myGUITexture.texture = normalTexture;
 }

C# - Button.cs

The C# version is a bit different from the JS version. It shows off some new features in Unity 1.2 for automatically attaching the GUITexture component when attaching the Button (using the RequireComponent attribute) and placing the Button in a custom submenu in the Components menu (using the AddComponentMenu attribute.)

It also groups the textures together into a separate object and has a separate method for changing the texture to ease customisation. Note that some properties and methods are marked protected and/or virtual to make it possible to customise the Button class by creating a new subclass. See the ToggleButton snippet for an example on how to subclass the Button class.

using UnityEngine;
using System.Collections;
 
public enum ButtonState {
    normal,
    hover,
    armed
}
 
[System.Serializable] // Required so it shows up in the inspector 
public class ButtonTextures {
    public Texture normal=null;
    public Texture hover=null;
    public Texture armed=null;
    public ButtonTextures() {}
 
    public Texture this [ButtonState state] {
        get {
            switch(state) {
                case ButtonState.normal:
                    return normal;
                case ButtonState.hover:
                    return hover;
                case ButtonState.armed:
                    return armed;
                default:
                    return null;
            }
        }
    }
}
 
 
[RequireComponent(typeof(GUITexture))]
[AddComponentMenu ("GUI/Button")]    
public class Button : MonoBehaviour {
 
    public GameObject messagee;
    public string message = "ButtonPressed";
    public ButtonTextures textures;
 
    protected int state = 0;
    protected GUITexture myGUITexture;
 
    protected virtual void SetButtonTexture(ButtonState state) {
        myGUITexture.texture=textures[state];
    }
 
    public virtual void Reset() {
        messagee = gameObject;
        message = "ButtonPressed";
    }
 
    public virtual void Start() {
        myGUITexture = GetComponent(typeof(GUITexture)) as GUITexture; 
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseEnter()
    {
        state++;
        if (state == 1)
            SetButtonTexture(ButtonState.hover);
    }
 
    public virtual void OnMouseDown()
    {
        state++;
        if (state == 2)
            SetButtonTexture(ButtonState.armed);
    }
 
    public virtual void OnMouseUp()
    {
        if (state == 2)
        {
            state--;
            if (messagee != null)
                messagee.SendMessage(message, this);
        }
        else
        {
            state --;
            if (state < 0)
                state = 0;
        }
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseExit()
    {
        if (state > 0)
            state--;
        if (state == 0)
            SetButtonTexture(ButtonState.normal);
    }
}


C# - Button.cs (iPhone Compatible)

Same as the C# version above, but added support for recognizing touch input from iPhone or Android devices. Also adds callback function for when the button is double-clicked/double-tapped.

using UnityEngine;
using System.Collections;
 
public enum ButtonState
{
    normal,
    hover,
    armed
}
 
[System.Serializable] // Required so it shows up in the inspector 
public class ButtonTextures
{
    public Texture normal=null;
    public Texture hover=null;
    public Texture armed=null;
    public ButtonTextures() {}
 
    public Texture this [ButtonState state]
	{
        get
		{
            switch(state)
			{
                case ButtonState.normal:
                    return normal;
                case ButtonState.hover:
                    return hover;
                case ButtonState.armed:
                    return armed;
                default:
                    return null;
            }
        }
    }
}
 
 
[RequireComponent(typeof(GUITexture))]
[AddComponentMenu ("GUI/Button")]    
public class GuiButton : MonoBehaviour
{
    public GameObject messagee;
    public string message = "";
	public string messageDoubleClick = "";
    public ButtonTextures textures;
 
    protected int state = 0;
    protected GUITexture myGUITexture;
 
	private int clickCount = 1;
	private float lastClickTime = 0.0f;
	static private float doubleClickSensitivity = 0.5f;
 
    protected virtual void SetButtonTexture(ButtonState state)
	{
		if (textures[state] != null)
		{
        	myGUITexture.texture = textures[state];
		}
    }
 
    public virtual void Reset()
	{
        messagee = gameObject;
        message = "";
		messageDoubleClick = "";
    }
 
	public bool HitTest(Vector2 pos)
	{
		return myGUITexture.HitTest(new Vector3(pos.x, pos.y, 0));
	}
 
    public virtual void Start()
	{
        myGUITexture = GetComponent(typeof(GUITexture)) as GUITexture; 
        SetButtonTexture(ButtonState.normal);
    }
 
    public virtual void OnMouseEnter()
    {
        state++;
        if (state == 1)
            SetButtonTexture(ButtonState.hover);
    }
 
    public virtual void OnMouseDown()
    {
        state++;
        if (state == 2)
            SetButtonTexture(ButtonState.armed);
    }
 
    public virtual void OnMouseUp()
    {
		if (Time.time - lastClickTime <= doubleClickSensitivity)
		{
			++clickCount;
		}
		else
		{
			clickCount = 1;
		}
 
        if (state == 2)
        {
            state--;
			if (clickCount == 1)
			{
				if (messagee != null && message != "")
				{
					messagee.SendMessage(message, this);
				}
			}
			else
			{
				if (messagee != null && messageDoubleClick != "")
				{
					messagee.SendMessage(messageDoubleClick, this);
				}
			}
        }
        else
        {
            state --;
            if (state < 0)
                state = 0;
        }
        SetButtonTexture(ButtonState.normal);
		lastClickTime = Time.time;
    }
 
    public virtual void OnMouseExit()
    {
        if (state > 0)
            state--;
        if (state == 0)
            SetButtonTexture(ButtonState.normal);
    }
 
#if (UNITY_IPHONE || UNITY_ANDROID)
	void Update()
	{
		int count = Input.touchCount;
		for (int i = 0; i < count; i++)
		{
			Touch touch = Input.GetTouch(i);
			if (HitTest(touch.position))
			{
				if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
				{
					SetButtonTexture(ButtonState.normal);
				}
				else
				{
					SetButtonTexture(ButtonState.armed);
				}
				if (touch.phase == TouchPhase.Began)
				{
					if (touch.tapCount == 1)
					{
						if (messagee != null && message != "")
						{
							messagee.SendMessage(message, this);
						}
					}
					else if (touch.tapCount == 2)
					{
						if (messagee != null && messageDoubleClick != "")
						{
							messagee.SendMessage(messageDoubleClick, this);
						}
					}
				}
				break;
			}
		}
	}
#endif
}



출처 : http://wiki.unity3d.com/index.php/Button

반응형
Posted by blueasa
, |