コード例 #1
0
 public override void Init(Entity entity, GameObject entityGO)
 {
     thisEntity = entity;
     position   = (PositionComponent)thisEntity.GetEntityComponent(ComponentID.Position);
     AiStateSystem.instance.RegisterAi(DoNextAction);
     actionManager = EntityActionManager.instance;
     thisEntity.OnActiveChanged += (active) => AiStateSystem.instance.UnRegisterAi(DoNextAction);
     thisEntity.OnActiveChanged += (active) => actionManager.EntityOnTileChanged(thisEntity, position.moveData);
 }
コード例 #2
0
ファイル: ItemManager.cs プロジェクト: smwolfskill/Lumiere
    private Entity getCollidingEntity(Collider2D collider)
    {
        GameObject          collidingObj        = collider.gameObject;
        EntityActionManager entityActionManager = collidingObj.GetComponent <EntityActionManager>();

        if (entityActionManager != null)
        {
            return(entityActionManager.entity);
        }
        return(null);
    }
コード例 #3
0
 public void Init()
 {
     SettingsManager.LoadSettings(""); //will load default settings since loading from file "" will fail
     player = new GameObject("Player", typeof(BoxCollider2D));
     entityActionManager        = player.AddComponent <EntityActionManager>();
     playerMove                 = Resources.Load <EntityAction>("PlayerMove");
     rigidbody                  = null;
     playerObj                  = Player.CreateInstance <Player>();
     playerObj.actions          = new EntityAction[] { playerMove };
     entityActionManager.entity = playerObj;
     Assert.IsNotNull(playerMove);
     Assert.IsNotNull(player.GetComponent <BoxCollider2D>());
 }
コード例 #4
0
    public void Init()
    {
        monster             = new GameObject("Monster", typeof(BoxCollider2D));
        entityActionManager = monster.AddComponent <EntityActionManager>();
        randomMove          = Resources.Load <EntityAction>("RandomMove");
        rigidbody           = null;

        monsterObject              = Monster.CreateInstance <Monster>();
        monsterObject.actions      = new EntityAction[] { randomMove };
        entityActionManager.entity = monsterObject;

        monster.SetActive(false);
        Assert.IsNotNull(randomMove);
        Assert.IsNotNull(monster.GetComponent <BoxCollider2D>());
    }
コード例 #5
0
    public override void Init(Entity entity, GameObject entityGO)
    {
        if (entityGO == null)
        {
            return;
        }

        OnInputNeeded = AbilitySystem.instance.IsInputNeeded;
        RegisterCBListener <Action <MoveData> >((data) => MoveSystem.instance.ChangePosition(data, entityGO.transform));
        CanMoveTo     = MapManager.instance.CanMoveTo;
        thisEntity    = entity;
        actionManager = EntityActionManager.instance;
        actionManager.EntityOnTileChanged(thisEntity, moveData);
        //thisEntity.OnActiveChanged += ClearCB;
    }
コード例 #6
0
ファイル: PickupItem.cs プロジェクト: smwolfskill/Lumiere
    /// <summary>
    /// Checks whether the player can pick up an item from the ground.
    /// </summary>
    /// <param name="obj">The Player's GameObject that wants to execute this action.</param>
    /// <returns>Return false if no item clicked upon, or player not in range of the object.</returns>
    public override bool Validate(GameObject obj)
    {
        //TODO: prevent player picking up items while inventory is open.
        //There is also an infinite loop bug if attempting to move while inventory is open.

        bool pickupItemInput = Input.GetKeyDown(SettingsManager.GetPickupItem());
        bool clickedOnItem   = false;

        if (pickupItemInput)
        {
            //Still uses mouse click because otherwise cannot know which item(s) in radius to pickup!
            //Gather 3D mouse position and raycasting information
            Ray     ray               = Camera.main.ScreenPointToRay(Input.mousePosition);
            Vector3 origin            = obj.transform.position; //location of the object (player)
            Vector3 worldPointClicked = Camera.main.ScreenToWorldPoint(Input.mousePosition);

            //Convert to 2D and detect any raycast hits on 2D colliders
            Ray2D        ray2D = new Ray2D(new Vector2(ray.origin.x, ray.origin.y), new Vector2(ray.direction.x, ray.direction.y));
            RaycastHit2D hit2D = Physics2D.Raycast(ray2D.origin, ray2D.direction);
            if (hit2D.collider != null)
            {
                itemObj     = hit2D.collider.gameObject;
                itemManager = itemObj.GetComponent <ItemManager>();
                if (itemManager != null)     //hit an item on the ground
                {
                    BoxCollider2D objCollider = obj.GetComponent <BoxCollider2D>();
                    float         dist        = Physics2D.Distance(objCollider, hit2D.collider).distance;
                    if (dist <= 0.0f)    //within collision range (so within pickup range)
                    {
                        toPickup = itemManager.item;
                        EntityActionManager actionManager = obj.GetComponent <EntityActionManager>();
                        target        = actionManager.entity; //player
                        clickedOnItem = true;
                    }
                }
            }
        }
        return(clickedOnItem);
    }
コード例 #7
0
ファイル: Player.cs プロジェクト: smwolfskill/Lumiere
    override public GameObject Spawn(Map map, Vector2 location)
    {
        GameObject player = base.Spawn(map, location);

        player.tag   = "Player";
        player.layer = LayerMask.NameToLayer("Player");

        Animator anim = player.AddComponent <Animator>();

        anim.runtimeAnimatorController = animatorController;
        MovementAnimation moveAnim = player.AddComponent <MovementAnimation>();

        AttackAnimationObject = CreateAttackAnimGameObject();
        AttackAnimationObject.transform.SetParent(player.transform);
        AttackAnimationObject.transform.localPosition = Vector3.zero;

        EntityActionManager actionManager = player.AddComponent <EntityActionManager>();

        actionManager.entity = this;
        PlayerObject entityObj = new PlayerObject(player, maxHealth);

        this.entityObject       = entityObj;
        entityObj.entityDropGen = entityDropGen;
        EntityHealthManager healthManagerTest = player.GetComponent <EntityHealthManager>();

        if (healthManagerTest == null)
        {
            EntityHealthManager healthManager = player.AddComponent <EntityHealthManager>();
            healthManager.entityObj = entityObj;
        }
        else
        {
            healthManagerTest.entityObj = this.entityObject;
        }
        player.AddComponent <EntityObjectManager>().entityObject = entityObj;


        return(player);
    }
コード例 #8
0
ファイル: Entity.cs プロジェクト: OutOfHandGames/PROMNight
	// Use this for initialization
	public void Start () {
		isMoving = false;
		target = Vector3.zero;
		hasPerformedAction = false;
        entityActionManager = GetComponent<EntityActionManager>();
	}
コード例 #9
0
 private void Awake()
 {
     instance = this;
 }