Beispiel #1
0
        public override void OnInspectorGUI()
        {
            InputMethod obj = (InputMethod)target;

            if (!obj.MatchesContextActionPool)
            {
                if (GUILayout.Button("Update Action List"))
                {
                    obj.UpdateInputs();
                }
            }

            obj.inputMode = (InputMode)EditorGUILayout.EnumPopup(
                "Input Mode", obj.inputMode);
            SerializedProperty contextProp = serializedObject.FindProperty("context");

            EditorGUILayout.PropertyField(contextProp, new GUIContent("Context"));

            List <ActionCombination> combs     = obj.combinations;
            SerializedProperty       combsProp = serializedObject.FindProperty("combinations");
            int indentLevel0 = EditorGUI.indentLevel;

            for (int i = 0; i < combs.Count; i++)
            {
                EditorGUI.indentLevel = indentLevel0;
                ActionCombination  comb     = combs[i];
                SerializedProperty combProp = combsProp.GetArrayElementAtIndex(i);
                DrawAction(comb, combProp);
            }

            serializedObject.ApplyModifiedProperties();

            //base.OnInspectorGUI();
        }
Beispiel #2
0
        private static void DrawAction(ActionCombination comb, SerializedProperty combProp)
        {
            string     actionName        = comb.actionName;
            GUIContent actionNameContent = new GUIContent(actionName);
            float      labelWidth        = EditorStyles.label.CalcSize(actionNameContent).x;

            EditorGUILayout.LabelField(actionName);

            int indentLevel1 = ++EditorGUI.indentLevel;

            DrawBindings(comb.GetDefaultCombination(), combProp,
                         "Default", "defaultCombination");

            EditorGUI.indentLevel = indentLevel1;
            DrawBindings(comb.GetCurrentCombination(), combProp,
                         "Current", "currentCombination");
        }
        public List <Sprite> GetSprites(ActionCombination combo)
        {
            List <Sprite> sprites = new List <Sprite>();

            for (int i = 0; i < inputIcons.Count; i++)
            {
                if (combo == null)
                {
                    Debug.Log($"Invalid Action Combination: {combo}");
                    return(null);
                }
                if (combo.Contains(inputIcons[i].input))
                {
                    sprites.Add(inputIcons[i].sprite);
                }
            }
            return(sprites);
        }
Beispiel #4
0
        public static string ConvertActionTagsToRichText(string input, InputIconSO iconSet, Func <string, TMP_SpriteAssetContainer> getContainer)
        {
            if (input == string.Empty)
            {
                return(input);
            }
            string s = input;

            List <string> actions = InputManager.GetCurrentActions();

            for (int i = 0; i < actions?.Count; i++)
            {
                string            action = actions[i];
                string            check;
                ActionCombination inputCombo = InputManager.GetBinding(action);
                if (inputCombo == null)
                {
                    Debug.Log($"No ActionCombination found for {action}");
                    return(input);
                }

                check = $"[:{action}]";
                if (s.Contains(check))
                {
                    s = s.Replace(check, $"<color=#00FFFF>{action}</color>");
                }

                if (iconSet == null)
                {
                    continue;
                }

                List <Sprite>            sprites   = iconSet.GetSprites(inputCombo);
                TMP_SpriteAssetContainer container = getContainer(action);
                if (container == null)
                {
                    Debug.Log($"Sprite Container not found for {action}.");
                    return(input);
                }
                List <TMP_SpriteAsset> assets = container?.spriteAssets;

                check = $"[{action}]";
                if (s.Contains(check))
                {
                    string tmpIconString = "";
                    for (int j = 0; j < sprites.Count; j++)
                    {
                        assets[j].spriteSheet          = sprites[j].texture;
                        assets[j].material.mainTexture = assets[j].spriteSheet;
                        tmpIconString += $"<sprite=\"{assets[j].name}\" index=0>";
                        if (j != sprites.Count - 1)
                        {
                            tmpIconString += " + ";
                        }
                    }
                    s = s.Replace(check, $"{tmpIconString} <color=#00FFFF>{action}</color>");
                }

                check = $"[{action}:]";
                if (s.Contains(check))
                {
                    string tmpIconString = "";
                    for (int j = 0; j < sprites.Count; j++)
                    {
                        assets[j].spriteSheet          = sprites[j].texture;
                        assets[j].material.mainTexture = assets[j].spriteSheet;
                        tmpIconString += $"<sprite=\"{assets[j].name}\" index=0>";
                        if (j != sprites.Count - 1)
                        {
                            tmpIconString += " + ";
                        }
                    }
                    s = s.Replace(check, tmpIconString);
                }
            }

            return(s);
        }