void OnEnable() { var proCamera2D = (ProCamera2D)target; if (proCamera2D.GameCamera == null) proCamera2D.GameCamera = proCamera2D.GetComponent<Camera>(); #if PC2D_TK2D_SUPPORT if (proCamera2D.Tk2dCam == null) proCamera2D.Tk2dCam = proCamera2D.GetComponent<tk2dCamera>(); #endif // Show correct axis name switch (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; // Review message if (EditorPrefs.GetInt("ProCamera2DReview", 0) >= 0) EditorPrefs.SetInt("ProCamera2DReview", EditorPrefs.GetInt("ProCamera2DReview", 0) + 1); if (EditorPrefs.GetInt("ProCamera2DReview", 0) >= 100) _showReviewMessage = true; // Get extensions and triggers to show on the list _extensions = new List<PC2DEditorExtension>(); _triggers = new List<PC2DEditorTrigger>(); MonoScript[] scripts = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); foreach (MonoScript m in scripts) { var scriptClass = m.GetClass(); if (scriptClass != null && scriptClass.IsSubclassOf(typeof(BasePC2D))) { var extensionName = scriptClass.GetField("ExtensionName"); if (extensionName != null) { var ext = new PC2DEditorExtension() { ExtName = extensionName.GetValue(null) as string, ExtType = scriptClass }; _extensions.Add(ext); } var triggerName = scriptClass.GetField("TriggerName"); if (triggerName != null) { var trig = new PC2DEditorTrigger() { TriggerName = triggerName.GetValue(null) as string, TriggerType = scriptClass, AllTriggers = FindObjectsOfType(scriptClass).ToList(), TriggerCurrentIndex = 0 }; _triggers.Add(trig); } } } _extensions = _extensions.OrderBy(s => s.ExtName).ToList(); _triggers = _triggers.OrderBy(s => s.TriggerName).ToList(); }
void OnEnable() { var proCamera2D = (ProCamera2D)target; if (proCamera2D.GameCamera == null) { proCamera2D.GameCamera = proCamera2D.GetComponent <Camera>(); } #if PC2D_TK2D_SUPPORT if (proCamera2D.Tk2dCam == null) { proCamera2D.Tk2dCam = proCamera2D.GetComponent <tk2dCamera>(); } #endif // Show correct axis name switch (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; // Review message if (EditorPrefs.GetInt("ProCamera2DReview", 0) >= 0) { EditorPrefs.SetInt("ProCamera2DReview", EditorPrefs.GetInt("ProCamera2DReview", 0) + 1); } if (EditorPrefs.GetInt("ProCamera2DReview", 0) >= 100) { _showReviewMessage = true; } // Get extensions and triggers to show on the list _extensions = new List <PC2DEditorExtension>(); _triggers = new List <PC2DEditorTrigger>(); MonoScript[] scripts = (MonoScript[])Resources.FindObjectsOfTypeAll(typeof(MonoScript)); foreach (MonoScript m in scripts) { var scriptClass = m.GetClass(); if (scriptClass != null && scriptClass.IsSubclassOf(typeof(BasePC2D))) { var extensionName = scriptClass.GetField("ExtensionName"); if (extensionName != null) { var ext = new PC2DEditorExtension() { ExtName = extensionName.GetValue(null) as string, ExtType = scriptClass, Component = proCamera2D.GetComponent(scriptClass) as BasePC2D }; _extensions.Add(ext); } var triggerName = scriptClass.GetField("TriggerName"); if (triggerName != null) { var trig = new PC2DEditorTrigger() { TriggerName = triggerName.GetValue(null) as string, TriggerType = scriptClass, AllTriggers = FindObjectsOfType(scriptClass).ToList(), TriggerCurrentIndex = 0 }; _triggers.Add(trig); } } } _extensions = _extensions.OrderBy(s => s.ExtName).ToList(); _triggers = _triggers.OrderBy(s => s.TriggerName).ToList(); }