コード例 #1
0
    void OnSelectionChange()
    {
        if (Selection.activeObject)
        {
            System.Type _t = Selection.activeObject.GetType();
            if (!((_t.Name == "Texture2D") || (_t.Name == "GameObject")))
            {
                return;                                                                         //テクスチャ・プレハブ以外は無効
            }
            //プレハブ読み込み
            string _Path = AssetDatabase.GetAssetPath(Selection.activeObject.GetInstanceID());
            _Path = System.IO.Path.GetDirectoryName(_Path) + "/" + System.IO.Path.GetFileNameWithoutExtension(_Path);
            GameObject _Prefab = AssetDatabase.LoadAssetAtPath(_Path + ".prefab", typeof(GameObject)) as GameObject;
            if (_Prefab)
            {
                if (!_Prefab.GetComponent <PMAP>())
                {
                    return;
                }

                mFilePath = _Path;
                mLayers.Clear();
                foreach (PMAP.Layer Class in _Prefab.GetComponent <PMAP>().mLayers)
                {
                    PMAP.Layer StructTest = Class.Clone();
                    mLayers.Add(StructTest);
                }
                mAddProtect = _Prefab.GetComponent <PMAP>().mAddProtect;
                Repaint();                      //再描画
            }
        }
    }
コード例 #2
0
    public void DropAreaWindow()
    {//ウィンドウ領域内のドラッグ&ドロップ
        Rect  _Rect  = new Rect(0, 0, this.position.xMax, this.position.yMax);
        Event _Event = Event.current;

        switch (_Event.type)
        {
        case EventType.DragUpdated:
        case EventType.DragPerform:
            if (!_Rect.Contains(_Event.mousePosition))
            {
                return;
            }
            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
            if (_Event.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();
                foreach (Object _Object in DragAndDrop.objectReferences)
                {
                    if (_Object.GetType().Name == "Texture2D")
                    {                            //投げられたテクスチャを追加
                        PMAP.Layer _Layer = new PMAP.Layer();
                        _Layer.mTexture = (Texture2D)_Object;
                        mLayers.Insert(0, _Layer);
                    }
                }
            }
            break;
        }
    }
コード例 #3
0
ファイル: PMAP_Maker.cs プロジェクト: ToshiyasuMiyabe/P-MAP
 public void DropAreaWindow()
 {
     //ウィンドウ領域内のドラッグ&ドロップ
     Rect _Rect = new Rect(0, 0, this.position.xMax, this.position.yMax);
     Event _Event = Event.current;
     switch (_Event.type)
     {
         case EventType.DragUpdated:
         case EventType.DragPerform:
             if (!_Rect.Contains(_Event.mousePosition))
                 return;
             DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
             if (_Event.type == EventType.DragPerform)
             {
                 DragAndDrop.AcceptDrag();
                 foreach (Object _Object in DragAndDrop.objectReferences)
                 {
                     if(_Object.GetType().Name == "Texture2D")
                     {//投げられたテクスチャを追加
                         PMAP.Layer _Layer = new PMAP.Layer();
                         _Layer.mTexture = (Texture2D)_Object;
                         mLayers.Insert(0,_Layer);
                     }
                 }
             }
             break;
     }
 }
コード例 #4
0
    void OnGUI()
    {//GUI描画
//		float LayerW = this.position.width;
        float LayerH    = 68;
        float LayerPosY = 1;

        GUILayout.BeginVertical(GUI.skin.box);
        GUILayout.Label("テクスチャをドロップして追加");
        GUILayout.EndVertical();

        mScrollPos = GUILayout.BeginScrollView(mScrollPos, GUILayout.Width(this.position.width), GUILayout.Height(this.position.height - 100));                //スクロール開始
        int _Index       = 0;
        int _RemoveIndex = -1;
        int _InsertIndex = -1;

        foreach (PMAP.Layer _Layer in mLayers)
        {
            GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
            GUILayout.BeginHorizontal(GUI.skin.box);
            GUI.backgroundColor = Color.white;

            GUILayout.BeginVertical(GUILayout.Width(16));
            GUI.contentColor = Color.yellow;
            GUI.enabled      = (_Index != 0);
            if (GUILayout.Button("▲"))
            {                            //レイヤー上移動
                _RemoveIndex = mLayers.IndexOf(_Layer);
                _InsertIndex = _RemoveIndex - 1;
            }
            GUI.enabled = true;
            GUI.enabled = (_Index != mLayers.Count - 1);
            if (GUILayout.Button("▼"))
            {                            //レイヤー下移動
                _RemoveIndex = mLayers.IndexOf(_Layer);
                _InsertIndex = _RemoveIndex + 1;
            }
            GUI.enabled      = true;
            GUI.contentColor = Color.white;
            GUILayout.EndVertical();

            GUI.backgroundColor = new Color(0.2f, 0.2f, 0.2f);
            GUILayout.Label(_Layer.mTexture, GUI.skin.box, GUILayout.Width(LayerH), GUILayout.Height(LayerH));
            GUI.backgroundColor = Color.white;

            GUILayout.BeginVertical(GUI.skin.box);

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(_Layer.mTexture.name, EditorStyles.boldLabel);
            if (GUILayout.Button("×", GUILayout.Width(24)))
            {                            //削除ボタン
                _RemoveIndex = mLayers.IndexOf(_Layer);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(4);
//				GUILayout.Space(6);

            GUILayout.BeginHorizontal();
            GUILayout.Label("ブレンドモード", GUILayout.Width(80));
            _Layer.mBlendType = (PMAP.Layer.BlendType)GUILayout.Toolbar((int)_Layer.mBlendType, new string[] { "アルファ", "加算", "事前乗算" });
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("透明度 " + _Layer.mTransparency.ToString() + "%", GUILayout.Width(80));
            _Layer.mTransparency = (int)GUILayout.HorizontalSlider(_Layer.mTransparency, 0, 100);
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            if (_RemoveIndex >= 0)
            {            //レイヤー削除・入れ替え
                PMAP.Layer _RLayer = mLayers[_RemoveIndex];
                mLayers.Remove(_RLayer);
                if (_InsertIndex >= 0)
                {
                    mLayers.Insert(_InsertIndex, _RLayer);
                }
                Repaint();
            }

            _Index++;
            LayerPosY += LayerH + 1;
        }
        GUILayout.EndScrollView();                                                                                      //スクロール完了


        GUILayout.BeginVertical(GUI.skin.box);

        mAddProtect = GUILayout.Toggle(mAddProtect, "加算部分の保護(スプライト用)");
        GUILayout.BeginHorizontal();
        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("名前を付けて保存", GUILayout.Width(120)))
        {
            CreateTexture();
        }
        GUI.backgroundColor = Color.white;
        if (GUILayout.Button("クリア", GUILayout.Width(80)))
        {
            ClearList();
        }
        GUILayout.EndHorizontal();

        GUI.backgroundColor = Color.yellow;
        if (!string.IsNullOrEmpty(mFilePath))
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("上書き保存", GUILayout.Width(80)))
            {
                SaveTexture();
            }
            GUILayout.Label(mFilePath + ".png");
            GUILayout.EndHorizontal();
        }
        else
        {
            GUILayout.Space(21);
        }


        GUILayout.EndVertical();

        DropAreaWindow();               //ウィンドウ領域内のドラッグ&ドロップ
    }