示例#1
0
 public void OnItemActiveChanged(Entity itemEntity, GameObject go, bool isActive, MoveData positionData)
 {
     if (isActive == false)
     {
         EntityActionManager.instance.EntityOnTileChanged(itemEntity, positionData);
         if (go == null)
         {
             return;
         }
         go.SetActive(false);
     }
     else
     {
         if (go == null)
         {
             // Spawn a new one
             go = EntityManager.instance.SpawnEntityGO(itemEntity, positionData);
             // Init Item component with new go
             ItemComponent item = (ItemComponent)itemEntity.GetEntityComponent(ComponentID.Item);
             item.Init(itemEntity, go);
         }
         go.SetActive(true);
         go.transform.position = new Vector2(positionData.X, positionData.Y);
         EntityActionManager.instance.EntityOnTileChanged(itemEntity, positionData);
     }
 }
示例#2
0
    //添加某一类型的组件
    public BasicComponent AddComponent(ComponentType type)
    {
        if (ExistSpecialComponent(type))
        {
            //Debug.Log("Exist same component Type" + type);
            return(GetSpecicalComponent(type));
        }
        //Debug.Log ("Add component" + type + " in " + gameObject);

        PropertyComponent property = GetComponent <PropertyComponent> ();

        switch (type)
        {
        case ComponentType.Property:
            PropertyComponent propertyComp = gameObject.AddComponent <PropertyComponent> ();
            propertyComp.Init(ComponentType.Property, this);
            m_components.Add(propertyComp);
            return(propertyComp);

        case ComponentType.Dead:
            DeadComponent deadComp = gameObject.AddComponent <DeadComponent> ();
            deadComp.Init(ComponentType.Dead, this);
            deadComp.hp = property.HP;
            m_components.Add(deadComp);

            return(deadComp);

        case ComponentType.State:
            StateComponent stateComp = gameObject.AddComponent <StateComponent> ();
            stateComp.Init(ComponentType.State, this);
            m_components.Add(stateComp);
            stateComp.m_actionPoint = property.AP;
            return(stateComp);

        case ComponentType.Ability:
            AbilityComponent abilityComp = gameObject.AddComponent <AbilityComponent> ();
            abilityComp.Init(ComponentType.Ability, this);
            m_components.Add(abilityComp);
            return(abilityComp);

        case ComponentType.Hide:
            HideComponent hideComp = gameObject.AddComponent <HideComponent> ();
            hideComp.Init(ComponentType.Hide, this);
            m_components.Add(hideComp);
            return(hideComp);

        case ComponentType.Move:
            MoveComponent moveComp = gameObject.AddComponent <MoveComponent> ();
            moveComp.Init(ComponentType.Move, this);
            m_components.Add(moveComp);
            moveComp.moveSpeed = property.moveSpd;
            moveComp.SPD       = property.SPD;
            return(moveComp);

        case ComponentType.Attack:
            AttackComponent attackComp = gameObject.AddComponent <AttackComponent> ();
            attackComp.Init(ComponentType.Attack, this);
            m_components.Add(attackComp);
            attackComp.STR = property.STR;
            return(attackComp);

        case ComponentType.Input:
            InputComponent inputComp = gameObject.AddComponent <InputComponent> ();
            inputComp.Init(ComponentType.Input, this);
            m_components.Add(inputComp);
            return(inputComp);

        case ComponentType.CheerUp:
            CheerUpComponent cheerUpComp = gameObject.AddComponent <CheerUpComponent> ();
            cheerUpComp.Init(ComponentType.CheerUp, this);
            m_components.Add(cheerUpComp);
            return(cheerUpComp);

        case ComponentType.Monitor:
            MonitorComponent monitorComp = gameObject.AddComponent <MonitorComponent> ();
            monitorComp.Init(ComponentType.Monitor, this);
            m_components.Add(monitorComp);
            monitorComp.m_SightArea = property.HRZ;
            return(monitorComp);

        case ComponentType.Knock:
            KnockComponent knockComp = gameObject.AddComponent <KnockComponent> ();
            knockComp.Init(ComponentType.Knock, this);
            m_components.Add(knockComp);
            knockComp.m_ridus = property.HRZ;
            return(knockComp);

        case ComponentType.Item:
            ItemComponent itemComp = gameObject.AddComponent <ItemComponent> ();
            itemComp.Init(ComponentType.Item, this);
            itemComp.item     = property.item;
            itemComp.numLimit = property.itemLimit;
            m_components.Add(itemComp);
            return(itemComp);

        case ComponentType.AI:
            AIComponent aiComp = gameObject.AddComponent <AIComponent> ();
            aiComp.Init(ComponentType.AI, this);
            m_components.Add(aiComp);
            return(aiComp);

        case ComponentType.UI:
            UIComponent uiComp = gameObject.AddComponent <UIComponent>();
            uiComp.Init(ComponentType.UI, this);
            m_components.Add(uiComp);
            return(uiComp);

        default:
            return(null);
        }
    }