Last active
August 29, 2015 14:02
-
-
Save smallrice45/a219d5f3f638cabe7363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class DestroySelf : MonoBehaviour { | |
public bool activeBool = false; | |
public TweenAlpha mTweenAlpha; | |
public TweenScale mTweenScale; | |
void Awake() | |
{ | |
mTweenAlpha = GetComponent<TweenAlpha> (); | |
mTweenScale = GetComponent<TweenScale> (); | |
} | |
void OnEnable() | |
{ | |
gameObject.transform.localScale = new Vector3(1,1,1); | |
GetComponent<UISprite>().alpha = 0.5f; | |
mTweenAlpha.ResetToBeginning (); | |
mTweenScale.ResetToBeginning (); | |
mTweenAlpha.enabled = true; | |
mTweenScale.enabled = true; | |
activeBool = false; | |
} | |
public void OnDestroySelf () { | |
if (!activeBool) | |
{ | |
activeBool = true; | |
gameObject.SetActive (false); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class EnemyStateChange : MonoBehaviour { | |
Animator m_Animator; | |
// Use this for initialization | |
void Start () { | |
m_Animator = GetComponent<Animator>(); | |
} | |
void OnPress (bool isPress) { | |
if (isPress) | |
{ | |
Dead(); | |
} | |
} | |
public void Dead () { | |
m_Animator.Play("Dead"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class ObjectPoolCreator : MonoBehaviour { | |
// 觸碰特效預置物 | |
public GameObject touchScreenFX; | |
public List<GameObject> PoolObjects; | |
private int poolCount = 0; | |
void Start() | |
{ | |
CreatPoolObject (); | |
} | |
void CreatPoolObject() | |
{ | |
for (int i = 0; i < 10; i++) | |
{ | |
print(i); | |
GameObject objectPerfab; | |
objectPerfab = Instantiate(touchScreenFX) as GameObject; | |
PoolObjects.Add(objectPerfab); | |
objectPerfab.transform.parent = this.transform; | |
objectPerfab.SetActive(false); | |
} | |
} | |
public GameObject GetObject() | |
{ | |
int nowObjectCount = poolCount; | |
if (poolCount >= PoolObjects.Count) { | |
poolCount = 0; | |
nowObjectCount = 0; | |
} else { | |
poolCount++; | |
} | |
PoolObjects [nowObjectCount].SetActive (true); | |
return PoolObjects [nowObjectCount]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class OnPressScreen : MonoBehaviour { | |
// 畫面尺寸底圖 | |
public UISprite mSprite; | |
// 目前底圖尺寸 | |
public Vector2 nowSpriteSize; | |
// 目前畫面尺寸 | |
public Vector2 nowScreenSize; | |
public Vector2 fixMun; | |
void Start() | |
{ | |
mSprite = GetComponent<UISprite>(); | |
// 取得目前底圖尺寸的一半 (以畫面正中心為原點) | |
nowSpriteSize = new Vector2( mSprite.localSize.x/2, mSprite.localSize.y/2); | |
// 取得目前螢幕尺寸的一半 (以畫面正中心為原點) | |
nowScreenSize = new Vector2( Screen.width/2, Screen.height/2); | |
// 修正值 (底圖與螢幕之間的比例來修正正確座標) | |
fixMun = new Vector2 (nowSpriteSize.x / nowScreenSize.x, nowSpriteSize.y / nowScreenSize.y); | |
} | |
void OnPress (bool isPress){ | |
if (isPress) | |
{ | |
ViewScreenFX(); | |
} | |
} | |
public void ViewScreenFX() | |
{ | |
// 尚未修正值的正確座標 (以畫面正中心為原點) | |
Vector2 lastTouchPosUnFix = new Vector2( UICamera.currentTouch.pos.x - nowScreenSize.x, UICamera.currentTouch.pos.y - nowScreenSize.y); | |
// 修正後的座標位置並轉換Vector3 (以畫面正中心為原點) | |
Vector2 lastTouchPosFix = new Vector2 ( lastTouchPosUnFix.x * fixMun.x, lastTouchPosUnFix.y * fixMun.y); | |
Vector3 posFix = new Vector3(lastTouchPosFix.x,lastTouchPosFix.y,-5); | |
UIManager.Singleton.m_TouchScreenFXPool.GetObject().transform.localPosition = posFix; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class TestOnPress : MonoBehaviour { | |
// Use this for initialization | |
void OnPress (bool isPress) { | |
if (isPress) | |
{ | |
UIManager.Singleton.m_TouchScreenEvent.ViewScreenFX(); | |
} | |
print (isPress); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class UIManager : MonoBehaviour { | |
#region Variables | |
private static UIManager s_singleton = null; | |
#endregion | |
public OnPressScreen m_TouchScreenEvent; | |
public ObjectPoolCreator m_TouchScreenFXPool; | |
#region Properpty | |
public static UIManager Singleton { | |
get { | |
// 沒有的話就試圖尋找 | |
if( s_singleton == null ) { | |
// 先從遊戲中物件搜尋 | |
s_singleton = GameObject.FindObjectOfType(typeof(UIManager)) as UIManager; | |
// 還是找不到就自己做一個 | |
if( s_singleton == null ) { | |
GameObject go = new GameObject("GameManager"); | |
s_singleton = go.AddComponent<UIManager>(); | |
} | |
} | |
return s_singleton; | |
} | |
} | |
#endregion | |
#region Behaviour | |
private void Awake() { | |
// 防錯用,摧毀掉多餘的物件 | |
if( UIManager.Singleton != this ) { | |
Destroy(this); | |
return ; | |
} | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment