Ejemplo n.º 1
0
 void OnEnable()
 {
     thisTransform = transform;
     if (cameraToUse == null)
         cameraToUse = Camera.main;
     camTransform = cameraToUse.transform;
     if(target == null)
         target = thisTransform;
     if(target != thisTransform)
     {
         GameObject targetGO = new GameObject("Object Label Target");
         targetGO.transform.position = target.position;
         targetGO.transform.parent = target;
         target = targetGO.transform;
     }
     if(text == null)
     {
         text = new PhysicalText(target);
     }
     text.textString = label;
     if(font != null)
     {
         text.font = font;
     }
     text.text.layer = LayerMask.NameToLayer("Units");
     textTransform = text.text.transform;
     textTransform.parent = target;
     textTransform.localPosition = offset;
     target.localScale = Vector3.zero;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Called once, at the beginning of the game.
 /// Replaces Awake().
 /// </summary>
 protected override void ClassSetup()
 {
     unitType = UnitType.Commander;
     spawnPoint = transform.position;
     _spawnTime = spawnTime;
     cameraPosition = Camera.main.transform.localPosition;
     if (defendObjective != null)
         defendObjective.SetOwner(this);
     commander = this;
     if (isPlayer && player == null)
     {
         player = this;
         uName = "You";
         gameObject.name = "Player";
         Screen.showCursor = false;
         isInSetup = true;
         if (cardBackground == null)
             cardBackground = Resources.Load("Prefabs/Unit Card Background") as GameObject;
         if (guiCamera != null)
         {
             respawnText = new PhysicalText(guiCamera.ViewportToWorldPoint(new Vector3(0.075f, 0.8f, 0.5f)));
             respawnText.textString = "Respawn in: ";
             respawnText.font = respawnFont;
             respawnText.text.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
             respawnText.text.transform.localRotation = Quaternion.Euler(new Vector3(90.0f, 0.0f, 0.0f));
         }
         showTutorial = true;
         guiRect = new Rect(0, 0, 500, Screen.height / guiTooltips.Length + 1);
         //Time.timeScale = 0.0f;
         float setupHeight = 20.0f;
         float setupWidth = 150.0f;
         float setupLeft = Screen.width / 2 - setupWidth / 2;
         setupEndRect = new Rect(setupLeft, setupHeight / 1.25f, setupWidth, setupHeight);
         setupRect = setupEndRect;
         setupWidth /= 2;
         setupRect.y = 0;
         setupLeft = Screen.width / 2 - setupWidth / 2;
         setupRect.x = setupLeft;
     }
     if (unitPrefab == null)
         unitPrefab = Resources.Load("Prefabs/Unit") as GameObject;
     while (unitsToGenerate > 0)
     {
         GenerateUnit(unitPrefab);
         unitsToGenerate--;
     }
     raycastIncrementRate = 5.0f;
     AddCommander(this);
 }
Ejemplo n.º 3
0
    private PhysicalText PlaceImagePlane(PhotoshopLayer pLayer)
    {
        //Store some reference variables:
        Texture image = pLayer.texture;
        int layer = pLayer.layer;
        string iName = pLayer.name;
        Debug.LogWarning(iName);
        Vector2 imageSize = new Vector2(image.width,image.height);

        // Protect for a not-set GUI size (dividing by 0):
        if(imageSize.x > guiSize.x || imageSize.y > guiSize.y)
            guiSize = imageSize;

        //Work out how big to make the image, based upon its location and size relative to the GUI:
        Vector2 scaledSize = pLayer.relativeSize;
        //Debug.Log ("Size: "+imageSize+", scaled size: "+scaledSize+", GUI Size: "+guiSize);
        Vector2 scaledLocation = pLayer.relativeLocation;
        //Debug.Log ("Location: "+location+", scaled location: "+scaledLocation+", layer: "+layer);

        //Work out how far away to place the image, to create layers:
        float distanceFromCamera = 50.0f + layer;

        //Create the physical representation of the texture in the game world:
        Vector3 center = new Vector3(scaledLocation.x + (scaledSize.x / 2), scaledLocation.y - (scaledSize.y / 2), distanceFromCamera);
        Vector3 position = guiCamera.ViewportToWorldPoint(center);
        //Debug.Log("Viewport position: "+center+", real world position: "+position);
        PhysicalText text = new PhysicalText(position);
        text.planeSize = 0.5f;
        Vector3 viewportTopLeft = new Vector3(scaledLocation.x,scaledLocation.y,distanceFromCamera);
        Vector3 viewportBottomRight = new Vector3(scaledLocation.x+scaledSize.x,scaledLocation.y-scaledSize.y,distanceFromCamera);
        //Debug.Log ("Max top left bounds (viewport): "+viewportTopLeft.x+", "+viewportTopLeft.y);
        //Debug.Log ("Max bottom right bounds (viewport): "+viewportBottomRight.x+", "+viewportBottomRight.y);
        Vector3 topLeftBounds = guiCamera.ViewportToWorldPoint(viewportTopLeft);
        Vector3 bottomRightBounds = guiCamera.ViewportToWorldPoint(viewportBottomRight);
        //Debug.Log ("Max top left bounds (real): "+topLeftBounds);
        //Debug.Log ("Max bottom right bounds (real): "+bottomRightBounds);
        float width = Mathf.Abs(topLeftBounds.x - bottomRightBounds.x);
        float height = Mathf.Abs(topLeftBounds.y - bottomRightBounds.y);
        //Debug.Log ("Real world width: "+width+", real world height: "+height);
        GameObject primitive;
        //Check to see if the texture is designated as a "special texture" (i.e. text):
        if(iName.Contains("^"))
        {
            text.textString = iName.Replace("^","");
            text.SetMaxBounds(width, height);
            primitive = text.text;
            primitive.transform.position = topLeftBounds;
            text.color = Color.black;
        }
        else
        {
            text.texture = image;
            primitive = text.text;
            primitive.transform.localEulerAngles = new Vector3(
                        primitive.transform.localEulerAngles.x,
                        primitive.transform.localEulerAngles.y + 180,
                        primitive.transform.localEulerAngles.z + 90);
            primitive.transform.localScale = new Vector3(height,width,1);
            primitive.transform.position = position;
        }
        guiLayers[layer] = text;
        pLayer.text = text;
        pLayer.realWorldBottomRightBounds = bottomRightBounds;
        pLayer.realWorldTopLeftBounds = topLeftBounds;
        primitive.name = "GUI Element "+image.name+", layer "+layer;
        return text;
    }