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

카테고리

분류 전체보기 (2738)
Unity3D (817)
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-05 21:38

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
, |

유니티 종료 시 호출되는 함수..


OnApplicationQuit()


참조 : http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnApplicationQuit.html



아래는 소스 사용 참고..


 IMPORTANT: This function has no effect on iPhone. Application can not prevent termination under iPhone OS.

(주의 : 아이폰에서는 CancelQuit()는 적용되지 않는다고 함. iOS는 프로그램의 종료를 방해할 수 없다고 함.)


1 using UnityEngine; 2 using System.Collections; 3 4 public class example : MonoBehaviour { 5 public float showSplashTimeout = 2.0F; 6 private bool allowQuitting = false; 7 void Awake() { 8 DontDestroyOnLoad(); 9 } 10 void OnApplicationQuit() { 11 if (Application.loadedLevelName.ToLower() != "finalsplash") 12 StartCoroutine("DelayedQuit"); 13 14 if (!allowQuitting) 15 Application.CancelQuit(); 16 17 } 18 IEnumerator DelayedQuit() { 19 Application.LoadLevel("finalsplash"); 20 yield return new WaitForSeconds(showSplashTimeout); 21 allowQuitting = true; 22 Application.Quit(); 23 } 24 }



출처 : http://docs.unity3d.com/Documentation/ScriptReference/Application.CancelQuit.html



OnApplicationPause()

게임 밖으로 나갈 때 호출되는 함수


참조 : http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnApplicationPause.html

반응형
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
, |

링크 : http://forum.unity3d.com/threads/159693-GenerateSecondaryUVSet-destroying-mesh



Answering to my own thread here.

It seems like the MeshMerger script from the wiki itself was causing this trouble. On fourth thought and investigation it seems like copying of triangles and vertices is kind of buggy in the script, so finally I also saw some lonesome vertices flowing in the world after combining. Therefore it might not be the best idea to use that script at all.

Nevertheless, the CombineChildren script from the Standard Assets turned out to be a much better basis to work with. I've rewritten parts of it now to suit my needs, which basically is generating the combined static geometry in the editor and being able to generate lightmaps for this as well. Works like a charm!

I've seen this topic multiple times in the community without a real solution, so it might be a good idea to have a script ready for this. No big adjustment, but I hope it helps some people out there. Here it is, use it as you wish.

CombineChildrenAdvanced.cs
Usage: Place this anywhere in your project and attach it to the parent gameObject containing the other meshes to be combined.
Basically it delivers the very same feature as the standard CombineChildren script, yet it needs to be executed in the editor.
By default it'll automatically generate the lightmapping UVs for the combined geometry. If you don't want this to happen, either use the CombineChildren.cs from the Standard Assets, or uncheck the corresponding checkbox.
If you want to split geometry up again, just use the corresponding button. It'll reset everything accordingly.

Code:  
  1. using UnityEngine;
  2. using System.Collections;
  3. /*
  4. Attach this script as a parent to some game objects. Then by using the corresponding controls you may generate combined meshes (with lightmapping UVs).
  5. This is useful as a performance optimization since it is faster to render one big mesh than many small meshes. See the docs on graphics performance optimization for more info.
  6.  
  7. Different materials will cause multiple meshes to be created, thus it is useful to share as many textures/material as you can.
  8. NOTE: Using multiple materials may break things due to lightmapping generation. So lightmapping UVs as well as splitting the combined geometry is not supported.
  9. Workaround: Create hierarchies in which the children only have exactly one material.
  10. */
  11.  
  12. [AddComponentMenu("Mad Vulture Games/Combine Children 1.5")]
  13. public class CombineChildrenAdvanced : MonoBehaviour {
  14.    
  15.     /// Usually rendering with triangle strips is faster.
  16.     /// However when combining objects with very low triangle counts, it can be faster to use triangles.
  17.     /// Best is to try out which value is faster in practice.
  18.     public bool generateTriangleStrips = true;
  19.     public bool generateLightmappingUVs = true;
  20.     public bool isCombined = false;
  21.    
  22.     public void Combine() {
  23.         Component[] filters  = GetComponentsInChildren(typeof(MeshFilter));
  24.        
  25.         if (filters.Length <= 1) {
  26.             Debug.LogWarning ("Not enough meshes to combine!");
  27.             return;
  28.         }
  29.        
  30.         Matrix4x4 myTransform = transform.worldToLocalMatrix;
  31.         Hashtable materialToMesh= new Hashtable();
  32.        
  33.         for (int i=0;i<filters.Length;i++) {
  34.             MeshFilter filter = (MeshFilter)filters[i];
  35.             Renderer curRenderer  = filters[i].renderer;
  36.             MeshCombineUtility.MeshInstance instance = new MeshCombineUtility.MeshInstance ();
  37.             instance.mesh = filter.sharedMesh;
  38.             if (curRenderer != null && curRenderer.enabled && instance.mesh != null) {
  39.                 instance.transform = myTransform * filter.transform.localToWorldMatrix;
  40.                
  41.                 Material[] materials = curRenderer.sharedMaterials;
  42.                 for (int m=0;m<materials.Length;m++) {
  43.                     instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);
  44.    
  45.                     ArrayList objects = (ArrayList)materialToMesh[materials[m]];
  46.                     if (objects != null) {
  47.                         objects.Add(instance);
  48.                     }
  49.                     else
  50.                     {
  51.                         objects = new ArrayList ();
  52.                         objects.Add(instance);
  53.                         materialToMesh.Add(materials[m], objects);
  54.                     }
  55.                 }
  56.                
  57.                 curRenderer.enabled = false;
  58.             }
  59.         }
  60.    
  61.         foreach (DictionaryEntry de  in materialToMesh) {
  62.             ArrayList elements = (ArrayList)de.Value;
  63.             MeshCombineUtility.MeshInstance[] instances = (MeshCombineUtility.MeshInstance[])elements.ToArray(typeof(MeshCombineUtility.MeshInstance));
  64.  
  65.             // We have a maximum of one material, so just attach the mesh to our own game object
  66.             if (materialToMesh.Count == 1)
  67.             {
  68.                 // Make sure we have a mesh filter & renderer
  69.                 if (GetComponent(typeof(MeshFilter)) == null)
  70.                     gameObject.AddComponent(typeof(MeshFilter));
  71.                 if (!GetComponent("MeshRenderer"))
  72.                     gameObject.AddComponent("MeshRenderer");
  73.    
  74.                 MeshFilter filter = (MeshFilter)GetComponent(typeof(MeshFilter));
  75.                 filter.mesh = MeshCombineUtility.Combine(instances, generateTriangleStrips);
  76.                 renderer.material = (Material)de.Key;
  77.                 renderer.enabled = true;
  78.             }
  79.             // We have multiple materials to take care of, build one mesh / gameobject for each material
  80.             // and parent it to this object
  81.             else
  82.             {
  83.                 GameObject go = new GameObject("Combined mesh");
  84.                 go.transform.parent = transform;
  85.                 go.transform.localScale = Vector3.one;
  86.                 go.transform.localRotation = Quaternion.identity;
  87.                 go.transform.localPosition = Vector3.zero;
  88.                 go.AddComponent(typeof(MeshFilter));
  89.                 go.AddComponent("MeshRenderer");
  90.                 go.renderer.material = (Material)de.Key;
  91.                 MeshFilter filter = (MeshFilter)go.GetComponent(typeof(MeshFilter));
  92.                 filter.mesh = MeshCombineUtility.Combine(instances, generateTriangleStrips);
  93.             }
  94.         }
  95.        
  96.         isCombined = true;
  97.     }
  98. }






CombineChildrenAdvancedEditor.cs
Usage: Place this in your Assets/Editor folder, it actually contains the main part of it.

Code:  
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. [CustomEditor(typeof(CombineChildrenAdvanced))]
  6. public class CombineChildrenAdvancedEditor : Editor {
  7.  
  8.     CombineChildrenAdvanced _target;
  9.    
  10.     void OnEnable() {
  11.         _target = (CombineChildrenAdvanced)target;
  12.     }
  13.    
  14.    
  15.    
  16.     public override void OnInspectorGUI() {
  17.        
  18.        
  19.         _target.generateTriangleStrips = EditorGUILayout.Toggle("Generate Triangle Strips", _target.generateTriangleStrips);
  20.         _target.generateLightmappingUVs = EditorGUILayout.Toggle ("Generate Lightmapping UVs", _target.generateLightmappingUVs);
  21.        
  22.         if (!_target.isCombined) {
  23.             if (GUILayout.Button ("Combine now (May take a while!)")) {
  24.                 _target.Combine();
  25.                
  26.                 if (_target.generateLightmappingUVs) {
  27.                     GenerateLightmappingUVs();
  28.                 }
  29.             }
  30.         }
  31.        
  32.         if (_target.isCombined) {
  33.             if (GUILayout.Button ("Generate Lightmap UVs")) {
  34.                 GenerateLightmappingUVs();
  35.             }
  36.            
  37.             if (GUILayout.Button ("Split Mesh")) {
  38.                 DestroyImmediate(_target.GetComponent (typeof(MeshFilter)));
  39.                 DestroyImmediate(_target.GetComponent (typeof(MeshRenderer)));
  40.                
  41.                 foreach (MeshRenderer mr in _target.GetComponentsInChildren(typeof(MeshRenderer))) {
  42.                     mr.enabled = true;
  43.                 }
  44.                
  45.                 _target.isCombined = false;
  46.             }
  47.         }
  48.     }
  49.    
  50.    
  51.    
  52.    
  53.     void GenerateLightmappingUVs() {
  54.         MeshFilter mf = _target.GetComponent(typeof(MeshFilter)) as MeshFilter;
  55.        
  56.         // make null check because if not enough meshes are present no combined mesh would have been created!
  57.         if (mf != null) {
  58.         }
  59.     }
  60.    
  61. }

Note: While the script still gives you the opportunity to use it with meshes with multiple materials (which will effectively generate multiple new gameObjects), this is not supported in this version, you might get errors. If you need that, feel free to build that yourself or let me know, shouldn't be hard to add.

반응형
Posted by blueasa
, |

작업하던 도중 모바일에선 경로가 파일경로가 바뀌고 읽어오지못하는 문제가 발생하였다.

pc에선 잘되지만 모바일에서만 이상이있었음

찾다 찾다 유니티 포럼에서 좋은거 긁어왔습니다. ㅋㅋ 아이폰도 됩니다~

 

 

1 public void writeStringToFile( string str, string filename ) 2 { 3 #if !WEB_BUILD 4 string path = pathForDocumentsFile( filename ); 5 FileStream file = new FileStream (path, FileMode.Create, FileAccess.Write); 6 7 StreamWriter sw = new StreamWriter( file ); 8 sw.WriteLine( str ); 9 10 sw.Close(); 11 file.Close(); 12 #endif 13 }


1 public string readStringFromFile( string filename)//, int lineIndex ) 2 { 3 #if !WEB_BUILD 4 string path = pathForDocumentsFile( filename ); 5 6 if (File.Exists(path)) 7 { 8 FileStream file = new FileStream (path, FileMode.Open, FileAccess.Read); 9 StreamReader sr = new StreamReader( file ); 10 11 string str = null; 12 str = sr.ReadLine (); 13 14 sr.Close(); 15 file.Close(); 16 17 return str; 18 } 19 else 20 { 21 return null; 22 } 23 #else 24 return null; 25 #endif 26 }

// 파일쓰고 읽는넘보다 이놈이 핵심이죠
1 public string pathForDocumentsFile( string filename ) 2 { 3 if (Application.platform == RuntimePlatform.IPhonePlayer) 4 { 5 string path = Application.dataPath.Substring( 0, Application.dataPath.Length - 5 ); 6 path = path.Substring( 0, path.LastIndexOf( '/' ) ); 7 return Path.Combine( Path.Combine( path, "Documents" ), filename ); 8 } 9 else if(Application.platform == RuntimePlatform.Android) 10 { 11 string path = Application.persistentDataPath; 12 path = path.Substring(0, path.LastIndexOf( '/' ) ); 13 return Path.Combine (path, filename); 14 } 15 else 16 { 17 string path = Application.dataPath; 18 path = path.Substring(0, path.LastIndexOf( '/' ) ); 19 return Path.Combine (path, filename); 20 } 21 }



[출처] Unity3D 모바일(안드로이드) 파일생성 및 읽고 쓰기|작성자 호랑낚시

반응형
Posted by blueasa
, |

Camera.WorldPositionToViewportPoint() 라는 함수를 사용합니다.


오늘 레퍼런스[2016-04-01] 확인해보니 유니티가 업데이트 되면서 함수명이 조금 바꼈네요.

Camera.WorldToViewportPoint() 입니다.


리턴되는 Vector3의 x, y 좌표가 [0~1] 범위 안에 있고, z좌표가 0보다 크면 보이는 겁니다. ^^



참조 : http://docs.unity3d.com/ScriptReference/Camera.WorldToViewportPoint.html


출처 : http://drago7.tistory.com/entry/Unity3D%EC%97%90%EC%84%9C-%EC%98%A4%EB%B8%8C%EC%A0%9D%ED%8A%B8%EA%B0%80-%EC%B9%B4%EB%A9%94%EB%9D%BC-%EB%B7%B0%ED%8F%AC%ED%8A%B8%EC%97%90-%EB%93%A4%EC%96%B4%EC%98%A4%EB%8A%94%EC%A7%80-%EC%B4%88%EA%B0%84%EB%8B%A8-%EC%B2%B4%ED%81%AC

반응형
Posted by blueasa
, |

링크 : http://hompy.info/664



CoverFlowScroll.unitypackage



요즘 제작중인 RPG 게임 GUI 에서 영웅 생성을 위해 캐릭터를 선택하는 UI 를 커버플로우(Cover Flow)로 구성하게 되어 NGUI 를 조금 응용해서 심플하게 구성해봤습니다. 아래 동영상과 유니티 데모를 보시면 대략 어떤 것인지 아실 수 있을 것이며 혹시나 구현 방법에 대해 관심 있는 분들은 첨부 파일을 받아서 패키지 임포트로 유니티에서 가져가 내용을 살펴 보시면 되겠습니다. NGUI 외에도 트위닝 모션을 위해 HOTween 플러그인을 사용하는 코드가 있으나 수정해서 쓰셔도 되겠습니다. 그리고 데모에 보이는 캐릭터 디자인 소스는 에셋 스토어에서 구입한 것이네요. NGUI 플러그인에 이런 기능도 포함되면 좋을 것 같은데 안된다면 아쉽지만 저처럼 이렇게 구현해야 되겠지요.^^ 여러분은 지금 어떤 기능들을 추가해보고 있나요?

[유니티 데모 링크] http://www.hompydesign.com/tmp/coverflow/

[패키지 첨부파일]  CoverFlowScroll.unitypackage

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Plugins;

public class HeroTable : MonoBehaviour {
   UISprite[] heros;

   Transform mTrans;
   bool mIsDragging = false;
   Vector3 mPosition, mLocalPosition;
   Vector3 mDragStartPosition;
   Vector3 mDragPosition;
   Vector3 mStartPosition;
   
   public float cellWidth = 160f;
   public float downScale = 0.4f;
   public int cellTotal = 6;
   public int seq = 3;
   
   public UILabel titleLabel;
   
   // Use this for initialization
   void Start () {
       StartCoroutine( DelayStart(1f) );
   }
   void Awake(){
       mTrans = transform;
       mPosition = mTrans.position;
       mLocalPosition = mTrans.localPosition;
   }
   
   IEnumerator DelayStart(float delayTime) {
       yield return new WaitForSeconds(delayTime);
       heros = gameObject.GetComponentsInChildren<UISprite>();
       SetPosition(false);
   }
   
   void SetSequence(bool isRight){
       Vector3 dist = mLocalPosition - mTrans.localPosition;
       float distX = Mathf.Round(dist.x/cellWidth);
       seq = (int)distX;
       if (seq >= cellTotal) seq = cellTotal - 1;
       if (seq <= 0) seq = 0;
   }
   
   void SetPosition(bool isMotion){
       Vector3 pos = mLocalPosition;
       pos -= new Vector3(seq * cellWidth, 0f0f);
       if (isMotion) {
           TweenParms parms = new TweenParms();
           parms.Prop("localPosition", pos);
           parms.Ease(EaseType.Linear);
           HOTween.To(mTrans, 0.1f, parms);
           HOTween.Play();
       else {
           mTrans.localPosition = pos;
       }
       titleLabel.text = heros[seq].spriteName;
   }

   void Drop () {
       Vector3 dist = mDragPosition - mDragStartPosition;
       if (dist.x>0f) SetSequence(true);
       else SetSequence(false);
       SetPosition(true);
   }

   void OnDrag (Vector2 delta) {
       Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
       float dist = 0f;
       Vector3 currentPos = ray.GetPoint(dist);

       if (UICamera.currentTouchID == -|| UICamera.currentTouchID == 0) {
           if (!mIsDragging) {
               mIsDragging = true;
               mDragPosition = currentPos;
           else {
               Vector3 pos = mStartPosition - (mDragStartPosition - currentPos);
               Vector3 cpos = new Vector3(pos.x, mTrans.position.y, mTrans.position.z);
               mTrans.position = cpos;
           }
       }
   }

   void OnPress (bool isPressed) {
       mIsDragging = false;
       Collider col = collider;
       if (col != null) {
           Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
           float dist = 0f;
           mDragStartPosition = ray.GetPoint(dist);
           mStartPosition = mTrans.position;
           col.enabled = !isPressed;
       }
       if (!isPressed) Drop();
   }
}

using UnityEngine;
using System.Collections;

public class HeroItem : MonoBehaviour {
   Transform mTrans, mParent;
   Vector3 scale;
   float cellWidth;
   float downScale;
   HeroTable hTable;

   void Start () {
       mTrans = transform;
       scale = mTrans.localScale;
       mParent = mTrans.parent;
       hTable = mParent.GetComponent<HeroTable>();
       cellWidth = hTable.cellWidth;
       downScale = hTable.downScale;
   }
   
   void Update () {
       Vector3 pos = mTrans.localPosition + mParent.localPosition;
       float dist = Mathf.Clamp(Mathf.Abs(pos.x), 0f, cellWidth);
       mTrans.localScale = ((cellWidth - dist*downScale) / cellWidth) * scale;
   }
}

반응형
Posted by blueasa
, |