Beispiel #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);
        }
    }
Beispiel #2
0
    public static void cleanShardAssets(UnityEngine.Object obj)
    {
        CLSharedAssets sharedAsset = null;
        CLRoleAvata    avata       = null;

        if (obj is GameObject)
        {
            sharedAsset = ((GameObject)obj).GetComponent <CLSharedAssets> ();
            avata       = ((GameObject)obj).GetComponent <CLRoleAvata> ();
            if (AssetDatabase.GetAssetPath(obj).Contains("/other/model/"))
            {
                ECLEditorUtl.cleanModleMaterials(AssetDatabase.GetAssetPath(obj));
            }
            UIFont font = ((GameObject)obj).GetComponent <UIFont> ();
            if (font != null)
            {
                string spName = font.spriteName;
                font.atlas      = null;
                font.material   = null;
                font.spriteName = spName;
            }
        }
        else if (obj is Material)
        {
            CLMaterialPool.cleanTexRef(ECLEditorUtl.getAssetName4Upgrade(obj), (Material)obj);
            sharedAsset = null;
        }
        else
        {
            sharedAsset = null;
        }
        bool isRefresh = false;

        if (avata != null)
        {
            avata.cleanMaterial();
            isRefresh = true;
        }
        if (sharedAsset != null)
        {
            sharedAsset.cleanRefAssets();
            isRefresh = true;
        }
        if (isRefresh && obj is GameObject)
        {
            //			AssetDatabase.Refresh ();
            //string path = AssetDatabase.GetAssetPath (obj);
            //EditorUtility.SetDirty (obj);
            //AssetDatabase.WriteImportSettingsIfDirty (path);
            //AssetDatabase.ImportAsset (path);
            PrefabUtility.SavePrefabAsset(obj as GameObject);
        }
    }
    /// <summary>
    /// Gets the material reference.
    /// </summary>
    /// <returns><c>true</c>, 说明有新资源移动到开发目录 <c>false</c> otherwise.</returns>
    /// <param name="sharedAsset">Shared asset.</param>
    /// <param name="tr">Tr.</param>
    public static bool getMaterialRef(CLSharedAssets sharedAsset, Transform tr)
    {
        bool ret  = false;
        bool ret1 = false;
        bool ret2 = false;
        bool ret3 = false;

        Renderer[] rds = tr.GetComponents <Renderer> ();
        Renderer   rd  = null;

        for (int r = 0; r < rds.Length; r++)
        {
            rd = rds [r];
            if (rd == null)
            {
                continue;
            }
            if (rd.sharedMaterials != null && rd.sharedMaterials.Length > 0)
            {
                for (int i = 0; i < rd.sharedMaterials.Length; i++)
                {
                    if (rd.sharedMaterials [i] == null)
                    {
                        continue;
                    }
                    Coolape.CLSharedAssets.CLMaterialInfor clMat = new Coolape.CLSharedAssets.CLMaterialInfor();
                    clMat.render = rd;
                    clMat.index  = i;
                    ret1         = ECLEditorUtl.moveAsset4Upgrade(rd.sharedMaterials [i]) || ret1 ? true : false;
                    string materialName = ECLEditorUtl.getAssetName4Upgrade(rd.sharedMaterials [i]);
                    clMat.materialName = materialName;
                    sharedAsset.materials.Add(clMat);

                    // save to cfg file
                    ArrayList propNames = new ArrayList();
                    ArrayList texNames  = new ArrayList();
                    ArrayList texPaths  = new ArrayList();
                    ret2 = ECLEditorUtl.getTexturesFromMaterial(rd.sharedMaterials [i], ref propNames, ref texNames, ref texPaths) || ret2 ? true : false;
                    saveMaterialTexCfg(materialName, propNames, texNames, texPaths);
                }
            }
        }

        for (int i = 0; i < tr.childCount; i++)
        {
            ret3 = getMaterialRef(sharedAsset, tr.GetChild(i)) || ret3 ? true : false;
        }
        return(ret1 || ret2 || ret3);
    }
    public static bool getAssets(CLSharedAssets sharedAsset, Transform tr)
    {
        bool ret1 = false;

        //fbx
        sharedAsset.meshs.Clear();
        if (!sharedAsset.isSkipModel)
        {
            ret1 = getMeshRef(sharedAsset, tr);
        }

        //sound

        //material
        sharedAsset.materials.Clear();
        return(getMaterialRef(sharedAsset, tr) || ret1);
    }
    public static bool getMeshRef(CLSharedAssets sharedAsset, Transform tr)
    {
        bool ret  = false;
        bool ret1 = false;
        bool ret2 = false;
        bool ret3 = false;

        MeshFilter[] mfs  = tr.GetComponents <MeshFilter> ();
        Mesh         mesh = null;

        for (int i = 0; i < mfs.Length; i++)
        {
            mesh = (mfs [i]).sharedMesh;
            if (mesh != null)
            {
                Coolape.CLSharedAssets.CLMeshInfor clMesh = new Coolape.CLSharedAssets.CLMeshInfor();
                clMesh.meshFilter = mfs [i];
                ret1 = ECLEditorUtl.moveAsset4Upgrade(mfs [i].sharedMesh) || ret1 ? true : false;
                string modelName = ECLEditorUtl.getAssetName4Upgrade(mfs [i].sharedMesh);
                ECLEditorUtl.cleanModleMaterials(modelName);
                clMesh.modelName = modelName;
                clMesh.meshName  = mesh.name;
                sharedAsset.meshs.Add(clMesh);
            }
        }

        SkinnedMeshRenderer[] smrs = tr.GetComponents <SkinnedMeshRenderer> ();
        for (int i = 0; i < smrs.Length; i++)
        {
            mesh = (smrs [i]).sharedMesh;
            if (mesh != null)
            {
                Coolape.CLSharedAssets.CLMeshInfor clMesh = new Coolape.CLSharedAssets.CLMeshInfor();
                clMesh.skinnedMesh = smrs [i];
                ret2 = ECLEditorUtl.moveAsset4Upgrade(smrs [i].sharedMesh) || ret2 ? true : false;
                string modelName = ECLEditorUtl.getAssetName4Upgrade(smrs [i].sharedMesh);
                ECLEditorUtl.cleanModleMaterials(modelName);
                clMesh.modelName = modelName;
                clMesh.meshName  = mesh.name;
                sharedAsset.meshs.Add(clMesh);
            }
        }

        Animator[] anis = tr.GetComponents <Animator> ();
        for (int i = 0; i < anis.Length; i++)
        {
            if (anis [i].avatar == null)
            {
                continue;
            }
            Coolape.CLSharedAssets.CLMeshInfor clMesh = new Coolape.CLSharedAssets.CLMeshInfor();
            ret2 = ECLEditorUtl.moveAsset4Upgrade(anis [i].avatar) || ret2 ? true : false;
            string modelName = ECLEditorUtl.getAssetName4Upgrade(anis [i].avatar);
            clMesh.modelName = modelName;
            clMesh.animator  = anis [i];
            sharedAsset.meshs.Add(clMesh);
        }

        for (int i = 0; i < tr.childCount; i++)
        {
            ret3 = getMeshRef(sharedAsset, tr.GetChild(i)) || ret3 ? true : false;
        }

        return(ret1 || ret2 || ret3);
    }
    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);
    }
 void OnEnable()
 {
     instance = target as CLSharedAssets;
     EditorPrefs.SetBool("CLS0", EventDelegate.IsValid(instance.onFinshLoad));
 }