示例#1
0
    /// <summary>
    ///   设置render
    /// </summary>
    private void LoadRenderToObj(XmlElement node, GameObject go)
    {
        Debug.Log("setting render to " + go.name);
        foreach (XmlElement renderNode in node.ChildNodes)
        {
            string renderName      = renderNode.GetAttribute("name");
            bool   receiverShadows = renderNode.GetAttribute("receiveShadows") == "True" ? true : false;

            List <string> temp;
            temp = FuncUtil.GetInstance().StrToStrList(renderNode.GetAttribute("boundsMin"));
            Vector3 boundsMin = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
            temp = FuncUtil.GetInstance().StrToStrList(renderNode.GetAttribute("boundsMax"));
            Vector3 boundsMax     = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
            int     lightmapIndex = int.Parse(renderNode.GetAttribute("lightmapIndex"));
            temp = FuncUtil.GetInstance().StrToStrList(renderNode.GetAttribute("lightmapTilingOffset"));
            Vector4 lightmapTilingOffset = new Vector4(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]), float.Parse(temp[3]));


            Renderer render;
            //动画文件应该配置的是其子节点的render
            if (go.name.Contains("Anim"))
            {
                render = go.transform.Find(renderName).GetComponent <Renderer>();
            }
            else
            {
                render = go.GetComponent <Renderer>();
            }
            render.lightmapIndex       = lightmapIndex;
            render.lightmapScaleOffset = lightmapTilingOffset;
            render.receiveShadows      = receiverShadows;
            render.bounds.SetMinMax(boundsMin, boundsMax);
        }
    }
示例#2
0
        public static CCheckBox CreateCheckBox(string name, int x, int y, Transform parent, int width = 0, int height = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(CHECKBOX_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CCheckBox asset = obj.GetComponent <CCheckBox>();

            asset.Selected = false;
            if (width > 0)
            {
                asset.Label.width = width;
            }
            if (height > 0)
            {
                asset.Label.height = height;
            }
            asset.Text = name;
            return(asset);
        }
示例#3
0
        //渐变的label
        public static UILabel CreateGradLabel(string text, int x, int y, int w, int h, Transform parent, Color color, Color topColor, Color bottomColor, Color effectColor, int size = 12, FontStyle style = FontStyle.Bold, NGUIText.Alignment align = NGUIText.Alignment.Left, int depth = 13, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(LABEL_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            UILabel label = obj.GetComponent <UILabel>();

            label.text           = text ?? "";
            label.width          = w;
            label.height         = h;
            label.fontSize       = size;
            label.fontStyle      = style;
            label.pivot          = pivot;
            label.alignment      = align;
            label.applyGradient  = true;
            label.gradientTop    = topColor;
            label.gradientBottom = bottomColor;
            label.effectColor    = effectColor;
            label.effectStyle    = UILabel.Effect.Outline;
            if (color == Color.black)
            {
                color = new Color(0, 1, 1);
            }
            label.color                 = color;
            label.depth                 = depth;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one * size / 20.0f;
            obj.transform.localPosition = new Vector3(x, y, 0);
            return(label);
        }
示例#4
0
        public static UISprite CreateSprite(string atlasPath, string spriteName, int x, int y, Transform parent = null, int width = 0, int height = 0, int depth = 0)
        {
            if (FuncUtil.GetUIAssetByPath(SPRITE_PAHT) == null)
            {
                return(null);
            }
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(SPRITE_PAHT)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent = parent;
            UISprite sp = obj.GetComponent <UISprite>();

            sp.transform.localPosition = new Vector3(x, y, 0);
            sp.transform.localScale    = Vector3.one;
            if (width == 0 || height == 0)
            {
                sp.MakePixelPerfect();
            }
            else
            {
                sp.width  = width;
                sp.height = height;
            }
            object  atlasObj = FuncUtil.GetUIAssetByPath(atlasPath, typeof(UIAtlas));
            UIAtlas atlas    = (atlasObj is GameObject) ? (atlasObj as GameObject).GetComponent <UIAtlas>() : atlasObj as UIAtlas;

            sp.atlas      = atlas;
            sp.spriteName = spriteName;
            sp.depth      = depth;
            return(sp);
        }
示例#5
0
        public static CTabBar CreateTabBar(int x, int y, Transform parent, string[] items, int itemW, int itemH, int depth, int offsetX = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(TABBAR_PATH)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CTabBar box         = obj.GetComponent <CTabBar>();
            var     defaultItem = DisplayUtil.GetChildByName(obj.transform, "Tab0");

            if (defaultItem != null)
            {
                GameObject.DestroyImmediate(defaultItem.gameObject);
            }
            box.RemoveItems();
            for (var i = 0; i < items.Length; i++)
            {
                var btn = CreateTabBarBtn(i * itemW + offsetX, 0, obj.transform, items[i], itemW, itemH, depth);
                btn.name = "Tab" + i;
            }
            box.Start();
            return(box);
        }
示例#6
0
        public static UISprite CreateSprite(string name, UIAtlas atlas, string spriteName, int x, int y, Transform parent = null, int width = 0, int height = 0, int depth = 8, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft)
        {
            if (FuncUtil.GetUIAssetByPath(SPRITE_PAHT) == null)
            {
                return(null);
            }
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(SPRITE_PAHT)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.transform.parent = parent;
            UISprite     sprite = obj.GetComponent <UISprite>();
            UISpriteData spData = (atlas != null) ? atlas.GetSprite(spriteName) : null;

            sprite.type                 = (spData == null || !spData.hasBorder) ? UISprite.Type.Simple : UISprite.Type.Sliced;
            sprite.atlas                = atlas;
            sprite.spriteName           = spriteName;
            sprite.pivot                = pivot;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            if (width == 0 || height == 0)
            {
                sprite.MakePixelPerfect();
            }
            else
            {
                sprite.width  = width;
                sprite.height = height;
            }
            sprite.depth = depth;
            return(sprite);
        }
示例#7
0
 protected override void OnStart()
 {
     base.OnStart();
     try {
         Overlay.width = _itemWidth;
         Overlay.transform.localPosition = new Vector3(PaddingLeft, Overlay.height, 0);
         resetSpSel();
         if (barInContent == false)
         {
             Content.baseClipRegion = new Vector4((this.width - Bar.width) / 2, -this.height / 2, this.width - Bar.width, this.height);
         }
         else
         {
             Content.baseClipRegion = new Vector4((this.width) / 2, -this.height / 2, this.width, this.height);
         }
         UIEventListener.Get(this.gameObject).onScroll = OnMouseScroll;
         if (isDefaultItemRender)
         {
             itemRender = typeof(CDefaultItemRender);
         }
         Recycle.position = new Vector3(9999, 9999, 9999);
     } catch (Exception e) {
         FuncUtil.ShowError(e.Message);
     }
 }
示例#8
0
        public static void SetLightMap(GameObject obj, int index, Vector4 offset)
        {
            List <Component> renderers = getComponentByType(obj, typeof(Renderer)) as List <Component>;

            if (renderers != null && (renderers.Count > 0))
            {
                for (int i = 0; i < renderers.Count; i++)
                {
                    Renderer renderer = renderers[i] as Renderer;
                    if (renderer != null)
                    {
                        renderer.lightmapIndex       = index;
                        renderer.lightmapScaleOffset = offset;
                        for (var j = 0; j < renderer.materials.Length; j++)
                        {
                            renderer.materials[j].shader = FuncUtil.FindShader(renderer.materials[j].shader.name);
                        }
                    }
                }
            }
            else
            {
                Terrain t = obj.GetComponent <Terrain>();
                if (t != null)
                {
                    t.lightmapIndex       = index;
                    t.lightmapScaleOffset = offset;
                }
            }
        }
示例#9
0
    private void LoadGameObject(XmlElement node, Transform parent = null)
    {
        GoConfig config = new GoConfig();

        config.name      = node.GetAttribute("name");
        config.occid     = node.GetAttribute("occid");
        config.isPerLoad = node.GetAttribute("isPerLoad") == "True" ? true : false;
        config.isSurface = node.GetAttribute("isSurface") == "True" ? true : false;
        config.asset     = node.GetAttribute("asset");
        config.parent    = parent;
        config.id        = node.GetAttribute("id");
        config.unitType  = node.GetAttribute("unitType");
        config.node      = node;
        config.tag       = node.GetAttribute("tag");
        List <string> temp;

        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("position"));
        config.position = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("rotation"));
        config.rotation = new Quaternion(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]), float.Parse(temp[3]));
        temp            = FuncUtil.GetInstance().StrToStrList(node.GetAttribute("scale"));
        config.scale    = new Vector3(float.Parse(temp[0]), float.Parse(temp[1]), float.Parse(temp[2]));
        configDict.Add(config.occid, config);
        //Debug.Log("Load GO " + config.occid);
        LoadAsset(config.asset, config.occid);
    }
示例#10
0
    //全部texture和mat放进各自的list里面
    void LoadAsset(string asset, string occid)
    {
        var depends = assetsDependDic[asset];

        for (int i = 0; i < depends.Count; i++)
        {
            //剔除shader
            if (!depends[i].Contains("shader") && !depends[i].Contains("FBX"))
            {
                var url = SceneConfig.GetInstance().prefix + depends[i].Substring(0, depends[i].IndexOf(".")).ToLower() + SceneConfig.GetInstance().suffix;
                if (!assetWaitingList.Contains(url))
                {
                    assetWaitingList.Add(url);
                    totalAssetNum++;
                    //根据assetName将url放进对应的list
                    if (FuncUtil.GetInstance().IsAssetTexture(depends[i]))
                    {
                        textureWaitingList.Add(url);
                    }
                    if (depends[i].Contains(".mat"))
                    {
                        matWaitingList.Add(url);
                    }
                    if (depends[i] == asset)
                    {
                        prefabWaitingList.Add(url);
                        mainAsseturlDict.Add(asset, url);
                    }
                }
            }
        }
    }
示例#11
0
 public static UIEventListener.VoidDelegate AddLink(UILabel lbl, Action <object> handler)
 {
     if (clickDic.ContainsKey(lbl.gameObject))
     {
         Dictionary <Action <object>, UIEventListener.VoidDelegate> dic = clickDic[lbl.gameObject];
         if (dic.ContainsKey(handler))
         {
             return(null);
         }
     }
     else
     {
         clickDic.Add(lbl.gameObject, new Dictionary <Action <object>, UIEventListener.VoidDelegate>());
         AddPress(lbl.gameObject, OnLabelPress, lbl);
         AddHover(lbl.gameObject, (o, b) => { if (!b)
                                              {
                                                  FuncUtil.SetCursor("CURSOR_NORMAL");
                                              }
                  });
     }
     UIEventListener.VoidDelegate de = delegate(GameObject go1) {
         string url = lbl.GetUrlAtPosition(UICamera.lastHit.point);
         if (url != null)
         {
             handler.DynamicInvoke(url);
         }
     };
     UIEventListener.Get(lbl.gameObject).onClick += de;
     clickDic[lbl.gameObject].Add(handler, de);
     return(de);
 }
示例#12
0
        public static CButton CreateImgButton(string path, string text, int depth, int x, int y, Transform parent, int w = 0, int h = 0, UIEventListener.VoidDelegate OnClick = null, string name = "Button", string toolTip = null)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(path)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            obj.name                    = name;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector3(x, y, 0);
            CButton  btn = obj.GetComponent <CButton>();
            UISprite sp  = btn.GetComponent <UISprite>();

            sp.depth = depth;
            if (w > 0 || h > 0)
            {
                sp.width  = w;
                sp.height = h;
            }
            if (toolTip != null)
            {
                btn.AddToolTip(toolTip);
            }
            if (OnClick != null)
            {
                UIEventListener.Get(obj).onClick = OnClick;
            }
            return(btn);
        }
示例#13
0
        public static UILabel CreateLabel(string text, int x, int y, int w, int h, Transform parent, Color color, int size = 12, FontStyle style = FontStyle.Bold, NGUIText.Alignment align = NGUIText.Alignment.Left, int depth = LABEL_DEFAULT_DEPTH, UIWidget.Pivot pivot = UIWidget.Pivot.TopLeft, int zRotate = 0)
        {
            GameObject obj = UnityEngine.Object.Instantiate(FuncUtil.GetUIAssetByPath(LABEL_URL)) as GameObject;

            if (obj == null)
            {
                return(null);
            }
            UILabel label = obj.GetComponent <UILabel>();

            label.text      = text ?? "";
            label.width     = w;
            label.height    = h;
            label.fontSize  = size;
            label.fontStyle = style;
            label.pivot     = pivot;
            label.alignment = align;
            if (color == Color.black)
            {
                color = new Color(0, 1, 1);
            }
            label.color                 = color;
            label.depth                 = depth;
            obj.transform.parent        = parent;
            obj.transform.localScale    = Vector3.one * size / 20.0f;
            obj.transform.localPosition = new Vector3(x, y, 0);
            obj.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, zRotate));
            return(label);
        }
示例#14
0
 public static FuncUtil GetInstance()
 {
     if (instance == null)
     {
         instance = new FuncUtil();
     }
     return(instance);
 }
示例#15
0
 private void SetMaxValue()
 {
     if ((int)Value == (int)Max)
     {
         FuncUtil.AddTip("当前已经是最大值");
         return;
     }
     Value = Max;
 }
示例#16
0
 public static void DoKeyCodeDelegate(KeyCodeDelegate func, GameObject arg, KeyCode key)
 {
     try {
         func(arg, key);
     } catch (Exception ex) {
         //TopTip.addTip(a.Method.Name + "执行出错" + ex.ToString());
         FuncUtil.ShowError(func.Method.Name + "执行出错" + ex.ToString());
     }
 }
示例#17
0
 public static void DoVectorDelegate(VectorDelegate func, GameObject arg, Vector2 delta)
 {
     try {
         func(arg, delta);
     } catch (Exception ex) {
         //TopTip.addTip(a.Method.Name + "执行出错" + ex.ToString());
         FuncUtil.ShowError(func.Method.Name + "执行出错" + ex.ToString());
     }
 }
示例#18
0
 public static void DoBoolDelegate(BoolDelegate func, GameObject arg, bool state)
 {
     try {
         func(arg, state);
     } catch (Exception ex) {
         //TopTip.addTip(a.Method.Name + "执行出错" + ex.ToString());
         FuncUtil.ShowError(func.Method.Name + "执行出错" + ex.ToString());
     }
 }
示例#19
0
 private void OnClickMinBtn(GameObject go)
 {
     if ((int)Value == (int)_Min)
     {
         FuncUtil.AddTip("当前已经是第一页");
         return;
     }
     Value = _Min;
 }
示例#20
0
 private void OnClickMaxBtn(GameObject go)
 {
     if ((int)Value == (int)_Max)
     {
         FuncUtil.AddTip("当前已经是最后一页");
         return;
     }
     Value = _Max;
 }
示例#21
0
 private void OnClickUpBtn(GameObject go)
 {
     if (Max - Value < float.Epsilon)
     {
         FuncUtil.AddTip("当前已经是最大值");
         return;
     }
     Value += Step;
 }
示例#22
0
        private void OnLoadMaskCullingComplete(string url)
        {
            var ttCulling = FuncUtil.GetUIAssetByPath(url) as Texture2D;

            if (material != null)
            {
                material.SetTexture("_Mask", ttCulling);
            }
            UpdateBaseTexture();
        }
示例#23
0
 private void OnClickDownBtn(GameObject go)
 {
     if ((Value - Min < float.Epsilon))
     {
         FuncUtil.AddTip("当前已经是最小值");
         Value = Min;
         return;
     }
     Value -= Step;
 }
示例#24
0
        public void SetObjAndInstantiate(UnityEngine.Object obj)
        {
            if (obj == null)
            {
                Debug.Log("没有这个对象" + this.GetType().ToString());
                return;
            }

            SetGO(Object.Instantiate(obj) as GameObject);
            FuncUtil.AddUIDep(obj, go);
        }
示例#25
0
 private void UpdateDefaultTexture()
 {
     if (string.IsNullOrEmpty(_defaultUrl))
     {
         return;
     }
     if (_url == _defaultUrl || mainTexture != null)
     {
         return;
     }
     FuncUtil.Load(_defaultUrl, (Action <String>)OnLoadTextureComplete, _defaultUrl);
 }
示例#26
0
 private void OnClickUpBtn(GameObject go)
 {
     if ((int)Value == (int)_Max)
     {
         FuncUtil.AddTip("当前已经是最后一页");
         return;
     }
     Value += Step;
     if (Value > _Max)
     {
         Value = _Max;
     }
 }
示例#27
0
    /// <summary>
    /// Auto-upgrade.
    /// </summary>

    protected override void OnInit()
    {
        if (!mFillCenter)
        {
            mFillCenter = true;
            centerType  = AdvancedType.Invisible;
#if UNITY_EDITOR && !DLL_TYPE
            NGUITools.SetDirty(this);
#endif
        }
        base.OnInit();
        FuncUtil.InitUISprite(this);
    }
示例#28
0
 private void OnClickDownBtn(GameObject go)
 {
     if ((int)Value == (int)_Min)
     {
         FuncUtil.AddTip("当前已经是第一页");
         return;
     }
     Value -= Step;
     if (Value < _Min)
     {
         Value = _Min;
     }
 }
示例#29
0
    public void Init()
    {
        var srcData = FuncUtil.GetSpriteData(name);

        if (srcData != null)
        {
            mSprites = srcData;
        }
        else
        {
            Debug.Log("UIAtlas为空:" + name);
        }
    }
示例#30
0
 protected override void OnHover(bool b)
 {
     base.OnHover(b);
     if (b && ToolTip != "")
     {
         ToolTipManager.Show(ToolTip, tipDely, tipWidth);
     }
     else if (b == false)
     {
         ToolTipManager.Hide();
     }
     if (b == true && _isEnable)
     {
         FuncUtil.SetCursor("CURSOR_CLICK_OVER");
         //currentTouch为null是为了防止在按钮上放开鼠标时触发OnHover
         //当鼠标离开时currentTouch为null,鼠标进入时currentTouch也为null,鼠标按下时才不为null
         if (UICamera.currentTouch == null)
         {
             if (_rollOverFun != null)
             {
                 _rollOverFun(gameObject);
             }
         }
     }
     else if (_isEnable == false)
     {
         FuncUtil.SetCursor("CURSOR_NORMAL");
     }
     else
     {
         if (_rollOutFun != null)
         {
             _rollOutFun(gameObject);
         }
         //if (/*!UICamera.IsPressIng && */FuncUtil.IsUICursor()) {
         //    FuncUtil.SetCursor("CURSOR_NORMAL");
         //}
     }
     if (relateChild)
     {
         GetChildBtns();
         foreach (Component child in childBtn)
         {
             if (child != this)
             {
                 (child as CButton).isEnabled = true;
                 (child as CButton).OnHover(b);
             }
         }
     }
 }