コード例 #1
0
    public void SetUp(LocalPlayerProperty _data, int _i)
    {
        OnCreate?.Invoke(_i);

        rigid            = gameObject.GetComponent <Rigidbody2D>();
        listeners        = gameObject.GetComponent <PhysicsControlListeners>();
        actionController = gameObject.GetComponent <ActionController>();
        SetUpLocalEvent();
        dataIndex = _i;

        Head _newHead =
            Instantiate(
                Head.LoadHead(PlayerSlot.heads_res[(int)_data.playerProperty[CustomPropertyCode.HEAD_CDOE]].name).gameObject,
                head.transform.position,
                Quaternion.identity,
                head.transform.parent
                ).GetComponent <Head>();
        Body _newBody =
            Instantiate(
                //Body.LoadBody(_data.playerProperty[CustomPropertyCode.BODY_CODE] as string).gameObject,
                Body.LoadBody(PlayerSlot.body_res[(int)_data.playerProperty[CustomPropertyCode.BODY_CODE]].name).gameObject,
                body.transform.position,
                Quaternion.identity,
                body.transform.parent
                ).GetComponent <Body>();

        Destroy(head.gameObject);
        Destroy(body.gameObject);

        head = _newHead;
        body = _newBody;
        body.GetComponent <PlayerAttackControl>()._player = this;
        head.ApplyBuff();

        //********Set Keys *****************
        SetKey(_i);


        //set team Layer
        //gameObject.layer = LayerMask.NameToLayer("Player" + _data.playerProperty[CustomPropertyCode.TEAM_CODE]);
        gameObject.layer = LayerMask.NameToLayer("Player" + _data.playerProperty[CustomPropertyCode.TEAM_LAYER]);

        int _team_code = (int)_data.playerProperty[CustomPropertyCode.TEAM_CODE];

        Debug.Log("set Team color " + CustomPropertyCode.TEAMCOLORS[_team_code] + " " + _team_code);

        //set team color
        head.GetComponent <SpriteRenderer>().color = CustomPropertyCode.TEAMCOLORS[_team_code];
        body.GetComponent <SpriteRenderer>().color = CustomPropertyCode.TEAMCOLORS[_team_code];

        //Landing animation  (called by manager)
        //AddLanding();
        //Test:
        //AddRevive();
    }
コード例 #2
0
    int jump_count = 0; //跳躍次數 (for 2段跳)
    private void Start()
    {
        rigid        = gameObject.GetComponent <Rigidbody2D>();
        listeners    = gameObject.GetComponent <PhysicsControlListeners>();
        animator     = gameObject.GetComponent <Animator>();
        playerAttack = gameObject.GetComponent <PlayerAttackControl>();
        sp           = gameObject.GetComponent <SpriteRenderer>();

        hitable = gameObject.GetComponent <HitableObj>();
        if (hitable != null)
        {
            hitable.Die_event    += Die;
            hitable.gotHit_event += Hurt;
        }

        listeners.eOnTouchGround += ResetJumpCount;
    }
コード例 #3
0
 private void SetUpLocalEvent()
 {
     hitable   = gameObject.GetComponent <HitableObj>();
     listeners = gameObject.GetComponent <PhysicsControlListeners>();
     if (actionController != null)
     {
         actionController.eActionQueueCleared += AddDefault;
     }
     if (hitable != null)
     {
         hitable.Die_event += AddDie;
         //hitable.gotHit_event += Hurt;
         //hitable.gotHit_event += OnHurt;
         hitable.HitBy_event += OnHurt;
         //hitable.HitBy_event += HurtDirectionCheck;
     }
     if (listeners != null)
     {
         listeners.eOnTouchGround += ResetJumpCount;
         listeners.eOnTouchGround += OnJumpEnd;
     }
 }
コード例 #4
0
    public void SetUpOnline(int _playerIndex)
    {
        OnCreate?.Invoke(_playerIndex);
        _pv     = GetComponent <PhotonView>();
        hitable = gameObject.GetComponent <HitableObj>();
        if (_pv == null)
        {
            return;
        }
        _isOnline = true;
        dataIndex = _playerIndex;
        Debug.Log("player index " + dataIndex);

        if (!_pv.IsMine)
        {
            //Destroy(GetComponent<PhysicsControlListeners>());
            Destroy(GetComponent <Rigidbody2D>());
            Destroy(GetComponent <ActionController>());
            //Destroy(body.GetComponent<PlayerAttackControl>());
            //Destroy(this);
        }
        else
        {
            //if (_hasInited){return;}
            //_hasInited = true;

            rigid            = gameObject.GetComponent <Rigidbody2D>();
            listeners        = gameObject.GetComponent <PhysicsControlListeners>();
            actionController = gameObject.GetComponent <ActionController>();
            _otherPlayers    = GetOtherPlayer();
            SetUpLocalEvent();

            string _head_path = "Prefab/Online/Head/" + PlayerSlot.heads_res[(int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.HEAD_CDOE]].name;
            string _body_path = "Prefab/Online/Body/" + PlayerSlot.body_res[(int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.BODY_CODE]].name;
            Head   _newHead   =
                PhotonNetwork.Instantiate(
                    _head_path,
                    //Instantiate(
                    //Resources.Load<Head>(_head_path),
                    head.transform.position,
                    Quaternion.identity
                    ).GetComponent <Head>();
            Body _newBody =
                PhotonNetwork.Instantiate(
                    _body_path,
                    //Instantiate(
                    //Resources.Load<Body>(_body_path),
                    body.transform.position,
                    Quaternion.identity
                    ).GetComponent <Body>();

            //_newBody.transform.SetParent(body.transform.parent);
            _newBody.transform.SetParent(transform);
            _newHead.transform.SetParent(transform);
            //_newHead.transform.SetParent(head.transform.parent);
            Destroy(head.gameObject);
            Destroy(body.gameObject);

            head = _newHead;
            body = _newBody;
            RpcSetUPParent();
            _pv.RPC("RpcSetupTeam", RpcTarget.All,
                    (int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.TEAM_CODE],
                    (int)PhotonNetwork.LocalPlayer.CustomProperties[CustomPropertyCode.TEAM_LAYER]);

            SetKey(0);

            SetupRpcFunction();
            //temp
            //AddLanding();
        }
    }