Ejemplo n.º 1
0
        public T GetAttribute <T>(Type type) where T : Attribute
        {
            T attribute;

            Type metadataType = XBaseTypes.GetAssociatedMetadataType(type);

            if (metadataType != null)
            {
                attribute = XAttributes.GetAttribute <T>(metadataType, true);
                if (attribute != null)
                {
                    return(attribute);
                }
            }

            attribute = XAttributes.GetAttribute <T>(type, true);
            if (attribute != null)
            {
                return(attribute);
            }

            foreach (Type typeInterface in type.GetInterfaces())
            {
                attribute = XAttributes.GetAttribute <T>(typeInterface, true);
                if (attribute != null)
                {
                    return(attribute);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
    public XRole CreateTestRole()
    {
        XAttributes attr = InitAttrFromClient(2);

        attr.AppearPostion    = Vector3.zero;
        attr.AppearQuaternion = Quaternion.identity;
        return(PrepareEntity <XRole>(attr));
    }
Ejemplo n.º 3
0
 public void UnloadEntity()
 {
     OnUnintial();
     _attr = null;
     XResources.Destroy(_object);
     _object = null;
     DetachAllComponents();
     base.Unload();
 }
Ejemplo n.º 4
0
    private void InitVariables()
    {
        XAttributes attr = _entity.Attributes;

        _normal_attack_prob = attr.NormalAttackProb;
        _enter_fight_range  = attr.EnterFightRange;
        _tick               = attr.AIActionGap;
        _is_fixed_in_cd     = attr.IsFixedInCD;
        _fight_together_dis = attr.FightTogetherDis;
    }
Ejemplo n.º 5
0
    public XNPC CreateNPC(XNpcList.RowData row, Vector3 pos, Quaternion rot)
    {
        XAttributes attr = InitAttrByPresent(row.PresentID);

        attr.AppearPostion    = pos;
        attr.AppearQuaternion = rot;
        var e = PrepareEntity <XNPC>(attr);

        Add(EntityType.Npc, e);
        return(e);
    }
Ejemplo n.º 6
0
    public XEntity CreateEntity <T>(uint staticid, Vector3 pos, Quaternion rot) where T : XEntity
    {
        XAttributes attr = InitAttrFromClient((int)staticid);

        attr.AppearPostion    = pos;
        attr.AppearQuaternion = rot;
        XEntity e = PrepareEntity <T>(attr);

        Add(EntityType.Entity, e);
        return(e);
    }
Ejemplo n.º 7
0
 public void Initilize(GameObject o, XAttributes attr)
 {
     base.Initilize();
     _object    = o;
     _transf    = o.transform;
     _attr      = attr;
     _present   = XTableMgr.GetTable <XEntityPresentation>().GetItemID(_attr.PresentID);
     components = new Dictionary <uint, XComponent>();
     anim       = AttachComponent <XAnimComponent>();
     OnInitial();
     InitAnim();
 }
Ejemplo n.º 8
0
    private XAttributes InitAttrByPresent(uint presentID)
    {
        XAttributes attr = new XAttributes();
        var         prow = XTableMgr.GetTable <XEntityPresentation>().GetItemID(presentID);

        if (prow == null)
        {
            throw new Exception("present is nil with id: " + presentID);
        }
        attr.Prefab    = prow.Prefab;
        attr.id        = (uint)XCommon.singleton.New_id;
        attr.PresentID = presentID;
        attr.Name      = prow.Name;
        return(attr);
    }
Ejemplo n.º 9
0
    public XPlayer CreatePlayer()
    {
        SceneList.RowData row   = XScene.singleton.SceneRow;
        int         statisticid = 2;
        XAttributes attr        = InitAttrFromClient(statisticid);
        string      s           = row.StartPos;

        string[] ss = s.Split('=');
        float[]  fp = new float[3];
        float.TryParse(ss[0], out fp[0]);
        float.TryParse(ss[1], out fp[1]);
        float.TryParse(ss[2], out fp[2]);
        attr.AppearPostion    = new Vector3(fp[0], fp[1], fp[2]);
        attr.AppearQuaternion = Quaternion.Euler(row.StartRot[0], row.StartRot[1], row.StartRot[2]);
        Player = PrepareEntity <XPlayer>(attr);
        return(Player);
    }
Ejemplo n.º 10
0
    private T PrepareEntity <T>(XAttributes attr) where T : XEntity
    {
        T          x = Activator.CreateInstance <T>();
        GameObject o = XResources.LoadInPool("Prefabs/" + attr.Prefab);

        o.name = attr.id.ToString();
        o.transform.position = attr.AppearPostion;
        o.transform.rotation = attr.AppearQuaternion;
        x.Initilize(o, attr);
        if (!_dic_entities.ContainsKey(attr.id) && !x.IsPlayer)
        {
            _dic_entities.Add(attr.id, x);
        }
        if (!_hash_entitys.Add(x) && !x.IsPlayer)
        {
            XDebug.Log("has exist entity: ", attr.id);
        }
        SetRelation <T>(x);
        return(x);
    }
Ejemplo n.º 11
0
    private XAttributes InitAttrFromClient(int statisticid)
    {
        var srow = XTableMgr.GetTable <XEntityStatistics>().GetByID(statisticid);

        if (srow == null)
        {
            throw new Exception("entity is nil with id: " + statisticid);
        }
        XAttributes attr = new XAttributes();
        var         prow = XTableMgr.GetTable <XEntityPresentation>().GetItemID(srow.PresentID);

        if (prow == null)
        {
            throw new Exception("present is nil with id: " + srow.PresentID);
        }
        attr.Prefab    = prow.Prefab;
        attr.id        = (uint)XCommon.singleton.New_id;
        attr.PresentID = srow.PresentID;
        attr.Name      = prow.Name;
        attr.InitAttribute(srow);
        return(attr);
    }