Beispiel #1
0
        protected override void ContextClickedItem(int id)
        {
            ConformObjectTreeViewItem item = FindItem(id, rootItem) as ConformObjectTreeViewItem;

            Assert.IsNotNull(item);
            if (item.conforms)
            {
                return;
            }

            // TODO ask the ConformObject to do this
            PropertyConformObject propertyConformObject = item.conformObject as PropertyConformObject;

            if (propertyConformObject != null)
            {
                GenericMenu menu = new GenericMenu();
                if (propertyConformObject.TemplateType == SerializedPropertyType.Generic)
                {
                    menu.AddItem(new GUIContent("Set children to Template Values"), false, FixCallback, item);
                }
                else if (propertyConformObject.TemplateType == SerializedPropertyType.ArraySize)
                {
                    menu.AddDisabledItem(new GUIContent("Cannot set array size"));
                }
                else
                {
                    menu.AddItem(new GUIContent("Set to " + propertyConformObject.TemplateValue), false, FixCallback, item);
                }

                menu.ShowAsContext();
            }
        }
Beispiel #2
0
        protected override void RowGUI(RowGUIArgs args)
        {
            ConformObjectTreeViewItem item = args.item as ConformObjectTreeViewItem;

            if (item == null)
            {
                Debug.LogWarning("Unknown TreeViewItem for conform tree");
                return;
            }

            for (int i = 0; i < args.GetNumVisibleColumns(); ++i)
            {
                if (i == 0)
                {
                    ConformsGUI(args.GetCellRect(i), item);
                }
                else if (i == 1)
                {
                    PropertyNameGUI(args.GetCellRect(i), item, ref args);
                }
                else if (i == 2 && item.conformObject != null)
                {
                    ExpectedValueGUI(args.GetCellRect(i), item);
                }
                else if (i == 3 && item.conformObject != null)
                {
                    ActualValueGUI(args.GetCellRect(i), item);
                }
            }
        }
Beispiel #3
0
        void PropertyNameGUI(Rect cellRect, ConformObjectTreeViewItem item, ref RowGUIArgs args)
        {
            float indent = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;

            Rect labelRect = cellRect;

            labelRect.xMin += indent;
            Rect iconRect = cellRect;

            if (args.item.icon != null)
            {
                iconRect.xMin += indent;
                iconRect.width = iconRect.height;
                GUI.DrawTexture(iconRect, args.item.icon);
                labelRect.x     += 18;
                labelRect.width -= 18;
            }

            if (item.conforms == false)
            {
                Color old = GUI.color;
                GUI.color = k_ConformFailColor;
                EditorGUI.LabelField(labelRect, args.label);
                GUI.color = old;
            }
            else
            {
                EditorGUI.LabelField(labelRect, args.label);
            }
        }
Beispiel #4
0
 void ConformsGUI(Rect cellRect, ConformObjectTreeViewItem item)
 {
     if (!item.conforms)
     {
         Color old = GUI.color;
         GUI.color = k_ConformFailColor * 0.8f;
         GUI.DrawTexture(cellRect, m_UnconformedTexture);
         GUI.color = old;
     }
 }
Beispiel #5
0
        void SortByMultipleColumns(IList <TreeViewItem> rows)
        {
            int[] sortedColumns = multiColumnHeader.state.sortedColumns;
            if (sortedColumns.Length == 0)
            {
                return;
            }

            bool[] columnAscending = new bool[sortedColumns.Length];
            for (int i = 0; i < sortedColumns.Length; i++)
            {
                columnAscending[i] = multiColumnHeader.IsSortedAscending(sortedColumns[i]);
            }

            ItemTree         root  = new ItemTree(null);
            Stack <ItemTree> stack = new Stack <ItemTree>();

            stack.Push(root);
            foreach (TreeViewItem row in rows)
            {
                ConformObjectTreeViewItem r = row as ConformObjectTreeViewItem;
                if (r == null)
                {
                    continue;
                }
                int activeParentDepth = stack.Peek().Depth;

                while (row.depth <= activeParentDepth)
                {
                    stack.Pop();
                    activeParentDepth = stack.Peek().Depth;
                }

                if (row.depth > activeParentDepth)
                {
                    ItemTree t = new ItemTree(r);
                    stack.Peek().AddChild(t);
                    stack.Push(t);
                }
            }

            root.Sort(sortedColumns, columnAscending);

            // convert back to rows
            List <TreeViewItem> newRows = new List <TreeViewItem>(rows.Count);

            root.ToList(newRows);
            rows.Clear();
            foreach (TreeViewItem treeViewItem in newRows)
            {
                rows.Add(treeViewItem);
            }
        }
Beispiel #6
0
        private static void FixCallback(object context)
        {
            if (context == null)
            {
                return;
            }

            // TODO multi-select
            ConformObjectTreeViewItem selectedNodes = context as ConformObjectTreeViewItem;

            Assert.IsNotNull(selectedNodes, "Context must be a ConformObjectTreeViewItem");
            selectedNodes.ApplyConform();
        }
Beispiel #7
0
        public void AddTreeViewItems(int parentId, ConformObjectTreeViewItem parent, AssetsTreeViewItem assetsTreeItem, int depth, int arrayIndex = -1)
        {
            int activePath = parentId + (Name.GetHashCode() * 31);
            ConformObjectTreeViewItem conformObjectTree = new ConformObjectTreeViewItem(activePath, depth, this)
            {
                AssetsTreeViewItem = assetsTreeItem
            };

            parent.AddChild(conformObjectTree);

            for (int i = 0; i < SubObjects.Count; ++i)
            {
                SubObjects[i].AddTreeViewItems(activePath, conformObjectTree, assetsTreeItem, depth + 1);
            }
        }
Beispiel #8
0
        void ExpectedValueGUI(Rect cellRect, ConformObjectTreeViewItem item)
        {
            Rect labelRect = cellRect;

            if (item.conforms == false)
            {
                Color old = GUI.color;
                GUI.color = k_ConformFailColor;
                EditorGUI.LabelField(labelRect, item.conformObject.ExpectedValue);
                GUI.color = old;
            }
            else
            {
                EditorGUI.LabelField(labelRect, item.conformObject.ExpectedValue);
            }
        }
        protected override void RowGUI(RowGUIArgs args)
        {
            ConformObjectTreeViewItem item = args.item as ConformObjectTreeViewItem;

            if (item != null)
            {
                float num = GetContentIndent(item) + extraSpaceBeforeIconAndLabel;

                Rect r = args.rowRect;
                if (args.item.icon != null)
                {
                    r.xMin += num;
                    r.width = r.height;
                    GUI.DrawTexture(r, args.item.icon);
                }

                Color old = GUI.color;
                if (item.conforms == false)
                {
                    GUI.color = k_ConformFailColor;
                }

                // This displays what the current value is
                if (item.conformObject != null && r.width > 400)
                {
                    Rect or = new Rect(r);
                    or.x    += r.width - 100;
                    or.width = 100;
                    EditorGUI.LabelField(or, item.conformObject.ActualValue);
                }

                r       = args.rowRect;
                r.xMin += num;
                if (args.item.icon != null)
                {
                    r.x     += r.height + 2f;
                    r.width -= r.height + 2f;
                }

                EditorGUI.LabelField(r, args.label);
                GUI.color = old;
            }
            else
            {
                base.RowGUI(args);
            }
        }
Beispiel #10
0
        private static void GenerateTreeElements(AssetsTreeViewItem assetsTreeItem, TreeViewItem root)
        {
            string activePath = assetsTreeItem.displayName + ":";

            // create root object for the Asset
            ConformObjectTreeViewItem conformObjectAssetRoot = new ConformObjectTreeViewItem(activePath.GetHashCode(), 0, activePath, true)
            {
                icon = assetsTreeItem.icon
            };

            if (conformObjectAssetRoot.children == null)
            {
                conformObjectAssetRoot.children = new List <TreeViewItem>();
            }
            root.AddChild(conformObjectAssetRoot);

            List <ConformData> data = assetsTreeItem.conformData;

            for (int i = 0; i < data.Count; ++i)
            {
                if (data[i].ConformObjects.Count == 0)
                {
                    continue;
                }

                int moduleHash = data[i].ImportTask.GetHashCode() + i;
                ConformObjectTreeViewItem conformObjectModuleRoot = new ConformObjectTreeViewItem(moduleHash, 1, data[i].ImportTask.GetType().Name, true);
                if (conformObjectModuleRoot.children == null)
                {
                    conformObjectModuleRoot.children = new List <TreeViewItem>();
                }
                conformObjectAssetRoot.AddChild(conformObjectModuleRoot);

                if (data[i].Conforms == false)
                {
                    conformObjectModuleRoot.conforms = false;
                    conformObjectAssetRoot.conforms  = false;
                }

                foreach (var conformObject in data[i].ConformObjects)
                {
                    conformObject.AddTreeViewItems(moduleHash, conformObjectModuleRoot, assetsTreeItem, 2);
                }
            }
        }
        public void AddTreeViewItems(int parentId, ConformObjectTreeViewItem parent, AssetsTreeViewItem assetsTreeItem, int depth, int arrayIndex = -1)
        {
            string extra         = arrayIndex >= 0 ? arrayIndex.ToString() : "";
            int    hashCodeForID = parentId + (Name + extra).GetHashCode() * 31;
            ConformObjectTreeViewItem conformObjectTree = new ConformObjectTreeViewItem(hashCodeForID, depth, this)
            {
                AssetsTreeViewItem = assetsTreeItem
            };

            parent.AddChild(conformObjectTree);

            for (int i = 0; i < SubObjects.Count; ++i)
            {
                // TODO will this be slow? , need to see if there is a better way to cache object type
                if (SubObjects[i] is PropertyConformObject)
                {
                    SubObjects[i].AddTreeViewItems(hashCodeForID, conformObjectTree, assetsTreeItem, depth + 1, AssetSerializedProperty.isArray ? i : -1);
                }
            }
        }
Beispiel #12
0
 public ItemTree(ConformObjectTreeViewItem i)
 {
     item     = i;
     children = new List <ItemTree>();
 }