public override void Initialise(PuppeteerAgent _owner)
    {
        m_Agent = _owner;

        FishManager.Instance.OnFishSpawned += OnFishSpawnedOrClaimed;
        FishManager.Instance.OnFishClaimed += OnFishSpawnedOrClaimed;
    }
Ejemplo n.º 2
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (_executingAgent.GetWorkingMemory().TryGetValue("LastInRangeExplosionPosition", out var lastPosition))
        {
            var fleeDirection = (m_Agent.transform.position - (Vector3)lastPosition).normalized;
            _executingAgent.AddOrUpdateWorkingMemory("TargetPosition", m_Agent.transform.position + fleeDirection * ExplosionManager.Instance.GetDangerRange() * 2);

            if (_executingAgent.TryGetComponent <Animator>(out var animator))
            {
                animator.SetTrigger(ANIMATOR_START_INJURED_RUN_KEY);

                if (_executingAgent.TryGetComponent <NavMeshAgent>(out var navMeshAgent))
                {
                    navMeshAgent.speed = 3;
                }
            }
        }
        else
        {
            m_CurrentActionState = ActionState.Failed;
            return;
        }
    }
Ejemplo n.º 3
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        _executingAgent.GetWorkingMemory().TryGetValue("PickupTarget", out var value);
        FishManager.Instance.AddFish(value != null ? value as GameObject : null);
    }
Ejemplo n.º 4
0
        public void AddPrefabIcon(VisualElement _iconContainer, PuppeteerAgent _agent)
        {
            _iconContainer.hierarchy.Clear();

            GameObject prefabObject = PrefabUtility.GetCorrespondingObjectFromSource(_agent.gameObject);
            string     path         = prefabObject != null?AssetDatabase.GetAssetPath(prefabObject) : null;

            IMGUIContainer icon = new IMGUIContainer(() =>
            {
                if (path != null)
                {
                    GameObject asset = AssetDatabase.LoadAssetAtPath <GameObject>(path);

                    Editor editor = GetPreviewEditor(asset);

                    editor.OnPreviewGUI(GUILayoutUtility.GetRect(170, 170), new GUIStyle()
                    {
                        normal = { background = Texture2D.whiteTexture }
                    });
                }
                else
                {
                    GUILayout.Label("Not a Prefab.");
                }
            })
            {
                focusable = false,
                name      = "prefabIcon",
            };

            icon.AddToClassList("prefabIcon");

            _iconContainer.hierarchy.Add(icon);
        }
Ejemplo n.º 5
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (m_Agent.TryGetComponent <Animator>(out var animator))
        {
            animator.SetTrigger(m_StartSittingKey);
        }
    }
    public override void Initialise(PuppeteerAgent _owner)
    {
        var sensorDesc = PuppeteerManager.Instance.GetSensorDescription(DescriptionGUID);

        if (sensorDesc != null)
        {
            m_ManagedWorldState = sensorDesc.ManagedWorldState;
        }
    }
Ejemplo n.º 7
0
    public override bool IsValid(PuppeteerAgent _executingAgent)
    {
        if (_executingAgent.gameObject.GetComponent <NavMeshAgent>() == null)
        {
            return(false);
        }

        return(_executingAgent.GetWorkingMemory().ContainsKey(TARGET_POSITION_KEY));
    }
    public override void Initialise(PuppeteerAgent _owner)
    {
        m_Agent = _owner;
        MushroomManager.Instance.OnMushroomCountChanged += SetHasEnoughMushrooms;

        var sensorDesc = PuppeteerManager.Instance.GetSensorDescription(DescriptionGUID);

        m_ManagedWorldState = sensorDesc.ManagedWorldState;
    }
Ejemplo n.º 9
0
    public override bool IsValid(PuppeteerAgent _executingAgent)
    {
        if (_executingAgent.TryGetComponent <Animator>(out _))
        {
            return(true);
        }

        m_CurrentActionState = ActionState.Failed;
        return(false);
    }
Ejemplo n.º 10
0
        private void EnsureArchetypeSelectorIsInSync()
        {
            PuppeteerAgent selectedAgent = (m_SelectedListItem as AgentListItem)?.GetAgent();

            if (selectedAgent == null)
            {
                return;
            }

            ref var archetypeField = ref m_AgentConfigurator.ArchetypeField;
Ejemplo n.º 11
0
        private AgentListItem CreateAgentListItem(PuppeteerAgent _agent)
        {
            AgentListItem item = new AgentListItem(_agent);

            item.OnMouseDown += UpdateSelectedListItem;
            m_ListItems.Add(item);

            _agent.OnPuppeteerAgentDestroy += PuppeteerAgentDestroy;

            return(item);
        }
Ejemplo n.º 12
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (!IsValid(_executingAgent))
        {
            return;
        }

        m_FishingLocation = FishManager.Instance.GetCurrentFishingSpotPosition();
    }
Ejemplo n.º 13
0
        private void ArchetypeFieldChangedEvent(ChangeEvent <Guid> _event)
        {
            PuppeteerAgent selectedAgent = (m_SelectedListItem as AgentListItem)?.GetAgent();

            if (selectedAgent == null)
            {
                return;
            }

            selectedAgent.ArchetypeGUID = _event.newValue;
            EditorUtility.SetDirty(selectedAgent);
        }
Ejemplo n.º 14
0
        public void OverrideTargetAgent(PuppeteerAgent _agent)
        {
            if (m_Agent != null)
            {
                m_Agent.OnPlanProgressed -= UpdatePlanForAgent;
            }

            m_Agent = _agent;
            if (m_Agent != null)
            {
                m_Agent.OnPlanProgressed += UpdatePlanForAgent;
            }
        }
Ejemplo n.º 15
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        Vector3 fishingSpot = FishManager.Instance.GetCurrentFishingSpotPosition();

        if (fishingSpot == null)
        {
            m_CurrentActionState = ActionState.Failed;
            return;
        }

        _executingAgent.AddOrUpdateWorkingMemory("TargetPosition", fishingSpot);
    }
Ejemplo n.º 16
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (!IsValid(_executingAgent))
        {
            return;
        }

        var animator = _executingAgent.GetComponent <Animator>();

        animator.SetTrigger(ANIMATOR_START_FISHING_KEY);

        m_EndFishingAt = FishManager.Instance.GetRandomFishingDuration() + Time.time;
    }
Ejemplo n.º 17
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        GameObject closestFish = FishManager.Instance.GetClosestUnclaimedFishToPosition(_executingAgent.gameObject.transform.position);

        if (closestFish == null)
        {
            m_CurrentActionState = ActionState.Failed;
            return;
        }

        _executingAgent.AddOrUpdateWorkingMemory("TargetPosition", closestFish.transform.position);
        _executingAgent.AddOrUpdateWorkingMemory("PickupTarget", closestFish);
    }
Ejemplo n.º 18
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        var targetFish = (GameObject)_executingAgent.GetWorkingMemory()["PickupTarget"];

        if (targetFish != null)
        {
            if (_executingAgent.gameObject.TryGetComponent <CarryHelper>(out var carryHelper))
            {
                carryHelper.ReplaceCarriedObject(targetFish);
            }
        }

        _executingAgent.AddOrUpdateWorkingMemory("TargetPosition", FishManager.Instance.GetHomeBaseTransform().position);
    }
Ejemplo n.º 19
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (!IsValid(_executingAgent))
        {
            m_CurrentActionState = ActionState.Failed;
            return;
        }

        m_TargetPosition         = (Vector3)_executingAgent.GetWorkingMemory()[TARGET_POSITION_KEY];
        m_Animator               = _executingAgent.GetComponent <Animator>();
        m_NavMeshAgent           = _executingAgent.GetComponent <NavMeshAgent>();
        m_NavMeshAgent.isStopped = false;
        m_NavMeshAgent.SetDestination(m_TargetPosition);
    }
    public override bool DetectWorldStateChange(PuppeteerAgent _owner)
    {
        var lastExplosionPosition = ExplosionManager.Instance.GetLastExplosionPositionIfAny();

        if (!lastExplosionPosition.HasValue)
        {
            return(false);
        }

        float range           = ExplosionManager.Instance.GetDangerRange();
        float squaredDistance = Vector3.SqrMagnitude(lastExplosionPosition.Value - _owner.gameObject.transform.position);

        if (squaredDistance > range * range)
        {
            return(false);
        }

        _owner.AddOrUpdateWorkingMemory("LastInRangeExplosionPosition", lastExplosionPosition.Value);
        _owner.AddOrUpdateWorkingMemory(m_ManagedWorldState, true);
        return(true);
    }
Ejemplo n.º 21
0
        protected override void UpdateConfigurator()
        {
            if (m_SelectedListItem is AgentListItem selectedAgentListItem)
            {
                EnableRightPanelContent();
                LazyInitConfigurator();

                PuppeteerAgent selectedAgent = selectedAgentListItem.GetAgent();
                if (selectedAgent == null)
                {
                    return;
                }

                EnsureArchetypeSelectorIsInSync();
                m_AgentConfigurator.ArchetypeField.SetValueWithoutNotify(selectedAgent.ArchetypeGUID);
                m_AgentConfigurator.AgentName.Unbind();
                m_AgentConfigurator.AgentName.Bind(new SerializedObject(selectedAgent.gameObject));
                AddPrefabIcon(m_AgentConfigurator.PrefabIcon, selectedAgent);

                UpdateWorkingMemoryDisplay(selectedAgent);
                UpdatePlanDisplay(selectedAgent);
            }
        }
Ejemplo n.º 22
0
        private void OtherTabArchetypeListItemDeleted(ListItem _deletedListItem)
        {
            if (_deletedListItem is ArchetypeListItem deletedArchetypeListItem)
            {
                for (int i = 0; i < m_ListItems.Count; ++i)
                {
                    if (m_ListItems[i] is AgentListItem agentListItem)
                    {
                        PuppeteerAgent agent = agentListItem.GetAgent();
                        if (agent == null)
                        {
                            continue;
                        }

                        if (agent.ArchetypeGUID != deletedArchetypeListItem.GetDescription().GUID)
                        {
                            continue;
                        }

                        agent.ArchetypeGUID = Guid.Empty;
                    }
                }
            }
        }
    public override bool DetectWorldStateChange(PuppeteerAgent _owner)
    {
        m_Agent.GetWorkingMemory().TryGetValue(m_ManagedWorldState, out var value);

        var fishingSpot = FishManager.Instance.GetCurrentFishingSpotPosition();

        if (value == null)
        {
            m_Agent.AddOrUpdateWorkingMemory(m_ManagedWorldState, fishingSpot);
            m_Agent.AddOrUpdateWorkingMemory(AT_TARGET_POSITION_KEY, false);
            m_Agent.AddOrUpdateWorkingMemory(HAS_TARGET_POSITION_KEY, true);
            return(true);
        }

        if (Vector3.Distance((Vector3)value, fishingSpot) > 1.0f)
        {
            m_Agent.AddOrUpdateWorkingMemory(m_ManagedWorldState, fishingSpot);
            m_Agent.AddOrUpdateWorkingMemory(AT_TARGET_POSITION_KEY, false);
            m_Agent.AddOrUpdateWorkingMemory(HAS_TARGET_POSITION_KEY, true);
            return(true);
        }

        return(false);
    }
Ejemplo n.º 24
0
    public override void Enter(PuppeteerAgent _executingAgent)
    {
        base.Enter(_executingAgent);

        if (!IsValid(_executingAgent))
        {
            return;
        }

        if (_executingAgent.GetWorkingMemory().TryGetValue("LastInRangeExplosionPosition", out var value))
        {
            m_HidingFromExplosionPosition = (Vector3)value;
        }

        if (_executingAgent.TryGetComponent <Animator>(out var animator))
        {
            m_Animator = animator;

            animator.SetTrigger(ANIMATOR_START_DUCKING_KEY);
            animator.SetBool(ANIMATOR_IS_DUCKING_KEY, true);
        }

        m_EndHideAt = ExplosionManager.Instance.GetRandomHideDuration() + Time.time;
    }
Ejemplo n.º 25
0
 public override void Enter(PuppeteerAgent _executingAgent)
 {
     PuppeteerLogger.Log(string.Format("{0} tries to use the PuppeteerDefault action. This won't have any effect.", _executingAgent), Core.Debug.LogType.Warning);
 }
Ejemplo n.º 26
0
 public AgentListItem(PuppeteerAgent _agent)
 {
     m_Agent = _agent;
     m_Text  = m_Agent.gameObject.name;
     Init();
 }