Esempio n. 1
0
    /// <summary>
    /// Controls behavior of the inspector.
    /// </summary>
    public override void OnInspectorGUI()
    {
        AreaFlagDef targ = (AreaFlagDef)target;

        // Has someone done something naughty?

        if (targ.areas == null || targ.areas == null || targ.areas.Count != targ.flags.Count)
        {
            Debug.LogError("Data null reference or size mismatch. Resetting component.", targ);
            targ.areas = new List <byte>();
            targ.flags = new List <int>();
        }

        List <byte> areas = targ.areas;
        List <int>  flags = targ.flags;

        EditorGUILayout.Separator();

        targ.SetPriority(EditorGUILayout.IntField("Priority", targ.Priority));

        EditorGUILayout.Separator();

        GUILayout.Label("Area / Flags");

        EditorGUILayout.Separator();

        if (areas.Count > 0)
        {
            EditorGUILayout.BeginVertical();

            int delChoice = -1;

            for (int i = 0; i < areas.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();

                // Note: Duplicates are a waste, but technically ok.

                areas[i] = mAreaControl.OnGUI(areas[i]);
                flags[i] = EditorGUILayout.MaskField(flags[i], mFlagNames);

                if (GUILayout.Button("X", GUILayout.Width(30)))
                {
                    delChoice = i;
                }

                EditorGUILayout.EndHorizontal();
            }

            if (delChoice >= 0)
            {
                flags.RemoveAt(delChoice);
                areas.RemoveAt(delChoice);
            }

            EditorGUILayout.EndVertical();
        }

        EditorGUILayout.BeginVertical();
        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();

        mAddSelection = mAreaControl.OnGUI(mAddSelection);

        if (GUILayout.Button("Add"))
        {
            areas.Add(mAddSelection);
            flags.Add(org.critterai.nmbuild.NMBuild.DefaultFlag);
            GUI.changed = true;
        }

        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndVertical();

        EditorGUILayout.Separator();

        GUILayout.Box("Input Build Processor\n\nAdds an NMGen processor that adds flags to"
                      + " polygons based on area assignment. E.g. Add the 'swim' flag to all 'water'"
                      + " polygons."
                      , EditorUtil.HelpStyle
                      , GUILayout.ExpandWidth(true));

        EditorGUILayout.Separator();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        // styles
        var subtitleLabelStyle = new GUIStyle(GUI.skin.label)
        {
            alignment = TextAnchor.LowerCenter, fontSize = 12
        };

        if (!string.IsNullOrEmpty(HelpText))
        {
            GUILayout.Space(10);
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
            EditorGUILayout.HelpBox(HelpText, MessageType.Info);
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
        }

        Origin = (MapOrigin)target;
        if (Origin == null)
        {
            return;
        }

        GUILayout.Space(10);
        EditorGUILayout.LabelField("Map Origin", subtitleLabelStyle, GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        if (GUILayout.Button("Import from Latitude and Longitude"))
        {
            ImportCoordinates w = EditorWindow.GetWindow <ImportCoordinates>(false, nameof(ImportCoordinates), true);
            w.Init(Origin);
            w.Show();
        }

        Origin.OriginEasting  = EditorGUILayout.DoubleField("Origin Easting", Origin.OriginEasting);
        Origin.OriginNorthing = EditorGUILayout.DoubleField("Origin Northing", Origin.OriginNorthing);
        Origin.UTMZoneId      = EditorGUILayout.IntSlider("UTM Zone ID", Origin.UTMZoneId, 1, 60);
        Origin.AltitudeOffset = EditorGUILayout.FloatField("Altitude Offset", Origin.AltitudeOffset);

        int currentlySelected = -1;

        currentlySelected = Array.FindIndex(TimeZones, tz => tz.DisplayName == Origin.TimeZoneString);
        if (currentlySelected == -1)
        {
            var timeZone = Origin.TimeZone;
            currentlySelected = Array.FindIndex(TimeZones, tz => tz.BaseUtcOffset == timeZone.BaseUtcOffset);
        }

        var values = TimeZones.Select(tz => tz.DisplayName.Replace("&", "&&")).ToArray();

        currentlySelected = EditorGUILayout.Popup("TimeZone", currentlySelected, values);
        if (currentlySelected != -1)
        {
            if (!Origin.TimeZone.Equals(TimeZones[currentlySelected]))
            {
                Origin.TimeZoneSerialized = TimeZones[currentlySelected].ToSerializedString();
                Origin.TimeZoneString     = TimeZones[currentlySelected].DisplayName;

                EditorUtility.SetDirty(Origin);
                Repaint();
            }
        }

        if (GUILayout.Button("Add Reference Point"))
        {
            AddReferencePoint(Origin);
        }
        if (GUILayout.Button("Update Map Origin using Reference Points"))
        {
            var points = FindObjectsOfType <MapOriginReferencePoint>();
            if (points.Length < 2)
            {
                Debug.LogError("We need at least 2 reference points");
            }
            else
            {
                var minimizeError = new MapOriginPositionErrorOptimalizer(Origin, points);
                minimizeError.Optimize();
            }
        }
        GUILayout.Space(20);
        EditorGUILayout.LabelField("Map Settings", subtitleLabelStyle, GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        Origin.IgnoreNPCVisible   = EditorGUILayout.Toggle("Ignore NPC Visible", Origin.IgnoreNPCVisible, GUILayout.ExpandWidth(true));
        Origin.IgnoreNPCSpawnable = EditorGUILayout.Toggle("Ignore NPC Spawnable", Origin.IgnoreNPCSpawnable, GUILayout.ExpandWidth(true));
        Origin.IgnoreNPCBounds    = EditorGUILayout.Toggle("Ignore NPC Bounds", Origin.IgnoreNPCBounds, GUILayout.ExpandWidth(true));
        Origin.NPCSizeMask        = EditorGUILayout.MaskField("NPC Categories", Origin.NPCSizeMask, NPCSizes);
        Origin.NPCMaxCount        = EditorGUILayout.IntSlider("NPC Max Count", Origin.NPCMaxCount, 1, 30);
        Origin.NPCSpawnBoundSize  = EditorGUILayout.IntSlider("NPC Spawn Bounds Size", Origin.NPCSpawnBoundSize, 25, 300);

        Origin.IgnorePedBounds   = EditorGUILayout.Toggle("Ignore Ped Bounds", Origin.IgnorePedBounds, GUILayout.ExpandWidth(true));
        Origin.IgnorePedVisible  = EditorGUILayout.Toggle("Ignore Ped Visible", Origin.IgnorePedVisible, GUILayout.ExpandWidth(true));
        Origin.PedMaxCount       = EditorGUILayout.IntSlider("Ped Max Count", Origin.PedMaxCount, 1, 30);
        Origin.PedSpawnBoundSize = EditorGUILayout.IntSlider("Ped Spawn Bounds Size", Origin.PedSpawnBoundSize, 25, 300);

        GUILayout.Space(20);
        EditorGUILayout.LabelField("Map Meta Data", subtitleLabelStyle, GUILayout.ExpandWidth(true));
        EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Map Description");
        Origin.Description = EditorGUILayout.TextArea(Origin.Description);
        EditorGUILayout.EndHorizontal();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(Origin);
        }
    }
        public override void OnInspectorGUI()
        {
            SerializedObject   _target      = new SerializedObject(target);
            SerializedProperty _layers      = _target.FindProperty("layers");
            SerializedProperty _viewRecords = _target.FindProperty("viewRecords");

            EditorGUILayout.HelpBox("All Views and Layers that you wish to use in your game may be registered here in the View Registrar.\n\n  Layers\nView layers will appear in the order that you specify here.\n\n  Views\nWhen setting up a view you must give it a name, specify its layer, and link the view.", MessageType.None);

            if (GUILayout.Button("Regenerate View Statics"))
            {
                GenerateStatics();
            }

            #region Layers

            EditorGUILayout.BeginHorizontal();
            {
                showLayers = EditorGUILayout.Foldout(showLayers, "Layers");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add Layer"))
                {
                    _layers.InsertArrayElementAtIndex(_layers.arraySize);
                    SerializedProperty layerName = _layers.GetArrayElementAtIndex(_layers.arraySize - 1).FindPropertyRelative("layerName");
                    layerName.stringValue = string.Empty;
                    showLayers            = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            if (showLayers)
            {
                bool layerUsesLightingChannel = false;

                for (int i = 0; i < _layers.arraySize; i++)
                {
                    SerializedProperty layer               = _layers.GetArrayElementAtIndex(i);
                    SerializedProperty layerName           = layer.FindPropertyRelative("layerName");
                    SerializedProperty isOverlay           = layer.FindPropertyRelative("isOverlay");
                    SerializedProperty layerShaderChannels = layer.FindPropertyRelative("additionalShaderChannels");
                    EditorGUILayout.BeginHorizontal(GUI.skin.box);
                    {
                        EditorGUILayout.BeginVertical();
                        {
                            GUILayout.Space(14);
                            EditorGUILayout.LabelField(string.Format("Layer {0}", i + 1), GUILayout.MaxWidth(80), GUILayout.MinWidth(60));
                        }
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.BeginVertical(GUILayout.MaxWidth(20));
                        {
                            GUILayout.Space(10);
                            if (GUILayout.Button("▴", GUILayout.Width(20), GUILayout.Height(12)))
                            {
                                _layers.MoveArrayElement(i, i - 1);
                            }
                            GUILayout.Space(-2);
                            if (GUILayout.Button("▾", GUILayout.Width(20), GUILayout.Height(12)))
                            {
                                _layers.MoveArrayElement(i, i + 1);
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            GUILayout.Space(7);
                            EditorGUILayout.BeginHorizontal();
                            {
                                layerName.stringValue = EditorGUILayout.TextField(layerName.stringValue);
                                EditorGUILayout.LabelField("Overlay", GUILayout.Width(65));
                                GUILayout.Space(-15);
                                isOverlay.boolValue = EditorGUILayout.Toggle(isOverlay.boolValue);
                            }
                            EditorGUILayout.EndHorizontal();

                            layerShaderChannels.intValue = EditorGUILayout.MaskField("Additional Shader Channels", layerShaderChannels.intValue, shaderChannelOptions, new GUILayoutOption[0]);

                            if (((layerShaderChannels.intValue & 8) | (layerShaderChannels.intValue & 16)) != 0)
                            {
                                layerUsesLightingChannel = true;
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUILayout.BeginVertical();
                        {
                            GUILayout.Space(3);
                            if (GUILayout.Button("-", GUILayout.Width(24), GUILayout.Height(36)))
                            {
                                _layers.DeleteArrayElementAtIndex(i);
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    EditorGUILayout.EndHorizontal();
                }

                if (layerUsesLightingChannel)
                {
                    EditorGUILayout.HelpBox("Shader channels Normal and Tangent are most often used with lighting, which an Overlay canvas does not support. Its likely these channels are not needed.", MessageType.Warning);
                }
            }
            #endregion

            #region View Records

            EditorGUILayout.BeginHorizontal();
            {
                showViews = EditorGUILayout.Foldout(showViews, "Views");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add View"))
                {
                    _viewRecords.InsertArrayElementAtIndex(_viewRecords.arraySize);
                    SerializedProperty view       = _viewRecords.GetArrayElementAtIndex(_viewRecords.arraySize - 1);
                    SerializedProperty viewName   = view.FindPropertyRelative("viewID");
                    SerializedProperty viewPrefab = view.FindPropertyRelative("view");
                    SerializedProperty isDialog   = view.FindPropertyRelative("isDialog");
                    SerializedProperty persistent = view.FindPropertyRelative("persistent");
                    SerializedProperty loadType   = view.FindPropertyRelative("loadType");
                    viewName.stringValue   = string.Empty;
                    viewPrefab.stringValue = string.Empty;
                    isDialog.boolValue     = false;
                    persistent.boolValue   = false;
                    loadType.stringValue   = fullyQualifiedLoadTypes[0];

                    showViews = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            if (showViews)
            {
                EditorGUI.indentLevel++;

                //Copy the layer names for use in the layer field of views
                List <string> layerNames = new List <string>();
                for (int i = 0; i < _layers.arraySize; i++)
                {
                    layerNames.Add(_layers.GetArrayElementAtIndex(i).FindPropertyRelative("layerName").stringValue);
                }

                // Update the record of which sets of view records are expanded
                if (expandedViewInfo.Count <= _viewRecords.arraySize)
                {
                    for (int i = expandedViewInfo.Count; i < _viewRecords.arraySize; i++)
                    {
                        expandedViewInfo.Add(false);
                    }
                }

                for (int i = 0; i < _viewRecords.arraySize; i++)
                {
                    SerializedProperty view           = _viewRecords.GetArrayElementAtIndex(i);
                    SerializedProperty viewName       = view.FindPropertyRelative("viewID");
                    SerializedProperty layerID        = view.FindPropertyRelative("layerID");
                    SerializedProperty viewPrefabPath = view.FindPropertyRelative("view");
                    SerializedProperty isDialog       = view.FindPropertyRelative("isDialog");
                    SerializedProperty persistent     = view.FindPropertyRelative("persistent");
                    SerializedProperty loadType       = view.FindPropertyRelative("loadType");

                    // Set View ID if View is linked but ID is empty
                    if (string.IsNullOrEmpty(viewName.stringValue) && string.IsNullOrEmpty(viewPrefabPath.stringValue) == false)
                    {
                        viewName.stringValue = Path.GetFileNameWithoutExtension(viewPrefabPath.stringValue);
                    }

                    // Correct the layer value if needed
                    if (prevLayers != null)
                    {
                        if (layerID.intValue >= 0 && layerID.intValue < prevLayers.Count)
                        {
                            string layer    = prevLayers[layerID.intValue];
                            int    newIndex = layerNames.FindIndex(name => name == layer);

                            if (layerID.intValue != newIndex)
                            {
                                layerID.intValue = newIndex;
                            }
                        }
                    }

                    expandedViewInfo[i] = EditorGUILayout.Foldout(expandedViewInfo[i], viewName.stringValue);
                    if (expandedViewInfo[i])
                    {
                        EditorGUI.indentLevel++;

                        EditorGUILayout.BeginVertical(GUI.skin.box);
                        {
                            EditorGUILayout.PropertyField(viewName);
                            EditorGUILayout.PropertyField(viewPrefabPath);
                            EditorGUILayout.PropertyField(persistent);

                            int loadTypeIndex = Mathf.Clamp(fullyQualifiedLoadTypes.IndexOf(loadType.stringValue), 0, int.MaxValue);
                            loadTypeIndex        = EditorGUILayout.Popup("Load Type", loadTypeIndex, shortenedLoadTypes.ToArray());
                            loadType.stringValue = fullyQualifiedLoadTypes[loadTypeIndex];

                            EditorGUILayout.PropertyField(isDialog);

                            if (!isDialog.boolValue)
                            {
                                EditorGUILayout.BeginHorizontal();
                                {
                                    layerID.intValue = EditorGUILayout.Popup("Layer", layerID.intValue, layerNames.ToArray());
                                }
                                EditorGUILayout.EndHorizontal();
                            }

                            if (GUILayout.Button("Remove"))
                            {
                                _viewRecords.DeleteArrayElementAtIndex(i);
                                expandedViewInfo.RemoveAt(i);
                            }
                        }
                        EditorGUILayout.EndVertical();

                        EditorGUI.indentLevel--;
                    }
                }

                prevLayers = new List <string>(layerNames);

                EditorGUI.indentLevel--;
            }
            #endregion

            _target.ApplyModifiedProperties();
        }
Esempio n. 4
0
 public static LayerMask LayerMaskField(string label, int selectedMask)
 {
     return(EditorGUILayout.MaskField(label, selectedMask, LayerUtil.GetAllLayerNames()));
 }
Esempio n. 5
0
        /// <summary>
        /// Returns the actions to draw before the State list is drawn.
        /// </summary>
        /// <returns>The actions to draw before the State list is drawn.</returns>
        protected override Action GetDrawCallback()
        {
            var baseCallback = base.GetDrawCallback();

            baseCallback += () =>
            {
                if (Foldout("Firing"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(PropertyFromName("m_ConsumableItemType"));
                    var fireMode = PropertyFromName("m_FireMode");
                    EditorGUILayout.PropertyField(fireMode);
                    if (fireMode.enumValueIndex == (int)ShootableWeapon.FireMode.Burst)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(PropertyFromName("m_BurstCount"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_BurstDelay"));
                        EditorGUI.indentLevel--;
                    }
                    var fireType = PropertyFromName("m_FireType");
                    EditorGUILayout.PropertyField(fireType);
                    if (fireType.enumValueIndex != (int)ShootableWeapon.FireType.Instant)
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(PropertyFromName("m_MinChargeLength"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_FullChargeLength"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_ChargeItemSubstateParameterValue"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_MinChargeStrength"));
                        if (Foldout("Charge Audio"))
                        {
                            EditorGUI.indentLevel++;
                            m_ReorderableChargeAudioClipsList = AudioClipSetInspector.DrawAudioClipSet(m_ShootableWeapon.ChargeAudioClipSet, PropertyFromName("m_ChargeAudioClipSet"), m_ReorderableChargeAudioClipsList, OnChargeAudioClipDraw, OnChargeAudioClipListAdd, OnChargeAudioClipListRemove);
                            EditorGUI.indentLevel--;
                        }
                        EditorGUI.indentLevel--;
                    }
                    EditorGUILayout.PropertyField(PropertyFromName("m_FireCount"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_Spread"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_FireInLookSourceDirection"));
                    EditorGUILayout.HelpBox("If a projectile prefab is specified then this projectile will be fired from the weapon. If no projectile is specified then a hitscan will be used.", MessageType.Info);
                    var projectile = PropertyFromName("m_Projectile");
                    EditorGUILayout.PropertyField(projectile);
                    if (projectile.objectReferenceValue == null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName("m_HitscanFireRange"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_MaxHitscanCollisionCount"));
                        InspectorUtility.UnityEventPropertyField(PropertyFromName("m_OnHitscanImpactEvent"));
                    }
                    else
                    {
                        if ((projectile.objectReferenceValue as GameObject).GetComponent <UltimateCharacterController.Objects.Projectile>() == null)
                        {
                            EditorGUILayout.HelpBox("The projectile must have the Projectile component attached to it.", MessageType.Error);
                        }
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(PropertyFromName("m_ProjectileFireVelocityMagnitude"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_ProjectileVisibility"));
                        var shootableWeapon = target as ShootableWeapon;
                        shootableWeapon.ProjectileStartLayer = EditorGUILayout.LayerField(new GUIContent("Projectile Start Layer",
                                                                                                         "The layer that the projectile should occupy when initially spawned."), shootableWeapon.ProjectileStartLayer);
                        shootableWeapon.ProjectileFiredLayer = EditorGUILayout.LayerField(new GUIContent("Projectile Fired Layer",
                                                                                                         "The layer that the projectile object should change to after being fired."), shootableWeapon.ProjectileFiredLayer);
                        EditorGUILayout.PropertyField(PropertyFromName("m_LayerChangeDelay"));
                        EditorGUILayout.PropertyField(PropertyFromName("m_ProjectileEnableDelayAfterOtherUse"));
                        EditorGUI.indentLevel--;
                    }
                    EditorGUILayout.PropertyField(PropertyFromName("m_DryFireItemSubstateParameterValue"));
                    if (InspectorUtility.Foldout(target, "Dry Fire Audio"))
                    {
                        EditorGUI.indentLevel++;
                        m_ReorderableDryFireAudioClipsList = AudioClipSetInspector.DrawAudioClipSet(m_ShootableWeapon.DryFireAudioClipSet, PropertyFromName("m_DryFireAudioClipSet"), m_ReorderableDryFireAudioClipsList, OnDryFireAudioClipDraw, OnDryFireAudioClipListAdd, OnDryFireAudioClipListRemove);
                        EditorGUI.indentLevel--;
                    }
                    EditorGUI.indentLevel--;
                }

                if (Foldout("Impact"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(PropertyFromName("m_ImpactLayers"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_DamageAmount"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ImpactForce"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ImpactForceFrames"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ImpactStateName"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ImpactStateDisableTimer"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_SurfaceImpact"));
                    EditorGUI.indentLevel--;
                }

                if (Foldout("Reload"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(PropertyFromName("m_ClipSize"));
                    var autoReloadProperty = PropertyFromName("m_AutoReload");
                    var autoReloadString   = Enum.GetNames(typeof(UltimateCharacterController.Character.Abilities.Items.Reload.AutoReloadType));
                    autoReloadProperty.intValue = EditorGUILayout.MaskField(new GUIContent("Auto Reload", autoReloadProperty.tooltip), (int)autoReloadProperty.intValue, autoReloadString);
                    EditorGUILayout.PropertyField(PropertyFromName("m_ReloadType"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ReloadCanCameraZoom"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ReloadCrosshairsSpread"));
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Event", PropertyFromName("m_ReloadEvent"));
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Complete Event", PropertyFromName("m_ReloadCompleteEvent"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_ReloadDetachAttachClip"));
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Detach Clip Event", PropertyFromName("m_ReloadDetachClipEvent"));
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Show Projectile Event", PropertyFromName("m_ReloadShowProjectileEvent"));
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Attach Projectile Event", PropertyFromName("m_ReloadAttachProjectileEvent"));
                    var reloadClipProperty = PropertyFromName("m_ReloadDropClip");
                    EditorGUILayout.PropertyField(reloadClipProperty);
                    if (reloadClipProperty.objectReferenceValue != null)
                    {
                        EditorGUI.indentLevel++;
                        var shootableWeapon = target as ShootableWeapon;
                        shootableWeapon.ReloadClipTargetLayer = EditorGUILayout.LayerField(new GUIContent("Reload Clip Target Layer",
                                                                                                          "The layer that the clip object should change to after being reloaded."), shootableWeapon.ReloadClipTargetLayer);
                        EditorGUILayout.PropertyField(PropertyFromName("m_ReloadClipLayerChangeDelay"));
                        InspectorUtility.DrawAnimationEventTrigger(target, "Reload Drop Clip Event", PropertyFromName("m_ReloadDropClipEvent"));
                        EditorGUI.indentLevel--;
                    }
                    InspectorUtility.DrawAnimationEventTrigger(target, "Reload Attach Clip Event", PropertyFromName("m_ReloadAttachClipEvent"));
                    if (Foldout("Animator Audio"))
                    {
                        EditorGUI.indentLevel++;
                        AnimatorAudioStateSetInspector.DrawAnimatorAudioStateSet(m_ShootableWeapon, m_ShootableWeapon.ReloadAnimatorAudioStateSet, "m_ReloadAnimatorAudioStateSet", true,
                                                                                 ref m_ReorderableReloadAnimatorAudioStateSetList, OnAnimatorAudioStateListDraw, OnAnimatorAudioStateListSelect,
                                                                                 OnAnimatorAudioStateListAdd, OnAnimatorAudioStateListRemove, SelectedReloadAnimatorAudioStateSetIndexKey,
                                                                                 ref m_ReorderableReloadAnimatorAudioStateSetAudioList, OnReloadAudioListElementDraw, OnReloadAudioListAdd, OnReloadAudioListRemove,
                                                                                 ref m_ReorderableReloadAnimatorAudioStateSetStateList,
                                                                                 OnAnimatorAudioStateSetStateListDraw, OnAnimatorAudioStateSetStateListAdd, OnAnimatorAudioStateSetStateListReorder, OnAnimatorAudioStateSetStateListRemove,
                                                                                 GetSelectedAnimatorAudioStateSetStateIndexKey(EditorPrefs.GetInt(SelectedReloadAnimatorAudioStateSetIndexKey)));
                        EditorGUI.indentLevel--;
                    }
                    if (InspectorUtility.Foldout(target, "Reload Complete Audio"))
                    {
                        EditorGUI.indentLevel++;
                        m_ReorderableReloadCompleteAudioClipsList = AudioClipSetInspector.DrawAudioClipSet(m_ShootableWeapon.ReloadCompleteAudioClipSet, PropertyFromName("m_ReloadCompleteAudioClipSet"), m_ReorderableReloadCompleteAudioClipsList, OnReloadCompleteAudioClipDraw, OnReloadCompleteAudioClipListAdd, OnReloadCompleteAudioClipListRemove);
                        EditorGUI.indentLevel--;
                    }
                }
                if (Foldout("Recoil"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(PropertyFromName("m_PositionRecoil"), true);
                    EditorGUILayout.PropertyField(PropertyFromName("m_RotationRecoil"), true);
                    EditorGUILayout.PropertyField(PropertyFromName("m_PositionCameraRecoil"), true);
                    EditorGUILayout.PropertyField(PropertyFromName("m_RotationCameraRecoil"), true);
                    EditorGUILayout.PropertyField(PropertyFromName("m_CameraRecoilAccumulation"));
                    EditorGUILayout.PropertyField(PropertyFromName("m_LocalizeRecoilForce"));
                    EditorGUI.indentLevel--;
                }
                if (Foldout("Muzzle Flash"))
                {
                    EditorGUI.indentLevel++;
                    var muzzleFlash = PropertyFromName("m_MuzzleFlash");
                    EditorGUILayout.PropertyField(muzzleFlash);
                    if (muzzleFlash.objectReferenceValue != null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName("m_PoolMuzzleFlash"));
                    }
                    EditorGUI.indentLevel--;
                }
                if (Foldout("Shell"))
                {
                    EditorGUI.indentLevel++;
                    var shell = PropertyFromName("m_Shell");
                    EditorGUILayout.PropertyField(shell);
                    if (shell.objectReferenceValue != null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName("m_ShellVelocity"), true);
                        EditorGUILayout.PropertyField(PropertyFromName("m_ShellTorque"), true);
                        EditorGUILayout.PropertyField(PropertyFromName("m_ShellEjectDelay"));
                    }
                    EditorGUI.indentLevel--;
                }
                if (Foldout("Smoke"))
                {
                    EditorGUI.indentLevel++;
                    var smoke = PropertyFromName("m_Smoke");
                    EditorGUILayout.PropertyField(smoke);
                    if (smoke.objectReferenceValue != null)
                    {
                        EditorGUILayout.PropertyField(PropertyFromName("m_SmokeSpawnDelay"));
                    }
                    EditorGUI.indentLevel--;
                }
                if (Foldout("Tracer"))
                {
                    EditorGUI.indentLevel++;
                    if (PropertyFromName("m_Projectile").objectReferenceValue == null)
                    {
                        var tracer = PropertyFromName("m_Tracer");
                        EditorGUILayout.PropertyField(tracer);
                        if (tracer.objectReferenceValue != null)
                        {
                            EditorGUILayout.PropertyField(PropertyFromName("m_TracerDefaultLength"));
                            EditorGUILayout.PropertyField(PropertyFromName("m_TracerSpawnDelay"));
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("A tracer can only be applied to hitscan weapons.", MessageType.Info);
                    }
                    EditorGUI.indentLevel--;
                }
                if (Foldout("Attachments"))
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.PropertyField(PropertyFromName("m_DisableScopeCameraOnNoAim"));
                    EditorGUI.indentLevel--;
                }
            };

            return(baseCallback);
        }
Esempio n. 6
0
        public void OnGUI()
        {
            GUILayout.Space(10);
            EditorGUILayout.BeginVertical();

            EditorGUILayout.BeginHorizontal();

            var layoutOptions = new[] { GUILayout.Width(32), GUILayout.Height(24) };

            if (GUILayout.Button(m_GUIRunAllTestsIcon, Styles.buttonLeft, layoutOptions))
            {
                RunTests();
                GUIUtility.ExitGUI();
            }
            if (GUILayout.Button(m_GUIRunSelectedTestsIcon, Styles.buttonMid, layoutOptions))
            {
                m_TestLines.RunSelectedTests();
            }
            if (GUILayout.Button(m_GUIRerunFailedTestsIcon, Styles.buttonRight, layoutOptions))
            {
                m_TestLines.RunTests(m_ResultList.Where(result => result.IsFailure || result.IsError).Select(l => l.FullName).ToArray());
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button(m_Settings.optionsFoldout ? m_GUIHideButton : m_GUIOptionButton, GUILayout.Height(24), GUILayout.Width(80)))
            {
                m_Settings.optionsFoldout = !m_Settings.optionsFoldout;
            }
            EditorGUILayout.EndHorizontal();

            if (m_Settings.optionsFoldout)
            {
                DrawOptions();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Filter:", GUILayout.Width(35));
            m_Settings.testFilter = EditorGUILayout.TextField(m_Settings.testFilter, EditorStyles.textField);

            if (m_AvailableCategories != null && m_AvailableCategories.Length > 0)
            {
                m_Settings.categoriesMask = EditorGUILayout.MaskField(m_Settings.categoriesMask, m_AvailableCategories, GUILayout.MaxWidth(90));
            }

            if (GUILayout.Button(m_Settings.filtersFoldout ? "Hide" : "Advanced", GUILayout.Width(80), GUILayout.Height(15)))
            {
                m_Settings.filtersFoldout = !m_Settings.filtersFoldout;
            }
            EditorGUILayout.EndHorizontal();

            if (m_Settings.filtersFoldout)
            {
                DrawFilters();
            }

            if (m_Settings.horizontalSplit)
            {
                EditorGUILayout.BeginVertical();
            }
            else
            {
                EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
            }

            RenderTestList();
            RenderTestInfo();

            if (m_Settings.horizontalSplit)
            {
                EditorGUILayout.EndVertical();
            }
            else
            {
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndVertical();
        }
Esempio n. 7
0
    private void createRigidBodyForceMoverBehaviorUI(MoverBehavior moverBehavior)
    {
        RigidBodyForceMoverBehavior rigidBodyForceMover = moverBehavior as RigidBodyForceMoverBehavior;

        if (rigidBodyForceMover != null)
        {
            EditorGUI.BeginChangeCheck();
            Vector3 forceMagnitude = EditorGUILayout.Vector3Field("Force Magnitude", rigidBodyForceMover.getForceMagnitude());
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(rigidBodyForceMover, "Force Magnitude");
                EditorUtility.SetDirty(rigidBodyForceMover);
                rigidBodyForceMover.setForceMagnitude(forceMagnitude);
            }

            EditorGUI.BeginChangeCheck();
            float duration = EditorGUILayout.DelayedFloatField("Duration", rigidBodyForceMover.getDuration());
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(rigidBodyForceMover, "Duration");
                EditorUtility.SetDirty(rigidBodyForceMover);
                rigidBodyForceMover.setDuration(duration);
            }

            EditorGUILayout.LabelField("RigidBody");
            EditorGUI.BeginChangeCheck();
            Rigidbody rigidBody = (Rigidbody)EditorGUILayout.ObjectField(rigidBodyForceMover.getRigidBody(), typeof(Rigidbody), true);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(rigidBodyForceMover, "RigidBody");
                EditorUtility.SetDirty(rigidBodyForceMover);
                rigidBodyForceMover.setRigidBody(rigidBody);
            }

            EditorGUI.BeginChangeCheck();
            bool isAdditiveForce = EditorGUILayout.Toggle("Is Additive Force", rigidBodyForceMover.getIsAdditiveForce());
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(rigidBodyForceMover, "Is Additive Force");
                EditorUtility.SetDirty(rigidBodyForceMover);
                rigidBodyForceMover.setIsAdditiveForce(isAdditiveForce);
            }

            EditorGUILayout.LabelField("Surface Collision Checker Transform");
            EditorGUI.BeginChangeCheck();
            Transform surfaceCheckTransform = (Transform)EditorGUILayout.ObjectField(rigidBodyForceMover.getSurfaceCheckSourceTransform(), typeof(Transform), true);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(rigidBodyForceMover, "Surface Collision Checker Transform");
                EditorUtility.SetDirty(rigidBodyForceMover);
                rigidBodyForceMover.setSurfaceCheckSourceTransform(surfaceCheckTransform);
            }

            if (surfaceCheckTransform)
            {
                EditorGUI.BeginChangeCheck();
                float surfaceCheckRadius = EditorGUILayout.DelayedFloatField("Checker Radius", rigidBodyForceMover.getSurfaceCheckRadius());
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(rigidBodyForceMover, "Checker Radius");
                    EditorUtility.SetDirty(rigidBodyForceMover);
                    rigidBodyForceMover.setSurfaceCheckRadius(surfaceCheckRadius);
                }

                LayerMask surfaceLayerMask = InspectorHelper.convert32BitLayerMaskToTrimmedMask(rigidBodyForceMover.getSurfaceLayerMask());
                EditorGUI.BeginChangeCheck();
                surfaceLayerMask = EditorGUILayout.MaskField("Surface Layer Mask", surfaceLayerMask, UnityEditorInternal.InternalEditorUtility.layers);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(rigidBodyForceMover, "Surface Layer Mask");
                    EditorUtility.SetDirty(rigidBodyForceMover);

                    rigidBodyForceMover.setSurfaceLayerMask(InspectorHelper.convertTrimmedLayerMaskTo32BitMask(surfaceLayerMask));
                }
            }
        }
    }
Esempio n. 8
0
    void OnGUI()
    {
        GUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
        GUI.SetNextControlName("OrderScoresButton");
        if (GUILayout.Button(actualOrder, GUI.skin.FindStyle("ToolBarButton")))
        {
            GUI.FocusControl("OrderScoresButton");
            orderScore();
        }
        if (GUILayout.Button("Add Score", GUI.skin.FindStyle("ToolBarButton")))
        {
            scorerScript.addScore();
        }
        if (GUILayout.Button("Reset PlayerPrefs", GUI.skin.FindStyle("ToolBarButton")))
        {
            PlayerPrefs.DeleteAll();
            foreach (var score in scorerScript.scoresScriptableObject.scores)
            {
                if (score.croissant)
                {
                    score.value = 0;
                }
                else
                {
                    score.value = int.MaxValue;
                }
            }
        }
        displayTags = GUILayout.Toggle(displayTags, "Display Tags", "ToolBarButton");
        GUILayout.FlexibleSpace();
        searchString = GUILayout.TextField(searchString, GUI.skin.FindStyle("ToolbarSeachTextField"), GUILayout.Width(140));
        if (GUILayout.Button("", GUI.skin.FindStyle("ToolbarSeachCancelButton")))
        {
            // Remove focus if cleared
            searchString = "";
            GUI.FocusControl(null);
        }
        GUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUI.BeginChangeCheck();
        circle = AssetDatabase.LoadAssetAtPath("Assets/ScoreLib/Sprites/Voyant.png", typeof(Texture)) as Texture;

        scorerScript   = Scorer.instance;
        achieverScript = Achiever.instance;

        if (scorerScript == null || achieverScript == null)
        {
            return;
        }

        EditorGUILayout.EndHorizontal();
        EditorStyles.textField.wordWrap = true;

        EditorGUILayout.BeginVertical();
        scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
        try
        {
            int i = 0;
            foreach (var score in scorerScript.scoresScriptableObject.scores.Where(a => a.tags.Contains(searchString) || a.name.Contains(searchString)).OrderBy(a => a.position))
            {
                if (score.position == -1)
                {
                    score.position = scorerScript.scoresScriptableObject.scores.IndexOf(score);
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Id " + scorerScript.scoresScriptableObject.scores.IndexOf(score), EditorStyles.boldLabel, GUILayout.Width(60));
                string resultCheckOperationnel;
                checkOperationel(score, out resultCheckOperationnel);
                Rect rectTexture = new Rect(new Vector2(54, i * 20 + 4), new Vector2(15, 15));
                GUI.DrawTexture(rectTexture, circle, ScaleMode.ScaleToFit, true);
                GUI.color = Color.white;
                EditorGUIUtility.labelWidth = 40;
                score.scoreType             = (Scorer.ScoreType)EditorGUILayout.EnumPopup("Type", score.scoreType, GUILayout.Width(155));
                AchieverWindow.textureTooltip(rectTexture, resultCheckOperationnel);
                EditorGUIUtility.labelWidth = 40;
                score.name = EditorGUILayout.TextField("Name", score.name);
                EditorGUIUtility.labelWidth = 70;
                EditorGUILayout.PrefixLabel("Description");
                score.description           = EditorGUILayout.TextArea(score.description, GUILayout.Width(150));
                EditorGUIUtility.labelWidth = 43;
                score.value = EditorGUILayout.FloatField("Value", score.value);
                if (displayTags)
                {
                    EditorGUIUtility.labelWidth = 35;
                    EditorGUILayout.PrefixLabel("Tags");
                    score.tags = EditorGUILayout.TextArea(score.tags, GUILayout.Width(100));
                }
                score.croissant = EditorGUILayout.Toggle("Croissant", score.croissant, GUILayout.Width(75));
                int achievementFlags = getAchievementFlags(score);
                achievementFlags = EditorGUILayout.MaskField("Achievements", achievementFlags, adapt(achieverScript.getNames()));
                updateListAchievement(score, achievementFlags);
                if (score.scoreType == Scorer.ScoreType.GameScore)
                {
                    int[]    namesOriginIndex;
                    string[] names = adapt(scorerScript.getNames(out namesOriginIndex));
                    int      relatedScoresFlags = getRelatedScoreFlags(score, namesOriginIndex);
                    relatedScoresFlags = EditorGUILayout.MaskField("Related Score", relatedScoresFlags, names);
                    updateListRelatedScore(score, relatedScoresFlags, namesOriginIndex);
                }

                if (GUILayout.Button("Remove Score"))
                {
                    removeScore(score);
                }
                EditorGUILayout.EndHorizontal();
                i++;
            }
        }
        catch (System.NullReferenceException) { }
        catch (System.InvalidOperationException) { }
        EditorGUILayout.EndScrollView();
        if (EditorGUI.EndChangeCheck())
        {
            EditorUtility.SetDirty(scorerScript.scoresScriptableObject);
        }
        EditorGUILayout.EndVertical();
    }
Esempio n. 9
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal("Toolbar", GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Load", "ToolbarButton"))
            {
                string path = EditorUtility.OpenFilePanel("Select Palette", "", "asset");
                path = path.Replace(Application.dataPath, "Assets");
                if (path.Length != 0)
                {
                    activePalette = (PaintPalette)AssetDatabase.LoadAssetAtPath(path, typeof(PaintPalette));
                    LoadPalette(activePalette);
                    if (!palettes.Contains(activePalette))
                    {
                        palettes.Add(activePalette);
                    }
                    Debug.Log("<color=cyan>[Prefab Painter] </color>Palette loaded.");
                }
            }
            if (activePalette != null)
            {
                GUILayout.Label(new GUIContent("Active: " + activePalette.name), "ToolbarButton");
            }
            else
            {
                GUILayout.Label(new GUIContent("Active: none"), "ToolbarButton");
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(new GUIContent("", saveIcon, "Save active prefabs as palette."), "ToolbarButton"))
            {
                if (activePalette != null && palettes.Contains(activePalette))
                {
                    if (displayOverrideWarning)
                    {
                        switch (EditorUtility.DisplayDialogComplex("Override palette", "Saving the current palette will override the currently active palette which is '" + activePalette.name + "'.", "Okay", "Cancel", "Okay and do not show again"))
                        {
                        case 0:
                            OverridePalette(activePalette);
                            break;

                        case 1:
                            break;

                        case 2:
                            OverridePalette(activePalette);
                            displayOverrideWarning = false;
                            break;

                        default:
                            break;
                        }
                    }
                    else
                    {
                        OverridePalette(activePalette);
                    }
                }
                else
                {
                    CreateNewPalette();
                }
            }
            if (GUILayout.Button(new GUIContent("", deleteIcon, "Remove currently loaded palette."), "ToolbarButton"))
            {
                Debug.Log("Remove Palette");
            }
            if (GUILayout.Button(new GUIContent("Palettes", "Load in a palette."), "ToolbarPopup"))
            {
                GenericMenu menu = new GenericMenu();
                if (palettes.Count > 0)
                {
                    for (int i = 0; i < palettes.Count; i++)
                    {
                        if (palettes[i] != null)
                        {
                            AddMenuItemForPalette(menu, palettes[i].name, palettes[i]);
                        }
                    }
                }
                menu.AddItem(new GUIContent("New Palette"), creatingNewPalette, OnNewPaletteSelected);
                menu.AddItem(new GUIContent("Clear List"), false, OnClearList);
                menu.ShowAsContext();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false);

            float tempSize    = brushSize;
            int   tempDensity = brushDensity;

            BrushSettingsFold = BeginFold("Brush Settings", BrushSettingsFold);
            if (BrushSettingsFold)
            {
                paintMask = EditorGUILayout.MaskField(
                    new GUIContent("Paint Layer", "On which layer the tool will paint."), paintMask,
                    layerNames.ToArray());
                brushSize      = EditorGUILayout.FloatField("Brush Size", brushSize);
                brushDensity   = EditorGUILayout.IntField("Brush Density", brushDensity);
                paintGroupName = EditorGUILayout.TextField("Paint Group Name", paintGroupName);
            }
            EndFold();

            listSize = Mathf.Max(0, listSize);

            DisplayPrefabs(paintObjects);
            if (Event.current.type == EventType.Layout && selectedPrefab != null)
            {
                displayPrefabSettings = true;
            }

            if (displayPrefabSettings)
            {
                selectedPrefab.displaySettings();
            }

            EditorGUILayout.Space();
            GUILayout.Space(75f + prefabListHeight);
            CheckForChanges(tempSize, tempDensity);
            EditorGUILayout.EndScrollView();
        }
Esempio n. 10
0
    public override void OnChildInspectorGUI()
    {
        serializedObject.Update();

        m_UnityEventHandlerInspector.OnGUI();

        GUILayout.Space(2);

        GUILayout.BeginVertical("Box");
        {
            EditorGUILayout.PropertyField(enableActionOnEvent, new GUIContent("Action On Event: "));

            if (enableActionOnEvent.boolValue)
            {
                EditorGUILayout.PropertyField(actionOnEventType, new GUIContent("Action On EventType: "));
                EditorGUILayout.PropertyField(curveInterpolation, new GUIContent("Curve Interpolation: "));
                EditorGUILayout.Slider(transitionDuration, 0.0f, 60.0f, new GUIContent("Fade Time (secs): "));
            }
        }
        GUILayout.EndVertical();

        GUILayout.Space(2);

        GUILayout.BeginVertical("Box");
        {
            bool useCallback = m_akEvent.m_callbackData != null;
#if UNITY_5_3_OR_NEWER
            EditorGUI.BeginChangeCheck();
#endif
            useCallback = EditorGUILayout.Toggle("Use Callback: ", useCallback);
#if UNITY_5_3_OR_NEWER
            if (EditorGUI.EndChangeCheck())
#endif
            {
#if UNITY_5_3_OR_NEWER
                Undo.RecordObject(target, "Use Callback Change");
#endif

                if (m_akEvent.m_callbackData == null && useCallback)
                {
                    m_akEvent.m_callbackData = ScriptableObject.CreateInstance <AkEventCallbackData>();

                    m_akEvent.m_callbackData.callbackFunc.Add(string.Empty);
                    m_akEvent.m_callbackData.callbackFlags.Add(0);
                    m_akEvent.m_callbackData.callbackGameObj.Add(null);
                }
                else if (!useCallback)
                {
                    m_akEvent.m_callbackData = null;
                }
            }

            if (m_akEvent.m_callbackData != null)
            {
                GUILayout.Space(3);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label("Game Object");
                    GUILayout.Label("Callback Function");
                    GUILayout.Label("Callback Flags");
                }
                GUILayout.EndHorizontal();

                m_akEvent.m_callbackData.uFlags = 0;

                for (int i = 0; i < m_akEvent.m_callbackData.callbackFunc.Count; i++)
                {
                    GUILayout.BeginHorizontal();
                    {
#if UNITY_5_3_OR_NEWER
                        EditorGUI.BeginChangeCheck();
#endif
                        GameObject gameObj = (GameObject)EditorGUILayout.ObjectField(m_akEvent.m_callbackData.callbackGameObj[i], typeof(GameObject), true);
                        string     func    = EditorGUILayout.TextField(m_akEvent.m_callbackData.callbackFunc[i]);

                        //Since some callback flags are unsupported, some bits are not used.
                        //But when using EditorGUILayout.MaskField, clicking the third flag will set the third bit to one even if the third flag in the AkCallbackType enum is unsupported.
                        //This is a problem because cliking the third supported flag would internally select the third flag in the AkCallbackType enum which is unsupported.
                        //To solve this problem we use a mask for display and another one for the actual callback
                        int displayMask = GetDisplayMask(m_akEvent.m_callbackData.callbackFlags[i]);
                        displayMask = EditorGUILayout.MaskField(displayMask, m_supportedCallbackFlags);
                        int flags = GetWwiseCallbackMask(displayMask);

#if UNITY_5_3_OR_NEWER
                        if (EditorGUI.EndChangeCheck())
#endif
                        {
#if UNITY_5_3_OR_NEWER
                            Undo.RecordObject(m_akEvent.m_callbackData, "Modified Callback");
#endif
                            m_akEvent.m_callbackData.callbackGameObj[i] = gameObj;
                            m_akEvent.m_callbackData.callbackFunc[i]    = func;
                            m_akEvent.m_callbackData.callbackFlags[i]   = flags;
                        }

                        if (GUILayout.Button("X"))
                        {
#if UNITY_5_3_OR_NEWER
                            Undo.RecordObject(m_akEvent.m_callbackData, "Remove Callback");
#endif

                            if (m_akEvent.m_callbackData.callbackFunc.Count == 1)
                            {
                                m_akEvent.m_callbackData.callbackFunc[0]    = string.Empty;
                                m_akEvent.m_callbackData.callbackFlags[0]   = 0;
                                m_akEvent.m_callbackData.callbackGameObj[0] = null;

                                //Changes to the textfield string will not be picked up by the text editor if it is selected.
                                //So we remove focus from the textfield to make sure it will get updated
                                GUIUtility.keyboardControl = 0;
                                GUIUtility.hotControl      = 0;
                            }
                            else
                            {
                                m_akEvent.m_callbackData.callbackFunc.RemoveAt(i);
                                m_akEvent.m_callbackData.callbackFlags.RemoveAt(i);
                                m_akEvent.m_callbackData.callbackGameObj.RemoveAt(i);

                                GUIUtility.keyboardControl = 0;
                                GUIUtility.hotControl      = 0;

                                i--;
                                continue;
                            }
                        }

                        m_akEvent.m_callbackData.uFlags |= m_akEvent.m_callbackData.callbackFlags[i];
                    }
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(3);

                if (GUILayout.Button("Add"))
                {
#if UNITY_5_3_OR_NEWER
                    Undo.RecordObject(m_akEvent.m_callbackData, "Add Callback");
#endif

                    m_akEvent.m_callbackData.callbackFunc.Add(string.Empty);
                    m_akEvent.m_callbackData.callbackFlags.Add(0);
                    m_akEvent.m_callbackData.callbackGameObj.Add(null);
                }

                GUILayout.Space(3);
            }
        }
        GUILayout.EndVertical();

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 11
0
        public override bool OnGUI()
        {
            GUILayout.Label("Setup:", EditorStyles.boldLabel);
            EditField("position");

            GUILayout.Space(10);

            EditField("shape");

            switch (action.shape)
            {
            case Overlap2d.ShapeType.Circle:
                EditField("radius");
                EditField("offset");
                break;

            case Overlap2d.ShapeType.Box:
                EditField("boxSize");
                EditField("offset");
                break;

            case Overlap2d.ShapeType.Area:
                EditField("pointA");
                EditField("pointB");
                break;

            case Overlap2d.ShapeType.Capsule:
                EditField("direction");
                EditField("size");
                EditField("offset");
                break;

            case Overlap2d.ShapeType.Point:
                EditField("point");
                break;
            }

            GUILayout.Space(10);

            EditField("minDepth");
            EditField("maxDepth");

            GUILayout.Label("Results:", EditorStyles.boldLabel);
            EditField("storeDidHit");
            EditField("storeGameObjects");
            EditField("everyFrame");

            GUILayout.Label("Filter:", EditorStyles.boldLabel);
            int temp = EditorGUILayout.MaskField("Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(action.layerMask.Value), InternalEditorUtility.layers);

            action.layerMask.Value = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(temp);

            GUILayout.Label("Debug:", EditorStyles.boldLabel);
            EditField("debug");
            if (action.debug.Value)
            {
                EditField("debugColor");
            }


            return(GUI.changed);
        }
    private void OnGUI()
    {
        EditorGUILayout.BeginHorizontal(new GUIStyle(GUI.skin.button));
        {
            EditorGUILayout.BeginVertical(new GUIStyle(GUI.skin.window));
            {
                EditorGUILayout.LabelField("Start of BeginVertical");
                EditorGUILayout.BeginHorizontal(new GUIStyle(GUI.skin.button));
                EditorGUILayout.LabelField("Horizontal 1");
                EditorGUILayout.LabelField("Horizontal 2");
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal(new GUIStyle(GUI.skin.button));
                EditorGUILayout.LabelField("Horizontal 1");
                EditorGUILayout.LabelField("Horizontal 2");
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.LabelField("EndVertical");
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginVertical(new GUIStyle(GUI.skin.window));
            {
                EditorGUILayout.LabelField("Start of BeginVertical");
                EditorGUILayout.LabelField("EndVertical");
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndHorizontal();

        scrollPos       = EditorGUILayout.BeginScrollView(scrollPos, true, true, GUILayout.Width(600f), GUILayout.Height(200f));
        colorValue      = EditorGUILayout.ColorField("ColorField", colorValue);
        curveValue      = EditorGUILayout.CurveField("CurveField", curveValue);
        intValue        = EditorGUILayout.IntField("IntField", intValue);
        delayedIntValue = EditorGUILayout.DelayedIntField("Delayed IntField", delayedIntValue);
        EditorGUILayout.LabelField($"IntValue: {intValue}, DelayedIntValue: {delayedIntValue}");
        floatValue   = EditorGUILayout.FloatField("FloatField", floatValue);
        foldoutValue = EditorGUILayout.Foldout(foldoutValue, "Foldout");
        EditorGUILayout.EndScrollView();

        foldoutGroupValue = EditorGUILayout.BeginFoldoutHeaderGroup(foldoutGroupValue, "Foldout Group");
        if (foldoutGroupValue)
        {
            EditorGUILayout.LabelField("Label 1");
            EditorGUILayout.LabelField("Label 2");
        }
        EditorGUILayout.EndFoldoutHeaderGroup();

        var rect = EditorGUILayout.GetControlRect();

        EditorGUILayout.LabelField($"Control Rect: {rect}");
        gradientValue = EditorGUILayout.GradientField(gradientValue);
        EditorGUILayout.HelpBox("This is HelpBox", MessageType.Info);
        sliderValue = EditorGUILayout.IntSlider("Int Slider", sliderValue, 10, 100);
        maskValue   = EditorGUILayout.MaskField("MaskField", maskValue, new string[] { "Mask1", "Mask2", "Mask3" });
        objectValue = EditorGUILayout.ObjectField("ObjectField", objectValue, typeof(Object), true);

        string[] popupOptions    = { "Option 1", "Option 2", "Option 3", "Option 4", "Option 5", };
        int[]    intOptionValues = { 1, 3, 5, 7, 9 };
        intPopupValue = EditorGUILayout.IntPopup("IntPopup", intPopupValue, popupOptions, intOptionValues);
        EditorGUILayout.LabelField($"IntPopup Value: {intPopupValue}");
        popupSelectedIndex = EditorGUILayout.Popup("Popup", popupSelectedIndex, popupOptions);
        EditorGUILayout.LabelField($"Popup Value: {popupSelectedIndex}");

        textAreaValue  = EditorGUILayout.TextArea("Text Area");
        textFieldValue = EditorGUILayout.TextField("Text Field", "Text Field");

        tagValue = EditorGUILayout.TagField("TagField");
        EditorGUILayout.Space(30f);
        toggleGroupEnabled = EditorGUILayout.BeginToggleGroup("Toggle Group", toggleGroupEnabled);
        toggleValue[0]     = EditorGUILayout.Toggle("Toggle1", toggleValue[0]);
        toggleValue[1]     = EditorGUILayout.Toggle("Toggle2", toggleValue[1]);
        toggleValue[2]     = EditorGUILayout.Toggle("Toggle3", toggleValue[2]);
        EditorGUILayout.EndToggleGroup();
        toggleLeftValue = EditorGUILayout.ToggleLeft("ToggleLeft", false);

        vector2Value = EditorGUILayout.Vector2Field("Vector2 Field", vector2Value);
        vector3Value = EditorGUILayout.Vector3Field("Vector3 Field", vector3Value);
    }
Esempio n. 13
0
    //[MenuItem("Examples/Mask Field usage")]
    //static void Init()
    //{
    //    MultiEnumTest window = (MultiEnumTest)GetWindow(typeof(MultiEnumTest));
    //    window.Show();
    //}

    void OnGUI()
    {
        flags = EditorGUILayout.MaskField("Player Flags", flags, options);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        EditorGUILayout.LabelField("Mobile Spotify Authorization", EditorStyles.boldLabel);

        GUIContent content = null;

        // Platform
        content            = new GUIContent("Platform", "Select the platform you're currently building for");
        m_service.Platform = (MobileSpotifyService.Platforms)EditorGUILayout.EnumPopup(content, m_service.Platform);

        // Warning box, platform specific TL;DR instructions
        string text = $"Make sure you select the right platform and follow the correct setup instructions. {Environment.NewLine}{Environment.NewLine}";

        if (m_service.Platform == MobileSpotifyService.Platforms.Android)
        {
            text += "Android: Make sure you setup your 'AndroidManifest.xml' correctly";
        }
        else if (m_service.Platform == MobileSpotifyService.Platforms.iOS)
        {
            text += "iOS: Make sure you setup your 'Spotify4UnityDelegate.mm' and 'link.xml' files AND imported the 'JSON.NET for Unity' asset";
        }
        EditorGUILayout.HelpBox(text, MessageType.Warning);

        // Client ID
        content            = new GUIContent("Client Id", "The Client Id of your application, from Spotify Dashboard");
        m_service.ClientId = EditorGUILayout.TextField(content, m_service.ClientId);

        // Scheme
        content          = new GUIContent("Scheme", "Name of the scheme to use, should match the same as inside your AndroidManifest.xml inside your 'intent-filter'");
        m_service.Scheme = EditorGUILayout.TextField(content, m_service.Scheme);

        // Redirect URL
        content = new GUIContent("Redirect URL Suffix", "Rest of the redirect URL after the scheme. If you're unsure what to put here, make it a unique path like 'oauth/spotify/'");
        m_service.RedirectUrlSuffix = EditorGUILayout.TextField(content, m_service.RedirectUrlSuffix);

        EditorGUILayout.HelpBox($"Your full redirect url will be '{m_service.Scheme}://{m_service.RedirectUrlSuffix}'.{Environment.NewLine}This needs to match the redirect url inside your Spotify Dashboard", MessageType.Info);

        EditorGUILayout.Space();

        // Auto Connect
        content = new GUIContent("Auto Connect", "Should the service start the authorize process on Start");
        m_service.AutoConnect = EditorGUILayout.Toggle(content, m_service.AutoConnect);

        // Reuse Auth Token
        content = new GUIContent("Reuse Auth Token", "Should the service save the current token to reuse on reopen the application");
        m_service.ReuseAuthTokens = EditorGUILayout.Toggle(content, m_service.ReuseAuthTokens);

        // Auto Reauthorize
        content = new GUIContent("Auto Reauthorize", "Should the service prompt the user for reauthorization when the current token has expired - " +
                                 "WARNING: Will instantly reauthorize the app and can happen when the user doesn't expect unless told");
        m_service.AutoReauthorize = EditorGUILayout.Toggle(content, m_service.AutoReauthorize);

        if (m_service.AutoReauthorize)
        {
            EditorGUILayout.HelpBox("This will automatically open a browser for authentification when it expires. It's recommended that you advice the user that this will happen", MessageType.Warning);
        }

        EditorGUILayout.Space();

        // Log Level
        content            = new GUIContent("Log Level", "Level of logs from Spotify4Unity that should be output to Unity console. Must have 'S4U_LOGS' in your 'Scripting Define Symbols' to show them");
        m_service.LogLevel = (Analysis.LogLevel)EditorGUILayout.EnumPopup(content, m_service.LogLevel);

        EditorGUILayout.Space();

#if UNITY_EDITOR
        EditorGUILayout.LabelField("Editor Debug Authorization", EditorStyles.boldLabel);

        EditorGUILayout.HelpBox("Please read the 'Mobile Setup' page of the Wiki for more information on being able to test in Editor", MessageType.Info);

        GUILayout.BeginHorizontal();

        content = new GUIContent("Debug Redirect URL", "The Client Id of your application, from Spotify Dashboard");
        string pcRedirect = EditorGUILayout.TextField(content, "http://localhost:4002");

        if (GUILayout.Button("Authorize"))
        {
            Application.OpenURL(m_service.GetAuthURL(m_service.ClientId, pcRedirect));
        }
        GUILayout.EndHorizontal();

        content = new GUIContent("URL Authentification", "The Client Id of your application, from Spotify Dashboard");
        m_service.DebugURLAuthorization = EditorGUILayout.TextField(content, m_service.DebugURLAuthorization);

        EditorGUILayout.Space();
#endif

        // Advanced Settings
        m_displayAdvancedSettings = EditorGUILayout.Foldout(m_displayAdvancedSettings, "Advanced Settings");
        if (m_displayAdvancedSettings)
        {
            EditorGUILayout.HelpBox("Selecting different scopes can and will break functionality! Read the Wiki and understand how 'Scopes' work before changing them", MessageType.Warning);

            string[] enums = Enum.GetNames(typeof(Scope));
            m_service.Scopes = (Scope)EditorGUILayout.MaskField("API Scopes", (int)m_service.Scopes, enums);

            // Connection Timeout
            content = new GUIContent("Connection Timeout (s)", "Amount of seconds before failing the authorization process");
            m_service.ConnectionTimeout = EditorGUILayout.IntField(content, m_service.ConnectionTimeout);
            // Update Frequency (ms)
            content = new GUIContent("Update Frequency (ms)", "Amount of milliseconds between doing an internal update check");
            m_service.UpdateFrequencyMs = EditorGUILayout.IntField(content, m_service.UpdateFrequencyMs);
        }

        EditorGUILayout.Space();
        MarkDirty();

        // Adds the iOS bridge script to the object if iOS platform is selected
        if (m_service.Platform == MobileSpotifyService.Platforms.iOS)
        {
            if (Selection.activeGameObject.GetComponent <iOSBridge>() == null)
            {
                Selection.activeGameObject.AddComponent <iOSBridge>();
            }
        }
        else
        {
            iOSBridge component = Selection.activeGameObject.GetComponent <iOSBridge>();
            if (this != null && component != null)
            {
                DestroyImmediate(component);

                EditorGUIUtility.ExitGUI();
            }
        }
    }
    void showOptionContent1()
    {
        GUILayout.Label("Base Setting", EditorStyles.boldLabel);
        m_Number = EditorGUILayout.IntSlider(m_Number, 0, 10);

        //实现一个渐隐效果的Toggle
        IsShowExtra.target = EditorGUILayout.ToggleLeft("显示一个额外的区域", IsShowExtra.target);
        //Extra block that can be toggled on and off.
        if (EditorGUILayout.BeginFadeGroup(IsShowExtra.faded))
        {
            //各种Field
            EditorGUI.indentLevel++;                   //加一层缩进
            EditorGUILayout.PrefixLabel("ColorField"); //PrefixLabel
            m_Color = EditorGUILayout.ColorField(m_Color);

            EditorGUILayout.PrefixLabel("TextField");
            m_String = EditorGUILayout.TextField(m_String);

            EditorGUILayout.PrefixLabel("EnumFlagsField");
            m_Flags = (ExampleFlagsEnum)EditorGUILayout.EnumFlagsField(m_Flags);

            EditorGUILayout.PrefixLabel("MaskField");
            flags = EditorGUILayout.MaskField("Player Flags", flags, options);

            // BoundsField
            bounds = EditorGUILayout.BoundsField("BoundsField", bounds); //??不理解这个是干嘛的
            EditorGUI.indentLevel--;                                     //还原缩进

            op = (OPTIONS)EditorGUILayout.EnumPopup("Primitive to create:", op);
        }
        EditorGUILayout.EndFadeGroup();

        //toggle group
        groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Setting", groupEnabled);
        pos[0]       = EditorGUILayout.Toggle("x", pos[0]);
        pos[1]       = EditorGUILayout.Toggle("y", pos[1]);
        pos[2]       = EditorGUILayout.Toggle("z", pos[2]);
        myFloat      = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
        EditorGUILayout.EndToggleGroup();

        //DropdownButton用法
        if (EditorGUILayout.DropdownButton(new GUIContent("Click and Drop"), FocusType.Keyboard))
        {
            var alls = new string[4] {
                "A", "B", "C", "D"
            };
            GenericMenu _menu = new GenericMenu();
            foreach (var item in alls)
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }
                //添加菜单
                _menu.AddItem(new GUIContent(item), item == selectItem, OnClickDropdownButton, item);
            }
            _menu.ShowAsContext();//显示菜单
        }


        //折叠栏
        bFoldOut = EditorGUILayout.Foldout(bFoldOut, status);
        if (bFoldOut)
        {
            if (Selection.activeTransform)
            {
                Selection.activeTransform.position =
                    EditorGUILayout.Vector3Field("Position", Selection.activeTransform.position);
                status = Selection.activeTransform.name;
            }
        }

        if (!Selection.activeTransform)
        {
            status   = "Select a GameObject";
            bFoldOut = false;
        }
    }
Esempio n. 16
0
    public override void OnInspectorGUI()
    {
        //if (showFtrace)
        {
            OnEnable();
            serializedObject.Update();

            EditorGUILayout.PropertyField(ftraceLightColor, new GUIContent("Color", "Color of the light"));
            EditorGUILayout.PropertyField(ftraceLightIntensity, new GUIContent("Intensity", "Color multiplier"));
            EditorGUILayout.PropertyField(ftraceLightShadowSpread, new GUIContent("Shadow spread", "Controls shadow blurriness from 0 to 1"));
            EditorGUILayout.PropertyField(ftraceLightSamples, new GUIContent("Shadow samples", "The amount of rays tested for this light. Rays are emitted from lightmap texel towards the light, distributed conically. Radius of the cone depends on Shadow Spread."));

            //ftraceLightBitmask.intValue = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings);
            int prevVal = ftraceLightBitmask.intValue;
            int newVal  = EditorGUILayout.MaskField(new GUIContent("Bitmask", "Lights only affect renderers with overlapping bits"), ftraceLightBitmask.intValue, selStrings);
            if (prevVal != newVal)
            {
                ftraceLightBitmask.intValue = newVal;
            }

            EditorGUILayout.PropertyField(ftraceLightBakeToIndirect, new GUIContent("Bake to indirect", "Add direct contribution from this light to indirect-only lightmaps"));
            if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue)
            {
                ftraceLightShadowmask.boolValue = false;
            }

            EditorGUILayout.PropertyField(ftraceLightShadowmask, new GUIContent("Shadowmask", "Enable mixed lighting. Static shadows from this light will be baked, and real-time light will cast shadows from dynamic objects."));
            if (ftraceLightBakeToIndirect.boolValue && ftraceLightShadowmask.boolValue)
            {
                ftraceLightBakeToIndirect.boolValue = false;
            }

            if (ftraceLightShadowmask.boolValue)
            {
                EditorGUILayout.PropertyField(ftraceLightShadowmaskDenoise, new GUIContent("Denoise shadowmask", "Apply denoising to shadowmask texture. For sharp shadows it may be unnecessary."));
            }

            EditorGUILayout.PropertyField(ftraceLightIndirectIntensity, new GUIContent("Indirect intensity", "Non-physical GI multiplier for this light"));

            serializedObject.ApplyModifiedProperties();
        }

        bool   showError = false;
        string why       = "";

        bool shadowmaskNoDynamicLight = false;

        foreach (BakeryDirectLight selectedLight in targets)
        {
            bool match = true;

            var light = selectedLight.GetComponent <Light>();
            if (light == null)
            {
                if (ftraceLightShadowmask.boolValue)
                {
                    shadowmaskNoDynamicLight = true;
                }
                continue;
            }
            if (!light.enabled)
            {
                if (ftraceLightShadowmask.boolValue)
                {
                    shadowmaskNoDynamicLight = true;
                }
            }
            var so = new SerializedObject(selectedLight);
            InitSerializedProperties(so);

            if (light.type != LightType.Directional)
            {
                match = false;
                why   = "real-time light is not direct";
            }

            if (light.bounceIntensity != ftraceLightIndirectIntensity.floatValue)
            {
                match = false;
                why   = "indirect intensity doesn't match";
            }

            var   clr = ftraceLightColor.colorValue;
            float eps = 1.0f / 255.0f;
            float lightR, lightG, lightB, lightInt;
            float fr, fg, fb;
            float fintensity = ftraceLightIntensity.floatValue;
            if (PlayerSettings.colorSpace == ColorSpace.Linear)
            {
                fr = clr.linear.r; // * fintensity;
                fg = clr.linear.g; // * fintensity;
                fb = clr.linear.b; // * fintensity;
            }
            else
            {
                fr = clr.r;
                fg = clr.g;
                fb = clr.b;
            }
            GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt);

            if (GraphicsSettings.lightsUseLinearIntensity || PlayerSettings.colorSpace != ColorSpace.Linear)
            {
                if (Mathf.Abs(lightR - fr) > eps || Mathf.Abs(lightG - fg) > eps || Mathf.Abs(lightB - fb) > eps)
                {
                    match = false;
                    why   = "color doesn't match";
                }
                else if (Mathf.Abs(lightInt - fintensity) > eps)
                {
                    match = false;
                    why   = "intensity doesn't match";
                }
            }
            else
            {
                eps *= Mathf.Max(lightInt, fintensity);
                if (Mathf.Abs(lightR * lightInt - fr * fintensity) > eps ||
                    Mathf.Abs(lightG * lightInt - fg * fintensity) > eps ||
                    Mathf.Abs(lightB * lightInt - fb * fintensity) > eps)
                {
                    match = false;
                    why   = "intensity doesn't match";
                }
            }

            if (!match)
            {
                showError = true;
            }
        }

        if (shadowmaskNoDynamicLight)
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Warning: shadowmask needs enabled real-time light to work");
        }

        if (showError)
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Real-time light doesn't match lightmap: " + why);
            if (GUILayout.Button("Match lightmapped to real-time"))
            {
                foreach (BakeryDirectLight selectedLight in targets)
                {
                    var light = selectedLight.GetComponent <Light>();
                    if (light == null)
                    {
                        continue;
                    }
                    //if (!light.enabled) continue;
                    var so = new SerializedObject(selectedLight);
                    InitSerializedProperties(so);

                    if (PlayerSettings.colorSpace != ColorSpace.Linear)
                    {
                        ftraceLightColor.colorValue     = light.color;
                        ftraceLightIntensity.floatValue = light.intensity;
                    }
                    else if (!GraphicsSettings.lightsUseLinearIntensity)
                    {
                        float lightR, lightG, lightB, lightInt;
                        GetLinearLightParameters(light, out lightR, out lightG, out lightB, out lightInt);
                        ftraceLightColor.colorValue     = new Color(lightR, lightG, lightB);
                        ftraceLightIntensity.floatValue = lightInt;
                    }
                    else
                    {
                        ftraceLightColor.colorValue     = light.color;
                        ftraceLightIntensity.floatValue = light.intensity;
                    }
                    ftraceLightIndirectIntensity.floatValue = light.bounceIntensity;

                    so.ApplyModifiedProperties();
                }
            }
            if (GUILayout.Button("Match real-time to lightmapped"))
            {
                foreach (BakeryDirectLight selectedLight in targets)
                {
                    var light = selectedLight.GetComponent <Light>();
                    if (light == null)
                    {
                        continue;
                    }
                    //if (!light.enabled) continue;
                    var so = new SerializedObject(selectedLight);
                    InitSerializedProperties(so);

                    Undo.RecordObject(light, "Change light");
                    if (PlayerSettings.colorSpace != ColorSpace.Linear)
                    {
                        light.color     = ftraceLightColor.colorValue;
                        light.intensity = ftraceLightIntensity.floatValue;
                    }
                    else if (!GraphicsSettings.lightsUseLinearIntensity)
                    {
                        float fr, fg, fb;
                        float fintensity = ftraceLightIntensity.floatValue;
                        var   clr        = ftraceLightColor.colorValue;
                        fr = clr.linear.r; // * fintensity;
                        fg = clr.linear.g; // * fintensity;
                        fb = clr.linear.b; // * fintensity;

                        fr = Mathf.Pow(fr * fintensity, 1.0f / 2.2f);
                        fg = Mathf.Pow(fg * fintensity, 1.0f / 2.2f);
                        fb = Mathf.Pow(fb * fintensity, 1.0f / 2.2f);
                        float fint = Mathf.Max(Mathf.Max(fr, fg), fb);
                        fr             /= fint;
                        fg             /= fint;
                        fb             /= fint;
                        light.color     = new Color(fr, fg, fb);
                        light.intensity = fint;
                    }
                    else
                    {
                        light.color     = ftraceLightColor.colorValue;
                        light.intensity = ftraceLightIntensity.floatValue;
                    }
                    light.type            = LightType.Directional;
                    light.bounceIntensity = ftraceLightIndirectIntensity.floatValue;
                }
            }
        }


        if (PlayerSettings.colorSpace == ColorSpace.Linear)
        {
            if (!GraphicsSettings.lightsUseLinearIntensity)
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Warning: project is not set up to use linear light intensity.");
                EditorGUILayout.LabelField("GraphicsSettings.lightsUseLinearIntensity should be TRUE.");
                if (GUILayout.Button("Fix"))
                {
                    GraphicsSettings.lightsUseLinearIntensity = true;
                }
            }
            else
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("Project is using linear light intensity. This is nice.");
                if (GUILayout.Button("Change to non-linear"))
                {
                    GraphicsSettings.lightsUseLinearIntensity = false;
                }
            }
        }
    }
Esempio n. 17
0
        public void Inspector()
        {
            Index = GetIndex();

            Utility.SetGUIColor(UltiDraw.DarkGrey);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();

                Utility.SetGUIColor(UltiDraw.LightGrey);
                using (new EditorGUILayout.VerticalScope("Box")) {
                    Utility.ResetGUIColor();

                    EditorGUILayout.BeginHorizontal();
                    Target.Folder = EditorGUILayout.TextField("Folder", "Assets/" + Target.Folder.Substring(Mathf.Min(7, Target.Folder.Length)));
                    if (Utility.GUIButton("Import", UltiDraw.DarkGrey, UltiDraw.White))
                    {
                        Import();
                    }
                    EditorGUILayout.EndHorizontal();


                    Utility.SetGUIColor(Target.GetActor() == null ? UltiDraw.DarkRed : UltiDraw.White);
                    Target.Actor = (Actor)EditorGUILayout.ObjectField("Actor", Target.GetActor(), typeof(Actor), true);
                    Utility.ResetGUIColor();

                    EditorGUILayout.ObjectField("Environment", Target.GetEnvironment(), typeof(Transform), true);

                    SetNameFilter(EditorGUILayout.TextField("Name Filter", NameFilter));
                    SetExportFilter(EditorGUILayout.Toggle("Export Filter", ExportFilter));
                    SetExcludeFilter(EditorGUILayout.Toggle("Exclude Filter", ExcludeFilter));

                    if (Instances.Length == 0)
                    {
                        LoadFile(-1);
                        EditorGUILayout.LabelField("No data available.");
                    }
                    else
                    {
                        LoadFile(EditorGUILayout.Popup("Data " + "(" + Instances.Length + ")", Index, Names));
                        EditorGUILayout.BeginHorizontal();
                        LoadFile(EditorGUILayout.IntSlider(Index + 1, 1, Instances.Length) - 1);
                        if (Utility.GUIButton("<", UltiDraw.DarkGrey, UltiDraw.White))
                        {
                            LoadFile(Mathf.Max(Index - 1, 0));
                        }
                        if (Utility.GUIButton(">", UltiDraw.DarkGrey, UltiDraw.White))
                        {
                            LoadFile(Mathf.Min(Index + 1, Instances.Length - 1));
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }

                if (Target.GetFile() != null)
                {
                    Utility.SetGUIColor(UltiDraw.Grey);
                    using (new EditorGUILayout.VerticalScope("Box")) {
                        Utility.ResetGUIColor();
                        Frame frame = Target.GetFile().Data.GetFrame(Target.Timestamp);

                        Utility.SetGUIColor(UltiDraw.Mustard);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.LabelField(Target.GetFile().Data.Name, GUILayout.Width(100f));
                            EditorGUILayout.LabelField("Frames: " + Target.GetFile().Data.GetTotalFrames(), GUILayout.Width(100f));
                            EditorGUILayout.LabelField("Time: " + Target.GetFile().Data.GetTotalTime().ToString("F3") + "s", GUILayout.Width(100f));
                            EditorGUILayout.LabelField("Framerate: " + Target.GetFile().Data.Framerate.ToString("F1") + "Hz", GUILayout.Width(130f));
                            EditorGUILayout.LabelField("Timescale:", GUILayout.Width(65f), GUILayout.Height(20f));
                            Target.Timescale = EditorGUILayout.FloatField(Target.Timescale, GUILayout.Width(30f), GUILayout.Height(20f));
                            if (Utility.GUIButton("M", Target.ShowMirror ? UltiDraw.Cyan : UltiDraw.LightGrey, UltiDraw.Black))
                            {
                                Target.SetMirror(!Target.ShowMirror);
                            }
                            if (Utility.GUIButton("T", Target.ShowTrajectory ? UltiDraw.Cyan : UltiDraw.LightGrey, UltiDraw.Black))
                            {
                                Target.ShowTrajectory = !Target.ShowTrajectory;
                            }
                            if (Utility.GUIButton("V", Target.ShowVelocities ? UltiDraw.Cyan : UltiDraw.LightGrey, UltiDraw.Black))
                            {
                                Target.ShowVelocities = !Target.ShowVelocities;
                            }
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.EndHorizontal();
                        }

                        Utility.SetGUIColor(UltiDraw.DarkGrey);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            if (Target.Playing)
                            {
                                if (Utility.GUIButton("||", Color.red, Color.black, 20f, 20f))
                                {
                                    Target.StopAnimation();
                                }
                            }
                            else
                            {
                                if (Utility.GUIButton("|>", Color.green, Color.black, 20f, 20f))
                                {
                                    Target.PlayAnimation();
                                }
                            }
                            if (Utility.GUIButton("<", UltiDraw.Grey, UltiDraw.White, 20f, 20f))
                            {
                                Target.LoadPreviousFrame();
                            }
                            if (Utility.GUIButton(">", UltiDraw.Grey, UltiDraw.White, 20f, 20f))
                            {
                                Target.LoadNextFrame();
                            }
                            int index = EditorGUILayout.IntSlider(frame.Index, 1, Target.GetFile().Data.GetTotalFrames(), GUILayout.Width(440f));
                            if (index != frame.Index)
                            {
                                Target.LoadFrame(index);
                            }
                            EditorGUILayout.LabelField(frame.Timestamp.ToString("F3") + "s", Utility.GetFontColor(Color.white), GUILayout.Width(50f));
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            Target.Window = EditorGUILayout.Slider(Target.Window, 0f, 1f);
                            GUILayout.FlexibleSpace();
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    for (int i = 0; i < Target.GetFile().Data.Modules.Length; i++)
                    {
                        Target.GetFile().Data.Modules[i].Inspector(Target);
                    }
                    string[] modules = new string[(int)Module.TYPE.Length + 1];
                    modules[0] = "Add Module...";
                    for (int i = 1; i < modules.Length; i++)
                    {
                        modules[i] = ((Module.TYPE)(i - 1)).ToString();
                    }
                    int module = EditorGUILayout.Popup(0, modules);
                    if (module > 0)
                    {
                        Target.GetFile().Data.AddModule((Module.TYPE)(module - 1));
                    }
                    if (Utility.GUIButton("Settings", Target.InspectSettings ? UltiDraw.Cyan : UltiDraw.LightGrey, UltiDraw.Black))
                    {
                        Target.InspectSettings = !Target.InspectSettings;
                    }
                    if (Target.InspectSettings)
                    {
                        Utility.SetGUIColor(UltiDraw.LightGrey);
                        using (new EditorGUILayout.VerticalScope("Box")) {
                            Utility.ResetGUIColor();
                            Target.GetFile().Data.Export = EditorGUILayout.Toggle("Export", Target.GetFile().Data.Export);
                            Target.SetScaling(EditorGUILayout.FloatField("Scaling", Target.GetFile().Data.Scaling));
                            Target.GetFile().Data.RootSmoothing = EditorGUILayout.IntField("Root Smoothing", Target.GetFile().Data.RootSmoothing);
                            Target.GetFile().Data.Ground = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(EditorGUILayout.MaskField("Ground Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(Target.GetFile().Data.Ground), InternalEditorUtility.layers));
                            Target.GetFile().Data.MirrorAxis = (MotionData.AXIS)EditorGUILayout.EnumPopup("Mirror Axis", Target.GetFile().Data.MirrorAxis);
                            string[] names = new string[Target.GetFile().Data.Source.Bones.Length];
                            for (int i = 0; i < Target.GetFile().Data.Source.Bones.Length; i++)
                            {
                                names[i] = Target.GetFile().Data.Source.Bones[i].Name;
                            }
                            for (int i = 0; i < Target.GetFile().Data.Source.Bones.Length; i++)
                            {
                                EditorGUILayout.BeginHorizontal();
                                Target.GetFile().Data.Source.Bones[i].Active = EditorGUILayout.Toggle(Target.GetFile().Data.Source.Bones[i].Active);
                                EditorGUI.BeginDisabledGroup(true);
                                EditorGUILayout.TextField(names[i]);
                                EditorGUI.EndDisabledGroup();
                                Target.GetFile().Data.SetSymmetry(i, EditorGUILayout.Popup(Target.GetFile().Data.Symmetry[i], names));
                                Target.GetFile().Data.Source.Bones[i].Alignment = EditorGUILayout.Vector3Field("", Target.GetFile().Data.Source.Bones[i].Alignment);
                                EditorGUILayout.EndHorizontal();
                            }

                            Utility.SetGUIColor(UltiDraw.Grey);
                            using (new EditorGUILayout.VerticalScope("Box")) {
                                Utility.ResetGUIColor();

                                Utility.SetGUIColor(UltiDraw.Cyan);
                                using (new EditorGUILayout.VerticalScope("Box")) {
                                    Utility.ResetGUIColor();
                                    EditorGUILayout.LabelField("Camera");
                                }

                                if (Utility.GUIButton("Auto Focus", Target.AutoFocus ? UltiDraw.Cyan : UltiDraw.LightGrey, UltiDraw.Black))
                                {
                                    Target.SetAutoFocus(!Target.AutoFocus);
                                }
                                Target.FocusHeight    = EditorGUILayout.FloatField("Focus Height", Target.FocusHeight);
                                Target.FocusOffset    = EditorGUILayout.FloatField("Focus Offset", Target.FocusOffset);
                                Target.FocusDistance  = EditorGUILayout.FloatField("Focus Distance", Target.FocusDistance);
                                Target.FocusAngle     = EditorGUILayout.Slider("Focus Angle", Target.FocusAngle, 0f, 360f);
                                Target.FocusSmoothing = EditorGUILayout.Slider("Focus Smoothing", Target.FocusSmoothing, 0f, 1f);
                            }

                            if (Utility.GUIButton("Copy Hierarchy", UltiDraw.DarkGrey, UltiDraw.White))
                            {
                                Target.CopyHierarchy();
                            }
                            if (Utility.GUIButton("Detect Symmetry", UltiDraw.DarkGrey, UltiDraw.White))
                            {
                                Target.GetFile().Data.DetectSymmetry();
                            }
                            if (Utility.GUIButton("Create Skeleton", UltiDraw.DarkGrey, UltiDraw.White))
                            {
                                Target.CreateSkeleton();
                            }

                            EditorGUILayout.BeginHorizontal();
                            if (Utility.GUIButton("Add Export Sequence", UltiDraw.DarkGrey, UltiDraw.White))
                            {
                                Target.GetFile().Data.AddSequence(1, Target.GetFile().Data.GetTotalFrames());
                            }
                            if (Utility.GUIButton("Remove Export Sequence", UltiDraw.DarkGrey, UltiDraw.White))
                            {
                                Target.GetFile().Data.RemoveSequence();
                            }
                            EditorGUILayout.EndHorizontal();
                            for (int i = 0; i < Target.GetFile().Data.Sequences.Length; i++)
                            {
                                Utility.SetGUIColor(UltiDraw.Grey);
                                using (new EditorGUILayout.VerticalScope("Box")) {
                                    Utility.ResetGUIColor();

                                    EditorGUILayout.BeginHorizontal();
                                    GUILayout.FlexibleSpace();
                                    if (Utility.GUIButton("X", Color.cyan, Color.black, 15f, 15f))
                                    {
                                        Target.GetFile().Data.Sequences[i].SetStart(Target.GetState().Index);
                                    }
                                    EditorGUILayout.LabelField("Start", GUILayout.Width(50f));
                                    Target.GetFile().Data.Sequences[i].SetStart(EditorGUILayout.IntField(Target.GetFile().Data.Sequences[i].Start, GUILayout.Width(100f)));
                                    EditorGUILayout.LabelField("End", GUILayout.Width(50f));
                                    Target.GetFile().Data.Sequences[i].SetEnd(EditorGUILayout.IntField(Target.GetFile().Data.Sequences[i].End, GUILayout.Width(100f)));
                                    if (Utility.GUIButton("X", Color.cyan, Color.black, 15f, 15f))
                                    {
                                        Target.GetFile().Data.Sequences[i].SetEnd(Target.GetState().Index);
                                    }
                                    GUILayout.FlexibleSpace();
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Recursively draw properties of the given SerializedProperty data.
        /// </summary>
        public static void DrawSerializedProperty(SerializedProperty prop, GUIStyle guiStyle = null)
        {
            switch (prop.propertyType)
            {
            case SerializedPropertyType.Generic:
                // make Array and Object to be fold
                prop.isExpanded = EditorGUILayout.Foldout(prop.isExpanded, prop.name);
                if (!prop.isExpanded)
                {
                    break;
                }

                // increase indentation
                EditorGUI.indentLevel++;
                if (!prop.isArray)
                {
                    // get Serializable Object
                    var child = prop.Copy();
                    var end   = prop.GetEndProperty(true);
                    if (child.Next(true))
                    {
                        while (!SerializedProperty.EqualContents(child, end))
                        {
                            DrawSerializedProperty(child);
                            if (!child.Next(false))
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    // Handles array type with separate way due to SerializedProperty provides
                    // its own method for array type.
                    prop.arraySize = EditorGUILayout.IntField("Length", prop.arraySize);
                    var showCount = Mathf.Min(prop.arraySize, maxVisibleArrayElements);
                    for (int i = 0; i < showCount; i++)
                    {
                        if (guiStyle != null)
                        {
                            using (new GUILayout.VerticalScope(guiStyle))
                            {
                                DrawSerializedProperty(prop.GetArrayElementAtIndex(i));
                            }
                        }
                        else
                        {
                            DrawSerializedProperty(prop.GetArrayElementAtIndex(i));
                        }
                    }
                    // Hide elements if it exceeds defined show count.
                    if (prop.arraySize > showCount)
                    {
                        using (new GUILayout.HorizontalScope())
                        {
                            // Do indentation
                            for (int i = 0; i < EditorGUI.indentLevel; i++)
                            {
                                GUILayout.Space(EditorGUIUtility.singleLineHeight);
                            }
                            if (GUILayout.Button("Show more ..."))
                            {
                                maxVisibleArrayElements += defaultVisibleArrayElements;
                            }
                        }
                    }
                }
                // decrease indentation
                EditorGUI.indentLevel--;
                break;

            case SerializedPropertyType.Integer:
                prop.intValue = EditorGUILayout.IntField(prop.name, prop.intValue);
                break;

            case SerializedPropertyType.Boolean:
                prop.boolValue = EditorGUILayout.Toggle(prop.name, prop.boolValue);
                break;

            case SerializedPropertyType.Float:
                prop.floatValue = EditorGUILayout.FloatField(prop.name, prop.floatValue);
                break;

            case SerializedPropertyType.String:
                prop.stringValue = EditorGUILayout.TextField(prop.name, prop.stringValue);
                break;

            case SerializedPropertyType.Color:
                prop.colorValue = EditorGUILayout.ColorField(prop.name, prop.colorValue);
                break;

            case SerializedPropertyType.ObjectReference:
                prop.objectReferenceValue = EditorGUILayout.ObjectField(
                    prop.name, prop.objectReferenceValue, typeof(Object), true);
                EditorGUI.indentLevel++;
                EditorGUILayout.LabelField("Type", prop.type);
                EditorGUI.indentLevel--;
                break;

            case SerializedPropertyType.LayerMask:
                prop.intValue = EditorGUILayout.IntField(prop.name, prop.intValue);
                break;

            case SerializedPropertyType.Enum:
                // Both of Mask and normal status are shown
                EditorGUILayout.PropertyField(prop);
                prop.enumValueIndex = EditorGUILayout.IntField(prop.name, prop.enumValueIndex);
                EditorGUI.indentLevel++;
                prop.enumValueIndex = EditorGUILayout.Popup("< Enum >", prop.enumValueIndex, prop.enumNames);
                prop.enumValueIndex = EditorGUILayout.MaskField("< Mask >", prop.enumValueIndex, prop.enumNames);
                EditorGUI.indentLevel--;
                break;

            case SerializedPropertyType.Vector2:
                prop.vector2Value = EditorGUILayout.Vector2Field(prop.name, prop.vector2Value);
                break;

            case SerializedPropertyType.Vector3:
                prop.vector3Value = EditorGUILayout.Vector3Field(prop.name, prop.vector3Value);
                break;

            case SerializedPropertyType.Rect:
                prop.rectValue = EditorGUILayout.RectField(prop.name, prop.rectValue);
                break;

            case SerializedPropertyType.ArraySize:
                prop.intValue = EditorGUILayout.IntField(prop.name, prop.intValue);
                break;

            case SerializedPropertyType.Character:
                EditorGUILayout.PropertyField(prop);
                break;

            case SerializedPropertyType.AnimationCurve:
                prop.animationCurveValue = EditorGUILayout.CurveField(prop.name, prop.animationCurveValue);
                break;

            case SerializedPropertyType.Bounds:
                prop.boundsValue = EditorGUILayout.BoundsField(prop.name, prop.boundsValue);
                break;

            case SerializedPropertyType.Gradient:
                EditorGUILayout.PropertyField(prop);
                break;

            case SerializedPropertyType.Quaternion:
                prop.quaternionValue = Quaternion.Euler(
                    EditorGUILayout.Vector3Field(prop.name, prop.quaternionValue.eulerAngles));
                break;
            }
        }
Esempio n. 19
0
 public int DrawAreaMaskPopup(string label, int mask)
 {
     return(EditorGUILayout.MaskField(label, mask, areaMaskOptions));
 }
Esempio n. 20
0
    public override void OnInspectorGUI()
    {
        GUIStyle bold_wrap = EditorStyles.boldLabel;

        bold_wrap.wordWrap = true;
        GUILayout.Label("Navmesh Preprocessor for HTC Vive Locomotion", bold_wrap);
        GUILayout.Label("Adrian Biagioli 2017", EditorStyles.miniLabel);

        GUILayout.Label("Before Using", bold_wrap);
        GUIStyle wrap = EditorStyles.label;

        wrap.wordWrap = true;
        GUILayout.Label(
            "Make sure you bake a Navigation Mesh (NavMesh) in Unity before continuing (Window > Navigation).  When you " +
            "are done, click \"Update Navmesh Data\" below.  This will update the graphic of the playable area " +
            "that the player will see in-game.\n", wrap);

        ViveNavMesh mesh = (ViveNavMesh)target;

        serializedObject.Update();

        // Area Mask //
        string[] areaNames  = GameObjectUtility.GetNavMeshAreaNames();
        int[]    area_index = new int[areaNames.Length];
        int      temp_mask  = 0;

        for (int x = 0; x < areaNames.Length; x++)
        {
            area_index[x] = GameObjectUtility.GetNavMeshAreaFromName(areaNames[x]);
            temp_mask    |= ((p_area.intValue >> area_index[x]) & 1) << x;
        }
        EditorGUI.BeginChangeCheck();
        temp_mask = EditorGUILayout.MaskField("Area Mask", temp_mask, areaNames);
        if (EditorGUI.EndChangeCheck())
        {
            p_area.intValue = 0;
            for (int x = 0; x < areaNames.Length; x++)
            {
                p_area.intValue |= (((temp_mask >> x) & 1) == 1 ? 0 : 1) << area_index[x];
            }
            p_area.intValue = ~p_area.intValue;
        }
        serializedObject.ApplyModifiedProperties();

        // Sanity check for Null properties //
        bool HasMesh = (mesh.SelectableMesh != null && mesh.SelectableMesh.vertexCount != 0) ||
                       (mesh.SelectableMeshBorder != null && mesh.SelectableMeshBorder.Length != 0);

        // Fixes below error message popping up with prefabs.  Kind of hacky but gets the job done
        bool isPrefab = EditorUtility.IsPersistent(target);

        if (isPrefab && mesh.SelectableMesh == null)
        {
            mesh.SelectableMesh = new Mesh();
        }

        bool MeshNull   = mesh.SelectableMesh == null;
        bool BorderNull = mesh.SelectableMeshBorder == null;

        if (MeshNull || BorderNull)
        {
            string str = "Internal Error: ";
            if (MeshNull)
            {
                str += "Selectable Mesh == null.  ";
            }
            if (BorderNull)
            {
                str += "Border point array == null.  ";
            }
            str +=
                "This may lead to strange behavior or serialization.  Try updating the mesh or delete and recreate the Navmesh object.  ";
            str += "If you are able to consistently get a Vive Nav Mesh object into this state, please submit a bug report.";
            EditorGUILayout.HelpBox(str, MessageType.Error);
        }

        // Update / Clear Navmesh Data //
        if (GUILayout.Button("Update Navmesh Data"))
        {
            Undo.RecordObject(mesh, "Update Navmesh Data");

            NavMeshTriangulation tri = NavMesh.CalculateTriangulation();

            Vector3[] verts = tri.vertices;
            int[]     tris  = tri.indices;
            int[]     areas = tri.areas;

            int vert_size = verts.Length;
            int tri_size  = tris.Length;
            RemoveMeshDuplicates(verts, tris, out vert_size, 0.01f);
            DewarpMesh(verts, mesh.DewarpingMethod, mesh.SampleRadius);
            CullNavmeshTriangulation(verts, tris, areas, p_area.intValue, mesh.IgnoreSlopedSurfaces, ref vert_size,
                                     ref tri_size);

            Mesh m = ConvertNavmeshToMesh(verts, tris, vert_size, tri_size);
            // Can't use SerializedProperties here because BorderPointSet doesn't derive from UnityEngine.Object
            mesh.SelectableMeshBorder = FindBorderEdges(m);

            serializedObject.Update();
            p_mesh.objectReferenceValue = m;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.SelectableMesh = mesh.SelectableMesh; // Make sure that setter is called
        }

        GUI.enabled = HasMesh;
        if (GUILayout.Button("Clear Navmesh Data"))
        {
            Undo.RecordObject(mesh, "Clear Navmesh Data");

            // Note: Unity does not serialize "null" correctly so we set everything to empty objects
            Mesh m = new Mesh();

            serializedObject.Update();
            p_mesh.objectReferenceValue = m;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.SelectableMesh = mesh.SelectableMesh; // Make sure setter is called

            mesh.SelectableMeshBorder = new BorderPointSet[0];
        }
        GUI.enabled = true;

        GUILayout.Label(HasMesh ? "Status: NavMesh Loaded" : "Status: No NavMesh Loaded");

        // Render Settings //
        EditorGUILayout.LabelField("Render Settings", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(p_material);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(mesh, "Change Ground Material");
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.GroundMaterial = new Material((Material)p_material.objectReferenceValue); // Reload material
        }

        EditorGUILayout.PropertyField(p_alpha);
        serializedObject.ApplyModifiedProperties();

        // Raycast Settings //
        EditorGUILayout.LabelField("Raycast Settings", EditorStyles.boldLabel);

        int  temp_layer_mask        = p_layer_mask.intValue;
        bool temp_ignore_layer_mask = p_ignore_layer_mask.boolValue;

        EditorGUI.BeginChangeCheck();
        temp_layer_mask = LayerMaskField("Layer Mask", temp_layer_mask);
        if (EditorGUI.EndChangeCheck())
        {
            p_layer_mask.intValue = temp_layer_mask;
        }
        serializedObject.ApplyModifiedProperties();
        EditorGUI.BeginChangeCheck();
        temp_ignore_layer_mask = EditorGUILayout.Toggle("Ignore Layer Mask", temp_ignore_layer_mask);
        if (EditorGUI.EndChangeCheck())
        {
            p_ignore_layer_mask.boolValue = temp_ignore_layer_mask;
        }
        serializedObject.ApplyModifiedProperties();

        QueryTriggerInteraction temp_query_trigger_interaction =
            (QueryTriggerInteraction)p_query_trigger_interaction.intValue;

        EditorGUI.BeginChangeCheck();
        temp_query_trigger_interaction =
            (QueryTriggerInteraction)EditorGUILayout.EnumPopup("Query Trigger Interaction", temp_query_trigger_interaction);
        if (EditorGUI.EndChangeCheck())
        {
            p_query_trigger_interaction.intValue = (int)temp_query_trigger_interaction;
        }
        serializedObject.ApplyModifiedProperties();

        // Navmesh Settings //
        EditorGUILayout.LabelField("Navmesh Settings", EditorStyles.boldLabel);
        GUILayout.Label(
            "Make sure the sample radius below is equal to your Navmesh Voxel Size (see Advanced > Voxel Size " +
            "in the navigation window).  Increase this if the selection disk is not appearing.", wrap);
        EditorGUILayout.PropertyField(p_sample_radius);
        EditorGUILayout.PropertyField(p_ignore_sloped_surfaces);
        EditorGUILayout.PropertyField(p_dewarp_method);

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 21
0
        /** Displays a LayerMask field.
         * \param label Label to display
         * \param showSpecial Use the Nothing and Everything selections
         * \param selected Current LayerMask
         * \note Unity 3.5 and up will use the EditorGUILayout.MaskField instead of a custom written one.
         */
        public static LayerMask LayerMaskField(string label, LayerMask selected, bool showSpecial)
        {
        #if !UNITY_3_4
            //Unity 3.5 and up

            if (layers == null || (System.DateTime.UtcNow.Ticks - lastUpdateTick > 10000000L && Event.current.type == EventType.Layout))
            {
                lastUpdateTick = System.DateTime.UtcNow.Ticks;
                if (layers == null)
                {
                    layers       = new List <string>();
                    layerNumbers = new List <int>();
                    layerNames   = new string[4];
                }
                else
                {
                    layers.Clear();
                    layerNumbers.Clear();
                }

                int emptyLayers = 0;
                for (int i = 0; i < 32; i++)
                {
                    string layerName = LayerMask.LayerToName(i);

                    if (layerName != "")
                    {
                        for (; emptyLayers > 0; emptyLayers--)
                        {
                            layers.Add("Layer " + (i - emptyLayers));
                        }
                        layerNumbers.Add(i);
                        layers.Add(layerName);
                    }
                    else
                    {
                        emptyLayers++;
                    }
                }

                if (layerNames.Length != layers.Count)
                {
                    layerNames = new string[layers.Count];
                }
                for (int i = 0; i < layerNames.Length; i++)
                {
                    layerNames[i] = layers[i];
                }
            }

            selected.value = EditorGUILayout.MaskField(label, selected.value, layerNames);

            return(selected);
        #else
            if (layers == null)
            {
                layers       = new List <string>();
                layerNumbers = new List <int>();
            }
            else
            {
                layers.Clear();
                layerNumbers.Clear();
            }

            string selectedLayers = "";

            for (int i = 0; i < 32; i++)
            {
                string layerName = LayerMask.LayerToName(i);

                if (layerName != "")
                {
                    if (selected == (selected | (1 << i)))
                    {
                        if (selectedLayers == "")
                        {
                            selectedLayers = layerName;
                        }
                        else
                        {
                            selectedLayers = "Mixed";
                        }
                    }
                }
            }

            if (Event.current.type != EventType.MouseDown && Event.current.type != EventType.ExecuteCommand)
            {
                if (selected.value == 0)
                {
                    layers.Add("Nothing");
                }
                else if (selected.value == -1)
                {
                    layers.Add("Everything");
                }
                else
                {
                    layers.Add(selectedLayers);
                }
                layerNumbers.Add(-1);
            }

            if (showSpecial)
            {
                layers.Add((selected.value == 0 ? "[X] " : "     ") + "Nothing");
                layerNumbers.Add(-2);

                layers.Add((selected.value == -1 ? "[X] " : "     ") + "Everything");
                layerNumbers.Add(-3);
            }

            for (int i = 0; i < 32; i++)
            {
                string layerName = LayerMask.LayerToName(i);

                if (layerName != "")
                {
                    if (selected == (selected | (1 << i)))
                    {
                        layers.Add("[X] " + layerName);
                    }
                    else
                    {
                        layers.Add("     " + layerName);
                    }
                    layerNumbers.Add(i);
                }
            }

            bool preChange = GUI.changed;

            GUI.changed = false;

            int newSelected = 0;

            if (Event.current.type == EventType.MouseDown)
            {
                newSelected = -1;
            }

            newSelected = EditorGUILayout.Popup(label, newSelected, layers.ToArray(), EditorStyles.layerMaskField);

            if (GUI.changed && newSelected >= 0)
            {
                int preSelected = selected;

                if (showSpecial && newSelected == 0)
                {
                    selected = 0;
                }
                else if (showSpecial && newSelected == 1)
                {
                    selected = -1;
                }
                else
                {
                    if (selected == (selected | (1 << layerNumbers[newSelected])))
                    {
                        selected &= ~(1 << layerNumbers[newSelected]);
                        //Debug.Log ("Set Layer "+LayerMask.LayerToName (LayerNumbers[newSelected]) + " To False "+selected.value);
                    }
                    else
                    {
                        //Debug.Log ("Set Layer "+LayerMask.LayerToName (LayerNumbers[newSelected]) + " To True "+selected.value);
                        selected = selected | (1 << layerNumbers[newSelected]);
                    }
                }

                if (selected == preSelected)
                {
                    GUI.changed = false;
                }
                else
                {
                    //Debug.Log ("Difference made");
                }
            }

            GUI.changed = preChange || GUI.changed;

            return(selected);
        #endif
        }
    public override void OnInspectorGUI()
    {
        var entry = target as PartRegistryAssetEntry;

        var registry = entry.GetComponentInParent <PartRegistryAuthoring>();

        EditorGUI.BeginChangeCheck();

        // TODO (mogensh) make general method to make WeakAssetReference field
        var guidStr = "";

        if (entry.Asset.IsSet() && m_lastReference != entry.Asset)
        {
            guidStr = entry.Asset.ToGuidStr();
            var path = AssetDatabase.GUIDToAssetPath(guidStr);

            var obj = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));

            lastObject      = obj;
            m_lastReference = entry.Asset;
        }
        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(new GUIContent("Asset" + "(" + guidStr + ")"));
        var newObj = EditorGUILayout.ObjectField(lastObject, typeof(GameObject), false);

        GUILayout.EndHorizontal();
        if (newObj != lastObject)
        {
            if (newObj != null)
            {
                var path = AssetDatabase.GetAssetPath(newObj);
                entry.Asset = new WeakAssetReference(AssetDatabase.AssetPathToGUID(path));
            }
        }


        var catNames = new string[registry.Categories.Count];

        for (var i = 0; i < registry.Categories.Count; i++)
        {
            catNames[i] = registry.Categories[i].Name;
        }

        entry.CategoryIndex = EditorGUILayout.Popup("Category", entry.CategoryIndex, catNames);

        var parts     = registry.Categories[entry.CategoryIndex].Parts;
        var partNames = new string[parts.Count];

        for (var i = 0; i < parts.Count; i++)
        {
            partNames[i] = parts[i].Name;
        }
        entry.PartIndex = EditorGUILayout.Popup("Part", entry.PartIndex, partNames);

        // Build type
        var buildTypeNames = Enum.GetNames(typeof(BuildType));

        entry.BuildTypeFlags = EditorGUILayout.MaskField("BuildTypes", entry.BuildTypeFlags, buildTypeNames);


        // Rig
        //Debug.Log($"registry.Rigs.Count {registry.Rigs.Count}");
        if (registry.Rigs.Count > 1)
        {
            var rigNames = new string[registry.Rigs.Count];
            for (var i = 0; i < registry.Rigs.Count; i++)
            {
                rigNames[i] = i + ":" + registry.Rigs[i];
            }

            entry.RigFlags = EditorGUILayout.MaskField("Rig", entry.RigFlags, rigNames);
        }

        // LOD
        if (registry.LODlevels.Count > 1)
        {
            var LODNames = new string[registry.LODlevels.Count];
            for (int i = 0; i < registry.LODlevels.Count; i++)
            {
                LODNames[i] = "LOD" + i;
            }
            entry.LODFlags = EditorGUILayout.MaskField("LOD", entry.LODFlags, LODNames);
        }

        var buildString = "Build:" + GetFlagString(entry.BuildTypeFlags, Enum.GetNames(typeof(BuildType)).Length);
        var rigString   = registry.Rigs.Count > 1 ? "Rig:" + GetFlagString(entry.RigFlags, registry.Rigs.Count)  : "";
        var lodString   = registry.LODlevels.Count > 1 ? "LOD:" + GetFlagString(entry.LODFlags, registry.LODlevels.Count) : "";
        var partStr     = parts[entry.PartIndex].Name;

        entry.name = registry.Categories[entry.CategoryIndex].Name + "." + partStr + "<" + buildString + " " + rigString + " " + lodString + ">";

        var change = EditorGUI.EndChangeCheck();

        if (change)
        {
            EditorUtility.SetDirty(entry);
            EditorUtility.SetDirty(entry.gameObject);
            EditorUtility.SetDirty(registry.gameObject);
        }
    }
Esempio n. 23
0
        public static int EnumFlagField(System.Type enumType, GUIContent label, int value)
        {
            var names = (from e in EnumUtil.GetUniqueEnumFlags(enumType) select e.ToString()).ToArray();

            return(EditorGUILayout.MaskField(label, value, names));
        }
Esempio n. 24
0
 public override int Mask(GUIContent content, int mask, string[] displayedOptions, GUIStyle style, Layout option)
 {
     return(EditorGUILayout.MaskField(content, mask, displayedOptions, style, option));
 }
Esempio n. 25
0
        public void Inspector(MotionEditor editor)
        {
            UltiDraw.Begin();

            UltiDraw.DrawSphere(Vector3.zero, Quaternion.identity, 1f, Color.red);

            Utility.SetGUIColor(UltiDraw.Grey);
            using (new EditorGUILayout.VerticalScope("Box")) {
                Utility.ResetGUIColor();

                Frame frame = Module.Data.GetFrame(editor.GetState().Index);

                SetSensor(EditorGUILayout.Popup("Sensor", Sensor, Module.Names));
                SetDistanceThreshold(EditorGUILayout.FloatField("Distance Threshold", DistanceThreshold));
                SetVelocityThreshold(EditorGUILayout.FloatField("Velocity Threshold", VelocityThtreshold));
                SetFilterWidth(EditorGUILayout.IntField("Filter Width", FilterWidth));
                SetOffset(EditorGUILayout.Vector3Field("Offset", Offset));
                SetNormal(EditorGUILayout.Vector3Field("Normal", Normal));
                SetMask(InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(EditorGUILayout.MaskField("Mask", InternalEditorUtility.LayerMaskToConcatenatedLayersMask(Mask), InternalEditorUtility.layers)));

                EditorGUILayout.BeginVertical(GUILayout.Height(50f));
                Rect ctrl = EditorGUILayout.GetControlRect();
                Rect rect = new Rect(ctrl.x, ctrl.y, ctrl.width, 50f);
                EditorGUI.DrawRect(rect, UltiDraw.Black);

                float startTime = frame.Timestamp - editor.GetWindow() / 2f;
                float endTime   = frame.Timestamp + editor.GetWindow() / 2f;
                if (startTime < 0f)
                {
                    endTime  -= startTime;
                    startTime = 0f;
                }
                if (endTime > Module.Data.GetTotalTime())
                {
                    startTime -= endTime - Module.Data.GetTotalTime();
                    endTime    = Module.Data.GetTotalTime();
                }
                startTime = Mathf.Max(0f, startTime);
                endTime   = Mathf.Min(Module.Data.GetTotalTime(), endTime);
                int start    = Module.Data.GetFrame(startTime).Index;
                int end      = Module.Data.GetFrame(endTime).Index;
                int elements = end - start;

                Vector3 prevPos = Vector3.zero;
                Vector3 newPos  = Vector3.zero;
                Vector3 bottom  = new Vector3(0f, rect.yMax, 0f);
                Vector3 top     = new Vector3(0f, rect.yMax - rect.height, 0f);

                //Contacts
                for (int i = start; i <= end; i++)
                {
                    top.x    = rect.xMin + (float)(i - start) / elements * rect.width;
                    bottom.x = rect.xMin + (float)(i - start) / elements * rect.width;

                    top.y    = rect.yMax - rect.height;
                    bottom.y = rect.yMax - rect.height / 2f;
                    if (RegularContacts[i - 1])
                    {
                        UltiDraw.DrawLine(top, bottom, UltiDraw.Green);
                    }

                    top.y    = rect.yMax - rect.height / 2f;
                    bottom.y = rect.yMax;
                    if (InverseContacts[i - 1])
                    {
                        UltiDraw.DrawLine(top, bottom, UltiDraw.Green);
                    }
                }

                //Sequences
                for (int i = 0; i < Module.Data.Sequences.Length; i++)
                {
                    float   left  = rect.x + (float)(Module.Data.Sequences[i].Start - 1) / (float)(Module.Data.GetTotalFrames() - 1) * rect.width;
                    float   right = rect.x + (float)(Module.Data.Sequences[i].End - 1) / (float)(Module.Data.GetTotalFrames() - 1) * rect.width;
                    Vector3 a     = new Vector3(left, rect.y, 0f);
                    Vector3 b     = new Vector3(right, rect.y, 0f);
                    Vector3 c     = new Vector3(left, rect.y + rect.height, 0f);
                    Vector3 d     = new Vector3(right, rect.y + rect.height, 0f);
                    UltiDraw.DrawTriangle(a, c, b, UltiDraw.Yellow.Transparent(0.25f));
                    UltiDraw.DrawTriangle(b, c, d, UltiDraw.Yellow.Transparent(0.25f));
                }

                //Current Pivot
                top.x    = rect.xMin + (float)(frame.Index - start) / elements * rect.width;
                bottom.x = rect.xMin + (float)(frame.Index - start) / elements * rect.width;
                top.y    = rect.yMax - rect.height;
                bottom.y = rect.yMax;
                UltiDraw.DrawLine(top, bottom, UltiDraw.Yellow);
                UltiDraw.DrawCircle(top, 3f, UltiDraw.Green);
                UltiDraw.DrawCircle(bottom, 3f, UltiDraw.Green);

                Handles.DrawLine(Vector3.zero, Vector3.zero);                 //Somehow needed to get it working...

                EditorGUILayout.EndVertical();
            }
            UltiDraw.End();
        }
Esempio n. 26
0
    void OnGUI()
    {
        titleContent.text = "打包设置编辑器";

        UpdateRelyPackageNames();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("过滤器:");

        RelyMaskFilter = EditorGUILayout.MaskField(RelyMaskFilter, RelyPackageNames);
        bundleQuery    = EditorGUILayout.TextField("", bundleQuery);
        EditorGUILayout.EndHorizontal();

        scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.ExpandHeight(false));

        isFoldRelyPackages = EditorGUILayout.Foldout(isFoldRelyPackages, "依赖包:");
        if (isFoldRelyPackages)
        {
            //依赖包视图
            RelyPackagesView();

            EditorGUILayout.Space();
        }

        EditorGUI.indentLevel = 0;
        isFoldBundles         = EditorGUILayout.Foldout(isFoldBundles, "AssetsBundle:");
        if (isFoldBundles)
        {
            //bundle包视图
            BundlesView();
        }
        GUILayout.EndScrollView();

        LogsScrollPos = GUILayout.BeginScrollView(LogsScrollPos, GUILayout.ExpandHeight(true));

        EditorGUI.indentLevel = 0;
        isFoldLog             = EditorGUILayout.Foldout(isFoldLog, "提示信息:");
        if (isFoldLog)
        {
            //提示信息视图
            LogView();
        }

        GUILayout.EndScrollView();

        EditorGUI.indentLevel = 0;
        GUILayout.BeginHorizontal();

        checkMaterial = EditorGUILayout.Toggle("检查材质球和贴图", checkMaterial);

        GUILayout.EndHorizontal();

        HotUpdateConfigGUI();

        if (GUILayout.Button("检查依赖关系"))
        {
            CheckPackage();
        }

        //if (GUILayout.Button("重新添加资源文件并保存"))
        //{
        //    AddAllResourceBundle();  //添加资源文件
        //    ArrangeBundlesByLayer(); //整理资源路径

        //    CreatPackageFile();                 //保存编辑器文件
        //    CheckAndCreatBundelPackageConfig(); //生成资源路径文件
        //}

        if (GUILayout.Button("保存游戏资源路径文件"))
        {
            CreatePackageFile();                //保存编辑器文件
            CheckAndCreatBundelPackageConfig(); //生成资源路径文件
        }

        if (!isPacking)
        {
            if (GUILayout.Button("打包"))
            {
                CheckAndPackage();
            }
        }
        else
        {
            if (GUILayout.Button("终止打包"))
            {
                EndPackage();
            }
        }

        if (GUILayout.Button("生成MD5"))
        {
            CheckAndCreatBundelPackageConfig();
        }

        GUILayout.BeginHorizontal();

        VersionService.LargeVersion = EditorGUILayout.IntField("large", VersionService.LargeVersion);
        VersionService.SmallVersion = EditorGUILayout.IntField("small", VersionService.SmallVersion);

        if (GUILayout.Button("保存版本文件"))
        {
            VersionService.CreateVersionFile();
        }

        GUILayout.EndHorizontal();

        if (isContent)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(messageContent);

            if (GUILayout.Button("关闭"))
            {
                isContent      = false;
                messageContent = "";
            }

            if (errorCount != 0 || warnCount != 0)
            {
                if (GUILayout.Button("清除"))
                {
                    isContent      = false;
                    messageContent = "";

                    ClearCheckLog();
                }
            }
            EditorGUILayout.EndHorizontal();
        }

        if (isProgress)
        {
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUI.ProgressBar(new Rect(3, position.height - 22, position.width - 6, 18), progress, progressContent);
        }
    }
    private void DrawPaintMode()
    {
        GNBlockMapEditorVM.PaintMode mode = viewModel.CurrentPaintMode;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.BeginHorizontal();
        GUILayout.Label("Paint Mode (p): ", EditorStyles.whiteBoldLabel);
        if (viewModel.SetCurrentPaintMode(NPVoxGUILayout.HotkeyToggleBar <GNBlockMapEditorVM.PaintMode>(
                                              new string[] { "Brush", "Random" },
                                              new GNBlockMapEditorVM.PaintMode[] {
            GNBlockMapEditorVM.PaintMode.BRUSH,
            GNBlockMapEditorVM.PaintMode.RANDOM
        },
                                              KeyCode.P,
                                              mode,
                                              true
                                              )))
        {
            SceneView.RepaintAll();
        }
        GUILayout.EndHorizontal();

        // if (viewModel.CurrentPaintMode == GNBlockMapEditorVM.PaintMode.RANDOM) // this leads to exception
        {
            GUILayout.BeginHorizontal();
            GNBlockMapEditorVM.RandomBrushFlags flags = (GNBlockMapEditorVM.RandomBrushFlags)EditorGUILayout.MaskField(
                new GUIContent("Options"),
                (int)viewModel.CurrentRandomBrushFlags,
                new string[] { "Prefab", "Rotate X", "Rotate Y", "Rotate Z", "Flip X", "Flip Y", "Flip Z" });
            if (flags != viewModel.CurrentRandomBrushFlags)
            {
                viewModel.CurrentRandomBrushFlags = flags;
                SceneView.RepaintAll();
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.EndVertical();
        DrawBrushSetup();
        GUILayout.EndHorizontal();
    }
Esempio n. 28
0
        override protected void DrawBody()
        {
            EditorGUILayout.PropertyField(itemType);
            if (itemType.enumValueIndex == 3)
            {
                if (settings.gameList.Count > 0)
                {
                    int index = EditorGUILayout.Popup(_identifyString.text, settings.gameList.IndexOf(_uid.stringValue), _gameListArray);
                    if (index < 0)
                    {
                        index = 0;
                    }
                    _uid.stringValue = IAPManagerProEditor.settings.gameList[index];
                }
                else
                {
                    EditorGUILayout.Popup(0, _gameListArray);
                }
            }
            else
            {
                searchTag.intValue = EditorGUILayout.MaskField("Search Tag", searchTag.intValue, _tagListArray);
            }
            EditorGUILayout.PropertyField(itemTemplate);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Layout", IAPEditorStyles.sectionTitle);
            GUILayout.Box(GUIContent.none, GUILayout.ExpandWidth(true), GUILayout.Height(1));
            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(layout);

            if (layout.enumValueIndex == 0)
            {
                EditorGUILayout.PropertyField(spacing);
                EditorGUILayout.PropertyField(cellSize);
                EditorGUILayout.PropertyField(padding, true);
                EditorGUILayout.PropertyField(startCorner);
                EditorGUILayout.PropertyField(startAxis);
                EditorGUILayout.PropertyField(contraint);
                if (contraint.enumValueIndex == 0)
                {
                }
                else
                {
                    EditorGUI.indentLevel = 1;
                    EditorGUILayout.PropertyField(constraintCount);
                    EditorGUI.indentLevel = 0;
                }
            }
            else
            {
                EditorGUILayout.PropertyField(spacingSingle);
                EditorGUILayout.PropertyField(padding, true);
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel("Child Force Expand");
                childForceExpandWidth.boolValue  = EditorGUILayout.ToggleLeft("Width", childForceExpandWidth.boolValue, GUILayout.Width(50));
                childForceExpandHeight.boolValue = EditorGUILayout.ToggleLeft("Height", childForceExpandHeight.boolValue, GUILayout.Width(50));
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            EditorGUILayout.PropertyField(OnGameLevelSelect);
        }
Esempio n. 29
0
        public override void OnInspectorGUI()
        {
            if (mMasks == null)
            {
                mMasks = M8.EditorExt.Utility.GenerateGenericMaskString();
            }

            SceneState data = target as SceneState;

            if (!Application.isPlaying)
            {
                var newUserData = EditorGUILayout.ObjectField("User Data", data.userData, typeof(UserData), false) as UserData;
                if (data.userData != newUserData)
                {
                    Undo.RecordObject(data, "Change User Data");
                    data.userData = newUserData;
                }

                //auto save config
                GUILayout.BeginVertical(GUI.skin.box);

                GUILayout.Label("Auto Save");

                var autoSaveOnSceneChange = EditorGUILayout.Toggle("On Scene Change", data.autoSaveOnSceneChange);
                if (data.autoSaveOnSceneChange != autoSaveOnSceneChange)
                {
                    Undo.RecordObject(data, "Change Auto Save");
                    data.autoSaveOnSceneChange = autoSaveOnSceneChange;
                }

                var autoSaveOnAppExit = EditorGUILayout.Toggle("On Application Exit", data.autoSaveOnApplicationExit);
                if (data.autoSaveOnApplicationExit != autoSaveOnAppExit)
                {
                    Undo.RecordObject(data, "Change Auto Save");
                    data.autoSaveOnApplicationExit = autoSaveOnAppExit;
                }

                GUILayout.EndVertical();

                //Globals
                initGlobalFoldout = EditorGUILayout.Foldout(initGlobalFoldout, "Scene Global Data");

                if (initGlobalFoldout)
                {
                    if (data.globalStartData == null)
                    {
                        data.globalStartData = new SceneState.InitData[0];
                    }

                    GUILayout.BeginVertical(GUI.skin.box);

                    int delSubKey = -1;
                    for (int j = 0; j < data.globalStartData.Length; j++)
                    {
                        SceneState.InitData initDat = data.globalStartData[j];

                        EditorGUI.BeginChangeCheck();

                        GUILayout.BeginVertical(GUI.skin.box);

                        GUILayout.BeginHorizontal();

                        initDat.name = GUILayout.TextField(initDat.name, GUILayout.MinWidth(200));

                        GUILayout.Space(32);

                        if (GUILayout.Button("DEL", GUILayout.MaxWidth(40)))
                        {
                            delSubKey = j;
                        }

                        GUILayout.EndHorizontal();

                        initDat.type = (SceneState.Type)EditorGUILayout.EnumPopup("Type", initDat.type);
                        switch (initDat.type)
                        {
                        case SceneState.Type.Integer:
                            initDat.ival = EditorGUILayout.IntField("Value", initDat.ival);
                            initDat.ival = EditorGUILayout.MaskField("Flags", initDat.ival, mMasks);
                            break;

                        case SceneState.Type.Float:
                            initDat.fval = EditorGUILayout.FloatField("Float", initDat.fval);
                            break;

                        case SceneState.Type.String:
                            initDat.sval = EditorGUILayout.TextField("String", initDat.sval);
                            break;
                        }

                        GUILayout.EndVertical();

                        if (delSubKey == -1 && EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(target, "SceneState - Edit [" + data.globalStartData[j].name + "]");

                            data.globalStartData[j] = initDat;
                        }
                    }

                    if (delSubKey != -1)
                    {
                        Undo.RecordObject(target, "SceneState - Removed [" + data.globalStartData[delSubKey].name + "]");

                        M8.ArrayUtil.RemoveAt(ref data.globalStartData, delSubKey);
                    }

                    if (GUILayout.Button("New Global Value"))
                    {
                        Undo.RecordObject(target, "SceneState - New Global Value");

                        System.Array.Resize(ref data.globalStartData, data.globalStartData.Length + 1);

                        data.globalStartData[data.globalStartData.Length - 1] = new SceneState.InitData(SceneState.Type.Integer);
                    }

                    GUILayout.EndVertical();
                }

                M8.EditorExt.Utility.DrawSeparator();

                //Scene Specifics
                initFoldout = EditorGUILayout.Foldout(initFoldout, "Scene Data");

                if (initFoldout)
                {
                    //Cache count

                    EditorGUI.BeginChangeCheck();

                    int cacheCount = EditorGUILayout.IntField("Cache Count", data.localStateCache);

                    if (EditorGUI.EndChangeCheck())
                    {
                        Undo.RecordObject(target, "SceneState - Cache Count Change");

                        data.localStateCache = cacheCount;
                    }

                    //Scenes

                    if (data.startData == null)
                    {
                        data.startData = new SceneState.InitSceneData[0];
                    }

                    int delKey = -1;

                    for (int i = 0; i < data.startData.Length; i++)
                    {
                        SceneState.InitSceneData sceneDat = data.startData[i];

                        GUILayout.BeginVertical(GUI.skin.box);

                        GUILayout.BeginHorizontal();

                        sceneDat.editFoldout = EditorGUILayout.Foldout(sceneDat.editFoldout, "Scene:");

                        GUILayout.Space(4);

                        //Scene name
                        EditorGUI.BeginChangeCheck();

                        string newScene = GUILayout.TextField(sceneDat.scene, GUILayout.MinWidth(200));

                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(target, "SceneState - Change Scene Name from " + sceneDat.scene + " to " + newScene);

                            sceneDat.scene = newScene;
                        }

                        GUILayout.Space(32);

                        if (GUILayout.Button("DEL", GUILayout.MaxWidth(40)))
                        {
                            delKey = i;
                        }

                        GUILayout.EndHorizontal();

                        if (sceneDat.editFoldout)
                        {
                            GUILayout.Label("Values:");

                            if (sceneDat.data != null)
                            {
                                int delSubKey = -1;
                                for (int j = 0; j < sceneDat.data.Length; j++)
                                {
                                    EditorGUI.BeginChangeCheck();

                                    SceneState.InitData initDat = sceneDat.data[j];

                                    GUILayout.BeginVertical(GUI.skin.box);

                                    GUILayout.BeginHorizontal();

                                    initDat.name = GUILayout.TextField(initDat.name, GUILayout.MinWidth(200));

                                    GUILayout.Space(32);

                                    if (GUILayout.Button("DEL", GUILayout.MaxWidth(40)))
                                    {
                                        delSubKey = j;
                                    }

                                    GUILayout.EndHorizontal();

                                    initDat.type = (SceneState.Type)EditorGUILayout.EnumPopup("Type", initDat.type);
                                    switch (initDat.type)
                                    {
                                    case SceneState.Type.Integer:
                                        initDat.ival = EditorGUILayout.IntField("Value", initDat.ival);
                                        initDat.ival = EditorGUILayout.MaskField("Flags", initDat.ival, mMasks);
                                        break;

                                    case SceneState.Type.Float:
                                        initDat.fval = EditorGUILayout.FloatField("Float", initDat.fval);
                                        break;

                                    case SceneState.Type.String:
                                        initDat.sval = EditorGUILayout.TextField("String", initDat.sval);
                                        break;
                                    }

                                    GUILayout.EndVertical();

                                    if (delKey != -1 && delSubKey != -1 && EditorGUI.EndChangeCheck())
                                    {
                                        Undo.RecordObject(target, "SceneState (" + sceneDat.scene + ") - Edit [" + sceneDat.data[j].name + "]");

                                        sceneDat.data[j] = initDat;
                                    }
                                }

                                if (delSubKey != -1)
                                {
                                    Undo.RecordObject(target, "SceneState (" + sceneDat.scene + ") - Removed [" + sceneDat.data[delSubKey].name + "]");

                                    M8.ArrayUtil.RemoveAt(ref sceneDat.data, delSubKey);
                                }
                            }

                            if (GUILayout.Button("New Value"))
                            {
                                Undo.RecordObject(target, "SceneState (" + sceneDat.scene + ") - New Value");

                                if (sceneDat.data == null)
                                {
                                    sceneDat.data = new SceneState.InitData[1];
                                }
                                else
                                {
                                    System.Array.Resize(ref sceneDat.data, sceneDat.data.Length + 1);
                                }

                                sceneDat.data[sceneDat.data.Length - 1] = new SceneState.InitData(SceneState.Type.Integer);
                            }
                        }

                        GUILayout.EndVertical();
                    }

                    if (delKey != -1)
                    {
                        Undo.RecordObject(target, "SceneState - Removed [" + data.startData[delKey].scene + "]");

                        M8.ArrayUtil.RemoveAt(ref data.startData, delKey);
                    }

                    if (GUILayout.Button("New Scene Data"))
                    {
                        Undo.RecordObject(target, "SceneState - New Scene Set Added");

                        System.Array.Resize(ref data.startData, data.startData.Length + 1);
                        data.startData[data.startData.Length - 1] = new SceneState.InitSceneData();
                    }
                }
            }
            else
            {
                M8.EditorExt.Utility.DrawSeparator();

                //global scene data
                runtimeGlobalFoldout = EditorGUILayout.Foldout(runtimeGlobalFoldout, "Global Scene Data");

                if (runtimeGlobalFoldout && data.global != null)
                {
                    foreach (var pair in data.global)
                    {
                        GUILayout.BeginVertical(GUI.skin.box);

                        GUILayout.Label(pair.Key);

                        switch (pair.Value.type)
                        {
                        case SceneState.Type.Integer:
                            EditorGUILayout.LabelField("Value", pair.Value.ival.ToString());
                            EditorGUILayout.MaskField("Flags", pair.Value.ival, mMasks);
                            break;

                        case SceneState.Type.Float:
                            EditorGUILayout.LabelField("Float", pair.Value.fval.ToString());
                            break;

                        case SceneState.Type.String:
                            EditorGUILayout.LabelField("String", pair.Value.sval);
                            break;

                        case SceneState.Type.Invalid:
                            EditorGUILayout.LabelField("Invalid!");
                            break;
                        }

                        GUILayout.EndVertical();
                    }
                }

                M8.EditorExt.Utility.DrawSeparator();

                //Scene data
                runtimeFoldout = EditorGUILayout.Foldout(runtimeFoldout, "Scene Data");

                if (runtimeFoldout && data.local != null)
                {
                    foreach (var pair in data.local)
                    {
                        GUILayout.BeginVertical(GUI.skin.box);

                        GUILayout.Label(pair.Key);

                        switch (pair.Value.type)
                        {
                        case SceneState.Type.Integer:
                            EditorGUILayout.LabelField("Value", pair.Value.ival.ToString());
                            EditorGUILayout.MaskField("Flags", pair.Value.ival, mMasks);
                            break;

                        case SceneState.Type.Float:
                            EditorGUILayout.LabelField("Float", pair.Value.fval.ToString());
                            break;

                        case SceneState.Type.String:
                            EditorGUILayout.LabelField("String", pair.Value.sval);
                            break;

                        case SceneState.Type.Invalid:
                            EditorGUILayout.LabelField("Invalid!");
                            break;
                        }

                        GUILayout.EndVertical();
                    }
                }

                M8.EditorExt.Utility.DrawSeparator();

                //value change
                GUILayout.BeginVertical(GUI.skin.box);

                GUILayout.Label("Override");

                mApplyName = GUILayout.TextField(mApplyName);
                mApplyType = (SceneState.Type)EditorGUILayout.EnumPopup("Type", mApplyType);
                switch (mApplyType)
                {
                case SceneState.Type.Integer:
                    mApplyValue = EditorGUILayout.IntField("Value", mApplyValue);
                    mApplyValue = EditorGUILayout.MaskField("Flags", mApplyValue, mMasks);
                    break;

                case SceneState.Type.Float:
                    mApplyFValue = EditorGUILayout.FloatField("Float", mApplyFValue);
                    break;

                case SceneState.Type.String:
                    mApplySValue = EditorGUILayout.TextField("String", mApplySValue);
                    break;
                }


                mApplyToGlobal   = GUILayout.Toggle(mApplyToGlobal, "Global");
                mApplyPersistent = GUILayout.Toggle(mApplyPersistent, "Persistent");

                var table = mApplyToGlobal ? data.global : data.local;

                if (GUILayout.Button("Apply") && !string.IsNullOrEmpty(mApplyName))
                {
                    switch (mApplyType)
                    {
                    case SceneState.Type.Integer:
                        table.SetValue(mApplyName, mApplyValue, mApplyPersistent);
                        break;

                    case SceneState.Type.Float:
                        table.SetValueFloat(mApplyName, mApplyFValue, mApplyPersistent);
                        break;

                    case SceneState.Type.String:
                        table.SetValueString(mApplyName, mApplySValue, mApplyPersistent);
                        break;
                    }

                    Repaint();
                }

                GUILayout.EndVertical();

                M8.EditorExt.Utility.DrawSeparator();

                //refresh
                if (GUILayout.Button("Refresh"))
                {
                    if (!string.IsNullOrEmpty(mApplyName))
                    {
                        var val = table.GetValueRaw(mApplyName);
                        mApplyValue  = val.ival;
                        mApplyFValue = val.fval;
                        mApplySValue = val.sval;
                    }
                    Repaint();
                }
            }
        }
Esempio n. 30
0
    public override void OnInspectorGUI()
    {
        if (mover == null)
        {
            Setup();
            return;
        }

        GUILayout.Label("Mover Options", EditorStyles.boldLabel);

        Rect _space;

        EditorGUI.BeginChangeCheck();

        mover.stepHeight = EditorGUILayout.Slider("Step Height", mover.stepHeight, 0f, 1f);

        GUILayout.Label("Collider Options", EditorStyles.boldLabel);

        mover.colliderHeight    = EditorGUILayout.FloatField("Collider Height", mover.colliderHeight);
        mover.colliderThickness = EditorGUILayout.FloatField("Collider Thickness", mover.colliderThickness);
        mover.colliderOffset    = EditorGUILayout.Vector3Field("Collider Offset", mover.colliderOffset);

        if (EditorGUI.EndChangeCheck())
        {
            mover.RecalculateColliderDimensions();
            OnEditorVariableChanged();
        }

        GUILayout.Label("Sensor Options", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();

        mover.sensorType      = (Sensor.CastType)EditorGUILayout.EnumPopup("Sensor Type", mover.sensorType);
        mover.sensorLayermask = EditorGUILayout.MaskField("Layermask", mover.sensorLayermask, physicsLayers);

        mover.isInDebugMode = EditorGUILayout.Toggle("Debug Mode", mover.isInDebugMode);

        if (EditorGUI.EndChangeCheck())
        {
            OnEditorVariableChanged();
        }

        if (mover.sensorType == Sensor.CastType.RaycastArray)
        {
            GUILayout.Label("Advanced Options", EditorStyles.centeredGreyMiniLabel);
        }
        GUILayout.Space(5);

        if (mover.sensorType == Sensor.CastType.Raycast)
        {
        }
        else if (mover.sensorType == Sensor.CastType.Spherecast)
        {
        }
        else if (mover.sensorType == Sensor.CastType.RaycastArray)
        {
            if (raycastArrayPositions == null)
            {
                raycastArrayPositions = Sensor.GetRaycastStartPositions(mover.sensorArrayRows, mover.sensorArrayRayCount, mover.sensorArrayRowsAreOffset, 1f);
            }

            EditorGUI.BeginChangeCheck();

            mover.sensorArrayRayCount      = EditorGUILayout.IntSlider("Number", mover.sensorArrayRayCount, 3, 9);
            mover.sensorArrayRows          = EditorGUILayout.IntSlider("Rows", mover.sensorArrayRows, 1, 5);
            mover.sensorArrayRowsAreOffset = EditorGUILayout.Toggle("Offset Rows", mover.sensorArrayRowsAreOffset);

            if (EditorGUI.EndChangeCheck())
            {
                raycastArrayPositions = Sensor.GetRaycastStartPositions(mover.sensorArrayRows, mover.sensorArrayRayCount, mover.sensorArrayRowsAreOffset, 1f);
                OnEditorVariableChanged();
            }

            GUILayout.Space(5);

            _space = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(100));

            Rect background = new Rect(_space.x + (_space.width - _space.height) / 2f, _space.y, _space.height, _space.height);
            EditorGUI.DrawRect(background, Color.grey);

            float point_size = 3f;

            Vector2 center = new Vector2(background.x + background.width / 2f, background.y + background.height / 2f);

            if (raycastArrayPositions != null && raycastArrayPositions.Length != 0)
            {
                for (int i = 0; i < raycastArrayPositions.Length; i++)
                {
                    Vector2 position = center + new Vector2(raycastArrayPositions[i].x, raycastArrayPositions[i].z) * background.width / 2f * 0.9f;

                    EditorGUI.DrawRect(new Rect(position.x - point_size / 2f, position.y - point_size / 2f, point_size, point_size), Color.white);
                }
            }

            if (raycastArrayPositions != null && raycastArrayPositions.Length != 0)
            {
                GUILayout.Label("Number of rays = " + raycastArrayPositions.Length, EditorStyles.centeredGreyMiniLabel);
            }
        }
    }