コード例 #1
0
    public override void OnInspectorGUI()
    {
        var script = (SpawnPool)target;

        EditorGUI.indentLevel = 0;
        PGEditorUtils.LookLikeControls();

        script.poolName = EditorGUILayout.TextField("Pool Name", script.poolName);

        script.matchPoolScale = EditorGUILayout.Toggle("Match Pool Scale", script.matchPoolScale);
        script.matchPoolLayer = EditorGUILayout.Toggle("Match Pool Layer", script.matchPoolLayer);

        script.dontReparent = EditorGUILayout.Toggle("Don't Reparent", script.dontReparent);

        script.dontDestroyOnLoad = EditorGUILayout.Toggle("Don't Destroy On Load", script.dontDestroyOnLoad);

        script.logMessages = EditorGUILayout.Toggle("Log Messages", script.logMessages);

        this.expandPrefabs = PGEditorUtils.SerializedObjFoldOutList <PrefabPool>
                             (
            "Per-Prefab Pool Options",
            script._perPrefabPoolOptions,
            this.expandPrefabs,
            ref script._editorListItemStates,
            true
                             );

        // Flag Unity to save the changes to to the prefab to disk
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        GUIContent content;

        EditorGUI.indentLevel       = 0;
        EditorGUIUtility.labelWidth = PGEditorUtils.CONTROLS_DEFAULT_LABEL_WIDTH;
        Object[] targetObjs = this.serializedObject.targetObjects;
        EventInfoListStandalone curEditTarget;

        content = new GUIContent
                  (
            "Event Info List",
            "A list of event descriptions to be passed by struct to Targets"
                  );

        if (this.serializedObject.isEditingMultipleObjects)
        {
            EditorGUILayout.PropertyField(this.eventInfoList, content, true);
        }
        else
        {
            GUILayout.Space(6);

            EditorGUI.indentLevel += 2;

            curEditTarget   = (EventInfoListStandalone)targetObjs[0];
            this.expandInfo = PGEditorUtils.SerializedObjFoldOutList <EventInfoListGUIBacker>
                              (
                content.text,
                curEditTarget._eventInfoListGUIBacker,
                this.expandInfo,
                ref curEditTarget._inspectorListItemStates,
                true
                              );

            EditorGUI.indentLevel -= 2;

            GUILayout.Space(4);
        }

        serializedObject.ApplyModifiedProperties();

        // Flag Unity to save the changes to to the prefab to disk
        //   This is needed to make the gizmos update immediatly.
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #3
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        GUIContent content;

        EditorGUI.indentLevel = 0;

        EditorGUIUtility.labelWidth = PGEditorUtils.CONTROLS_DEFAULT_LABEL_WIDTH;

        Object[] targetObjs = this.serializedObject.targetObjects;

        EventFireController curEditTarget;


        // Try and init the TargetTracker field
        for (int i = 0; i < targetObjs.Length; i++)
        {
            curEditTarget = (EventFireController)targetObjs[i];
            if (curEditTarget.targetTracker == null)
            {
                curEditTarget.targetTracker = curEditTarget.GetComponent <TargetTracker>();               // null OK
            }
        }


        content = new GUIContent("Interval", "Fire every X seconds");
        EditorGUILayout.PropertyField(this.interval, content);

        content = new GUIContent
                  (
            "Init Countdown at 0",
            "Able to fire immediatly when first spawned, before interval count begins"
                  );
        EditorGUILayout.PropertyField(this.initIntervalCountdownAtZero, content);

        content = new GUIContent
                  (
            "Notify Targets",
            "Sets the target notification behavior. Telling targets they are hit is optional " +
            "for situations where a delayed response is required, such as launching a , " +
            "projectile or for custom handling.\n" +
            "\n" +
            "MODES\n" +
            "    Off\n" +
            "        Do not notify anything. delegates can still be used\n" +
            "        for custom handling\n" +
            "    Direct\n" +
            "        OnFire targets will be notified immediately\n" +
            "    PassInfoToEventTrigger\n" +
            "        OnFire, for each Target hit, a new EventTrigger will\n" +
            "        be spawned and passed this EventFireController's \n" +
            "        EventInfo.\n" +
            "    UseEventTriggerInfo\n" +
            "        Same as PassInfoToEventTrigger but the new\n" +
            "        EventTrigger will use its own EventInfo (this \n" +
            "        EventTrigger's EventInfo will be ignored). "
                  );
        EditorGUILayout.PropertyField(this.notifyTargets, content);

        //
        // If using an EventTrigger Prefab...
        //
        EventFireController.NOTIFY_TARGET_OPTIONS curOption;
        curOption = (EventFireController.NOTIFY_TARGET_OPTIONS) this.notifyTargets.enumValueIndex;
        if (curOption > EventFireController.NOTIFY_TARGET_OPTIONS.Direct)
        {
            EditorGUI.indentLevel += 1;

            content = new GUIContent
                      (
                "Spawn At Transform",
                "This transform is optionally used as the position at which an EventTrigger " +
                "prefab is spawned from. Some Utility components may also use this as a " +
                "position reference if chosen."
                      );

            EditorGUILayout.PropertyField(this.spawnEventTriggerAtTransform, content);

            if (curOption == EventFireController.NOTIFY_TARGET_OPTIONS.PassInfoToEventTrigger ||
                curOption == EventFireController.NOTIFY_TARGET_OPTIONS.UseEventTriggerInfo)
            {
                content = new GUIContent
                          (
                    "EventTrigger Prefab",
                    "An optional EventTrigger to spawn OnFire depending on notifyTarget's " +
                    "NOTIFY_TARGET_OPTIONS."
                          );

                EditorGUILayout.PropertyField(this.eventTriggerPrefab, content);
            }

            if (InstanceManager.POOLING_ENABLED)
            {
                if (this.eventTriggerPrefab.objectReferenceValue != null)
                {
                    content = new GUIContent
                              (
                        "Use Pooling",
                        "If false, do not add the new instance to a pool. Use Unity's " +
                        "Instantiate/Destroy"
                              );

                    EditorGUILayout.PropertyField(this.usePooling, content);

                    if (this.usePooling.boolValue)
                    {
                        EditorGUI.indentLevel += 1;

                        content = new GUIContent
                                  (
                            "Override Pool",
                            "If an eventTriggerPrefab is spawned, setting this to true will " +
                            "override the EventTrigger's poolName and use this instead. The " +
                            "instance will also be passed this EventFireController's " +
                            "eventTriggerPoolName to be used when the EventTrigger is " +
                            "desapwned."
                                  );

                        EditorGUILayout.PropertyField(this.overridePoolName, content);

                        if (this.overridePoolName.boolValue)
                        {
                            content = new GUIContent
                                      (
                                "Pool Name",
                                "The name of a pool to be used with PoolManager or other " +
                                "pooling solution. If not using pooling, this will do " +
                                "nothing and be hidden in the Inspector.\n" +
                                "WARNING: If poolname is set to '', Pooling will be disabled " +
                                "and Unity's Instantiate will be used."
                                      );

                            EditorGUILayout.PropertyField(this.eventTriggerPoolName, content);
                        }

                        EditorGUI.indentLevel -= 1;
                    }
                }
                else
                {
                    this.overridePoolName.boolValue = false;                      // Reset
                }
            }

            EditorGUI.indentLevel -= 1;
        }

        if (curOption != EventFireController.NOTIFY_TARGET_OPTIONS.UseEventTriggerInfo)
        {
            content = new GUIContent
                      (
                "Event Info List",
                "A list of event descriptions to be passed by struct to Targets"
                      );

            if (this.serializedObject.isEditingMultipleObjects)
            {
                EditorGUILayout.PropertyField(this.eventInfoList, content, true);
            }
            else
            {
                EditorGUI.indentLevel += 2;

                curEditTarget            = (EventFireController)targetObjs[0];
                this.expandEventInfoList = PGEditorUtils.SerializedObjFoldOutList <EventInfoListGUIBacker>
                                           (
                    content.text,
                    curEditTarget._eventInfoList,
                    this.expandEventInfoList,
                    ref curEditTarget._editorListItemStates,
                    true
                                           );

                EditorGUI.indentLevel -= 2;
            }
        }


        // Init with the TargetTracker found on the same GameObject if possible
        for (int i = 0; i < targetObjs.Length; i++)
        {
            curEditTarget = (EventFireController)targetObjs[i];
            if (curEditTarget.targetTracker == null)
            {
                curEditTarget.targetTracker = curEditTarget.GetComponent <AreaTargetTracker>();
            }
        }

        GUILayout.Space(6);

        content = new GUIContent
                  (
            "TargetTracker",
            "This FireController's TargetTracker. Defaults to one on the same GameObject."
                  );
        EditorGUILayout.PropertyField(this.targetTracker, content);

        GUILayout.Space(8);

        content = new GUIContent("Debug Level", "Set it higher to see more verbose information.");
        EditorGUILayout.PropertyField(this.debugLevel, content);

        serializedObject.ApplyModifiedProperties();

        // Flag Unity to save the changes to to the prefab to disk
        //   This is needed to make the gizmos update immediatly.
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #4
0
    public override void OnInspectorGUI()
    {
        var script = (Detonator)target;

        GUIStyle style;

        PGEditorUtils.LookLikeControls();
        EditorGUI.indentLevel = 1;

        script.targetLayers = PGEditorUtils.LayerMaskField
                              (
            "Hit Layers",
            script.targetLayers
                              );

        script.perimeterLayer = EditorGUILayout.LayerField("Range Layer", script.perimeterLayer);

        EditorGUILayout.BeginHorizontal();

        // Only trigger the update if it actually changes. This runs code in a peroperty
        //   that may be expensive
        var shape = script.perimeterShape;

        shape = PGEditorUtils.EnumPopup <TargetTracker.PERIMETER_SHAPES>("Detonation Shape", shape);
        if (shape != script.perimeterShape)
        {
            script.perimeterShape = shape;
        }

        script.overrideGizmoVisibility = false;

        GUILayout.Label("Gizmo", GUILayout.MaxWidth(40));
        script.drawGizmo = EditorGUILayout.Toggle(script.drawGizmo, GUILayout.MaxWidth(47));
        EditorGUILayout.EndHorizontal();

        if (script.drawGizmo)
        {
            EditorGUI.indentLevel = 3;
            EditorGUILayout.BeginHorizontal();

            script.gizmoColor = EditorGUILayout.ColorField("Gizmo Color", script.gizmoColor);

            style            = EditorStyles.miniButton;
            style.alignment  = TextAnchor.MiddleCenter;
            style.fixedWidth = 52;

            bool clicked = GUILayout.Toggle(false, "Reset", style);
            if (clicked)
            {
                script.gizmoColor = script.defaultGizmoColor;
            }

            EditorGUILayout.EndHorizontal();

            EditorGUI.indentLevel = 2;

            GUILayout.Space(4);
        }

        script.durration = EditorGUILayout.FloatField("Expand Durration", script.durration);

        // Display some information
        GUILayout.Space(6);
        style           = new GUIStyle(EditorStyles.label);
        style.wordWrap  = true;
        style.fontStyle = FontStyle.Italic;
        GUILayout.Label
        (
            "If spawned by a projectile, " +
            "the folowing range and effects are inherited from the projectile...",
            style
        );


        Vector3 range = script.range;

        switch (script.perimeterShape)
        {
        case TargetTracker.PERIMETER_SHAPES.Sphere:
            range.x = EditorGUILayout.FloatField("Max Range", range.x);
            range.y = range.x;
            range.z = range.x;
            break;

        case TargetTracker.PERIMETER_SHAPES.Box:
            range = EditorGUILayout.Vector3Field("Max Range", range);
            break;

        case TargetTracker.PERIMETER_SHAPES.Capsule:
            range   = EditorGUILayout.Vector2Field("Max Range", range);
            range.z = range.x;
            break;
        }
        script.range = range;

        GUILayout.Space(6);

        this.expandEffects = PGEditorUtils.SerializedObjFoldOutList <HitEffectGUIBacker>
                             (
            "EffectOnTargets",
            script._effectsOnTarget,
            this.expandEffects,
            ref script._editorListItemStates,
            true
                             );

        GUILayout.Space(4);
        script.debugLevel = (DEBUG_LEVELS)EditorGUILayout.EnumPopup("Debug Level", (System.Enum)script.debugLevel);


        // Flag Unity to save the changes to to the prefab to disk
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #5
0
    public override void OnInspectorGUI()
    {
        var script = (FireController)target;

        GUIContent content;

        EditorGUI.indentLevel = 1;
        PGEditorUtils.LookLikeControls();

        content         = new GUIContent("Interval", "Fire every X seconds");
        script.interval = EditorGUILayout.FloatField(content, script.interval);

        content = new GUIContent
                  (
            "Init Countdown at 0",
            "Able to fire immediatly when first spawned, before interval count begins"
                  );
        script.initIntervalCountdownAtZero = EditorGUILayout.Toggle(content, script.initIntervalCountdownAtZero);

        content = new GUIContent
                  (
            "Wait For Alignment",
            "Wait for the emitter to line up with the target before fireing. The " +
            "count will continue so this will fire as soon as possible."
                  );
        script.waitForAlignment = EditorGUILayout.Toggle(content, script.waitForAlignment);
        if (script.waitForAlignment)
        {
            EditorGUI.indentLevel = 2;

            script.emitter = PGEditorUtils.ObjectField <Transform>("Emitter (Optional)", script.emitter);

            content = new GUIContent
                      (
                "Angle Tolerance",
                "If waitForAlignment is true: If the emitter is pointing towards " +
                "the target within this angle in degrees, the target can be fired on."
                      );
            script.lockOnAngleTolerance = EditorGUILayout.FloatField(content, script.lockOnAngleTolerance);

            content = new GUIContent
                      (
                "Flat Comparison",
                "If false the true angles will be compared for alignment. " +
                "(More precise. Emitter must point at target.)\n" +
                "If true, only the direction matters. " +
                "(Good when turning in a direction but perfect alignment isn't needed.)"
                      );
            script.flatAngleCompare = EditorGUILayout.Toggle(content, script.flatAngleCompare);

            EditorGUI.indentLevel = 1;
        }

        script.notifyTargets = PGEditorUtils.EnumPopup <FireController.NOTIFY_TARGET_OPTIONS>
                               (
            "Notify Targets",
            script.notifyTargets
                               );

        if (script.notifyTargets > FireController.NOTIFY_TARGET_OPTIONS.Off)
        {
            script.ammoPrefab = PGEditorUtils.ObjectField <Transform>
                                (
                "Ammo (Optional)",
                script.ammoPrefab
                                );
        }


        EditorGUI.indentLevel = 2;

        this.expandEffects = PGEditorUtils.SerializedObjFoldOutList <HitEffectGUIBacker>
                             (
            "EffectOnTargets",
            script._effectsOnTarget,
            this.expandEffects,
            ref script._editorListItemStates,
            true
                             );

        EditorGUI.indentLevel = 1;


        GUILayout.Space(4);
        script.debugLevel = PGEditorUtils.EnumPopup <DEBUG_LEVELS>("Debug Level", script.debugLevel);

        // Flag Unity to save the changes to to the prefab to disk
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #6
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        GUIContent content;

        EditorGUI.indentLevel = 0;

        EditorGUIUtility.labelWidth = PGEditorUtils.CONTROLS_DEFAULT_LABEL_WIDTH;

        Object[] targetObjs = this.serializedObject.targetObjects;

        EventTrigger curEditTarget;

        if (InstanceManager.POOLING_ENABLED)
        {
            content = new GUIContent
                      (
                "PoolName",
                "The name of a pool to be used with PoolManager or other pooling solution. If " +
                "not using pooling, this will do nothing and be hidden in the Inspector. "
                      );
            EditorGUILayout.PropertyField(this.poolName, content);
        }

        content = new GUIContent
                  (
            "Hit Layers",
            "The layers in which the Area is allowed to find targets."
                  );
        EditorGUILayout.PropertyField(this.targetLayers, content);


        content = new GUIContent
                  (
            "Hit Mode",
            "Determines what should cause this EventTrigger to fire.\n" +
            "    TargetOnly\n" +
            "        Only a direct hit will trigger the OnFire event\n" +
            "    HitLayers\n" +
            "        Contact with any colliders in any of the layers in\n" +
            "        the HitLayers mask  will trigger the OnFire event."
                  );
        EditorGUILayout.PropertyField(this.hitMode, content);


        content = new GUIContent
                  (
            "listenTimeout (0 = OFF)",
            "An optional timer to allow this EventTrigger to timeout and self-destruct. When " +
            "set to a value above zero, when this reaches 0, the Fire coroutine will be " +
            "started and anything in range may be hit (depending on settings). This can be " +
            "used to give a projectile a max amount of time it can fly around before it " +
            "dies, or a time-based land mine or pick-up."
                  );
        EditorGUILayout.PropertyField(this.listenTimeout, content);

        content = new GUIContent
                  (
            "Fire On Spawn",
            "If true, the event will be fired as soon as this EventTrigger is spawned by " +
            "instantiation or pooling."
                  );
        EditorGUILayout.PropertyField(this.fireOnSpawn, content);

        content = new GUIContent
                  (
            "Fire On Sleep",
            "If this EventTrigger has a rigidbody, setting this to true will cause it to " +
            "fire if it falls asleep. See Unity's docs for more information on how " +
            "this happens."
                  );
        EditorGUILayout.PropertyField(this.fireOnRigidBodySleep, content);

        content = new GUIContent
                  (
            "Area Hit",
            "If true, more than just the primary target will be affected when this EventTrigger " +
            "fires. Use the range options to determine the behavior."
                  );
        EditorGUILayout.PropertyField(this.areaHit, content);

        // To make the gizmo delay work correctly, update the GUI here.
        serializedObject.ApplyModifiedProperties();

        if (this.areaHit.boolValue)
        {
            this.overrideGizmoVisibility.boolValue = false;

            EditorGUI.indentLevel += 1;

            content = new GUIContent(
                "Targets (-1 = all)",
                "The number of targets to return. Set to -1 to return all targets"
                );
            EditorGUILayout.PropertyField(this.numberOfTargets, content);


            content = new GUIContent("Sorting Style", "The style of sorting to use");
            EditorGUILayout.PropertyField(this.sortingStyle, content);

            var sortingStyle = (EventTrigger.SORTING_STYLES) this.sortingStyle.enumValueIndex;
            if (sortingStyle != EventTrigger.SORTING_STYLES.None)
            {
                EditorGUI.indentLevel += 1;

                content = new GUIContent(
                    "Minimum Interval",
                    "How often the target list will be sorted. If set to 0, " +
                    "sorting will only be triggered when Targets enter or exit range."
                    );
                EditorGUILayout.PropertyField(this.updateInterval, content);

                EditorGUI.indentLevel -= 1;
            }


            EditorGUI.BeginChangeCheck();
            content = new GUIContent
                      (
                "Area Layer",
                "The layer to put the Area in."
                      );
            content = EditorGUI.BeginProperty(new Rect(0, 0, 0, 0), content, this.areaLayer);

            int layer = EditorGUILayout.LayerField(content, this.areaLayer.intValue);

            // If changed, trigger the property setter for all objects being edited
            if (EditorGUI.EndChangeCheck())
            {
                for (int i = 0; i < targetObjs.Length; i++)
                {
                    curEditTarget = (EventTrigger)targetObjs[i];

                    Undo.RecordObject(curEditTarget, targetObjs[0].GetType() + " Area Layer");

                    curEditTarget.areaLayer = layer;
                }
            }
            EditorGUI.EndProperty();


            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            content = new GUIContent
                      (
                "Area Shape",
                "The shape of the Area used to detect targets in range"
                      );
            EditorGUILayout.PropertyField(this.areaShape, content);

            // If changed, trigger the property setter for all objects being edited
            if (EditorGUI.EndChangeCheck())
            {
                var shape = (AreaTargetTracker.AREA_SHAPES) this.areaShape.enumValueIndex;

                for (int i = 0; i < targetObjs.Length; i++)
                {
                    curEditTarget = (EventTrigger)targetObjs[i];

                    Undo.RecordObject(curEditTarget, targetObjs[0].GetType() + " areaShape");

                    curEditTarget.areaShape = shape;
                }
            }

            content = new GUIContent
                      (
                "Gizmo ",
                "Visualize the Area in the Editor by turning this on."
                      );
            PGEditorUtils.ToggleButton(this.drawGizmo, content, 50);

            EditorGUILayout.EndHorizontal();

            if (this.drawGizmo.boolValue)
            {
                EditorGUI.indentLevel += 1;
                EditorGUILayout.BeginHorizontal();

                content = new GUIContent
                          (
                    "Gizmo Color",
                    "The color of the gizmo when displayed"
                          );
                EditorGUILayout.PropertyField(this.gizmoColor, content);

                // If clicked, reset the color to the default
                GUIStyle style = EditorStyles.miniButton;
                style.alignment  = TextAnchor.MiddleCenter;
                style.fixedWidth = 52;
                if (GUILayout.Button("Reset", style))
                {
                    for (int i = 0; i < this.serializedObject.targetObjects.Length; i++)
                    {
                        curEditTarget            = (EventTrigger)this.serializedObject.targetObjects[i];
                        curEditTarget.gizmoColor = curEditTarget.defaultGizmoColor;
                    }
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel -= 1;

                GUILayout.Space(4);
            }

            content = new GUIContent
                      (
                "Duration (<0 = stay)",
                "An optional duration to control how long this EventTrigger stays active. " +
                "Each target will only be hit once with the event notification unless the " +
                "Target leaves and then re-enters range. Set this to -1 to keep it alive " +
                "forever."
                      );
            EditorGUILayout.PropertyField(this.duration, content);

            serializedObject.ApplyModifiedProperties();

            if (this.duration.floatValue > 0)
            {
                EditorGUI.indentLevel += 1;

                content = new GUIContent
                          (
                    "Start Range",
                    "When duration is greater than 0 this can be used have the range change " +
                    "over the course of the duration. This is used for things like a " +
                    "chockwave from a large explosion, which grows over time. "
                          );
                content = EditorGUI.BeginProperty(new Rect(0, 0, 0, 0), content, this.startRange);

                EditorGUI.BeginChangeCheck();
                Vector3 startRange = this.startRange.vector3Value;
                switch ((AreaTargetTracker.AREA_SHAPES) this.areaShape.enumValueIndex)
                {
                case AreaTargetTracker.AREA_SHAPES.Circle2D:                  // Fallthrough
                case AreaTargetTracker.AREA_SHAPES.Sphere:
                    startRange.x = EditorGUILayout.FloatField(content, startRange.x);
                    startRange.y = startRange.x;
                    startRange.z = startRange.x;
                    break;

                case AreaTargetTracker.AREA_SHAPES.Box2D:
                    float oldZ = startRange.z;
                    startRange   = EditorGUILayout.Vector2Field(content.text, startRange);
                    startRange.z = oldZ;                      // Nice to maintain if switching between 2D and 3D
                    break;

                case AreaTargetTracker.AREA_SHAPES.Box:
                    startRange = EditorGUILayout.Vector3Field(content.text, startRange);
                    break;

                case AreaTargetTracker.AREA_SHAPES.Capsule:
                    startRange   = EditorGUILayout.Vector2Field(content.text, startRange);
                    startRange.z = startRange.x;
                    break;
                }

                // Only assign the value back if it was actually changed by the user.
                // Otherwise a single value will be assigned to all objects when multi-object
                // editing, even when the user didn't touch the control.
                if (EditorGUI.EndChangeCheck())
                {
                    this.startRange.vector3Value = startRange;
                }

                EditorGUI.EndProperty();

                EditorGUI.indentLevel -= 1;
            }


            this.displayRange <EventTrigger>(targetObjs);


            EditorGUI.BeginChangeCheck();
            content = new GUIContent
                      (
                "Position Offset",
                "An optional position offset for the Area. For example, if you have an" +
                "object resting on the ground which has a range of 4, a position offset of" +
                "Vector3(0, 4, 0) will place your Area so it is also sitting on the ground."
                      );
            EditorGUILayout.PropertyField(this.areaPositionOffset, content);

            // If changed, trigger the property setter for all objects being edited
            if (EditorGUI.EndChangeCheck())
            {
                string undo_message = targetObjs[0].GetType() + " areaPositionOffset";

                for (int i = 0; i < targetObjs.Length; i++)
                {
                    curEditTarget = (EventTrigger)targetObjs[i];

                    Undo.RecordObject(curEditTarget, undo_message);

                    curEditTarget.areaPositionOffset = this.areaPositionOffset.vector3Value;
                }
            }


            EditorGUI.BeginChangeCheck();
            content = new GUIContent
                      (
                "Rotation Offset",
                "An optional rotational offset for the Area."
                      );
            EditorGUILayout.PropertyField(this.areaRotationOffset, content);

            // If changed, trigger the property setter for all objects being edited
            if (EditorGUI.EndChangeCheck())
            {
                string undo_message = targetObjs[0].GetType() + " areaPositionOffset";
                for (int i = 0; i < targetObjs.Length; i++)
                {
                    curEditTarget = (EventTrigger)targetObjs[i];

                    Undo.RecordObject(curEditTarget, undo_message);

                    curEditTarget.areaRotationOffset = this.areaRotationOffset.vector3Value;
                }
            }

            GUILayout.Space(8);
        }
        else
        {
            this.overrideGizmoVisibility.boolValue = true;
        }

        content = new GUIContent
                  (
            "Notify Targets",
            "Sets the target notification behavior. Telling targets they are hit is optional " +
            "for situations where a delayed response is required, such as launching a , " +
            "projectile or for custom handling.\n" +
            "\n" +
            "MODES\n" +
            "    Off\n" +
            "        Do not notify anything. delegates can still be used\n" +
            "        for custom handling\n" +
            "    Direct\n" +
            "        OnFire targets will be notified immediately\n" +
            "    PassInfoToEventTrigger\n" +
            "        For every Target hit, a new EventTrigger will be\n" +
            "        spawned and passed this EventTrigger's \n" +
            "        EventInfo. PassToEventTriggerOnce is more \n" +
            "        commonly used when secondary EventTrigger is\n" +
            "        needed, but this can be used for some creative\n" +
            "        or edge use-cases.\n" +
            "    PassInfoToEventTriggerOnce\n" +
            "        OnFire a new EventTrigger will be spawned and\n" +
            "        passed this EventTrigger's EventInfo. Only 1 will\n" +
            "        be spawned. This is handy for making bombs \n" +
            "        where only the first Target would trigger the \n" +
            "        event and only 1 EventTrigger would be spawned\n" +
            "        to expand over time (using duration and start\n" +
            "        range attributes).\n" +
            "    UseEventTriggerInfo\n" +
            "        Same as PassInfoToEventTrigger but the new\n" +
            "        EventTrigger will use its own EventInfo (this \n" +
            "        EventTrigger's EventInfo will be ignored).\n" +
            "    UseEventTriggerInfoOnce\n" +
            "        Same as PassInfoToEventTriggerOnce but the new\n" +
            "        EventTrigger will will used its own EventInfo\n" +
            "        (this EventTrigger's EventInfo will be ignored)."
                  );
        EditorGUILayout.PropertyField(this.notifyTargets, content);

        //
        // If using EventTrigger...
        //
        EventTrigger.NOTIFY_TARGET_OPTIONS curOption;
        curOption = (EventTrigger.NOTIFY_TARGET_OPTIONS) this.notifyTargets.enumValueIndex;
        if (curOption > EventTrigger.NOTIFY_TARGET_OPTIONS.Direct)
        {
            EditorGUI.indentLevel += 1;

            content = new GUIContent
                      (
                "EventTrigger Prefab",
                "An optional prefab to instance another EventTrigger. This can be handy if you " +
                "want to use a 'one-shot' event trigger to then spawn one that expands over " +
                "time using the duration and startRange to simulate a huge explosion."

                      );

            EditorGUILayout.PropertyField(this.eventTriggerPrefab, content);

            if (InstanceManager.POOLING_ENABLED)
            {
                EditorGUI.indentLevel += 1;
                if (this.eventTriggerPrefab.objectReferenceValue != null)
                {
                    content = new GUIContent
                              (
                        "Use Pooling",
                        "If false, do not add the new instance to a pool. Use Unity's " +
                        "Instantiate/Destroy"
                              );

                    EditorGUILayout.PropertyField(this.usePooling, content);

                    if (this.usePooling.boolValue)
                    {
                        content = new GUIContent
                                  (
                            "Override Pool Name",
                            "If an eventTriggerPrefab is spawned, setting this to true will " +
                            "override the EventTrigger's poolName and use this instead. The " +
                            "instance will also be passed this EventTrigger's " +
                            "eventTriggerPoolName to be used when the EventTrigger is " +
                            "desapwned."
                                  );

                        EditorGUILayout.PropertyField(this.overridePoolName, content);

                        if (this.overridePoolName.boolValue)
                        {
                            content = new GUIContent
                                      (
                                "Pool Name",
                                "The name of a pool to be used with PoolManager or other " +
                                "pooling solution. If not using pooling, this will do " +
                                "nothing and be hidden in the Inspector.\n" +
                                "WARNING: If poolname is set to '', Pooling will be " +
                                "disabled and Unity's Instantiate will be used."
                                      );

                            EditorGUILayout.PropertyField(this.eventTriggerPoolName, content);
                        }
                    }

                    EditorGUI.indentLevel -= 1;
                }
                else
                {
                    this.overridePoolName.boolValue = false;                      // Reset
                }
            }

            EditorGUI.indentLevel -= 1;
        }

        if (curOption < EventTrigger.NOTIFY_TARGET_OPTIONS.UseEventTriggerInfo)
        {
            if (this.serializedObject.isEditingMultipleObjects)
            {
                content = new GUIContent
                          (
                    "Event Info List",
                    "A list of EventInfo structs which hold one or more event descriptions of how " +
                    "this EventTrigger can affect a Target."
                          );
                EditorGUILayout.PropertyField(this.eventInfoList, content, true);
            }
            else
            {
                EditorGUI.indentLevel += 2;

                curEditTarget        = (EventTrigger)targetObjs[0];
                this.expandEventInfo = PGEditorUtils.SerializedObjFoldOutList <EventInfoListGUIBacker>
                                       (
                    "Event Info List",
                    curEditTarget._eventInfoList,
                    this.expandEventInfo,
                    ref curEditTarget._editorListItemStates,
                    true
                                       );

                EditorGUI.indentLevel -= 2;
            }
        }

        GUILayout.Space(4);

        content = new GUIContent
                  (
            "Debug Level", "Set it higher to see more verbose information."
                  );
        EditorGUILayout.PropertyField(this.debugLevel, content);

        serializedObject.ApplyModifiedProperties();

        // Flag Unity to save the changes to to the prefab to disk
        //   This is needed to make the gizmos update immediatly.
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
コード例 #7
0
    // Use this for initialization
    public override void OnInspectorGUI()
    {
        FontAnalyse script = (FontAnalyse)target;

        EditorGUI.indentLevel = 0;
        PGEditorUtils.LookLikeControls();


        Rect sfxPathRect = EditorGUILayout.GetControlRect();

        // 用刚刚获取的文本输入框的位置和大小参数,创建一个文本输入框,用于输入特效路径
        EditorGUI.TextField(sfxPathRect, "ImgPath", script.ImgPath);
        // 判断当前鼠标正拖拽某对象或者在拖拽的过程中松开了鼠标按键
        // 同时还需要判断拖拽时鼠标所在位置处于文本输入框内
        if ((Event.current.type == EventType.DragUpdated ||
             Event.current.type == EventType.DragExited) &&
            sfxPathRect.Contains(Event.current.mousePosition))
        {
            // 判断是否拖拽了文件
            if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
            {
                string sfxPath = DragAndDrop.paths [0];
                // 拖拽的过程中,松开鼠标之后,拖拽操作结束,此时就可以使用获得的 sfxPath 变量了
                                #if UNITY_EDITOR_OSX
                if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragExited)
                {
                                #else
                if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragUpdated)
                {
                                #endif
                    DragAndDrop.AcceptDrag();

                    script.ImgPath = common.TextUtil.cut(sfxPath, "Resources/", false, false);
                }
            }
        }

        sfxPathRect = EditorGUILayout.GetControlRect();
        // 用刚刚获取的文本输入框的位置和大小参数,创建一个文本输入框,用于输入特效路径
        EditorGUI.TextField(sfxPathRect, "DataPath", script.DataPath);
        // 判断当前鼠标正拖拽某对象或者在拖拽的过程中松开了鼠标按键
        // 同时还需要判断拖拽时鼠标所在位置处于文本输入框内
        if ((Event.current.type == EventType.DragUpdated ||
             Event.current.type == EventType.DragExited) &&
            sfxPathRect.Contains(Event.current.mousePosition))
        {
            // 判断是否拖拽了文件
            if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0)
            {
                string sfxPath = DragAndDrop.paths [0];
                // 拖拽的过程中,松开鼠标之后,拖拽操作结束,此时就可以使用获得的 sfxPath 变量了
                                #if UNITY_EDITOR_OSX
                if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragExited)
                {
                                #else
                if (!string.IsNullOrEmpty(sfxPath) && Event.current.type == EventType.DragUpdated)
                {
                                #endif
                    DragAndDrop.AcceptDrag();

                    script.DataPath = common.TextUtil.cut(sfxPath, "Resources/", false, false);
                }
            }
        }

        script.advanceAddition = EditorGUILayout.IntField("advanceAddition", script.advanceAddition);
        script.pixelPerUnit    = EditorGUILayout.FloatField("pixelPerUnit", script.pixelPerUnit);
//
//		script.matchPoolScale = EditorGUILayout.Toggle("Match Pool Scale", script.matchPoolScale);
//		script.matchPoolLayer = EditorGUILayout.Toggle("Match Pool Layer", script.matchPoolLayer);
//
//		script.dontReparent = EditorGUILayout.Toggle("Don't Reparent", script.dontReparent);
//
//		script._dontDestroyOnLoad = EditorGUILayout.Toggle("Don't Destroy On Load", script._dontDestroyOnLoad);
//
//		script.logMessages = EditorGUILayout.Toggle("Log Messages", script.logMessages);
        EditorGUILayout.BeginHorizontal();           // 1/2 the item button width
        GUILayout.Space(0);

        // Master add at end button. List items will insert
        if (GUILayout.Button(new GUIContent("Generate", "Click to generate data"), EditorStyles.toolbarButton))
        {
            if (script.ImgPath != null && script.DataPath != null)
            {
                script.slice(script.ImgPath, script.DataPath);
                CharacterGroup[] groups = FindObjectsOfType <CharacterGroup>();
                for (int i = 0; i < groups.Length; i++)
                {
                    groups[i].setTextInEditor(false);
                }
            }
        }

        if (GUILayout.Button(new GUIContent("Clear", "Click to generate data"), EditorStyles.toolbarButton))
        {
            script.clear();
        }
        EditorGUILayout.EndHorizontal();

        this.expandPrefabs = PGEditorUtils.SerializedObjFoldOutList <FontData>
                             (
            "Per-Prefab Pool Options",
            script.fontDataList,
            this.expandPrefabs,
            ref script._editorListItemStates,
            true
                             );

        // Flag Unity to save the changes to to the prefab to disk
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }
}
コード例 #8
0
    public override void OnInspectorGUI()
    {
        var script = (Projectile)target;

        PGEditorUtils.LookLikeControls();
        GUIContent content;

        EditorGUI.indentLevel = 1;

        script.targetLayers = PGEditorUtils.LayerMaskField
                              (
            "Hit Layers",
            script.targetLayers
                              );

        script.detonationMode = PGEditorUtils.EnumPopup <Projectile.DETONATION_MODES>
                                (
            "Detonation Mode",
            script.detonationMode
                                );

        content = new GUIContent
                  (
            "Timer (0 = OFF)",
            "An optional timer (in seconds) to detonate this " +
            "projectile if it expires."
                  );
        script.timer = EditorGUILayout.FloatField(content, script.timer);

        content = new GUIContent
                  (
            "Detonate On Sleep",
            "If the projectile has a rigidbody, this will detonate it if it falls " +
            "asleep. See Unity's docs for more information on how this happens."
                  );
        script.detonateOnRigidBodySleep = EditorGUILayout.Toggle(content,
                                                                 script.detonateOnRigidBodySleep);

        content        = new GUIContent("Area Hit", "True to an area, not just a single target");
        script.areaHit = EditorGUILayout.Toggle(content, script.areaHit);

        if (script.areaHit)
        {
            EditorGUI.indentLevel  = 2;
            script.numberOfTargets = EditorGUILayout.IntField("Targets (-1 for all)", script.numberOfTargets);

            script.sortingStyle = PGEditorUtils.EnumPopup <TargetTracker.SORTING_STYLES>
                                  (
                "Sorting Style",
                script.sortingStyle
                                  );


            if (script.sortingStyle != TargetTracker.SORTING_STYLES.None)
            {
                EditorGUI.indentLevel = 3;
                script.sortInterval   = EditorGUILayout.FloatField("Min Interval", script.sortInterval);
                EditorGUI.indentLevel = 2;
            }

            script.perimeterLayer = EditorGUILayout.LayerField("Range Layer", script.perimeterLayer);

            EditorGUILayout.BeginHorizontal();

            // Only trigger the update if it actually changes. This runs code in a peroperty
            //   that may be expensive
            var shape = script.perimeterShape;
            shape = PGEditorUtils.EnumPopup <TargetTracker.PERIMETER_SHAPES>("Perimeter Shape", shape);
            if (shape != script.perimeterShape)
            {
                script.perimeterShape = shape;
            }

            script.overrideGizmoVisibility = false;

            GUILayout.Label("Gizmo", GUILayout.MaxWidth(40));
            script.drawGizmo = EditorGUILayout.Toggle(script.drawGizmo, GUILayout.MaxWidth(47));
            EditorGUILayout.EndHorizontal();

            if (script.drawGizmo)
            {
                EditorGUI.indentLevel = 3;
                EditorGUILayout.BeginHorizontal();

                script.gizmoColor = EditorGUILayout.ColorField("Gizmo Color", script.gizmoColor);

                GUIStyle style = EditorStyles.miniButton;
                style.alignment  = TextAnchor.MiddleCenter;
                style.fixedWidth = 52;

                bool clicked = GUILayout.Toggle(false, "Reset", style);
                if (clicked)
                {
                    script.gizmoColor = script.defaultGizmoColor;
                }

                EditorGUILayout.EndHorizontal();

                EditorGUI.indentLevel = 2;

                GUILayout.Space(4);
            }

            Vector3 range = script.range;
            switch (script.perimeterShape)
            {
            case TargetTracker.PERIMETER_SHAPES.Sphere:
                range.x = EditorGUILayout.FloatField("Range", range.x);
                range.y = range.x;
                range.z = range.x;
                break;

            case TargetTracker.PERIMETER_SHAPES.Box:
                range = EditorGUILayout.Vector3Field("Range", range);
                break;

            case TargetTracker.PERIMETER_SHAPES.Capsule:
                range   = EditorGUILayout.Vector2Field("Range", range);
                range.z = range.x;
                break;
            }
            script.range = range;


            //script.perimeterPositionOffset = EditorGUILayout.Vector3Field("Position Offset", script.perimeterPositionOffset);
            //script.perimeterRotationOffset = EditorGUILayout.Vector3Field("Rotation Offset", script.perimeterRotationOffset);
            GUILayout.Space(8);
        }
        else
        {
            script.overrideGizmoVisibility = true;
        }

        EditorGUI.indentLevel = 1;

        script.notifyTargets = PGEditorUtils.EnumPopup <Projectile.NOTIFY_TARGET_OPTIONS>
                               (
            "Notify Targets",
            script.notifyTargets
                               );

        script.detonationPrefab = PGEditorUtils.ObjectField <Transform>
                                  (
            "Spawn On Detonation",
            script.detonationPrefab
                                  );

        EditorGUI.indentLevel = 2;

        this.expandEffects = PGEditorUtils.SerializedObjFoldOutList <HitEffectGUIBacker>
                             (
            "EffectOnTargets   (May be inherited)",
            script._effectsOnTarget,
            this.expandEffects,
            ref script._editorListItemStates,
            true
                             );

        GUILayout.Space(4);
        script.debugLevel = (DEBUG_LEVELS)EditorGUILayout.EnumPopup("Debug Level", (System.Enum)script.debugLevel);


        // Flag Unity to save the changes to to the prefab to disk
        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
        }
    }