Exemple #1
0
 public void Init()
 {
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft != null)
         {
             //make sure all children is inited.
             xft.Initialize();
             if (!EffectDic.ContainsKey(child.name))
             {
                 EffectDic[child.name] = new List <XffectComponent>();
             }
             EffectDic[child.name].Add(xft);
         }
         CompositeXffect cxft = child.GetComponent <CompositeXffect>();
         if (cxft != null)
         {
             cxft.Initialize();
             if (!CompEffectDic.ContainsKey(child.name))
             {
                 CompEffectDic[child.name] = new List <CompositeXffect>();
             }
             CompEffectDic[child.name].Add(cxft);
         }
     }
     mInited = true;
 }
 void Awake()
 {
     m_instance = this;
     foreach (Transform child in transform)
     {
         XffectComponent xft = child.GetComponent <XffectComponent>();
         if (xft != null)
         {
             //make sure all children is inited.
             xft.Initialize();
             if (!EffectDic.ContainsKey(child.name))
             {
                 EffectDic[child.name] = new ArrayList();
             }
             EffectDic[child.name].Add(xft);
         }
         CompositeXffect cxft = child.GetComponent <CompositeXffect>();
         if (cxft != null)
         {
             cxft.Initialize();
             if (!CompEffectDic.ContainsKey(child.name))
             {
                 CompEffectDic[child.name] = new ArrayList();
             }
             CompEffectDic[child.name].Add(cxft);
         }
     }
 }
    void DrawPresets()
    {
        #region preset box0
        EditorGUILayout.BeginVertical("box");

        if (mShowingPresetList.Count > 0)
        {
            #region rows
            EditorGUILayout.BeginHorizontal();
            int rows       = 1;
            int iconwidths = 0;
            for (int i = 0; i < mShowingPresetList.Count; i++)
            {
                rows        = Mathf.FloorToInt(PresetViewWidth / PRESET_WIDTH);
                iconwidths += PRESET_WIDTH;
                if (iconwidths > PresetViewWidth && i > 0)
                {
                    iconwidths = PRESET_WIDTH;
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.BeginHorizontal();
                }


                if (PresetViewWidth >= PRESET_WIDTH * 2)
                {
                    EditorGUILayout.BeginVertical("box", GUILayout.MaxWidth(Mathf.CeilToInt(PresetViewWidth / rows) - 44 / rows));
                }
                else
                {
                    EditorGUILayout.BeginVertical("box");
                }


                //begin preset unit
                EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(46));

                //EditorGUI.DrawPreviewTexture(new Rect(0, 0, 40, 40), texTest);



                if (GUILayout.Button(mShowingPresetList[i].PreviewIcon, PreviewButtonStyle, new GUILayoutOption[] { GUILayout.Width(64), GUILayout.Height(64) }))
                {
                    GameObject pobj = AssetDatabase.LoadAssetAtPath(mShowingPresetList[i].Path, typeof(GameObject)) as GameObject;

                    if (pobj == null)
                    {
                        Debug.LogWarning("prefab isn't existed, please refresh." + mShowingPresetList[i].Path);
                    }
                    else
                    {
                        GameObject obj = PrefabUtility.InstantiatePrefab(pobj) as GameObject;
                        if (obj != null)
                        {
                            Selection.activeGameObject = obj;
                            XffectComponent xobj = obj.GetComponent <XffectComponent>();
                            if (xobj != null)
                            {
                                xobj.EditView = true;
                                xobj.EnableEditView();
                            }

                            CompositeXffect cxobj = obj.GetComponent <CompositeXffect>();
                            if (cxobj != null)
                            {
                                cxobj.EnableEditView();
                            }
                        }

                        EditorUtility.UnloadUnusedAssetsImmediate();
                        System.GC.Collect();
                    }
                }

                //GUI.backgroundColor = bcolor;

                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField(mShowingPresetList[i].Name, new GUILayoutOption[] { GUILayout.Width(PRESET_WIDTH - 64), GUILayout.Height(40) });
                EditorGUILayout.LabelField(mShowingPresetList[i].CreatedTime);
                EditorGUILayout.EndVertical();

                //end preset unit
                EditorGUILayout.EndHorizontal();

                //end preset frame
                EditorGUILayout.EndVertical();
            }

            //end presets box.
            EditorGUILayout.EndHorizontal();
            #endregion //row
        }
        else
        {
            EditorGUILayout.HelpBox("No prefabs found.", MessageType.Info);
        }

        //end outer frame box.
        EditorGUILayout.EndVertical();
        #endregion //box0
    }
    void RefreshPresets()
    {
        Data.Presets.Clear();

        // check all prefabs to see if we can find any objects we are interested in
        List <string>  allPrefabPaths = new List <string>();
        Stack <string> paths          = new Stack <string>();

        paths.Push(Application.dataPath);
        while (paths.Count != 0)
        {
            string   path  = paths.Pop();
            string[] files = Directory.GetFiles(path, "*.prefab");
            foreach (var file in files)
            {
                allPrefabPaths.Add(file.Substring(Application.dataPath.Length - 6));
            }

            foreach (string subdirs in Directory.GetDirectories(path))
            {
                paths.Push(subdirs);
            }
        }

        // Check all prefabs
        int currPrefabCount = 1;

        foreach (string prefabPath in allPrefabPaths)
        {
            EditorUtility.DisplayProgressBar("Xffect Browser", "Searching xffect prefabs in project folder, please wait...", (float)currPrefabCount / (float)(allPrefabPaths.Count));

            GameObject iterGo = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
            if (!iterGo)
            {
                continue;
            }

            XffectComponent xft     = iterGo.GetComponent <XffectComponent>();
            CompositeXffect cxffect = iterGo.GetComponent <CompositeXffect>();
            if (xft == null && cxffect == null)
            {
                continue;
            }

            Data.Presets.Add(new XffectPresetData(ConvertPathToCategoryPath(prefabPath), prefabPath));



            ++currPrefabCount;
            if (currPrefabCount % 50 == 0)
            {
                iterGo = null;
                xft    = null;
                EditorUtility.UnloadUnusedAssetsImmediate();
                System.GC.Collect();
            }
        }


        // unload all unused assets
        EditorUtility.UnloadUnusedAssetsImmediate();
        System.GC.Collect();


        //save
        EditorUtility.SetDirty(Data);
        AssetDatabase.Refresh();
        AssetDatabase.SaveAssets();


        EditorUtility.ClearProgressBar();


        RefreshDic();
        RefreshShowingPresetItems(mCurSelectCategory, mSearchString);
    }
Exemple #5
0
    void OnEnable()
    {
        Script = target as CompositeXffect;

        InitCapture();
    }