void Start() { //Create Compute Shader Data ParticleGridPositionCheck = new ComputeBuffer(BoidsCount, Marshal.SizeOf(typeof(Int3))); ParticleBoidBufferRead = new ComputeBuffer(BoidsCount, Marshal.SizeOf(typeof(ParticleBoid))); ParticleBoidBufferWrite = new ComputeBuffer(BoidsCount, Marshal.SizeOf(typeof(ParticleBoid))); GenerateCharacterAffectorFromPath("Assets/CharacterTest/ren.json"); //foreach (var affector in affectorData) //{ // var go = GameObject.CreatePrimitive(PrimitiveType.Sphere); // go.transform.localScale = new Vector3(1,1, 1); // go.transform.position = affector.position; //} var pData = new ParticleBoid[BoidsCount]; for (int i = 0; i < pData.Length; i++) { pData[i] = CreateBoidData(); } ParticleBoidBufferRead.SetData(pData); pData = null; BoidParticleRenderMateiral = new Material(BoidParticleShader); BoidParticleRenderMateiral.hideFlags = HideFlags.HideAndDontSave; _numberOfGrids = (int)(gridDim.x * gridDim.y * gridDim.z); sorter = new GridOptimizer3D <ParticleBoid>(BoidsCount, range, gridDim); //StartCoroutine(GetData()); StartCoroutine(ChangeRotationSpeed()); }
ParticleBoid CreateBoidData() { ParticleBoid boidData = new ParticleBoid(); Vector3 pos = Target.transform.position + UnityEngine.Random.insideUnitSphere * SpawnRadius; //Vector3 pos = new Vector3(UnityEngine.Random.Range(0f, 100f), UnityEngine.Random.Range(0f, 100f), // UnityEngine.Random.Range(0f, 100f)); Quaternion rot = Quaternion.Slerp(transform.rotation, UnityEngine.Random.rotation, 0.3f); boidData.position = pos; boidData.direction = rot.eulerAngles; boidData.noise_offset = UnityEngine.Random.value * 10.0f; return(boidData); }