コード例 #1
0
        //Shows the agent field in case an agent type is specified through the use of the generic versions of Action or Condition Task
        void ShowAgentField()
        {
            if (task.agentType == null)
            {
                return;
            }

            TaskAgentParameter agentParam = agentParameterProp.value;

            if (Application.isPlaying && task.agentIsOverride && agentParam.value == null)
            {
                GUILayout.Label("<b>Missing Agent Reference</b>".FormatError());
                return;
            }

            GUI.color = Color.white.WithAlpha(task.agentIsOverride ? 0.65f : 0.5f);
            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.BeginHorizontal();

            if (task.agentIsOverride)
            {
                BBParameterEditor.ParameterField(null, agentParam, task.ownerSystem.contextObject);
            }
            else
            {
                var compInfo = task.agent == null?task.agentType.FriendlyName().FormatError() : task.agentType.FriendlyName();

                var icon    = TypePrefs.GetTypeIcon(task.agentType);
                var label   = string.Format("Use Self ({0})", compInfo);
                var content = EditorUtils.GetTempContent(label, icon);
                GUILayout.Label(content, GUILayout.Height(18), GUILayout.Width(0), GUILayout.ExpandWidth(true));
            }

            GUI.color = Color.white;

            if (!Application.isPlaying)
            {
                var newOverride = EditorGUILayout.Toggle(task.agentIsOverride, GUILayout.Width(18));
                if (newOverride != task.agentIsOverride)
                {
                    UndoUtility.RecordObject(task.ownerSystem.contextObject, "Override Agent");
                    task.agentIsOverride = newOverride;
                }
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
コード例 #2
0
        //Shows the agent field in case an agent type is specified either with [AgentType] attribute or through the use of the generic versions of Action or Condition Task
        void ShowAgentField()
        {
            if (task.agentType == null)
            {
                return;
            }

            TaskAgentParameter taskAgent = overrideAgentProp.value;

            if (Application.isPlaying && task.agentIsOverride && taskAgent.value == null)
            {
                GUI.color = Colors.lightRed;
                GUILayout.Label("<b>!Missing Agent Reference!</b>");
                GUI.color = Color.white;
                return;
            }


            var isMissingType = task.agent == null;
            var infoString    = isMissingType? "<color=#ff5f5f>" + task.agentType.FriendlyName() + "</color>": task.agentType.FriendlyName();

            GUI.color           = new Color(1f, 1f, 1f, task.agentIsOverride? 1f : 0.5f);
            GUI.backgroundColor = GUI.color;
            GUILayout.BeginVertical(task.agentIsOverride? "box" : "button");
            GUILayout.BeginHorizontal();


            if (task.agentIsOverride)
            {
                if (taskAgent.useBlackboard)
                {
                    GUI.color = new Color(0.9f, 0.9f, 1f, 1f);
                    var varNames = new List <string>();

                    //Local
                    if (taskAgent.bb != null)
                    {
                        varNames.AddRange(taskAgent.bb.GetVariableNames(task.agentType));
                    }

                    //Globals
                    foreach (var globalBB in GlobalBlackboard.allGlobals)
                    {
                        varNames.Add(globalBB.name + "/");

                        var globalVars = globalBB.GetVariableNames(task.agentType);
                        for (var i = 0; i < globalVars.Length; i++)
                        {
                            globalVars[i] = globalBB.name + "/" + globalVars[i];
                        }

                        varNames.AddRange(globalVars);
                    }

                    //No Dynamic for AgentField for convenience and user error safety
                    varNames.Add("(DynamicVar)");

                    if (varNames.Contains(taskAgent.name) || string.IsNullOrEmpty(taskAgent.name))
                    {
                        taskAgent.name = EditorUtils.StringPopup(taskAgent.name, varNames, false, true);
                        if (taskAgent.name == "(DynamicVar)")
                        {
                            taskAgent.name = "_";
                        }
                    }
                    else
                    {
                        taskAgent.name = EditorGUILayout.TextField(taskAgent.name);
                    }
                }
                else
                {
                    taskAgent.value = EditorGUILayout.ObjectField(taskAgent.value, task.agentType, true) as Component;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                var icon    = TypePrefs.GetTypeIcon(task.agentType);
                var label   = string.Format("Use Self ({0})", infoString);
                var content = new GUIContent(label, icon);
                GUILayout.Label(content, GUILayout.Height(16));
                GUILayout.EndHorizontal();
            }


            GUI.color = Color.white;

            if (task.agentIsOverride)
            {
                if (isMissingType)
                {
                    GUILayout.Label("(" + infoString + ")", GUILayout.Height(15));
                }
                taskAgent.useBlackboard = EditorGUILayout.Toggle(taskAgent.useBlackboard, EditorStyles.radioButton, GUILayout.Width(18));
            }

            GUI.color           = Color.white;
            GUI.backgroundColor = Color.white;

            if (!Application.isPlaying)
            {
                task.agentIsOverride = EditorGUILayout.Toggle(task.agentIsOverride, GUILayout.Width(18));
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }