Search Unity

Access to public properties in the Animation editor.

Discussion in 'Animation' started by yurowm, Jun 13, 2020.

  1. yurowm

    yurowm

    Joined:
    Feb 16, 2015
    Posts:
    136
    Hi there,

    I have small idea for improvement the Animation editor. I hope the Unity developers will see it and add into the road map.
    Currently we have an access only to the serializable fields of components we want to animate. But there is a lot of cases when we can want to animate something that is not available in the Animation editor. It can be some kind of structs and their elements, it can be arrays and their elements too. It can be something complex like count of childs, or anything else. I understand how the animations and the editor works, and why we can't animate it now. But what if we had possibility to animate public properties which has read and write access? I sure that it is a very simple improvement, but it will give us a lot of possibilities. For example, if we need to animate first of an array elements in a component, we just create a public property with read and write access, and in the "set" method we write a logic of changes and call some kind of Refresh method to apply changes.

    I have made a small illustration of how it could looks like.

    Code (CSharp):
    1. using System;
    2. using System.Linq;
    3. using UnityEngine;
    4.  
    5. public class TestComponent : MonoBehaviour {
    6.    
    7.     public Element[] elements;
    8.    
    9.     public Color ColorOfFirstElement {
    10.         get => elements.FirstOrDefault().color;
    11.         set {
    12.             if (elements.Length <= 0) return;
    13.            
    14.             elements[0].color = value;
    15.             Refresh();
    16.         }
    17.     }  
    18.    
    19.     public float SizeOfFirstElement {
    20.         get => elements.FirstOrDefault().size;
    21.         set {
    22.             if (elements.Length <= 0) return;
    23.            
    24.             elements[0].size = value;
    25.             Refresh();
    26.         }
    27.     }
    28.    
    29.     public void Refresh() {
    30.         Debug.Log("Refresh component state");
    31.     }
    32.    
    33.     [Serializable]
    34.     public struct Element {
    35.         public string name;
    36.         public float size;
    37.         public Color color;
    38.     }
    39. }
    upload_2020-6-13_11-57-24.png