예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (this.GetComponent <Collider>().bounds.Contains(lScript.getHitPoint()))
        {
            canDraw = true;
        }
        else
        {
            canDraw = false;
        }
        if (canDraw && cScript.isTriggerDown())
        {
            //thisTrail = (GameObject)Instantiate(trailPrefab, lScript.getHitPoint(), transform.rotation, transform.parent);
            //thisTrail.GetComponent<LineRenderer>().numPositions = 100;
            //Debug.Log(thisTrail.GetComponent<LineRenderer>().numPositions);
            //drawing = thisTrail.GetComponent<LineRenderer>();

            //source.PlayOneShot(drawSound, 1f);
            //float vol = Random.Range(volLowRange, volHighRange);
        }
        if (canDraw && cScript.isTrigger())
        {
            //drawing.numPositions++;
            //drawing.SetPosition(drawing.numPositions - 1, lScript.getHitPoint());
            this.transform.parent.GetComponent <Rigidbody>().isKinematic = true;

            //thisTrail.GetComponent<LineRenderer>().numPositions = 20;
            //thisTrail.transform.position = lScript.getHitPoint();
            //thisTrail.transform.position = Vector3.MoveTowards(transform.position, GameObject.Find("Camera (head)").transform.position, 10);
            //thisTrail.transform.LookAt(GameObject.Find("Camera (head)").transform);
            //thisTrail.GetComponent<Renderer>().material.color = colorScript.getColor();
            //GameObject pixel = Instantiate(trailPrefab, lScript.getHitPoint(), transform.rotation, transform.parent);
            //pixel.GetComponent<Renderer>().material.color = colorScript.getColor();
        }
        else
        {
            this.transform.parent.GetComponent <Rigidbody>().isKinematic = false;
        }
        if (cScript.isTrigger() && !source.isPlaying && canDraw)
        {
            source.Play();
        }

        if (cScript.isTriggerUp() && source.isPlaying)
        {
            source.Stop();
        }
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log("HitPoint: " + lScript.getHitPoint() + "this: " + this.transform.position + "Dif: " + (lScript.getHitPoint() - this.transform.position));
        //Debug.Log(lScript.getHitPoint().x - this.transform.position.x);
        if (cScript.isTrigger() && transform.parent.Find("innerNote").GetComponent <trailScript>().canDraw&& lScript.getTextureCoord() != Vector2.zero)
        {
            //Debug.Log("sadasdasdad");
            //Debug.Log(Mathf.RoundToInt(lScript.getTextureCoord().x * 320) + " " + Mathf.RoundToInt(lScript.getTextureCoord().y * 320));


            int midPointX = Mathf.RoundToInt(lScript.getTextureCoord().x *size);
            int midPointY = Mathf.RoundToInt(lScript.getTextureCoord().y *size);
            curColor = colorScript.getColor();
            radius   = (strokeScript.getStrokeSize() - 1) / 2;
            //for (int i = 0; i < strokeSize; i++)
            //{
            //for (int j = 0; j < strokeSize; j++)
            //{
            //canvasTexture.SetPixel(midPointX-((strokeSize-1)/2)+j,midPointY - ((strokeSize - 1) / 2) + i, colorScript.getColor());
            //}
            //}


            for (int x = midPointX - radius; x <= midPointX; x++)
            {
                for (int y = midPointY - radius; y <= midPointY; y++)
                {
                    // we don't have to take the square root, it's slow
                    if ((x - midPointX) * (x - midPointX) + (y - midPointY) * (y - midPointY) <= radius * radius)
                    {
                        int xSym = midPointX - (x - midPointX);
                        int ySym = midPointY - (y - midPointY);
                        // (x, y), (x, ySym), (xSym , y), (xSym, ySym) are in the circle
                        if (x >= 0 && x <= size && y >= 0 && y <= size)
                        {
                            canvasTexture.SetPixel(x, y, curColor);
                            if (ySym >= 0 && ySym <= size)
                            {
                                canvasTexture.SetPixel(x, ySym, curColor);
                                if (xSym >= 0 && xSym <= size)
                                {
                                    canvasTexture.SetPixel(xSym, y, curColor);
                                    canvasTexture.SetPixel(xSym, ySym, curColor);
                                }
                            }
                        }
                    }
                }
            }

            canvasTexture.Apply();
            //Debug.Log(canvasTexture);
            //this.GetComponent<Renderer>().material.mainTexture = canvasTexture;
        }
    }