コード例 #1
0
    private void Update()
    {
        if (goingForward)
        {
            progress += Time.deltaTime / duration;
            if (progress > 1f)
            {
                if (mode == SplineWalkerMode.Once)
                {
                    progress = 1f;
                }
                else if (mode == SplineWalkerMode.Loop)
                {
                    progress -= 1f;
                }
                else
                {
                    progress     = 2f - progress;
                    goingForward = false;
                }
            }
        }
        else
        {
            progress -= Time.deltaTime / duration;
            if (progress < 0f)
            {
                progress     = -progress;
                goingForward = true;
            }
        }

        Vector3 position = spline.GetPoint(progress);

        transform.localPosition = position;
        if (lookForward)
        {
            transform.LookAt(position + spline.GetDirection(progress));
            transform.Rotate(0, arrowCorrection, arrowCorrection);
        }

        if (lookField)
        {
            if (fieldControl.FieldMode == VectorFieldMode.Sink)
            {
                transform.LookAt(fieldControl.GetVectorTransform(transform.position));

                if (!Camera)
                {
                    transform.Rotate(0, arrowCorrection, arrowCorrection);
                }
            }
            else if (fieldControl.FieldMode == VectorFieldMode.Source)
            {
                transform.LookAt(fieldControl.GetVectorTransform(transform.position));
                transform.Rotate(0, arrowCorrection, arrowCorrection);
            }
        }
    }
コード例 #2
0
    // Use this for initialization
    void Start()
    {
        if (!curveRenderer)
        {
            curveRenderer = GetComponent <LineRenderer>();
            //cartesianLines = new List<LineRenderer>();
        }

        //LineRenderer lRend1 = new GameObject().AddComponent<LineRenderer>() as LineRenderer;
        //lRend1.SetVertexCount(2);
        //lRend1.SetPosition(0, origin+transform.position);
        //lRend1.SetPosition(1, xend + transform.position);
        //lRend1.material.color = Color.white;
        //lRend1.enabled = true;
        //cartesianLines.Add(lRend1);


        //LineRenderer lRend2 = new GameObject().AddComponent<LineRenderer>() as LineRenderer;
        //lRend2.SetVertexCount(2);
        //lRend2.SetPosition(0, origin + transform.position);
        //lRend2.SetPosition(1, yend + transform.position);
        //lRend2.material.color = Color.white;
        //lRend2.enabled = true;
        //cartesianLines.Add(lRend2);


        //LineRenderer lRend3 = new GameObject().AddComponent<LineRenderer>() as LineRenderer;
        //lRend3.SetVertexCount(2);
        //lRend3.SetPosition(0, origin + transform.position);
        //lRend3.SetPosition(1, zend + transform.position);
        //lRend3.material.color = Color.white;
        //lRend3.enabled = true;
        //cartesianLines.Add(lRend3);

        //cartesian = new GameObject[(int)xrange / density, (int)yrange / density, (int)zrange / density];
        //Material material = Resources.Load("ArrowAsset/materials", typeof(Material)) as Material;
        Mesh myMesh = (Mesh)Resources.Load("ArrowAsset/CorrectedPivotArrow", typeof(Mesh));

        GameObject prefab = new GameObject("Arrows");

        prefab.transform.localScale += new Vector3(scale, scale, scale);
        prefab.AddComponent <MeshFilter>();
        prefab.AddComponent <MeshRenderer>();
        prefab.GetComponent <MeshFilter>().sharedMesh = myMesh;
        //prefab.GetComponent<MeshRenderer>().material.color = Color.white;
        Material myMaterial = (Material)Resources.Load("ArrowAsset/MyWhite", typeof(Material));

        prefab.GetComponent <MeshRenderer>().material = myMaterial;


        for (int i = 0; i < (int)xrange / density; i = i + 1)
        {
            for (int j = 0; j < (int)yrange / density; j = j + 1)
            {
                for (int k = 0; k < (int)zrange / density; k = k + 1)
                {
                    /*
                     * cartesian[i, j, k] = new GameObject();
                     * cartesian[i, j, k].transform.position = new Vector3(i * density, j * density, k * density);
                     * cartesian[i, j, k].AddComponent<MeshFilter>();
                     * cartesian[i, j, k].AddComponent<MeshRenderer>();
                     * cartesian[i, j, k].GetComponent<MeshFilter>().sharedMesh = myMesh;
                     * cartesian[i, j, k].GetComponent<MeshRenderer>().material.color = Color.white;
                     *
                     * cartesian[i, j, k].transform.localScale += new Vector3(50, 50, 50);
                     */

                    GameObject arrow;

                    Vector3 pos = origin + new Vector3(i * density, j * density, k * density) + transform.position;

                    if (fieldControl.FieldMode == VectorFieldMode.Sink)
                    {
                        arrow = (Instantiate(prefab, pos, Quaternion.identity)) as GameObject;
                        arrow.transform.LookAt(fieldControl.GetVectorTransform(transform.position));
                        arrow.transform.Rotate(0, arrowCorrection, arrowCorrection);
                    }
                    else if (fieldControl.FieldMode == VectorFieldMode.Source)
                    {
                        arrow = (Instantiate(prefab, pos, Quaternion.identity)) as GameObject;
                        arrow.transform.LookAt(fieldControl.GetVectorTransform(transform.position));
                        arrow.transform.Rotate(0, arrowCorrection, arrowCorrection);
                    }
                    else
                    {
                        arrow = Instantiate(prefab, pos, Quaternion.identity) as GameObject;
                    }
                    arrow = null;
                }
            }
        }
    }