void InitCreatedBody(PooledBody b, string name, double mass, Color col) { b.body.orbitData.eclipticNormal = new Vector3d(); b.body.orbitData.orbitNormal = new Vector3d(); b.go.SetActive(true); b.body.enabled = false; b.go.name = name; b.body.mass = mass; b.meshRend.material.color = col; b.orbitDisplay.OrbitLineMaterial = predictionSystem == null ? null : predictionSystem.LinesMaterial; b.light.enabled = mass > illumMassTreshold; var mat = Instantiate(mass > illumMassTreshold ? emitMat : bodyMat); mat.color = col; b.meshRend.material = mat; if (b.velocityLine.material.name.ToLower().Contains("default")) { b.velocityLine.material = Instantiate(emitMat); b.velocityLine.material.color = velocitiesColor; } var linesW = GetSizeOfBody((float)mass) * 0.1f; b.velocityLine.SetWidth(linesW, linesW); b.velocityLine.enabled = _isDrawVectors; }
void OnMouseStay(Vector2 pos, int btn) { if (btn == 0) { if (capturedBody != null) { if (capturedBody.isReady) { capturedBody = null; } else { capturedBody.body.enabled = false; capturedBody.body.position = new Vector3d(GetWorldRaycastPos(pos)); capturedBody.body.FindAndSetMostProperAttractor(); if (_isAutoOrbit) { capturedBody.body.MakeOrbitCircle(true); } if (_isKeplerMotion) { capturedBody.orbitDisplay.DrawOrbit(); } capturedBody.body.orbitData.isDirty = true; } } } }
void OnMouseDown(Vector2 pos, int btn) { if (isAdding && btn == 0 && capturedBody == null) { capturedBody = pool.GetReadyOne(); if (_isKeplerMotion) { capturedBody.orbitDisplay.enabled = _isDrawOrbits; capturedBody.predictionDisplay.enabled = false; } else { capturedBody.orbitDisplay.enabled = false; capturedBody.predictionDisplay.enabled = _isDrawOrbits; } InitCreatedBody(capturedBody, "body_" + pool.ActiveCount, initMass, bodiesColors[Random.Range(0, bodiesColors.Length)]); capturedBody.body.enabled = true; //capturedBody.body.mass = 1; capturedBody.body.position = new Vector3d(GetWorldRaycastPos(pos)); capturedBody.body.transformRef.localScale = new Vector3(1, 1, 1) * GetSizeOfBody(initMass); capturedBody.body.useKeplerMotion = _isKeplerMotion; if (_isAutoOrbit) { capturedBody.body.MakeOrbitCircle(true); } else { capturedBody.body.velocity = new Vector3d(); } OnActiveBodiesCountChanged(); } }
void OnMouseUp(Vector2 pos, int btn) { if (btn == 0) { if (capturedBody != null) { capturedBody.body.enabled = true; //capturedBody.body.mass = initMass; capturedBody.body.useKeplerMotion = _isKeplerMotion; capturedBody.body.orbitData.isDirty = true; capturedBody = null; } } }