コード例 #1
0
        /// <summary>
        /// 当前目录查找,然后往上递归
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private AssetRule SearchRecursive(string path)
        {
            foreach (var findAsset in AssetDatabase.FindAssets("t:AssetRule", new[] { Path.GetDirectoryName(path) }))
            {
                var p = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(findAsset));
                if (p == Path.GetDirectoryName(path))
                {
                    string    setName = string.Empty;
                    AssetRule rule    = AssetDatabase.LoadAssetAtPath <AssetRule>(AssetDatabase.GUIDToAssetPath(findAsset));
                    if (rule != null && rule.IsMatch(assetImporter, out setName))
                    {
                        //Debug.LogWarning("Find:" + rule + " " + setName);
                        return(rule);
                    }
                }
            }

            path = Directory.GetParent(path).FullName;
            path = path.Replace('\\', '/');
            path = path.Remove(0, Application.dataPath.Length);
            path = path.Insert(0, "Assets");
            if (path != "Assets")
            {
                return(SearchRecursive(path));
            }
            return(null);
        }
コード例 #2
0
        public static void CreateAssetRule()
        {
            AssetRule newRule = AssetRule.CreateAssetRule();

            string selectionPath = "Assets";

            foreach (Object obj in Selection.GetFiltered(typeof(Object), SelectionMode.Assets))
            {
                selectionPath = AssetDatabase.GetAssetPath(obj);
                if (File.Exists(selectionPath))
                {
                    selectionPath = Path.GetDirectoryName(selectionPath);
                }
                break;
            }

            string newRuleFileName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(selectionPath, "NewAssetRule.asset"));

            newRuleFileName = newRuleFileName.Replace("\\", "/");
            AssetDatabase.CreateAsset(newRule, newRuleFileName);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = newRule;
        }
コード例 #3
0
        public static AssetRule CreateAssetRule()
        {
            AssetRule assetRule = AssetRule.CreateInstance <AssetRule>();

            assetRule.Init();

            return(assetRule);
        }
コード例 #4
0
        private void OnPreprocessModel()
        {
            AssetRule rule = FindAssetRule(assetImporter.assetPath);

            if (rule == null)
            {
                return;
            }

            rule.ApplySettings(assetImporter);
        }
コード例 #5
0
        public override void OnInspectorGUI()
        {
            m_CurRule = (AssetRule)target;

            DrawAddBtn();

            GUILayout.Space(20);
            m_CurRule.showLog = EditorGUILayout.Toggle(new GUIContent("ShowLog"), m_CurRule.showLog);
            string[] names = GetNames();
            if (names != null && names.Length > 0)
            {
                m_SelectedID = EditorGUILayout.Popup("Sets", m_SelectedID, names);
            }

            DrawDelete();

            DrawSelect();

            serializedObject.ApplyModifiedProperties();
        }