예제 #1
0
        public override void EndInit()
        {
            ProxyData proxyData = Node.ProxyData;
            Type      type      = CSharpProxyManager.Instance.GetType(proxyData.ClassType);

            m_NodeProxy = Activator.CreateInstance(type) as BaseNodeProxy;
            m_NodeProxy.BeginInit();
            m_NodeProxy.SetNode(Node);
            m_NodeProxy.SetData(Node.NodeData);
            m_NodeProxy.SetContext(Node.Context);
            m_NodeProxy.EndInit();
        }
        public BaseNodeProxy CreateProxy(BaseNode node)
        {
            if (node == null)
            {
                //组合节点必须有子节点
                string msg = "BehaviorTreeManager.CreateProxy() \n Create nodeProxy failed,node is null.";
                LogError(msg);
                throw new Exception(msg);
            }

            //重置节点状态
            if (node.Status != ENodeStatus.None)
            {
                node.Status = ENodeStatus.None;
            }

            IProxyManager proxyManager = null;

            for (int i = 0; i < m_ProxyManagers.Count; i++)
            {
                IProxyManager tempProxyManager = m_ProxyManagers[i];
                ProxyData     proxyData        = tempProxyManager.GetProxyData(node.ClassType);
                if (proxyData != null)
                {
                    proxyManager = tempProxyManager;
                    break;
                }
            }

            if (proxyManager == null)
            {
                string msg = $"BehaviorTreeManager.CreateProxy() \n Create nodeProxy failed,proxyManager is null.";
                LogError(msg);
                throw new Exception(msg);
            }

            BaseNodeProxy nodeProxy = proxyManager.CreateProxy();

            if (nodeProxy == null)
            {
                string msg = $"BehaviorTreeManager.CreateProxy() \n Create nodeProxy failed,ClassType:{node.ProxyData.ClassType}";
                LogError(msg);
                throw new Exception(msg);
            }

            nodeProxy.BeginInit();
            nodeProxy.SetNode(node);
            nodeProxy.SetData(node.NodeData);
            nodeProxy.SetContext(node.Context);
            nodeProxy.EndInit();

            return(nodeProxy);
        }