///Resolve the final Variable reference.
        private Variable ResolveReference(IBlackboard targetBlackboard, bool useID)
        {
            var targetName = this.name;

            if (targetName != null && targetName.Contains("/"))
            {
                var split = targetName.Split('/');
                targetBlackboard = GlobalBlackboard.Find(split[0]);
                targetName       = split[1];
            }

            Variable result = null;

            if (targetBlackboard == null)
            {
                return(null);
            }
            if (useID && targetVariableID != null)
            {
                result = targetBlackboard.GetVariableByID(targetVariableID);
            }
            if (result == null && !string.IsNullOrEmpty(targetName))
            {
                result = targetBlackboard.GetVariable(targetName, varType);
            }
            return(result);
        }
Beispiel #2
0
        ///Promotes the parameter to a variable on the target blackboard (overriden if parameter name is a path to a global bb).
        public Variable PromoteToVariable(IBlackboard targetBB)
        {
            if (string.IsNullOrEmpty(name))
            {
                varRef = null;
                return(null);
            }

            var varName = name;
            var bbName  = targetBB != null? targetBB.name : string.Empty;

            if (name.Contains("/"))
            {
                var split = name.Split('/');
                bbName   = split[0];
                varName  = split[1];
                targetBB = GlobalBlackboard.Find(bbName);
            }

            if (targetBB == null)
            {
                varRef = null;
                Debug.LogError(string.Format("Parameter '{0}' failed to promote to a variable, because Blackboard named '{1}' could not be found.", varName, bbName));
                return(null);
            }

            varRef = targetBB.AddVariable(varName, varType);
            Debug.Log(string.Format("Parameter '{0}' (of type '{1}') promoted to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), bbName));
            return(varRef);
        }
        ///Promotes the parameter to a variable on the target blackboard (overriden if parameter name is a path to a global bb).
        public Variable PromoteToVariable(IBlackboard targetBB)
        {
            if (string.IsNullOrEmpty(name))
            {
                varRef = null;
                return(null);
            }

            var varName = name;
            var bbName  = targetBB != null? targetBB.name : string.Empty;

            if (name.Contains("/"))
            {
                var split = name.Split('/');
                bbName   = split[0];
                varName  = split[1];
                targetBB = GlobalBlackboard.Find(bbName);
            }

            if (targetBB == null)
            {
                varRef = null;
                Logger.LogError(string.Format("Parameter '{0}' failed to promote to a variable, because Blackboard named '{1}' could not be found.", varName, bbName), "Variable", this);
                return(null);
            }

            varRef = targetBB.AddVariable(varName, varType);
            if (varRef != null)
            {
                                #if UNITY_EDITOR
                if (NodeCanvas.Editor.NCPrefs.logDynamicParametersInfo)
                {
                    Logger.Log(string.Format("Parameter '{0}' (of type '{1}') promoted to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), bbName), "Variable", this);
                }
                                #endif
            }
            else
            {
                Logger.LogError(string.Format("Parameter {0} (of type '{1}') failed to promote to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), bbName), "Variable", this);
            }
            return(varRef);
        }