using UnityEngine;
 
[ExecuteInEditMode]
public class AnimateHierarchyOrder : MonoBehaviour {
 
    public float siblingOrder;
    void Awake(){
        siblingOrder = transform.GetSiblingIndex();
    }
 
    void OnValidate(){
        siblingOrder = Mathf.Round(siblingOrder);
        if(siblingOrder != transform.GetSiblingIndex()){
            transform.SetSiblingIndex((int)siblingOrder);
            siblingOrder = transform.GetSiblingIndex();
        }
    }
 
    void OnDidApplyAnimationProperties(){
        OnValidate();
    }

    public void UpdateOrder(int siblingOrder){
        this.siblingOrder = siblingOrder;
        OnValidate();
    }

    public void UpdateOrder(){
        OnValidate();
    }
}