示例#1
0
        void OnGUI()
        {
            if (helpIcon == null)
            {
                helpIcon = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON);
            }
            if (helpIconActive == null)
            {
                helpIconActive = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON_ACTIVE);
            }

            if (prefabList == null || prefabList.Count == 0)
            {
                this.Close();
            }

            EditorGUILayout.BeginHorizontal(GPUInstancerEditorConstants.Styles.box);
            EditorGUILayout.LabelField(GPUInstancerEditorConstants.GPUI_VERSION, GPUInstancerEditorConstants.Styles.boldLabel);
            GUILayout.FlexibleSpace();
            GPUInstancerEditor.DrawWikiButton(GUILayoutUtility.GetRect(40, 20), "#Scene_Prefab_Importer");
            GUILayout.Space(10);
            DrawHelpButton(GUILayoutUtility.GetRect(20, 20), showHelpText);
            EditorGUILayout.EndHorizontal();

            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterIntro, true);

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            EditorGUILayout.BeginHorizontal();

            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.importSelectedPrefabs, GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                List <GameObject> selectedPrefabs = new List <GameObject>();
                for (int i = 0; i < prefabList.Count; i++)
                {
                    if (isEnabledArray[i])
                    {
                        selectedPrefabs.Add(prefabList[i]);
                    }
                }

                if (selectedPrefabs.Count > 0)
                {
                    GameObject go = new GameObject("GPUI Prefab Manager");
                    GPUInstancerPrefabManager prefabManager = go.AddComponent <GPUInstancerPrefabManager>();
                    selectedPrefabs.ForEach(p => prefabManager.AddPickerObject(p));
                    this.Close();
                    Selection.activeGameObject = go;
                }
                else
                {
                    EditorUtility.DisplayDialog(GPUInstancerEditorConstants.TEXT_info, GPUInstancerEditorConstants.TEXT_noPrefabInstanceSelected, GPUInstancerEditorConstants.TEXT_close);
                }
            });

            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.cancel, Color.red, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                this.Close();
            });

            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterImportCancel);
            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Select All"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = true;
                }
            }
            if (GUILayout.Button("Select None"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = false;
                }
            }
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterSelectAllNone);

            EditorGUILayout.BeginHorizontal();
            instanceCountToSelect = EditorGUILayout.IntSlider(instanceCountToSelect, 0, maxInstanceCount);
            if (GUILayout.Button("Select Min. Instance Count"))
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = instanceCountToSelect <= instanceCountArray[i];
                }
            }
            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterSelectOverCount);
            GUILayout.Space(5);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            GPUInstancerEditorConstants.DrawCustomLabel("Prefab Instances", GPUInstancerEditorConstants.Styles.boldLabel);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabImporterInstanceList);
            GUILayout.Space(5);
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            EditorGUILayout.BeginVertical();
            if (prefabList != null)
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    isEnabledArray[i] = EditorGUILayout.BeginToggleGroup(prefabList[i].name + " (Instance Count: " + instanceCountArray[i] + ")", isEnabledArray[i]);
                    EditorGUILayout.EndToggleGroup();
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();

            //GameObject go = new GameObject("GPUI Prefab Manager");
            //GPUInstancerPrefabManager prefabManager = go.AddComponent<GPUInstancerPrefabManager>();

            //Selection.activeGameObject = go;
        }
        void OnGUI()
        {
            if (helpIcon == null)
            {
                helpIcon = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON);
            }
            if (helpIconActive == null)
            {
                helpIconActive = Resources.Load <Texture2D>(GPUInstancerConstants.EDITOR_TEXTURES_PATH + GPUInstancerEditorConstants.HELP_ICON_ACTIVE);
            }

            EditorGUILayout.BeginHorizontal(GPUInstancerEditorConstants.Styles.box);
            EditorGUILayout.LabelField(GPUInstancerEditorConstants.GPUI_VERSION, GPUInstancerEditorConstants.Styles.boldLabel);
            GUILayout.FlexibleSpace();
            GPUInstancerEditor.DrawWikiButton(GUILayoutUtility.GetRect(40, 20), "#The_Prefab_Replacer");
            GUILayout.Space(10);
            DrawHelpButton(GUILayoutUtility.GetRect(20, 20), showHelpText);
            EditorGUILayout.EndHorizontal();

            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabReplacerIntro, true);

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            EditorGUILayout.BeginHorizontal();

            GPUInstancerEditorConstants.DrawColoredButton(new GUIContent("Replace Selection With Prefab"), GPUInstancerEditorConstants.Colors.green, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                ReplaceSelectionWithPrefab();
            });

            GPUInstancerEditorConstants.DrawColoredButton(GPUInstancerEditorConstants.Contents.cancel, Color.red, Color.white, FontStyle.Bold, Rect.zero,
                                                          () =>
            {
                this.Close();
            });

            EditorGUILayout.EndHorizontal();
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabReplacerReplaceCancel);

            GUILayout.Space(10);
            selectedPrefab = (GameObject)EditorGUILayout.ObjectField("Prefab", selectedPrefab, typeof(GameObject), false);

#if UNITY_2018_3_OR_NEWER
            if (selectedPrefab != null &&
                PrefabUtility.GetPrefabAssetType(selectedPrefab) != PrefabAssetType.Regular &&
                PrefabUtility.GetPrefabAssetType(selectedPrefab) != PrefabAssetType.Variant)
#else
            if (selectedPrefab != null && PrefabUtility.GetPrefabType(selectedPrefab) != PrefabType.Prefab)
#endif
            { selectedPrefab = null; }
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabReplacerPrefab);

            replaceNames = EditorGUILayout.Toggle("Replace Names", replaceNames);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabReplacerReplaceNames);

            GUILayout.Space(10);
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(GPUInstancerEditorConstants.Styles.box);
            GUILayout.Space(5);
            GPUInstancerEditorConstants.DrawCustomLabel("Selected GameObjects", GPUInstancerEditorConstants.Styles.boldLabel);
            DrawHelpText(GPUInstancerEditorConstants.HELPTEXT_prefabReplacerSelectedObjects);
            GUILayout.Space(5);
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            EditorGUILayout.BeginVertical();
            foreach (Transform selectedTransform in Selection.transforms)
            {
                EditorGUILayout.LabelField(selectedTransform.name);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }