Exemplo n.º 1
0
 private void Run()
 {
     m_ScriptableInfo.Content                 = m_Content;
     m_ScriptableInfo.Items                   = ResourceProcessor.Instance.ItemList;
     m_ScriptableInfo.Groups                  = ResourceProcessor.Instance.GroupList;
     m_ScriptableInfo.Results                 = m_Results;
     m_ScriptableInfo.ResourceEditWindow      = m_ResourceEditWindow;
     m_ScriptableInfo.ResourceProcessor       = ResourceProcessor.Instance;
     m_ScriptableInfo.ResourceEditWindowType  = typeof(ResourceEditWindow);
     m_ScriptableInfo.ResourceProcessorType   = typeof(ResourceProcessor);
     m_ScriptableInfo.ResourceEditUtilityType = typeof(ResourceEditUtility);
     if (ResourceEditUtility.LoadScript(m_Command, ResourceProcessor.Instance.Params, new Dictionary <string, DslExpression.CalculatorValue> {
         { "@context", DslExpression.CalculatorValue.FromObject(m_ScriptableInfo) }
     }))
     {
         var r = ResourceEditUtility.EvalScript(m_Object, m_Item);
         if (!r.IsNullObject)
         {
             m_Results.Enqueue(string.Format("cmd:{0} result:{1}", m_Command, r.ToString()));
         }
         else
         {
             m_Results.Enqueue(string.Format("cmd:{0} result:null", m_Command));
         }
     }
     m_Content = m_ScriptableInfo.Content;
 }
Exemplo n.º 2
0
    private static bool UpdatePrefab(ResourceParams param, UnityEngine.GameObject prefab, bool onlySetting)
    {
        bool rt = ResourceEditUtility.SetParamsToResource("prefabsetparams", param, prefab);

        rt = rt || ResourceEditUtility.ForceSaveAndReimport;
        if (!onlySetting && rt)
        {
            if (ResourceEditUtility.EnableSaveAndReimport)
            {
                EditorUtility.SetDirty(prefab);
            }
        }
        return(true);
    }
    private static bool UpdateModel(ResourceParams param, ModelImporter modelImporter, bool onlySetting)
    {
        bool rt = ResourceEditUtility.SetParamsToResource("modelsetparams", param, modelImporter);

        rt = rt || ResourceEditUtility.ForceSaveAndReimport;
        if (!onlySetting && rt)
        {
            if (ResourceEditUtility.EnableSaveAndReimport)
            {
                //modelImporter.SaveAndReimport();
                AssetDatabase.ImportAsset(modelImporter.assetPath);
            }
        }
        return(true);
    }
    public static bool UpdateDB(string assetPath, ModelImporter modelImporter)
    {
        ResourceParams param;
        string         guid = AssetDatabase.AssetPathToGUID(assetPath);

        if (!DBInstance.Data.TryGetResourceParams(guid, out param))
        {
            param          = new ResourceParams();
            param.Resource = assetPath;
            DBInstance.Data.AddOrMerge(guid, param);
        }
        else
        {
        }
        bool rt = ResourceEditUtility.GetParamsFromResource("modelgetparams", param, modelImporter);

        return(rt);
    }
Exemplo n.º 5
0
    public static bool UpdateDB(string assetPath, UnityEngine.GameObject prefab)
    {
        ResourceParams param;
        string         guid = AssetDatabase.AssetPathToGUID(assetPath);

        if (!DBInstance.Data.TryGetResourceParams(guid, out param))
        {
            param          = new ResourceParams();
            param.Resource = assetPath;
            DBInstance.Data.AddOrMerge(guid, param);
        }
        else
        {
        }
        bool rt = ResourceEditUtility.GetParamsFromResource("prefabgetparams", param, prefab);

        return(rt);
    }
    private void Run()
    {
        m_ScriptableInfo.Content                 = m_Content;
        m_ScriptableInfo.Results                 = m_Results;
        m_ScriptableInfo.ResourceEditWindow      = m_ResourceEditWindow;
        m_ScriptableInfo.ResourceProcessor       = ResourceProcessor.Instance;
        m_ScriptableInfo.ResourceEditWindowType  = typeof(ResourceEditWindow);
        m_ScriptableInfo.ResourceProcessorType   = typeof(ResourceProcessor);
        m_ScriptableInfo.ResourceEditUtilityType = typeof(ResourceEditUtility);
        var r = ResourceEditUtility.EvalScript(m_Command, ResourceProcessor.Instance.Params, m_Object, m_Item, new Dictionary <string, object> {
            { "@context", m_ScriptableInfo }
        });

        if (null != r)
        {
            m_Results.Enqueue(string.Format("cmd:{0} result:{1}", m_Command, r.ToString()));
        }
        else
        {
            m_Results.Enqueue(string.Format("cmd:{0} result:null", m_Command));
        }
        m_Content = m_ScriptableInfo.Content;
    }
    public override void OnInspectorGUI()
    {
        bool saveDB = false;

        toDel.Clear();
        ModelImporterParamsDB db = target as ModelImporterParamsDB;
        int count = db.Data.Count;

        if (count == 0)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(EMPTY);
            GUILayout.EndHorizontal();
        }
        else
        {
            for (int i = 0; i < count; ++i)
            {
                string         guid  = db.Data.GetResourceKey(i);
                string         path  = AssetDatabase.GUIDToAssetPath(guid);
                ResourceParams param = db.Data.GetResourceParams(i);
                bool           valid = !string.IsNullOrEmpty(path) && param != null;
                if (!valid)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(VALID);
                    if (GUILayout.Button(DELETE))
                    {
                        toDel.Add(guid);
                        saveDB = true;
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {
                    if (foldout.Count < i + 1)
                    {
                        foldout.Add(false);
                    }
                    var pathArr = path.Split('/');
                    if (EditorGUILayout.Foldout(foldout[i], i + ":" + pathArr[pathArr.Length - 1].ToString()))
                    {
                        foldout[i] = true;
                        for (int ix = 0; ix < param.Count; ++ix)
                        {
                            var key = param.GetKey(ix);
                            var val = param.GetValue(ix);
                            GUILayout.BeginHorizontal();
                            GUILayout.Label(string.Format("{0}:{1}", key, val));
                            GUILayout.EndHorizontal();
                        }

                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button(SELECT))
                        {
                            var asset = AssetDatabase.LoadMainAssetAtPath(path);
                            if (asset == null)
                            {
                                if (EditorUtility.DisplayDialog(NOT_FOUND_TITLE, string.Format(NOT_FOUND_CONTEXT, path), OK, NO))
                                {
                                    toDel.Add(guid);
                                    saveDB = true;
                                }
                            }
                            else
                            {
                                Selection.activeObject = asset;
                            }
                        }
                        if (GUILayout.Button(UPDATERES))
                        {
                            var importer = AssetImporter.GetAtPath(path) as ModelImporter;
                            if (null != importer)
                            {
                                ModelImporterParamsDB.UpdateModel(path, importer, false);
                                AssetDatabase.ImportAsset(path);
                            }
                        }
                        if (GUILayout.Button(UPDATEDB))
                        {
                            var importer = AssetImporter.GetAtPath(path) as ModelImporter;
                            if (null != importer)
                            {
                                ModelImporterParamsDB.UpdateDB(path, importer);
                                saveDB = true;
                            }
                        }
                        if (GUILayout.Button(DELETE))
                        {
                            toDel.Add(guid);
                            saveDB = true;
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        foldout[i] = false;
                    }
                }
            }
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(ModelImporterParamsDB.SYNC_ALL))
            {
                ResourceEditUtility.ResetResourceParamsCalculator();
                ModelImporterParamsDB.UpdateAllModels();
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.BeginHorizontal();
        objToAdd = EditorGUILayout.ObjectField(objToAdd, typeof(UnityEngine.GameObject), false);
        if (GUILayout.Button(ADD) && null != objToAdd)
        {
            var path     = AssetDatabase.GetAssetPath(objToAdd);
            var importer = AssetImporter.GetAtPath(path) as ModelImporter;
            if (null != importer)
            {
                ModelImporterParamsDB.UpdateDB(path, importer);
                saveDB = true;
            }
        }
        GUILayout.EndHorizontal();

        foreach (var del in toDel)
        {
            db.Data.Remove(del);
        }

        if (saveDB)
        {
            EditorUtility.SetDirty(target);
            AssetDatabase.SaveAssets();
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button(ModelImporterParamsDB.IMPORT))
        {
            string file = EditorUtility.OpenFilePanel(ModelImporterParamsDB.IMPORT_DIALOG, string.Empty, "json");
            if (!string.IsNullOrEmpty(file))
            {
                ModelImporterParamsDB.Import(file);
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(ModelImporterParamsDB.EXPORT))
        {
            string file = EditorUtility.SaveFilePanel(ModelImporterParamsDB.EXPORT_DIALOG, string.Empty, "modeldata", "json");
            if (!string.IsNullOrEmpty(file))
            {
                ModelImporterParamsDB.Export(file);
            }
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(ModelImporterParamsDB.FETCH))
        {
            ModelImporterParamsDB.Fetch();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button(ModelImporterParamsDB.COMMIT))
        {
            ModelImporterParamsDB.Commit();
        }
        GUILayout.EndHorizontal();
    }
 private string GetRootPath()
 {
     return(ResourceEditUtility.GetRootPath());
 }
 private string RelativePathToFilePath(string path)
 {
     return(ResourceEditUtility.RelativePathToFilePath(path));
 }
 private bool IsAssetPath(string path)
 {
     return(ResourceEditUtility.IsAssetPath(path));
 }