using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using SC.InputSystem; using DG.Tweening; //肾小囊 public class Bowman : PointerDelegate { [SerializeField] private Transform mTarget; [SerializeField] private Transform receivePoint;//重复利用的点 [SerializeField] private Transform endPoint;//目的地 [SerializeField] private BloodManager.BloodItemType[] fliterTypes;//可以过滤的东西 [SerializeField] private BloodManager.BloodItemType[] recycleTypes;//可以回收的 void Start () { } private void OnDestroy() { } // Update is called once per frame void Update () { CheckRay(); } Ray ray; RaycastHit hit; GameObject obj; private void CheckRay() { if(Camera.main == null) { return; } if (Input.GetMouseButtonDown(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, float.MaxValue,1 << 0)) { if (hit.rigidbody != null) { obj = hit.rigidbody.gameObject; CheckItem(); } } } } private void CheckItem() { BloodItem item = obj.GetComponentInParent(); if(item != null) { if(Array.IndexOf(fliterTypes, item.MType) == -1 && false) { //不是可以过滤的东西 } else { if (item.StopMove()) { ChangeItemForward(item); } } } } //让小球朝向我 private void ChangeItemForward(BloodItem item) { item.transform.LookAt(mTarget); item.transform.DOLocalMove(mTarget.transform.position, 1.0f).SetEase(Ease.Linear).OnComplete(Test).SetAutoKill(true); return; //iTween.Stop(item.gameObject); Hashtable args = new Hashtable(); args.Add("position", mTarget.transform.position); args.Add("time", 1.0f); //移动结束时调用,参数和上面类似 args.Add("easeType", iTween.EaseType.linear); args.Add("oncomplete", "Arrived"); args.Add("oncompleteparams", item); args.Add("oncompletetarget", gameObject); iTween.MoveTo(item.gameObject, args); } private void Test() { Debug.Log("到达了指定地方"); } //到达了指定的地方 private void Arrived(BloodItem item) { Debug.Log("到达了指定地方" + Vector3.Distance(item.transform.position, mTarget.transform.position)); //item.SetMoveDir(-Vector3.forward); //return; iTween.Stop(item.gameObject); if (Array.IndexOf(recycleTypes, item.MType) != -1 && CheckNeedReceived(item.MType)) { Debug.Log("这是可以回收的"); //不是可以过滤的东西 iTween.MoveTo(item.gameObject, iTween.Hash("position", receivePoint, "easeType", iTween.EaseType.linear, "loopType", iTween.LoopType.none, "delay", 1)); } else { Debug.Log("这是废物"); iTween.MoveTo(item.gameObject, iTween.Hash("position", endPoint, "easeType", iTween.EaseType.linear, "loopType", iTween.LoopType.none, "delay", 1)); } } private bool CheckNeedReceived(BloodManager.BloodItemType cType) { return false; var randomValue = UnityEngine.Random.Range(0,100); var max_value = 0 ; switch(cType) { case BloodManager.BloodItemType.Water: max_value = 80; break; case BloodManager.BloodItemType.MineralSalt: max_value = 50; break; case BloodManager.BloodItemType.Protein: max_value = 100; break; case BloodManager.BloodItemType.Urea: max_value = 0; break; } if(randomValue < max_value) { return true; } return false; } //加分的部分 public bool IsGod(BloodItem item) { if (Array.IndexOf(fliterTypes, item.MType) != -1) { return true; } return false; } //不能漏掉的 要扣分的 public bool IsRecyle(BloodItem item) { if (Array.IndexOf(recycleTypes, item.MType) != -1) { return true; } return false; } protected override void partAnyKeyDownDelegate(InputKeyCode keyCode, InputDevicePartBase part) { if (!GamePlayerData.Instance.room_data.IsReconnectOwner()) { //return;//过滤掉不是老师点击的情况 } CheckRayItem(); } private void CheckRayItem() { ray = new Ray( API_InputSystem.Position, API_InputSystem.Normal); if (Physics.Raycast(ray, out hit, float.MaxValue, 1 << 0)) { if (hit.rigidbody != null) { obj = hit.rigidbody.gameObject; CheckItem(); } } } }