コード例 #1
0
    /// <summary>
    /// Draws the login panel
    /// </summary>
    public void DrawPlatformLoginPanel(HomeController controller, GUISkin skin)
    {
        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        EditorGUILayout.BeginVertical();
        EditorGUILayout.LabelField(new GUIContent("SELECT PLATFORM"), skin.GetStyle("Subtitle"));
        EditorStyles.popup.fixedHeight = 30;
        EditorStyles.popup.fontSize    = 12;

        if (!controller.IsDevMode)
        {
            controller.PlatformSelection = EditorGUILayout.Popup(controller.PlatformSelection, controller.PlatformType, GUILayout.Width(300), GUILayout.Height(30));
        }
        else
        {
            controller.PlatformSelection = EditorGUILayout.Popup(controller.PlatformSelection, controller.PlatformTypeDev, GUILayout.Width(300), GUILayout.Height(30));
        }

        EditorStyles.popup.fixedHeight = 15;
        EditorStyles.popup.fontSize    = 11;
        GUILayout.Space(20);

        if (!controller.IsDevMode)
        {
            switch (controller.PlatformSelection)
            {
            case 0:
                controller.LoginInfo.apiurl = "https://kovan.cloud.enjin.io/";
                break;

            case 1:
                if (controller.IsLoginStatus(LoginState.INVALIDTPURL))
                {
                    EditorGUILayout.LabelField(new GUIContent("PLEASE PROVIDE VALID PLATFORM URL"), skin.GetStyle("SubtitleRed"));
                }
                else
                {
                    EditorGUILayout.LabelField(new GUIContent("CUSTOM PLATFORM URL"), skin.GetStyle("Subtitle"));
                }

                controller.LoginInfo.apiurl = EditorGUILayout.TextField(controller.LoginInfo.apiurl, skin.textField, GUILayout.Width(300), GUILayout.Height(30));
                GUILayout.Space(20);
                break;
            }
        }
        else
        {
            switch (controller.PlatformSelection)
            {
            case 0:
                controller.LoginInfo.apiurl = "https://master.cloud.enjin.dev/";
                break;

            case 1:
                controller.LoginInfo.apiurl = "https://kovan.cloud.enjin.io/";
                break;

            case 2:
                controller.LoginInfo.apiurl = "https://update-smart-contracts.cloud.enjin.dev/";
                break;

            case 3:
                if (controller.IsLoginStatus(LoginState.INVALIDTPURL))
                {
                    EditorGUILayout.LabelField(new GUIContent("PLEASE PROVIDE VALID PLATFORM URL"), skin.GetStyle("SubtitleRed"));
                }
                else
                {
                    EditorGUILayout.LabelField(new GUIContent("CUSTOM PLATFORM URL"), skin.GetStyle("Subtitle"));
                }

                controller.LoginInfo.apiurl = EditorGUILayout.TextField(controller.LoginInfo.apiurl, skin.textField, GUILayout.Width(300), GUILayout.Height(30));
                GUILayout.Space(20);
                break;

            case 4:
                controller.LoginInfo.apiurl = "https://cloud.enjin.io/";
                break;

            case 5:
                Debug.LogWarning("[WARNING] This feature is not available at this time. Reverting to Kovan Testnet");
                controller.PlatformSelection = 0;
                break;
            }
        }

        EditorGUILayout.LabelField(new GUIContent("EMAIL"), skin.GetStyle("Subtitle"));
        GUI.SetNextControlName("emailField");
        controller.LoginInfo.username = EditorGUILayout.TextField(controller.LoginInfo.username, skin.textField, GUILayout.Width(300), GUILayout.Height(30));
        GUILayout.Space(20);
        EditorGUILayout.LabelField(new GUIContent("PASSWORD"), skin.GetStyle("Subtitle"));
        GUI.SetNextControlName("passField");
        controller.LoginInfo.password = EditorGUILayout.PasswordField(controller.LoginInfo.password, skin.textField, GUILayout.Width(300), GUILayout.Height(30));

        if (Event.current.isKey && Event.current.keyCode == KeyCode.Return)
        {
            if (GUI.GetNameOfFocusedControl() == "emailField")
            {
                EditorGUI.FocusTextInControl("passField");
            }
            else if (GUI.GetNameOfFocusedControl() == "passField")
            {
                GUI.FocusControl(null);
                ProcessLogin(controller);
            }
        }

        GUILayout.Space(30);
        EditorGUILayout.BeginHorizontal(GUILayout.Width(300));

        if (GUILayout.Button(new GUIContent("SIGN UP"), GUILayout.Height(36)))
        {
            Application.OpenURL(controller.LoginInfo.apiurl);
        }

        GUILayout.Space(8);

        if (GUILayout.Button(new GUIContent("LOGIN"), GUILayout.Height(36)))
        {
            GUI.FocusControl(null);
            ProcessLogin(controller);
        }

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(14);

        if (controller.IsLoginStatus(LoginState.INVALIDUSERPASS))
        {
            EditorGUILayout.BeginHorizontal(GUILayout.Width(300));
            GUILayout.FlexibleSpace();
            EditorGUILayout.LabelField(new GUIContent("USERNAME OR PASSWORD IS INCORRECT"), skin.GetStyle("SubtitleRed"), GUILayout.Width(250));
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(10);
        }

        EditorGUILayout.BeginHorizontal(GUILayout.Width(300));
        GUILayout.FlexibleSpace();

        if (GUILayout.Button(new GUIContent("FORGOT PASSWORD"), GUILayout.Width(160)))
        {
            Application.OpenURL(controller.LoginInfo.apiurl + "#/reset");
        }

        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
    }
コード例 #2
0
    protected void EditMenuItem(CtxMenu.Item item, UIAtlas atlas)
    {
        if (item == null)
        {
            return;
        }

        GUILayoutOption[] itemSpriteOpt    = { GUILayout.Height(16f), GUILayout.Width(140f) };
        GUILayoutOption[] itemSpriteDelOpt = { GUILayout.Height(16f), GUILayout.Width(60f) };

        Color normalColor, disabledColor;

        Rect box = EditorGUILayout.BeginVertical();

        GUILayout.Space(4f);
        GUI.Box(box, "");

        EditorGUILayout.BeginHorizontal();
        item.isSelected = EditorGUILayout.Toggle(item.isSelected, GUILayout.Width(12f));

        EditorGUIUtility.labelWidth = 64f;
        CtxMenu.ItemStyle itemStyle = (CtxMenu.ItemStyle)EditorGUILayout.EnumFlagsField("Style", item.style,
                                                                                        GUILayout.Width(188f));

        if (item.style != itemStyle)
        {
            RegisterUndo();

            bool wasSubmenu = item.isSubmenu;

            item.style = itemStyle;

            if (item.isSubmenu && !wasSubmenu)
            {
                item.id = -1;
            }
        }

        if (item.isCheckable)
        {
            EditorGUIUtility.labelWidth = 44f;
            int mutexGroup = EditorGUILayout.IntField("Mutex", item.mutexGroup, GUILayout.Width(88f));
            if (mutexGroup != item.mutexGroup)
            {
                RegisterUndo();
                item.mutexGroup = mutexGroup;
            }
        }

        EditorGUIUtility.labelWidth = 80f;
        EditorGUILayout.EndHorizontal();

        if ((item.style & CtxMenu.ItemStyle.Separator) != (CtxMenu.ItemStyle) 0)
        {
            item.id = -1;
        }
        else
        {
            EditorGUILayout.BeginHorizontal();
            string text = EditorGUILayout.TextField("    Text", item.text, GUILayout.Width(204f));
            if (item.text != text)
            {
                RegisterUndo();
                item.text = text;
            }

            EditorGUIUtility.labelWidth = 32f;
            GUILayout.Space(12f);
            int itemId = EditorGUILayout.IntField("ID", item.id, GUILayout.Width(76f));
            if (item.id != itemId)
            {
                RegisterUndo();
                item.id = itemId;
            }
            EditorGUIUtility.labelWidth = 80f;

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("    Icon", GUILayout.Width(76f));

            string iconTitle = item.icon;
            if (string.IsNullOrEmpty(iconTitle))
            {
                iconTitle = "...";
            }

            if (GUILayout.Button(iconTitle, itemSpriteOpt))
            {
                currentItem        = item;
                NGUISettings.atlas = atlas;
                SpriteSelector.Show(OnItemIcon);
            }

            GUILayout.Space(12f);
            if (GUILayout.Button("None", itemSpriteDelOpt))
            {
                if (!string.IsNullOrEmpty(item.icon))
                {
                    RegisterUndo();
                }

                item.icon = "";
            }

            EditorGUILayout.EndHorizontal();

            if (!string.IsNullOrEmpty(item.icon))
            {
                EditorGUILayout.BeginHorizontal();
                normalColor = EditorGUILayout.ColorField("    Normal", item.spriteColor, GUILayout.Width(140f));
                if (normalColor != item.spriteColor)
                {
                    RegisterUndo();
                    item.spriteColor = normalColor;
                }
                GUILayout.Space(32f);
                disabledColor = EditorGUILayout.ColorField("Disabled", item.spriteColorDisabled, GUILayout.Width(140f));
                if (item.spriteColorDisabled != disabledColor)
                {
                    RegisterUndo();
                    item.spriteColorDisabled = disabledColor;
                }
                EditorGUILayout.EndHorizontal();
            }

            if (item.isSubmenu)
            {
                CtxMenu submenu = (CtxMenu)EditorGUILayout.ObjectField("    Submenu", item.submenu, typeof(CtxMenu), true, GUILayout.Width(317f));
                if (item.submenu != submenu)
                {
                    RegisterUndo();
                    item.submenu = submenu;

#if CTX_NO_SERIALIZATION_FIX
                    if (submenu.items == null || submenu.items.Length == 0)
                    {
                        Debug.Log("Wizzy Submenu Item Transfer Test!!!!");

                        if (item.submenuItems != null && item.submenuItems.Length > 0)
                        {
                            Debug.Log("Wizzy Submenu Item Transfer!!!!");
                            submenu.items     = item.submenuItems;
                            item.submenuItems = null;

                            EditorUtility.SetDirty(submenu);
                            EditorUtility.SetDirty(target);
                        }
                    }
#endif
                }

                if (submenu != null)
#if CTX_NO_SERIALIZATION_FIX
                { EditMenuItemList(ref item.submenuItems, submenu.atlas, false, ref item.isEditingItems); }
#else
                { EditMenuItemList(ref submenu.items, submenu.atlas, false, ref item.isEditingItems); }
#endif
            }
        }

        GUILayout.Space(4f);
        EditorGUILayout.EndVertical();
        GUILayout.Space(4f);
    }
コード例 #3
0
        public override void ShowGUI(MenuSource source)
        {
            EditorGUILayout.BeginVertical("Button");

            fixedOption = EditorGUILayout.Toggle("Fixed option number?", fixedOption);
            if (fixedOption)
            {
                numSlots     = 1;
                slotSpacing  = 0f;
                optionToShow = EditorGUILayout.IntField("Option to display:", optionToShow);
            }
            else
            {
                maxSlots = EditorGUILayout.IntField("Max no. of slots:", maxSlots);

                if (source == MenuSource.AdventureCreator)
                {
                    numSlots    = EditorGUILayout.IntSlider("Test slots:", numSlots, 1, maxSlots);
                    slotSpacing = EditorGUILayout.Slider("Slot spacing:", slotSpacing, 0f, 20f);
                    orientation = (ElementOrientation)EditorGUILayout.EnumPopup("Slot orientation:", orientation);
                    if (orientation == ElementOrientation.Grid)
                    {
                        gridWidth = EditorGUILayout.IntSlider("Grid size:", gridWidth, 1, 10);
                    }
                }
            }

            if (source == MenuSource.AdventureCreator)
            {
                anchor      = (TextAnchor)EditorGUILayout.EnumPopup("Text alignment:", anchor);
                textEffects = (TextEffects)EditorGUILayout.EnumPopup("Text effect:", textEffects);
            }

            displayType = (SaveDisplayType)EditorGUILayout.EnumPopup("Display:", displayType);
            if (displayType != SaveDisplayType.LabelOnly)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Empty slot texture:", GUILayout.Width(145f));
                blankSlotTexture = (Texture2D)EditorGUILayout.ObjectField(blankSlotTexture, typeof(Texture2D), false, GUILayout.Width(70f), GUILayout.Height(30f));
                EditorGUILayout.EndHorizontal();
            }
            saveListType = (AC_SaveListType)EditorGUILayout.EnumPopup("List type:", saveListType);
            if (saveListType == AC_SaveListType.Save)
            {
                showNewSaveOption = EditorGUILayout.Toggle("Show 'New save' option?", showNewSaveOption);
                if (showNewSaveOption)
                {
                    newSaveText = EditorGUILayout.TextField("'New save' text:", newSaveText);
                }
                autoHandle = EditorGUILayout.Toggle("Save when click on?", autoHandle);
                if (autoHandle)
                {
                    ActionListGUI("ActionList after saving:");
                }
                else
                {
                    ActionListGUI("ActionList when click:");
                }
            }
            else if (saveListType == AC_SaveListType.Load)
            {
                autoHandle = EditorGUILayout.Toggle("Load when click on?", autoHandle);
                if (autoHandle)
                {
                    ActionListGUI("ActionList after loading:");
                }
                else
                {
                    ActionListGUI("ActionList when click:");
                }
            }
            else if (saveListType == AC_SaveListType.Import)
            {
                autoHandle = true;
                                #if UNITY_STANDALONE
                importProductName  = EditorGUILayout.TextField("Import project name:", importProductName);
                importSaveFilename = EditorGUILayout.TextField("Import save filename:", importSaveFilename);
                ActionListGUI("ActionList after import:");
                checkImportBool = EditorGUILayout.Toggle("Require Bool to be true?", checkImportBool);
                if (checkImportBool)
                {
                    checkImportVar = EditorGUILayout.IntField("Global Variable ID:", checkImportVar);
                }
                                #else
                EditorGUILayout.HelpBox("This feature is only available for standalone platforms (PC, Mac, Linux)", MessageType.Warning);
                                #endif
            }

            if (source != MenuSource.AdventureCreator)
            {
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical("Button");
                uiHideStyle = (UIHideStyle)EditorGUILayout.EnumPopup("When invisible:", uiHideStyle);
                EditorGUILayout.LabelField("Linked button objects", EditorStyles.boldLabel);

                if (fixedOption)
                {
                    uiSlots = ResizeUISlots(uiSlots, 1);
                }
                else
                {
                    uiSlots = ResizeUISlots(uiSlots, maxSlots);
                }

                for (int i = 0; i < uiSlots.Length; i++)
                {
                    uiSlots[i].LinkedUiGUI(i, source);
                }
            }

            EditorGUILayout.EndVertical();

            base.ShowGUI(source);
        }
コード例 #4
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginVertical("Box");
        if (manager)
        {
            EditorGUILayout.LabelField("寻路单元格大小", manager.BaseCellSize.ToString());
        }
        else
        {
            EditorGUILayout.HelpBox("未找到A*管理器对象!", MessageType.Warning);
        }
        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(unitSize, new GUIContent("单位大小"));
        if (unitSize.vector2IntValue.x < 1)
        {
            unitSize.vector2IntValue = new Vector2Int(1, unitSize.vector2IntValue.y);
        }
        if (unitSize.vector2IntValue.y < 1)
        {
            unitSize.vector2IntValue = new Vector2Int(unitSize.vector2IntValue.x, 1);
        }
        if (manager)
        {
            EditorGUILayout.LabelField("单位实际大小", string.Format("宽: {0} 高: {1}",
                                                               (manager.BaseCellSize * unitSize.vector2IntValue.x).ToString(), (manager.BaseCellSize * unitSize.vector2IntValue.y).ToString()));
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical("Box");
        EditorGUILayout.PropertyField(footOffset, new GUIContent("自身脚部偏移"));
        EditorGUILayout.PropertyField(fixedOffset, new GUIContent("近似位置修正值"));
        if (fixedOffset.floatValue < 0)
        {
            fixedOffset.floatValue = 0;
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical("Box");
        if (Application.isPlaying)
        {
            GUI.enabled = false;
            EditorGUILayout.PropertyField(target, new GUIContent("跟随目标(可选)"));
            GUI.enabled = true;
        }
        else
        {
            EditorGUILayout.PropertyField(target, new GUIContent("跟随目标(可选)"));
        }
        if (target.objectReferenceValue)
        {
            if ((target.objectReferenceValue as Transform) != unit.transform)
            {
                EditorGUILayout.PropertyField(targetFootOffset, new GUIContent("目标脚部偏移"));
                EditorGUILayout.PropertyField(targetFollowStartDistance, new GUIContent("目标开始跟随距离"));
                if (Application.isPlaying)
                {
                    GUI.enabled = false;
                }
                EditorGUILayout.PropertyField(repathRate, new GUIContent("目标位置刷新频率(秒)"));
                if (Application.isPlaying)
                {
                    GUI.enabled = true;
                }
            }
            else
            {
                EditorGUILayout.HelpBox("跟随目标是自身!", MessageType.Warning);
            }
        }
        if (targetFollowStartDistance.floatValue < 0)
        {
            targetFollowStartDistance.floatValue = 0;
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical("Box");
        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }
        EditorGUILayout.PropertyField(moveMode, new GUIContent("移动方式"));
        if (Application.isPlaying)
        {
            GUI.enabled = true;
        }
        if (moveMode.enumValueIndex == 1)
        {
            if (!manager)
            {
                if (!rigidbody2D.objectReferenceValue)
                {
                    EditorGUILayout.PropertyField(rigidbody, new GUIContent("刚体"));
                    if (rigidbody.objectReferenceValue)
                    {
                        EditorGUILayout.PropertyField(turnSpeed, new GUIContent("转向速度"));
                        EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
                    }
                }
                if (!rigidbody.objectReferenceValue)
                {
                    EditorGUILayout.PropertyField(rigidbody2D, new GUIContent("2D 刚体"));
                    if (rigidbody2D.objectReferenceValue)
                    {
                        EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
                    }
                }
            }
            else
            {
                if (manager.ThreeD)
                {
                    EditorGUILayout.PropertyField(rigidbody, new GUIContent("刚体"));
                    if (rigidbody.objectReferenceValue)
                    {
                        EditorGUILayout.PropertyField(turnSpeed, new GUIContent("转向速度"));
                        EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
                    }
                }
                else
                {
                    EditorGUILayout.PropertyField(rigidbody2D, new GUIContent("2D 刚体"));
                    if (rigidbody2D.objectReferenceValue)
                    {
                        EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
                    }
                }
            }
        }
        else if (moveMode.enumValueIndex == 2)
        {
            EditorGUILayout.PropertyField(controller, new GUIContent("控制器"));
            if (controller.objectReferenceValue)
            {
                EditorGUILayout.PropertyField(turnSpeed, new GUIContent("转向速度"));
                EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
            }
        }
        else
        {
            if (manager && manager.ThreeD || !manager)
            {
                EditorGUILayout.PropertyField(turnSpeed, new GUIContent("转向速度"));
            }
            EditorGUILayout.PropertyField(moveSpeed, new GUIContent("移动速度"));
        }
        if (moveSpeed.floatValue < 0.01f)
        {
            moveSpeed.floatValue = 0.01f;
        }
        if (manager && manager.ThreeD || !manager)
        {
            slopeLimit.floatValue = EditorGUILayout.Slider("最大移动坡度", slopeLimit.floatValue, 0, 90);
        }
        EditorGUILayout.PropertyField(stopDistance, new GUIContent("提前停止距离"));
        if (stopDistance.floatValue < 0)
        {
            stopDistance.floatValue = 0;
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.BeginVertical("Box");
        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }
        EditorGUILayout.PropertyField(animator, new GUIContent("动画控制器(可选)"));
        if (animator.objectReferenceValue)
        {
            EditorGUILayout.PropertyField(animaHorizontal, new GUIContent("动画水平参数"));
            EditorGUILayout.PropertyField(animaVertical, new GUIContent("动画控垂直参数"));
            EditorGUILayout.PropertyField(animaMagnitude, new GUIContent("动画模参数"));
        }
        if (Application.isPlaying)
        {
            GUI.enabled = true;
        }
        EditorGUILayout.EndVertical();


        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(pathRenderer, new GUIContent("路线渲染器(可选)"));
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(drawGizmos, new GUIContent("绘制Gizmos"));
        if (drawGizmos.boolValue)
        {
            EditorGUILayout.PropertyField(lineColor, new GUIContent("连线颜色"));
            EditorGUILayout.PropertyField(pointColor, new GUIContent("折点颜色"));
        }
        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }
コード例 #5
0
        protected override void OnCustomInspectorGUI(params CustomOverrideProperty[] extraOverride)
        {
            base.OnCustomInspectorGUI(extraOverride);

            serializedObject.Update();
            overrides = extraOverride;

            // Can't go below 0
            if (cooldownTime.floatValue < 0.0f)
            {
                cooldownTime.floatValue = 0.0f;
            }

            GUI.color = Color.yellow;
            var item = (InventoryItemBase)target;

            if (item.gameObject.activeInHierarchy && item.rarity != null && item.rarity.dropObject != null)
            {
                if (GUILayout.Button("Convert to drop object"))
                {
                    var dropObj      = item.rarity.dropObject;
                    var dropInstance = (GameObject)PrefabUtility.InstantiatePrefab(dropObj.gameObject);
                    var itemTrigger  = dropInstance.AddComponent <ItemTrigger>();

                    var t = target;
                    if (t == null)
                    {
                        t = PrefabUtility.GetCorrespondingObjectFromSource(t);
                    }

                    string path  = AssetDatabase.GetAssetPath(t);
                    var    asset = (GameObject)AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
                    if (asset != null)
                    {
                        itemTrigger.itemPrefab = asset.GetComponent <InventoryItemBase>();

                        dropInstance.transform.SetParent(item.transform.parent);
                        dropInstance.transform.SetSiblingIndex(item.transform.GetSiblingIndex());
                        dropInstance.transform.position = item.transform.position;
                        dropInstance.transform.rotation = item.transform.rotation;

                        Selection.activeGameObject = itemTrigger.gameObject;

                        item.StartCoroutine(DestroyImmediateThis(item));
                    }

                    return;
                }
            }
            GUI.color = Color.white;

            if (target == null)
            {
                return;
            }

            var excludeList = new List <string>()
            {
                "m_Script",
                id.name,
                itemName.name,
                description.name,
                stats.name,
                usageRequirements.name,
                useCategoryCooldown.name,
                overrideDropObjectPrefab.name,
                category.name,
                icon.name,
                weight.name,
                layoutSizeCols.name,
                layoutSizeRows.name,
                requiredLevel.name,
                rarity.name,
                buyPrice.name,
                sellPrice.name,
                isDroppable.name,
                isSellable.name,
                isStorable.name,
                maxStackSize.name,
                cooldownTime.name,
            };

            GUILayout.Label("Default", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);
            if (FindOverride(id.name) != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.LabelField("ID: ", id.intValue.ToString());
            GUI.enabled = true;

            if (FindOverride(itemName.name) != null)
            {
                GUI.enabled = false;
            }

            GUI.SetNextControlName("ItemEditor_itemName");
            EditorGUILayout.PropertyField(itemName);

            GUI.enabled = true;

            if (FindOverride(description.name) != null)
            {
                GUI.enabled = false;
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Description", GUILayout.Width(EditorGUIUtility.labelWidth - 5));
            EditorGUILayout.BeginVertical();
            EditorGUILayout.HelpBox("Note, that you can use rich text like <b>asd</b> to write bold text and <i>Potato</i> to write italic text.", MessageType.Info);
            description.stringValue = EditorGUILayout.TextArea(description.stringValue, EditorStyles.richTextArea);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();


            GUI.enabled = true;

            EditorGUILayout.PropertyField(icon);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Item layout");

            EditorGUILayout.BeginVertical();
            for (int i = 1; i < 7; i++)
            {
                EditorGUILayout.BeginHorizontal();
                for (int j = 1; j < 7; j++)
                {
                    if (layoutSizeCols.intValue < j || layoutSizeRows.intValue < i)
                    {
                        GUI.color = Color.gray;
                    }

                    var c = new GUIStyle("CN Box");
                    c.alignment = TextAnchor.MiddleCenter;
                    if (GUILayout.Button(j + " X " + i, c, GUILayout.Width(40), GUILayout.Height(40)))
                    {
                        layoutSizeCols.intValue = j;
                        layoutSizeRows.intValue = i;
                    }

                    GUI.color = Color.white;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            if (item.icon != null)
            {
                var a = item.icon.bounds.size.x / item.icon.bounds.size.y;
                var b = (float)item.layoutSizeCols / item.layoutSizeRows;

                if (Mathf.Approximately(a, b) == false)
                {
                    EditorGUILayout.HelpBox("Layout size is different from icon aspect ratio.", MessageType.Warning);
                }
            }

#if RELATIONS_INSPECTOR
            if (GUILayout.Button("Show relations", GUILayout.ExpandWidth(false)))
            {
                EditorWindow
                .GetWindow <RelationsInspector.RelationsInspectorWindow>()
                .GetAPI1
                .ResetTargets(new[] { t }, typeof(RelationsInspector.InventoryProBackends.ItemBackend));
            }
#endif


            EditorGUILayout.EndVertical();

            // Draws remaining items
            GUILayout.Label("Item specific", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            foreach (var x in extraOverride)
            {
                if (x.action != null)
                {
                    x.action();
                }

                excludeList.Add(x.serializedName);
            }

            DrawPropertiesExcluding(serializedObject, excludeList.ToArray());
            EditorGUILayout.EndVertical();

            #region Properties

            GUILayout.Label("Item stats", EditorStyles.titleStyle);
            GUILayout.Label("You can create stats in the Item editor / Item stats editor");

            EditorGUILayout.BeginVertical();
            _statsList.DoLayoutList();
            EditorGUILayout.EndVertical();


            GUILayout.Label("Usage requirement stats", EditorStyles.titleStyle);
            GUILayout.Label("Add stats the user is required to have in order to use this item.");
            GUILayout.Label("Example: Usage stat of 10 strength means:");
            GUILayout.Label("The user can only use this item if he/she has 10 or more strength.");

            EditorGUILayout.BeginVertical();
            _usageRequirementList.DoLayoutList();
            EditorGUILayout.EndVertical();

            #endregion

            GUILayout.Label("Behavior", EditorStyles.titleStyle);
            EditorGUILayout.BeginVertical(EditorStyles.boxStyle);

            GUILayout.Label("Details", EditorStyles.titleStyle);
            if (rarity.objectReferenceValue != null)
            {
                var color = ((ItemRarity)rarity.objectReferenceValue).color;
                color.a   = 1.0f; // Ignore alpha in the editor.
                GUI.color = color;
            }

            ObjectPickerUtility.RenderObjectPickerForType <ItemRarity>(rarity);
            GUI.color = Color.white;

            ObjectPickerUtility.RenderObjectPickerForType <ItemCategory>(category);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(useCategoryCooldown);
            if (useCategoryCooldown.boolValue)
            {
                if (category.objectReferenceValue != null)
                {
                    var c = (ItemCategory)category.objectReferenceValue;
                    EditorGUILayout.LabelField(string.Format("({0} seconds)", c.cooldownTime));
                }
            }

            EditorGUILayout.EndHorizontal();
            if (useCategoryCooldown.boolValue == false)
            {
                EditorGUILayout.PropertyField(cooldownTime);
            }


            EditorGUILayout.PropertyField(overrideDropObjectPrefab);

            GameObject dropPrefab = null;
            if (overrideDropObjectPrefab.objectReferenceValue != null)
            {
                EditorGUILayout.HelpBox("Overriding drop object to: " + overrideDropObjectPrefab.objectReferenceValue.name, MessageType.Info);
                dropPrefab = (GameObject)overrideDropObjectPrefab.objectReferenceValue;
            }
            else if (item.rarity != null && item.rarity.dropObject != null)
            {
                EditorGUILayout.HelpBox("Using rarity drop object: " + item.rarity.dropObject.name, MessageType.Info);
                dropPrefab = item.rarity.dropObject;
            }
            else
            {
                EditorGUILayout.HelpBox("No drop object set.", MessageType.Info);
                dropPrefab = item.gameObject;
            }

            if (dropPrefab.GetComponentsInChildren <Collider>(true).Any(o => o.isTrigger) == false && dropPrefab.GetComponentsInChildren <Collider2D>(true).Any(o => o.isTrigger) == false)
            {
                EditorGUILayout.HelpBox("Drop object has no triggers and therefore can never be picked up!", MessageType.Error);
            }


            GUILayout.Label("Buying & Selling", EditorStyles.titleStyle);
//            EditorGUILayout.BeginHorizontal();
//            EditorGUILayout.LabelField("Buy price", GUILayout.Width(EditorStyles.labelWidth));
            EditorGUILayout.PropertyField(buyPrice);
//            EditorGUILayout.EndHorizontal();

//            EditorGUILayout.BeginHorizontal();
//            EditorGUILayout.LabelField("Sell price", GUILayout.Width(EditorStyles.labelWidth));
            EditorGUILayout.PropertyField(sellPrice);
//            EditorGUILayout.EndHorizontal();

            GUILayout.Label("Restrictions", EditorStyles.titleStyle);
            EditorGUILayout.PropertyField(isDroppable);
            EditorGUILayout.PropertyField(isSellable);
            EditorGUILayout.PropertyField(isStorable);
            EditorGUILayout.PropertyField(maxStackSize);
            EditorGUILayout.PropertyField(weight);
            EditorGUILayout.PropertyField(requiredLevel);

            EditorGUILayout.EndVertical();


            serializedObject.ApplyModifiedProperties();
        }
コード例 #6
0
    //自作クラス配列用フィールド===============================================
    private void ClassArrField(SerializedProperty aspClssArr, string aFoldoutCntent,
                               ref bool aFoldut, UnityAction <SerializedProperty, int> aClassField)
    {
        SerializedProperty spArr = aspClssArr;
        bool fAddBtt             = false; //要素追加ボタン
        bool fSubBtt             = false; //要素削除ボタン
        int  indexBff            = 0;     //要素数一時保存

        //三角
        Rect folRect = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight);

        aFoldut = EditorGUI.Foldout(new Rect(folRect.x, folRect.y, 0, folRect.height), aFoldut, "");
        if (GUI.Button(folRect, aFoldoutCntent, EditorStyles.label))
        {
            aFoldut = !aFoldut;
        }

        if (aFoldut)
        {
            EditorGUI.indentLevel++;
            //配列サイズ
            spArr.arraySize = EditorGUILayout.IntField("Length", spArr.arraySize);
            if (spArr.arraySize <= 0)
            {
                EditorGUI.indentLevel--;
                return;
            }

            //要素
            for (int i = 0; i < spArr.arraySize; i++)
            {
                EditorGUILayout.BeginVertical("box");

                GUILayout.Label("Element " + i);
                aClassField(spArr.GetArrayElementAtIndex(i), i);

                //配列を追加/削除ボタン
                Rect r   = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight);
                Rect br1 = new Rect(r.width - 20, r.y, 30, r.height);
                Rect br2 = new Rect(r.width - 60, r.y, 30, r.height);
                GUILayout.BeginHorizontal();
                if (GUI.Button(br1, "-"))
                {
                    fSubBtt = true; indexBff = i;
                }
                if (GUI.Button(br2, "+"))
                {
                    fAddBtt = true; indexBff = i;
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.Space();
                EditorGUILayout.EndVertical();
            }

            EditorGUI.indentLevel--;
        }

        if (fAddBtt)
        {
            spArr.InsertArrayElementAtIndex(indexBff);
        }
        if (fSubBtt)
        {
            spArr.DeleteArrayElementAtIndex(indexBff);
        }
    }
コード例 #7
0
    public override void OnInspectorGUI()
    {
        InitializeInspector();

        if (spriteCollectionIndex == null || allSpriteCollectionNames == null)
        {
            GUILayout.Label("data not found");
            if (GUILayout.Button("Refresh"))
            {
                initialized = false;
                InitializeInspector();
            }
            return;
        }

        tk2dSpriteAnimation anim = (tk2dSpriteAnimation)target;

        EditorGUI.indentLevel++;
        EditorGUILayout.BeginVertical();

        if (anim.clips.Length == 0)
        {
            if (GUILayout.Button("Add clip"))
            {
                anim.clips           = new tk2dSpriteAnimationClip[1];
                anim.clips[0]        = new tk2dSpriteAnimationClip();
                anim.clips[0].name   = "New Clip 0";
                anim.clips[0].frames = new tk2dSpriteAnimationFrame[1];

                anim.clips[0].frames[0] = new tk2dSpriteAnimationFrame();
                var spriteCollection = tk2dSpriteGuiUtility.GetDefaultSpriteCollection();
                anim.clips[0].frames[0].spriteCollection = spriteCollection;
                anim.clips[0].frames[0].spriteId         = spriteCollection.FirstValidDefinitionIndex;
            }
        }
        else         // has anim clips
        {
            // All clips
            string[] allClipNames = new string[anim.clips.Length];
            for (int i = 0; i < anim.clips.Length; ++i)
            {
                allClipNames[i] = anim.clips[i].name;
            }
            currentClip = Mathf.Clamp(currentClip, 0, anim.clips.Length);

            #region AddAndDeleteClipButtons
            EditorGUILayout.BeginHorizontal();
            currentClip = EditorGUILayout.Popup("Clips", currentClip, allClipNames);

            // Add new clip
            if (GUILayout.Button("+", GUILayout.MaxWidth(28), GUILayout.MaxHeight(14)))
            {
                int previousClipId = currentClip;

                // try to find an empty slot
                currentClip = -1;
                for (int i = 0; i < anim.clips.Length; ++i)
                {
                    if (anim.clips[i].name.Length == 0)
                    {
                        currentClip = i;
                        break;
                    }
                }

                if (currentClip == -1)
                {
                    tk2dSpriteAnimationClip[] clips = new tk2dSpriteAnimationClip[anim.clips.Length + 1];
                    for (int i = 0; i < anim.clips.Length; ++i)
                    {
                        clips[i] = anim.clips[i];
                    }
                    currentClip        = anim.clips.Length;
                    clips[currentClip] = new tk2dSpriteAnimationClip();
                    anim.clips         = clips;
                }

                string uniqueName = "New Clip ";
                int    uniqueId   = 0;
                for (int i = 0; i < anim.clips.Length; ++i)
                {
                    string uname = uniqueName + uniqueId.ToString();
                    if (anim.clips[i].name == uname)
                    {
                        uniqueId++;
                        i = -1;
                        continue;
                    }
                }

                anim.clips[currentClip]          = new tk2dSpriteAnimationClip();
                anim.clips[currentClip].name     = uniqueName + uniqueId.ToString();
                anim.clips[currentClip].fps      = 15;
                anim.clips[currentClip].wrapMode = tk2dSpriteAnimationClip.WrapMode.Loop;
                anim.clips[currentClip].frames   = new tk2dSpriteAnimationFrame[1];
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                if (previousClipId < anim.clips.Length &&
                    anim.clips[previousClipId] != null &&
                    anim.clips[previousClipId].frames != null &&
                    anim.clips[previousClipId].frames.Length != 0 &&
                    anim.clips[previousClipId].frames[anim.clips[previousClipId].frames.Length - 1] != null &&
                    anim.clips[previousClipId].frames[anim.clips[previousClipId].frames.Length - 1].spriteCollection != null)
                {
                    var previousClip = anim.clips[previousClipId];
                    var lastFrame    = previousClip.frames[previousClip.frames.Length - 1];
                    frame.spriteCollection = lastFrame.spriteCollection;
                    frame.spriteId         = lastFrame.spriteId;
                }
                else
                {
                    var spriteCollection = tk2dSpriteGuiUtility.GetDefaultSpriteCollection();
                    frame.spriteCollection = spriteCollection;
                    frame.spriteId         = spriteCollection.FirstValidDefinitionIndex;
                }
                anim.clips[currentClip].frames[0] = frame;

                GUI.changed = true;
            }

            // Delete clip
            if (GUILayout.Button("-", GUILayout.MaxWidth(28), GUILayout.MaxHeight(14)))
            {
                anim.clips[currentClip].name   = "";
                anim.clips[currentClip].frames = new tk2dSpriteAnimationFrame[0];

                currentClip = 0;
                // find first non zero clip
                for (int i = 0; i < anim.clips.Length; ++i)
                {
                    if (anim.clips[i].name != "")
                    {
                        currentClip = i;
                        break;
                    }
                }

                GUI.changed = true;
            }
            EditorGUILayout.EndHorizontal();
            #endregion

            #region PruneClipList
            // Prune clip list
            int lastActiveClip = 0;
            for (int i = 0; i < anim.clips.Length; ++i)
            {
                if (!(anim.clips[i].name == "" && anim.clips[i].frames != null && anim.clips[i].frames.Length == 0))
                {
                    lastActiveClip = i;
                }
            }
            if (lastActiveClip != anim.clips.Length - 1)
            {
                System.Array.Resize <tk2dSpriteAnimationClip>(ref anim.clips, lastActiveClip + 1);
                GUI.changed = true;
            }
            #endregion

            // If anything has changed up to now, redraw
            if (GUI.changed)
            {
                EditorUtility.SetDirty(anim);
                Repaint();
                return;
            }

            EditorGUI.indentLevel = 2;
            tk2dSpriteAnimationClip clip = anim.clips[currentClip];

            // Clip properties

            // Name
            clip.name = EditorGUILayout.TextField("Name", clip.name);

            #region NumberOfFrames
            // Number of frames
            int clipNumFrames = (clip.frames != null)?clip.frames.Length:0;
            int newFrameCount = 0;
            if (clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.Single)
            {
                newFrameCount = 1;                 // only one frame, no need to display
            }
            else
            {
                int maxFrameCount = 400;
                int startSection  = Mathf.Max(clipNumFrames - 5, 1);
                int endSection    = Mathf.Min(clipNumFrames + 5, maxFrameCount);

                string[] numFrameStr = new string[maxFrameCount - 1];
                int      div         = 20;

                int    divStart = 0;
                int    divEnd   = 0;
                string section  = "";
                for (int i = 1; i < startSection; ++i)
                {
                    if (i > divEnd)
                    {
                        divStart = divEnd + 1;
                        divEnd   = Mathf.Min(startSection - 1, divStart + div - 1);
                        section  = divStart.ToString() + " .. " + divEnd.ToString();
                    }
                    numFrameStr[i - 1] = section + "/" + i.ToString();
                }

                for (int i = startSection; i < endSection; ++i)
                {
                    numFrameStr[i - 1] = i.ToString();
                }

                divEnd = endSection - 1;
                for (int i = endSection; i < maxFrameCount; ++i)
                {
                    if (i > divEnd)
                    {
                        divStart = Mathf.Max(divEnd + 1, endSection);
                        divEnd   = Mathf.Min(((divStart + div) / div) * div, maxFrameCount - 1);
                        section  = divStart.ToString() + " .. " + divEnd.ToString();
                    }
                    numFrameStr[i - 1] = section + "/" + i.ToString();
                }

                newFrameCount = EditorGUILayout.Popup("Num Frames", clipNumFrames - 1, numFrameStr) + 1;
                if (newFrameCount == 0)
                {
                    newFrameCount = 1;                                     // minimum = 1
                }
            }

            if (newFrameCount != clipNumFrames)
            {
                // Ungroup
                if (newFrameCount > clipNumFrames)
                {
                    tk2dPreferences.inst.groupAnimDisplay = false;
                    scrollPosition.y += 1000000.0f;                     // push to the end
                }

                tk2dSpriteAnimationFrame[] frames = new tk2dSpriteAnimationFrame[newFrameCount];

                int c1 = Mathf.Min(clipNumFrames, frames.Length);
                for (int i = 0; i < c1; ++i)
                {
                    frames[i] = new tk2dSpriteAnimationFrame();
                    frames[i].CopyFrom(clip.frames[i]);
                }
                if (c1 > 0)
                {
                    for (int i = c1; i < frames.Length; ++i)
                    {
                        frames[i] = new tk2dSpriteAnimationFrame();
                        frames[i].CopyFrom(clip.frames[c1 - 1]);
                    }
                }
                else
                {
                    for (int i = 0; i < frames.Length; ++i)
                    {
                        frames[i] = new tk2dSpriteAnimationFrame();
                        var spriteCollection = tk2dSpriteGuiUtility.GetDefaultSpriteCollection();
                        frames[i].spriteCollection = spriteCollection;
                        frames[i].spriteId         = spriteCollection.FirstValidDefinitionIndex;
                    }
                }

                clip.frames   = frames;
                clipNumFrames = newFrameCount;
            }
            #endregion

            // Frame rate
            if (clip.wrapMode != tk2dSpriteAnimationClip.WrapMode.Single)
            {
                clip.fps = EditorGUILayout.FloatField("Frame rate", clip.fps);
            }

            // Wrap mode
            clip.wrapMode = (tk2dSpriteAnimationClip.WrapMode)EditorGUILayout.EnumPopup("Wrap mode", clip.wrapMode);
            if (clip.wrapMode == tk2dSpriteAnimationClip.WrapMode.LoopSection)
            {
                clip.loopStart = EditorGUILayout.IntField("Loop start", clip.loopStart);
                clip.loopStart = Mathf.Clamp(clip.loopStart, 0, clip.frames.Length - 1);
            }

            #region DrawFrames
            EditorGUI.indentLevel = 0;

            GUILayout.Space(8);
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.Label("Frames");
            GUILayout.FlexibleSpace();

            // Reverse
            if (clip.wrapMode != tk2dSpriteAnimationClip.WrapMode.Single &&
                GUILayout.Button("Reverse", EditorStyles.toolbarButton))
            {
                System.Array.Reverse(clip.frames);
                GUI.changed = true;
            }

            // Auto fill
            if (clip.wrapMode != tk2dSpriteAnimationClip.WrapMode.Single && clip.frames.Length >= 1)
            {
                AutoFill(clip);
            }

            if (GUILayout.Button(tk2dPreferences.inst.horizontalAnimDisplay?"H":"V", EditorStyles.toolbarButton, GUILayout.MaxWidth(24)))
            {
                tk2dPreferences.inst.horizontalAnimDisplay = !tk2dPreferences.inst.horizontalAnimDisplay;
                Repaint();
            }

            tk2dPreferences.inst.groupAnimDisplay = GUILayout.Toggle(tk2dPreferences.inst.groupAnimDisplay, "Group", EditorStyles.toolbarButton);

            EditorGUILayout.EndHorizontal();

            // Sanitize frame data
            for (int i = 0; i < clip.frames.Length; ++i)
            {
                if (clip.frames[i].spriteCollection == null || clip.frames[i].spriteCollection.spriteDefinitions.Length == 0)
                {
                    EditorUtility.DisplayDialog("Warning", "Invalid sprite collection found.\nThis clip will now be deleted", "Ok");

                    clip.name   = "";
                    clip.frames = new tk2dSpriteAnimationFrame[0];
                    Repaint();
                    return;
                }

                if (clip.frames[i].spriteId < 0 || clip.frames[i].spriteId >= clip.frames[i].spriteCollection.Count)
                {
                    EditorUtility.DisplayDialog("Warning", "Invalid frame found, resetting to frame 0", "Ok");
                    clip.frames[i].spriteId = 0;
                }
            }

            // Warning when one of the frames has different poly count
            if (clipNumFrames > 0)
            {
                bool differentPolyCount = false;
                int  polyCount          = clip.frames[0].spriteCollection.spriteDefinitions[clip.frames[0].spriteId].positions.Length;
                for (int i = 1; i < clipNumFrames; ++i)
                {
                    int thisPolyCount = clip.frames[i].spriteCollection.spriteDefinitions[clip.frames[i].spriteId].positions.Length;
                    if (thisPolyCount != polyCount)
                    {
                        differentPolyCount = true;
                        break;
                    }
                }

                if (differentPolyCount)
                {
                    Color bg = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;
                    GUILayout.TextArea("Sprites have different poly counts. Performance will be affected");
                    GUI.backgroundColor = bg;
                }
            }

            // Draw frames
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();

            DrawClipEditor(clip);

            EditorGUILayout.EndHorizontal();
            #endregion
        }

        EditorGUILayout.EndVertical();
        EditorGUI.indentLevel--;

        if (GUI.changed)
        {
            EditorUtility.SetDirty(anim);
        }
    }
コード例 #8
0
        private void DrawAssetDependencyViewer()
        {
            if (!m_Analyzed)
            {
                DrawAnalyzeButton();
                return;
            }

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(5f);
                EditorGUILayout.BeginVertical(GUILayout.Width(position.width * 0.4f));
                {
                    GUILayout.Space(5f);
                    string title = null;
                    if (string.IsNullOrEmpty(m_AssetsFilter))
                    {
                        title = Utility.Text.Format("Assets In Resources ({0})", m_AssetCount.ToString());
                    }
                    else
                    {
                        title = Utility.Text.Format("Assets In Resources ({0}/{1})", m_CachedAssetNames.Length.ToString(), m_AssetCount.ToString());
                    }
                    EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height - 150f));
                    {
                        m_AssetsScroll = EditorGUILayout.BeginScrollView(m_AssetsScroll);
                        {
                            int selectedIndex = GUILayout.SelectionGrid(m_SelectedAssetIndex, m_CachedAssetNames, 1, "toggle");
                            if (selectedIndex != m_SelectedAssetIndex)
                            {
                                m_SelectedAssetIndex     = selectedIndex;
                                m_SelectedAssetName      = m_CachedAssetNames[selectedIndex];
                                m_SelectedDependencyData = m_Controller.GetDependencyData(m_SelectedAssetName);
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical("box");
                    {
                        EditorGUILayout.LabelField("Asset Name", m_SelectedAssetName ?? "<None>");
                        EditorGUILayout.LabelField("Resource Name", m_SelectedAssetName == null ? "<None>" : m_Controller.GetAsset(m_SelectedAssetName).Resource.FullName);
                        EditorGUILayout.BeginHorizontal();
                        {
                            AssetsOrder assetsOrder = (AssetsOrder)EditorGUILayout.EnumPopup("Order by", m_AssetsOrder);
                            if (assetsOrder != m_AssetsOrder)
                            {
                                m_AssetsOrder = assetsOrder;
                                OnAssetsOrderOrFilterChanged();
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            string assetsFilter = EditorGUILayout.TextField("Assets Filter", m_AssetsFilter);
                            if (assetsFilter != m_AssetsFilter)
                            {
                                m_AssetsFilter = assetsFilter;
                                OnAssetsOrderOrFilterChanged();
                            }
                            EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(m_AssetsFilter));
                            {
                                if (GUILayout.Button("x", GUILayout.Width(20f)))
                                {
                                    m_AssetsFilter = null;
                                    GUI.FocusControl(null);
                                    OnAssetsOrderOrFilterChanged();
                                }
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(GUILayout.Width(position.width * 0.6f - 14f));
                {
                    GUILayout.Space(5f);
                    EditorGUILayout.LabelField(Utility.Text.Format("Dependency Resources ({0})", m_SelectedDependencyData.DependencyResourceCount.ToString()), EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height * 0.2f));
                    {
                        m_DependencyResourcesScroll = EditorGUILayout.BeginScrollView(m_DependencyResourcesScroll);
                        {
                            Resource[] dependencyResources = m_SelectedDependencyData.GetDependencyResources();
                            foreach (Resource dependencyResource in dependencyResources)
                            {
                                GUILayout.Label(dependencyResource.FullName);
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.LabelField(Utility.Text.Format("Dependency Assets ({0})", m_SelectedDependencyData.DependencyAssetCount.ToString()), EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height * 0.3f));
                    {
                        m_DependencyAssetsScroll = EditorGUILayout.BeginScrollView(m_DependencyAssetsScroll);
                        {
                            Asset[] dependencyAssets = m_SelectedDependencyData.GetDependencyAssets();
                            foreach (Asset dependencyAsset in dependencyAssets)
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    if (GUILayout.Button("GO", GUILayout.Width(30f)))
                                    {
                                        m_SelectedAssetName      = dependencyAsset.Name;
                                        m_SelectedAssetIndex     = new List <string>(m_CachedAssetNames).IndexOf(m_SelectedAssetName);
                                        m_SelectedDependencyData = m_Controller.GetDependencyData(m_SelectedAssetName);
                                    }

                                    GUILayout.Label(dependencyAsset.Name);
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.LabelField(Utility.Text.Format("Scattered Dependency Assets ({0})", m_SelectedDependencyData.ScatteredDependencyAssetCount.ToString()), EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height * 0.5f - 116f));
                    {
                        m_ScatteredDependencyAssetsScroll = EditorGUILayout.BeginScrollView(m_ScatteredDependencyAssetsScroll);
                        {
                            string[] scatteredDependencyAssetNames = m_SelectedDependencyData.GetScatteredDependencyAssetNames();
                            foreach (string scatteredDependencyAssetName in scatteredDependencyAssetNames)
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    int count = m_Controller.GetHostAssets(scatteredDependencyAssetName).Length;
                                    EditorGUI.BeginDisabledGroup(count < 2);
                                    {
                                        if (GUILayout.Button("GO", GUILayout.Width(30f)))
                                        {
                                            m_SelectedScatteredAssetName  = scatteredDependencyAssetName;
                                            m_SelectedScatteredAssetIndex = new List <string>(m_CachedScatteredAssetNames).IndexOf(m_SelectedScatteredAssetName);
                                            m_SelectedHostAssets          = m_Controller.GetHostAssets(m_SelectedScatteredAssetName);
                                            m_ToolbarIndex = 2;
                                            GUI.FocusControl(null);
                                        }
                                    }
                                    EditorGUI.EndDisabledGroup();
                                    GUILayout.Label(count > 1 ? Utility.Text.Format("{0} ({1})", scatteredDependencyAssetName, count.ToString()) : scatteredDependencyAssetName);
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #9
0
        private void DrawScatteredAssetViewer()
        {
            if (!m_Analyzed)
            {
                DrawAnalyzeButton();
                return;
            }

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Space(5f);
                EditorGUILayout.BeginVertical(GUILayout.Width(position.width * 0.4f));
                {
                    GUILayout.Space(5f);
                    string title = null;
                    if (string.IsNullOrEmpty(m_ScatteredAssetsFilter))
                    {
                        title = Utility.Text.Format("Scattered Assets ({0})", m_ScatteredAssetCount.ToString());
                    }
                    else
                    {
                        title = Utility.Text.Format("Scattered Assets ({0}/{1})", m_CachedScatteredAssetNames.Length.ToString(), m_ScatteredAssetCount.ToString());
                    }
                    EditorGUILayout.LabelField(title, EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height - 132f));
                    {
                        m_ScatteredAssetsScroll = EditorGUILayout.BeginScrollView(m_ScatteredAssetsScroll);
                        {
                            int selectedIndex = GUILayout.SelectionGrid(m_SelectedScatteredAssetIndex, m_CachedScatteredAssetNames, 1, "toggle");
                            if (selectedIndex != m_SelectedScatteredAssetIndex)
                            {
                                m_SelectedScatteredAssetIndex = selectedIndex;
                                m_SelectedScatteredAssetName  = m_CachedScatteredAssetNames[selectedIndex];
                                m_SelectedHostAssets          = m_Controller.GetHostAssets(m_SelectedScatteredAssetName);
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.BeginVertical("box");
                    {
                        EditorGUILayout.LabelField("Scattered Asset Name", m_SelectedScatteredAssetName ?? "<None>");
                        EditorGUILayout.BeginHorizontal();
                        {
                            ScatteredAssetsOrder scatteredAssetsOrder = (ScatteredAssetsOrder)EditorGUILayout.EnumPopup("Order by", m_ScatteredAssetsOrder);
                            if (scatteredAssetsOrder != m_ScatteredAssetsOrder)
                            {
                                m_ScatteredAssetsOrder = scatteredAssetsOrder;
                                OnScatteredAssetsOrderOrFilterChanged();
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.BeginHorizontal();
                        {
                            string scatteredAssetsFilter = EditorGUILayout.TextField("Assets Filter", m_ScatteredAssetsFilter);
                            if (scatteredAssetsFilter != m_ScatteredAssetsFilter)
                            {
                                m_ScatteredAssetsFilter = scatteredAssetsFilter;
                                OnScatteredAssetsOrderOrFilterChanged();
                            }
                            EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(m_ScatteredAssetsFilter));
                            {
                                if (GUILayout.Button("x", GUILayout.Width(20f)))
                                {
                                    m_ScatteredAssetsFilter = null;
                                    GUI.FocusControl(null);
                                    OnScatteredAssetsOrderOrFilterChanged();
                                }
                            }
                            EditorGUI.EndDisabledGroup();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(GUILayout.Width(position.width * 0.6f - 14f));
                {
                    GUILayout.Space(5f);
                    EditorGUILayout.LabelField(Utility.Text.Format("Host Assets ({0})", m_SelectedHostAssets.Length.ToString()), EditorStyles.boldLabel);
                    EditorGUILayout.BeginVertical("box", GUILayout.Height(position.height - 68f));
                    {
                        m_HostAssetsScroll = EditorGUILayout.BeginScrollView(m_HostAssetsScroll);
                        {
                            foreach (Asset hostAsset in m_SelectedHostAssets)
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    if (GUILayout.Button("GO", GUILayout.Width(30f)))
                                    {
                                        m_SelectedAssetName      = hostAsset.Name;
                                        m_SelectedAssetIndex     = new List <string>(m_CachedAssetNames).IndexOf(m_SelectedAssetName);
                                        m_SelectedDependencyData = m_Controller.GetDependencyData(m_SelectedAssetName);
                                        m_ToolbarIndex           = 1;
                                        GUI.FocusControl(null);
                                    }

                                    GUILayout.Label(Utility.Text.Format("{0} [{1}]", hostAsset.Name, hostAsset.Resource.FullName));
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndScrollView();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #10
0
        /// <summary>
        /// Draws the header for the Updates tab.
        /// </summary>
        private void DrawUpdatesHeader()
        {
            GUIStyle headerStyle = new GUIStyle();

            if (Application.HasProLicense())
            {
                headerStyle.normal.background = MakeTex(20, 20, new Color(0.05f, 0.05f, 0.05f));
            }
            else
            {
                headerStyle.normal.background = MakeTex(20, 20, new Color(0.4f, 0.4f, 0.4f));
            }

            EditorGUILayout.BeginVertical(headerStyle);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    bool showAllVersionsTemp = EditorGUILayout.Toggle("Show All Versions", showAllUpdateVersions);
                    if (showAllVersionsTemp != showAllUpdateVersions)
                    {
                        showAllUpdateVersions = showAllVersionsTemp;
                        UpdateUpdatePackages();
                    }

                    if (GUILayout.Button("Install All Updates", GUILayout.Width(150)))
                    {
                        NugetHelper.UpdateAll(updatePackages, NugetHelper.InstalledPackages);
                        NugetHelper.UpdateInstalledPackages();
                        UpdateUpdatePackages();
                    }

                    if (GUILayout.Button("Refresh", GUILayout.Width(60)))
                    {
                        Refresh(true);
                    }
                }
                EditorGUILayout.EndHorizontal();

                bool showPrereleaseTemp = EditorGUILayout.Toggle("Show Prerelease", showPrereleaseUpdates);
                if (showPrereleaseTemp != showPrereleaseUpdates)
                {
                    showPrereleaseUpdates = showPrereleaseTemp;
                    UpdateUpdatePackages();
                }

                bool enterPressed = Event.current.Equals(Event.KeyboardEvent("return"));

                EditorGUILayout.BeginHorizontal();
                {
                    int oldFontSize = GUI.skin.textField.fontSize;
                    GUI.skin.textField.fontSize = 25;
                    updatesSearchTerm           = EditorGUILayout.TextField(updatesSearchTerm, GUILayout.Height(30));

                    if (GUILayout.Button("Search", GUILayout.Width(100), GUILayout.Height(28)))
                    {
                        // the search button emulates the Enter key
                        enterPressed = true;
                    }

                    GUI.skin.textField.fontSize = oldFontSize;
                }
                EditorGUILayout.EndHorizontal();

                // search only if the enter key is pressed
                if (enterPressed)
                {
                    if (updatesSearchTerm != "Search")
                    {
                        filteredUpdatePackages = updatePackages.Where(x => x.Id.ToLower().Contains(updatesSearchTerm) || x.Title.ToLower().Contains(updatesSearchTerm)).ToList();
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
コード例 #11
0
        /// <summary>
        /// Draws the given <see cref="NugetPackage"/>.
        /// </summary>
        /// <param name="package">The <see cref="NugetPackage"/> to draw.</param>
        private void DrawPackage(NugetPackage package, GUIStyle packageStyle, GUIStyle contrastStyle)
        {
            IEnumerable <NugetPackage> installedPackages = NugetHelper.InstalledPackages;
            var installed = installedPackages.FirstOrDefault(p => p.Id == package.Id);

            EditorGUILayout.BeginHorizontal();
            {
                // The Unity GUI system (in the Editor) is terrible.  This probably requires some explanation.
                // Every time you use a Horizontal block, Unity appears to divide the space evenly.
                // (i.e. 2 components have half of the window width, 3 components have a third of the window width, etc)
                // GUILayoutUtility.GetRect is SUPPOSED to return a rect with the given height and width, but in the GUI layout.  It doesn't.
                // We have to use GUILayoutUtility to get SOME rect properties, but then manually calculate others.
                EditorGUILayout.BeginHorizontal();
                {
                    const int iconSize = 32;
                    int       padding  = EditorStyles.label.padding.vertical;
                    Rect      rect     = GUILayoutUtility.GetRect(iconSize, iconSize);
                    // only use GetRect's Y position.  It doesn't correctly set the width, height or X position.

                    rect.x      = padding;
                    rect.y     += padding;
                    rect.width  = iconSize;
                    rect.height = iconSize;

                    if (package.Icon != null)
                    {
                        GUI.DrawTexture(rect, package.Icon, ScaleMode.StretchToFill);
                    }
                    else
                    {
                        GUI.DrawTexture(rect, defaultIcon, ScaleMode.StretchToFill);
                    }

                    rect.x     = iconSize + 2 * padding;
                    rect.width = position.width / 2 - (iconSize + padding);
                    rect.y    -= padding; // This will leave the text aligned with the top of the image


                    EditorStyles.label.fontStyle = FontStyle.Bold;
                    EditorStyles.label.fontSize  = 16;

                    Vector2 idSize = EditorStyles.label.CalcSize(new GUIContent(package.Id));
                    rect.y += (iconSize / 2 - idSize.y / 2) + padding;
                    GUI.Label(rect, package.Id, EditorStyles.label);
                    rect.x += idSize.x;

                    EditorStyles.label.fontSize  = 10;
                    EditorStyles.label.fontStyle = FontStyle.Normal;

                    Vector2 versionSize = EditorStyles.label.CalcSize(new GUIContent(package.Version));
                    rect.y += (idSize.y - versionSize.y - padding / 2);

                    if (!string.IsNullOrEmpty(package.Authors))
                    {
                        string  authorLabel = string.Format("by {0}", package.Authors);
                        Vector2 size        = EditorStyles.label.CalcSize(new GUIContent(authorLabel));
                        GUI.Label(rect, authorLabel, EditorStyles.label);
                        rect.x += size.x;
                    }

                    if (package.DownloadCount > 0)
                    {
                        string  downloadLabel = string.Format("{0} downloads", package.DownloadCount.ToString("#,#"));
                        Vector2 size          = EditorStyles.label.CalcSize(new GUIContent(downloadLabel));
                        GUI.Label(rect, downloadLabel, EditorStyles.label);
                        rect.x += size.x;
                    }
                }

                GUILayout.FlexibleSpace();
                if (installed != null && installed.Version != package.Version)
                {
                    GUILayout.Label(string.Format("Current Version {0}", installed.Version));
                }
                GUILayout.Label(string.Format("Version {0}", package.Version));


                if (installedPackages.Contains(package))
                {
                    // This specific version is installed
                    if (GUILayout.Button("Uninstall"))
                    {
                        // TODO: Perhaps use a "mark as dirty" system instead of updating all of the data all the time?
                        NugetHelper.Uninstall(package);
                        NugetHelper.UpdateInstalledPackages();
                        UpdateUpdatePackages();
                    }
                }
                else
                {
                    if (installed != null)
                    {
                        if (installed < package)
                        {
                            // An older version is installed
                            if (GUILayout.Button("Update"))
                            {
                                NugetHelper.Update(installed, package);
                                NugetHelper.UpdateInstalledPackages();
                                UpdateUpdatePackages();
                            }
                        }
                        else if (installed > package)
                        {
                            // A newer version is installed
                            if (GUILayout.Button("Downgrade"))
                            {
                                NugetHelper.Update(installed, package);
                                NugetHelper.UpdateInstalledPackages();
                                UpdateUpdatePackages();
                            }
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Install"))
                        {
                            NugetHelper.InstallIdentifier(package);
                            AssetDatabase.Refresh();
                            NugetHelper.UpdateInstalledPackages();
                            UpdateUpdatePackages();
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical();
                {
                    // Show the package details
                    EditorStyles.label.wordWrap  = true;
                    EditorStyles.label.fontStyle = FontStyle.Normal;

                    string summary = package.Summary;
                    if (string.IsNullOrEmpty(summary))
                    {
                        summary = package.Description;
                    }

                    if (!package.Title.Equals(package.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        summary = string.Format("{0} - {1}", package.Title, summary);
                    }

                    if (summary.Length >= 240)
                    {
                        summary = string.Format("{0}...", summary.Substring(0, 237));
                    }

                    EditorGUILayout.LabelField(summary);

                    bool   detailsFoldout;
                    string detailsFoldoutId = string.Format("{0}.{1}", package.Id, "Details");
                    if (!foldouts.TryGetValue(detailsFoldoutId, out detailsFoldout))
                    {
                        foldouts[detailsFoldoutId] = detailsFoldout;
                    }
                    detailsFoldout             = EditorGUILayout.Foldout(detailsFoldout, "Details");
                    foldouts[detailsFoldoutId] = detailsFoldout;

                    if (detailsFoldout)
                    {
                        EditorGUI.indentLevel++;
                        if (!string.IsNullOrEmpty(package.Description))
                        {
                            EditorGUILayout.LabelField("Description", EditorStyles.boldLabel);
                            EditorGUILayout.LabelField(package.Description);
                        }

                        if (!string.IsNullOrEmpty(package.ReleaseNotes))
                        {
                            EditorGUILayout.LabelField("Release Notes", EditorStyles.boldLabel);
                            EditorGUILayout.LabelField(package.ReleaseNotes);
                        }

                        // Show project URL link
                        if (!string.IsNullOrEmpty(package.ProjectUrl))
                        {
                            EditorGUILayout.LabelField("Project Url", EditorStyles.boldLabel);
                            GUILayoutLink(package.ProjectUrl);
                            GUILayout.Space(4f);
                        }


                        // Show the dependencies
                        if (package.Dependencies.Count > 0)
                        {
                            EditorStyles.label.wordWrap  = true;
                            EditorStyles.label.fontStyle = FontStyle.Italic;
                            StringBuilder builder = new StringBuilder();

                            NugetFrameworkGroup frameworkGroup = NugetHelper.GetBestDependencyFrameworkGroupForCurrentSettings(package);
                            foreach (var dependency in frameworkGroup.Dependencies)
                            {
                                builder.Append(string.Format(" {0} {1};", dependency.Id, dependency.Version));
                            }
                            EditorGUILayout.Space();
                            EditorGUILayout.LabelField(string.Format("Depends on:{0}", builder.ToString()));
                            EditorStyles.label.fontStyle = FontStyle.Normal;
                        }

                        // Create the style for putting a box around the 'Clone' button
                        var cloneButtonBoxStyle = new GUIStyle("box");
                        cloneButtonBoxStyle.stretchWidth   = false;
                        cloneButtonBoxStyle.margin.top     = 0;
                        cloneButtonBoxStyle.margin.bottom  = 0;
                        cloneButtonBoxStyle.padding.bottom = 4;

                        var normalButtonBoxStyle = new GUIStyle(cloneButtonBoxStyle);
                        normalButtonBoxStyle.normal.background = packageStyle.normal.background;

                        bool showCloneWindow = openCloneWindows.Contains(package);
                        cloneButtonBoxStyle.normal.background = showCloneWindow ? contrastStyle.normal.background : packageStyle.normal.background;

                        // Create a simillar style for the 'Clone' window
                        var cloneWindowStyle = new GUIStyle(cloneButtonBoxStyle);
                        cloneWindowStyle.padding = new RectOffset(6, 6, 2, 6);

                        // Show button bar
                        EditorGUILayout.BeginHorizontal();
                        {
                            if (package.RepositoryType == RepositoryType.Git || package.RepositoryType == RepositoryType.TfsGit)
                            {
                                if (!string.IsNullOrEmpty(package.RepositoryUrl))
                                {
                                    EditorGUILayout.BeginHorizontal(cloneButtonBoxStyle);
                                    {
                                        var cloneButtonStyle = new GUIStyle(GUI.skin.button);
                                        cloneButtonStyle.normal = showCloneWindow ? cloneButtonStyle.active : cloneButtonStyle.normal;
                                        if (GUILayout.Button("Clone", cloneButtonStyle, GUILayout.ExpandWidth(false)))
                                        {
                                            showCloneWindow = !showCloneWindow;
                                        }

                                        if (showCloneWindow)
                                        {
                                            openCloneWindows.Add(package);
                                        }
                                        else
                                        {
                                            openCloneWindows.Remove(package);
                                        }
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }

                            if (!string.IsNullOrEmpty(package.LicenseUrl) && package.LicenseUrl != "http://your_license_url_here")
                            {
                                // Creaete a box around the license button to keep it alligned with Clone button
                                EditorGUILayout.BeginHorizontal(normalButtonBoxStyle);
                                // Show the license button
                                if (GUILayout.Button("View License", GUILayout.ExpandWidth(false)))
                                {
                                    Application.OpenURL(package.LicenseUrl);
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                        }
                        EditorGUILayout.EndHorizontal();

                        if (showCloneWindow)
                        {
                            EditorGUILayout.BeginVertical(cloneWindowStyle);
                            {
                                // Clone latest label
                                EditorGUILayout.BeginHorizontal();
                                GUILayout.Space(20f);
                                EditorGUILayout.LabelField("clone latest");
                                EditorGUILayout.EndHorizontal();

                                // Clone latest row
                                EditorGUILayout.BeginHorizontal();
                                {
                                    if (GUILayout.Button("Copy", GUILayout.ExpandWidth(false)))
                                    {
                                        GUI.FocusControl(package.Id + package.Version + "repoUrl");
                                        GUIUtility.systemCopyBuffer = package.RepositoryUrl;
                                    }

                                    GUI.SetNextControlName(package.Id + package.Version + "repoUrl");
                                    EditorGUILayout.TextField(package.RepositoryUrl);
                                }
                                EditorGUILayout.EndHorizontal();

                                // Clone @ commit label
                                GUILayout.Space(4f);
                                EditorGUILayout.BeginHorizontal();
                                GUILayout.Space(20f);
                                EditorGUILayout.LabelField("clone @ commit");
                                EditorGUILayout.EndHorizontal();

                                // Clone @ commit row
                                EditorGUILayout.BeginHorizontal();
                                {
                                    // Create the three commands a user will need to run to get the repo @ the commit. Intentionally leave off the last newline for better UI appearance
                                    string commands = string.Format("git clone {0} {1} --no-checkout{2}cd {1}{2}git checkout {3}", package.RepositoryUrl, package.Id, Environment.NewLine, package.RepositoryCommit);

                                    if (GUILayout.Button("Copy", GUILayout.ExpandWidth(false)))
                                    {
                                        GUI.FocusControl(package.Id + package.Version + "commands");

                                        // Add a newline so the last command will execute when pasted to the CL
                                        GUIUtility.systemCopyBuffer = (commands + Environment.NewLine);
                                    }

                                    EditorGUILayout.BeginVertical();
                                    GUI.SetNextControlName(package.Id + package.Version + "commands");
                                    EditorGUILayout.TextArea(commands);
                                    EditorGUILayout.EndVertical();
                                }
                                EditorGUILayout.EndHorizontal();
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUI.indentLevel--;
                    }

                    EditorGUILayout.Separator();
                    EditorGUILayout.Separator();
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();
        }
コード例 #12
0
        /// <summary>
        /// Draws the header which allows filtering the online list of packages.
        /// </summary>
        private void DrawOnlineHeader()
        {
            GUIStyle headerStyle = new GUIStyle();

            if (Application.HasProLicense())
            {
                headerStyle.normal.background = MakeTex(20, 20, new Color(0.05f, 0.05f, 0.05f));
            }
            else
            {
                headerStyle.normal.background = MakeTex(20, 20, new Color(0.4f, 0.4f, 0.4f));
            }

            EditorGUILayout.BeginVertical(headerStyle);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    bool showAllVersionsTemp = EditorGUILayout.Toggle("Show All Versions", showAllOnlineVersions);
                    if (showAllVersionsTemp != showAllOnlineVersions)
                    {
                        showAllOnlineVersions = showAllVersionsTemp;
                        UpdateOnlinePackages();
                    }

                    if (GUILayout.Button("Refresh", GUILayout.Width(60)))
                    {
                        Refresh(true);
                    }
                }
                EditorGUILayout.EndHorizontal();

                bool showPrereleaseTemp = EditorGUILayout.Toggle("Show Prerelease", showOnlinePrerelease);
                if (showPrereleaseTemp != showOnlinePrerelease)
                {
                    showOnlinePrerelease = showPrereleaseTemp;
                    UpdateOnlinePackages();
                }

                bool enterPressed = Event.current.Equals(Event.KeyboardEvent("return"));

                EditorGUILayout.BeginHorizontal();
                {
                    int oldFontSize = GUI.skin.textField.fontSize;
                    GUI.skin.textField.fontSize = 25;
                    onlineSearchTerm            = EditorGUILayout.TextField(onlineSearchTerm, GUILayout.Height(30));

                    if (GUILayout.Button("Search", GUILayout.Width(100), GUILayout.Height(28)))
                    {
                        // the search button emulates the Enter key
                        enterPressed = true;
                    }

                    GUI.skin.textField.fontSize = oldFontSize;
                }
                EditorGUILayout.EndHorizontal();

                // search only if the enter key is pressed
                if (enterPressed)
                {
                    // reset the number to skip
                    numberToSkip = 0;
                    UpdateOnlinePackages();
                }
            }
            EditorGUILayout.EndVertical();
        }
コード例 #13
0
        private void PreviewEvent(Rect previewRect, EditorEventRef selectedEvent)
        {
            GUILayout.BeginArea(previewRect);

            bool isNarrow = previewRect.width < 400;

            var style = new GUIStyle(EditorStyles.label);

            EditorStyles.label.fontStyle = FontStyle.Bold;
            EditorGUIUtility.labelWidth  = 75;

            var copyIcon = EditorGUIUtility.Load("FMOD/CopyIcon.png") as Texture;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Full Path", selectedEvent.Path, style, GUILayout.ExpandWidth(true));
            if (GUILayout.Button(copyIcon, GUILayout.ExpandWidth(false)))
            {
                EditorGUIUtility.systemCopyBuffer = selectedEvent.Path;
            }
            EditorGUILayout.EndHorizontal();



            StringBuilder builder = new StringBuilder();

            selectedEvent.Banks.ForEach((x) => { builder.Append(Path.GetFileNameWithoutExtension(x.Path)); builder.Append(", "); });
            EditorGUILayout.LabelField("Banks", builder.ToString(0, Math.Max(0, builder.Length - 2)), style);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Panning", selectedEvent.Is3D ? "3D" : "2D", style);
            EditorGUILayout.LabelField("Oneshot", selectedEvent.IsOneShot.ToString(), style);
            if (!isNarrow)
            {
                EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style);
            }
            EditorGUILayout.EndHorizontal();
            if (isNarrow)
            {
                EditorGUILayout.LabelField("Streaming", selectedEvent.IsStream.ToString(), style);
            }

            EditorGUIUtility.labelWidth  = 0;
            EditorStyles.label.fontStyle = FontStyle.Normal;

            if (Event.current.type == EventType.Repaint)
            {
                var lastRect = GUILayoutUtility.GetLastRect();
                if (!isNarrow)
                {
                    previewCustomRect = new Rect(lastRect.width / 2 - 200, lastRect.yMax + 10, 400, 150);
                }
                else
                {
                    previewCustomRect = new Rect(lastRect.width / 2 - 130, lastRect.yMax + 10, 260, 150);
                }
            }

            GUI.Box(new Rect(0, previewCustomRect.yMin, previewRect.width, 1), GUIContent.none);
            GUI.Box(new Rect(0, previewCustomRect.yMax, previewRect.width, 1), GUIContent.none);

            GUILayout.BeginArea(previewCustomRect);

            Texture playOff  = EditorGUIUtility.Load("FMOD/TransportPlayButtonOff.png") as Texture;
            Texture playOn   = EditorGUIUtility.Load("FMOD/TransportPlayButtonOn.png") as Texture;
            Texture stopOff  = EditorGUIUtility.Load("FMOD/TransportStopButtonOff.png") as Texture;
            Texture stopOn   = EditorGUIUtility.Load("FMOD/TransportStopButtonOn.png") as Texture;
            Texture openIcon = EditorGUIUtility.Load("FMOD/transportOpen.png") as Texture;

            var transportButtonStyle = new GUIStyle();

            transportButtonStyle.padding.left = 4;
            transportButtonStyle.padding.top  = 10;

            var  previewState = EditorUtils.PreviewState;
            bool playing      = previewState == PreviewState.Playing;
            bool paused       = previewState == PreviewState.Paused;
            bool stopped      = previewState == PreviewState.Stopped;

            EditorGUILayout.BeginVertical();
            if (!isNarrow)
            {
                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(stopped || paused ? stopOn : stopOff, transportButtonStyle, GUILayout.ExpandWidth(false)))
            {
                forceRepaint = false;
                if (paused)
                {
                    EditorUtils.PreviewStop();
                }
                if (playing)
                {
                    EditorUtils.PreviewPause();
                }
            }
            if (GUILayout.Button(playing ? playOn : playOff, transportButtonStyle, GUILayout.ExpandWidth(false)))
            {
                if (playing || stopped)
                {
                    EditorUtils.PreviewEvent(selectedEvent);
                }
                else
                {
                    EditorUtils.PreviewPause();
                }
                forceRepaint = true;
            }
            if (GUILayout.Button(new GUIContent(openIcon, "Show Event in FMOD Studio"), transportButtonStyle, GUILayout.ExpandWidth(false)))
            {
                string cmd = string.Format("studio.window.navigateTo(studio.project.lookup(\"{0}\"))", selectedEvent.Guid.ToString("b"));
                EditorUtils.SendScriptCommand(cmd);
            }


            EditorGUILayout.EndHorizontal();
            if (!isNarrow)
            {
                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndVertical();

            {
                Texture circle  = EditorGUIUtility.Load("FMOD/preview.png") as Texture;
                Texture circle2 = EditorGUIUtility.Load("FMOD/previewemitter.png") as Texture;

                var originalColour = GUI.color;
                if (!selectedEvent.Is3D)
                {
                    GUI.color = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                }

                Rect rect = new Rect(isNarrow ? 120 : 150, 10, 128, 128);
                GUI.DrawTexture(rect, circle);

                Vector2 centre = rect.center;
                Rect    rect2  = new Rect(rect.center.x + eventPosition.x - 6, rect.center.y + eventPosition.y - 6, 12, 12);
                GUI.DrawTexture(rect2, circle2);

                GUI.color = originalColour;


                if (selectedEvent.Is3D && (Event.current.type == EventType.mouseDown || Event.current.type == EventType.mouseDrag) && rect.Contains(Event.current.mousePosition))
                {
                    var     newPosition = Event.current.mousePosition;
                    Vector2 delta       = (newPosition - centre);
                    float   distance    = delta.magnitude;
                    if (distance < 60)
                    {
                        eventPosition   = newPosition - rect.center;
                        previewDistance = distance / 60.0f * selectedEvent.MaxDistance;
                        delta.Normalize();
                        float angle = Mathf.Atan2(delta.y, delta.x);
                        previewOrientation = angle + Mathf.PI * 0.5f;
                    }
                    Event.current.Use();
                }

                EditorUtils.PreviewUpdatePosition(previewDistance, previewOrientation);
            }


            float   hoffset  = isNarrow ? 15 : 300;
            float   voffset  = isNarrow ? 50 : 10;
            Texture meterOn  = EditorGUIUtility.Load("FMOD/LevelMeter.png") as Texture;
            Texture meterOff = EditorGUIUtility.Load("FMOD/LevelMeterOff.png") as Texture;

            float[] metering    = EditorUtils.GetMetering();
            int     meterHeight = isNarrow ? 86 : 128;
            int     meterWidth  = (int)((128 / (float)meterOff.height) * meterOff.width);

            foreach (float rms in metering)
            {
                GUI.DrawTexture(new Rect(hoffset, voffset, meterWidth, meterHeight), meterOff);

                float db = 20.0f * Mathf.Log10(rms * Mathf.Sqrt(2.0f));
                db = Mathf.Clamp(db, -80.0f, 10.0f);
                float   visible       = 0;
                int[]   segmentPixels = new int[] { 0, 18, 38, 60, 89, 130, 187, 244, 300 };
                float[] segmentDB     = new float[] { -80.0f, -60.0f, -50.0f, -40.0f, -30.0f, -20.0f, -10.0f, 0, 10.0f };
                int     segment       = 1;
                while (segmentDB[segment] < db)
                {
                    segment++;
                }
                visible = segmentPixels[segment - 1] + ((db - segmentDB[segment - 1]) / (segmentDB[segment] - segmentDB[segment - 1])) * (segmentPixels[segment] - segmentPixels[segment - 1]);

                visible *= meterHeight / (float)meterOff.height;

                Rect levelPosRect = new Rect(hoffset, meterHeight - visible + voffset, meterWidth, visible);
                Rect levelUVRect  = new Rect(0, 0, 1.0f, visible / meterHeight);
                GUI.DrawTextureWithTexCoords(levelPosRect, meterOn, levelUVRect);
                hoffset += meterWidth + 5.0f;
            }

            GUILayout.EndArea();

            Rect paramRect = new Rect(0, previewCustomRect.yMax + 10, previewRect.width, previewRect.height - (previewCustomRect.yMax + 10));

            GUILayout.BeginArea(paramRect);

            paramScroll = GUILayout.BeginScrollView(paramScroll, false, false);
            foreach (var paramRef in selectedEvent.Parameters)
            {
                if (!previewParamValues.ContainsKey(paramRef.Name))
                {
                    previewParamValues[paramRef.Name] = paramRef.Default;
                }
                previewParamValues[paramRef.Name] = EditorGUILayout.Slider(paramRef.Name, previewParamValues[paramRef.Name], paramRef.Min, paramRef.Max);
                EditorUtils.PreviewUpdateParameter(paramRef.Name, previewParamValues[paramRef.Name]);
            }
            GUILayout.EndScrollView();

            GUILayout.EndArea();
            GUILayout.EndArea();
        }
コード例 #14
0
                public void ShowGUILayout(int index, ButtonClick onAdd, ButtonClick onRemove)
                {
                    var guiColor = GUI.color;

                    GUI.color *= EditorGUIUtility.isProSkin || HasErrors ? Color.white : new Color(.75f, .75f, .75f, 1f);
                    var style = EditorStyles.helpBox;

                    if (HasErrors)
                    {
                        style = expanded ? TCP2_GUI.ErrorPropertyHelpBoxExp : TCP2_GUI.ErrorPropertyHelpBox;
                    }
                    EditorGUILayout.BeginVertical(style);
                    GUI.color = guiColor;

                    using (new SGUILayout.IndentedLine(16))
                    {
                        const float buttonWidth = 20;

                        var rect       = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUIUtility.singleLineHeight));
                        var guiContent = new GUIContent(string.Format("{0} ({1})", Label, implementationTypeLabel));
                        rect.width -= buttonWidth * 2;

                        // hover
                        TCP2_GUI.DrawHoverRect(rect);

                        EditorGUI.BeginChangeCheck();
                        expanded = EditorGUI.Foldout(rect, expanded, guiContent, true, TCP2_GUI.HeaderDropDown);
                        if (EditorGUI.EndChangeCheck())
                        {
                            if (Event.current.alt || Event.current.control)
                            {
                                var state = expanded;
                                foreach (var cmp in ShaderGenerator2.CurrentConfig.CustomMaterialProperties)
                                {
                                    cmp.expanded = state;
                                }
                            }
                        }

                        rect.x     += rect.width;
                        rect.width  = buttonWidth;
                        rect.height = EditorGUIUtility.singleLineHeight;
                        if (GUI.Button(rect, "+", EditorStyles.miniButtonLeft))
                        {
                            onAdd(index);
                        }
                        rect.x += rect.width;
                        if (GUI.Button(rect, "-", EditorStyles.miniButtonRight))
                        {
                            onRemove(index);
                        }

                        var labelWidth = TCP2_GUI.HeaderDropDown.CalcSize(guiContent).x;
                        rect        = GUILayoutUtility.GetLastRect();
                        rect.y     += 2;
                        rect.x     += labelWidth;
                        rect.width -= labelWidth;
                        GUI.Label(rect, ": " + PropertyName, SGUILayout.Styles.GrayMiniLabel);
                    }

                    if (expanded)
                    {
                        GUILayout.Space(4);

                        implementation.NewLineGUI(false);
                    }

                    EditorGUILayout.EndVertical();
                }
コード例 #15
0
ファイル: MeshUtils.cs プロジェクト: cxgr/mesh_utils
        void OnGUI()
        {
            GUI.color = Color.red;
            if (GUILayout.Button("RESET", GUILayout.Width(60)))
            {
                Reset();
            }
            GUI.color = Color.white;

            EditorGUILayout.Separator();

            EditorGUILayout.LabelField("OBJ: ", (null != objWithMesh ? objWithMesh.name : "no mesh filter"));

            EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

            if (null != objWithMesh)
            {
                if (!isPivotEditModeActive)
                {
                    GUI.color = (Color.red + Color.yellow) / 2f;
                    if (GUILayout.Button("EDIT"))
                    {
                        Edit_Begin();
                    }
                }
                else
                {
                    EditorGUILayout.LabelField("PIVOT:");
                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginHorizontal();
                    {
                        weightedAverage = GUILayout.Toggle(weightedAverage, "weighted avg");

                        if (GUILayout.Button("C HOR"))
                        {
                            Edit_MovePivotCenterHor();
                        }

                        if (GUILayout.Button("C VER"))
                        {
                            Edit_MovePivotCenterVer();
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.Separator();

                    EditorGUILayout.BeginVertical();
                    {
                        GUI.color = Color.cyan;
                        if (GUILayout.Button("TOP", GUILayout.Width(100f)))
                        {
                            Edit_MovePivotTop();
                        }
                        GUI.color = Color.yellow;
                        if (GUILayout.Button("BTM", GUILayout.Width(100f)))
                        {
                            Edit_MovePivotBottom();
                        }
                        GUI.color = Color.white;
                    }
                    EditorGUILayout.EndVertical();

                    EditorGUILayout.TextArea("", GUI.skin.horizontalSlider);

                    EditorGUILayout.BeginHorizontal();
                    {
                        GUI.color = Color.green;
                        if (GUILayout.Button("SAVE AS"))
                        {
                            Edit_SaveAsAsset();
                        }
                        GUI.color = (Color.red + Color.yellow) / 2f;
                        if (GUILayout.Button("OVERWRITE"))
                        {
                            Edit_SaveOverwrite();
                        }
                        GUI.color = Color.red;
                        if (GUILayout.Button("ABORT"))
                        {
                            Edit_Abort();
                        }
                        GUI.color = Color.white;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
コード例 #16
0
 public static void BeginSectionContent()
 {
     EditorGUILayout.BeginVertical(GenesisStyles.SectionContent);
 }
コード例 #17
0
        public override void ShowGUI(Menu menu)
        {
            MenuSource source = menu.menuSource;

            EditorGUILayout.BeginVertical("Button");

            fixedOption = EditorGUILayout.ToggleLeft("Fixed Profile ID only?", fixedOption);
            if (fixedOption)
            {
                numSlots     = 1;
                slotSpacing  = 0f;
                optionToShow = EditorGUILayout.IntField("ID to display:", optionToShow);
            }
            else
            {
                showActive = EditorGUILayout.Toggle("Include active?", showActive);
                maxSlots   = EditorGUILayout.IntField("Max no. of slots:", maxSlots);

                if (source == MenuSource.AdventureCreator)
                {
                    numSlots    = EditorGUILayout.IntSlider("Test slots:", numSlots, 1, maxSlots);
                    slotSpacing = EditorGUILayout.Slider("Slot spacing:", slotSpacing, 0f, 20f);
                    orientation = (ElementOrientation)EditorGUILayout.EnumPopup("Slot orientation:", orientation);
                    if (orientation == ElementOrientation.Grid)
                    {
                        gridWidth = EditorGUILayout.IntSlider("Grid size:", gridWidth, 1, 10);
                    }
                }
            }

            if (source == MenuSource.AdventureCreator)
            {
                anchor      = (TextAnchor)EditorGUILayout.EnumPopup("Text alignment:", anchor);
                textEffects = (TextEffects)EditorGUILayout.EnumPopup("Text effect:", textEffects);
                if (textEffects != TextEffects.None)
                {
                    outlineSize = EditorGUILayout.Slider("Effect size:", outlineSize, 1f, 5f);
                }
            }

            autoHandle = EditorGUILayout.ToggleLeft("Switch profile when click on?", autoHandle);

            if (autoHandle)
            {
                ActionListGUI("ActionList after selecting:", menu.title, "After_Selecting");
            }
            else
            {
                ActionListGUI("ActionList when click:", menu.title, "When_Click");
            }

            if (source != MenuSource.AdventureCreator)
            {
                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical("Button");
                uiHideStyle = (UIHideStyle)EditorGUILayout.EnumPopup("When invisible:", uiHideStyle);
                EditorGUILayout.LabelField("Linked button objects", EditorStyles.boldLabel);

                uiSlots = ResizeUISlots(uiSlots, maxSlots);
                for (int i = 0; i < uiSlots.Length; i++)
                {
                    uiSlots[i].LinkedUiGUI(i, source);
                }
            }

            EditorGUILayout.EndVertical();

            base.ShowGUI(menu);
        }
コード例 #18
0
ファイル: TypesWindow.cs プロジェクト: frank731/topdown
        private void TypePane()
        {
            if (selectedType < 0)
            {
                return;
            }

            var style = EditorStyle.Get;

            var typeListItem = types[selectedType];
            var type         = typeListItem.type;

            typePaneScrollPos = EditorGUILayout.BeginScrollView(typePaneScrollPos, style.area);

            GUILayout.Label(typeListItem.name, style.subheading);
            GUILayout.Label(typeListItem.namespaceName);

            EditorGUILayout.BeginVertical(style.area);

            bool hasParameterlessConstructor = ES3Reflection.HasParameterlessConstructor(type);
            bool isComponent = ES3Reflection.IsAssignableFrom(typeof(Component), type);

            string path = GetOutputPath(types[selectedType].type);

            // An ES3Type file already exists.
            if (File.Exists(path))
            {
                if (hasParameterlessConstructor || isComponent)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Reset to Default"))
                    {
                        SelectNone(true, true);
                        AssetDatabase.MoveAssetToTrash("Assets" + path.Remove(0, Application.dataPath.Length));
                        SelectType(selectedType);
                    }
                    if (GUILayout.Button("Edit ES3Type Script"))
                    {
                        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, 1);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to modify the ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                    if (GUILayout.Button("Click here to edit the ES3Type script"))
                    {
                        UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, 1);
                    }
                    if (GUILayout.Button("Reset to Default"))
                    {
                        SelectAll(true, true);
                        File.Delete(path);
                        AssetDatabase.Refresh();
                    }
                }
            }
            // No ES3Type file and no fields.
            else if (fields.Length == 0)
            {
                if (!hasParameterlessConstructor && !isComponent)
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to create an ES3Type script and modify it to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                }

                if (GUILayout.Button("Create ES3Type Script"))
                {
                    Generate();
                }
            }
            // No ES3Type file, but fields are selectable.
            else
            {
                if (!hasParameterlessConstructor && !isComponent)
                {
                    EditorGUILayout.HelpBox("This type has no public parameterless constructors.\n\nTo support this type you will need to select the fields you wish to serialize below, and then modify the generated ES3Type script to use a specific constructor instead of the parameterless constructor.", MessageType.Info);
                    if (GUILayout.Button("Select all fields and generate ES3Type script"))
                    {
                        SelectAll(true, false);
                        Generate();
                    }
                }
                else
                {
                    if (GUILayout.Button("Create ES3Type Script"))
                    {
                        Generate();
                    }
                }
            }

            EditorGUILayout.EndVertical();

            PropertyPane();

            EditorGUILayout.EndScrollView();
        }
コード例 #19
0
    public override void OnInspectorGUI()
    {
        //MAIN LAYOUT
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
        EditorGUILayout.BeginVertical(rootGroupStyle);
        EditorGUILayout.BeginHorizontal(rootGroupStyle);
        GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("GAME CONFIGURATION", EditorStyles.boldLabel); GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        //MUSIC.
        EditorGUILayout.BeginVertical(rootGroupStyle);
        instance.showMusic = EditorGUILayout.Foldout(instance.showMusic, ("MUSIC"), EditorStyles.foldout);
        if (instance.showMusic)
        {
            EditorGUILayout.BeginVertical(rootGroupStyle);
            instance.MUSIC.gameMusic      = (AudioClip)EditorGUILayout.ObjectField("Game Music:", instance.MUSIC.gameMusic, (typeof(AudioClip)), false);
            instance.MUSIC.looseMusic     = (AudioClip)EditorGUILayout.ObjectField("Loose Music:", instance.MUSIC.looseMusic, (typeof(AudioClip)), false);
            instance.MUSIC.countDownSound = (AudioClip)EditorGUILayout.ObjectField("Countdown Sound:", instance.MUSIC.countDownSound, (typeof(AudioClip)), false);
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();
        //END MUSIC.
        //GUI.
        EditorGUILayout.BeginVertical(rootGroupStyle);
        instance.showGui = EditorGUILayout.Foldout(instance.showGui, ("GUI"), EditorStyles.foldout);
        if (instance.showGui)
        {
            EditorGUILayout.BeginVertical(rootGroupStyle);
            //Config
            instance.GUI.gameoverDelay = EditorGUILayout.FloatField("Game Over Delay:", instance.GUI.gameoverDelay);
            instance.GUI.gamesPerAds   = EditorGUILayout.IntField("Show Ads every:", instance.GUI.gamesPerAds);
            instance.GUI.gamesPerRate  = EditorGUILayout.IntField("Show Rate every:", instance.GUI.gamesPerRate);
            //Menus
            instance.GUI.gameoverMenu   = (GameOverMenu)EditorGUILayout.ObjectField("Game Over Menu:", instance.GUI.gameoverMenu, (typeof(GameOverMenu)), false);
            instance.GUI.pauseMenu      = (PauseMenu)EditorGUILayout.ObjectField("Pause Menu:", instance.GUI.pauseMenu, (typeof(PauseMenu)), false);
            instance.GUI.objectivesMenu = (Objectives)EditorGUILayout.ObjectField("Objectives Menu:", instance.GUI.objectivesMenu, (typeof(Objectives)), false);
            instance.GUI.storeMenu      = (StoreMenu)EditorGUILayout.ObjectField("Store Menu:", instance.GUI.storeMenu, (typeof(StoreMenu)), false);
            instance.GUI.optionsMenu    = (Options)EditorGUILayout.ObjectField("Options Menu:", instance.GUI.optionsMenu, (typeof(Options)), false);
            instance.GUI.scoresMenu     = (ChoosScore)EditorGUILayout.ObjectField("Scores Menu:", instance.GUI.scoresMenu, (typeof(ChoosScore)), false);
            instance.GUI.rateMenu       = (RateApp)EditorGUILayout.ObjectField("Scores Menu:", instance.GUI.rateMenu, (typeof(RateApp)), false);
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();
        //END GUI.

        //STORE.
        EditorGUILayout.BeginVertical(rootGroupStyle);
        instance.showStore = EditorGUILayout.Foldout(instance.showStore, ("STORE ITEMS"), EditorStyles.foldout);
        if (instance.showStore)
        {
            EditorGUILayout.Space();
            //SUITS
            EditorGUILayout.BeginHorizontal(subGroupStyle);
            GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("SUITS");
            GUILayout.FlexibleSpace(); if (StyledButton("ADD SUIT"))
            {
                addSuit();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (instance.STORE_ITEMS.suits.Count == 0)
            {
                EditorGUILayout.BeginVertical(subGroupStyle);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace(); GUILayout.Label("NO SUITS YET"); GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.BeginVertical(rootGroupStyle);
                for (int s = 0; s < instance.STORE_ITEMS.suits.Count; s++)
                {
                    EditorGUILayout.BeginVertical(rootGroupStyle);
                    instance.STORE_ITEMS.suits[s].showItem = EditorGUILayout.Foldout(instance.STORE_ITEMS.suits[s].showItem, (System.String.IsNullOrEmpty(instance.STORE_ITEMS.suits[s].name)? "NEW SUIT":instance.STORE_ITEMS.suits[s].name.ToUpper()), EditorStyles.foldout);
                    if (instance.STORE_ITEMS.suits[s].showItem)
                    {
                        instance.STORE_ITEMS.suits[s].name    = EditorGUILayout.TextField("Name:", instance.STORE_ITEMS.suits[s].name);
                        instance.STORE_ITEMS.suits[s].itemId  = EditorGUILayout.TextField("Item ID:", instance.STORE_ITEMS.suits[s].itemId);
                        instance.STORE_ITEMS.suits[s].cost    = EditorGUILayout.IntField("Cost:", instance.STORE_ITEMS.suits[s].cost);
                        instance.STORE_ITEMS.suits[s].type    = (Item.ItemType)EditorGUILayout.EnumPopup("Type:", instance.STORE_ITEMS.suits[s].type);
                        instance.STORE_ITEMS.suits[s].icon    = (Sprite)EditorGUILayout.ObjectField("Icon:", instance.STORE_ITEMS.suits[s].icon, typeof(Sprite), false);
                        instance.STORE_ITEMS.suits[s].texture = (Texture)EditorGUILayout.ObjectField("Texture:", instance.STORE_ITEMS.suits[s].texture, typeof(Texture), false);
                        EditorGUILayout.BeginHorizontal();
                        if (StyledButton("Remove"))
                        {
                            removeSuit(s);
                        }
                        if (StyledButton("Move Up"))
                        {
                            moveUpSuit(s);
                        }
                        if (StyledButton("Move Down"))
                        {
                            moveDownSuit(s);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
                //END SUITS.
            }
            EditorGUILayout.Space();
            //BOARDS.
            EditorGUILayout.BeginHorizontal(subGroupStyle);
            GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("BOARDS");
            GUILayout.FlexibleSpace(); if (StyledButton("ADD BOARD"))
            {
                addBoard();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (instance.STORE_ITEMS.boards.Count == 0)
            {
                EditorGUILayout.BeginVertical(subGroupStyle);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace(); GUILayout.Label("NO BOARDS YET"); GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.BeginVertical(rootGroupStyle);
                for (int s = 0; s < instance.STORE_ITEMS.boards.Count; s++)
                {
                    EditorGUILayout.BeginVertical(rootGroupStyle);
                    instance.STORE_ITEMS.boards[s].showItem = EditorGUILayout.Foldout(instance.STORE_ITEMS.boards[s].showItem, (System.String.IsNullOrEmpty(instance.STORE_ITEMS.boards[s].name)? "NEW BOARD":instance.STORE_ITEMS.boards[s].name.ToUpper()), EditorStyles.foldout);
                    if (instance.STORE_ITEMS.boards[s].showItem)
                    {
                        instance.STORE_ITEMS.boards[s].name    = EditorGUILayout.TextField("Name:", instance.STORE_ITEMS.boards[s].name);
                        instance.STORE_ITEMS.boards[s].itemId  = EditorGUILayout.TextField("Item ID:", instance.STORE_ITEMS.boards[s].itemId);
                        instance.STORE_ITEMS.boards[s].cost    = EditorGUILayout.IntField("Cost:", instance.STORE_ITEMS.boards[s].cost);
                        instance.STORE_ITEMS.boards[s].type    = (Item.ItemType)EditorGUILayout.EnumPopup("Type:", instance.STORE_ITEMS.boards[s].type);
                        instance.STORE_ITEMS.boards[s].icon    = (Sprite)EditorGUILayout.ObjectField("Icon:", instance.STORE_ITEMS.boards[s].icon, typeof(Sprite), false);
                        instance.STORE_ITEMS.boards[s].texture = (Texture)EditorGUILayout.ObjectField("Texture:", instance.STORE_ITEMS.boards[s].texture, typeof(Texture), false);
                        EditorGUILayout.BeginHorizontal();
                        if (StyledButton("Remove"))
                        {
                            removeBoard(s);
                        }
                        if (StyledButton("Move Up"))
                        {
                            moveUpBoard(s);
                        }
                        if (StyledButton("Move Down"))
                        {
                            moveDownBoard(s);
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.EndVertical();
                //END BOARDS.
            }
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();
        //END STORE.


        //EFFECTS.
        EditorGUILayout.BeginVertical(rootGroupStyle);
        instance.showMisc = EditorGUILayout.Foldout(instance.showMisc, ("EXTRA"), EditorStyles.foldout);
        if (instance.showMisc)
        {
            EditorGUILayout.BeginVertical(rootGroupStyle);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal(rootGroupStyle);
            GUILayout.FlexibleSpace(); EditorGUILayout.LabelField("HIT EFFECTS");
            GUILayout.FlexibleSpace(); if (StyledButton("ADD EFFECT"))
            {
                addEffect();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            if (instance.hitEffects.Length == 0)
            {
                EditorGUILayout.BeginVertical(rootGroupStyle);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace(); GUILayout.Label("FILE EMPTY"); GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndVertical();
            }
            else
            {
                for (int e = 0; e < instance.hitEffects.Length; e++)
                {
                    EditorGUILayout.BeginVertical(rootGroupStyle);
                    EditorGUILayout.BeginHorizontal();
                    instance.hitEffects[e] = (Sprite)EditorGUILayout.ObjectField(instance.hitEffects[e], typeof(Sprite), false);
                    if (StyledButton("Remove Effect"))
                    {
                        removeEffect(e);
                    }
                    EditorGUILayout.EndHorizontal();
                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();
        EditorGUILayout.Space();
        //END EFFECTS.

        EditorGUILayout.BeginHorizontal(rootGroupStyle);
        EditorGUILayout.LabelField("CONNECTIONS", EditorStyles.boldLabel);
        instance.CONNECTIONS = (ConnectionsConfig)EditorGUILayout.ObjectField(instance.CONNECTIONS, (typeof(ConnectionsConfig)), false);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        //END MAIN LAYOUT
        EditorUtility.SetDirty(instance);
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndVertical();
        EditorGUILayout.EndScrollView();
    }
コード例 #20
0
        private void OnGUI()
        {
            #region --- STYLES ---

            var mainTitleStyle = new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleCenter,
                fontStyle = FontStyle.Bold,
                fontSize  = 12
            };

            var titleStyle = new GUIStyle(GUI.skin.label)
            {
                fontStyle = FontStyle.Bold,
                fontSize  = 11
            };

            var titleStyleCenter = new GUIStyle(GUI.skin.label)
            {
                fontStyle = FontStyle.Bold,
                alignment = TextAnchor.MiddleCenter,
                fontSize  = 11
            };

            var labelStyle = new GUIStyle(GUI.skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            };

            var targetButtonStyle = new GUIStyle(GUI.skin.button)
            {
                fixedWidth = 100
            };

            #endregion

            if (_selectedBrain == null)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(C.DEBUG_NO_AIBRAIN_COMPONENT, MessageType.Info);
            }
            else if (!Application.isPlaying)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(C.DEBUG_APPLICATION_NOT_PLAYING, MessageType.Warning);
            }
            else if (!_selectedBrain.gameObject.activeInHierarchy)
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox(C.DEBUG_GAMEOBJECT_DISABLED, MessageType.Warning);
            }
            else
            {
                EditorGUILayout.BeginVertical();

                _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.ExpandWidth(true));

                #region --- HEADER ---

                EditorGUILayout.Space();
                EditorGUILayout.LabelField(C.DEBUG_SELECTED_BRAIN_LABEL + _selectedGameObject.name, mainTitleStyle, null);

                var label = C.DEBUG_BRAIN_IS_LABEL;
                label += _selectedBrain.BrainActive
                    ? C.DEBUG_ACTIVE_LABEL
                    : C.DEBUG_INACTIVE_LABEL;

                label += " | ";
                label += _selectedBrain.Target == null ? C.DEBUG_TARGET_NULL_LABEL : C.DEBUG_TARGET_LABEL + ": " + _selectedBrain.Target.name;
                EditorGUILayout.LabelField(label, labelStyle, null);

                #endregion

                #region --- STATE TRACKING --

                _previousStateName = _currentStateName == _selectedBrain.CurrentState.StateName
                    ? _previousStateName
                    : _currentStateName;
                _currentStateName = _selectedBrain.CurrentState.StateName;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical(GUI.skin.box);

                label = C.DEBUG_PREVIOUS_STATE_LABEL;
                EditorGUILayout.LabelField(label, titleStyleCenter, null);
                label = _previousStateName;
                EditorGUILayout.LabelField(label, labelStyle, null);
                label = C.DEBUG_TIME_IN_STATE_LABEL + ": " + _selectedBrain.TimeInPreviousState.ToString("0.##");
                EditorGUILayout.LabelField(label, labelStyle, null);

                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical(GUI.skin.box);

                label = C.DEBUG_CURRENT_STATE_LABEL;
                EditorGUILayout.LabelField(label, titleStyleCenter, null);
                label = _currentStateName;
                EditorGUILayout.LabelField(label, labelStyle, null);
                label = C.DEBUG_TIME_IN_STATE_LABEL + ": " + _selectedBrain.TimeInThisState.ToString("0.##");
                EditorGUILayout.LabelField(label, labelStyle, null);

                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();

                #endregion


                #region --- ACTIONS ---

                var ar = (from action in _actionList where action != null select action.GetType().Name).ToArray();
                label = C.DEBUG_PERFORMING_LABEL + ": " + string.Join(", ", ar);

                EditorGUILayout.LabelField(label, labelStyle, null);

                #endregion

                EditorGUILayout.Space();

                #region --- STATE TRANSITIONS ---

                label = C.DEBUG_STATE_TRANSITIONS_LABEL;
                EditorGUILayout.LabelField(label, titleStyle);

                foreach (var aiState in _selectedBrain.States)
                {
                    var buttonLabel = aiState.StateName;
                    GUI.backgroundColor = Color.white;
                    if (_selectedBrain.CurrentState.StateName == aiState.StateName)
                    {
                        GUI.backgroundColor = new Color(0f, .8f, 1f, 1);
                        buttonLabel         = "[C] " + aiState.StateName;
                    }
                    foreach (var transition in _selectedBrain.CurrentState.Transitions)
                    {
                        if (transition.FalseState != aiState.StateName && transition.TrueState != aiState.StateName)
                        {
                            continue;
                        }
                        GUI.backgroundColor = new Color(0f, .7f, 1f, 1);
                        buttonLabel         = "[>>] " + aiState.StateName;
                    }

                    EditorGUI.BeginDisabledGroup(_selectedBrain.CurrentState.StateName == aiState.StateName);
                    if (GUILayout.Button(buttonLabel))
                    {
                        TransitionToState(aiState.StateName);
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUI.backgroundColor = Color.white;

                #endregion

                EditorGUILayout.Space();

                #region --- TARGET ---

                label = C.DEBUG_SET_TARGET_LABEL;
                EditorGUILayout.LabelField(label, titleStyle);

                EditorGUILayout.BeginHorizontal();
                aiBrainTarget = EditorGUILayout.ObjectField(C.DEBUG_TARGET_LABEL, aiBrainTarget, typeof(GameObject), true) as GameObject;
                EditorGUI.BeginDisabledGroup(aiBrainTarget == null || !aiBrainTarget.scene.IsValid());
                if (GUILayout.Button(C.DEBUG_SET_LABEL, targetButtonStyle) && aiBrainTarget != null)
                {
                    _selectedBrain.Target = aiBrainTarget.transform;
                }
                EditorGUI.EndDisabledGroup();
                EditorGUI.BeginDisabledGroup(aiBrainTarget == null);
                if (GUILayout.Button(C.DEBUG_REMOVE_LABEL, targetButtonStyle))
                {
                    _selectedBrain.Target = null;
                    aiBrainTarget         = null;
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.LabelField("Target: " + _selectedBrain.Target);
                EditorGUILayout.LabelField("LastKnownTargetPosition: " + _selectedBrain._lastKnownTargetPosition);

                #endregion

                EditorGUILayout.EndScrollView();
                EditorGUILayout.EndVertical();
            }
        }
コード例 #21
0
    void DrawClipEditor(tk2dSpriteAnimationClip clip)
    {
        EditorGUIUtility.LookLikeControls(80.0f, 50.0f);

        var frameBorderStyle = EditorStyles.textField;

        int clipNumFrames = clip.frames.Length;

        if (tk2dPreferences.inst.horizontalAnimDisplay)
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(144.0f));
            EditorGUILayout.BeginHorizontal();

            for (int i = 0; i < clipNumFrames; ++i)
            {
                int frameCount = GetFrameCount(clip, i);
                EditorGUILayout.BeginHorizontal(frameBorderStyle);

                EditorGUILayout.BeginVertical();
                GUILayout.Label(new GUIContent(i.ToString(), "Frame"));
//				GUILayout.Label(new GUIContent((i / clip.fps).ToString("0.00" + "s"), "Time"));
                EditorGUILayout.EndVertical();
                DrawSpritePreview(clip.frames[i].spriteCollection, clip.frames[i].spriteId);

                EditorGUILayout.BeginVertical();
                DrawFrameEditor(clip, i, frameCount);
                EditorGUILayout.EndVertical();

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUILayout.Space();

                i += (frameCount - 1);
            }

            DrawAddFrame(clip, false);

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndScrollView();
        }
        else
        {
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            EditorGUILayout.BeginVertical();

            for (int i = 0; i < clipNumFrames; ++i)
            {
                int frameCount = GetFrameCount(clip, i);
                EditorGUILayout.BeginHorizontal(frameBorderStyle);

                EditorGUILayout.BeginVertical();
                GUILayout.Label(new GUIContent(i.ToString(), "Frame"));
//				GUILayout.Label(new GUIContent((i / clip.fps).ToString("0.00" + "s"), "Time"));
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                DrawFrameEditor(clip, i, frameCount);
                EditorGUILayout.EndVertical();

                DrawSpritePreview(clip.frames[i].spriteCollection, clip.frames[i].spriteId);

                EditorGUILayout.EndHorizontal();

                i += (frameCount - 1);
            }

            DrawAddFrame(clip, true);

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }

        if (deferredFrameOp != null)
        {
            deferredFrameOp(clip);
            deferredFrameOp = null;

            GUI.changed = true;
        }
    }
コード例 #22
0
        public static void ArrayEditor(SerializedProperty objInfoList, Type objectType, Action <int> ArrayEditorMiddle, Action <int> ArrayEditorTrail, params string[] propertyHeader)
        {
            EditorGUILayout.BeginVertical("BOX");
            EditorGUI.indentLevel += 1;
            for (int i = 0; i < objInfoList.arraySize; i++)
            {
                int index = i;
                EditorGUI.indentLevel += 1;
                EditorGUILayout.BeginHorizontal("BOX");
                EditorGUILayout.BeginVertical();



                var fields = objectType.GetFields();

                for (int a = 0; a < fields.Length; a++)
                {
                    var arrayObject         = objInfoList.GetArrayElementAtIndex(i).FindPropertyRelative(fields[a].Name);
                    EditorNameAttribute ena = Attribute.GetCustomAttribute(fields[a], typeof(EditorNameAttribute)) as EditorNameAttribute;

                    if (fields[a].FieldType.IsArray)
                    {
                        ArrayEditor(arrayObject, fields[a].FieldType.GetElementType(), null, null);
                    }
                    else
                    {
                        if (fields[a].FieldType == typeof(Sprite))
                        {
                            EditorGUILayout.Separator();
                            if (ena != null)
                            {
                                EditorGUILayout.ObjectField(arrayObject, new GUIContent(ena.Name));
                            }
                            else
                            {
                                EditorGUILayout.ObjectField(arrayObject);
                            }
                        }
                        else if (fields[a].FieldType == typeof(Vector2))
                        {
                            EditorGUILayout.Separator();
                            if (ena != null)
                            {
                                EditorGUILayout.PropertyField(arrayObject, new GUIContent(ena.Name));
                            }
                            else
                            {
                                EditorGUILayout.PropertyField(arrayObject);
                            }
                        }
                        else
                        {
                            EditorGUILayout.Separator();
                            if (ena != null)
                            {
                                EditorGUILayout.PropertyField(arrayObject, new GUIContent(ena.Name));
                            }
                            else
                            {
                                EditorGUILayout.PropertyField(arrayObject);
                            }
                        }
                    }
                }


                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();


                if (GUILayout.Button("刪除"))
                {
                    objInfoList.DeleteArrayElementAtIndex(i);
                }

                if (ArrayEditorMiddle != null)
                {
                    ArrayEditorMiddle(index);
                }


                EditorGUILayout.EndVertical();



                if (ArrayEditorTrail != null)
                {
                    ArrayEditorTrail(index);
                }

                EditorGUILayout.EndHorizontal();


                EditorGUILayout.Space();
                EditorGUI.indentLevel -= 1;
            }

            EditorGUI.indentLevel -= 1;

            if (GUILayout.Button("新增欄位"))
            {
                objInfoList.arraySize++;
            }
            //if (GUILayout.Button("刪除全部"))
            //{
            //    objInfoList.ClearArray();
            //}
            EditorGUILayout.EndVertical();
        }
コード例 #23
0
        public override void OnInspectorGUI()
        {
            if (!RenderProfileHeader(ProfileTitle, ProfileDescription, target, true, BackProfileType.Input))
            {
                return;
            }

            serializedObject.Update();

            using (new EditorGUI.DisabledGroupScope(IsProfileLock((BaseMixedRealityProfile)target)))
            {
                EditorGUILayout.PropertyField(indicatorsPrefab);

                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical("Label");
                EditorGUILayout.PropertyField(mouseRotationSensitivity);
                EditorGUILayout.PropertyField(mouseX);
                EditorGUILayout.PropertyField(mouseY);
                EditorGUILayout.PropertyField(mouseScroll);
                EditorGUILayout.PropertyField(doublePressTime);
                EditorGUILayout.PropertyField(isHandsFreeInputEnabled);
                EditorGUILayout.EndVertical();

                EditorGUILayout.PropertyField(isCameraControlEnabled);
                {
                    EditorGUILayout.BeginVertical("Label");
                    using (new EditorGUI.DisabledGroupScope(!isCameraControlEnabled.boolValue))
                    {
                        EditorGUILayout.PropertyField(mouseLookSpeed);
                        EditorGUILayout.PropertyField(mouseLookButton);
                        EditorGUILayout.PropertyField(mouseLookToggle);
                        EditorGUILayout.PropertyField(isControllerLookInverted);
                        EditorGUILayout.PropertyField(currentControlMode);
                        EditorGUILayout.PropertyField(fastControlKey);
                        EditorGUILayout.PropertyField(controlSlowSpeed);
                        EditorGUILayout.PropertyField(controlFastSpeed);
                        EditorGUILayout.PropertyField(moveHorizontal);
                        EditorGUILayout.PropertyField(moveVertical);
                        EditorGUILayout.PropertyField(moveUpDown);
                        EditorGUILayout.PropertyField(lookHorizontal);
                        EditorGUILayout.PropertyField(lookVertical);

                        EditorGUILayout.EndVertical();
                    }
                }

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(defaultEyeGazeSimulationMode);

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(defaultControllerSimulationMode);
                {
                    EditorGUILayout.BeginVertical("Label");

                    EditorGUILayout.PropertyField(toggleLeftControllerKey);
                    EditorGUILayout.PropertyField(toggleRightControllerKey);
                    EditorGUILayout.PropertyField(controllerHideTimeout);
                    EditorGUILayout.PropertyField(leftControllerManipulationKey);
                    EditorGUILayout.PropertyField(rightControllerManipulationKey);
                    EditorGUILayout.PropertyField(mouseControllerRotationSpeed);
                    EditorGUILayout.PropertyField(controllerRotateButton);
                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(defaultControllerDistance);
                    EditorGUILayout.PropertyField(controllerDepthMultiplier);
                    EditorGUILayout.PropertyField(controllerJitterAmount);
                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(defaultHandGesture);
                    EditorGUILayout.PropertyField(leftMouseHandGesture);
                    EditorGUILayout.PropertyField(middleMouseHandGesture);
                    EditorGUILayout.PropertyField(rightMouseHandGesture);
                    EditorGUILayout.PropertyField(handGestureAnimationSpeed);
                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(holdStartDuration);
                    EditorGUILayout.PropertyField(navigationStartThreshold);
                    EditorGUILayout.Space();

                    EditorGUILayout.PropertyField(motionControllerTriggerKey);
                    EditorGUILayout.PropertyField(motionControllerGrabKey);
                    EditorGUILayout.PropertyField(motionControllerMenuKey);
                    EditorGUILayout.Space();

                    EditorGUILayout.EndVertical();
                }

                serializedObject.ApplyModifiedProperties();
            }
        }
コード例 #24
0
        void OnGUI()
        {
            if (!UIUtils.Initialized || UIUtils.CurrentWindow == null)
            {
                EditorGUILayout.LabelField(NoASEWindowWarning);
                return;
            }

            if (m_init)
            {
                Init();
            }

            KeyCode key = Event.current.keyCode;

            if (key == ShortcutsManager.ScrollUpKey)
            {
                m_currentScrollPos.y -= 10;
                if (m_currentScrollPos.y < 0)
                {
                    m_currentScrollPos.y = 0;
                }
                Event.current.Use();
            }

            if (key == ShortcutsManager.ScrollDownKey)
            {
                m_currentScrollPos.y += 10;
                Event.current.Use();
            }

            if (Event.current.type == EventType.MouseDrag && Event.current.button > 0)
            {
                m_currentScrollPos.x += Constants.MenuDragSpeed * Event.current.delta.x;
                if (m_currentScrollPos.x < 0)
                {
                    m_currentScrollPos.x = 0;
                }

                m_currentScrollPos.y += Constants.MenuDragSpeed * Event.current.delta.y;
                if (m_currentScrollPos.y < 0)
                {
                    m_currentScrollPos.y = 0;
                }
            }

            m_availableArea = new Rect(WindowPosX, WindowPosY, position.width - 2 * WindowPosX, position.height - 2 * WindowPosY);
            GUILayout.BeginArea(m_availableArea);
            {
                if (GUILayout.Button("Wiki Page"))
                {
                    Application.OpenURL(Constants.HelpURL);
                }

                m_currentScrollPos = GUILayout.BeginScrollView(m_currentScrollPos);
                {
                    EditorGUILayout.BeginVertical();
                    {
                        NodeUtils.DrawPropertyGroup(ref m_portAreaFoldout, PortLegendTitle, DrawPortInfo);
                        float currLabelWidth = EditorGUIUtility.labelWidth;
                        EditorGUIUtility.labelWidth = 1;
                        NodeUtils.DrawPropertyGroup(ref m_editorShortcutAreaFoldout, EditorShortcutsTitle, DrawEditorShortcuts);
                        NodeUtils.DrawPropertyGroup(ref m_menuShortcutAreaFoldout, MenuShortcutsTitle, DrawMenuShortcuts);
                        NodeUtils.DrawPropertyGroup(ref m_nodesShortcutAreaFoldout, NodesShortcutsTitle, DrawNodesShortcuts);
                        NodeUtils.DrawPropertyGroup(ref m_compatibleAssetsFoldout, CompatibleAssetsTitle, DrawCompatibleAssets);
                        NodeUtils.DrawPropertyGroup(ref m_nodesDescriptionAreaFoldout, NodesDescTitle, DrawNodeDescriptions);
                        EditorGUIUtility.labelWidth = currLabelWidth;
                    }
                    EditorGUILayout.EndVertical();
                }
                GUILayout.EndScrollView();
            }
            GUILayout.EndArea();
        }
コード例 #25
0
        private void EditorWindow(int id)
        {
            EditorGUILayout.BeginVertical();

            // Draw sprites on the map
            if (spritesheet)
            {
                for (int i = 0; i < gridCells.Count; ++i)
                {
                    // Loop through all layers and draw sprites corresponding to them
                    foreach (int layer in tilemap.MapRepresentation.Keys)
                    {
                        if (tilemap.MapRepresentation[layer].Cells[i] != -1)
                        {
                            int tileId   = tilemap.MapRepresentation[layer].Cells[i]; //Extract tileId corresponding to current grid cell and layer
                            int spriteId = tilemap.Tiles[tileId].SpriteId;            // Get tile using its id and extract spriteId from it
                            GUI.DrawTextureWithTexCoords(gridCells[i], spritesheet, tilemap.Sprites[spriteId].DrawArea);
                        }
                    }
                }
            }

            // Listen for mouse down and mouse drag events (only left mouse button)
            Event inputEvent = Event.current;

            if ((inputEvent.type == EventType.MouseDown || inputEvent.type == EventType.MouseDrag) && inputEvent.button == 0)
            {
                // Check if any of map grid cells contain mouse position
                for (int i = 0; i < gridCells.Count; ++i)
                {
                    if (gridCells[i].Contains(inputEvent.mousePosition))
                    {
                        // Paint if paint mode is set and a tile to pint is actually selected
                        if (state == EditState.Paint && selectedTileId >= 0)
                        {
                            tilemap.MapRepresentation[selectedLayer].Cells[i] = tilemap.Tiles[selectedTileId].Id;
                        }
                        // Erase tile from map if erase mode is selected
                        else if (state == EditState.Erase)
                        {
                            tilemap.MapRepresentation[selectedLayer].Cells[i] = -1;
                        }
                        // Use mouse event and request repaint
                        inputEvent.Use();
                        Repaint();
                        break;
                    }
                }
            }

            // Draw helper lines to visualize the map grid
            Handles.BeginGUI();
            Handles.color = Color.blue;
            for (int x = (int)editorWindowRect.x + mapCellSize; x <= mapCellSize * mapSize; x += mapCellSize)
            {
                Handles.DrawLine(new Vector3(x, editorWindowRect.y), new Vector3(x, mapCellSize * 16));
            }
            for (int y = (int)editorWindowRect.y + mapCellSize; y <= mapCellSize * mapSize; y += mapCellSize)
            {
                Handles.DrawLine(new Vector3(editorWindowRect.x, y), new Vector3(mapCellSize * 15, y));
            }
            Handles.EndGUI();

            EditorGUILayout.EndVertical();
        }
コード例 #26
0
    void OnGUI()
    {
        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Particle Scaler Utility", EditorStyles.whiteLargeLabel);

        if (selectedObjects.Count == 0)
        {
            EditorGUILayout.HelpBox("Please select at least one GameObject in the hierarchy containing a Particle System.", MessageType.Warning);
        }

        EditorGUILayout.Separator();

        scaleChildren  = EditorGUILayout.Toggle("Scale Children", scaleChildren);
        scalePosition  = EditorGUILayout.Toggle("Scale Position", scalePosition);
        restartOnScale = EditorGUILayout.Toggle("Clear on Scale", restartOnScale);

        EditorGUI.BeginDisabledGroup(!validSelection);

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Preset Scales", EditorStyles.boldLabel);
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("25%", GUILayout.Height(30)))
        {
            ApplyScale(0.25f);
        }
        if (GUILayout.Button("50%", GUILayout.Height(30)))
        {
            ApplyScale(0.5f);
        }
        if (GUILayout.Button("75%", GUILayout.Height(30)))
        {
            ApplyScale(0.75f);
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("150%", GUILayout.Height(30)))
        {
            ApplyScale(1.5f);
        }
        if (GUILayout.Button("200%", GUILayout.Height(30)))
        {
            ApplyScale(2f);
        }
        if (GUILayout.Button("250%", GUILayout.Height(30)))
        {
            ApplyScale(2.5f);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Custom Scale", EditorStyles.boldLabel);
        scale = EditorGUILayout.Slider("Custom Scale", scale, 0.1f, 10f);
        if (GUILayout.Button("Apply Custom Scale!", GUILayout.Height(40)))
        {
            ApplyScale(scale);
        }

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Selected Objects:", EditorStyles.boldLabel);
        EditorGUILayout.BeginVertical("Box");
        for (int i = 0; i < selectedObjects.Count; i++)
        {
            GameObject obj = selectedObjects[i];
            EditorGUILayout.LabelField((i + 1) + ". " + obj.name, EditorStyles.miniLabel);
        }
        EditorGUILayout.EndVertical();

        EditorGUI.EndDisabledGroup();

        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Particle Scaler Utility v1.0 - lukepeek.com", EditorStyles.miniLabel);


        this.Repaint();
    }
コード例 #27
0
    public override void OnInspectorGUI()
    {
        m_object.Update();
        DrawDefaultInspector();

        _2dxFX_AL_SandFX _2dxScript = (_2dxFX_AL_SandFX)target;

        Texture2D icon = Resources.Load("2dxfxinspector-al") as Texture2D;

        if (icon)
        {
            Rect  r;
            float ih     = icon.height;
            float iw     = icon.width;
            float result = ih / iw;
            float w      = Screen.width;
            result = result * w;
            r      = GUILayoutUtility.GetRect(ih, result);
            EditorGUI.DrawTextureTransparent(r, icon);
        }
        EditorGUILayout.LabelField("Advanced Lightning may work on mobile high-end devices and may be slower than the Standard 2DxFX effects due to is lightning system. Use it only if you need it.", EditorStyles.helpBox);
        EditorGUILayout.PropertyField(m_object.FindProperty("AddShadow"), new GUIContent("Add Shadow", "Use a unique material, reduce drastically the use of draw call"));
        if (_2dxScript.AddShadow)
        {
            EditorGUILayout.PropertyField(m_object.FindProperty("ReceivedShadow"), new GUIContent("Received Shadow : No Transparency and Use Z Buffering instead of Sprite Order Layers", "Received Shadow, No Transparency and Use Z Buffering instead of Sprite Order Layers"));
            if (_2dxScript.ReceivedShadow)
            {
                EditorGUILayout.LabelField("Note 1: Blend Fusion work but without transparency\n", EditorStyles.helpBox);
            }
        }

        // Mode Blend
        string BlendMethode = "Normal";

        if (_2dxScript.BlendMode == 0)
        {
            BlendMethode = "Normal";
        }
        if (_2dxScript.BlendMode == 1)
        {
            BlendMethode = "Additive";
        }
        if (_2dxScript.BlendMode == 2)
        {
            BlendMethode = "Darken";
        }
        if (_2dxScript.BlendMode == 3)
        {
            BlendMethode = "Lighten";
        }
        if (_2dxScript.BlendMode == 4)
        {
            BlendMethode = "Linear Burn";
        }
        if (_2dxScript.BlendMode == 5)
        {
            BlendMethode = "Linear Dodge";
        }
        if (_2dxScript.BlendMode == 6)
        {
            BlendMethode = "Multiply";
        }
        if (_2dxScript.BlendMode == 7)
        {
            BlendMethode = "Soft Aditive";
        }
        if (_2dxScript.BlendMode == 8)
        {
            BlendMethode = "2x Multiplicative";
        }

        EditorGUILayout.PropertyField(m_object.FindProperty("ForceMaterial"), new GUIContent("Shared Material", "Use a unique material, reduce drastically the use of draw call"));

        if (_2dxScript.ForceMaterial == null)
        {
            _2dxScript.ActiveChange = true;
        }
        else
        {
            if (GUILayout.Button("Remove Shared Material"))
            {
                _2dxScript.ForceMaterial = null;
                _2dxScript.ShaderChange  = 1;
                _2dxScript.ActiveChange  = true;
                _2dxScript.CallUpdate();
            }

            EditorGUILayout.PropertyField(m_object.FindProperty("ActiveChange"), new GUIContent("Change Material Property", "Change The Material Property"));
        }

        if (_2dxScript.ActiveChange)
        {
            EditorGUILayout.BeginVertical("Box");

            Texture2D icone = Resources.Load("2dxfx-icon-color") as Texture2D;
            EditorGUILayout.PropertyField(m_object.FindProperty("Sand"), new GUIContent("Sand Value", icone, "Turn your sprite into a sand sprite !"));

            EditorGUILayout.BeginVertical("Box");

            icone = Resources.Load("2dxfx-icon-fade") as Texture2D;
            EditorGUILayout.PropertyField(m_object.FindProperty("_Alpha"), new GUIContent("Fading", icone, "Fade from nothing to showing"));

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Change Blend Fusion = " + BlendMethode, EditorStyles.whiteLargeLabel);
            if (_2dxScript.ReceivedShadow)
            {
                EditorGUILayout.LabelField("Note: Blend Fusion is not working correctly with Received Shadow", EditorStyles.helpBox);
            }

            EditorGUILayout.BeginHorizontal("Box");

            if (GUILayout.Button("Normal", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 0;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Additive", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 1;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Darken", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 2;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Lighten", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 3;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Linear Burn", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 4;
                _2dxScript.CallUpdate();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal("Box");

            if (GUILayout.Button("Linear Dodge", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 5;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Multiply", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 6;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("Soft Aditive", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 7;
                _2dxScript.CallUpdate();
            }
            if (GUILayout.Button("2x Multiplicative", EditorStyles.toolbarButton))
            {
                _2dxScript.BlendMode = 8;
                _2dxScript.CallUpdate();
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
        }

        m_object.ApplyModifiedProperties();
    }
コード例 #28
0
    public override void OnInspectorGUI()
    {
        // Update the block list
        GetTarget.Update();

        SerializedProperty global_TextSettingsRef = TextSettings;
        SerializedProperty global_Sound = global_TextSettingsRef.FindPropertyRelative("TextSound");
        SerializedProperty global_DisplaySpeed = global_TextSettingsRef.FindPropertyRelative("TextDisplaySpeed");
        //SerializedProperty global_BlockDelay = global_TextSettingsRef.FindPropertyRelative("BlockDelay");
        SerializedProperty global_TimeNextThread = global_TextSettingsRef.FindPropertyRelative("TimeToNextThread");
        SerializedProperty global_DecayTime = global_TextSettingsRef.FindPropertyRelative("TextDecayTime");
        SerializedProperty global_TextOutput = global_TextSettingsRef.FindPropertyRelative("GlobalTextOutput");
        

        GUIStyle boldStyle = new GUIStyle
        {
            fontStyle = FontStyle.Bold
        };

        GUIStyle wordWarpStyle = new GUIStyle
        {
            wordWrap = true
        };

        GUILayoutOption[] TextLayout = {
            GUILayout.MaxWidth(500),
            GUILayout.MinHeight(45),
            GUILayout.MaxHeight(100)
        };

        GUILayoutOption[] AddRemoveLayout =
        {
            GUILayout.Height(17),
            GUILayout.Width(17)
        };

        GUIStyle AddRemoveStyle = GUI.skin.button;

        AddRemoveStyle.alignment = TextAnchor.MiddleCenter;


        EditorGUILayout.LabelField("Text Display Settings", boldStyle);
        global_Sound.objectReferenceValue = EditorGUILayout.ObjectField
            (
                "    Sound",
                global_Sound.objectReferenceValue,
                typeof(AudioClip),
                true
            );
        global_DisplaySpeed.floatValue = EditorGUILayout.FloatField("    Chararcter Delay Time", global_DisplaySpeed.floatValue);
        //global_BlockDelay.floatValue = EditorGUILayout.FloatField("    Block Delay", global_BlockDelay.floatValue);
        global_TimeNextThread.floatValue = EditorGUILayout.FloatField("    Time To Next Thread", global_TimeNextThread.floatValue);
        global_DecayTime.floatValue = EditorGUILayout.FloatField("    Decay Time", global_DecayTime.floatValue);
        global_TextOutput.objectReferenceValue = EditorGUILayout.ObjectField
            (
                "    Text Output",
                global_TextOutput.objectReferenceValue,
                typeof(TextMeshProUGUI),
                true
            );

        EditorGUILayout.Space();

        // Button to add a new block of dialogue
        if (GUILayout.Button("Add New Block of Dialogue", GUILayout.Height(18)))
        {
            controller.DialogueBlockList.Add(new DialogueController.DialogueBlock());
        }


        if (controller.DialogueBlockList.Count > 1)
        {
            if (GUILayout.Button("Remove a Block of Dialogue", GUILayout.Height(18)))
                controller.DialogueBlockList.RemoveAt(controller.DialogueBlockList.Count - 1);
        }

        // If there is no block, add one (happens when a new container is created)
        if (controller.DialogueBlockList.Count == 0)
        {
            controller.DialogueBlockList.Add(new DialogueController.DialogueBlock());
        }



        EditorGUILayout.Space();

        // Display the block  in the inspector
        for (int i = 0; i < BlockList.arraySize; i++)
        {

            SerializedProperty m_BlockRef = BlockList.GetArrayElementAtIndex(i);
            SerializedProperty m_BlockName = m_BlockRef.FindPropertyRelative("BlockName");
            SerializedProperty m_Repeatable = m_BlockRef.FindPropertyRelative("CanBeShownAgain");
            SerializedProperty m_BlockDelay = m_BlockRef.FindPropertyRelative("BlockDelay");
            SerializedProperty m_BlockThread = m_BlockRef.FindPropertyRelative("DialogueThread");
            SerializedProperty m_TriggerQuickAccess = m_BlockRef.FindPropertyRelative("TriggerQuickAccess");
            SerializedProperty m_LocalFontSettings = m_BlockRef.FindPropertyRelative("localDialogueSettings");

            // Add each block to the enum.
        
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("___________________________________________________________________________________________________________________________________________");
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Block: " + m_BlockName.stringValue, boldStyle);

            m_BlockName.stringValue = EditorGUILayout.TextField("Block Name", m_BlockName.stringValue);

            if (m_BlockName.stringValue == "")
            {
                m_BlockName.stringValue = i.ToString();
            }

            // If the block doesn't have a thread, add one
            if (m_BlockThread.arraySize == 0)
            {
                m_BlockThread.InsertArrayElementAtIndex(0);
                m_BlockThread.GetArrayElementAtIndex(0).stringValue = "Text...";
            }



            EditorGUILayout.PropertyField(m_Repeatable);
            EditorGUILayout.PropertyField(m_BlockDelay);

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            // The bit for adding a new thread
            if (GUILayout.Button("Add New Thread", GUILayout.Width(117), GUILayout.Height(18)))
            {
                m_BlockThread.InsertArrayElementAtIndex(m_BlockThread.arraySize);
                m_BlockThread.GetArrayElementAtIndex(m_BlockThread.arraySize - 1).stringValue = "Text...";
            }
            if (m_BlockThread.arraySize > 1)
            {
                if (GUILayout.Button("Remove a Thread", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20)))
                {
                    m_BlockThread.DeleteArrayElementAtIndex(m_BlockThread.arraySize - 1);
                }
            }
            EditorGUILayout.EndHorizontal();

            for (int n = 0; n < m_BlockThread.arraySize; n++)
            {

                EditorGUILayout.BeginHorizontal();
                // Text box
                m_BlockThread.GetArrayElementAtIndex(n).stringValue = GUILayout.TextArea(m_BlockThread.GetArrayElementAtIndex(n).stringValue, TextLayout);

                EditorGUILayout.BeginVertical();
                // Add Button
                if (GUILayout.Button("+", AddRemoveStyle, AddRemoveLayout))
                {
                    m_BlockThread.InsertArrayElementAtIndex(n);
                    m_BlockThread.GetArrayElementAtIndex(n + 1).stringValue = "Text...";
                }
                // Remove button
                if (m_BlockThread.arraySize > 1)
                {
                    if (GUILayout.Button("-", AddRemoveStyle, AddRemoveLayout))
                    {
                        // Remove TExt box
                        m_BlockThread.DeleteArrayElementAtIndex(n);
                    }
                }

                EditorGUILayout.EndVertical();


                EditorGUILayout.EndHorizontal();
            }



            EditorGUILayout.PropertyField(m_TriggerQuickAccess);

            EditorGUILayout.Space();
            
            

            EditorGUILayout.BeginHorizontal();
            // Add / Remove buttons for the blocks
            if (GUILayout.Button("+", AddRemoveStyle, AddRemoveLayout))
            {
                controller.DialogueBlockList.Insert(i + 1, new DialogueController.DialogueBlock());
            }
            if (controller.DialogueBlockList.Count > 1)
            {

                if (GUILayout.Button("-", AddRemoveStyle, AddRemoveLayout))
                {
                    controller.DialogueBlockList.RemoveAt(i);
                }
            }

            EditorGUILayout.EndHorizontal();
            
        }

        GetTarget.ApplyModifiedProperties();

    }
コード例 #29
0
    public override void OnInspectorGUI()
    {
        tk2dSlicedSprite sprite = (tk2dSlicedSprite)target;

        base.OnInspectorGUI();

        if (sprite.Collection == null)
        {
            return;
        }


        EditorGUILayout.BeginVertical();

        var spriteData = sprite.GetCurrentSpriteDef();

        // need raw extents (excluding scale)
        Vector3 extents = spriteData.boundsData[1];

        // this is the size of one texel
        Vector3 spritePixelMultiplier = new Vector3(0, 0);

        bool newCreateBoxCollider = EditorGUILayout.Toggle("Create Box Collider", sprite.CreateBoxCollider);

        if (newCreateBoxCollider != sprite.CreateBoxCollider)
        {
            Undo.RegisterUndo(targetSlicedSprites, "Create Box Collider");
            sprite.CreateBoxCollider = newCreateBoxCollider;
        }

        // if either of these are zero, the division to rescale to pixels will result in a
        // div0, so display the data in fractions to avoid this situation
        bool editBorderInFractions = true;

        if (spriteData.texelSize.x != 0.0f && spriteData.texelSize.y != 0.0f && extents.x != 0.0f && extents.y != 0.0f)
        {
            spritePixelMultiplier = new Vector3(extents.x / spriteData.texelSize.x, extents.y / spriteData.texelSize.y, 1);
            editBorderInFractions = false;
        }

        if (!editBorderInFractions)
        {
            if (sprite.transform.localScale == Vector3.one && sprite.legacyMode)
            {
                Vector2 scalePixelUnits        = new Vector2(spritePixelMultiplier.x * sprite.scale.x, spritePixelMultiplier.y * sprite.scale.y);
                Vector2 scalePixelUnitsChanged = EditorGUILayout.Vector2Field("Scale (Pixel Units)", scalePixelUnits);
                if (scalePixelUnits != scalePixelUnitsChanged)
                {
                    Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite Scale");
                    foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                    {
                        spr.scale = new Vector3(scalePixelUnitsChanged.x / spritePixelMultiplier.x, scalePixelUnitsChanged.y / spritePixelMultiplier.y, sprite.scale.z);
                    }
                }
            }
            else
            {
                Vector2 newDimensions = EditorGUILayout.Vector2Field("Dimensions (Pixel Units)", sprite.dimensions);
                if (newDimensions != sprite.dimensions)
                {
                    Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite Dimensions");
                    foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                    {
                        spr.dimensions = newDimensions;
                    }
                }

                tk2dSlicedSprite.Anchor newAnchor = (tk2dSlicedSprite.Anchor)EditorGUILayout.EnumPopup("Anchor", sprite.anchor);
                if (newAnchor != sprite.anchor)
                {
                    Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite Anchor");
                    foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                    {
                        spr.anchor = newAnchor;
                    }
                }
            }

            EditorGUILayout.PrefixLabel("Border");
            EditorGUI.indentLevel++;

            float newBorderLeft = EditorGUILayout.FloatField("Left", sprite.borderLeft * spritePixelMultiplier.x) / spritePixelMultiplier.x;
            if (newBorderLeft != sprite.borderLeft)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderLeft");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderLeft = newBorderLeft;
                }
            }
            float newBorderRight = EditorGUILayout.FloatField("Right", sprite.borderRight * spritePixelMultiplier.x) / spritePixelMultiplier.x;
            if (newBorderRight != sprite.borderRight)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderRight");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderRight = newBorderRight;
                }
            }
            float newBorderTop = EditorGUILayout.FloatField("Top", sprite.borderTop * spritePixelMultiplier.y) / spritePixelMultiplier.y;
            if (newBorderTop != sprite.borderTop)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderTop");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderTop = newBorderTop;
                }
            }
            float newBorderBottom = EditorGUILayout.FloatField("Bottom", sprite.borderBottom * spritePixelMultiplier.y) / spritePixelMultiplier.y;
            if (newBorderBottom != sprite.borderBottom)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderBottom");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderBottom = newBorderBottom;
                }
            }

            bool newBorderOnly = EditorGUILayout.Toggle("Draw Border Only", sprite.BorderOnly);
            if (newBorderOnly != sprite.BorderOnly)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite Border Only");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.BorderOnly = newBorderOnly;
                }
            }

            EditorGUI.indentLevel--;
        }
        else
        {
            GUILayout.Label("Border (Displayed as Fraction).\nSprite Collection needs to be rebuilt.", "textarea");
            EditorGUI.indentLevel++;

            float newBorderLeft = EditorGUILayout.FloatField("Left", sprite.borderLeft);
            if (newBorderLeft != sprite.borderLeft)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderLeft");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderLeft = newBorderLeft;
                }
            }
            float newBorderRight = EditorGUILayout.FloatField("Right", sprite.borderRight);
            if (newBorderRight != sprite.borderRight)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderRight");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderRight = newBorderRight;
                }
            }
            float newBorderTop = EditorGUILayout.FloatField("Top", sprite.borderTop);
            if (newBorderTop != sprite.borderTop)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderTop");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderTop = newBorderTop;
                }
            }
            float newBorderBottom = EditorGUILayout.FloatField("Bottom", sprite.borderBottom);
            if (newBorderBottom != sprite.borderBottom)
            {
                Undo.RegisterUndo(targetSlicedSprites, "Sliced Sprite BorderBottom");
                foreach (tk2dSlicedSprite spr in targetSlicedSprites)
                {
                    spr.borderBottom = newBorderBottom;
                }
            }

            EditorGUI.indentLevel--;
        }

        // One of the border valus has changed, so simply rebuild mesh data here
        if (GUI.changed)
        {
            foreach (tk2dSlicedSprite spr in targetSlicedSprites)
            {
                spr.Build();
                EditorUtility.SetDirty(spr);
            }
        }

        EditorGUILayout.EndVertical();
    }
コード例 #30
0
        public void RenderEditorGUI(UnityEngine.Object undoRecordObject)
        {
            bool        newBool;
            const float toggleWidth = 65.0f;

            // Shortcut name label
            EditorGUILayout.BeginVertical("Box");
            EditorGUILayoutEx.SectionHeader(Name);

            // Enabled/disabled
            var content = new GUIContent();

            content.text    = "Is enabled";
            content.tooltip = "Allows you to enable/disable a shortcut key.";
            newBool         = EditorGUILayout.ToggleLeft(content, IsEnabled);
            if (newBool != IsEnabled)
            {
                EditorUndoEx.Record(undoRecordObject);
                IsEnabled = newBool;
            }

            int selectedIndex = _availableKeyNames.IndexOf(Key.ToString());
            int newIndex      = EditorGUILayout.Popup("Key", selectedIndex, _availableKeyNames.ToArray());

            if (newIndex != selectedIndex)
            {
                EditorUndoEx.Record(undoRecordObject);
                Key = _availableKeys[newIndex];
            }

            // Modifiers
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical("Box");
            newBool = EditorGUILayout.ToggleLeft("LCtrl", _lCtrl, GUILayout.Width(toggleWidth));
            if (newBool != _lCtrl)
            {
                EditorUndoEx.Record(undoRecordObject);
                _lCtrl = newBool;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            newBool = EditorGUILayout.ToggleLeft("LCmd", _lCmd, GUILayout.Width(toggleWidth));
            if (newBool != _lCmd)
            {
                EditorUndoEx.Record(undoRecordObject);
                _lCmd = newBool;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            newBool = EditorGUILayout.ToggleLeft("LAlt", _lAlt, GUILayout.Width(toggleWidth));
            if (newBool != _lAlt)
            {
                EditorUndoEx.Record(undoRecordObject);
                _lAlt = newBool;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical("Box");
            newBool = EditorGUILayout.ToggleLeft("LShift", _lShift, GUILayout.Width(toggleWidth));
            if (newBool != _lShift)
            {
                EditorUndoEx.Record(undoRecordObject);
                _lShift = newBool;
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            // Mouse buttons
            if (_staticData.CanHaveMouseButtons)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical("Box");
                newBool = EditorGUILayout.ToggleLeft("LMouse", _lMouseBtn, GUILayout.Width(toggleWidth));
                if (newBool != _lMouseBtn)
                {
                    EditorUndoEx.Record(undoRecordObject);
                    _lMouseBtn = newBool;
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical("Box");
                newBool = EditorGUILayout.ToggleLeft("RMouse", _rMouseBtn, GUILayout.Width(toggleWidth));
                if (newBool != _rMouseBtn)
                {
                    EditorUndoEx.Record(undoRecordObject);
                    _rMouseBtn = newBool;
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical("Box");
                newBool = EditorGUILayout.ToggleLeft("MMouse", _mMouseBtn, GUILayout.Width(toggleWidth));
                if (newBool != _mMouseBtn)
                {
                    EditorUndoEx.Record(undoRecordObject);
                    _mMouseBtn = newBool;
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();
        }