/// <summary> /// 處理滑鼠狀態 /// </summary> private void ProcessMouseState() { switch (this.currentMouseType) { case MouseType.初始播放引導動畫: //播放引導動畫 PlayHandBoneAnimation.script.animationType = PlayHandBoneAnimation.AnimationType.拖曳引導; //PlayHintBoneAnimation.script.animationType = PlayHintBoneAnimation.AnimationType.拖曳操作畫布; this.currentMouseType = MouseType.無狀態; break; case MouseType.無狀態: if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) this.currentMouseType = MouseType.點擊; break; case MouseType.點擊: if (Physics.Raycast(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition), new Vector3(0, 0, 1), out this.hit, 100, this.TargetLayer)) { this.clickTime += Time.deltaTime; if (this.clickTime > this.clickTime_threshold) { this.Target = this.hit.transform.gameObject; this.clickTime = 0; if (!this.Target.GetComponent<PictureInfo>().CanMove) { this.currentMouseType = MouseType.無狀態; return; } if(!this.GetComponent<iTween>()) iTween.ValueTo(this.gameObject, iTween.Hash( "name", "PickObject", "from", 1, "to", 0.5F, "onupdate", "changePictureAlpha", "loopType", "pingPong", "time", 1 )); this.currentPictureType = this.Target.GetComponent<PictureInfo>().Type; this.currentMouseType = MouseType.拖曳中; } //取消手指動畫 PlayHandBoneAnimation.script.animationType = PlayHandBoneAnimation.AnimationType.空動畫; } break; case MouseType.拖曳中: if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) { //將中心點修正 float offsetY = this.Target.GetComponent<SmoothMoves.Sprite>().size.y * this.Target.transform.localScale.y * 0.5f; this.Target.transform.position = new Vector3(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).x, this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).y - offsetY, this.Target.transform.position.z); } else if (this.currentPictureType == PictureInfo.PictureType.土坡) { this.Target.transform.position = new Vector3(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).x, this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).y, this.Target.transform.position.z); } this.Target.GetComponent<PictureInfo>().ChangeScaleDepth(); if (!Input.GetKey(KeyCode.Mouse0) && !Input.GetKey(KeyCode.Mouse1)) this.currentMouseType = MouseType.放開; break; case MouseType.放開: //iTween.StopByName("PickObject"); this.Target.GetComponent<SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 1)); if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) this.馬樹範圍提示物件.GetComponent<SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 0)); else if (this.currentPictureType == PictureInfo.PictureType.土坡) this.土坡範圍提示物件.GetComponent<SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 0)); bool isContain = false; if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) { foreach (var area in GameManager.script.馬樹放置範圍清單) { if (area.isContainArea(this.Target.transform.position)) { isContain = true; this.Target.GetComponent<PictureInfo>().isUsed = true; break; } } } else if (this.currentPictureType == PictureInfo.PictureType.土坡) { if (GameManager.script.土坡放置範圍.isContainArea(this.Target.transform.position)) { isContain = true; PictureInfo script = this.Target.GetComponent<PictureInfo>(); script.CanMove = false; script.isUsed = true; this.Target.transform.localPosition = new Vector3(0, 0, script.MaxDepth); } } if (!isContain & this.currentPictureType != PictureInfo.PictureType.未定義) this.Target.GetComponent<PictureInfo>().BacktoOriginPosition(); this.currentPictureType = PictureInfo.PictureType.未定義; this.currentMouseType = MouseType.無狀態; break; } }
/// <summary> /// 處理滑鼠狀態 /// </summary> private void ProcessMouseState() { switch (this.currentMouseType) { case MouseType.初始播放引導動畫: //播放引導動畫 PlayHandBoneAnimation.script.animationType = PlayHandBoneAnimation.AnimationType.拖曳引導; //PlayHintBoneAnimation.script.animationType = PlayHintBoneAnimation.AnimationType.拖曳操作畫布; this.currentMouseType = MouseType.無狀態; break; case MouseType.無狀態: if (Input.GetKey(KeyCode.Mouse0) || Input.GetKey(KeyCode.Mouse1)) { this.currentMouseType = MouseType.點擊; } break; case MouseType.點擊: if (Physics.Raycast(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition), new Vector3(0, 0, 1), out this.hit, 100, this.TargetLayer)) { this.clickTime += Time.deltaTime; if (this.clickTime > this.clickTime_threshold) { this.Target = this.hit.transform.gameObject; this.clickTime = 0; if (!this.Target.GetComponent <PictureInfo>().CanMove) { this.currentMouseType = MouseType.無狀態; return; } if (!this.GetComponent <iTween>()) { iTween.ValueTo(this.gameObject, iTween.Hash( "name", "PickObject", "from", 1, "to", 0.5F, "onupdate", "changePictureAlpha", "loopType", "pingPong", "time", 1 )); } this.currentPictureType = this.Target.GetComponent <PictureInfo>().Type; this.currentMouseType = MouseType.拖曳中; } //取消手指動畫 PlayHandBoneAnimation.script.animationType = PlayHandBoneAnimation.AnimationType.空動畫; } break; case MouseType.拖曳中: if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) { //將中心點修正 float offsetY = this.Target.GetComponent <SmoothMoves.Sprite>().size.y *this.Target.transform.localScale.y * 0.5f; this.Target.transform.position = new Vector3(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).x, this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).y - offsetY, this.Target.transform.position.z); } else if (this.currentPictureType == PictureInfo.PictureType.土坡) { this.Target.transform.position = new Vector3(this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).x, this.ViewCamera.ScreenToWorldPoint(Input.mousePosition).y, this.Target.transform.position.z); } this.Target.GetComponent <PictureInfo>().ChangeScaleDepth(); if (!Input.GetKey(KeyCode.Mouse0) && !Input.GetKey(KeyCode.Mouse1)) { this.currentMouseType = MouseType.放開; } break; case MouseType.放開: //iTween.StopByName("PickObject"); this.Target.GetComponent <SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 1)); if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) { this.馬樹範圍提示物件.GetComponent <SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 0)); } else if (this.currentPictureType == PictureInfo.PictureType.土坡) { this.土坡範圍提示物件.GetComponent <SmoothMoves.Sprite>().SetColor(new Color(1, 1, 1, 0)); } bool isContain = false; if (this.currentPictureType == PictureInfo.PictureType.馬 || this.currentPictureType == PictureInfo.PictureType.樹 || this.currentPictureType == PictureInfo.PictureType.未分類) { foreach (var area in GameManager.script.馬樹放置範圍清單) { if (area.isContainArea(this.Target.transform.position)) { isContain = true; this.Target.GetComponent <PictureInfo>().isUsed = true; break; } } } else if (this.currentPictureType == PictureInfo.PictureType.土坡) { if (GameManager.script.土坡放置範圍.isContainArea(this.Target.transform.position)) { isContain = true; PictureInfo script = this.Target.GetComponent <PictureInfo>(); script.CanMove = false; script.isUsed = true; this.Target.transform.localPosition = new Vector3(0, 0, script.MaxDepth); } } if (!isContain & this.currentPictureType != PictureInfo.PictureType.未定義) { this.Target.GetComponent <PictureInfo>().BacktoOriginPosition(); } this.currentPictureType = PictureInfo.PictureType.未定義; this.currentMouseType = MouseType.無狀態; break; } }