Skip to content

Commit

Permalink
Merging to master for v0.4 release
Browse files Browse the repository at this point in the history
  • Loading branch information
areyoutoo committed Mar 4, 2015
2 parents d690759 + e96b4a8 commit db1f571
Show file tree
Hide file tree
Showing 42 changed files with 620 additions and 1,246 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
*.userprefs

# Ignore project settings folder (for now)
Project/ProjectSettings
Project/ProjectSettings
*.meta
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Changelog for ChicoPlugins
====

v0.4 (March 3, 2015)
----

* New: "Movers" module. Quick components to make objects spin, bounce, or face targets.
* New: "MouseManager" class. Helpful for tracking simple mouse and touch input over multiple frames.
* Changed: ComponentPool names are now read directly from scene hierarchy.
* Removed: CUI module.
* Improved documentation for several classes.


v0.3 (October 15, 2014)
----

Expand Down
1 change: 1 addition & 0 deletions Project/Assets/Plugins/ChicoPlugins/Audio/MusicLooper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// <remarks>
/// Still calls onMusicFinished() after re-starting the music.
/// </remarks>
[AddComponentMenu("ChicoPlugins/Music/Looper")]
public class MusicLooper : MusicPlayer {
protected override void MusicFinished() {
music.Play();
Expand Down
9 changes: 6 additions & 3 deletions Project/Assets/Plugins/ChicoPlugins/Audio/MusicPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using UnityEngine;
using System.Collections;

[AddComponentMenu("ChicoPlugins/Music/Player")]
public class MusicPlayer : MonoBehaviour {
public AudioSource music;

Expand Down Expand Up @@ -28,7 +29,8 @@ protected void Awake() {
return;
}
}


baseVolume = music.volume;
ConfigureSource(music);

float configMulti = GetConfigVolumeMulti();
Expand All @@ -53,8 +55,7 @@ protected void Update() {
/// Desired music volume; will be modified according to baseVolume.
/// </param>
public void SetVolumeMulti(float volume) {
volume /= baseVolume;
ApplyVolumeMulti(volume);
ApplyVolumeMulti(volume * baseVolume);
}

/// <summary>
Expand Down Expand Up @@ -95,6 +96,8 @@ protected virtual void OnUpdate() {}
/// Configure an AudioSource for use with music. Maybe also useful for UI?
/// </summary>
public static void ConfigureSource(AudioSource source) {
if (source == null) return;

source.ignoreListenerPause = true;
source.ignoreListenerVolume = true;
source.bypassEffects = true;
Expand Down
2 changes: 1 addition & 1 deletion Project/Assets/Plugins/ChicoPlugins/Bags/RandomBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;

/// <summary>
/// Bag returns items in random order.
/// Bag returns items at random, like a fair dice roll.
/// </summary>
public class RandomBag<T> : SimpleBag<T> {
protected List<T> members;
Expand Down
6 changes: 4 additions & 2 deletions Project/Assets/Plugins/ChicoPlugins/Bags/ShuffleBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System.Collections.Generic;

/// <summary>
/// Bag returns item in random order. Will not repeat until bag is "emptied" and "refilled".
///
/// Bag returns items at random, like a deck of cards.
/// </summary>
/// <remarks>
/// Note that the big will automatically refill itself once emptied.
/// </remarks>
public class ShuffleBag<T> : RandomBag<T> {
/// <summary>
/// An internal list, used by Refill().
Expand Down
2 changes: 1 addition & 1 deletion Project/Assets/Plugins/ChicoPlugins/Bags/WeightedBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;

/// <summary>
/// Bag returns item with weighted randomness. Items are NOT removed.
/// Bag returns items at random with weights, like a biased dice roll.
/// </summary>
public class WeightedBag<T> : AbstractBag<T> {
const float DEFAULT_WEIGHT = 1f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ public static class TransformExtensions {
/// <summary>
/// Gets all direct children.
/// </summary>
/// <returns>
/// The children.
/// </returns>
/// <param name='root'>
/// Root.
/// </param>
public static Transform[] GetChildren(this Transform root) {
Transform[] children = new Transform[root.childCount];
int i=0;
Expand All @@ -21,6 +27,9 @@ public static Transform[] GetChildren(this Transform root) {
/// <summary>
/// Attaches a list of transforms to this one.
/// </summary>
/// <param name='root'>
/// Parent transform.
/// </param>
/// <param name='children'>
/// Array, list, or other collection of transforms to add.
/// </param>
Expand All @@ -30,16 +39,16 @@ public static void AttachChildren(this Transform root, IEnumerable<Transform> ch
}
}

/// <summary>
/// Attach one transform to this one.
/// </summary>
public static void AttachChild(this Transform root, Transform child) {
child.parent = root;
}

/// <summary>
/// Clears the position of this transform without affecting its children.
/// </summary>
/// <param name='root'>
/// Root.
/// </param>
public static void ClearLocalPosition(this Transform root) {
var children = root.GetChildren();
root.DetachChildren();
Expand All @@ -50,6 +59,9 @@ public static void ClearLocalPosition(this Transform root) {
/// <summary>
/// Clears rotation of this transform without affecting its children.
/// </summary>
/// <param name='root'>
/// Root.
/// </param>
public static void ClearLocalRotation(this Transform root) {
var children = root.GetChildren();
root.DetachChildren();
Expand All @@ -60,23 +72,20 @@ public static void ClearLocalRotation(this Transform root) {
/// <summary>
/// Clears scale of this transform without affecting children.
/// </summary>
/// <param name='root'>
/// Root.
/// </param>
public static void ClearLocalScale(this Transform root) {
var children = root.GetChildren();
root.DetachChildren();
root.localScale = Vector3.one;
root.AttachChildren(children);
}

/// <summary>
/// Multiplies this transform's localScale.
/// </summary>
public static void MultiplyScale(this Transform root, float multiplier) {
root.transform.localScale = root.transform.localScale * multiplier;
}

/// <summary>
/// Multiplies this transform's localScale component-wise with another Vector3.
/// </summary>
public static void MultiplyScale(this Transform root, Vector3 multiplier) {
root.transform.localScale = root.transform.localScale.WithScale(multiplier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,22 @@
/// Extension methods for Unity's Vector2 class.
/// </summary>
public static class Vector2Extensions {
/// <summary>
/// Creates a Vector3 with matching (x,y), requested (z).
/// </summary>
public static Vector3 ToVector3(this Vector2 v, float z) {
return new Vector3(v.x, v.y, z);
}

/// <summary>
/// Copies this vector, overrides the copy's X.
/// </summary>
public static Vector3 WithX(this Vector2 v, float x) {
return new Vector2(x, v.y);
}

/// <summary>
/// Copies this vector, overrides the copy's Y.
/// </summary>
public static Vector3 WithY(this Vector2 v, float y) {
return new Vector2(v.x, y);
}

/// <summary>
/// Copies this vector, overrides the copy's length.
/// </summary>
public static Vector2 WithLength(this Vector2 v, float length) {
return v.normalized * length;
}

/// <summary>
/// Copies this vector, multiplies the copy component-wise with another vector.
/// </summary>
/// <remarks>
/// There is no float/int override because that's just scalar multiplication. ;)
/// </remarks>
public static Vector2 WithScale(this Vector2 v, Vector2 scale) {
return Vector2.Scale(v, scale);
}
Expand Down
48 changes: 27 additions & 21 deletions Project/Assets/Plugins/ChicoPlugins/Extensions/Vector3Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,53 @@
/// Extension methods for Unity's Vector3 class.
/// </summary>
public static class Vector3Extensions {
/// <summary>
/// Copies this vector, overrides the copy's X.
/// </summary>
public static Vector3 WithX(this Vector3 v, float x) {
return new Vector3(x, v.y, v.z);
}

/// <summary>
/// Copies this vector, overrides the copy's Y.
/// </summary>
public static Vector3 WithY(this Vector3 v, float y) {
return new Vector3(v.x, y, v.z);
}

/// <summary>
/// Copies this vector, overrides the copy's Z.
/// </summary>
public static Vector3 WithZ(this Vector3 v, float z) {
return new Vector3(v.x, v.y, z);
}

/// <summary>
/// Copies this vector, multiplies the copy component-wise with another vector.
/// </summary>
/// <remarks>
/// There is no float/int override because that's just scalar multiplication. ;)
/// </remarks>
public static Vector3 WithScale(this Vector3 v, Vector3 other) {
return Vector3.Scale(v, other);
}

public static Vector3 WithScaleX(this Vector3 v, float scale) {
return new Vector3(v.x * scale, v.y, v.z);
}

public static Vector3 WithScaleY(this Vector3 v, float scale) {
return new Vector3(v.x, v.y * scale, v.z);
}

public static Vector3 WithScaleZ(this Vector3 v, float scale) {
return new Vector3(v.x, v.y, v.z * scale);
}

public static Vector3 WithClampX(this Vector3 v, float min, float max) {
float clamped = Mathf.Clamp(v.x, min, max);
return new Vector3(clamped, v.y, v.z);
}

public static Vector3 WithClampY(this Vector3 v, float min, float max) {
float clamped = Mathf.Clamp(v.y, min, max);
return new Vector3(v.x, clamped, v.z);
}

public static Vector3 WithClampZ(this Vector3 v, float min, float max) {
float clamped = Mathf.Clamp(v.z, min, max);
return new Vector3(v.x, v.y, clamped);
}

/// <summary>
/// Copies this vector, overrides the copy's length.
/// </summary>
public static Vector3 WithLength(this Vector3 v, float length) {
return v.normalized * length;
}

/// <summary>
/// Returns Vector2 with matching (x,y).
/// </summary>
public static Vector2 ToVector2(this Vector3 v) {
return new Vector2(v.x, v.y);
}
Expand Down
22 changes: 22 additions & 0 deletions Project/Assets/Plugins/ChicoPlugins/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ChicoPlugins

The MIT License (MIT)

Copyright (c) 2013 Robert Utter

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions Project/Assets/Plugins/ChicoPlugins/Loading/LevelLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/// <summary>
/// Switch levels with a loading screen.
/// </summary>
[AddComponentMenu("ChicoPlugins/Loading/Level Loader")]
public class LevelLoader : MonoBehaviour {
/// <summary>
/// Global hook for level loading with transition scene.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/// <remarks>
/// Recommended for use as a placeholder with LevelLoader.
/// </remarks>
[AddComponentMenu("ChicoPlugins/Loading/Simple Load UI")]
public class SimpleLoadUI : MonoBehaviour {
public Color backgroundColor = Color.black;
public Color textColor = Color.blue;
Expand Down
24 changes: 24 additions & 0 deletions Project/Assets/Plugins/ChicoPlugins/Movers/Bouncer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using System.Collections;

/// <summary>
/// Simple movement: bounces an object up and down.
/// </summary>
[AddComponentMenu("ChicoPlugins/Movers/Bouncer")]
public class Bouncer : MonoBehaviour {

Vector3 origin;

public Vector3 dir = Vector3.up;
public float period = 4f;

void Start () {
origin = transform.position;
}

// Update is called once per frame
void Update () {
float sin = Mathf.Sin(Time.time / (period * 2f * Mathf.PI));
transform.position = origin + dir * sin;
}
}
20 changes: 20 additions & 0 deletions Project/Assets/Plugins/ChicoPlugins/Movers/Facer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEngine;
using System.Collections;

/// <summary>
/// Simple movement: makes one object face another, once per frame.
/// </summary>
[AddComponentMenu("ChicoPlugins/Movers/Facer")]
public class Facer : MonoBehaviour {
public Transform target;
public bool freezeVertical = true;

// Update is called once per frame
void Update () {
Vector3 targetPos = target.position;
if (freezeVertical) {
targetPos.y = transform.position.y;
}
transform.LookAt(targetPos);
}
}
Loading

0 comments on commit db1f571

Please sign in to comment.