Exemple #1
0
    void generateObjectUI()
    {
        //GameObject objectUI = new GameObject();
        Canvas         canvas = objectUI.AddComponent <Canvas>();
        FreezeRotation test   = objectUI.AddComponent <FreezeRotation>();

        canvas.renderMode = RenderMode.WorldSpace;
        CanvasScaler cs = objectUI.AddComponent <CanvasScaler>();

        cs.scaleFactor          = 10.0f;
        cs.dynamicPixelsPerUnit = 10f;
        GraphicRaycaster gr = objectUI.AddComponent <GraphicRaycaster>();

        objectUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 3.0f);
        objectUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 3.0f);

        objectUI.name = "Personal";
        bool bWorldPosition = false;

        objectUI.GetComponent <RectTransform>().SetParent(this.transform, bWorldPosition);
        objectUI.transform.localPosition = new Vector3(0f, 0f, 0f);
        objectUI.transform.localScale    = new Vector3(
            1.0f / this.transform.localScale.x * 0.1f,
            1.0f / this.transform.localScale.y * 0.1f,
            1.0f / this.transform.localScale.z * 0.1f);
    }
Exemple #2
0
    /*
     * public void damagedCheck() {
     *      Color img = imageUI.GetComponent<Image>().color;
     *      if(isDamaged) {
     *              img.a = Mathf.Lerp (img.a, 5.00f, Time.deltaTime);
     *
     *      } else {
     *              img.a = Mathf.Lerp (img.a, 0.0f, Time.deltaTime);
     *      }
     *      imageUI.GetComponent<Image>().color = img;
     * }
     *
     * void generateImageUI() {
     *      imageUI.name = "ImageUI";
     *      //imageUI.GetComponent<RectTransform>().position.z = -45;
     *      imageUI.transform.parent = objectUI.transform;
     *      Image image = imageUI.AddComponent<Image>();
     *
     *      Color color = new Color32(50,0,0,50);
     *      //color.r = 25;
     *      //color.b = 0;
     *      //color.g = 0;
     *      //color.a = 25;
     *      image.color = color;
     * }
     */

    void generateObjectUI()
    {
        //GameObject objectUI = new GameObject();
        Canvas         canvas = objectUI.AddComponent <Canvas>();
        FreezeRotation test   = objectUI.AddComponent <FreezeRotation>();

        canvas.renderMode = RenderMode.WorldSpace;
        CanvasScaler cs = objectUI.AddComponent <CanvasScaler>();

        cs.scaleFactor          = 10.0f;
        cs.dynamicPixelsPerUnit = 10f;
        GraphicRaycaster gr = objectUI.AddComponent <GraphicRaycaster>();

        objectUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 3.0f);
        objectUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 3.0f);

        textUI.name             = "HealthUI";
        textUI.transform.parent = objectUI.transform;

        Text health = textUI.AddComponent <Text>();

        textUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 3.0f);
        textUI.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 3.0f);
        health.alignment          = TextAnchor.MiddleCenter;
        health.horizontalOverflow = HorizontalWrapMode.Overflow;
        health.verticalOverflow   = VerticalWrapMode.Overflow;
        Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");

        health.font     = ArialFont;
        health.fontSize = 6;
        health.text     = "100";
        health.enabled  = true;
        health.color    = Color.white;
        health.GetComponent <Text>().material = targetMaterial;

        objectUI.name = "Text Label";
        bool bWorldPosition = false;

        objectUI.GetComponent <RectTransform>().SetParent(this.transform, bWorldPosition);
        objectUI.transform.localPosition = new Vector3(0f, 0f, 0f);
        objectUI.transform.localScale    = new Vector3(
            1.0f / this.transform.localScale.x * 0.1f,
            1.0f / this.transform.localScale.y * 0.1f,
            1.0f / this.transform.localScale.z * 0.1f);
    }
 public void SetFreezeRotation(FreezeRotation value)
 {
     freezeRotation = value;
 }