Example #1
0
    public void OnSubClick()
    {
        if (images.Count == 0)
        {
            return;
        }
        //int removeIndex = Random.Range(0, images.Count - 1);
        int removeIndex       = 0;
        UIDynamicRawImage obj = images[removeIndex];

        images.RemoveAt(removeIndex);
        GameObject.Destroy(obj.transform.parent.parent.gameObject);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        UIDynamicRawImage myScript = (UIDynamicRawImage)target;

        GUILayout.Space(5);
        EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------");
        GUILayout.Space(5);
        myScript.mGroup = (DynamicAtlasGroup)EditorGUILayout.EnumPopup("Group", myScript.mGroup);
        EditorGUILayout.LabelField("Texture Path", myScript.currentPath);

        GUILayout.Space(5);


        if (EditorApplication.isPlaying)
        {
            if (GUILayout.Button("Show DynamicAtlas"))
            {
                DynamicAtlasWindow.ShowWindow(myScript.mGroup);
            }
        }
        else
        {
            if ((lastTexture != myScript.texture) || (myScript.texture != null && myScript.currentPath == null))
            {
                lastTexture = myScript.texture;
                string path = AssetDatabase.GetAssetPath(myScript.texture);
                myScript.currentPath = path;
            }

            if (myScript.texture == null)
            {
                lastTexture          = null;
                myScript.currentPath = null;
            }
            else
            {
                if (String.IsNullOrEmpty(myScript.currentPath))
                {
                    string path = AssetDatabase.GetAssetPath(myScript.texture);
//                    Debug.Log($"myScript.currentPath:{myScript.currentPath}   path:{path}");
                    myScript.currentPath = path;
                }
            }
        }
        EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------");

        EditorGUILayout.LabelField("--------------------------------------------------------------------------------------------------------------------");
    }
Example #3
0
    public void OnAddClick()
    {
        index++;
        var item = imageParent.AddChild(image.gameObject);
        var pos  = image.transform.localPosition;

        item.transform.localPosition = new Vector3(pos.x + (index + 1) * 100, pos.y + (index + 1) * 100, 0);

        UIDynamicRawImage data      = item.transform.Find("RawImage/DynamicImage").GetComponent <UIDynamicRawImage>();
        string            imageName = paths[pathIndex];

        data.SetImage(imageName);
        data.gameObject.name = imageName;
        pathIndex++;
        if (pathIndex >= paths.Count)
        {
            pathIndex = 0;
        }
        images.Add(data);
    }