public void DataLoadCallback(object o)
        {
            TextureEntry[] entries = scrollContent.GetComponentsInChildren <TextureEntry> ();
            Dictionary <string, TextureEntry> dict = new Dictionary <string, TextureEntry> ();

            foreach (var entry in entries)
            {
                if (entry.TexturePath == null)
                {
                    continue;
                }
                dict [entry.TexturePath] = entry;
            }

            EditedTexture[] ets = FindObjectsOfType <EditedTexture> ();
            foreach (EditedTexture et in ets)
            {
                et.Restore();
            }

            SavedEditedTexture[] sets = o as SavedEditedTexture[];
            foreach (var s in sets)
            {
                if (s.textureFilePath != null && dict.ContainsKey(s.textureFilePath))
                {
                    GameObject    go = GameObject.Find(s.path);
                    EditedTexture et = AddEditedTextureTo(go);
                    et.Set(dict [s.textureFilePath]);
                }
            }

            orgTextureMap.Clear();
        }
        private EditedTexture AddEditedTextureTo(GameObject go)
        {
            EditedTexture[] ets = go.GetComponents <EditedTexture> ();
            foreach (var e in ets)
            {
                e.Restore();
                Destroy(e);
            }
            EditedTexture et = go.AddComponent <EditedTexture> ();

            return(et);
        }
        private void ResetTexture()
        {
            if (pointedRenderer == null)
            {
                return;
            }

            Material      mat = targetSharedMaterial ? pointedRenderer.sharedMaterial : pointedRenderer.material;
            EditedTexture et  = pointedRenderer.GetComponent <EditedTexture> ();

            if (et)
            {
                et.SetTextureTo(mat);
            }
            else if (orgTextureMap.ContainsKey(mat))
            {
                mat.mainTexture = orgTextureMap [mat];
            }

            pointedRenderer = null;
        }
        // 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;
                        }
                    });
                }
            }
        }