예제 #1
0
        ///Resolves and gets an actor based on the key name
        public IDialogueActor GetActorReferenceByName(string paramName)
        {
            //Check for INSTIGATOR selection
            if (paramName == INSTIGATOR_NAME)
            {
                //return it directly if it implements IDialogueActor
                if (agent is IDialogueActor)
                {
                    return((IDialogueActor)agent);
                }

                //Otherwise use the default actor and set name and transform from agent
                if (agent != null)
                {
                    return(new ProxyDialogueActor(agent.gameObject.name, agent.transform));
                }

                return(new ProxyDialogueActor("Null Instigator", null));
            }

            //Check for non INSTIGATOR selection. If there IS an actor reference return it
            var refData = actorParameters.Find(r => r.name == paramName);

            if (refData != null && refData.actor != null)
            {
                return(refData.actor);
            }

            //Otherwise use the default actor and set the name to the key and null transform
            Logger.Log(string.Format("An actor entry '{0}' on DialogueTree has no reference. A dummy Actor will be used with the entry Key for name", paramName), "Dialogue Tree", this);
            return(new ProxyDialogueActor(paramName, null));
        }
예제 #2
0
        //Create and set a UnityObject variable node on drop
        protected override void OnDropAccepted(Object o, Vector2 mousePos)
        {
            if (o == null)
            {
                return;
            }

            if (UnityEditor.EditorUtility.IsPersistent(this) && !UnityEditor.EditorUtility.IsPersistent(o))
            {
                Logger.Log("This Graph is an asset. The dragged object is a scene reference. The reference will not persist!", LogTag.EDITOR);
            }

            var targetType = o.GetType();
            var menu       = new UnityEditor.GenericMenu();

            menu = AppendDragAndDropObjectMenu(menu, o, "", mousePos);
            menu.AddSeparator("/");
            menu = this.AppendTypeReflectionNodesMenu(menu, targetType, "", mousePos, null, o);
            if (o is GameObject)
            {
                foreach (var component in (o as GameObject).GetComponents <Component>().Where(c => c.hideFlags == 0))
                {
                    var cType = component.GetType();
                    menu = AppendDragAndDropObjectMenu(menu, component, cType.Name + "/", mousePos);
                    menu = this.AppendTypeReflectionNodesMenu(menu, cType, "", mousePos, null, component);
                }
            }

            menu.ShowAsBrowser("Add Node For Drag & Drop Instance");
            Event.current.Use();
        }
예제 #3
0
 //...
 protected void OnEnable()
 {
     if (IsPrefabAsset())
     {
         return;
     }
     if (string.IsNullOrEmpty(_identifier))
     {
         _identifier = gameObject.name;
     }
     if (Application.isPlaying)
     {
         if (Find(identifier) != null)
         {
             Logger.Log(string.Format("There exist more than one Global Blackboards with same identifier name '{0}'. The old one will now be destroyed.", identifier), LogTag.BLACKBOARD, this);
             if (_singletonMode == SingletonMode.DestroyComponentOnly)
             {
                 Destroy(this);
             }
             if (_singletonMode == SingletonMode.DestroyEntireGameObject)
             {
                 Destroy(this.gameObject);
             }
             return;
         }
         if (_dontDestroyOnLoad)
         {
             DontDestroyOnLoad(this.gameObject);
         }
     }
     if (!_allGlobals.Contains(this))
     {
         _allGlobals.Add(this);
     }
 }
예제 #4
0
 void OnCustomEvent(string eventName, IEventData data)
 {
     if (eventName.Equals(this.eventName.value, System.StringComparison.OrdinalIgnoreCase))
     {
         Logger.Log(string.Format("Event Received from ({0}): '{1}'", agent.gameObject.name, name), LogTag.EVENT, this);
         YieldReturn(true);
     }
 }
예제 #5
0
 protected override void OnGraphPaused()
 {
     Logger.Log(string.Format("Dialogue Paused '{0}'", this.name), "Dialogue Tree", this);
     if (OnDialoguePaused != null)
     {
         OnDialoguePaused(this);
     }
 }
예제 #6
0
        protected override void OnGraphUnpaused()
        {
            currentNode = currentNode != null ? currentNode : (DTNode)primeNode;
            EnterNode(currentNode);

            Logger.Log(string.Format("Dialogue Resumed '{0}'", this.name), "Dialogue Tree", this);
            if (OnDialogueStarted != null)
            {
                OnDialogueStarted(this);
            }
        }
예제 #7
0
 void OnCustomEvent(string eventName, ParadoxNotion.IEventData msg)
 {
     if (eventName.Equals(this.eventName.value, System.StringComparison.OrdinalIgnoreCase))
     {
         var senderGraph = Graph.GetElementGraph(msg.sender);
         this.sender   = senderGraph != null ? senderGraph.agent as GraphOwner : null;
         this.receiver = ResolveReceiver(msg.receiver);
         Logger.Log(string.Format("Event Received from ({0}): '{1}'", receiver.name, eventName), LogTag.EVENT, this);
         onReceived.Call(new Flow());
     }
 }
예제 #8
0
 void IUpdatable.Update()
 {
     if (send)
     {
         send = false;
         var sw = new Stopwatch();
         sw.Start();
         o.Call(new Flow());
         sw.Stop();
         Logger.Log(string.Format("Debug Event Elapsed Time: {0} ms.", sw.ElapsedMilliseconds), LogTag.EDITOR, this);
     }
 }
 void OnCustomEvent(string eventName, ParadoxNotion.IEventData msg)
 {
     if (eventName.Equals(this.eventName.value, System.StringComparison.OrdinalIgnoreCase))
     {
         var receivedValue = msg.valueBoxed;
         if (ObjectUtils.AnyEquals(receivedValue, value.value))
         {
             Logger.Log(string.Format("Event Received from ({0}): '{1}'", agent.gameObject.name, eventName), LogTag.EVENT, this);
             YieldReturn(true);
         }
     }
 }
예제 #10
0
        protected override void OnGraphStoped()
        {
            currentDialogue  = previousDialogue;
            previousDialogue = null;
            currentNode      = null;

            Logger.Log(string.Format("Dialogue Finished '{0}'", this.name), "Dialogue Tree", this);
            if (OnDialogueFinished != null)
            {
                OnDialogueFinished(this);
            }
        }
예제 #11
0
        public void OnCustomEvent(ParadoxNotion.Services.MessageRouter.MessageData <EventData> msg)
        {
            if (msg.value.name.ToUpper() == eventName.value.ToUpper())
            {
                this.receiver = ResolveReceiver(msg.receiver);

                                #if UNITY_EDITOR
                if (NodeCanvas.Editor.NCPrefs.logEvents)
                {
                    Logger.Log(string.Format("Event Received from ({0}): '{1}'", receiver.name, msg.value.name), "Event", this);
                }
                                #endif

                onReceived.Call(new Flow());
            }
        }
예제 #12
0
        public void OnCustomEvent(ParadoxNotion.Services.MessageRouter.MessageData <EventData> msg)
        {
            if (msg.value.name.ToUpper() == eventName.value.ToUpper())
            {
                var senderGraph = Graph.GetElementGraph(msg.sender);
                this.sender   = senderGraph != null ? senderGraph.agent as GraphOwner : null;
                this.receiver = ResolveReceiver(msg.receiver);

#if UNITY_EDITOR
                if (NodeCanvas.Editor.Prefs.logEvents)
                {
                    Logger.Log(string.Format("Event Received from ({0}): '{1}'", receiver.name, msg.value.name), "Event", this);
                }
#endif

                onReceived.Call(new Flow());
            }
        }
예제 #13
0
        ///Set the value of the Variable variable defined by its name. If a data by that name and type doesnt exist, a new data is added by that name
        public static Variable SetVariableValue(this IBlackboard blackboard, string varName, object value)
        {
            Variable variable;

            if (!blackboard.variables.TryGetValue(varName, out variable))
            {
                Logger.Log(string.Format("No Variable of name '{0}' and type '{1}' exists on Blackboard '{2}'. Adding new instead...", varName, value != null ? value.GetType().FriendlyName() : "null", blackboard), LogTag.BLACKBOARD, blackboard);
                variable = blackboard.AddVariable(varName, value);
                return(variable);
            }

            try { variable.value = value; }
            catch {
                Logger.LogError(string.Format("Can't cast value '{0}' to blackboard variable of name '{1}' and type '{2}'", value != null ? value.ToString() : "null", varName, variable.varType.FriendlyName()), LogTag.BLACKBOARD, blackboard);
                return(null);
            }

            return(variable);
        }
예제 #14
0
        protected override void OnGraphStarted()
        {
            previousDialogue = currentDialogue;
            currentDialogue  = this;

            Logger.Log(string.Format("Dialogue Started '{0}'", this.name), "Dialogue Tree", this);
            if (OnDialogueStarted != null)
            {
                OnDialogueStarted(this);
            }

            if (!(agent is IDialogueActor))
            {
                Logger.Log("INSTIGATOR agent used in DialogueTree does not implement IDialogueActor. A dummy actor will be used.", "Dialogue Tree", this);
            }

            currentNode = currentNode != null ? currentNode : (DTNode)primeNode;
            EnterNode(currentNode);
        }
예제 #15
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;
                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);
        }
예제 #16
0
        ///<summary>Promotes the parameter to a variable on the target blackboard (overriden if parameter name is a path to a global bb).</summary>
        public Variable PromoteToVariable(IBlackboard targetBB)
        {
            if (string.IsNullOrEmpty(name))
            {
                varRef = null;
                return(null);
            }

            var varName = name;
            var bbName  = 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), LogTag.VARIABLE, this);
                return(null);
            }

            varRef = targetBB.AddVariable(varName, varType);
            if (varRef != null)
            {
                Logger.Log(string.Format("Parameter '{0}' (of type '{1}') promoted to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), targetBB), LogTag.VARIABLE, this);
            }
            else
            {
                Logger.LogError(string.Format("Parameter {0} (of type '{1}') failed to promote to a Variable in Blackboard '{2}'.", varName, varType.FriendlyName(), targetBB), LogTag.VARIABLE, this);
            }
            return(varRef);
        }
예제 #17
0
        ///Adds a new Variable in the blackboard defining name and type instead of value
        public static Variable AddVariable(this IBlackboard blackboard, string varName, Type type)
        {
            if (blackboard.variables.TryGetValue(varName, out Variable result))
            {
                if (result.CanConvertTo(type))
                {
                    Logger.Log(string.Format("Variable with name '{0}' already exists in blackboard '{1}'. Returning existing instead of new.", varName, blackboard), LogTag.BLACKBOARD, blackboard);
                    return(result);
                }
                else
                {
                    Logger.LogError(string.Format("Variable with name '{0}' already exists in blackboard '{1}', but is of a different type! Returning null instead of new.", varName, blackboard), LogTag.BLACKBOARD, blackboard);
                    return(null);
                }
            }

            var variableType = typeof(Variable <>).RTMakeGenericType(new Type[] { type });
            var newVariable  = (Variable)Activator.CreateInstance(variableType);

            newVariable.name = varName;
            blackboard.variables[varName] = newVariable;
            blackboard.TryInvokeOnVariableAdded(newVariable);
            return(newVariable);
        }
예제 #18
0
 public override void Invoke(object obj)
 {
     Logger.Log(obj, NodeCanvas.Framework.LogTag.EXECUTION, parentNode);
 }
예제 #19
0
 public override void Invoke(string text)
 {
     Logger.Log(text, NodeCanvas.Framework.LogTag.EXECUTION, parentNode);
 }
예제 #20
0
        ///A IDictionary editor
        public static IDictionary DictionaryEditor(GUIContent content, IDictionary dict, Type dictType, InspectedFieldInfo info)
        {
            var keyType   = dictType.RTGetGenericArguments()[0];
            var valueType = dictType.RTGetGenericArguments()[1];

            if (object.Equals(dict, null))
            {
                GUILayout.Label("Null Dictionary");
                return(dict);
            }

            if (!CachedFoldout(dictType, content))
            {
                return(dict);
            }

            GUILayout.BeginVertical();

            var keys   = dict.Keys.Cast <object>().ToList();
            var values = dict.Values.Cast <object>().ToList();

            if (GUILayout.Button("Add Element"))
            {
                if (!typeof(UnityObject).IsAssignableFrom(keyType))
                {
                    object newKey = null;
                    if (keyType == typeof(string))
                    {
                        newKey = string.Empty;
                    }
                    else
                    {
                        newKey = Activator.CreateInstance(keyType);
                    }

                    if (dict.Contains(newKey))
                    {
                        Logger.LogWarning(string.Format("Key '{0}' already exists in Dictionary", newKey.ToString()), "Editor");
                        return(dict);
                    }

                    keys.Add(newKey);
                }
                else
                {
                    Logger.LogWarning("Can't add a 'null' Dictionary Key", "Editor");
                    return(dict);
                }

                values.Add(valueType.IsValueType ? Activator.CreateInstance(valueType) : null);
            }

            //clear before reconstruct
            dict.Clear();

            for (var i = 0; i < keys.Count; i++)
            {
                GUILayout.BeginHorizontal("box");
                GUILayout.Box("", GUILayout.Width(6), GUILayout.Height(35));

                GUILayout.BeginVertical();
                keys[i]   = ReflectedFieldInspector("K:", keys[i], keyType, info);
                values[i] = ReflectedFieldInspector("V:", values[i], valueType, info);
                GUILayout.EndVertical();

                if (GUILayout.Button("X", GUILayout.Width(18), GUILayout.Height(34)))
                {
                    keys.RemoveAt(i);
                    values.RemoveAt(i);
                }

                GUILayout.EndHorizontal();

                try { dict.Add(keys[i], values[i]); }
                catch { Logger.Log("Dictionary Key removed due to duplicate found", "Editor"); }
            }

            Separator();

            GUILayout.EndVertical();
            return(dict);
        }