Exemplo n.º 1
0
    public static CelestialOrbit Create(uint physicalOwnerID, CelestialBody virtualParent)
    {
        CelestialOrbit orbit = null;

        CelestialBody physicalOwner = CelestialManagerPhysical.Instance.GetCelestialBody(physicalOwnerID);

        if (null != physicalOwner)
        {
            GameObject gameObject = new GameObject();

            if (null != gameObject)
            {
                gameObject.name = physicalOwner.name + "_Orbit";

                orbit = gameObject.AddComponent <CelestialOrbit>();

                orbit.m_PhysicalOwnerID = physicalOwnerID;

                orbit.m_VirtualParent = virtualParent;

                orbit.UpdatePosition();

                int layerID = LayerMask.NameToLayer("Virtual Universe");
                if (layerID != -1)
                {
                    gameObject.layer = layerID;
                }
            }

            orbit.m_LineRenderer.useWorldSpace = false;

            // Adjust the resolution based on the type of body
            if (physicalOwner.Type == CelestialBody.CelestialType.Planet)
            {
                m_ResolutionScale = 200.0;
            }
            else
            {
                m_ResolutionScale = 60.0;
            }
        }

        return(orbit);
    }
Exemplo n.º 2
0
    // Use this for initialization
    private void Start()
    {
        if (m_VirtualManager.Init())
        {
            // Find all of the planets
            List <CelestialBody> planets = m_VirtualManager.GetCelestialBodies(CelestialBody.CelestialType.All);
            foreach (CelestialBody celestialBody in planets)
            {
                // Create HUD element
                CelestialBodyHUD celestialBodyHUD = CreateHUDElement(celestialBody);

                m_HUDList.Add(celestialBodyHUD);

                // Create orbit

                // Only virtual bodies have visual orbits
                CelestialVirtual celestialVirtual = celestialBody as CelestialVirtual;

                if (celestialBody.HasOrbit && null != celestialVirtual)
                {
                    CelestialBody virtualParent = m_VirtualManager.GetCelestialBody(celestialBody.OrbitParentID);

                    // The orbit needs the id of the physical owner and a reference to the virtual parent
                    CelestialOrbit orbit = CelestialOrbit.Create(celestialVirtual.OwnerID, virtualParent);

                    // Use the same grouping parent as the virtual owner
                    orbit.transform.SetParent(celestialBody.transform.parent);

                    m_CelestialOrbits.Add(orbit);
                }
            }

            // Setup the HUD objects to notify us when clicked
            CelestialClickable[] clickableGUIObjects = GetComponentsInChildren <CelestialClickable>();

            foreach (CelestialClickable clickableGUIObject in clickableGUIObjects)
            {
                if (clickableGUIObject.m_EnableClick)
                {
                    clickableGUIObject.SetSelected = ClickSelected;
                    clickableGUIObject.SetTargeted = ClickTargeted;
                }
                clickableGUIObject.DisableClickMiss = ClickDisableMiss;

                if (clickableGUIObject.m_EnableDrag)
                {
                    clickableGUIObject.MouseDrag = ClickDrag;
                }
            }

            // Set default filter
            if (m_ProximityPanel != null)
            {
                m_ProximityPanel.ToggleFilter_Planets();
            }

            // Set default scale
            SetAutoScale(false);

            // Setup the view camera to a default position
            CelestialBody body = m_VirtualManager.GetCelestialBody("Earth");
            if (body)
            {
                m_ViewCamera.SetTargetedObject(body);
            }
        }
        else
        {
            Debug.LogError("VirtualManager failed to initialize!");
        }
    }