/// <summary>
        /// Determines if the target is valid
        /// </summary>
        /// <returns>A CustomPhysicsHit result of a Line Cast to the target, or a default one if the target is invalid</returns>
        protected virtual MatrixManager.CustomPhysicsHit ValidateTarget()
        {
            if (FollowTarget != null)
            {
                if (mobAI.IsDead == false && mobAI.IsUnconscious == false)
                {
                    var followLivingBehaviour = FollowTarget.GetComponent <LivingHealthMasterBase>();
                    if (followLivingBehaviour != null)
                    {
                        if (followLivingBehaviour.IsDead)
                        {
                            FollowTarget = null;
                        }
                    }

                    //Continue if it still exists and is in range
                    if (FollowTarget != null && TargetDistance() < TetherRange)
                    {
                        Vector3 dir     = (Vector3)(TargetTile.WorldPositionServer - OriginTile.WorldPositionServer).Normalize() / 1.5f;
                        var     hitInfo = MatrixManager.Linecast(OriginTile.WorldPositionServer + dir,
                                                                 LayerTypeSelection.Windows | LayerTypeSelection.Grills, checkMask, TargetTile.WorldPositionServer);

                        if (hitInfo.ItHit)
                        {
                            return(hitInfo);
                        }
                    }
                }
            }

            FollowTarget = null;
            Deactivate();
            return(new MatrixManager.CustomPhysicsHit());
        }
Exemple #2
0
    public void Init()
    {
        if (GameManager.instance.player == null)
        {
            FollowTarget cam = null;
            if (playerCanvasInst == null)
            {
                playerCanvasInst = Instantiate(playerCanvasPrefab);
            }
            if (playerInst == null)
            {
                playerInst = Instantiate(playerPrefab, transform.position, Quaternion.identity);
            }
            if (camInst == null)
            {
                camInst    = Instantiate(cameraPrefab);
                cam        = camInst.GetComponent <FollowTarget>();
                cam.target = playerInst.transform;
                GameManager.instance.player = playerInst;
            }
            Player    player    = playerInst.GetComponent <Player>();
            Character character = playerCanvasInst.GetComponentInChildren <Character>();
            player.character = character;

            cam.GetComponent <PixelPerfectCam>().zoom = PlayerSettings.instance.zoom;
            PlayerSettings.instance.onZoom            = cam.GetComponent <PixelPerfectCam>().ApplyZoom;

            //character.player = player;
            //character.Init();
            //character.gameObject.SetActive(false);
            TInv.UI_Inventory inv = _InventoryManager.instance.playerInventoryUI;
            inv.inventory = player.GetComponent <TInv.InventoryObject>();
            inv.inventory.LoadInventory();
            inv.Refresh();
            DontDestroyOnLoad(playerCanvasInst);
            //playerCanvasInst.GetComponentInChildren<InventoryManager>().player = playerInst.GetComponent<Player>();

            GameManager.instance.canvas = playerCanvasInst.GetComponent <Canvas>();
        }
    }
Exemple #3
0
    void Start()
    {
        if (Canvas == null)
        {
            Debug.LogError("Please set a canvas for health bar.");
        }
        m_SliderRectTransform = m_Slider.GetComponent <Slider>().transform as RectTransform;

        transform.SetParent(Canvas.transform);

        m_ObjectHeight = FollowTarget.GetComponent <MeshRenderer>().bounds.size.y;
        Debug.Log("object height." + m_ObjectHeight);
    }
        void FixedUpdate()
        {
            if (
                Entity.Equals(Entity.Null) ||
                !entityManager.HasComponent <PathAgent>(Entity) ||
                !entityManager.HasComponent <Translation>(Entity) ||
                !entityManager.HasComponent <Rotation>(Entity)
                )
            {
                return;
            }

            var agent = entityManager.GetComponentData <PathAgent>(Entity);

            agent.TypeID = PathUtil.GetAgentType(Type);
            agent.Offset = Offset;

            entityManager.SetComponentData(Entity, agent);

            if (!lastWorldDestination.Equals(WorldDestination))
            {
                entityManager.AddComponentData(Entity, new PathDestination
                {
                    WorldPoint = WorldDestination
                });

                lastWorldDestination = WorldDestination;

                InitializeEntityTransform(); // Reinitialize in case GameObject transform changes in-between pathing.
            }

            gameObject.transform.position = entityManager.GetComponentData <Translation>(Entity).Value;
            gameObject.transform.rotation = entityManager.GetComponentData <Rotation>(Entity).Value;

            if (FollowTarget != null && FollowTarget.GetComponent <PathAgentHybrid>() != null)
            {
                entityManager.AddComponentData(Entity, new PathFollow
                {
                    Target      = FollowTarget.GetComponent <PathAgentHybrid>().Entity,
                    MaxDistance = FollowMaxDistance,
                    MinDistance = FollowMinDistance,
                });
            }
            else if (entityManager.HasComponent <PathFollow>(Entity))
            {
                entityManager.RemoveComponent <PathFollow>(Entity);
            }
        }
        void FixedUpdate()
        {
            if (
                Entity.Equals(Entity.Null) ||
                !entityManager.HasComponent <NavAgent>(Entity) ||
                !entityManager.HasComponent <Parent>(Entity) ||
                !entityManager.HasComponent <Translation>(Entity) ||
                !entityManager.HasComponent <Rotation>(Entity)
                )
            {
                return;
            }

            var agent = entityManager.GetComponentData <NavAgent>(Entity);

            agent.JumpDegrees          = JumpDegrees;
            agent.JumpGravity          = JumpGravity;
            agent.JumpSpeedMultiplierX = JumpSpeedMultiplierX;
            agent.JumpSpeedMultiplierY = JumpSpeedMultiplierY;
            agent.TranslationSpeed     = TranslationSpeed;
            agent.RotationSpeed        = RotationSpeed;
            agent.TypeID = NavUtil.GetAgentType(Type);
            agent.Offset = Offset;

            entityManager.SetComponentData(Entity, agent);

            if (!lastWorldDestination.Equals(WorldDestination))
            {
                entityManager.AddComponentData <NavDestination>(Entity, new NavDestination
                {
                    WorldPoint = WorldDestination,
                    Teleport   = Teleport
                });

                lastWorldDestination = WorldDestination;

                InitializeEntityTransform(); // Reinitialize in case GameObject transform changes in-between pathing.
            }

            var surfaceEntity = entityManager.GetComponentData <Parent>(Entity);

            if (surfaceEntity.Value.Equals(Entity.Null) || !entityManager.HasComponent <NavSurface>(surfaceEntity.Value))
            {
                return;
            }

            surfaceSystem.GameObjectMapTryGetValue(
                entityManager.GetComponentData <NavSurface>(surfaceEntity.Value).TransformInstanceID,
                out var surfaceGameObject
                );

            if (surfaceGameObject == null)
            {
                return;
            }

            gameObject.transform.SetParent(surfaceGameObject.transform);
            gameObject.transform.localPosition = entityManager.GetComponentData <Translation>(Entity).Value / surfaceGameObject.transform.localScale;
            gameObject.transform.localRotation = entityManager.GetComponentData <Rotation>(Entity).Value;

            if (FollowTarget != null && FollowTarget.GetComponent <NavAgentHybrid>() != null)
            {
                entityManager.AddComponentData(Entity, new NavFollow
                {
                    Target      = FollowTarget.GetComponent <NavAgentHybrid>().Entity,
                    MaxDistance = FollowMaxDistance,
                    MinDistance = FollowMinDistance,
                });
            }
            else if (entityManager.HasComponent <NavFollow>(Entity))
            {
                entityManager.RemoveComponent <NavFollow>(Entity);
            }
        }
    private IEnumerator ResetTarget(FollowTarget enemy)
    {
        yield return(new WaitForSeconds(3f));

        enemy.GetComponent <FollowTarget>().SetTarget(mainCharacter.transform, false);
    }