コード例 #1
0
        private static void UpdateExistingRules()
        {
            // clear current list
            assetRules = new List <AssetAuditor.AssetRule>();

            // get all assets in the proxyassets folder
            foreach (var asset in AssetDatabase.FindAssets("", new[] { AssetAuditorPreferences.ProxyAssetsDirectory }))
            {
                var guidToAssetPath = AssetDatabase.GUIDToAssetPath(asset);
                var assetImporter   = AssetImporter.GetAtPath(guidToAssetPath);

                AssetAuditor.AssetRule ar = new AssetAuditor.AssetRule();
                ar = JsonUtility.FromJson <AssetAuditor.AssetRule>(assetImporter.userData);
                assetRules.Add(ar);
            }
            int i = 0;

            // make sure that the current asset is selected from assetRules
            foreach (var assetRule in assetRules)
            {
                if (assetRule.AssetGuid == currentAsset)
                {
                    selected = i;
                    return;
                }
                i++;
            }
            // if we get to here we couldnt find and asset to be the currently selected
            // set it to -1 and ignore anything to be currently selected
            selected     = -1;
            currentAsset = "";
        }
コード例 #2
0
        private void DoRuleSelectionGUI()
        {
            EditorGUI.BeginChangeCheck();
            selected = EditorGUI.Popup(ruleSelectRect, "Rule Name", selected, assetRuleNames.ToArray());
            if (EditorGUI.EndChangeCheck())
            {
                selectedSelective = 0;
                GatherData();
            }

            // make wildcard editable and update selection from it
            if (assetRules != null && selected != -1)// && !string.IsNullOrEmpty(assetRules[selected].WildCard))
            {
                AssetAuditor.AssetRule ar = assetRules[selected];
                EditorGUI.BeginChangeCheck();
                ar.WildCard = EditorGUI.TextField(wildCardDisplayRect, "WildCard ", ar.WildCard);
                if (EditorGUI.EndChangeCheck())
                {
                    assetRules[selected] = ar;
                    GatherData();
                    AssetAuditor.WriteUserData(AssetDatabase.GUIDToAssetPath(ar.AssetGuid), ar);
                }

                if (ar.SelectiveProperties != null && ar.SelectiveProperties.Count > 0)
                {
                    selectedSelective = EditorGUI.Popup(SelectivePropRect, "Selective Properties", selectedSelective, ar.SelectiveProperties.ToArray());
                }
                else
                {
                    EditorGUI.LabelField(SelectivePropRect, " No Selective Properties in the Asset Rule");
                }

                if (GUI.Button(AddSelectivePropRect, "+"))
                {
                    // add a new selective property
                    if (ar.SelectiveProperties != null && !ar.SelectiveProperties.Contains("Unnasigned property"))
                    {
                        ar.SelectiveProperties.Add("Unnasigned property");
                    }
                    assetRules[selected] = ar;
                    GatherData();
                    AssetAuditor.WriteUserData(AssetDatabase.GUIDToAssetPath(ar.AssetGuid), ar);
                }
                if (ar.SelectiveProperties != null && ar.SelectiveProperties.Count > 0)
                {
                    if (GUI.Button(RemoveSelectivePropRect, "-"))
                    {
                        // remove last selective property
                        ar.SelectiveProperties.RemoveAt(ar.SelectiveProperties.Count - 1);

                        if (ar.SelectiveProperties.Count == 0)
                        {
                            ar.SelectiveMode = false;
                        }

                        assetRules[selected] = ar;
                        GatherData();
                        AssetAuditor.WriteUserData(AssetDatabase.GUIDToAssetPath(ar.AssetGuid), ar);
                    }
                    editSelective = GUI.Toggle(EditSelectedPropButtonRect, editSelective, "Edit", "Button");
                    if (editSelective)
                    {
                        SerializedObject so = new SerializedObject(
                            AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(ar.AssetGuid)));
                        EditorGUI.BeginChangeCheck();
                        editSelectiveProp = EditorGUI.Popup(EditSelectedPropDropDownRect, editSelectiveProp,
                                                            AssetAuditor.GetPropertyNames(so));

                        if (EditorGUI.EndChangeCheck())
                        {
                            ar.SelectiveProperties[selectedSelective] =
                                AssetAuditor.GetPropertyNames(so)[editSelectiveProp];

                            assetRules[selected] = ar;
                            GatherData();
                            AssetAuditor.WriteUserData(AssetDatabase.GUIDToAssetPath(ar.AssetGuid), ar);
                        }
                    }
                }
            }
        }