-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added editor scripts rather than in main script updated package
- Loading branch information
Brogan
committed
Jul 31, 2018
1 parent
6f6024b
commit d0138d9
Showing
19 changed files
with
1,501 additions
and
1,368 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 2 additions & 3 deletions
5
Assets/ScreenSwipe.unitypackage.meta → Assets/ScreenSwipe/Editor.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
public class ScreenSwipeCustomMenu : MonoBehaviour | ||
{ | ||
private static void AddToUndo(GameObject go, MenuCommand menuCommand) | ||
{ | ||
// Ensure it gets reparented if this was a context click (otherwise does nothing) | ||
GameObjectUtility.SetParentAndAlign(go, (GameObject)menuCommand.context); | ||
|
||
// Register the creation in the undo system | ||
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name); | ||
Selection.activeObject = go; | ||
} | ||
|
||
private static GameObject CreateUIObject(string name, GameObject parent) | ||
{ | ||
GameObject go = new GameObject(name); | ||
go.AddComponent<RectTransform>(); | ||
GameObjectUtility.SetParentAndAlign(go, parent); | ||
return go; | ||
} | ||
|
||
[MenuItem("GameObject/UI/Screen Swipe/Screen Swipe", false, 10)] | ||
private static void AddScreenSwipe(MenuCommand menuCommand) | ||
{ | ||
Canvas canvas = FindObjectOfType<Canvas>(); | ||
|
||
GameObject go = CreateUIObject("Screen Swipe", canvas.gameObject); | ||
|
||
var rect = go.transform as RectTransform; | ||
rect.pivot = new Vector2(0.5f, 0.5f); | ||
rect.anchorMax = new Vector2(); | ||
rect.anchorMin = new Vector2(); | ||
|
||
|
||
// content | ||
GameObject content = CreateUIObject("Content", go); | ||
|
||
// first page | ||
GameObject firstPage = CreateUIObject("Page_01", content); | ||
firstPage.transform.SetParent(content.transform); | ||
firstPage.AddComponent<Image>(); | ||
|
||
// first page text | ||
GameObject fistPageText = CreateUIObject("Text", firstPage); | ||
fistPageText.transform.SetParent(firstPage.transform); | ||
var text = fistPageText.AddComponent<Text>(); | ||
text.text = "Page_01"; | ||
|
||
// screen swipe | ||
var screenSwipe = go.AddComponent<ScreenSwipe>(); | ||
screenSwipe.Content = content.transform as RectTransform; | ||
|
||
// add to undo | ||
AddToUndo(go, menuCommand); | ||
} | ||
|
||
[MenuItem("GameObject/UI/Screen Swipe/Pagination", false, 10)] | ||
private static void AddPagination(MenuCommand menuCommand) | ||
{ | ||
Canvas canvas = FindObjectOfType<Canvas>(); | ||
|
||
GameObject go = CreateUIObject("Pagination", canvas.gameObject); | ||
go.AddComponent<ToggleGroup>(); | ||
|
||
// layout | ||
var layout = go.AddComponent<HorizontalLayoutGroup>(); | ||
layout.spacing = 10; | ||
layout.childAlignment = TextAnchor.MiddleCenter; | ||
|
||
// content size fitter | ||
var sizeFitter = go.AddComponent<ContentSizeFitter>(); | ||
sizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; | ||
|
||
for (int i = 0; i < 3; i++) | ||
{ | ||
// toggle | ||
GameObject firstToggle = CreateUIObject("Toggle_" + i, go); | ||
var toggle = firstToggle.AddComponent<Toggle>(); | ||
|
||
// toggle background | ||
GameObject toggleBackGround = CreateUIObject("Background", firstToggle); | ||
var bgImage = toggleBackGround.AddComponent<Image>(); | ||
bgImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Background.psd"); | ||
bgImage.type = Image.Type.Sliced; | ||
|
||
// check mark | ||
GameObject toggleCheckmark = CreateUIObject("Checkmark", toggleBackGround); | ||
var checkmark = toggleCheckmark.AddComponent<Image>(); | ||
checkmark.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Checkmark.psd"); | ||
checkmark.type = Image.Type.Simple; | ||
|
||
// set toggle component | ||
toggle.targetGraphic = bgImage; | ||
toggle.graphic = checkmark; | ||
} | ||
|
||
AddToUndo(go, menuCommand); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
[CustomEditor(typeof(ScreenSwipe))] | ||
public class ScreenSwipeEditor : Editor | ||
{ | ||
// editing | ||
SerializedProperty _editingScreen; | ||
|
||
//swipe | ||
SerializedProperty _swipeType; | ||
SerializedProperty _swipeTime; | ||
SerializedProperty _swipeVelocityThreshold; | ||
SerializedProperty _skipScreen; | ||
SerializedProperty _skipScreenVelocityThreshold; | ||
|
||
// content | ||
SerializedProperty _maskContent; | ||
SerializedProperty _content; | ||
SerializedProperty _spacing; | ||
SerializedProperty _pagination; | ||
SerializedProperty _currentScreen; | ||
SerializedProperty _startingScreen; | ||
SerializedProperty _screens; | ||
|
||
// screen change events | ||
SerializedProperty _pollForScreenOrientationChange; | ||
SerializedProperty _editorRefreshKey; | ||
|
||
// controlls | ||
SerializedProperty _isInteractable; | ||
SerializedProperty _nextButton; | ||
SerializedProperty _previousButton; | ||
SerializedProperty _disableButtonsAtEnds; | ||
|
||
// tween | ||
SerializedProperty _tweenTime; | ||
SerializedProperty _easeType; | ||
|
||
// events | ||
SerializedProperty _onScreenDrag; | ||
SerializedProperty _onScreenChanged; | ||
SerializedProperty _onScreenTweenEnd; | ||
|
||
private void OnEnable() | ||
{ | ||
// editing | ||
_editingScreen = serializedObject.FindProperty("editingScreen"); | ||
|
||
// swipe | ||
_swipeType = serializedObject.FindProperty("swipeType"); | ||
_swipeTime = serializedObject.FindProperty("swipeTime"); | ||
_swipeVelocityThreshold = serializedObject.FindProperty("swipeVelocityThreshold"); | ||
_skipScreen = serializedObject.FindProperty("skipScreen"); | ||
_skipScreenVelocityThreshold = serializedObject.FindProperty("skipScreenVelocityThreshold"); | ||
|
||
// content | ||
_maskContent = serializedObject.FindProperty("maskContent"); | ||
_content = serializedObject.FindProperty("content"); | ||
_spacing = serializedObject.FindProperty("spacing"); | ||
_pagination = serializedObject.FindProperty("pagination"); | ||
_currentScreen = serializedObject.FindProperty("currentScreen"); | ||
_startingScreen = serializedObject.FindProperty("startingScreen"); | ||
_screens = serializedObject.FindProperty("screens"); | ||
|
||
// screen change | ||
_pollForScreenOrientationChange = serializedObject.FindProperty("pollForScreenOrientationChange"); | ||
_editorRefreshKey = serializedObject.FindProperty("editorRefreshKey"); | ||
|
||
// controlls | ||
_isInteractable = serializedObject.FindProperty("isInteractable"); | ||
_nextButton = serializedObject.FindProperty("nextButton"); | ||
_previousButton = serializedObject.FindProperty("previousButton"); | ||
_disableButtonsAtEnds = serializedObject.FindProperty("disableButtonsAtEnds"); | ||
|
||
// tween | ||
_tweenTime = serializedObject.FindProperty("tweenTime"); | ||
_easeType = serializedObject.FindProperty("easeType"); | ||
|
||
// events | ||
_onScreenDrag = serializedObject.FindProperty("onScreenDragBegin"); | ||
_onScreenChanged = serializedObject.FindProperty("onScreenChanged"); | ||
_onScreenTweenEnd = serializedObject.FindProperty("onScreenTweenEnd"); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
serializedObject.Update(); | ||
|
||
var _target = (ScreenSwipe)target; | ||
|
||
// editing | ||
EditorGUILayout.PropertyField(_editingScreen); | ||
if (GUILayout.Button("GoToScreen")) | ||
_target.EditingScreen(); | ||
|
||
//swipe | ||
EditorGUILayout.PropertyField(_swipeType); | ||
EditorGUILayout.PropertyField(_swipeTime); | ||
EditorGUILayout.PropertyField(_swipeVelocityThreshold); | ||
EditorGUILayout.PropertyField(_skipScreen); | ||
if (_skipScreen.boolValue) | ||
EditorGUILayout.PropertyField(_skipScreenVelocityThreshold); | ||
|
||
// contents | ||
EditorGUILayout.PropertyField(_maskContent); | ||
EditorGUILayout.PropertyField(_content); | ||
EditorGUILayout.PropertyField(_spacing); | ||
EditorGUILayout.PropertyField(_pagination); | ||
EditorGUILayout.PropertyField(_currentScreen); | ||
EditorGUILayout.PropertyField(_startingScreen); | ||
EditorGUILayout.PropertyField(_screens, true); | ||
|
||
//screen | ||
EditorGUILayout.PropertyField(_pollForScreenOrientationChange); | ||
if (_target.pollForScreenOrientationChange) | ||
EditorGUILayout.PropertyField(_editorRefreshKey); | ||
|
||
// controlls | ||
EditorGUILayout.PropertyField(_isInteractable); | ||
EditorGUILayout.PropertyField(_nextButton); | ||
EditorGUILayout.PropertyField(_previousButton); | ||
if (_target.NextButton != null || _target.PreviousButton != null) | ||
EditorGUILayout.PropertyField(_disableButtonsAtEnds); | ||
|
||
// tween | ||
EditorGUILayout.PropertyField(_tweenTime); | ||
EditorGUILayout.PropertyField(_easeType); | ||
|
||
//events | ||
EditorGUILayout.PropertyField(_onScreenDrag); | ||
EditorGUILayout.PropertyField(_onScreenChanged); | ||
EditorGUILayout.PropertyField(_onScreenTweenEnd); | ||
|
||
serializedObject.ApplyModifiedProperties(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.