Esempio n. 1
0
 void Awake()
 {
     main = this;
     content.Clear ();
     foreach (ContentAssistantItem item in cItems)
         content.Add(item.item.name, item.item);
 }
 public void Initialize()
 {
     main = this;
     content.Clear();
     foreach (ContentAssistantItem item in cItems)
     {
         content.Add(item.item.name, item.item);
     }
 }
			public override IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
				ContentAssistant contentAssistant = new ContentAssistant();
				contentAssistant.enableAutoActivation(true);
				//contentAssistant.enableAutoInsert(true);
				contentAssistant.enablePrefixCompletion(true);
				contentAssistant.setContentAssistProcessor(new ContentAssistProcessor(editor, sourceViewer), IDocument.DEFAULT_CONTENT_TYPE);
				return contentAssistant;
			}
    public override void OnInspectorGUI()
    {
        main = (ContentAssistant)target;
        Undo.RecordObject (main, "");
        if (main.cItems == null) main.cItems = new List<ContentAssistant.ContentAssistantItem> ();

        obj = (GameObject) EditorGUILayout.ObjectField("Item", obj, typeof (GameObject), false);
        category = EditorGUILayout.TextField ("Category", category);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button ("Add", GUILayout.Width (50))) {
            if (obj == null || category == "") return;
            ContentAssistant.ContentAssistantItem item;
            item.category = category;
            item.item = obj;
            main.cItems.Add(item);
            if (!visible.ContainsKey(category))
                visible.Add(category, true);
            else
                visible[category] = true;
            obj = null;
            category = "";
            return;
        }
        if (GUILayout.Button ("Clear", GUILayout.Width (50))) {
            obj = null;
            category = "";
        }
        if (GUILayout.Button ("Sort", GUILayout.Width (50))) {
            main.cItems.Sort(delegate(ContentAssistant.ContentAssistantItem x, ContentAssistant.ContentAssistantItem y) {
                return x.item.name.CompareTo(y.item.name);
            });
            categories.Sort (delegate(string x, string y) {
                return x.CompareTo(y);
            });
        }
        if (GUILayout.Button ("Show all", GUILayout.Width (60))) {
            foreach (string c in categories)
                visible[c] = true;
        }
        if (GUILayout.Button ("Hide all", GUILayout.Width (60))) {
            foreach (string c1 in categories)
                visible[c1] = false;
        }
        EditorGUILayout.EndHorizontal();
        categories.Clear ();
        foreach (ContentAssistant.ContentAssistantItem i in main.cItems)
            if (!categories.Contains (i.category)) {
                categories.Add (i.category);
                if (!visible.ContainsKey(i.category))
                    visible.Add(i.category, false);
            }
        foreach (string s in categories) {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(visible[s] ? "-" : "+", GUILayout.Width(20)))
                visible[s] = !visible[s];
            GUILayout.Label(s, EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();
            if (!visible[s]) continue;
            foreach (ContentAssistant.ContentAssistantItem j in main.cItems) {
                if (j.category == s) {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    if (GUILayout.Button ("X", GUILayout.Width (20))) {
                        obj = j.item;
                        category = j.category;
                        main.cItems.Remove(j);
                        return;
                    }
                    EditorGUILayout.ObjectField(j.item, typeof (GameObject), false, GUILayout.Width(250));
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
    }
    public override void OnInspectorGUI()
    {
        if (!metaTarget)
        {
            EditorGUILayout.HelpBox("ContentAssistant is missing", MessageType.Error);
            return;
        }
        main = (ContentAssistant)metaTarget;
        Undo.RecordObject(main, "");

        if (main.cItems == null)
        {
            main.cItems = new List <ContentAssistant.ContentAssistantItem> ();
        }

        foreach (ContentAssistant.ContentAssistantItem i in main.cItems)
        {
            if (!categories.ContainsKey(i.category))
            {
                categories.Add(i.category, new AnimBool(false));
                categories[i.category].valueChanged.AddListener(RepaintIt);
            }
        }

        foreach (var key in categories.Keys)
        {
            categories[key].target = GUILayout.Toggle(categories[key].target, key, EditorStyles.foldout);

            if (EditorGUILayout.BeginFadeGroup(categories[key].faded))
            {
                foreach (ContentAssistant.ContentAssistantItem j in main.cItems.FindAll(x => x.category == key))
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        obj           = j.item;
                        this.category = j.category;
                        main.cItems.Remove(j);
                        return;
                    }
                    GameObject _obj = (GameObject)EditorGUILayout.ObjectField(j.item, typeof(GameObject), false, GUILayout.Width(250));
                    if (j.item != _obj)
                    {
                        main.cItems[main.cItems.IndexOf(j)] = new ContentAssistant.ContentAssistantItem(_obj, key);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndFadeGroup();
        }

        #region Add item
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add", GUILayout.Width(50)))
        {
            if (obj == null || category == null)
            {
                return;
            }
            if (category == "")
            {
                category = "Other";
            }
            main.cItems.Add(new ContentAssistant.ContentAssistantItem(obj, category));
            if (!categories.ContainsKey(category))
            {
                categories.Add(category, new AnimBool(true));
            }
            else
            {
                categories[category].target = true;
            }
            obj      = null;
            category = "";
        }
        obj = (GameObject)EditorGUILayout.ObjectField(obj, typeof(GameObject), false, GUILayout.Width(150));
        GUILayout.Label("in", GUILayout.Width(30));
        category = GUILayout.TextField(category, GUILayout.Width(150));
        EditorGUILayout.EndHorizontal();
        #endregion
    }
Esempio n. 6
0
    public override void OnInspectorGUI()
    {
        main = (ContentAssistant)target;
        if (main.cItems == null)
        {
            main.cItems = new List <ContentAssistant.ContentAssistantItem> ();
        }

        obj      = (GameObject)EditorGUILayout.ObjectField("Item", obj, typeof(GameObject), false);
        category = EditorGUILayout.TextField("Category", category);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add", GUILayout.Width(50)))
        {
            if (obj == null || category == "")
            {
                return;
            }
            ContentAssistant.ContentAssistantItem item;
            item.category = category;
            item.item     = obj;
            main.cItems.Add(item);
            if (!visible.ContainsKey(category))
            {
                visible.Add(category, true);
            }
            else
            {
                visible[category] = true;
            }
            obj      = null;
            category = "";
            return;
        }
        if (GUILayout.Button("Clear", GUILayout.Width(50)))
        {
            obj      = null;
            category = "";
        }
        if (GUILayout.Button("Sort", GUILayout.Width(50)))
        {
            main.cItems.Sort(delegate(ContentAssistant.ContentAssistantItem x, ContentAssistant.ContentAssistantItem y) {
                return(x.item.name.CompareTo(y.item.name));
            });
            categories.Sort(delegate(string x, string y) {
                return(x.CompareTo(y));
            });
        }
        if (GUILayout.Button("Show all", GUILayout.Width(60)))
        {
            foreach (string c in categories)
            {
                visible[c] = true;
            }
        }
        if (GUILayout.Button("Hide all", GUILayout.Width(60)))
        {
            foreach (string c1 in categories)
            {
                visible[c1] = false;
            }
        }
        EditorGUILayout.EndHorizontal();
        categories.Clear();
        foreach (ContentAssistant.ContentAssistantItem i in main.cItems)
        {
            if (!categories.Contains(i.category))
            {
                categories.Add(i.category);
                if (!visible.ContainsKey(i.category))
                {
                    visible.Add(i.category, false);
                }
            }
        }
        foreach (string s in categories)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button(visible[s] ? "-" : "+", GUILayout.Width(20)))
            {
                visible[s] = !visible[s];
            }
            GUILayout.Label(s, EditorStyles.boldLabel);
            EditorGUILayout.EndHorizontal();
            if (!visible[s])
            {
                continue;
            }
            foreach (ContentAssistant.ContentAssistantItem j in main.cItems)
            {
                if (j.category == s)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        obj      = j.item;
                        category = j.category;
                        main.cItems.Remove(j);
                        return;
                    }
                    EditorGUILayout.ObjectField(j.item, typeof(GameObject), false, GUILayout.Width(250));
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
        EditorUtility.SetDirty(main);
    }