Exemple #1
0
    public static void resetShardAssets(UnityEngine.Object obj)
    {
        CLSharedAssets sharedAsset = null;
        CLRoleAvata    avata       = null;

        if (obj != null && obj is GameObject)
        {
            // 没搞明白,执行到这里时,textureMgr已经为null了,因此再取一次
            sharedAsset = ((GameObject)obj).GetComponent <CLSharedAssets> ();
            avata       = ((GameObject)obj).GetComponent <CLRoleAvata> ();

            UIFont font = ((GameObject)obj).GetComponent <UIFont> ();
            if (font != null)
            {
                if (!string.IsNullOrEmpty(font.atlasName))
                {
                    font.atlas = CLUIInit.self.getAtlasByName(font.atlasName);
                    if (font.atlas)
                    {
                        font.material = font.atlas.spriteMaterial;
                    }
                }
            }
        }
        else if (obj != null && obj is Material)
        {
            CLMaterialPool.resetTexRef(ECLEditorUtl.getAssetName4Upgrade(obj), (Material)obj, null, null);
            sharedAsset = null;
        }
        else
        {
            sharedAsset = null;
        }

        bool isRefresh = false;

        if (avata != null)
        {
            avata.setDefaultMaterial();
            isRefresh = true;
        }
        if (sharedAsset != null)
        {
            sharedAsset.reset();
            sharedAsset.resetAssets();
            isRefresh = true;
        }
        if (isRefresh && obj is GameObject)
        {
            //string path = AssetDatabase.GetAssetPath (obj);
            //EditorUtility.SetDirty (obj);
            //AssetDatabase.WriteImportSettingsIfDirty (path);
            //AssetDatabase.ImportAsset (path);
            PrefabUtility.SavePrefabAsset(obj as GameObject);
        }
    }
    public override void OnInspectorGUI()
    {
        instance = target as CLSharedAssets;
        ECLEditorUtl.BeginContents();
        {
            GUI.color = Color.yellow;
            instance.isDonnotResetAssets = EditorGUILayout.Toggle("is Donnot Reset Assets", instance.isDonnotResetAssets);
            instance.isSkipModel         = EditorGUILayout.Toggle("is Skip Manage Model", instance.isSkipModel);
            GUI.color = Color.white;
        }
        ECLEditorUtl.EndContents();

        if (state1)
        {
            tabName = "Click Close Materials";
        }
        else
        {
            tabName = "Click Open Materials";
        }
        using (new FoldableBlock(ref state1, tabName, null)) {
            if (state1)
            {
                for (int i = 0; i < instance.materials.Count; i++)
                {
                    ECLEditorUtl.BeginContents();
                    {
                        GUILayout.BeginHorizontal();
                        {
                            EditorGUILayout.ObjectField("Render", (Object)(instance.materials [i].render), typeof(Renderer), true);
                            GUI.color = Color.red;
                            if (GUILayout.Button("Delete", GUILayout.Width(60)))
                            {
                                if (EditorUtility.DisplayDialog("Alert", "Really want to delete?", "Okay", "Cancel"))
                                {
                                    instance.materials.RemoveAt(i);
                                    break;
                                }
                            }
                            GUI.color = Color.white;
                        }
                        GUILayout.EndHorizontal();
//				EditorGUILayout.IntField ("Index", instance.materials [i].index);
                        EditorGUILayout.TextField("Material Name", instance.materials [i].materialName);
                        EditorGUILayout.ObjectField("Material", (Object)(getMaterial(instance.materials [i].materialName)), typeof(Material), true);
                    }
                    ECLEditorUtl.EndContents();
                }
            }
        }


        if (state2)
        {
            tabName = "Click Close Meshs";
        }
        else
        {
            tabName = "Click Open Meshs";
        }
        using (new FoldableBlock(ref state2, tabName, null)) {
            if (state2)
            {
                for (int i = 0; i < instance.meshs.Count; i++)
                {
                    ECLEditorUtl.BeginContents();
                    {
                        GUILayout.BeginHorizontal();
                        {
                            if (instance.meshs [i].meshFilter != null)
                            {
                                EditorGUILayout.ObjectField("Mesh Fiter", (Object)(instance.meshs [i].meshFilter), typeof(MeshFilter), true);
                            }
                            else if (instance.meshs[i].skinnedMesh != null)
                            {
                                EditorGUILayout.ObjectField("Skinned Mesh", (Object)(instance.meshs [i].skinnedMesh), typeof(SkinnedMeshRenderer), true);
                            }
                            else if (instance.meshs[i].animator != null)
                            {
                                EditorGUILayout.ObjectField("Animator", (Object)(instance.meshs[i].animator), typeof(Animator), true);
                            }

                            GUI.color = Color.red;
                            if (GUILayout.Button("Delete", GUILayout.Width(60)))
                            {
                                if (EditorUtility.DisplayDialog("Alert", "Really want to delete?", "Okay", "Cancel"))
                                {
                                    instance.meshs.RemoveAt(i);
                                    break;
                                }
                            }
                            GUI.color = Color.white;
                        }
                        GUILayout.EndHorizontal();

                        if (instance.meshs [i].animator != null)
                        {
                            EditorGUILayout.ObjectField("Avatar", (Object)(getAvatar(instance.meshs [i].modelName)), typeof(Avatar), true);
                        }
                        EditorGUILayout.TextField("Model Name", instance.meshs [i].modelName);
                        EditorGUILayout.ObjectField("Mesh", (Object)(getMesh(instance.meshs [i].modelName, instance.meshs [i].meshName)), typeof(Mesh), true);
                    }
                    ECLEditorUtl.EndContents();
                }
            }
        }

        GUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("Get"))
            {
                getAssets(instance, instance.transform);
                EditorUtility.SetDirty(instance);
                EditorUtility.DisplayDialog("Success", "Finish get Assets", "Okay");
            }

            if (GUILayout.Button("Clean"))
            {
                cleanMaterialInfor();
                EditorUtility.DisplayDialog("Success", "Finish clean Assets", "Okay");
            }

            if (GUILayout.Button("Reset"))
            {
                instance.reset();
                instance.resetAssets();
                EditorUtility.DisplayDialog("Success", "Finish reset Assets", "Okay");
            }
        }
        GUILayout.EndHorizontal();

//		base.OnInspectorGUI ();

        GUILayout.Space(3f);
        NGUIEditorTools.SetLabelWidth(80f);
        bool minimalistic = NGUISettings.minimalisticLook;

        DrawEvents("CLS0", "On Finish Load", instance.onFinshLoad, minimalistic);
    }