Ejemplo n.º 1
0
    public static bool AddClipPopup(string a_rLabel, out Uni2DAnimationClip a_rAnimationClip, params GUILayoutOption[] a_rGUILayoutOptions)
    {
        bool bHasChanged;

        // Get button control ID
        int iControlID = GUIUtility.GetControlID(FocusType.Passive);

        EditorGUI.BeginChangeCheck( );
        {
            // Get selected value for our control
            // If no PopupCallbackInfo instance exists, the returned value is a_rClip
            a_rAnimationClip = PopupCallbackInfo <Uni2DAnimationClip> .GetSelectedValueForControl(iControlID, null);
        }
        bHasChanged = EditorGUI.EndChangeCheck( );

        // Create a new generic menu
        // Each item menu will use AtlasPopupCallback as callback
        // AtlasPopupCallback will perform the logic and save the selected atlas to
        // the PopupCallbackInfo instance.
        if (GUILayout.Button(a_rLabel, a_rGUILayoutOptions))
        {
            // Create a new popup callback info (control ID) and save it as current instance
            PopupCallbackInfo <Uni2DAnimationClip> .instance = new PopupCallbackInfo <Uni2DAnimationClip>(iControlID, null);

            // Create our generic menu
            GenericMenu oPopupMenu = new GenericMenu( );

            // "Create" special item menu
            oPopupMenu.AddItem(new GUIContent("Create a new animation clip...", "Creates a new Uni2D animation clip"), false, ClipPopupCallback, "NEW");

            Uni2DEditorAssetTable rAssetTable = Uni2DEditorAssetTable.Instance;

            // List all available atlases
            Dictionary <string, string> oAvailableAnimationClips = rAssetTable.GetAllClipNames( );
            if (oAvailableAnimationClips.Count != 0)
            {
                oPopupMenu.AddSeparator("");

                // Add an item menu for each ready to use atlas
                foreach (KeyValuePair <string, string> rAnimationClipNameGUIDPair in oAvailableAnimationClips)
                {
                    oPopupMenu.AddItem(new GUIContent(rAnimationClipNameGUIDPair.Value), false, ClipPopupCallback, rAnimationClipNameGUIDPair.Key);
                }
            }

            // Finally show up the menu
            oPopupMenu.ShowAsContext( );
        }

        return(bHasChanged);
    }