Example #1
0
    public void paint(Paintable paintable, Vector3 pos, float radius = 1f, float hardness = .5f, float strength = .5f, Color?color = null)
    {
        RenderTexture mask      = paintable.getMask();
        RenderTexture uvIslands = paintable.getUVIslands();
        RenderTexture extend    = paintable.getExtend();
        RenderTexture support   = paintable.getSupport();
        Renderer      rend      = paintable.getRenderer();

        paintMaterial.SetFloat(prepareUVID, 0);
        paintMaterial.SetVector(positionID, pos);
        paintMaterial.SetFloat(hardnessID, hardness);
        paintMaterial.SetFloat(strengthID, strength);
        paintMaterial.SetFloat(radiusID, radius);
        paintMaterial.SetTexture(textureID, support);
        paintMaterial.SetColor(colorID, color ?? Color.red);
        extendMaterial.SetFloat(uvOffsetID, paintable.extendsIslandOffset);
        extendMaterial.SetTexture(uvIslandsID, uvIslands);

        command.SetRenderTarget(mask);
        command.DrawRenderer(rend, paintMaterial, 0);

        command.SetRenderTarget(support);
        command.Blit(mask, support);

        command.SetRenderTarget(extend);
        command.Blit(mask, extend, extendMaterial);

        Graphics.ExecuteCommandBuffer(command);
        command.Clear();
    }
Example #2
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
 }
Example #3
0
 private void Update()
 {
     foreach (Renderer renderer in renderers)
     {
         renderer.material.color = Paintable.GetColor(color);
     }
 }
Example #4
0
 // Paint anything paintable that you are colliding with
 private void try_paint()
 {
     foreach (paintable Paintable in touching_paintables)
     {
         Paintable.paint_in();
     }
 }
Example #5
0
    void Update()
    {
        bool click;

        click = Mouse.current.leftButton.isPressed;

        if (click)
        {
            Vector3 position = Mouse.current.position.ReadValue();
            if (cam == null)
            {
                cam = Camera.main;
            }
            Ray        ray = cam.ScreenPointToRay(position);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100.0f))
            {
                Debug.DrawRay(ray.origin, hit.point - ray.origin, Color.red);
                transform.position = hit.point;
                Paintable p = hit.collider.GetComponent <Paintable>();
                if (p != null)
                {
                    PaintManager.instance.paint(p, hit.point, radius, hardness, strength, paintColor);
                }
            }
        }
    }
Example #6
0
    private void OnCollisionStay(Collision other)
    {
        Paintable p = other.collider.GetComponent <Paintable>();

        if (p != null)
        {
            Vector3 pos = other.contacts[0].point;
            PaintManager.instance.paint(p, pos, radius, hardness, strength, paintColor);
        }
    }
Example #7
0
    // Use this for initialization
    public void SetParent(Paintable p)
    {
        _parent = p;

        GameManager gm           = GameManager.Instance;
        Color?      currentColor = gm.CurrentColor;

        if (currentColor.HasValue)
        {
            this.GetComponent <Image>().color = currentColor.Value;
        }
    }
Example #8
0
        public int GetSubmesh(P3dPaintableTexture paintableTexture)
        {
            var material = paintableTexture.Material;

            if (material == null)
            {
                paintableTexture.UpdateMaterial();

                material = paintableTexture.Material;
            }

            return(Paintable.GetMaterialIndex(material));
        }
Example #9
0
    private void CheckGroup(int[] arr, ref HashSet <int> errors)
    {
        List <Color> colors = new List <Color>();

        foreach (int n in arr)
        {
            Paintable image = Images[n];
            if (colors.Contains(image.color))
            {
                errors.Add(n);
            }
            colors.Add(image.color);
        }
    }
Example #10
0
        private void AreaOpened(AreaDataObservable area)
        {
            CameraReset();
            _loadedAreaData = _objectMapper.Map <AreaData>(area);
            _loadedArea     = _entityFactory.Create <Area, AreaData>(_loadedAreaData);

            Texture2D texture = _loadedArea.GetComponent <Renderable>().Texture;

            _objectPainter = _entityFactory.Create <ObjectPainter, Texture2D>(texture);
            Paintable paintable = _objectPainter.GetComponent <Paintable>();

            paintable.AreaHeight = _loadedAreaData.Height;
            paintable.AreaWidth  = _loadedAreaData.Width;
        }
Example #11
0
    private void CheckColumn(int column, ref HashSet <int> errors)
    {
        List <Color> colors = new List <Color>();

        for (int i = column; i < 25; i += 5)
        {
            Paintable image = Images[i];
            if (colors.Contains(image.color))
            {
                errors.Add(i);
            }
            colors.Add(image.color);
        }
    }
Example #12
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         RaycastHit hit;
         if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit))
         {
             Paintable script = hit.collider.gameObject.GetComponent <Paintable>();
             if (null != script)
             {
                 script.PaintOn(hit.textureCoord, splashTexture);
             }
         }
     }
 }
Example #13
0
    private void CheckRow(int row, ref HashSet <int> errors)
    {
        List <Color> colors = new List <Color>();
        int          start = row * 5, end = row * 5 + 5;

        for (int i = start; i < end; i++)
        {
            Paintable image = Images[i];
            if (colors.Contains(image.color))
            {
                errors.Add(i);
            }
            colors.Add(image.color);
        }
    }
Example #14
0
    void OnParticleCollision(GameObject other)
    {
        int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);

        Paintable p = other.GetComponent <Paintable>();

        if (p != null)
        {
            for (int i = 0; i < numCollisionEvents; i++)
            {
                Vector3 pos    = collisionEvents[i].intersection;
                float   radius = Random.Range(minRadius, maxRadius);
                PaintManager.instance.paint(p, pos, radius, hardness, strength, paintColor);
            }
        }
    }
Example #15
0
    // Update is called once per frame
    void Update()
    {
        centerRay = Camera.main.ScreenPointToRay(screenCenter);
        if (Physics.Raycast(centerRay, out hit, maxRayDistance, collisionLayerMask))
        {
            paintButton.SetActive(true);
            //do the mat thing
            if (paintableThing == null)
            {
                paintableThing = hit.collider.gameObject;
                try {
                    paintable = paintableThing.GetComponent <Paintable> ();
                    paintable.Hilight();
                } catch (System.Exception ex) {
                    Debug.Log("Paintable not found. Exception: " + ex);
                }

                Debug.Log("it hit " + paintableThing.name);
            }
        }
        else
        {
            paintButton.SetActive(false);
            if (paintableThing != null)
            {
                Debug.Log("it didn't hit");

                try {
                    paintable = paintableThing.GetComponent <Paintable> ();
                    paintable.UnHilight();
                } catch (System.Exception ex) {
                    Debug.Log("Paintable not found. Exception: " + ex);
                }
                paintableThing = null;
            }

            //click to cycle up materials
            if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
            {
                touchPosition = Input.GetTouch(0).position;
                screenPoint   = new Vector2(touchPosition.x, touchPosition.y);
                touchRay      = Camera.main.ScreenPointToRay(screenPoint);

                SelectPaintable(touchRay);
            }
        }
    }
Example #16
0
    public void Paint(Paintable paintable, Vector3 pos, float radius, float hardness, float strength, Color paintColor)
    {
        var paintTex = paintable.PaintTexture;
        var maskTex  = paintable.MaskTexture;
        var renderer = paintable.Renderer;

        SetupPaint(paintMaterial, paintTex, pos, radius, hardness, strength, paintColor);
        command.SetRenderTarget(paintTex);
        command.DrawRenderer(renderer, paintMaterial, 0);

        SetupPaint(maskMaterial, maskTex, pos, radius, hardness, strength, Color.white);
        command.SetRenderTarget(maskTex);
        command.DrawRenderer(renderer, maskMaterial, 0);

        Graphics.ExecuteCommandBuffer(command);
        command.Clear();
    }
Example #17
0
    public void initTextures(Paintable paintable)
    {
        RenderTexture mask      = paintable.getMask();
        RenderTexture uvIslands = paintable.getUVIslands();
        RenderTexture extend    = paintable.getExtend();
        RenderTexture support   = paintable.getSupport();
        Renderer      rend      = paintable.getRenderer();

        command.SetRenderTarget(mask);
        command.SetRenderTarget(extend);
        command.SetRenderTarget(support);

        paintMaterial.SetFloat(prepareUVID, 1);
        command.SetRenderTarget(uvIslands);
        command.DrawRenderer(rend, paintMaterial, 0);

        Graphics.ExecuteCommandBuffer(command);
        command.Clear();
    }
Example #18
0
        /// <inheritdoc />
        public override void Process(Entity entity)
        {
            Vector2   mousePosition = _inputService.GetMousePosition();
            Position  position      = entity.GetComponent <Position>();
            Paintable paintable     = entity.GetComponent <Paintable>();

            mousePosition.X += _camera.Position.X;
            mousePosition.Y += _camera.Position.Y;

            Vector2 tilePosition  = _isoMathService.ScreenPositionToMapTile(mousePosition);
            Vector2 worldPosition = _isoMathService.MapTileToScreenPosition(tilePosition);

            position.X = worldPosition.X;
            position.Y = worldPosition.Y;


            if (_inputService.IsLeftMouseDown())
            {
            }
        }
Example #19
0
    protected override void OnUpdate()
    {
        PaintBucket[] buckets = FindObjectsOfType <PaintBucket>();
        foreach (PaintBucket bucket in buckets)
        {
            if (bucket.Bounds.Contains(PaintTipPosition))
            {
                Color = bucket.Color;
            }
        }

        paintMaterial.color = Paintable.GetColor(Color);

        Vector2 rightStick = RightStick;

        if (Trigger > 0.1f && rightStick.sqrMagnitude > 0.1f)
        {
            Paint();
        }

        if (invert)
        {
            rightStick *= -1f;
        }

        float x         = rightStick.x;
        float magnitude = rightStick.magnitude;

        if (rightStick.y < 0f)
        {
            magnitude *= -1f;
            x         *= -1f;
        }

        x *= 90f;
        if (rightStick.sqrMagnitude > 0.02f)
        {
            Vector3 eulerAngles = new Vector3(magnitude * 90f, x, 0f);
            transform.eulerAngles = eulerAngles;
        }
    }
Example #20
0
    private void Paint()
    {
        Paintable[] paintables       = FindObjectsOfType <Paintable>();
        float       closestDistance  = float.MaxValue;
        Paintable   closestPaintable = null;

        foreach (Paintable paintable in paintables)
        {
            float dist = (paintable.transform.position - PaintTipPosition).sqrMagnitude;
            if (dist < closestDistance && dist < paintBrushRadius * paintBrushRadius)
            {
                closestDistance  = dist;
                closestPaintable = paintable;
            }
        }

        //paint the thingy
        if (closestPaintable)
        {
            closestPaintable.Paint(Color);
        }
    }
Example #21
0
    void PaintAt(Vector2 screenPosition)
    {
        Camera camera = Camera.main;

        if (camera != null)
        {
            RaycastHit hit;
            Ray        ray = camera.ScreenPointToRay(screenPosition);

            if (Physics.Raycast(ray, out hit, float.PositiveInfinity, -1))
            {
                Point  = hit.point;
                Normal = -ray.direction;

                Paintable[] paintables = hit.transform.GetComponentsInChildren <Paintable>();
                for (int i = 0; i < paintables.Length; ++i)
                {
                    Paintable paintable = paintables[i];
                    paintable.HandleHit(this);
                }
            }
        }
    }
Example #22
0
    private bool HitUVPosition(ref Vector3 uvWorldPosition)
    {
        RaycastHit hitInfo;
        Vector3    cursorPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0.0f);
        Ray        cursorRay = mainCamera.ScreenPointToRay(cursorPos);

        if (Physics.Raycast(cursorRay, out hitInfo, 100.0F, paintableLayerMask))
        {
            Paintable paintable = hitInfo.transform.parent.GetComponent <Paintable>();
            if (paintable.MeshCollider == null || paintable.MeshCollider.sharedMesh == null)
            {
                return(false);
            }

            Vector2 pixelUV = hitInfo.textureCoord;
            uvWorldPosition.x = pixelUV.x - paintCanvasCamera.orthographicSize; //To center the UV on X
            uvWorldPosition.y = pixelUV.y - paintCanvasCamera.orthographicSize; //To center the UV on Y
            uvWorldPosition.z = 0.0f;
            return(true);
        }

        return(false);
    }
Example #23
0
    void Update()
    {
        bool click;

        click = mouseSingleClick ? Input.GetMouseButtonDown(0) : Input.GetMouseButton(0);

        if (click)
        {
            Vector3    position = Input.mousePosition;
            Ray        ray      = cam.ScreenPointToRay(position);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100.0f))
            {
                Debug.DrawRay(ray.origin, hit.point - ray.origin, Color.red);
                transform.position = hit.point;
                Paintable p = hit.collider.GetComponent <Paintable>();
                if (p != null)
                {
                    PaintManager.instance.paint(p, hit.point, radius, hardness, strength, paintColor);
                }
            }
        }
    }
Example #24
0
    public void PaintTile(Paintable paintable)
    {
        paintable.GetComponent<SpriteRenderer>().sprite = level.tileType[tileToPaint].GetComponent<SpriteRenderer>().sprite;
        if (level.spawnObject[tileToPaint] != null) {
            SpriteRenderer renderer = level.spawnObject[tileToPaint].GetComponent<SpriteRenderer>();
            if (!renderer) {
                renderer = level.spawnObject[tileToPaint].GetComponentInChildren<SpriteRenderer>();
            }

            if (renderer) {
                paintable.GetComponent<Paintable>().shownPickup.GetComponent<SpriteRenderer>().sprite = renderer.sprite;
                paintable.GetComponent<Paintable>().shownPickup.SetActive(true);
            }
        } else {
            paintable.GetComponent<Paintable>().shownPickup.SetActive(false);
        }
        tileIDs[Mathf.RoundToInt(paintable.transform.position.x - xOffset), Mathf.RoundToInt(paintable.transform.position.y - yOffset)] = tileToPaint;
    }
Example #25
0
 private void OnDrawGizmos()
 {
     Gizmos.color = Paintable.GetColor(Color);
     Gizmos.DrawWireSphere(PaintTipPosition, paintBrushRadius);
 }
    public override void Update()
    {
        base.Update();
        Vector3    rayOrgin = OverworldController.Player.transform.position;
        RaycastHit hit;
        int        currentPaintFloor = -1;

        if (Physics.Raycast(rayOrgin, Vector3.down, out hit, 0.6f))
        {
            Paintable paintableScript = hit.collider.gameObject.GetComponent <Paintable>();
            if (paintableScript != null)
            {
                RenderTexture maskTexture   = paintableScript.getExtend();
                Vector2       hitCoordinate = hit.textureCoord;

                RenderTexture singlePixelTexture = new RenderTexture(1, 1, 0);
                Graphics.CopyTexture(
                    maskTexture,
                    0,
                    0,
                    (int)(hitCoordinate.x * 1024),
                    (int)(hitCoordinate.y * 1024),
                    1,
                    1,
                    singlePixelTexture,
                    0,
                    0,
                    0,
                    0
                    );
                RenderTexture.active = singlePixelTexture;

                Texture2D tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);

                tex.ReadPixels(new Rect(0, 0, 1, 1), 0, 0);
                Color underPixel = tex.GetPixel(0, 0);

                RenderTexture.active = null;
                singlePixelTexture.Release();

                if (underPixel.a > 0.8f)
                {
                    Vector3 underPixelVector = new Vector3(underPixel.r, underPixel.g, underPixel.b);
                    float   smallestDistance = 10000;
                    int     colorIdx         = 0;
                    foreach (Color abilityColor in abilityColors)
                    {
                        Vector3 abilityColorVector = new Vector3(abilityColor.r, abilityColor.g, abilityColor.b);
                        float   colorDistance      = Vector3.Distance(underPixelVector, abilityColorVector);
                        if (colorDistance < smallestDistance)
                        {
                            smallestDistance  = colorDistance;
                            currentPaintFloor = colorIdx;
                        }
                        colorIdx += 1;
                    }
                }
            }
        }
        Debug.Log(currentPaintFloor);
        if (currentPaintFloor == 1)
        {
            OverworldController.Player.GetComponent <CharacterMovementOverworld>().ForceJump(20);
        }
    }
Example #27
0
 void Start()
 {
     //doodleCanvas = GameObject.FindWithTag("SketchBook");
     paintable = UIManager.Instance.SketchBook.GetComponent <Paintable>();
 }
Example #28
0
 private void OnDrawGizmos()
 {
     Gizmos.color = Paintable.GetColor(color);
     Gizmos.DrawWireCube(Bounds.center, Bounds.size);
 }
Example #29
0
 private void Update()
 {
     foreach (Renderer renderer in renderers)
     {
         renderer.material.color = colorPainted == ColorType.None ? unpaintedColor : Paintable.GetColor(colorPainted);
     }
 }