private static void GenerateTreeElements(AssetViewItem assetItem, TreeViewItem root)
        {
            string           activePath   = assetItem.displayName + ":";
            PropertyViewItem propertyRoot = new PropertyViewItem(activePath.GetHashCode(), 0, activePath, true)
            {
                icon = assetItem.icon
            };

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

            List <IConformObject> data = assetItem.conformData;

            for (int i = 0; i < data.Count; ++i)
            {
                // Add all ConformObject's that are properties
                if (data[i] is PropertyConformObject)
                {
                    AddChildProperty(activePath, propertyRoot, (PropertyConformObject)data[i], assetItem, 1);
                }
            }
        }
예제 #2
0
        protected override void DoubleClickedItem(int id)
        {
            base.DoubleClickedItem(id);
            AssetViewItem pathItem = FindItem(id, rootItem) as AssetViewItem;

            if (pathItem == null)
            {
                return;
            }

            Selection.activeObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(pathItem.path);
            EditorGUIUtility.PingObject(Selection.activeObject);
        }
예제 #3
0
        internal void SetupSelection(IList <int> selectedIds)
        {
            m_SelectedItems.Clear();

            for (int i = 0; i < selectedIds.Count; ++i)
            {
                AssetViewItem item = FindItem(selectedIds[i], rootItem) as AssetViewItem;
                if (item != null)
                {
                    m_SelectedItems.Add(item);
                }
            }

            m_PropertyList.SetSelection(m_SelectedItems);
        }
        private void CopyProperties(AssetViewItem item)
        {
            if (m_ConstrainProperties.Count > 0)
            {
                SerializedObject profileSerializedObject = new SerializedObject(ReferenceAssetImporter);
                SerializedObject assetImporterSO         = new SerializedObject(item.AssetImporter);
                CopyConstrainedProperties(assetImporterSO, profileSerializedObject);
            }
            else
            {
                EditorUtility.CopySerialized(ReferenceAssetImporter, item.AssetImporter);
            }

            item.conforms = true;
            item.ReimportAsset();
        }
예제 #5
0
        protected override void ContextClickedItem(int id)
        {
            // TODO allow on a folder
            AssetViewItem item = FindItem(id, rootItem) as AssetViewItem;

            if (item == null || item.conforms)
            {
                return;
            }

            GenericMenu menu = new GenericMenu();

            // TODO get list of possible selections from modules

            menu.AddItem(new GUIContent("Conform to Template Properties"), false, FixCallbackImporterProperties, item);
            menu.ShowAsContext();
        }
        public void FixCallback(AssetDetailList calledFromTreeView, object context)
        {
            // TODO find out how to multi select
            // TODO if selection is a folder

            AssetViewItem selectedNodes = context as AssetViewItem;

            if (selectedNodes != null)
            {
                CopyProperties(selectedNodes);
                foreach (IConformObject data in selectedNodes.conformData)
                {
                    data.Conforms = true;
                }
                calledFromTreeView.m_PropertyList.Reload();
            }
            else
            {
                Debug.LogError("Could not fix Asset with no Assets selected.");
            }
        }
예제 #7
0
        protected override void RowGUI(RowGUIArgs args)
        {
            AssetViewItem item = args.item as AssetViewItem;

            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;
                }

                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);
            }
        }
예제 #8
0
        private void GenerateTreeElements(AuditProfile profile, TreeViewItem root)
        {
            List <string> associatedAssets = GetFilteredAssets(profile);

            // early out if there are no affected assets
            if (associatedAssets.Count == 0)
            {
                Debug.Log("No matching assets found for " + profile.name);
                return;
            }

            string        activePath   = "Assets";
            AssetViewItem assetsFolder = new AssetViewItem(activePath.GetHashCode(), 0, activePath, true);

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

            Dictionary <int, AssetViewItem> items = new Dictionary <int, AssetViewItem>
            {
                { activePath.GetHashCode(), assetsFolder }
            };

            foreach (var assetPath in associatedAssets)
            {
                // split the path to generate folder structure
                string path    = assetPath.Substring(7);
                var    strings = path.Split(new[] { '/' }, StringSplitOptions.None);
                activePath = "Assets";

                AssetViewItem active = assetsFolder;

                // for each module
                List <IConformObject> conformData = profile.GetConformData(assetPath);
                bool result = true;
                for (int i = 0; i < conformData.Count; ++i)
                {
                    if (conformData[i].Conforms == false)
                    {
                        result = false;
                        break;
                    }
                }

                if (!result && assetsFolder.conforms)
                {
                    assetsFolder.conforms = false;
                }

                AssetImporter    assetImporter   = AssetImporter.GetAtPath(assetPath);
                SerializedObject assetImporterSO = new SerializedObject(assetImporter);

                // the first entries have lower depth
                for (int i = 0; i < strings.Length; i++)
                {
                    activePath += "/" + strings[i];
                    int id = activePath.GetHashCode();

                    if (i == strings.Length - 1)
                    {
                        AssetViewItem item = new AssetViewItem(id, i + 1, strings[i], result)
                        {
                            icon        = AssetDatabase.GetCachedIcon(assetPath) as Texture2D,
                            path        = activePath,
                            conformData = conformData,
                            assetObject = assetImporterSO,
                            isAsset     = true
                        };
                        active.AddChild(item);
                        active = item;
                        if (items.ContainsKey(id))
                        {
                            Debug.LogError("id already in for " + activePath);
                        }
                        items.Add(id, item);
                    }
                    else
                    {
                        AssetViewItem item;
                        if (!items.TryGetValue(id, out item))
                        {
                            item = new AssetViewItem(id, i + 1, strings[i], result)
                            {
                                path = activePath,
                                icon = AssetDatabase.GetCachedIcon(activePath) as Texture2D
                            };
                            active.AddChild(item);
                            items.Add(id, item);
                        }
                        else if (result == false)
                        {
                            if (item.conforms)
                            {
                                item.conforms = false;
                            }
                        }

                        active = item;
                    }
                }
            }
        }
        private static void AddChildProperty(string parentPath, PropertyViewItem parent, PropertyConformObject propertyConformObject, AssetViewItem assetItem, int depth, int arrayIndex = -1)
        {
            string           extra      = arrayIndex >= 0 ? arrayIndex.ToString() : "";
            string           activePath = parentPath + propertyConformObject.Name + extra;
            PropertyViewItem property   = new PropertyViewItem(activePath, depth, propertyConformObject)
            {
                assetViewItem = assetItem
            };

            parent.AddChild(property);

            for (int i = 0; i < propertyConformObject.SubObjects.Count; ++i)
            {
                // TODO will this be slow? , need to see if there is a better way to cache object type
                if (propertyConformObject.SubObjects[i] is PropertyConformObject)
                {
                    AddChildProperty(activePath, property, (PropertyConformObject)propertyConformObject.SubObjects[i], assetItem, depth + 1, propertyConformObject.AssetSerializedProperty.isArray ? i : -1);
                }
            }
        }