示例#1
0
    private void Start()
    {
        _camp = GameObject.Find("InitializeController").GetComponent <Initialize>().Camp;
        GameBody.GetComponent <SpriteRenderer>().color = _camp;
        Interact.GetComponent <InteractController>().InteractAreaColor = _camp;
        Interact.GetComponent <InteractController>().InteractCollider.GetComponent <ColliderController>().Camp = _camp;
        BodyCollider.GetComponent <ColliderController>().Camp = _camp;
        StateBar statebar = Info.GetComponent <StateBar>();

        _health = PlayerConfig._TotalHealth;
        _energy = PlayerConfig._TotalEnergy;
        statebar.TotalHealth   = _health;
        statebar.TotalEnergy   = _energy;
        statebar.CurrentEnergy = _energy;
        statebar.CurrentHealth = _health;
        GameObject.Find("Collector").GetComponent <Collector>().Player = gameObject;
        Vector3 CP = new Vector3();

        CP   = transform.position;
        CP.z = -10;
        Camera.main.transform.position = CP;
        WS = GameObject.Find("WebSocketController").GetComponent <WebSocketController>();
        PP = new MessageBox.PlayerPosition();
        MB = new MessageBox.MessageBase();
    }
示例#2
0
    private void Shoot()
    {
        if (OwnController.Info.GetComponent <StateBar>().CurrentEnergy >= 10)
        {
            GameObject bullet = Instantiate(Bullet, transform.position, transform.rotation);
            bullet.GetComponent <BulletController>().Damage = _damage;
            bullet.GetComponent <BulletController>().Speed  = _bulletSpeed;
            //OwnController.Info.GetComponent<StateBar>().ConsumeEnergy(10);
            BulletController bulletController = bullet.GetComponent <BulletController>();
            bulletController.target         = Target.GetComponent <ColliderController>().GameBody;
            bulletController.targetCollider = Target;
            bulletController.isShoot        = true;
            bulletController.Camp           = OwnController.Camp;

            MessageBox.MessageBase MB = new MessageBox.MessageBase();
            MB.Type = "SendBulletMessage";
            MessageBox.Position SP = new MessageBox.Position
            {
                x = transform.position.x,
                y = transform.position.y
            };
            MessageBox.SendBulletMessage SBM = new MessageBox.SendBulletMessage();
            SBM.ShooterID     = OwnController.id;
            SBM.StartPosition = JsonUtility.ToJson(SP);
            SBM.TargetID      = Target.gameObject.GetComponent <OtherObjectController>().id;
            MB.Message        = JsonUtility.ToJson(SBM);
            WS.Send(JsonUtility.ToJson(MB));
        }
    }
示例#3
0
 public void CreateMessageAndSend()
 {
     MessageBox.MessageBase MB = new MessageBox.MessageBase();
     MB.Type = "ChangeStateBar";
     MessageBox.ChangeStateBar CSB = new MessageBox.ChangeStateBar
     {
         id     = id,
         Health = _CurrentHealth,
         Energy = _CurrentEnergy,
         Shield = _CurrentShield
     };
     MB.Message = JsonUtility.ToJson(CSB);
     WS.Send(JsonUtility.ToJson(MB));
 }
示例#4
0
    // Use this for initialization
    void Awake()
    {
        MessageBase            = new MessageBox.MessageBase();
        InitializeMessage      = new MessageBox.InitializeMessage();
        OtherInitializeMessage = new MessageBox.OtherInitializeMessage();
        PlayerPosition         = new MessageBox.PlayerPosition();
        BulletMessage          = new MessageBox.BulletMessage();
        ChangeStateBar         = new MessageBox.ChangeStateBar();
        BuildMessage           = new MessageBox.BuildMessage();
        Collector  = GameObject.Find("Collector").GetComponent <Collector>();
        Initialize = GameObject.Find("InitializeController").GetComponent <Initialize>();
        Debug.Log("start connect");
        SocketConnect("ws://192.168.0.106:2222");
        Debug.Log("connect done");

        Bullet = Resources.Load <GameObject>("Prefabs/OtherBullet");
    }