Advertisement
jamieTheCoder

AnimationShowcase

Sep 6th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | Software | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using TMPro;
  6. using MoreMountains.TopDownEngine;
  7.  
  8. /// <summary>
  9. /// Checks the _animator for any Trigger parameters, then creates buttons that trigger each in UI
  10. /// Add this script to a UI object with a Layout component.
  11. /// </summary>
  12.  
  13. public class AnimationShowcase : MonoBehaviour
  14. {
  15.     [SerializeField] private Animator _animator;
  16.     [SerializeField] private Button _buttonPrefab;
  17.    
  18.     private void AddButton(AnimatorControllerParameter parameter)
  19.     {
  20.         //create a new button
  21.         var button = Instantiate(_buttonPrefab,transform);
  22.         //Set the button text to the trigger name
  23.         foreach (var tmpText in button.GetComponentsInChildren<TMP_Text>())
  24.         {
  25.             tmpText.text = parameter.name;
  26.             //set the button's click behaviour
  27. // this is the problem i'm trying to set the bool to either true or false based on its current value
  28. // i think the right word is a flip flop
  29.             button.onClick.AddListener(()=> parameter != parameter);
  30.         }
  31.     }
  32.     public void SetAnimatorOnAnimShowcase(Animator animator)
  33.     {
  34.         _animator = animator;
  35.         Debug.Log("animator set");
  36.         //Find all parameters in the Animator
  37.         foreach (var parameter in _animator.parameters)
  38.         {
  39.             //if it's a Trigger, create a button for it
  40.             if(parameter.type == AnimatorControllerParameterType.Bool)
  41.             {
  42.                 Debug.Log(parameter);
  43.                 AddButton(parameter);
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Tags: Unity game dev
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement