private void SwitchAtlas()
        {
            // copy property
            foreach (string spriteName in duplicateSprites)
            {
                CopySpriteProperty(atlasFrom.GetSprite(spriteName), atlasTo.GetSprite(spriteName));
            }
            UISprite[]       sprites = sceneRoot.GetComponentsInChildren <UISprite>(true);
            HashSet <string> set     = new HashSet <string>(duplicateSprites);
            StringBuilder    str     = new StringBuilder();

            foreach (UISprite s in sprites)
            {
                if (s.atlas == atlasFrom && set.Contains(s.spriteName))
                {
                    s.atlas = atlasTo;
                    CompatibilityEditor.SetDirty(s);
                    CompatibilityEditor.SetDirty(atlasTo);
                    str.AppendFormat("{0}({1})\n", GetScenePath(s.gameObject), s.GetType().FullName);
                }
            }
            if (str.Length > 0)
            {
                Debug.Log(str.ToString());
            }
            Debug.Log("Switching Atals " + atlasFrom.name + " -> " + atlasTo.name + " is DONE.");
        }
Beispiel #2
0
 private void ConvertToSprite()
 {
     spriteList = new List <UISprite>();
     foreach (UITexture tex in targetObj.GetComponentsInChildren <UITexture>(true))
     {
         if (tex.mainTexture == null)
         {
             continue;
         }
         TexSetter setter = tex.GetComponent <TexSetter>();
         TexLoader loader = tex.GetComponent <TexLoader>();
         if (setter != null && setter.textures.Count == 1)
         {
             if (!AssetBundlePath.inst.IsCdnAsset(loader.Target.mainTexture))
             {
                 setter.DestroyEx();
                 loader.DestroyEx();
             }
         }
         if (loader != null)
         {
             continue;
         }
         UIAtlas atlas = atlasMap.Get(tex.mainTexture.name);
         if (atlas != null)
         {
             var s = tex.ConvertToSprite();
             s.atlas = atlas;
             CompatibilityEditor.SetDirty(s.atlas);
             spriteList.Add(s);
         }
     }
 }
        private void OnItemAdd(Object o, int i)
        {
            if (o == null)
            {
                return;
            }
            GameObject    obj = o as GameObject;
            UIButton      btn = obj.GetComponentEx <UIButton>();
            EventDelegate d   = GetCallback(btn.onClick, handler, handler.OnButtonClick);

            if (d == null)
            {
                EventDelegateUtil.AddCallback(btn.onClick, handler.OnButtonClick, btn.gameObject);
                if (obj.GetComponent <Collider2D>() == null)
                {
                    BoxCollider2D collider = obj.AddComponent <BoxCollider2D>();
                    if (obj.GetComponent <SpriteRenderer>() != null)
                    {
                        UpdateSpriteCollider(collider, false);
                    }
                    else
                    {
                        NGUITools.UpdateWidgetCollider(collider, false);
                    }
                }
            }
            CompatibilityEditor.SetDirty(obj);
        }
Beispiel #4
0
        void OnEnable()
        {
            this.handler              = target as ToggleHandler;
            toggleInspector           = new ArrayDrawer <GameObject>(handler, "toggleObj");
            toggleInspector.onInsert += OnItemAdd;

            // convert OnClick -> OnButtonClick
            for (int i = 0; i < toggleInspector.Count; ++i)
            {
                GameObject o = toggleInspector[i] as GameObject;
                if (o != null)
                {
                    UIToggle b = o.GetComponent <UIToggle>();
                    foreach (EventDelegate d in b.onChange)
                    {
                        if (d.target == handler && d.methodName == "OnToggleChange")
                        {
                            EventDelegate.Parameter[] p = d.parameters;
                            d.methodName = "OnToggleChange";
                            if (d.isValid)
                            {
                                d.parameters[0] = p[0];
                            }
                            CompatibilityEditor.SetDirty(o);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning(handler.name + ".ToggleHandler has null arguments");
                }
            }
        }
        public UIWindowInspectorImpl(UIWindow window)
        {
            this.window            = window;
            this.varInspector      = new SerializedInspector(new SerializedObject(window), "ui", "alpha");
            this.animClipInspector = new AnimClipInspector(window, "showClip", "hideClip");
            if (window.ui == null)
            {
                Transform uiTrans = window.transform.Find("ui");

                if (uiTrans != null)
                {
                    window.ui = uiTrans.gameObject;
                }
                else
                {
                    List <Transform> children = new List <Transform>();
                    foreach (Transform t in window.transform)
                    {
                        children.Add(t);
                    }
                    window.ui = new GameObject("ui");
                    window.ui.transform.SetParent(window.transform, false);
                    foreach (Transform t in children)
                    {
                        t.parent = window.ui.transform;
                    }
                }
                CompatibilityEditor.SetDirty(window);
            }
        }
Beispiel #6
0
        public override void OnInspectorGUI()
        {
            if (table == null)
            {
                return;
            }
            bool changed = false;


            EditorGUILayout.BeginHorizontal(GUILayout.Width(WIDTH * table.columnCount));
            changed |= DrawRowHeader();

            changed |= DrawColumn();
            changed |= DrawRowButton();
            EditorGUILayout.EndHorizontal();
            if (table.components.Length == 0)
            {
                if (GUILayout.Button("Click To Add Line"))
                {
                    table.components = new UITableCell[table.maxPerLine];
                    table.InitArray();
                }
            }

            if (changed)
            {
                table.InvalidateLayout();
                CompatibilityEditor.SetDirty(table);
            }
        }
    public override void OnInspectorGUI()
    {
        if (panel == null)
        {
            return;
        }
        bool changed = false;

#if TEXTMESH_PRO
        foreach (TextMeshPro t in text)
        {
            if (IsChanged(t))
            {
                changed = true;
            }
        }
        GUI.enabled = changed;
        if (GUILayout.Button("Set TextMeshPro SortingLayer"))
        {
            Undo.RecordObjects(text, "TextMeshPro SortingLayer");
            foreach (TextMeshPro t in text)
            {
                if (IsChanged(t))
                {
                    t.sortingLayerID = sortingLayerId;
                    t.GetComponent <Renderer>().sortingLayerID = sortingLayerId;
                    CompatibilityEditor.SetDirty(t);
                }
            }
        }
#endif
        GUI.enabled = true;
    }
Beispiel #8
0
        private void Save()
        {
            HashSet <GameObject> prefabs = new HashSet <GameObject>();

            foreach (var pair in mod)
            {
                pair.Key.textKey = pair.Value;
                CompatibilityEditor.SetDirty(pair.Key);
                GameObject p = PrefabUtility.FindPrefabRoot(pair.Key.gameObject);
                if (p != null)
                {
                    prefabs.Add(p);
                }
            }
            mod.Clear();
            if (prefabs.IsNotEmpty())
            {
                foreach (GameObject p in prefabs)
                {
                    // apply prefab change
                    PrefabUtility.ReplacePrefab(p, PrefabUtility.GetPrefabParent(p), ReplacePrefabOptions.ConnectToPrefab);
                }
                AssetDatabase.SaveAssets();
                EditorSceneBridge.SaveScene();
            }
        }
        public void OnGridGUI()
        {
            if (grid == null)
            {
                return;
            }

            bool changed = false;

            if (grid.maxPerLine <= 0)
            {
                grid.maxPerLine = 1;
                changed         = true;
            }

            if (changed)
            {
                grid.InitArray();
            }

            changed    |= DrawTableStructure();
            changed    |= DrawSize();
            GUI.enabled = true;

            if (changed)
            {
                grid.InitArray();
                CompatibilityEditor.SetDirty(grid);
                if (grid.enabled)
                {
                    NGUIUtil.Reposition(grid.transform);
                    grid.Reposition();
                }
            }
        }
Beispiel #10
0
 public static void ChangeTexture(Texture srcTex, Texture dstTex)
 {
     BuildScript.ForEachPrefab((path, popup) => {
         foreach (UITexture t in popup.GetComponentsInChildren <UITexture>(true))
         {
             if (t.mainTexture == srcTex)
             {
                 t.mainTexture = dstTex;
                 CompatibilityEditor.SetDirty(t);
             }
         }
         return(null);
     });
     BuildScript.ForEachScene(roots => {
         foreach (Transform r in roots)
         {
             foreach (UITexture t in r.GetComponentsInChildren <UITexture>(true))
             {
                 if (t.mainTexture == srcTex)
                 {
                     t.mainTexture = dstTex;
                     CompatibilityEditor.SetDirty(t);
                 }
             }
         }
         return(null);
     });
 }
        public bool OnInspectorGUI()
        {
            Animation anim    = script.GetComponent <Animation>();
            bool      changed = false;

            EditorGUI.indentLevel++;
            foreach (string varName in clipVars)
            {
                AnimationClip val = ReflectionUtil.GetFieldValue <AnimationClip>(script, varName);
                if (anim != null)
                {
                    if (EditorGUIUtil.PopupNullable <AnimationClip>(varName, ref val, anim.GetAllClips().ToArray()))
                    {
                        ReflectionUtil.SetFieldValue(script, varName, val);
                        changed = true;
                    }
                }
                else
                {
                    if (val != null)
                    {
                        ReflectionUtil.SetFieldValue <AnimationClip>(script, varName, null);
                        changed = true;
                    }
                }
            }
            EditorGUI.indentLevel--;
            if (changed)
            {
                CompatibilityEditor.SetDirty(script);
            }
            return(changed);
        }
 public void OnInspectorGUI()
 {
     if (EditorGUIUtil.ObjectField <GameObject>("Empty Obj", ref grid.emptyObj, true))
     {
         CompatibilityEditor.SetDirty(grid.emptyObj);
     }
     OnGridGUI();
 }
Beispiel #13
0
        private static void TranslateLabel(UIText l)
        {
            string t = Lexicon.Translate(l.text);

            if (t.IsNotEmpty())
            {
                l.SetText(t);
                CompatibilityEditor.SetDirty(l);
            }
        }
 public static void CopyTexture(TexSetter s, TexLoader l)
 {
     if (l.Target.mainTexture != null && AssetBundlePath.inst.IsCdnAsset(l.Target.mainTexture))
     {
         AssetRef r = new AssetRef();
         r.cdn = true;
         r.SetPath(l.Target.mainTexture);
         s.textures.Add(r);
         CompatibilityEditor.SetDirty(s);
     }
 }
 public void OnEnable()
 {
     if (grid.InitArray())
     {
         CompatibilityEditor.SetDirty(grid);
     }
     if (grid.enabled)
     {
         grid.InvalidateLayout();
     }
 }
        public static void AddDragScrollView()
        {
            UIScrollView view = Selection.activeGameObject.GetComponent <UIScrollView>();

            foreach (BoxCollider2D box in view.GetComponentsInChildren <BoxCollider2D>(true))
            {
                UIDragScrollView drag = box.gameObject.GetComponentEx <UIDragScrollView>();
                drag.scrollView = view;
                CompatibilityEditor.SetDirty(drag);
                Debug.Log("Add DragScrollView for " + box.transform.GetScenePath(), box.gameObject);
            }
        }
Beispiel #17
0
 public void SetValue(Object val)
 {
     if (field != null)
     {
         field.SetValue(obj, val);
     }
     else if (property != null)
     {
         property.SetValue(obj, val, null);
     }
     CompatibilityEditor.SetDirty(obj);
 }
 private static void SetButtonTextColor()
 {
     foreach (GameObject o in Selection.gameObjects)
     {
         UIButton btn = o.GetComponent <UIButton>();
         if (btn != null)
         {
             btn.SetButtonTextColor();
             CompatibilityEditor.SetDirty(btn.gameObject);
         }
     }
 }
Beispiel #19
0
 private void InvalidateArray()
 {
     handler.InitToggles();
     CompatibilityEditor.SetDirty(handler);
     foreach (GameObject b in handler.toggleObj)
     {
         if (b != null)
         {
             SetDirty(b.GetComponentEx <UIToggle>());
             b.GetComponentEx <BoxCollider2D>();
         }
     }
 }
Beispiel #20
0
        public override void OnInspectorGUI()
        {
            varInspector.OnInspectorGUI();
            if (arrDrawer == null && sprite.sprite != null && sprite.sprite.atlas != null)
            {
                string[] sprList = sprite.sprite.atlas.GetListOfSprites().ToArray();
                arrDrawer = new ArrayDrawer <SpriteAnimInfo>(sprite, sprite, "anim", new SpriteAnimInfoItemDrawer(sprList));
                arrDrawer.createDefaultValue = () => new SpriteAnimInfo();
                arrDrawer.addSelected        = false;
            }
            if (arrDrawer == null)
            {
                return;
            }
            if (arrDrawer.Draw(Rotorz.ReorderableList.ReorderableListFlags.ShowIndices))
            {
                CompatibilityEditor.SetDirty(target);
            }

            if (sprite.anim != null && sprite.anim.Length == 1 && GUILayout.Button("Add all"))
            {
                string firstName = sprite.anim[0].name;
                string baseName  = firstName.DetachSuffix();
                string separator = firstName.Length == baseName.Length? "": firstName[baseName.Length].ToString();
                if (char.IsDigit(separator[0]))
                {
                    separator = "";
                }
                int          i    = 1;
                string       name = baseName.AddSuffix(separator, i);
                UISpriteData s    = sprite.sprite.atlas.GetSprite(name);
                while (s != null)
                {
                    arrDrawer.Add(new SpriteAnimInfo(name, sprite.anim[0].delay));
                    i++;
                    name = baseName.AddSuffix(separator, i);
                    s    = sprite.sprite.atlas.GetSprite(name);
                }
                CompatibilityEditor.SetDirty(sprite);
            }
            if (EditorGUIUtil.FloatField("Global Delay", ref globalDelay))
            {
                foreach (SpriteAnimInfo i in sprite.anim)
                {
                    i.delay = globalDelay;
                }
                CompatibilityEditor.SetDirty(sprite);
            }
        }
        override public void OnInspectorGUI()
        {
            bool changed = varInspector.OnInspectorGUI();

            if (changed)
            {
                NGUIUtil.DisableAnchor(layout.top);
                NGUIUtil.DisableAnchor(layout.center);
                NGUIUtil.DisableAnchor(layout.bottom);
                NGUIUtil.DisableAnchor(layout.left);
                NGUIUtil.DisableAnchor(layout.right);
                layout.InvalidateLayout();
                CompatibilityEditor.SetDirty(target);
            }
        }
        void OnEnable()
        {
            inspector = new UIWindowInspectorImpl(target as UIWindow);
            UIWindow  win   = target as UIWindow;
            PopupBase popup = win.GetComponent <PopupBase>();

            if (popup != null)
            {
                UITabHandler tab = popup.GetComponentInChildrenEx <UITabHandler>();
                if (tab != null)
                {
                    popup.tabs = tab;
                    CompatibilityEditor.SetDirty(popup);
                }
            }
        }
Beispiel #23
0
        public static void FindKey(UIText l)
        {
            string text = l.text;

            if (l.textKey.IsEmpty() && text.IsNotEmpty())
            {
                string key = Lexicon.FindAltKey(text);
                if (key.IsNotEmpty())
                {
                    l.textKey = key;
                    CompatibilityEditor.SetDirty(l.gameObject);
                }
                else
                {
                }
            }
        }
Beispiel #24
0
        private void ExtendTabCollider(UIButton tabButton)
        {
            UIWidget w = tabButton.GetComponent <UIWidget>();

            w.autoResizeBoxCollider = false;
            NGUITools.AddWidgetCollider(tabButton.gameObject);
            BoxCollider2D collider = tabButton.GetComponent <BoxCollider2D>();
            Vector2       offset   = collider.offset;

            offset.y += 15;
            Vector2 size = collider.size;

            size.y         += 40;
            size.x         += 8;
            collider.size   = size;
            collider.offset = offset;
            CompatibilityEditor.SetDirty(tabButton.gameObject);
        }
Beispiel #25
0
 private static void Rename(GameObject a)
 {
     foreach (var s in a.GetComponentsInChildren <UISprite>(true))
     {
         if (s.atlas != null && s.atlas.name == "holdem_atlas")
         {
             foreach (string[] r in rename)
             {
                 if (s.spriteName.ToLower() == r[0])
                 {
                     Debug.LogFormat("{0} -> {1}", s.spriteName, r[1]);
                     s.spriteName = r[1];
                     CompatibilityEditor.SetDirty(s);
                 }
             }
         }
     }
 }
Beispiel #26
0
 private void SetDirty(UIToggle btn)
 {
     if (btn == null)
     {
         return;
     }
     CompatibilityEditor.SetDirty(btn);
     if (btn.onChange != null)
     {
         foreach (EventDelegate d in btn.onChange)
         {
             if (d.parameters.IsNotEmpty() && d.parameters[0].obj != null)
             {
                 CompatibilityEditor.SetDirty(d.parameters[0].obj);
             }
         }
     }
 }
        public void OnInspectorGUI()
        {
            bool changed = varInspector.OnInspectorGUI();

            changed |= animClipInspector.OnInspectorGUI();
            if (NGUIEditorTools.DrawHeader("Panel Event"))
            {
                NGUIEditorTools.BeginContents();
                NGUIEditorTools.DrawEvents("OnInit", window, window.onInit);
                NGUIEditorTools.DrawEvents("OnShowBegin", window, window.onShowBegin);
                NGUIEditorTools.DrawEvents("OnShowBegun", window, window.onShowBegun);
                NGUIEditorTools.DrawEvents("OnShowEnd", window, window.onShowEnd);
                NGUIEditorTools.DrawEvents("OnHideBegin", window, window.onHideBegin);
                NGUIEditorTools.DrawEvents("OnHideEnd", window, window.onHideEnd);
                NGUIEditorTools.EndContents();
            }
            if (changed)
            {
                CompatibilityEditor.SetDirty(window);
            }
        }
        void OnEnable()
        {
            this.handler            = target as ButtonHandler;
            this.drawer             = new ArrayDrawer <GameObject>(handler, "buttons");
            drawer.onInsert        += OnInsert;
            drawer.allowSceneObject = true;
            drawer.allowSelection   = false;

            // check validation
            Action <GameObject> callback = handler.OnButtonClick;
            string callbackName          = callback.Method.Name;
            bool   changed = false;

            foreach (GameObject o in handler.buttons)
            {
                if (o == null)
                {
                    Debug.LogWarning("There is null element in " + handler.transform.GetScenePath(), handler);
                }
                else
                {
                    UIButton button = o.GetComponent <UIButton>();
                    if (button == null ||
                        button.onClick.IsEmpty() ||
                        button.onClick[0].methodName != callbackName ||
                        button.onClick[0].parameters.IsEmpty() ||
                        button.onClick[0].parameters[0].obj != button.gameObject)
                    {
                        EventDelegateUtil.SetCallback(button.onClick, callback, button.gameObject);
                        CompatibilityEditor.SetDirty(button.gameObject);
                        changed = true;
                        //              EditorGUILayout.HelpBox(o.name+" is invalid", MessageType.Error);
                    }
                }
            }
            if (changed)
            {
                AssetDatabase.SaveAssets();
            }
        }
Beispiel #29
0
 private void ApplyTableToText()
 {
     // Apply modifications
     foreach (var pair in mod)
     {
         pair.Key.textKey = pair.Value;
         CompatibilityEditor.SetDirty(pair.Key);
     }
     mod.Clear();
     foreach (UIText l in labels)
     {
         if (l.textKey != null)
         {
             string trans = Lexicon.Get(l.textKey);
             if (trans.IsNotEmpty())
             {
                 l.SetText(trans);
                 CompatibilityEditor.SetDirty(l);
             }
         }
     }
 }
 private void InvalidateArray()
 {
     CompatibilityEditor.SetDirty(handler);
     foreach (GameObject o in handler.buttons)
     {
         if (o != null)
         {
             UIButton btn = o.GetComponent <UIButton>();
             if (btn == null)
             {
                 btn = o.AddComponent <UIButton>();
                 if (o.GetComponent <Collider2D>() == null)
                 {
                     BoxCollider2D col = o.AddComponent <BoxCollider2D>();
                     col.isTrigger = true;
                     NGUITools.UpdateWidgetCollider(col, false);
                 }
             }
             SetDirty(btn);
         }
     }
 }