示例#1
0
        public int AddClient(Guid aiId, IContextProvider contextProvider, float intervalMin, float intervalMax, float startDelayMin, float startDelayMax)
        {
            if (AIManager.GetAI(aiId) == null)
            {
                Debug.LogWarning(string.Concat(base.gameObject.name, ": Unable to load AI, no AI with the specified ID exists."));
                return(-1);
            }
            UtilityAIConfig utilityAIConfig = new UtilityAIConfig()
            {
                aiId          = aiId.ToString(),
                intervalMin   = intervalMin,
                intervalMax   = intervalMax,
                startDelayMin = startDelayMin,
                startDelayMax = startDelayMax,
                isActive      = true
            };

            if (this._usedClients == (int)this.aiConfigs.Length)
            {
                this.Resize <UtilityAIConfig>(ref this.aiConfigs, Mathf.Max(2, (int)this.aiConfigs.Length * 2));
            }
            this.aiConfigs[this._usedClients] = utilityAIConfig;
            LoadBalancedUtilityAIClient loadBalancedUtilityAIClient = new LoadBalancedUtilityAIClient(aiId, contextProvider, intervalMin, intervalMax, startDelayMin, startDelayMax);

            return(this.AddClient(loadBalancedUtilityAIClient));
        }
示例#2
0
        /// <summary>
        /// Adds a <see cref="LoadBalancedUtilityAIClient"/> to the list of clients maintained by this <see cref="UtilityAIComponent"/>.
        /// </summary>
        /// <param name="aiId">The ai identifier.</param>
        /// <param name="contextProvider">The context provider.</param>
        /// <param name="intervalMin">The interval minimum.</param>
        /// <param name="intervalMax">The interval maximum.</param>
        /// <param name="startDelayMin">The start delay minimum.</param>
        /// <param name="startDelayMax">The start delay maximum.</param>
        /// <returns></returns>
        public int AddClient(Guid aiId, IContextProvider contextProvider, float intervalMin, float intervalMax, float startDelayMin, float startDelayMax)
        {
            var ai = AIManager.GetAI(aiId);

            if (ai == null)
            {
                Debug.LogWarning(this.gameObject.name + ": Unable to load AI, no AI with the specified ID exists.");
                return(-1);
            }

            var aiConfig = new UtilityAIConfig()
            {
                aiId          = aiId.ToString(),
                intervalMin   = intervalMin,
                intervalMax   = intervalMax,
                startDelayMin = startDelayMin,
                startDelayMax = startDelayMax,
                isActive      = true
            };

            if (_usedClients == this.aiConfigs.Length)
            {
                Resize(ref this.aiConfigs, Mathf.Max(2, this.aiConfigs.Length * 2));
            }

            aiConfigs[_usedClients] = aiConfig;

            var client = new LoadBalancedUtilityAIClient(aiId, contextProvider, intervalMin, intervalMax, startDelayMin, startDelayMax);

            return(AddClient(client));
        }