Exemple #1
0
        private void OnGUI()
        {
            StyleFactory.DrawTitle("Message Box Prefab Manager");

            EditorGUILayout.LabelField(string.Format("Place your message box prefabs in 'Assets/MKStudio/Easy Message Box/Prefabs'{0}To add a message box to the scene, select a Canvas and click the 'Add' button.{1}The 'Default' button sets the template to use when there is no template in the scene.",
                                                     System.Environment.NewLine, System.Environment.NewLine),
                                       EditorStyles.centeredGreyMiniLabel, GUILayout.Height(EditorGUIUtility.singleLineHeight * 2 + 5f));

            if (fileResources == null)
            {
                EditorGUILayout.HelpBox("Cannot find the Resource folder, make sure the folder 'Assets/MKStudio/Easy Message Box/Resources' exists", MessageType.Error);
            }
            else if (fileResources.Count == 0)
            {
                EditorGUILayout.HelpBox("Default Message Box prefab is missing", MessageType.Error);
            }

            if (filePrefabs == null)
            {
                EditorGUILayout.HelpBox("Cannot locate prefabs folder, make sure the folder 'Assets/MKStudio/Easy Message Box/Prefabs' exists", MessageType.Error);
            }
            else if (filePrefabs.Count == 0)
            {
                EditorGUILayout.HelpBox("No message box prefab found in 'Prefabs' folder. Make sure you place the prefabs under 'Assets/Xen Studio/Easy Message Box/Prefabs'", MessageType.Info);
            }
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            Rect lastRct = new Rect();

            EditorGUILayout.LabelField("Prefab Name", EditorStyles.miniBoldLabel);
            int total = (fileResources == null ? 0 : fileResources.Count) + (filePrefabs == null ? 0 : filePrefabs.Count);

            if (Event.current.type == EventType.Repaint)
            {
                lastRct = GUILayoutUtility.GetLastRect();
            }
            for (int i = 0; i < total; i++)
            {
                EditorGUILayout.BeginHorizontal();
                if (fileResources != null && i < fileResources.Count)
                {
                    if (i % 2 == 0)
                    {
                        EditorGUI.DrawRect(new Rect(lastRct.x, lastRct.y + (i + 1) * (EditorGUIUtility.singleLineHeight + 2f), lastRct.width, EditorGUIUtility.singleLineHeight), new Color(1f, 1f, 1f, 0.1f));
                    }
                    DrawItem(fileResources[i]);
                }
                int totalResource = (fileResources == null ? 0 : fileResources.Count);
                if (filePrefabs != null && i >= totalResource)
                {
                    if (i % 2 == 0)
                    {
                        EditorGUI.DrawRect(new Rect(lastRct.x, lastRct.y + (i + 1) * (EditorGUIUtility.singleLineHeight + 2f), lastRct.width, EditorGUIUtility.singleLineHeight), new Color(1f, 1f, 1f, 0.1f));
                    }
                    DrawItem(filePrefabs[i - totalResource]);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("");
            EditorGUILayout.LabelField(string.Format("MK Studio - Easy Message Box {0}", EasyMessageBox.VersionString), EditorStyles.miniLabel, GUILayout.Width(175f));
            EditorGUILayout.EndHorizontal();
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            StyleFactory.DrawTitle("Easy Message Box - Template List");
            //EditorGUILayout.LabelField("Template List", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Add a prefab as a template with the 'Prefab Manager', or manually place your a prefab as the child of this GameObject and include it in the list by pressing the 'Auto Detect' button.", MessageType.Info);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("ID", EditorStyles.miniLabel, wId);
            EditorGUILayout.LabelField("Template", EditorStyles.miniLabel, wPrefab);
            EditorGUILayout.EndHorizontal();

            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.MaxHeight(mPrefabList.arraySize * (EditorGUIUtility.singleLineHeight + 2f) + EditorGUIUtility.singleLineHeight));

            if (mPrefabList.arraySize == 0)
            {
                EditorGUILayout.HelpBox("No template in the list, will use the 'Default' prefab set in Prefab Manager as the template. Add a message box prefab using Prefab Manager.", MessageType.Info);
            }

            for (int i = 0; i < mPrefabList.arraySize; i++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(i.ToString(), wId);
                EditorGUILayout.PropertyField(mPrefabList.GetArrayElementAtIndex(i), GUIContent.none);
                if (GUILayout.Button("Remove", EditorStyles.miniButton, wDelBtn))
                {
                    mPrefabList.GetArrayElementAtIndex(i).objectReferenceValue = null;
                    mPrefabList.DeleteArrayElementAtIndex(i);
                }

                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("");
            Color original = GUI.backgroundColor;

            GUI.backgroundColor = new Color(0.000f, 0.745f, 0.439f);
            if (GUILayout.Button("Prefab Manager...", GUILayout.Width(125f)))
            {
                PrefabManager.Initiate();
            }
            GUI.backgroundColor = new Color(0.058f, 0.585f, 0.745f);
            if (GUILayout.Button(new GUIContent("Auto Detect", "Auto detects message boxes in the children of this GameObject and sets the templates correctly. Will also remove empty items in the list."), GUILayout.Width(80f)))
            {
                var childMessageBoxes       = Selection.activeGameObject.GetComponentsInChildren <BoxController>(true);
                List <GameObject> templates = new List <GameObject>();
                for (int i = 0; i < childMessageBoxes.Length; i++)
                {
                    if (!templates.Contains(childMessageBoxes[i].gameObject))
                    {
                        templates.Add(childMessageBoxes[i].gameObject);
                    }
                }
                List <int> idToRemove = new List <int>();
                for (int i = 0; i < mPrefabList.arraySize; i++)
                {
                    if (mPrefabList.GetArrayElementAtIndex(i).objectReferenceValue == null)
                    {
                        idToRemove.Add(i);
                    }
                    else if ((mPrefabList.GetArrayElementAtIndex(i).objectReferenceValue as GameObject) == null)
                    {
                        idToRemove.Add(i);
                    }
                    else if (templates.Contains(mPrefabList.GetArrayElementAtIndex(i).objectReferenceValue as GameObject))
                    {
                        templates.Remove(mPrefabList.GetArrayElementAtIndex(i).objectReferenceValue as GameObject);
                    }
                }
                for (int i = idToRemove.Count - 1; i >= 0; i--)
                {
                    mPrefabList.GetArrayElementAtIndex(idToRemove[i]).objectReferenceValue = null;
                    mPrefabList.DeleteArrayElementAtIndex(idToRemove[i]);
                }
                for (int i = 0; i < templates.Count; i++)
                {
                    mPrefabList.arraySize++;
                    mPrefabList.GetArrayElementAtIndex(mPrefabList.arraySize - 1).objectReferenceValue = templates[i];
                }
            }
            GUI.backgroundColor = original;

            //if (GUILayout.Button("Manually Add", GUILayout.Width(100f)))
            //{
            //    mPrefabList.arraySize++;
            //    mPrefabList.GetArrayElementAtIndex(mPrefabList.arraySize - 1).objectReferenceValue = null;
            //}
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            serializedObject.ApplyModifiedProperties();
        }