GetByName() public static method

Return a UIPackage with a certain name.
public static GetByName ( string name ) : UIPackage
name string Name of the package.
return UIPackage
コード例 #1
0
        void OnEnable()
        {
            if (Application.isPlaying)
            {
                CreateContainer();

                if (!string.IsNullOrEmpty(packagePath) && UIPackage.GetByName(packageName) == null)
                {
                    UIPackage.AddPackage(packagePath);
                }
            }
            else
            {
                //不在播放状态时我们不在OnEnable创建,因为Prefab也会调用OnEnable,延迟到Update里创建(Prefab不调用Update)
                //每次播放前都会disable/enable一次。。。
                if (container != null)                //如果不为null,可能是因为Prefab revert, 而不是因为Assembly reload,
                {
                    OnDestroy();
                }

                EMRenderSupport.Add(this);
                screenSizeVer     = 0;
                uiBounds.position = position;
                uiBounds.size     = cachedUISize;
                if (uiBounds.size == Vector2.zero)
                {
                    uiBounds.size = new Vector2(30, 30);
                }
            }
        }
コード例 #2
0
        void OnEnable()
        {
            if (Application.isPlaying)
            {
                CreateContainer();

                if (!string.IsNullOrEmpty(packagePath) && UIPackage.GetByName(packageName) == null)
                {
                    UIPackage.AddPackage(packagePath);
                }
            }
            else
            {
                EMRenderSupport.Add(this);
            }
        }
コード例 #3
0
ファイル: UIPanel.cs プロジェクト: miracle12am/FairyGUI-unity
        void CreateUI_EditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            DisplayOptions.SetEditModeHideFlags();
            GObject obj = UIPackage.CreateObject(packageName, componentName);
            if (obj != null && !(obj is GComponent))
            {
                obj.Dispose();
                Debug.LogWarning("Not a GComponnet: " + packageName + "/" + componentName);
                return;
            }
            _ui = (GComponent)obj;

            if (_ui != null)
            {
                _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                _ui.gameObjectName = "UI(AutoGenerated)";

                _ui.position = position;
                if (scale.x != 0 && scale.y != 0)
                {
                    _ui.scale = scale;
                }
                _ui.rotationX = rotation.x;
                _ui.rotationY = rotation.y;
                _ui.rotation  = rotation.z;
                this.container.AddChildAt(_ui.displayObject, 0);

                cachedUISize  = _ui.size;
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#else
            PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName);
            if (pi != null)
            {
                cachedUISize  = new Vector2(pi.width, pi.height);
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#endif
        }
コード例 #4
0
ファイル: UIPainter.cs プロジェクト: qutin/github-kgui-qutin
        void OnEnable()
        {
            if (Application.isPlaying)
            {
                CreateContainer();

                if (!string.IsNullOrEmpty(packagePath) && UIPackage.GetByName(packageName) == null)
                {
                    UIPackage.AddPackage(packagePath);
                }
            }
            else
            {
                if (!_renderTargets.Contains(this))
                {
                    _renderTargets.Add(this);
                }
            }
        }
コード例 #5
0
        void CreateUI_EditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

#if UNITY_5
            UIObjectFactory.packageItemExtensions.Clear();
            UIObjectFactory.loaderConstructor = null;
            DisplayOptions.SetEditModeHideFlags();

            _ui = (GComponent)UIPackage.CreateObject(packageName, componentName);

            if (_ui != null)
            {
                _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                _ui.gameObjectName = "UI(AutoGenerated)";

                _ui.position = position;
                if (scale.x != 0 && scale.y != 0)
                {
                    _ui.scale = scale;
                }
                _ui.rotationX = rotation.x;
                _ui.rotationY = rotation.y;
                _ui.rotation  = rotation.z;
                this.container.AddChildAt(_ui.displayObject, 0);

                cachedUISize  = _ui.size;
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#else
            PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName);
            if (pi != null)
            {
                cachedUISize  = new Vector2(pi.width, pi.height);
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#endif
        }
コード例 #6
0
ファイル: UIPanel.cs プロジェクト: qutin/github-kgui-qutin
        void CreateUI_EditMode()
        {
            if (!packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

#if UNITY_5
            UIObjectFactory.packageItemExtensions.Clear();
            UIObjectFactory.loaderConstructor = null;
            DisplayOptions.SetEditModeHideFlags();
            DisplayOptions.defaultRoot = new Transform[] { this.transform };
            _ui = (GComponent)UIPackage.CreateObject(packageName, componentName);
            DisplayOptions.defaultRoot = null;

            if (_ui != null)
            {
                _ui.position = position;
                if (scale.x != 0 && scale.y != 0)
                {
                    _ui.scale = scale;
                }
                _ui.rotationX = rotation.x;
                _ui.rotationY = rotation.y;
                _ui.rotation  = rotation.z;
                this.container.AddChild(_ui.displayObject);

                cachedUISize  = _ui.size;
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#else
            PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName);
            if (pi != null)
            {
                cachedUISize  = new Vector2(pi.width, pi.height);
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#endif
        }
コード例 #7
0
        void CreateUI_EditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }


            DisplayObject.hideFlags = HideFlags.DontSaveInEditor;
            GObject obj = UIPackage.CreateObject(packageName, componentName);

            if (obj != null && !(obj is GComponent))
            {
                obj.Dispose();
                Debug.LogWarning("Not a GComponnet: " + packageName + "/" + componentName);
                return;
            }
            _ui = (GComponent)obj;

            if (_ui != null)
            {
                _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                _ui.gameObjectName = "UI(AutoGenerated)";

                _ui.position = position;
                if (scale.x != 0 && scale.y != 0)
                {
                    _ui.scale = scale;
                }
                _ui.rotationX = rotation.x;
                _ui.rotationY = rotation.y;
                _ui.rotation  = rotation.z;
                this.container.AddChildAt(_ui.displayObject, 0);

                cachedUISize  = _ui.size;
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
        }
コード例 #8
0
        void CaptureInEditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

            _captured = true;

            DisplayOptions.SetEditModeHideFlags();
            GComponent view = (GComponent)UIPackage.CreateObject(packageName, componentName);

            if (view != null)
            {
                DestroyTexture();

                _texture = CaptureCamera.CreateRenderTexture(Mathf.RoundToInt(view.width), Mathf.RoundToInt(view.height), false);

                Container root = (Container)view.displayObject;
                root.layer = CaptureCamera.layer;
                root.SetChildrenLayer(CaptureCamera.layer);
                root.gameObject.hideFlags = HideFlags.None;
                root.gameObject.SetActive(true);

                GameObject cameraObject = new GameObject("Temp Capture Camera");
                Camera     camera       = cameraObject.AddComponent <Camera>();
                camera.depth         = 0;
                camera.cullingMask   = 1 << CaptureCamera.layer;
                camera.clearFlags    = CameraClearFlags.Depth;
                camera.orthographic  = true;
                camera.nearClipPlane = -30;
                camera.farClipPlane  = 30;
                camera.enabled       = false;
                camera.targetTexture = _texture;

                float halfHeight = (float)_texture.height / 2;
                camera.orthographicSize = halfHeight;
                cameraObject.transform.localPosition = root.cachedTransform.TransformPoint(halfHeight * camera.aspect, -halfHeight, 0);

                UpdateContext context = new UpdateContext();
                //run two times
                context.Begin();
                view.displayObject.Update(context);
                context.End();

                context.Begin();
                view.displayObject.Update(context);
                context.End();

                RenderTexture old = RenderTexture.active;
                RenderTexture.active = _texture;
                GL.Clear(true, true, Color.clear);
                camera.Render();
                RenderTexture.active = old;

                camera.targetTexture = null;
                view.Dispose();
                GameObject.DestroyImmediate(cameraObject);

                if (_renderer != null)
                {
                    _renderer.sharedMaterial.mainTexture = _texture;
                }
            }
        }
コード例 #9
0
ファイル: UIPanel.cs プロジェクト: uurain/MoveSyncDemo
        void OnEnable()
        {
            if (Application.isPlaying)
            {
                if (this.container == null)
                {
                    CreateContainer();

                    if (!string.IsNullOrEmpty(packagePath) && UIPackage.GetByName(packageName) == null)
                    {
                        UIPackage.AddPackage(packagePath, (string name, string extension, System.Type type) =>
                        {
#if UNITY_EDITOR
                            return(UnityEditor.AssetDatabase.LoadAssetAtPath(name + extension, type));
#else
                            return(null);
#endif
                        });

                        if (dependPkgPath != "")
                        {
                            string[] paths = dependPkgPath.Split(';');
                            for (int i = 0; i < paths.Length; ++i)
                            {
                                string path = string.Format("assets/abasset/ui/package/&{0}/{1}", paths[i], paths[i]);
                                UIPackage.AddPackage(path, (string name, string extension, System.Type type) =>
                                {
#if UNITY_EDITOR
                                    return(UnityEditor.AssetDatabase.LoadAssetAtPath(name + extension, type));
#else
                                    return(null);
#endif
                                });
                            }
                        }
                    }
                }
                else
                {
                    this.container._disabled = false;
                }
            }
            else
            {
                //不在播放状态时我们不在OnEnable创建,因为Prefab也会调用OnEnable,延迟到Update里创建(Prefab不调用Update)
                //每次播放前都会disable/enable一次。。。
                if (container != null)                //如果不为null,可能是因为Prefab revert, 而不是因为Assembly reload,
                {
                    OnDestroy();
                }

                EMRenderSupport.Add(this);
                screenSizeVer     = 0;
                uiBounds.position = position;
                uiBounds.size     = cachedUISize;
                if (uiBounds.size == Vector2.zero)
                {
                    uiBounds.size = new Vector2(30, 30);
                }
            }
        }
コード例 #10
0
ファイル: UIPainter.cs プロジェクト: qutin/github-kgui-qutin
        void CaptureInEditMode()
        {
            if (!packageListReady || UIPackage.GetByName(packageName) == null)
            {
                return;
            }

            _captured = true;
            GameObject tempGo = new GameObject("Temp Object");

            tempGo.layer = CaptureCamera.layer;

            UIObjectFactory.packageItemExtensions.Clear();
            UIObjectFactory.loaderConstructor = null;
            DisplayOptions.SetEditModeHideFlags();
            DisplayOptions.defaultRoot = new Transform[] { tempGo.transform };
            GComponent view = (GComponent)UIPackage.CreateObject(packageName, componentName);

            DisplayOptions.defaultRoot = null;

            if (view != null)
            {
                if (texture != null)
                {
                    DestroyTexture();
                }

                CreateTexture(Mathf.CeilToInt(view.width), Mathf.CeilToInt(view.height));

                Container root = (Container)view.displayObject;
                root.layer = CaptureCamera.layer;
                root.SetChildrenLayer(CaptureCamera.layer);
                root.gameObject.hideFlags = HideFlags.None;
                root.gameObject.SetActive(true);

                GameObject cameraObject = new GameObject("Temp Capture Camera");
                Camera     camera       = cameraObject.AddComponent <Camera>();
                camera.depth            = 0;
                camera.cullingMask      = 1 << CaptureCamera.layer;
                camera.clearFlags       = CameraClearFlags.Depth;
                camera.orthographic     = true;
                camera.orthographicSize = view.height / 2;
                camera.nearClipPlane    = -30;
                camera.farClipPlane     = 30;
                camera.enabled          = false;
                camera.targetTexture    = texture;

                Vector3 pos = root.cachedTransform.position;
                pos.x += camera.orthographicSize * camera.aspect;
                pos.y -= camera.orthographicSize;
                pos.z  = 0;
                cameraObject.transform.localPosition = pos;

                UpdateContext context = new UpdateContext();
                //run two times
                context.Begin();
                view.displayObject.Update(context);
                context.End();

                context.Begin();
                view.displayObject.Update(context);
                context.End();

                RenderTexture old = RenderTexture.active;
                RenderTexture.active = texture;
                GL.Clear(true, true, Color.clear);
                camera.Render();
                RenderTexture.active = old;

                camera.targetTexture = null;
                view.Dispose();
                GameObject.DestroyImmediate(cameraObject);
                GameObject.DestroyImmediate(tempGo);

                this.GetComponent <Renderer>().sharedMaterial.mainTexture = texture;
            }
        }