Esempio n. 1
0
        public void Set(TextureEntry entry)
        {
            Init();

            TextureEditorManager master = FindObjectOfType <TextureEditorManager> ();

            MeshRenderer mr = GetComponent <MeshRenderer> ();

            entry.SetTextureTo(master.targetSharedMaterial ? mr.sharedMaterial : mr.material, orgTexture);

            textureFilePath = entry.TexturePath;
            editedTexture   = entry.rawImage.texture;
        }
        // Update is called once per frame
        void Update()
        {
            if (applying)
            {
                return;
            }

            if (EventSystem.current.IsPointerOverGameObject())
            {
                ResetTexture();
                return;
            }

            if (currentTextureEntry != null)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, 100))
                {
                    MeshRenderer r = hit.transform.GetComponent <MeshRenderer> ();
                    if (r == null)
                    {
                        ResetTexture();
                        return;
                    }


                    if (pointedRenderer != r)
                    {
                        if (pointedRenderer != null)
                        {
                            ResetTexture();
                        }
                        pointedRenderer = r;

                        Material mat = targetSharedMaterial ? r.sharedMaterial : r.material;
                        if (!orgTextureMap.ContainsKey(mat))
                        {
                            EditedTexture et = pointedRenderer.GetComponent <EditedTexture> ();
                            if (et)
                            {
                                orgTextureMap [mat] = et.orgTexture;
                            }
                            else
                            {
                                orgTextureMap [mat] = mat.mainTexture;
                            }
                        }
                        currentTextureEntry.SetTextureTo(mat, orgTextureMap [mat]);
                    }
                }
                else if (pointedRenderer != null)
                {
                    ResetTexture();
                    return;
                }
            }
            if (Input.GetMouseButtonDown(0))
            {
                if (pointedRenderer != null)
                {
                    applying = true;
                    dialog.Show("Apply this texture?", "Are you applying this texture?",
                                "Apply", "Cancel", (x) => {
                        if (x)
                        {
                            EditedTexture et = AddEditedTextureTo(pointedRenderer.gameObject);
                            ResetTexture();
                            et.Set(currentTextureEntry);
                            pointedRenderer = null;

                            applying = false;
                        }
                        else
                        {
                            applying = false;
                        }
                    });
                }
            }
        }