示例#1
0
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DTriggerRails = (ProCamera2DTriggerRails)target;

            if (proCamera2DTriggerRails.ProCamera2D != null && proCamera2DTriggerRails.ProCamera2DRails == null)
            {
                proCamera2DTriggerRails.ProCamera2DRails = proCamera2DTriggerRails.ProCamera2D.GetComponentInChildren <ProCamera2DRails>();
            }
        }
示例#3
0
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DNumericBoundaries)target);
        }
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DLimitDistance)target);
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DTriggerBoundaries = (ProCamera2DTriggerBoundaries)target;

            if (proCamera2DTriggerBoundaries.NumericBoundaries == null && proCamera2DTriggerBoundaries.ProCamera2D != null)
            {
                var numericBoundaries = proCamera2DTriggerBoundaries.ProCamera2D.GetComponent <ProCamera2DNumericBoundaries>();
                proCamera2DTriggerBoundaries.NumericBoundaries = numericBoundaries == null?proCamera2DTriggerBoundaries.ProCamera2D.gameObject.AddComponent <ProCamera2DNumericBoundaries>() : numericBoundaries;
            }

            _script = MonoScript.FromMonoBehaviour(proCamera2DTriggerBoundaries);
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DTriggerBoundaries = (ProCamera2DTriggerBoundaries)target;

            if (proCamera2DTriggerBoundaries.NumericBoundaries == null && proCamera2DTriggerBoundaries.ProCamera2D != null)
            {
                var numericBoundaries = proCamera2DTriggerBoundaries.ProCamera2D.GetComponent <ProCamera2DNumericBoundaries>();
                proCamera2DTriggerBoundaries.NumericBoundaries = numericBoundaries == null?proCamera2DTriggerBoundaries.ProCamera2D.gameObject.AddComponent <ProCamera2DNumericBoundaries>() : numericBoundaries;
            }

            if (proCamera2DTriggerBoundaries.PositionAndSizeOverrider == null && proCamera2DTriggerBoundaries.ProCamera2D != null)
            {
                var positionAndSizeOverrider = proCamera2DTriggerBoundaries.ProCamera2D.GetComponent <ProCamera2DPositionAndSizeOverrider>();
                proCamera2DTriggerBoundaries.PositionAndSizeOverrider = positionAndSizeOverrider == null?proCamera2DTriggerBoundaries.ProCamera2D.gameObject.AddComponent <ProCamera2DPositionAndSizeOverrider>() : positionAndSizeOverrider;

                proCamera2DTriggerBoundaries.PositionAndSizeOverrider.hideFlags = HideFlags.HideInInspector;
            }

            _script = MonoScript.FromMonoBehaviour(proCamera2DTriggerBoundaries);
        }
示例#7
0
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DCinematics)target);

            // Cinematic targets list
            _cinematicTargetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("CinematicTargets"), false, true, false, true);

            _cinematicTargetsList.drawElementCallback = (rect, index, isActive, isFocused) => {
                rect.y += 2;
                var element = _cinematicTargetsList.serializedProperty.GetArrayElementAtIndex(index);

                EditorGUI.PrefixLabel(new Rect(
                                          rect.x,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("Target", "The target transform"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 90,
                                            rect.y,
                                            90,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("TargetTransform"), GUIContent.none);

                EditorGUI.PrefixLabel(new Rect(
                                          rect.x + 200,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("EaseType", "The type of the movement the camera will do to reach this target"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 260,
                                            rect.y,
                                            rect.width - 260,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("EaseType"), GUIContent.none);

                rect.y += 25;
                EditorGUI.PrefixLabel(new Rect(
                                          rect.x,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("EaseInDuration", "The time it takes to reach this target"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 90,
                                            rect.y,
                                            30,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("EaseInDuration"), GUIContent.none);

                EditorGUI.PrefixLabel(new Rect(
                                          rect.x + 135,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("HoldDuration", "The time the camera follows this target. If below 0, you'll have to manually move to the next target by using the GoToNextTarget method."));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 215,
                                            rect.y,
                                            30,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("HoldDuration"), GUIContent.none);

                EditorGUI.PrefixLabel(new Rect(
                                          rect.x + 260,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("Zoom", "The zoom the camera will reach when focusing on this target"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 300,
                                            rect.y,
                                            rect.width - 300,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("Zoom"), GUIContent.none);

                rect.y += 25;
                EditorGUI.PrefixLabel(new Rect(
                                          rect.x,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("SendMessage Name", "The name of the SendMessage to be sent to the target once it arrives its position"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 115,
                                            rect.y,
                                            70,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("SendMessageName"), GUIContent.none);

                EditorGUI.PrefixLabel(new Rect(
                                          rect.x + 195,
                                          rect.y,
                                          90,
                                          10),
                                      new GUIContent("SendMessage Param", "The (optional) string parameter to send"));
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 310,
                                            rect.y,
                                            rect.width - 310,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("SendMessageParam"), GUIContent.none);
            };

            _cinematicTargetsList.drawHeaderCallback = (Rect rect) => {
                EditorGUI.LabelField(rect, "Cinematic Targets");
            };

            _cinematicTargetsList.elementHeight = 90;
            _cinematicTargetsList.draggable     = true;
        }
示例#8
0
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DTriggerInfluence)target);
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DRooms = (ProCamera2DRooms)target;

            // Add Numeric Boundaries component if needed
            var numericBoundaries = proCamera2DRooms.ProCamera2D.GetComponent <ProCamera2DNumericBoundaries>();

            if (numericBoundaries == null)
            {
                proCamera2DRooms.ProCamera2D.gameObject.AddComponent <ProCamera2DNumericBoundaries>();
            }

            // Create Vector conversion methods
            switch (proCamera2DRooms.ProCamera2D.Axis)
            {
            case MovementAxis.XY:
                Vector3H  = vector => vector.x;
                Vector3V  = vector => vector.y;
                VectorHVD = (h, v, d) => new Vector3(h, v, d);
                break;

            case MovementAxis.XZ:
                Vector3H  = vector => vector.x;
                Vector3V  = vector => vector.z;
                VectorHVD = (h, v, d) => new Vector3(h, d, v);
                break;

            case MovementAxis.YZ:
                Vector3H  = vector => vector.z;
                Vector3V  = vector => vector.y;
                VectorHVD = (h, v, d) => new Vector3(d, v, h);
                break;
            }

            // Script
            _script = MonoScript.FromMonoBehaviour(proCamera2DRooms);

            // Create rooms if non-existant
            if (proCamera2DRooms.Rooms.Count == 0)
            {
                proCamera2DRooms.Rooms.Add(new Room()
                {
                    Dimensions         = new Rect(0, 0, 10, 10),
                    TransitionDuration = 1f,
                    ZoomScale          = 1.5f
                });
            }

            // Rooms List
            _roomsList = new ReorderableList(serializedObject, serializedObject.FindProperty("Rooms"), false, true, true, true);

            _roomsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Rooms");
            };

            _roomsList.onSelectCallback = (list) =>
            {
                _currentlyEditingRoom = _roomsList.index;
                SceneView.RepaintAll();
            };

            _roomsList.onAddCallback = (list) =>
            {
                var index = list.serializedProperty.arraySize;
                list.serializedProperty.arraySize++;
                list.index = index;

                var newEntry = list.serializedProperty.GetArrayElementAtIndex(list.count - 1);
                if (list.count > 1)
                {
                    var prevRect = list.serializedProperty.GetArrayElementAtIndex(list.count - 2).FindPropertyRelative("Dimensions").rectValue;
                    prevRect.x += prevRect.width;
                    newEntry.FindPropertyRelative("Dimensions").rectValue = prevRect;
                }
                else if (list.count == 1)
                {
                    newEntry.FindPropertyRelative("Dimensions").rectValue          = new Rect(0, 0, 10, 10);
                    newEntry.FindPropertyRelative("TransitionDuration").floatValue = 1f;
                    newEntry.FindPropertyRelative("ZoomScale").floatValue          = 1.5f;
                }

                _currentlyEditingRoom = index;
            };

            _roomsList.onRemoveCallback = (list) =>
            {
                _currentlyEditingRoom = -1;
                SceneView.RepaintAll();
                ReorderableList.defaultBehaviours.DoRemoveButton(list);
            };

            _roomsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _roomsList.serializedProperty.GetArrayElementAtIndex(index);

                EditorGUI.DropShadowLabel(new Rect(rect.x, rect.y + 3, 60, 10), "Room " + index);
                rect.y += 20;

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("ID", "The room id"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("ID", "The room id"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 80,
                                            rect.y,
                                            100,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("ID"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y, 65, 10), new GUIContent("Rect", "The room size and position"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y, 65, 10), new GUIContent("Rect", "The room size and position"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 260,
                                            rect.y,
                                            rect.width - 260,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("Dimensions"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 45, 65, 10), new GUIContent("Ease Type", ""), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 45, 65, 10), new GUIContent("Ease Type", ""));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 80,
                                            rect.y + 45,
                                            100,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TransitionEaseType"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y + 45, 65, 10), new GUIContent("Duration", "How long it takes for the camera to reach this room"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y + 45, 65, 10), new GUIContent("Duration", "How long it takes for the camera to reach this room"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 260,
                                            rect.y + 45,
                                            rect.width - 260,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TransitionDuration"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 70, 65, 10), new GUIContent("Scale To Fit", "If checked, the camera will resize to fit the room"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 70, 65, 10), new GUIContent("Scale To Fit", "If checked, the camera will resize to fit the room"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 80,
                                            rect.y + 70,
                                            20,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("ScaleCameraToFit"), GUIContent.none);

                GUI.enabled = !element.FindPropertyRelative("ScaleCameraToFit").boolValue;
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 120, rect.y + 70, 65, 10), new GUIContent("Zoom", "If checked, the camera will zoom when entering the room"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 120, rect.y + 70, 65, 10), new GUIContent("Zoom", "If checked, the camera will zoom when entering the room"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 160,
                                            rect.y + 70,
                                            20,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("Zoom"), GUIContent.none);
                GUI.enabled = true;

                GUI.enabled = !element.FindPropertyRelative("ScaleCameraToFit").boolValue&& element.FindPropertyRelative("Zoom").boolValue;
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y + 70, 65, 10), new GUIContent("Scale", "The zoom scale"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 200, rect.y + 70, 65, 10), new GUIContent("Scale", "The zoom scale"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 260,
                                            rect.y + 70,
                                            rect.width - 260,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("ZoomScale"), GUIContent.none);
                GUI.enabled = true;
            };

            _roomsList.elementHeight = 130;
            _roomsList.draggable     = true;
        }
示例#10
0
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _proCamera2DParallax = (ProCamera2DParallax)target;

            _proCamera2D = _proCamera2DParallax.ProCamera2D;

            _script = MonoScript.FromMonoBehaviour(_proCamera2DParallax);

            // Parallax layers List
            _parallaxLayersList = new ReorderableList(serializedObject, serializedObject.FindProperty("ParallaxLayers"), false, true, true, true);

            // Draw element callback
            _parallaxLayersList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _parallaxLayersList.serializedProperty.GetArrayElementAtIndex(index);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Camera", "The parallax camera"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 65,
                                            rect.y,
                                            80,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("ParallaxCamera"), GUIContent.none);


                // Speed slider
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 170, rect.y, 65, 10), new GUIContent("Speed", "The relative speed at which the camera should move in comparison to the main camera."));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 210,
                                            rect.y,
                                            rect.width - 210,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("Speed"), GUIContent.none);


                // Layer mask
                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Culling Mask", "Which layers should this camera render?"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 85,
                                            rect.y + 25,
                                            rect.width - 85,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("LayerMask"), GUIContent.none);
            };

            // Draw header callback
            _parallaxLayersList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "Parallax layers");

            // Add element callback
            _parallaxLayersList.onAddCallback = list => AddParallaxLayer();

            // Remove element callback
            _parallaxLayersList.onRemoveCallback = list =>
            {
                if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete this layer?", "Yes", "No"))
                {
                    var cam = list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera;
                    if (cam != null)
                    {
                        DestroyImmediate(cam.gameObject);
                    }

                    ReorderableList.defaultBehaviours.DoRemoveButton(list);
                }
            };

            // Select element callback
            _parallaxLayersList.onSelectCallback = list =>
            {
                EditorGUIUtility.PingObject(list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("ParallaxCamera").objectReferenceValue as Camera);
            };

            _parallaxLayersList.elementHeight = 65;
            _parallaxLayersList.headerHeight  = 18;
            _parallaxLayersList.draggable     = true;
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DForwardFocus)target);
        }
示例#12
0
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DRails = (ProCamera2DRails)target;

            // Get nodes from play mode
            serializedObject.Update();

            #if UNITY_5_3_OR_NEWER
            if (_currentScene != UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name)
            {
                _playModeNodes.Clear();
            }

            _currentScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;
            #else
            if (_currentScene != EditorApplication.currentScene)
            {
                _playModeNodes.Clear();
            }

            _currentScene = EditorApplication.currentScene;
            #endif

            if (!Application.isPlaying && _playModeNodes.Count > 0)
            {
                var list = serializedObject.FindProperty("RailNodes");
                list.ClearArray();
                for (int i = 0; i < _playModeNodes.Count; i++)
                {
                    list.InsertArrayElementAtIndex(i);
                    var preset = list.GetArrayElementAtIndex(i);
                    preset.vector3Value = _playModeNodes[i];
                }
                _playModeNodes.Clear();
            }
            serializedObject.ApplyModifiedProperties();

            // Script
            _script = MonoScript.FromMonoBehaviour(proCamera2DRails);

            // Create Vector conversion methods
            switch (proCamera2DRails.ProCamera2D.Axis)
            {
            case MovementAxis.XY:
                Vector3H = vector => vector.x;
                Vector3V = vector => vector.y;
                VectorHV = (h, v) => new Vector3(h, v, 0);
                break;

            case MovementAxis.XZ:
                Vector3H = vector => vector.x;
                Vector3V = vector => vector.z;
                VectorHV = (h, v) => new Vector3(h, 0, v);
                break;

            case MovementAxis.YZ:
                Vector3H = vector => vector.z;
                Vector3V = vector => vector.y;
                VectorHV = (h, v) => new Vector3(0, v, h);
                break;
            }

            // Create nodes if non-existant
            if (proCamera2DRails.RailNodes.Count < 2)
            {
                proCamera2DRails.RailNodes.Add(VectorHV(1, 1));
                proCamera2DRails.RailNodes.Add(VectorHV(2, 2));
            }

            // Show correct axis name
            var hAxis = "";
            var vAxis = "";
            switch (proCamera2DRails.ProCamera2D.Axis)
            {
            case MovementAxis.XY:
                hAxis = "X";
                vAxis = "Y";
                break;

            case MovementAxis.XZ:
                hAxis = "X";
                vAxis = "Z";
                break;

            case MovementAxis.YZ:
                hAxis = "Y";
                vAxis = "Z";
                break;
            }

            // Targets List
            _targetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("CameraTargets"), false, false, true, true);

            _targetsList.onSelectCallback = (list) =>
            {
                EditorGUIUtility.PingObject(_targetsList.serializedProperty.GetArrayElementAtIndex(_targetsList.index).FindPropertyRelative("TargetTransform").objectReferenceValue);
            };

            _targetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _targetsList.serializedProperty.GetArrayElementAtIndex(index);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Transform", "The target transform"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y, 65, 10), new GUIContent("Transform", "The target transform"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 65,
                                            rect.y,
                                            80,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TargetTransform"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x + 160, rect.y, 65, 10), new GUIContent("Offset", "Offset the camera position relative to this target"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x + 160, rect.y, 65, 10), new GUIContent("Offset", "Offset the camera position relative to this target"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 200,
                                            rect.y,
                                            rect.width - 200,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TargetOffset"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Influence" + hAxis, "How much does this target horizontal position influences the camera position?"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 25, 65, 10), new GUIContent("Influence" + hAxis, "How much does this target horizontal position influences the camera position?"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 80,
                                            rect.y + 25,
                                            rect.width - 80,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TargetInfluenceH"), GUIContent.none);

                #if UNITY_5
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 40, 65, 10), new GUIContent("Influence" + vAxis, "How much does this target vertical position influences the camera position?"), EditorStyles.boldLabel);
                #else
                EditorGUI.PrefixLabel(new Rect(rect.x, rect.y + 40, 65, 10), new GUIContent("Influence" + vAxis, "How much does this target vertical position influences the camera position?"));
                #endif
                EditorGUI.PropertyField(new Rect(
                                            rect.x + 80,
                                            rect.y + 40,
                                            rect.width - 80,
                                            EditorGUIUtility.singleLineHeight),
                                        element.FindPropertyRelative("TargetInfluenceV"), GUIContent.none);
            };

            _targetsList.elementHeight = 80;
            _targetsList.headerHeight  = 0;
            _targetsList.draggable     = true;
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DShake = (ProCamera2DShake)target;

            _script = MonoScript.FromMonoBehaviour(proCamera2DShake);

            // Get presets from play mode
            serializedObject.Update();
            if (!Application.isPlaying && _playModePresets.Count > 0)
            {
                var list = serializedObject.FindProperty("ShakePresets");
                list.ClearArray();
                for (int i = 0; i < _playModePresets.Count; i++)
                {
                    list.InsertArrayElementAtIndex(i);
                    var preset = list.GetArrayElementAtIndex(i);
                    preset.FindPropertyRelative("Name").stringValue        = _playModePresets[i].Name;
                    preset.FindPropertyRelative("Strength").vector3Value   = _playModePresets[i].Strength;
                    preset.FindPropertyRelative("Duration").floatValue     = _playModePresets[i].Duration;
                    preset.FindPropertyRelative("Vibrato").intValue        = _playModePresets[i].Vibrato;
                    preset.FindPropertyRelative("Smoothness").floatValue   = _playModePresets[i].Smoothness;
                    preset.FindPropertyRelative("Randomness").floatValue   = _playModePresets[i].Randomness;
                    preset.FindPropertyRelative("InitialAngle").floatValue = _playModePresets[i].InitialAngle;
                    preset.FindPropertyRelative("Rotation").vector3Value   = _playModePresets[i].Rotation;
                }
                _playModePresets.Clear();
            }
            serializedObject.ApplyModifiedProperties();

            // Shake presets list
            _shakePresetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("ShakePresets"), false, true, false, true);

            _shakePresetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _shakePresetsList.serializedProperty.GetArrayElementAtIndex(index);

                EditorGUI.PropertyField(new Rect(
                                            rect.x,
                                            rect.y,
                                            rect.width / 3f,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("Name"), GUIContent.none);

                // Apply preset values to the editor
                if (GUI.Button(new Rect(
                                   rect.x + rect.width / 3f + 5,
                                   rect.y,
                                   rect.width / 3f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Apply"))
                {
                    proCamera2DShake.Strength     = element.FindPropertyRelative("Strength").vector3Value;
                    proCamera2DShake.Duration     = element.FindPropertyRelative("Duration").floatValue;
                    proCamera2DShake.Vibrato      = element.FindPropertyRelative("Vibrato").intValue;
                    proCamera2DShake.Smoothness   = element.FindPropertyRelative("Smoothness").floatValue;
                    proCamera2DShake.Randomness   = element.FindPropertyRelative("Randomness").floatValue;
                    proCamera2DShake.InitialAngle = element.FindPropertyRelative("InitialAngle").floatValue;
                    proCamera2DShake.Rotation     = element.FindPropertyRelative("Rotation").vector3Value;

                    proCamera2DShake.UseRandomInitialAngle = proCamera2DShake.InitialAngle < 0;

                    EditorUtility.SetDirty(target);
                }

                // Shake with the preset values
                GUI.enabled = Application.isPlaying;
                if (GUI.Button(new Rect(
                                   rect.x + 2 * rect.width / 3f + 5,
                                   rect.y,
                                   rect.width / 3f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Shake!"))
                {
                    proCamera2DShake.Shake(
                        element.FindPropertyRelative("Duration").floatValue,
                        element.FindPropertyRelative("Strength").vector3Value,
                        element.FindPropertyRelative("Vibrato").intValue,
                        element.FindPropertyRelative("Randomness").floatValue,
                        element.FindPropertyRelative("InitialAngle").floatValue,
                        element.FindPropertyRelative("Rotation").vector3Value,
                        element.FindPropertyRelative("Smoothness").floatValue
                        );
                }
                GUI.enabled = true;
            };

            _shakePresetsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Shake Presets");
            };

            _shakePresetsList.elementHeight = 30;
            _shakePresetsList.draggable     = true;
        }
 void OnEnable()
 {
     ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);
 }
示例#15
0
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DPanAndZoom)target);
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            _script = MonoScript.FromMonoBehaviour((ProCamera2DTransitionsFX)target);
        }
        void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DShake = (ProCamera2DShake)target;

            _script = MonoScript.FromMonoBehaviour(proCamera2DShake);

            //
            // ShakePresets list
            //
            _shakePresetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("ShakePresets"), true, true, true, true);

            _shakePresetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _shakePresetsList.serializedProperty.GetArrayElementAtIndex(index);

                if (element == null || element.objectReferenceValue == null)
                {
                    proCamera2DShake.ShakePresets.RemoveAt(index);
                    return;
                }

                // Name field
                EditorGUI.LabelField(
                    new Rect(
                        rect.x,
                        rect.y,
                        rect.width / 2f,
                        EditorGUIUtility.singleLineHeight * 1.1f),
                    ((ShakePreset)element.objectReferenceValue).name);

                // Edit button
                if (GUI.Button(new Rect(
                                   rect.x + 2 * rect.width / 4f + 5,
                                   rect.y - 2,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Edit"))
                {
                    Selection.activeObject = (ShakePreset)element.objectReferenceValue;
                }

                // Shake button
                GUI.enabled = Application.isPlaying;
                if (GUI.Button(new Rect(
                                   rect.x + 3 * rect.width / 4f + 5,
                                   rect.y - 2,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Shake!"))
                {
                    proCamera2DShake.Shake((ShakePreset)element.objectReferenceValue);
                }
                GUI.enabled = true;
            };

            _shakePresetsList.onAddCallback = (list) =>
            {
                _currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive) + 100;
                EditorGUIUtility.ShowObjectPicker <ShakePreset>(null, false, "", _currentPickerWindow);
            };

            _shakePresetsList.onSelectCallback = (list) =>
            {
                var element = _shakePresetsList.serializedProperty.GetArrayElementAtIndex(list.index);

                if (element != null)
                {
                    EditorGUIUtility.PingObject(element.objectReferenceValue);
                }
            };

            _shakePresetsList.onRemoveCallback = (list) =>
            {
                var element = _shakePresetsList.serializedProperty.GetArrayElementAtIndex(list.index);

                proCamera2DShake.ShakePresets.Remove((ShakePreset)element.objectReferenceValue);
            };

            _shakePresetsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Shake Presets");
            };


            //
            // ConstantShakePresets list
            //

            _constantShakePresetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("ConstantShakePresets"), true, true, true, true);

            _constantShakePresetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _constantShakePresetsList.serializedProperty.GetArrayElementAtIndex(index);

                if (element == null || element.objectReferenceValue == null)
                {
                    proCamera2DShake.ConstantShakePresets.RemoveAt(index);
                    return;
                }

                var preset = (ConstantShakePreset)element.objectReferenceValue;

                // Name field
                EditorGUI.LabelField(
                    new Rect(
                        rect.x,
                        rect.y,
                        rect.width / 2f,
                        EditorGUIUtility.singleLineHeight * 1.1f),
                    (preset).name);

                // Toggle to enable on start
                if (!Application.isPlaying)
                {
                    if (GUI.Toggle(new Rect(
                                       rect.x + 1 * rect.width / 4f + 5,
                                       rect.y - 2,
                                       rect.width / 4f - 5,
                                       EditorGUIUtility.singleLineHeight * 1.1f),
                                   proCamera2DShake.StartConstantShakePreset == preset,
                                   "Enable on Start"))
                    {
                        if (Event.current.type == EventType.Used && EditorApplication.timeSinceStartup - _toggleButtonClick > .5)
                        {
                            if (proCamera2DShake.StartConstantShakePreset == preset)
                            {
                                proCamera2DShake.StartConstantShakePreset = null;
                            }
                            else
                            {
                                proCamera2DShake.StartConstantShakePreset = preset;
                            }

                            _toggleButtonClick = EditorApplication.timeSinceStartup;
                        }
                    }
                }

                // Edit button
                if (GUI.Button(new Rect(
                                   rect.x + 2 * rect.width / 4f + 5,
                                   rect.y - 2,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Edit"))
                {
                    Selection.activeObject = preset;
                }

                // Shake button
                GUI.enabled = Application.isPlaying;
                if (GUI.Button(new Rect(
                                   rect.x + 3 * rect.width / 4f + 5,
                                   rect.y - 2,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), (proCamera2DShake.CurrentConstantShakePreset != null && proCamera2DShake.CurrentConstantShakePreset.GetInstanceID() == preset.GetInstanceID()) ? "Disable" : "Enable"))
                {
                    if (proCamera2DShake.CurrentConstantShakePreset == null || proCamera2DShake.CurrentConstantShakePreset.GetInstanceID() != preset.GetInstanceID())
                    {
                        proCamera2DShake.ConstantShake(preset);
                    }
                    else
                    {
                        proCamera2DShake.StopConstantShaking();
                    }
                }
                GUI.enabled = true;
            };

            _constantShakePresetsList.onAddCallback = (list) =>
            {
                _currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive) + 100;
                EditorGUIUtility.ShowObjectPicker <ConstantShakePreset>(null, false, "", _currentPickerWindow);
            };

            _constantShakePresetsList.onSelectCallback = (list) =>
            {
                var element = _constantShakePresetsList.serializedProperty.GetArrayElementAtIndex(list.index);

                if (element != null)
                {
                    EditorGUIUtility.PingObject(element.objectReferenceValue);
                }
            };

            _constantShakePresetsList.onRemoveCallback = (list) =>
            {
                var element = _constantShakePresetsList.serializedProperty.GetArrayElementAtIndex(list.index);

                proCamera2DShake.ConstantShakePresets.Remove((ConstantShakePreset)element.objectReferenceValue);
            };

            _constantShakePresetsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Constant Shake Presets");
            };
        }
        void OnEnable()
        {
            ProCamera2DEditorHelper.AssignProCamera2D(target as BasePC2D);

            var proCamera2DShake = (ProCamera2DShake)target;

            _script = MonoScript.FromMonoBehaviour(proCamera2DShake);

            // Get presets from play mode
            if (_playModePresets == null)
            {
                _playModePresets = new List <ShakePreset>();
            }

            serializedObject.Update();

            #if UNITY_5_3_OR_NEWER
            if (_currentScene != UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name)
            {
                _playModePresets.Clear();
            }

            _currentScene = UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name;
            #else
            if (_currentScene != EditorApplication.currentScene)
            {
                _playModePresets.Clear();
            }

            _currentScene = EditorApplication.currentScene;
            #endif

            if (!Application.isPlaying && _playModePresets.Count > 0)
            {
                var list = serializedObject.FindProperty("ShakePresets");
                list.ClearArray();
                for (int i = 0; i < _playModePresets.Count; i++)
                {
                    list.InsertArrayElementAtIndex(i);
                    var preset = list.GetArrayElementAtIndex(i);
                    preset.FindPropertyRelative("Name").stringValue          = _playModePresets[i].Name;
                    preset.FindPropertyRelative("Strength").vector3Value     = _playModePresets[i].Strength;
                    preset.FindPropertyRelative("Duration").floatValue       = _playModePresets[i].Duration;
                    preset.FindPropertyRelative("Vibrato").intValue          = _playModePresets[i].Vibrato;
                    preset.FindPropertyRelative("Smoothness").floatValue     = _playModePresets[i].Smoothness;
                    preset.FindPropertyRelative("Randomness").floatValue     = _playModePresets[i].Randomness;
                    preset.FindPropertyRelative("InitialAngle").floatValue   = _playModePresets[i].InitialAngle;
                    preset.FindPropertyRelative("Rotation").vector3Value     = _playModePresets[i].Rotation;
                    preset.FindPropertyRelative("IgnoreTimeScale").boolValue = _playModePresets[i].IgnoreTimeScale;
                }
                _playModePresets.Clear();
            }
            serializedObject.ApplyModifiedProperties();

            // Shake presets list
            _shakePresetsList = new ReorderableList(serializedObject, serializedObject.FindProperty("ShakePresets"), false, true, false, true);

            _shakePresetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
            {
                rect.y += 2;
                var element = _shakePresetsList.serializedProperty.GetArrayElementAtIndex(index);

                // Name field
                EditorGUI.PropertyField(new Rect(
                                            rect.x,
                                            rect.y,
                                            rect.width / 4f,
                                            EditorGUIUtility.singleLineHeight * 1.1f),
                                        element.FindPropertyRelative("Name"), GUIContent.none);

                // Load button
                if (GUI.Button(new Rect(
                                   rect.x + rect.width / 4f + 5,
                                   rect.y,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Load"))
                {
                    proCamera2DShake.Strength        = element.FindPropertyRelative("Strength").vector3Value;
                    proCamera2DShake.Duration        = element.FindPropertyRelative("Duration").floatValue;
                    proCamera2DShake.Vibrato         = element.FindPropertyRelative("Vibrato").intValue;
                    proCamera2DShake.Smoothness      = element.FindPropertyRelative("Smoothness").floatValue;
                    proCamera2DShake.Randomness      = element.FindPropertyRelative("Randomness").floatValue;
                    proCamera2DShake.InitialAngle    = element.FindPropertyRelative("InitialAngle").floatValue;
                    proCamera2DShake.Rotation        = element.FindPropertyRelative("Rotation").vector3Value;
                    proCamera2DShake.IgnoreTimeScale = element.FindPropertyRelative("IgnoreTimeScale").boolValue;

                    proCamera2DShake.UseRandomInitialAngle = proCamera2DShake.InitialAngle < 0;

                    EditorUtility.SetDirty(target);
                }

                // Save button
                if (GUI.Button(new Rect(
                                   rect.x + 2 * rect.width / 4f + 5,
                                   rect.y,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Save"))
                {
                    element.FindPropertyRelative("Strength").vector3Value     = proCamera2DShake.Strength;
                    element.FindPropertyRelative("Duration").floatValue       = proCamera2DShake.Duration;
                    element.FindPropertyRelative("Vibrato").intValue          = proCamera2DShake.Vibrato;
                    element.FindPropertyRelative("Smoothness").floatValue     = proCamera2DShake.Smoothness;
                    element.FindPropertyRelative("Randomness").floatValue     = proCamera2DShake.Randomness;
                    element.FindPropertyRelative("InitialAngle").floatValue   = proCamera2DShake.InitialAngle;
                    element.FindPropertyRelative("Rotation").vector3Value     = proCamera2DShake.Rotation;
                    element.FindPropertyRelative("IgnoreTimeScale").boolValue = proCamera2DShake.IgnoreTimeScale;

                    proCamera2DShake.UseRandomInitialAngle = proCamera2DShake.InitialAngle < 0;

                    EditorUtility.SetDirty(target);

                    Repaint();
                }

                // Shake button
                GUI.enabled = Application.isPlaying;
                if (GUI.Button(new Rect(
                                   rect.x + 3 * rect.width / 4f + 5,
                                   rect.y,
                                   rect.width / 4f - 5,
                                   EditorGUIUtility.singleLineHeight * 1.1f), "Shake!"))
                {
                    proCamera2DShake.Shake(
                        element.FindPropertyRelative("Duration").floatValue,
                        element.FindPropertyRelative("Strength").vector3Value,
                        element.FindPropertyRelative("Vibrato").intValue,
                        element.FindPropertyRelative("Randomness").floatValue,
                        element.FindPropertyRelative("InitialAngle").floatValue,
                        element.FindPropertyRelative("Rotation").vector3Value,
                        element.FindPropertyRelative("Smoothness").floatValue,
                        element.FindPropertyRelative("IgnoreTimeScale").boolValue
                        );
                }
                GUI.enabled = true;
            };

            _shakePresetsList.drawHeaderCallback = (Rect rect) =>
            {
                EditorGUI.LabelField(rect, "Shake Presets");
            };

            _shakePresetsList.elementHeight = 30;
            _shakePresetsList.draggable     = true;
        }