public int AddSpine(SpineAnimator sa)
 {
     roots[numJobs] = numBones;
     transforms.Add(sa.gameObject.transform);
     damping[numJobs]   = sa.damping;
     boneCount[numJobs] = sa.children.Count + 1;
     for (int i = 0; i < sa.children.Count; i++)
     {
         transforms.Add(sa.children[i]);
         offsets[numBones + i + 1] = sa.offsets[i]; // No offset for the 0th
     }
     numJobs++;
     numBones += sa.children.Count + 1;
     return(numJobs - 1);
 }
Beispiel #2
0
        private void Awake()
        {
            movement = GetComponent <Movement>();
            matching = GetComponent <Matching>();

            playerPool = new PlayerPool(prefab);
            transforms = new TransformAccessArray(4, 2);

            for (var i = 0; i < 4; i++)
            {
                var rent = playerPool.Rent();
                var trs  = rent.transform;

                rent.index = i;
                transforms.Add(trs);
            }

            matching
            .JoinClientAsObservable
            .Subscribe(index =>
            {
                Debug.Log(index.ToString());

                for (var i = 0; i < transforms.capacity; i++)
                {
                    var trs = transforms[i];

                    if (trs.GetComponent <IdentifierComponent>().index != index)
                    {
                        continue;
                    }

                    player = trs;
                    trs.gameObject.AddComponent <PlayerController>();
                    transforms.RemoveAtSwapBack(i);
                    break;
                }
            });

            matching
            .LeaveClientAsObservable
            .Subscribe(x =>
            {
                var go = player.gameObject;
                Destroy(go.GetComponent <PlayerController>());
                transforms.Add(player);
            });
        }
 public void Add(GameObject sway)
 {
     transforms.capacity = transforms.length + 1;
     transforms.Add(sway.transform);
     theta[numJobs] = 0;
     numJobs++;
 }
Beispiel #4
0
        void Start()
        {
            // 修改为符合Jobs要求的数据结构
            m_FishVels       = new NativeArray <Vector3>(amountOfFish, Allocator.Persistent);
            m_TrsAccessArray = new TransformAccessArray(amountOfFish);
            m_FishRotTimes   = new NativeArray <float>(amountOfFish, Allocator.Persistent);

            for (int i = 0; i < amountOfFish; i++)
            {
                // 在规定边界范围内随机生成鱼
                var trsFish = (Transform)Instantiate(objectPrefab,
                                                     transform.position + new Vector3(
                                                         UnityEngine.Random.Range(-spawnBounds.x / 2, spawnBounds.x / 2),
                                                         0,
                                                         UnityEngine.Random.Range(-spawnBounds.z / 2, spawnBounds.z / 2)),
                                                     Quaternion.identity);


                // 在用JobsParallelForTransform的情况下,transform不能有parent,否则都会被视为一个transform来处理,无法分别运行在多个核上
                // 详情见:https://forum.unity.com/threads/jobs-performance-questions.520406/
                //trsFish.parent = this.transform;
                m_TrsAccessArray.Add(trsFish);
                m_FishRotTimes[i] = Random.Range(1f, 5f);
                m_FishVels[i]     = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f));
            }
        }
Beispiel #5
0
        public void Expand(int _count)
        {
            if (!AssetOnly)
            {
                var name           = asset.name;
                var writeIntoArray = transformAccess.isCreated;

                for (int i = 0; i < _count; ++i)
                {
                    var newObject = GameObject.Instantiate(asset, root);
                    newObject.SetActive(false);
                    newObject.name = string.Concat(name, '_', totalCount);
#if UNITY_EDITOR
                    newObject.hideFlags = hideInEditor ? HideFlags.HideInHierarchy : HideFlags.None;
#endif
                    objectInsideThisPool.Add(newObject);
                    ++totalCount;

                    if (writeIntoArray)
                    {
                        transformAccess.Add(newObject.transform);
                    }
                }
            }
        }
    private void Start()
    {
        // Initialize velocities with a persistent allocator of size amountOfFish, which is a pre-declared variable.
        velocities = new NativeArray <Vector3>(amountOfFish, Allocator.Persistent);

        // Initialize transformAccessArray with size amountOfFish.
        transformAccessArray = new TransformAccessArray(amountOfFish);

        for (int i = 0; i < amountOfFish; i++)
        {
            float distanceX =
                Random.Range(-spawnBounds.x / 2, spawnBounds.x / 2);

            float distanceZ =
                Random.Range(-spawnBounds.z / 2, spawnBounds.z / 2);

            // Create a random spawn point within spawnBounds.
            Vector3 spawnPoint = (transform.position + Vector3.up * spawnHeight) + new Vector3(distanceX, 0, distanceZ);

            // Instantiate objectPrefab, which is a fish, at spawnPoint with no rotation.
            Transform t = (Transform)Instantiate(objectPrefab, spawnPoint, Quaternion.identity);

            // Add the instantiated transform to transformAccessArray.
            transformAccessArray.Add(t);
        }
    }
        private void CreateCameraTrajectoryNode()
        {
            var camPos            = _firstPersonCamera.transform.position;
            var camRot            = _firstPersonCamera.transform.rotation;
            var camRotEulerAngles = camRot.eulerAngles;

            camRotEulerAngles.x = 0;
            camRotEulerAngles.z = 0;
            camRot = Quaternion.Euler(camRotEulerAngles);

            var trajectoryNode = Instantiate(_cameraTrajectoryNodePrefab, camPos, camRot);

            trajectoryNode.transform.parent = _cameraTrajectoryRoot;

            var arrowPos = new Vector3(camPos.x, FloorPosition.y, camPos.z);

            var arrowNode = Instantiate(_arrowPrefab, arrowPos, camRot);

            arrowNode.transform.parent = _cameraTrajectoryRoot;
            arrowNode.transform.Rotate(0, k_ModelRotation, 0, Space.Self);

            // Jobs
            _trajectoryTransforms.Add(trajectoryNode.transform);
            _arrowTransforms.Add(arrowNode.transform);
            // Jobs
        }
    private void Spawn()
    {
        if (prefab == null || spawnArea == null || spawnObjects.Count > 0)
        {
            return;
        }

        Vector3 area   = spawnArea.transform.position;
        Vector3 scale  = spawnArea.transform.localScale;
        float   radius = Mathf.Max(scale.x, scale.y, scale.z);

        transformAccessArray = new TransformAccessArray(spawnNum);
        moveDirections       = new NativeArray <Vector3>(spawnNum, Allocator.Persistent);
        rotateAngles         = new NativeArray <Vector3>(spawnNum, Allocator.Persistent);

        spawnObjects.Clear();
        for (int i = 0; i < spawnNum; i++)
        {
            Vector3    pos = Random.insideUnitSphere * radius + area;
            GameObject go  = Instantiate(prefab, pos, prefab.transform.rotation);
            spawnObjects.Add(go);

            transformAccessArray.Add(go.transform);
            moveDirections[i] = moveDirection * Random.Range(minMoveSpeed, maxMoveSpeed);
            rotateAngles[i]   = rotateAngle * Random.Range(minRotateSpeed, maxRotateSpeed);
        }

        DisplayCount();
    }
Beispiel #9
0
    private void Update()
    {
        float startTime = Time.realtimeSinceStartup;

        if (useJobs)
        {
            //NativeArray<float3> postions = new NativeArray<float3>(prefabs.Count, Allocator.TempJob);
            NativeArray <float>  speeds = new NativeArray <float>(prefabs.Count, Allocator.TempJob);
            TransformAccessArray trans  = new TransformAccessArray(prefabs.Count);
            for (int i = 0; i < prefabs.Count; i++)
            {
                //postions[i] = prefabs[i].trans.localPosition;
                trans.Add(prefabs[i].trans);
                speeds[i] = prefabs[i].speed;
            }
            //ReallyToughParallelJob job = new ReallyToughParallelJob()
            ReallyToughTransJob job = new ReallyToughTransJob()
            {
                //positionArray = postions,
                speedArray = speeds,
                deltaTime  = Time.deltaTime
            };
            //JobHandle handle = job.Schedule(prefabs.Count, 100);
            JobHandle handle = job.Schedule(trans);
            handle.Complete();
            for (int i = 0; i < prefabs.Count; i++)
            {
                //prefabs[i].trans.localPosition = postions[i];
                //prefabs[i].trans = trans[i];
                prefabs[i].speed = speeds[i];
            }
            //postions.Dispose();
            speeds.Dispose();
            trans.Dispose();
        }
        else
        {
            ReallyToughMoveTask();
        }

        /*if (!useJobs)
         * {
         *  for (int i = 0; i < 10; i++)
         *  {
         *      ReallyToughTask();
         *  }
         * }
         * else
         * {
         *  NativeList<JobHandle> handles = new NativeList<JobHandle>(Allocator.Temp);
         *  for (int i = 0; i < 10; i++)
         *  {
         *      JobHandle handle = ReallyToughrJobTask();
         *      handles.Add(handle);
         *  }
         *  JobHandle.CompleteAll(handles);
         *  handles.Dispose();
         * }*/
        Debug.Log((Time.realtimeSinceStartup - startTime) * 1000 + "ms");
    }
    // Update is called once per frame
    void Update()
    {
        movehandle.Complete();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            movehandle.Complete();
            transforms.capacity = transforms.length + 1;
            var obj = Instantiate(text, new Vector3(0, 1, -5), text.transform.rotation) as GameObject;
            transforms.Add(obj.transform);
        }

        //slidingjob = new SlidingJob()
        //{
        //    speed = 0.1f,
        //    resetpos = new Vector3(0, 1, -5)
        //};

        switchingjob = new SwitchingJob()
        {
            framecount     = Time.frameCount,
            switchinterval = random.Next(2, 25),
            textprefab     = text,
            type           = 0
        };
        //if(transforms.length>=1)
        //{
        //    movehandle = switchingjob.Schedule();
        //}

        //movehandle = slidingjob.Schedule(transforms);
        JobHandle.ScheduleBatchedJobs();
    }
Beispiel #11
0
        public void AddNewColumn(OreColumn oreColumn)
        {
            audioSourceEffects.PlayOneShot(addColumnSound);

            var columnHolder = InstantiateColumn(oreColumn);

            columnHolder.transform.SetAsFirstSibling();
            columnHolder.transform.localPosition = new Vector3(-1 * _prefabSize.x, 0, 0);

            var transformAccessArray = new TransformAccessArray(_game.GetOreColumns().Count);

            for (int i = 0; i < spawnPoint.transform.childCount; i++)
            {
                transformAccessArray.Add(spawnPoint.transform.GetChild(i));
            }

            new MoveColumnsLeftJob
            {
                PrefabWidth = _prefabSize.x
            }
            .Schedule(transformAccessArray)
            .Complete();

            transformAccessArray.Dispose();
        }
Beispiel #12
0
    private void OnSpaceClicked(IEventBase eventBase)
    {
        SpaceClicked ev = eventBase as SpaceClicked;

        if (ev != null)
        {
            handle.Complete();
            for (int i = 0; i < enemyCount; i++)
            {
                float x = UnityEngine.Random.Range(transform.position.x + firstPosition.x, transform.position.x + endPostion.x);
                float y = UnityEngine.Random.Range(firstPosition.y + transform.position.y, endPostion.y + transform.position.y);

                var obj = Instantiate(enemyPrefab, new Vector3(x, y, transform.position.z), Quaternion.identity) as GameObject;

                if (obj is null)
                {
                    Debug.LogError($"failed to create enemy!");
                }
                else
                {
                    transforms.Add(obj.transform);
                }
            }
        }
    }
Beispiel #13
0
    private void Update()
    {
        float startTime = Time.realtimeSinceStartup;

        //Objenin sürekli hareket halinde olmasını sağlamak için gerekli tanımları yaptık
        NativeArray <float>  moveYArray           = new NativeArray <float> (BodyList.Count, Allocator.TempJob);
        TransformAccessArray transformAccessArray = new TransformAccessArray(BodyList.Count);

        for (int i = 0; i < BodyList.Count; i++)
        {
            moveYArray[i] = BodyList[i].moveY;
            transformAccessArray.Add(BodyList[i].transform);
        }

        ReallyToughParallelJobTransforms reallyToughParallelJobTransforms = new ReallyToughParallelJobTransforms {
            deltaTime  = Time.deltaTime,
            moveYArray = moveYArray,
        };

        JobHandle jobHandle = reallyToughParallelJobTransforms.Schedule(transformAccessArray);

        jobHandle.Complete();

        for (int i = 0; i < BodyList.Count; i++)
        {
            BodyList[i].moveY = moveYArray[i];
        }

        moveYArray.Dispose();
        transformAccessArray.Dispose();

        txtTotal.text = "TOTAL\n" + GameObject.FindGameObjectWithTag("bodies").transform.childCount.ToString();   //Obje sayısını güncel tuttuk
    }
    internal void AddMobsToSystem(int mobCnt)
    {
        movementJH.Complete();

        if (!taa_mobs.isCreated)
        {
            taa_mobs = new TransformAccessArray(0);
        }

        if (na_mobStates == null || !na_mobStates.IsCreated)
        {
            na_mobStates = new NativeArray <MobState>(0, Allocator.Persistent);
        }

        if (!nl_startPos.IsCreated)
        {
            nl_startPos = new NativeList <Vector3>(Allocator.Persistent);
        }

        if (!nl_targetPos.IsCreated)
        {
            nl_targetPos = new NativeList <Vector3>(Allocator.Persistent);
        }

        int oldMobCnt = PoolManager.instance.MobPool.m_cnt - mobCnt;

        for (int i = 0; i < mobCnt; ++i)
        {
            var startPos   = GameManager.instance.GetSpawnPosFromStart(GameManager.instance.m_defaultSpawnPos, oldMobCnt + i, 2.0f);
            var SpawnedMob = PoolManager.instance.MobPool.SpawnObject(startPos, Quaternion.identity) as MobFightComponent;
            taa_mobs.Add(SpawnedMob.transform);

            nl_startPos.Add(startPos);
            nl_targetPos.Add(new Vector3(startPos.x, startPos.y, GameManager.instance.Target.transform.position.z));
        }

        if (na_mobStates.Length > 0)
        {
            var tempMobState = new NativeArray <MobState>(na_mobStates, Allocator.Temp);
            na_mobStates.Dispose();
            na_mobStates = new NativeArray <MobState>(tempMobState.Length + mobCnt, Allocator.Persistent);
            NativeArray <MobState> .Copy(tempMobState, 0, na_mobStates, 0, tempMobState.Length);
        }
        else
        {
            na_mobStates.Dispose();
            na_mobStates = new NativeArray <MobState>(mobCnt, Allocator.Persistent);
        }

        for (int i = oldMobCnt; i < na_mobStates.Length; ++i)
        {
            na_mobStates[i] = MobState.ToTarget;
        }

        if (PoolManager.instance.SpearPool.m_cnt < PoolManager.instance.MobPool.m_cnt)
        {
            int diff = PoolManager.instance.MobPool.m_cnt - PoolManager.instance.SpearPool.m_cnt;
            AddSpearsToSystem(diff);
        }
    }
Beispiel #15
0
 public int Add(Transform t, Vector3 axis)
 {
     transforms.Add(t);
     this.axis[numJobs] = axis;
     numJobs++;
     return(numJobs - 1);
 }
Beispiel #16
0
    /// <summary>
    /// create a job for transform position all enimies with speed
    /// </summary>
    private void JobWorkToTransform()
    {
        NativeArray <float>  speedArr             = new NativeArray <float>(enemies.Count, Allocator.TempJob);
        TransformAccessArray transformAccessArray = new TransformAccessArray(enemies.Count);

        for (int i = 0; i < enemies.Count; i++)
        {
            speedArr[i] = enemies[i].speed;
            transformAccessArray.Add(enemies[i].transform);
        }

        UpdateTransform job = new UpdateTransform
        {
            deltaTime  = Time.deltaTime,
            speedArray = speedArr,
            targetX    = _targetX,
        };

        JobHandle jobHandle = job.Schedule(transformAccessArray);

        jobHandle.Complete();

        speedArr.Dispose();
        transformAccessArray.Dispose();
    }
Beispiel #17
0
        public static void OnDroneCountChange()
        {
            movementJobHandle.Complete();
            energyJobHandle.Complete();
            _Transforms.Dispose();
            _Transforms = new TransformAccessArray(0);
            foreach (Drone drone in Drones.Values)
            {
                _Transforms.Add(drone.transform);
            }
            _JobInfoArray.Dispose();
            _JobInfoArray = new NativeArray <MovementInfo>(_Transforms.length, Allocator.Persistent);
            _EnergyInfoArray.Dispose();
            _EnergyInfoArray = new NativeArray <EnergyInfo>(_Transforms.length, Allocator.Persistent);
            _PreviousPositions.Dispose();
            _PreviousPositions = new NativeArray <Vector3>(_Transforms.length, Allocator.Persistent);
            int j = 0;

            foreach (Drone drone in Drones.Values)
            {
                _PreviousPositions[j] = drone.PreviousPosition;

                _JobInfoArray[j]    = new MovementInfo();
                _JobInfoArray[j]    = drone.GetMovementInfo(_JobInfoArray[j]);
                _EnergyInfoArray[j] = new EnergyInfo();
                _EnergyInfoArray[j] = drone.GetEnergyInfo(_EnergyInfoArray[j]);
                j++;
            }
        }
        /// データ追加
        /// 追加したインデックスを返す
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public int Add(Transform element)
        {
            int index = 0;

            int id = element.GetInstanceID();

            if (referenceDict.ContainsKey(id))
            {
                // 参照カウンタ+
                referenceDict[id] = referenceDict[id] + 1;
                return(indexDict[id]);
            }

            if (emptyStack.Count > 0)
            {
                // 再利用
                index = emptyStack.Dequeue();
                transformArray[index] = element;
            }
            else
            {
                // 新規
                index = transformArray.length;
                transformArray.Add(element);
            }
            useIndexDict.Add(index, id);
            indexDict.Add(id, index);
            referenceDict.Add(id, 1);
            nativeLength = transformArray.length;

            return(index);
        }
    private void Update()
    {
        // Time.realtimeSinceStartup : 게임이 시작된 시간으로부터 경과한 실제 시간을 나타냅니다.
        float startTime = Time.realtimeSinceStartup;

        if (useJobs)
        {
            NativeArray <float>  moveYArray           = new NativeArray <float>(sphereList.Count, Allocator.TempJob);
            TransformAccessArray transformAccessArray = new TransformAccessArray(sphereList.Count);

            // List 내 위치와 moveY 저장
            for (int i = 0; i < sphereList.Count; i++)
            {
                //positionArray[i] = sphereList[i].transform.position;
                moveYArray[i] = sphereList[i].moveY;
                transformAccessArray.Add(sphereList[i].transform);
            }

            ReallyToughParalleJobTransform reallyToughParalleJobTransform = new ReallyToughParalleJobTransform
            {
                deltaTime  = Time.deltaTime,
                moveYArray = moveYArray,
            };

            JobHandle jobHandle = reallyToughParalleJobTransform.Schedule(transformAccessArray);
            jobHandle.Complete();

            for (int i = 0; i < sphereList.Count; i++)
            {
                sphereList[i].moveY = moveYArray[i];
            }

            moveYArray.Dispose();
            transformAccessArray.Dispose();
        }
        else
        {
            foreach (SphereT sphere in sphereList)
            {
                sphere.transform.position += new Vector3(0, sphere.moveY * Time.deltaTime);

                if (sphere.transform.position.y > 5f)
                {
                    sphere.moveY = -math.abs(sphere.moveY);
                }
                if (sphere.transform.position.y < -5f)
                {
                    sphere.moveY = +math.abs(sphere.moveY);
                }
                float value = 0f;
                for (int i = 0; i < 5000; i++)
                {
                    value = math.exp10(math.sqrt(value));
                }
            }
        }
        // 1 Update 경과 시간 (ms)
        Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms");
    }
    internal void AddSpearsToSystem(int spearCnt)
    {
        spearMovementJH.Complete();

        if (!taa_spears.isCreated)
        {
            taa_spears = new TransformAccessArray(0);
        }

        if (!na_spearVelocities.IsCreated)
        {
            na_spearVelocities = new NativeArray <Vector3>(0, Allocator.Persistent);
        }

        if (!na_spearState.IsCreated)
        {
            na_spearState = new NativeArray <SpearState>(0, Allocator.Persistent);
        }

        PoolManager.instance.SpearPool.Expand(spearCnt);

        int oldMobCnt = PoolManager.instance.SpearPool.m_cnt - spearCnt;

        for (int i = 0; i < spearCnt; ++i)
        {
            taa_spears.Add(PoolManager.instance.SpearPool.GetAt(oldMobCnt + i).transform);
        }

        if (na_spearVelocities.Length > 0)
        {
            var tempSpearVelocities = new NativeArray <Vector3>(na_spearVelocities, Allocator.Temp);
            na_spearVelocities.Dispose();
            na_spearVelocities = new NativeArray <Vector3>(tempSpearVelocities.Length + spearCnt, Allocator.Persistent);
            NativeArray <Vector3> .Copy(tempSpearVelocities, 0, na_spearVelocities, 0, tempSpearVelocities.Length);
        }
        else
        {
            na_spearVelocities.Dispose();
            na_spearVelocities = new NativeArray <Vector3>(spearCnt, Allocator.Persistent);
        }

        if (na_spearState.Length > 0)
        {
            var tempSpearActive = new NativeArray <SpearState>(na_spearState, Allocator.Temp);
            na_spearState.Dispose();
            na_spearState = new NativeArray <SpearState>(tempSpearActive.Length + spearCnt, Allocator.Persistent);
            NativeArray <SpearState> .Copy(tempSpearActive, 0, na_spearState, 0, tempSpearActive.Length);
        }
        else
        {
            na_spearState.Dispose();
            na_spearState = new NativeArray <SpearState>(spearCnt, Allocator.Persistent);
        }

        for (int i = oldMobCnt; i < na_spearState.Length; ++i)
        {
            na_spearState[i] = SpearState.Inactive;
        }
    }
    // Use this for initialization
    void Start()
    {
        transformcamera = new TransformAccessArray(1, -1);
        transformcamera.Add(Camera.main.transform);


        transforms = new TransformAccessArray(0, -1);
        //SlidingJob
        //Vector3[] vtemp;
        List <float>   vtemp        = new List <float>();
        List <Vector3> resetpostemp = new List <Vector3>();
        var            x            = 0;
        var            z            = 150f;
        //Debug.Log(Screen.width / 10);
        var totalsymbols = 0;


        for (int i = 0; i < 20; i++)
        {
            for (int j = 0; j < 20; j++)
            {
                var stream_temp = new Stream(TextRain);
                //stream_temp.generateSymbols(x, 100f, z);//y = 50f
                stream_temp.generateSymbols(x, (float)random.Next(90, 111), z);//y = 50f

                totalsymbols += stream_temp.totalsymbols;
                for (int k = 0; k < stream_temp.symbols.Count; k++)
                {
                    transforms.capacity += 1;
                    transforms.Add(stream_temp.symbols[k].obj.transform);
                    vtemp.Add(stream_temp.symbols[k].speed);
                    resetpostemp.Add(stream_temp.symbols[k].obj.transform.position);
                }


                streams.Add(stream_temp);

                x = x + 10;
            }
            x = 0;
            z = z + 25;
        }
        m_Velocities = new NativeArray <float>(totalsymbols, Allocator.Persistent);
        m_Velocities.CopyFrom(vtemp.ToArray());

        resetpos = new NativeArray <Vector3>(totalsymbols, Allocator.Persistent);
        resetpos.CopyFrom(resetpostemp.ToArray());

        vtemp.Clear();
        vtemp = null;

        resetpostemp.Clear();
        resetpostemp = null;


        shoulddive = true;
        shouldup   = false;
    }
Beispiel #22
0
 public void Add(Sway sway)
 {
     transforms.capacity = transforms.length + 1;
     transforms.Add(sway.transform);
     theta[numJobs]     = 0;
     angle[numJobs]     = sway.angle;
     frequency[numJobs] = sway.frequency;
     numJobs++;
 }
Beispiel #23
0
        protected override void OnAdd(SatelliteSystemData systemData)
        {
            var satelliteData = new SatelliteData(systemData);

            data.Add(satelliteData);
            planets.Add(systemData.Planet);
            planetPositions.Add(float3.zero);
            satellitePositions.Add(float3.zero);
        }
Beispiel #24
0
 private void CreateGameObjects()
 {
     for (int i = 0; i < _numberOfObjects; i++)
     {
         GameObject gameObject = Instantiate(_prefab, Util.GetNext(_min, _max), Quaternion.identity);
         _positions[i] = gameObject.transform.position;
         _transforms.Add(gameObject.transform);
     }
 }
Beispiel #25
0
    private GameObject SpawnBat()
    {
        GameObject bat = Instantiate(batPrefab, new Vector3(0f, 5f, -12f), Quaternion.identity);

        bat.transform.localScale = new Vector3(10, 10, 10);
        transforms.Add(bat.transform);
        randNums.Add(0f);
        //if (randNums.Length < ++numBats) ResizeNativeArray();
        return(bat);
    }
Beispiel #26
0
 protected void Start()
 {
     m_Velocities = new NativeArray <float3>(objectCount, Allocator.Persistent);
     GameObject[] list = SetupUtils.PlaceRandomCubes(objectCount, radius);
     m_TransformsAccessArray = new TransformAccessArray(objectCount);
     for (int i = 0; i < objectCount; i++)
     {
         m_TransformsAccessArray.Add(list[i].transform);
     }
 }
Beispiel #27
0
        private IEnumerator GravityAnimationCoroutine(int column)
        {
            var columnTransform = spawnPoint.GetChild(column);

            while (true)
            {
                var transformAccessArray = new TransformAccessArray(OreColumn.ColumnSize);

                float gapDistance = 0;
                for (var i = 0; i < columnTransform.childCount; i++)
                {
                    var oreTransform = columnTransform.GetChild(i);
                    if (gapDistance < ComparisonThreshold)
                    {
                        gapDistance = oreTransform.localPosition.y - i * _prefabSize.y;
                        if (gapDistance > ComparisonThreshold)
                        {
                            transformAccessArray.Add(oreTransform);
                        }
                    }
                    else
                    {
                        transformAccessArray.Add(oreTransform);
                    }
                }

                if (gapDistance < ComparisonThreshold)
                {
                    transformAccessArray.Dispose();
                    break;
                }

                new MoveOresDownJob()
                {
                    StepSize = Math.Min(Time.deltaTime * animationSpeed, gapDistance)
                }
                .Schedule(transformAccessArray)
                .Complete();

                transformAccessArray.Dispose();
                yield return(null);
            }
        }
Beispiel #28
0
 private void AddShips()
 {
     transforms.capacity = transforms.length + numberOfShipsToAdd;
     for (int i = 0; i < numberOfShipsToAdd; i++)
     {
         tempTransform = Instantiate(shipPrefab, RandomScreenPosition(), Quaternion.Euler(Vector3.zero)).transform;
         ships.Add(tempTransform);
         transforms.Add(tempTransform);
     }
 }
Beispiel #29
0
 public void AddShips(int shipCount)
 {
     for (int i = 0; i < shipCount; i++)
     {
         Vector3    pos       = shipData.GetRandomTopSpawnPos(10);
         Quaternion rot       = Quaternion.Euler(0f, 180f, 0f);
         var        enemyShip = Instantiate(shipPrefab, pos, rot) as GameObject;
         enemyShipTransforms.Add(enemyShip.transform);
     }
 }
Beispiel #30
0
        public int RegisterObject(ObjectDistanceToggle _newEntry)
        {
            isActive = true;
            int index = currentLODList.Count;

            ObjectDistanceToggleList.Add(_newEntry);
            gameObjectList.Add(_newEntry.gameObject);
            currentLODList.Add(LODLevel.NOTSET);
            /// setup temp array
            TransformAccessArray tempArray             = new TransformAccessArray(indexes);
            NativeArray <float>  templod0DistanceArray = new NativeArray <float>(indexes + 1, Allocator.Persistent);

            for (int i = 0; i < indexes; i++)
            {
                tempArray.Add(transformAccessArray[i]);
                templod0DistanceArray[i] = lod0DistanceArray[i];
            }
            tempArray.Add(_newEntry.transform);
            templod0DistanceArray[indexes] = _newEntry.lod0;
            indexes = index + 1;
            /// copy temp aray into new array
            if (indexes > 1)
            {
                lod0DistanceArray.Dispose();
                distanceToPlayerArray.Dispose();
                transformAccessArray.Dispose();
                LODLevelArray.Dispose();
            }
            transformAccessArray  = new TransformAccessArray(indexes);
            lod0DistanceArray     = new NativeArray <float>(indexes, Allocator.Persistent);
            distanceToPlayerArray = new NativeArray <float>(indexes, Allocator.Persistent);
            LODLevelArray         = new NativeArray <LODLevel>(indexes, Allocator.Persistent);
            for (int i = 0; i < indexes; i++)
            {
                transformAccessArray.Add(tempArray[i]);
                lod0DistanceArray[i] = templod0DistanceArray[i];
            }
            /// dispose temp array
            tempArray.Dispose();
            templod0DistanceArray.Dispose();
            return(index);
        }