public void OnLeftMouse()
    {
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        Debug.DrawRay(Camera.main.transform.position, ray.direction * 100, Color.white, 5);
        if (Physics.Raycast(ray, out hit, 10000))
        {
            Debug.Log("Clicked on " + hit.transform.name);
            Debug.DrawRay(transform.position, ray.direction * 100, Color.red, 5);
            if (hit.transform.tag == "Focusable")
            {
                if (current_focused == hit.transform)
                {
                    return;
                }
                current_focused = hit.transform;
                //PlayerView.instance.FocusOnPlanet(hit.transform);
                BodyBehaviour hit_body = hit.transform.GetComponent <BodyBehaviour>();
                if (hit_body.data.type == "Star")
                {
                    StartCoroutine(CameraBehaviour.instance.FocusTransform(current_focused, 500));
                }
                else if (hit_body.data.type == "Planet")
                {
                    StartCoroutine(CameraBehaviour.instance.FocusTransform(current_focused, 100));
                }
                else
                {
                    StartCoroutine(CameraBehaviour.instance.FocusTransform(current_focused, 25));
                }
            }
        }
    }
    IEnumerator GenerateChildren()
    {
        if (data.children_count <= 0)
        {
            yield break;
        }

        int current_orbit = 1;

        for (int i = 0; i < data.children_count; i++)
        {
            GameObject    orbitator_object = new GameObject("Orbitator " + current_orbit);
            OrbitData     orbitator        = orbitator_object.AddComponent <OrbitData>();
            BodyBehaviour new_body         = Instantiate(BodyGenerator.instance.bodyPrefab,
                                                         transform.position,
                                                         Quaternion.identity).GetComponent <BodyBehaviour>();
            new_body.data            = BodyGenerator.instance.SetupBody(data.type);
            new_body.gameObject.name = new_body.data.type;
            Vector3 orbit_rotation_vector = new Vector3(Random.Range(-0.3f, 0.3f) * new_body.data.orbit_velocity,
                                                        Random.Range(-1f, 1f) * new_body.data.orbit_velocity,
                                                        0);
            orbitator.rotation_vector    = orbit_rotation_vector;
            orbitator.transform.position = transform.position;
            orbitator.following          = transform;
            new_body.transform.position  = transform.position;
            new_body.transform.parent    = orbitator.transform;
            new_body.transform.position  = transform.position + new Vector3(0, 0, (new_body.data.orbit_radius * current_orbit) + 2);
            print("Old pos " + orbitator.transform.localRotation);
            float rand1 = Random.Range(-360f, 360f);
            float rand2 = Random.Range(-360f, 360f);
            orbitator.transform.localRotation = Quaternion.Euler(orbit_rotation_vector.x * rand1 * 100,
                                                                 orbit_rotation_vector.y * rand2 * 100,
                                                                 0);
            print("New pos " + orbitator.transform.localRotation);
            current_orbit++;
        }
        yield return(null);

        //print("Generated children");
        yield break;
    }
Exemplo n.º 3
0
    public void OnStart()
    {
        if (!isOwner)
        {
            MeshRenderer[] mrs = GetComponentsInChildren <MeshRenderer>();
            foreach (var mr in mrs)
            {
                mr.gameObject.layer = 0;
            }
        }

        body = GetComponentInChildren <BodyBehaviour>();
        if (body != null)
        {
            body.OnStart();
        }

        sight = GetComponentInChildren <SightBehaviour>();
        if (sight != null)
        {
            sight.OnStart();
        }
    }