Exemplo n.º 1
0
        /// <summary>
        /// Frame update for GUI objects. Heartbeat of the window that
        /// allows us to update the UI
        /// </summary>
        public void OnGUI()
        {
            // *** ENTER SECTION ***
            GUILayout.BeginVertical(EditorHelper.GroupBox);

            GUILayout.Space(5f);

            GUILayout.BeginHorizontal();

            string lOriginalSearch = mSearchString;

            mSearchString = GUILayout.TextField(lOriginalSearch, GUI.skin.FindStyle("ToolbarSeachTextField"), GUILayout.ExpandWidth(true));
            if (mSearchString != lOriginalSearch)
            {
                mSelectedItemIndex = -1;
                MotionSelectWindow.GetFilteredMotionTypes(mFilteredTypes, mMasterTypes, mSearchString);
            }

            if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
            {
                GUI.FocusControl(null);

                mSearchString      = "";
                mSelectedItemIndex = -1;
                MotionSelectWindow.GetFilteredMotionTypes(mFilteredTypes, mMasterTypes, mSearchString);
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(5f);

            GUILayout.EndVertical();

            // *** MID SECTION ***
            GUILayout.BeginHorizontal();

            mScrollPosition = GUILayout.BeginScrollView(mScrollPosition, ScrollArea);

            if (mFilteredTypes != null)
            {
                for (int i = 0; i < mFilteredTypes.Count; i++)
                {
                    GUILayout.BeginHorizontal();

                    mFilteredTypes[i].IsSelected = GUILayout.Toggle(mFilteredTypes[i].IsSelected, "", GUILayout.Width(16f));

                    GUIStyle lRowStyle = (i == mSelectedItemIndex ? EditorHelper.SelectedLabel : EditorHelper.Label);
                    if (GUILayout.Button(mFilteredTypes[i].Name, lRowStyle, GUILayout.MinWidth(100)))
                    {
                        mSelectedItemIndex = i;
                    }

                    GUILayout.EndHorizontal();
                }
            }

            GUILayout.EndScrollView();

            GUILayout.Space(5f);

            GUILayout.BeginVertical(EditorHelper.Box, GUILayout.MinWidth(200f));

            string lName = (mSelectedItemIndex < 0 || mSelectedItemIndex >= mFilteredTypes.Count ? "" : mFilteredTypes[mSelectedItemIndex].Name);

            GUILayout.Label(lName, TitleStyle, GUILayout.Height(17f));

            if (mSelectedItemIndex >= 0 && mSelectedItemIndex < mFilteredTypes.Count)
            {
                GUILayout.BeginHorizontal();

                string lPath = mFilteredTypes[mSelectedItemIndex].Path;

                if (GUILayout.Button(EditorGUIUtility.FindTexture("cs Script Icon"), GUI.skin.label, GUILayout.Width(20), GUILayout.Height(20)))
                {
                    foreach (var lAssetPath in AssetDatabase.GetAllAssetPaths())
                    {
                        if (lAssetPath.EndsWith(lPath))
                        {
                            var lScript = (MonoScript)AssetDatabase.LoadAssetAtPath(lAssetPath, typeof(MonoScript));
                            if (lScript != null && mFilteredTypes[mSelectedItemIndex].Type == lScript.GetClass())
                            {
                                AssetDatabase.OpenAsset(lScript);
                                break;
                            }
                        }
                    }
                }

                if (GUILayout.Button(lPath, PathStyle))
                {
                    foreach (var lAssetPath in AssetDatabase.GetAllAssetPaths())
                    {
                        if (lAssetPath.EndsWith(lPath))
                        {
                            var lScript = (MonoScript)AssetDatabase.LoadAssetAtPath(lAssetPath, typeof(MonoScript));
                            if (lScript != null && mFilteredTypes[mSelectedItemIndex].Type == lScript.GetClass())
                            {
                                AssetDatabase.OpenAsset(lScript);
                            }
                        }
                    }
                }

                GUILayout.FlexibleSpace();

                GUILayout.EndHorizontal();

                GUILayout.Space(3f);

                string lDescription = mFilteredTypes[mSelectedItemIndex].Description;
                GUILayout.Label(lDescription, DescriptionStyle);

                string lCategories = mFilteredTypes[mSelectedItemIndex].TypeTags;
                if (lCategories != null && lCategories.Length > 0)
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Tags: " + lCategories, TagsStyle);
                }
                else
                {
                    GUILayout.FlexibleSpace();
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
            }

            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            // *** BUTTON SECTION ***
            GUILayout.BeginVertical(EditorHelper.GroupBox);

            GUILayout.Space(2f);

            GUILayout.BeginHorizontal();

            int lCount = 0;

            for (int i = 0; i < mMasterTypes.Count; i++)
            {
                if (mMasterTypes[i].IsSelected)
                {
                    lCount++;
                }
            }

            if (GUILayout.Button("deselect all (" + lCount + ")", GUI.skin.label, GUILayout.Width(100f)))
            {
                for (int i = 0; i < mMasterTypes.Count; i++)
                {
                    mMasterTypes[i].IsSelected = false;
                }
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Select", GUILayout.Width(70)))
            {
                if (OnSelectedEvent != null)
                {
                    List <Type> lMotionTypes = new List <Type>();
                    for (int i = 0; i < mMasterTypes.Count; i++)
                    {
                        if (mMasterTypes[i].IsSelected)
                        {
                            lMotionTypes.Add(mMasterTypes[i].Type);
                        }
                    }

                    OnSelectedEvent(lMotionTypes);
                }

                mSelectedItemIndex = -1;
                Close();
            }

            if (GUILayout.Button("Cancel", GUILayout.Width(70)))
            {
                mSelectedItemIndex = -1;
                Close();
            }

            GUILayout.EndHorizontal();

            GUILayout.Space(2f);

            GUILayout.EndVertical();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes the window
 /// </summary>
 public void Awake()
 {
     MotionSelectWindow.GetMasterMotionTypes(mMasterTypes);
     MotionSelectWindow.GetFilteredMotionTypes(mFilteredTypes, mMasterTypes, mSearchString);
 }