예제 #1
0
        private string GetNodePath(BossBehaviour behaviour, BehaviourNode node)
        {
            var arrayName  = node is ActionBehaviourNode ? "_actionBehaviours" : "_compoundBehaviours";
            var arrayField = behaviour.GetType().GetField(arrayName, BindingFlags.NonPublic | BindingFlags.Instance);

            if (arrayField == null)
            {
                throw new ApplicationException(string.Format("Cannot find field {0} in class {1}", arrayName,
                                                             behaviour.GetType()));
            }

            var dict      = arrayField.GetValue(behaviour);
            var keysField = FindFieldInHierarchy(dict.GetType(), "_keys");

            if (keysField == null)
            {
                throw new ApplicationException(string.Format("Cannot find field {0} in class {1}", "_keys",
                                                             dict.GetType()));
            }

            var list = (IList)keysField.GetValue(dict);

            var index = list.IndexOf(node.Guid);

            if (index < 0)
            {
                throw new ArgumentException(string.Format("Cannot find node {0}", node));
            }

            var path = string.Format("{0}._values.Array.data[{1}]", arrayName, index);

            return(path);
        }