示例#1
0
 private void ResetRightStick(Vector2 canvasPosition)
 {
     stickRightNeutralPos = canvasPosition;
     stickRightTiltedPos  = stickRightNeutralPos;
     if (stickRightBackgroundObject == null)
     {
         if (UICreator.CreateImage(stickBackgroundModel, ref stickRightBackgroundObject, ref stickRightBackgroundImage,
                                   interfaceCanvasObject))
         {
             stickRightBackgroundTrans = stickRightBackgroundObject.GetComponent <RectTransform>();
             if (stickRightBackgroundTrans == null)
             {
                 stickRightBackgroundImage = null;
                 Destroy(stickRightBackgroundObject);
                 stickRightBackgroundObject = null;
             }
         }
     }
     if (stickRightForegroundObject == null)
     {
         if (UICreator.CreateImage(stickForegroundModel, ref stickRightForegroundObject, ref stickRightForegroundImage,
                                   interfaceCanvasObject))
         {
             stickRightForegroundTrans = stickRightForegroundObject.GetComponent <RectTransform>();
             if (stickRightForegroundTrans == null)
             {
                 stickRightForegroundImage = null;
                 Destroy(stickRightForegroundObject);
                 stickRightForegroundObject = null;
             }
         }
     }
     if (stickRightBackgroundTrans != null)
     {
         stickRightBackgroundTrans.anchoredPosition = stickRightNeutralPos;
     }
     if (stickRightForegroundTrans != null)
     {
         stickRightForegroundTrans.anchoredPosition = stickRightTiltedPos;
     }
     draggingRightStick = true;
 }
示例#2
0
    /// <summary>
    /// 記事サムネイルを生成する
    /// </summary>
    /// <param name="parent"></param>
    /// <returns></returns>
    public void CreateNewsImage_200(GameObject parent, MsgBaseNewsData news)
    {
        try
        {
            //イメージを生成する
            Image image = UICreator.CreateImage(parent);

            //サイズ調整
            RectTransform rectTransform = image.GetComponent <RectTransform>();
            rectTransform.anchorMin = new Vector2(0, 1f);
            rectTransform.anchorMax = new Vector2(0, 1f);
            rectTransform.pivot     = new Vector2(0.5f, 0.5f);
            rectTransform.offsetMax = new Vector2(245, -45f);
            rectTransform.offsetMin = new Vector2(22.0f, -135f);
            rectTransform.sizeDelta = new Vector2(245, 135);

            image.GetComponent <Image>().sprite = Sprite.Create(LpsImageLoader.CreateTextureFromBinary(news.THUMBNAIL_DATA), new Rect(0, 0, news.THUMBNAIL_WIDTH, news.THUMBNAIL_HEIGHT), Vector2.zero);
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
    }
示例#3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        static EditorContextMenu()
        {
            m_commandList = new Dictionary <CommandType, Command>();

            m_commandList.Add(
                CommandType.ASSET_FILE_DUP,
                new Command(
                    new GUIContent("アセット複製"), ASSET_FILE_DUP_func, ASSET_FILE_DUP_condition));

            #region CommandType.SHOW_GUID
            m_commandList.Add(
                CommandType.SHOW_GUID,
                new Command(
                    new GUIContent("Info"),
                    (uobj) => {
                Debug.Log(uobj.name);
                var po = PrefabUtility.GetPrefabObject(uobj);
                if (po == null)
                {
                    Debug.Log("PrefabUtility.GetPrefabObject: null");
                }
                else
                {
                    Debug.Log("PrefabUtility.GetPrefabObject: " + po.name);
                }

                var pp = PrefabUtility.GetCorrespondingObjectFromSource(uobj);
                if (pp == null)
                {
                    Debug.Log("PrefabUtility.GetPrefabParent: null");
                }
                else
                {
                    Debug.Log("PrefabUtility.GetPrefabParent: " + pp.name);
                }
            },
                    (uobj) => {
                return(true);
            }));
            #endregion

            #region CommandType.ASSET2BAK
            m_commandList.Add(CommandType.ASSET2BAK,
                              new Command(
                                  new GUIContent("bakにする"),
                                  (uobj) => {
                var path = AssetDatabase.GetAssetPath(uobj);
                File.Move(path, path + ".bak");
                File.Move(path + ".meta", path + ".bak.meta");
                AssetDatabase.Refresh();
            },
                                  (uobj) => {
                return(true);
            }));
            #endregion

            #region CommandType.EDITOR_ONLY_CHILDRENS
            m_commandList.Add(CommandType.EDITOR_ONLY_CHILDRENS,
                              new Command(
                                  new GUIContent("EditorOnly Childrens"),
                                  (uobj) => {
                var gobj  = uobj as GameObject;
                var array = gobj.GetComponentsInChildren <Transform>(true)
                            .Where(c => c != gobj.transform)
                            .Select(c => c.gameObject)
                            .ToArray();

                foreach (var a in array)
                {
                    a.tag = "EditorOnly";
                }
            },
                                  (uobj) => {
                return(true);
            }));
            #endregion

            #region CommandType.SELECT_MAKE_IMAGE
#if ENABLE_UGUI
            m_commandList.Add(CommandType.SELECT_MAKE_IMAGE,
                              new Command(
                                  new GUIContent("Make Image"),
                                  (uobj) => {
                Debug.Log(uobj.name);
                Sprite spr    = uobj as Sprite;
                Texture2D tex = uobj as Texture2D;

                foreach (var item in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(uobj)))
                {
                    //フラグをすべて None にして非表示設定を解除
                    //item.hideFlags = HideFlags.None;
                    if (item.GetType() == typeof(Sprite))
                    {
                        var img    = UICreator.CreateImage();
                        img.sprite = item as Sprite;
                        img.name   = item.name;
                        img.SetNativeSize();
                    }
                }
            },
                                  (uobj) => {
                if (uobj.GetType() == typeof(Texture2D))
                {
                    return(true);
                }
                return(false);
            }));
#endif
            #endregion

            #region CommandType.SELECT_MAKE_IMAGE
#if ENABLE_UGUI
            m_commandList.Add(CommandType.SELECT_MAKE_SPRITE,
                              new Command(
                                  new GUIContent("Make Sprite"),
                                  (uobj) => {
                Debug.Log(uobj.name);
                Sprite spr    = uobj as Sprite;
                Texture2D tex = uobj as Texture2D;

                foreach (var item in AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(uobj)))
                {
                    //フラグをすべて None にして非表示設定を解除
                    //item.hideFlags = HideFlags.None;
                    if (item.GetType() == typeof(Sprite))
                    {
                        //var img = UICreator.CreateImage();
                        //img.sprite = item as Sprite;
                        //img.name = item.name;

                        EditorApplication.ExecuteMenuItem("GameObject/2D Object/Sprite");
                        var b    = Selection.activeGameObject.GetComponent <SpriteRenderer>();
                        b.sprite = item as Sprite;
                        b.name   = item.name;
                    }
                }
            },
                                  (uobj) => {
                if (uobj.GetType() == typeof(Texture2D))
                {
                    return(true);
                }
                return(false);
            }));
#endif
            #endregion

            #region CommandType.SELECT_ATTACH_SPRITE
#if ENABLE_UGUI
            m_commandList.Add(CommandType.SELECT_ATTACH_SPRITE,
                              new Command(
                                  new GUIContent("選択中のコンポーネントに設定"),
                                  (uobj) => {
                //Debug.Log( uobj.name );
                Sprite spr = uobj as Sprite;
                //Texture2D tex = uobj as Texture2D;
                var img = Selection.activeGameObject.GetComponent <Image>();
                if (img != null)
                {
                    img.sprite = spr;
                }
                //foreach( var item in AssetDatabase.LoadAllAssetsAtPath( AssetDatabase.GetAssetPath( uobj ) ) ) {
                //	//フラグをすべて None にして非表示設定を解除
                //	//item.hideFlags = HideFlags.None;
                //	if( item.GetType() == typeof( Sprite ) ) {
                //		//var img = UICreator.CreateImage();
                //		//img.sprite = item as Sprite;
                //		//img.name = item.name;

                //		EditorApplication.ExecuteMenuItem( "GameObject/2D Object/Sprite" );
                //		var b = Selection.activeGameObject.GetComponent<SpriteRenderer>();
                //		b.sprite = item as Sprite;
                //		b.name = item.name;
                //	}
                //}
            },
                                  (uobj) => {
                if (uobj.GetType() == typeof(Sprite))
                {
                    return(true);
                }
                return(false);
            }));
#endif
            #endregion

            #region CommandType.MOVE_PARENT
            m_commandList.Add(CommandType.MOVE_PARENT,
                              new Command(
                                  new GUIContent("上の階層に移動する"),
                                  (uobj) => {
                var gobj = uobj as GameObject;
                gobj.transform.parent = gobj.transform.parent.parent;
            },
                                  (uobj) => {
                return(true);
            }));
            #endregion



            // Hirarchy ウィンドウの OnGUI イベントで呼び出されるコールバックを登録します
            EditorApplication.hierarchyWindowItemOnGUI += (instanceID, selectionRect) => {
                ShowContextMenu(0);
            };

            //  OnGUI イベントごとに ProjectWindow に表示されているリスト項目ごとに呼び出されるデリゲートです
            EditorApplication.projectWindowItemOnGUI += (guid, selectionRect) => {
                ShowContextMenu(1);
            };


            /// 汎用で書けるInitializeOnLoad時の初期化がないので
            /// コンテキストとは関係ないがここに処理を挟む
            Selection.selectionChanged += () => {
                if (Selection.activeGameObject == null)
                {
                    return;
                }
                try {
                    Selection.activeGameObject.SendMessage("OnSelectionChanged", SendMessageOptions.DontRequireReceiver);
                }
                catch (Exception) {
                }
            };
        }