Ejemplo n.º 1
0
    public void Hit(Vector3 hitPoint)
    {
        activeZones.Add(zones[GetClosestZone(hitPoint)]);

        CustomRenderTextureUpdateZone[] tempZoneArray = activeZones.ToArray();
        customRenderTexture.SetUpdateZones(tempZoneArray);

        if (updateCoroutine == null)
        {
            updateCoroutine = StartCoroutine(ToggleUpdate());
        }

        customRenderTexture.Update();
        currentUpdateDuration += updateDuration;
    }
    void UpdateZones()
    {
        bool       leftClick  = Input.GetMouseButton(0);
        bool       rightClick = Input.GetMouseButton(1);
        var        ray        = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (!leftClick && !rightClick)
        {
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, detectLayer))
            {
                Debug.DrawLine(Camera.main.transform.position, hit.point, Color.blue);
                //Debug.Log(myTexture2D.GetPixel((int)hit.point.x,(int)hit.point.z));
                //Debug.Log(new Vector2((int)hit.point.x,(int)hit.point.z));
            }
        }
        else
        {
            if (Physics.Raycast(ray, out hit, Mathf.Infinity, detectLayer))
            {
                var defaultZone = new CustomRenderTextureUpdateZone();
                defaultZone.needSwap         = true;
                defaultZone.passIndex        = 0;
                defaultZone.rotation         = 0f;
                defaultZone.updateZoneCenter = new Vector2(0.5f, 0.5f);
                defaultZone.updateZoneSize   = new Vector2(1f, 1f);

                var clickZone = new CustomRenderTextureUpdateZone();
                clickZone.needSwap         = true;
                clickZone.passIndex        = leftClick ? 1 : 2;
                clickZone.rotation         = 0f;
                clickZone.updateZoneCenter = new Vector2(hit.textureCoord.x, 1f - hit.textureCoord.y);
                clickZone.updateZoneSize   = new Vector2(0.01f, 0.01f);

                texture.SetUpdateZones(new CustomRenderTextureUpdateZone[] { defaultZone, clickZone });


                Debug.DrawLine(Camera.main.transform.position, hit.point, Color.red);
                // Vector2Int pointMatrix = new Vector2Int(
                //     (int)(hit.point.x + texture.width/2),
                //     (int)(hit.point.z + texture.height/2));
                //Debug.Log(myTexture2D.GetPixel(0,1));
                //Debug.Log(pointMatrix);
            }
        }
    }
Ejemplo n.º 3
0
    public static int SetUpdateZones(IntPtr l)
    {
        int result;

        try
        {
            CustomRenderTexture             customRenderTexture = (CustomRenderTexture)LuaObject.checkSelf(l);
            CustomRenderTextureUpdateZone[] updateZones;
            LuaObject.checkArray <CustomRenderTextureUpdateZone>(l, 2, out updateZones);
            customRenderTexture.SetUpdateZones(updateZones);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Ejemplo n.º 4
0
    void Start()
    {
        center = new Vector3(5f, 0f, 5f);
        texture.initializationColor = Color.clear;
        texture.Initialize();
        texture.ClearUpdateZones();
        p.x = target.position.x * 0.1f * texture.width;
        p.y = target.position.z * 0.1f * texture.height;
        material.SetVector("_WorldPos", p);

        var defaultZone = new CustomRenderTextureUpdateZone();

        defaultZone.needSwap         = true;
        defaultZone.passIndex        = 0;
        defaultZone.rotation         = 0f;
        defaultZone.updateZoneCenter = new Vector2(0.5f, 0.5f);
        defaultZone.updateZoneSize   = new Vector2(1f, 1f);

        texture.SetUpdateZones(new CustomRenderTextureUpdateZone[] { defaultZone });
    }
Ejemplo n.º 5
0
    void UpdateZones()
    {
        customRenderTexture = GetComponent <Renderer>().sharedMaterial.mainTexture as CustomRenderTexture;
        int totalCount = zonesX * zonesY;

        zones = new CustomRenderTextureUpdateZone[totalCount];
        float size = 1 / Mathf.Sqrt(totalCount);

        for (int i = 0; i < totalCount; i++)
        {
            float xPos = i % zonesX;
            float yPos = i / zonesY;

            CustomRenderTextureUpdateZone newZone = new CustomRenderTextureUpdateZone();
            newZone.updateZoneCenter = new Vector3(xPos * size + size / 2, yPos * size + size / 2, 0);
            newZone.updateZoneSize   = new Vector3(size, size, size);
            zones[i] = newZone;
        }
        CustomRenderTextureUpdateZone[] clearZone = new CustomRenderTextureUpdateZone[1];
        clearZone[0].updateZoneCenter = new Vector2(0.5f, 0.5f);
        clearZone[0].updateZoneSize   = Vector2.zero;
        customRenderTexture.SetUpdateZones(clearZone);
    }
Ejemplo n.º 6
0
    public void OnCollision(List <Ray> rays)
    {
        RaycastHit hit;

        List <Vector2> uvs = new List <Vector2>();

        foreach (var ray in rays)
        {
            if (Physics.Raycast(ray, out hit))
            {
                uvs.Add(hit.textureCoord);
            }
        }

        int hitCnt = uvs.Count;

        CustomRenderTextureUpdateZone[] updateZones = new CustomRenderTextureUpdateZone[hitCnt + 1];
        for (int i = 0; i < hitCnt; i++)
        {
            updateZones[i].needSwap         = true;
            updateZones[i].passIndex        = 1;
            updateZones[i].rotation         = 0f;
            updateZones[i].updateZoneCenter = new Vector2(uvs[i].x, 1f - uvs[i].y);
            updateZones[i].updateZoneSize   = new Vector2(0.01f, 0.01f);
            Debug.Log("bbbb");
        }


        updateZones[hitCnt].needSwap         = true;
        updateZones[hitCnt].passIndex        = 0; // 波動方程式のシミュレーションのパス
        updateZones[hitCnt].rotation         = 0f;
        updateZones[hitCnt].updateZoneCenter = new Vector2(0.5f, 0.5f);
        updateZones[hitCnt].updateZoneSize   = new Vector2(1f, 1f);


        _texture.SetUpdateZones(updateZones);
    }