コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        ModelDrawer = new TrajectryDrawer(lineLength, lineWidth, dt);
        StreamReader txtfile = new StreamReader(Application.dataPath + "/MotionLog913.txt", Encoding.UTF8);

        index = 0;
        string str = txtfile.ReadToEnd();

        file = str.Split('\n');
        while (cont)
        {
            GameObject traj_p = Instantiate(SwingHolderPrefab);
            GameObject former = new GameObject("former");
            GameObject latter = new GameObject("latter");

            former.transform.parent = traj_p.transform;
            latter.transform.parent = traj_p.transform;

            while (SetPosition())
            {
                if (UpdatePos() < 0)
                {
                    break;
                }
            }
            while (SwingStart() < 0.15f)
            {
                if (UpdatePos() < 0)
                {
                    break;
                }
            }
            //Unityは左手系→ボールのzを前にしたとき、ユーザにとって右側はx軸の正の方向
            if (SwingStart() <= 0f)
            {
                if (UpdatePos() < 0)
                {
                    break;
                }
                Destroy(traj_p);
                continue;
            }
            foreach (Transform child in this.transform)
            {
                child.gameObject.SetActive(false);
            }
            Debug.Log("swing may start");
            GameObject last;
            ModelDrawer.SetColorAndTag(new Color(1.0f, 0f, 0f, 0.1f), "TakeBack");
            ModelDrawer.setLength(this.lineLength);

            Dummy.position = TargetPos;
            Dummy.rotation = TargetRot;
            ModelDrawer.init(Dummy, former);
            while (true)
            {
                Dummy.position = TargetPos;
                Dummy.rotation = TargetRot;
                last           = ModelDrawer.drawLine(Dummy);
                if (last != null)
                {
                    break;
                }
                if (UpdatePos() < 0)
                {
                    break;
                }
                ;
            }
            if (int.Parse(last.name) <= 0)
            {
                Destroy(traj_p);
                continue;
            }
            ModelDrawer.Turn(lineLength * 2f, latter);
            Color c2 = new Color(0f, 1.0f, 0f, 0.1f);
            ModelDrawer.SetColorAndTag(c2, "DownSwing");

            while (true)
            {
                Dummy.position = TargetPos;
                Dummy.rotation = TargetRot;
                last           = ModelDrawer.drawLine(Dummy);
                if (last != null)
                {
                    break;
                }
                if (UpdatePos() < 0)
                {
                    break;
                }
            }
            if (int.Parse(last.name) <= 0)
            {
                Destroy(traj_p);
                continue;
            }

            Destroy(last);
            Debug.Log("swing ends");
            traj_p.transform.parent = this.transform;
            if (!cont)
            {
                Destroy(traj_p);
            }
        }
    }
コード例 #2
0
    private IEnumerator SwingRecord(bool active)
    {
        //スイングホルダー 親オブジェクトの作成



        int num_of_swing = 0;

        while (true)
        {
            GameObject traj_p = Instantiate(SwingHolderPrefab);
            GameObject former = new GameObject("former");
            GameObject latter = new GameObject("latter");

            former.transform.parent = traj_p.transform;
            latter.transform.parent = traj_p.transform;

            Debug.Log(num_of_swing++);
            while (SetPosition())
            {
                yield return(null);
            }
            while (SwingStart() < 0.15f)
            {
                yield return(null);
            }
            //Unityは左手系→ボールのzを前にしたとき、ユーザにとって右側はx軸の正の方向
            if (SwingStart() <= 0f)
            {
                yield return(null);

                continue;
            }
            foreach (Transform child in this.transform)
            {
                child.gameObject.SetActive(false);
            }
            Debug.Log("swing may start");
            GameObject last;
            ModelDrawer.SetColorAndTag(new Color(1.0f, 0f, 0f, 0.1f), "TakeBack");
            ModelDrawer.setLength(this.lineLength);
            ModelDrawer.init(TargetPos, former);
            while (true)
            {
                last = ModelDrawer.drawLine(TargetPos);
                if (last != null)
                {
                    break;
                }
                yield return(null);
            }
            if (int.Parse(last.name) <= 10)
            {
                continue;
            }

            ModelDrawer.Turn(lineLength * 2f, latter);
            Color c2 = new Color(0f, 1.0f, 0f, 0.1f);
            ModelDrawer.SetColorAndTag(c2, "DownSwing");

            while (true)
            {
                last = ModelDrawer.drawLine(TargetPos);
                if (last != null)
                {
                    break;
                }
                yield return(null);
            }
            if (int.Parse(last.name) <= 10)
            {
                continue;
            }
            Destroy(last);
            Debug.Log("swing ends");
            traj_p.transform.parent = this.transform;
        }

        /*
         * while (true)
         * {
         *  Vector3 ball2head = ballpos.rotation * (Clubhead.transform.position - ballpos.position);
         *  yield return null;
         *  //if (ball2head.magnitude < 0.2f) break;
         *  if (Mathf.Abs(ball2head.x) < 0.15f) break;
         * }
         * Debug.Log("position has been set");
         * ModelDrawer.SetColorAndTag(new Color(1.0f, 0f, 0f, 0.1f), "TakeBack");
         * ModelDrawer.setLength(this.lineLength);
         * ModelDrawer.init(TargetPos, former);
         *
         *
         *
         * while (true)
         * {
         *
         *  Vector3 ball2head = ballpos.rotation * (Clubhead.transform.position - ballpos.position);
         *  Debug.Log(ball2head);
         *  if (ball2head.x <= 0.15f)
         *  {
         *      //touchPos = TargetPos.position;
         *      ModelDrawer.init(TargetPos.position, former);
         *      ModelDrawer.SetPrefab(linePrefab);
         *      PlayerDrawer.init(TargetPos.position, player_swing);
         *      PlayerDrawer.SetPrefab(PlayerlinePrefab);
         *      yield return null;
         *      break;
         *  }
         *  yield return null;
         * }
         *
         *
         * //predir = new Vector3(0f, 0f, 0f);
         * Debug.Log("Swing start");
         *
         * //GameObject last;
         * while (true)
         * {
         *
         *  last = ModelDrawer.drawLine(TargetPos);
         *  if (last != null) break;
         *  yield return null;
         * }
         *
         * //Color c2 = new Color(0f, 1.0f, 0f, 0.1f);
         * //last.GetComponent<MeshRenderer>().material.color = c2;
         * //last.tag = "TakeBack";
         * //last.name = (ModelDrawer.Turn()).ToString();
         * Destroy(last);
         * ModelDrawer.Turn(lineLength * 2f, latter);
         *
         * yield return null;
         * Debug.Log("down swing starts");
         * ModelDrawer.SetColorAndTag(c2, "DownSwing");
         *
         * while (true)
         * {
         *
         *  last = ModelDrawer.drawLine(TargetPos);
         *
         *  if (last != null) break;
         *  yield return null;
         * }
         * Destroy(last);
         * Debug.Log("swing ends");
         * //yield return null;
         * swing.Add(traj_p);
         */
    }