예제 #1
0
    void RpcAddAbility(AbilityTypes type, int viewID)
    {
        var prefab = _data.GetAbilityPrefab(type);

        if (!prefab)
        {
            return;
        }

        var obj = Instantiate(prefab);

        obj.transform.parent        = transform;
        obj.transform.position      = transform.position;
        obj.transform.localRotation = Quaternion.Euler(0, 0, 0);
        var comp = obj.GetComponent <Ability>();

        if (!comp)
        {
            Destroy(obj);
            return;
        }

        obj.name = comp.AbilityName;

        if (Abilities == null)
        {
            Abilities = new Dictionary <TribotInput.InputButtons, Ability>();
        }

        if (Abilities.ContainsKey(comp.MappedButton))
        {
            var oldAbility = Abilities[comp.MappedButton];
            Abilities[comp.MappedButton] = comp;

            if (oldAbility != null)
            {
                Destroy(oldAbility.gameObject);
            }
        }
        else
        {
            Abilities.Add(comp.MappedButton, comp);
        }
        comp.PlayerState  = _state;
        comp.PlayerIndex  = Index;
        comp.CastCallBack = CastEvent;

        var view = obj.AddComponent <PhotonView>();

        view.viewID = viewID;
    }