public static T InitFrom <T>(GameElement elm) where T : GameElement { var t = Activator.CreateInstance <T>(); t.Name = elm.Name; t.Id = elm.Id; t.Type = elm.Type; t.Parent = elm.Parent; t.Children = elm.Children; t.Location = elm.Location; t.Rectangle = elm.Rectangle; t.IsOnScreen = elm.IsOnScreen; return(t); }
private static GameElement GetProperties(UnityEngine.Object go) { var elm = new GameElement { Name = go.name, Id = go.GetInstanceID().ToString(), Type = typeof(GameObject).ToString(), IsOnScreen = null }; if (go.GetType().IsSubclassOf(typeof(Component)) || go.GetType() == typeof(Component)) { var gc = (Component)go; var tf = gc.GetComponent <RectTransform>(); if (tf != null) { float x = tf.position.x; float y = tf.position.y; var parent = tf.parent?.name; var children = new string[tf.childCount]; int i = 0; foreach (Transform child in tf.transform) { children[i++] = child.name; } elm.Rectangle = new RectangleF(x, y, tf.rect.width, tf.rect.height); elm.Location = new PointF(x, y); elm.Parent = parent; elm.Children = children; elm.IsOnScreen = gc.gameObject.activeSelf; } } return(elm); }