Esempio n. 1
0
 void OnCollisionEnterasd(Collision other)
 {
     if (rb != null)                         //TODO: this if statement is temporary, not a real solution
     {
         if (Spawner != null)
         {
             if (other.transform.tag == "Unit") //&& other.gameObject != Spawner && other.GetType() == typeof(BoxCollider) && OnDifferentTeam(other.gameObject)){
             {
                 if (other.gameObject != Spawner && other.GetType() == typeof(BoxCollider) && OnDifferentTeam(other.gameObject))
                 {
                     GameObject hitUnit = other.gameObject;
                     Cube       hitCube = hitUnit.GetComponent <Cube>();
                     hitCube.TakeDamage(damage, rb.velocity);
                     Rigidbody hitRig = hitUnit.GetComponent <Rigidbody>();
                     hitRig.AddForce(rb.velocity.normalized * impactForce, ForceMode.Impulse);
                     CubePool.AddToLaserPool(gameObject);
                 }
             }
         }
         if (other.transform.tag == "Laser" && OnDifferentTeam(other.gameObject))
         {
             LaserCollision(other.gameObject);
         }
     }
 }
Esempio n. 2
0
    public void InitPool()
    {
        //设置实例
        if (poolInstance == null)
        {
            poolInstance = this;
        }
        else
        {
            Destroy(this);
        }
        // DontDestroyOnLoad(this);
        //设置载体
        if (poolParent == null)
        {
            Debug.Log("需要设置poolParent");
            return;
        }

        //初始化数据
        poolAmount  = objectPrefabs.Length;
        objectIndex = 0;
        lockPool    = false;


        objects = new List <GameObject>();
        for (int i = 0; i < poolAmount; i++)
        {
            objects.Add(Instantiate(objectPrefabs[i], poolParent.transform));
            objects[i].SetActive(false);
        }
    }
Esempio n. 3
0
 void Despawn()
 {
     if (Time.time > spawnTime + DespawnTime)
     {
         CubePool.AddToLaserPool(gameObject);
     }
 }
Esempio n. 4
0
    void LaserCollisionOld(GameObject other)
    {
        print("BROKEN");
        gameObject.GetComponent <BoxCollider>().enabled  = false;
        gameObject.GetComponent <MeshRenderer>().enabled = false;
        GameObject        deathCube  = (GameObject)Resources.Load("DeathCube");
        List <GameObject> cubes      = new List <GameObject>();
        float             cubeAmount = gameObject.transform.localScale.z / 0.25f;

        cubeAmount = cubeAmount / cubeAmountMod;
        deathCube.transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, 0.25f);
        deathCube.GetComponent <MeshRenderer>().material = GetComponent <MeshRenderer>().material;
        float   startZ        = transform.position.z - (transform.localScale.z / 2);
        Vector3 startPosition = new Vector3(transform.position.x, transform.position.y, startZ);
        Vector3 additive      = new Vector3(0, 0, 0);

        for (int i = 0; i < cubeAmount; i++)
        {
            cubes.Add((GameObject)Instantiate(deathCube, startPosition + additive, Quaternion.identity));
            additive += new Vector3(0, 0, 0.25f * cubeAmountMod);
        }
        foreach (GameObject cube in cubes)
        {
            if (rb != null)
            {
                cube.GetComponent <Rigidbody>().AddForce(rb.velocity * 10);
            }
        }
        GetComponent <BoxCollider>().enabled = false;
        CubePool.AddToLaserPool(gameObject);
    }
Esempio n. 5
0
 void OnTriggerExit(Collider other)
 {
     if (other.GetType() == typeof(BoxCollider))         //TODO: make add to pool instead of destroy
     //CubePool.AddToPool(other.gameObject);
     {
         CubePool.AddToPool(other.gameObject);
     }
 }
Esempio n. 6
0
 void GetCubes()
 {
     deathSubs = new List <GameObject>();
     for (int i = 0; i < particleCount; i++)
     {
         deathSubs.Add(CubePool.RemoveFromPool());
     }
 }
Esempio n. 7
0
 public void GetSubCubes(int subCount)
 {
     subCubes = new List <GameObject>();
     for (int i = 0; i < subCount; i++)
     {
         subCubes.Add(CubePool.RemoveFromPool());
     }
     //gameObject.SetActive(false);
 }
Esempio n. 8
0
 private void MakeSingleton()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Esempio n. 9
0
    private void Awake()
    {
        cubePoolInstance = this;
        poolObjects      = new List <GameObject>();

        for (int i = 0; i < poolSize; i++)
        {
            GameObject obj = Instantiate(cubePrefab);
            obj.SetActive(false);
            poolObjects.Add(obj);
        }
    }
Esempio n. 10
0
    void LaserCollision(GameObject other)
    {
        //gameObject.GetComponent <MeshRenderer>().enabled = false;
        Vector3 vel = rb.velocity;

        gameObject.GetComponent <BoxCollider>().enabled = false;
        GetCubes();
        SetupSubs();
        EnableSubs();
        PrepDeathSubCube();
        AddVelocityToSubs(vel);

        CubePool.AddToLaserPool(gameObject);
    }
Esempio n. 11
0
    void SetupLaser(Quaternion direction)
    {
        laser = CubePool.RemoveFromLaserPool();
        Laser laserProp = laser.GetComponent <Laser>();

        laserProp.SetTeam(cube.teamNumber);   //TODO: make method for this
        laserProp.SetSpawner(gameObject);
        laser.transform.position                    = transform.position;
        laser.transform.rotation                    = direction;
        laser.GetComponent <Laser>().enabled        = true;
        laser.GetComponent <MeshRenderer>().enabled = true;
        laser.GetComponent <BoxCollider>().enabled  = true;
        laser.SetActive(true);
    }
Esempio n. 12
0
    void Start()
    {
        #region Sample
        var cubePool = new CubePool(transform, m_pCubePrefab);

        m_btn.OnClickAsObservable().Subscribe(_ =>
        {
            var cube = cubePool.Rent();
            Observable.Interval(TimeSpan.FromSeconds(5)).First().Subscribe(x =>
            {
                cubePool.Return(cube);
            });
        }).AddTo(this);
        #endregion
    }
Esempio n. 13
0
    public void addCube(VectorInt3 point, Color c)
    {
        Cube cube = null;

        if (_cubes.ContainsKey(point))
        {
            cube = _cubes [point];
        }
        else
        {
            cube = CubePool.GetInstance().create();
            cube.transform.parent = this.transform;
            cube.gameObject.SetActive(true);
            _cubes [point] = cube;
        }

        Debug.Log(unit_ + "ace");
        cube.setup(point, c, unit_);
    }
Esempio n. 14
0
 // Update is called once per frame
 void Update()
 {
     time       = System.DateTime.Now;
     timer.text = "UTC: " + time.Hour + ":" + time.Minute + ":" + time.Second;
     if (time.Second >= nextActionTime && (int)time.Second % 2 == 0)
     {
         nextActionTime = time.Second + period;
         if (CubePool.GenerateCube != null)
         {
             CubePool.GenerateCube();
         }
         if (time.Second > 2)
         {
             reset = false;
         }
     }
     else if (!reset && time.Second == 0)
     {
         nextActionTime = 0.0f;
         reset          = true;
     }
 }
Esempio n. 15
0
    void Death(Vector3 vel = default(Vector3))
    {
        gameObject.GetComponent <BoxCollider>().enabled  = false;
        gameObject.GetComponent <MeshRenderer>().enabled = false;
        float   newScale       = transform.localScale.x / 2;
        Vector3 newVectorScale = transform.localScale / 2;

        GetSubCubes(8);
        PrepSubCubesDefaults();
        if (newScale < 1)
        {
            PrepDeathSubCube();
        }
        else
        {
            PrepRegularSubCube();
        }
        PositionSubCubes(newScale);
        EnableSubCubes();
        GiveSubsVelocity(vel);
        GiveSubsTarger();
        CubePool.AddToPool(gameObject);
    }
Esempio n. 16
0
 void Spawn()
 {
     unit = CubePool.RemoveFromPool();
     SetupAndEnable();
 }
Esempio n. 17
0
 void Start()
 {
     cubePool = new CubePool(cubePrefab);
     cubePool.PreloadAsync(10, 1).Subscribe();
 }
Esempio n. 18
0
 void Awake()
 {
     CubePool.instance_ = this;
     pool_.init(createPrototype());
 }