Example #1
0
 // called on InitializeOnLoad
 static BobbinCore()
 {
     if (Instance == null)
     {
         Instance = new BobbinCore();
     }
     EditorApplication.update += Instance.OnEditorUpdate;
 }
Example #2
0
        void ToolBar()
        {
            using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("Refresh", "force Bobbin to scan for changed files immediately"), GUILayout.Width(80)))
                {
                    BobbinCore.DoRefresh();
                }
                asset.autoRefresh = EditorGUILayout.ToggleLeft(new GUIContent("Auto refresh?", "if enabled, Bobbin will automatically download new files from the internet"), asset.autoRefresh, GUILayout.MaxWidth(90));

                EditorGUILayout.Space();
                GUILayout.Label("every", GUILayout.MaxWidth(36));
                asset.refreshInterval = System.Convert.ToDouble(Mathf.Clamp(EditorGUILayout.IntField(System.Convert.ToInt32(asset.refreshInterval), GUILayout.MaxWidth(30)), 5, 999));
                GUILayout.Label("sec.", GUILayout.MaxWidth(30));

                GUILayout.EndHorizontal();
                GUILayout.Space(5);
                if (asset.autoRefresh)
                {
                    Rect rect            = GUILayoutUtility.GetRect(50, 18, "TextField", GUILayout.MaxWidth(10000));
                    var  progress        = EditorApplication.timeSinceStartup - BobbinCore.lastRefreshTime;
                    var  progressPercent = progress / BobbinSettings.Instance.refreshInterval;
                    EditorGUI.ProgressBar(rect, Mathf.Clamp01(System.Convert.ToSingle(progressPercent)), "Auto refresh in " + (BobbinSettings.Instance.refreshInterval - progress).ToString("F0"));
                }
            }
            using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
            {
                var style = "miniButton";

                if (GUILayout.Button("Add New File", style))
                {
                    Undo.RecordObject(asset, "Add Item To Asset");

                    // Add item as child of selection
                    var selection = m_TreeView.GetSelection();
                    // TreeElement parent = (selection.Count == 1 ? m_TreeView.treeModel.Find(selection[0]) : null) ?? m_TreeView.treeModel.root;
                    TreeElement parent  = m_TreeView.treeModel.root;
                    int         depth   = parent != null ? parent.depth + 1 : 0;
                    int         id      = m_TreeView.treeModel.GenerateUniqueID();
                    var         element = new BobbinPath("Item " + id, depth, id);
                    m_TreeView.treeModel.AddElement(element, parent, 0);

                    // Select newly created element
                    m_TreeView.SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame);
                }

                if (GUILayout.Button("Remove Highlighted File(s)", style))
                {
                    Undo.RecordObject(asset, "Remove Item From Asset");
                    var selection = m_TreeView.GetSelection();
                    m_TreeView.treeModel.RemoveElements(selection);
                }
            }
        }
Example #3
0
        void CellGUI(Rect cellRect, TreeViewItem <BobbinPath> item, MyColumns column, ref RowGUIArgs args)
        {
            // Center cell rect vertically (makes it easier to place controls, icons etc in the cells)
            CenterRectUsingSingleLineHeight(ref cellRect);

            switch (column)
            {
            // case MyColumns.Icon1:
            //  {
            //      GUI.DrawTexture(cellRect, s_TestIcons[GetIcon1Index(item)], ScaleMode.ScaleToFit);
            //  }
            //  break;
            case MyColumns.Toggle:
            {
                item.data.enabled = EditorGUI.Toggle(cellRect, new GUIContent("", "enable refresh?"), item.data.enabled);         // hide when outside cell rect
            }
            break;

            case MyColumns.Name:
            {
                cellRect.width     -= 20;
                item.data.name      = GUI.TextField(cellRect, item.data.name);
                cellRect.x         += cellRect.width;
                cellRect.width      = 20;
                GUI.backgroundColor = Color.Lerp(Color.red, Color.white, 0.75f);
                if (GUI.Button(cellRect, new GUIContent("x", "delete this item")))
                {
                    if (EditorUtility.DisplayDialog("Bobbin: confirm deletion", "Really delete " + item.data.name + "?", "Yes, delete", "No, cancel"))
                    {
                        var list = new List <BobbinPath>();
                        list.Add(item.data);
                        treeModel.RemoveElements(list);
                    }
                }
                GUI.backgroundColor = Color.white;
            }
            break;

            case MyColumns.Value1:
            case MyColumns.Value2:
            case MyColumns.Value3:
            {
                cellRect.xMin += 5f;         // When showing controls make some extra spacing

                if (column == MyColumns.Value1)
                {
                    bool hasURL = item.data.url != null && item.data.url.Length > 4;
                    if (hasURL)
                    {
                        cellRect.width -= 20;
                    }
                    item.data.url = GUI.TextField(cellRect, item.data.url);
                    if (hasURL)
                    {
                        cellRect.x    += cellRect.width;
                        cellRect.width = 20;
                        if (GUI.Button(cellRect, new GUIContent(">", "click to view in web browser: " + BobbinCore.UnfixURL(item.data.url))))
                        {
                            Application.OpenURL(BobbinCore.UnfixURL(item.data.url));
                        }
                    }
                }
                if (column == MyColumns.Value2)
                {
                    item.data.fileType = (Bobbin.FileType)EditorGUI.EnumPopup(cellRect, (Enum)item.data.fileType);
                }
                if (column == MyColumns.Value3)
                {
                    if (item.data.assetReference != null)
                    {
                        cellRect.x              += 24;
                        cellRect.width          -= 24;
                        GUI.enabled              = false;
                        item.data.assetReference = EditorGUI.ObjectField(cellRect, item.data.assetReference, typeof(UnityEngine.Object), false);
                        GUI.enabled              = true;
                        cellRect.x              -= 20;
                        cellRect.width           = 20;
                        if (GUI.Button(cellRect, new GUIContent("x", "reset asset file path\n" + item.data.filePath)))
                        {
                            item.data.assetReference = null;
                            item.data.filePath       = "";
                            item.data.lastFileHash   = "";
                        }
                    }
                    else
                    {
                        if (GUI.Button(cellRect, new GUIContent("Save As...", "click to select asset file path")))
                        {
                            var newPath = EditorUtility.SaveFilePanelInProject("Bobbin: save " + item.data.name + " URL as file...", item.data.name + "." + item.data.fileType.ToString(), item.data.fileType.ToString(), "Save URL as file...");
                            if (newPath != null && newPath.Length > 0)
                            {
                                item.data.filePath     = newPath;
                                item.data.lastFileHash = "";
                                if (item.data.url.Length > 4)
                                {         // only fetch from WWW if user inputed a URL
                                    BobbinCore.DoRefresh();
                                }
                            }
                        } // end if button
                    }     // end else
                }         // end if column3
            }

            break;
            }
        }