Skip to content

Commit

Permalink
updated project to 2018.2
Browse files Browse the repository at this point in the history
added editor scripts rather than in main script

updated package
  • Loading branch information
Brogan committed Jul 31, 2018
1 parent 6f6024b commit d0138d9
Show file tree
Hide file tree
Showing 19 changed files with 1,501 additions and 1,368 deletions.
Binary file removed Assets/ScreenSwipe.unitypackage
Binary file not shown.
574 changes: 308 additions & 266 deletions Assets/ScreenSwipe/Demo.unity

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 102 additions & 0 deletions Assets/ScreenSwipe/Editor/ScreenSwipeCustomMenu.cs
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);
}
}
11 changes: 11 additions & 0 deletions Assets/ScreenSwipe/Editor/ScreenSwipeCustomMenu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions Assets/ScreenSwipe/Editor/ScreenSwipeEditor.cs
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();
}
}
11 changes: 11 additions & 0 deletions Assets/ScreenSwipe/Editor/ScreenSwipeEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/ScreenSwipe/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Neither the name of the author nor the names of contributors may be used to endo
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// to stop obsolete warnings
#pragma warning disable 0618

#region Namespaces
using System;
using System.Collections;
Expand Down
File renamed without changes.
Loading

0 comments on commit d0138d9

Please sign in to comment.