Skip to content

Commit 8d17e92

Browse files
committed
Update Version to 1.2.1
1 parent 913f1df commit 8d17e92

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1289
-517
lines changed

Assets/JCSUnity_Framework/Scenes/2D/2D_AttackScene.unity

Lines changed: 181 additions & 294 deletions
Large diffs are not rendered by default.

Assets/JCSUnity_Framework/Scripts/2D/JCS_OrderLayerObject.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace JCSUnity
1313
{
14+
1415
[RequireComponent(typeof(SpriteRenderer))]
1516
public class JCS_OrderLayerObject
1617
: MonoBehaviour
@@ -38,8 +39,14 @@ private void Awake()
3839
JCS_OrderLayer jcsOrderLayer = this.GetComponentInParent<JCS_OrderLayer>();
3940
if (jcsOrderLayer != null)
4041
{
42+
// override the current order layer.
4143
spriteRenderer.sortingOrder = jcsOrderLayer.GetOrderLayer();
4244
}
45+
else
46+
{
47+
// set to default order layer
48+
spriteRenderer.sortingOrder = JCS_GameSettings.instance.DEFAULT_ORDER_LAYER;
49+
}
4350
}
4451

4552
//========================================

Assets/JCSUnity_Framework/Scripts/3D/JCS_3DPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class JCS_3DPlayer
3535
// Unity's function
3636
//------------------------------
3737

38-
private void Update()
38+
protected override void Update()
3939
{
4040
PlayerInput();
4141

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* $File: JCS_ThrowAction.cs $
3+
* $Date: $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information $
7+
* Copyright (c) 2016 by Shen, Jen-Chieh $
8+
*/
9+
using UnityEngine;
10+
using System.Collections;
11+
12+
13+
namespace JCSUnity
14+
{
15+
16+
/// <summary>
17+
/// Do the throw action like "Plants vs Zombies"'s corn plants.
18+
/// </summary>
19+
public class JCS_ThrowAction
20+
: MonoBehaviour
21+
{
22+
23+
//----------------------
24+
// Public Variables
25+
26+
//----------------------
27+
// Private Variables
28+
private bool mEffect = false;
29+
30+
[Tooltip("Target we are throwing to.")]
31+
[SerializeField] private Transform mTargetTransform = null;
32+
33+
private Vector3 mStartingPosition = Vector3.zero;
34+
private Vector3 mVelocity = Vector3.zero;
35+
36+
private bool mReachInflectionPoint = false;
37+
private float mInflectionPointX = 0;
38+
[Tooltip("Speed of x")]
39+
[SerializeField] private float mHorizontalFriction = 0.4f; // x & z axis
40+
[Tooltip("Speed of y")]
41+
[SerializeField] private float mVerticalForce = 5; // y axis
42+
43+
//----------------------
44+
// Protected Variables
45+
46+
//========================================
47+
// setter / getter
48+
//------------------------------
49+
public void SetTargetTransform(Transform trans) { this.mTargetTransform = trans; }
50+
51+
//========================================
52+
// Unity's function
53+
//------------------------------
54+
55+
private void LateUpdate()
56+
{
57+
#if (UNITY_EDITOR)
58+
Test();
59+
#endif
60+
if (!mEffect)
61+
return;
62+
63+
DoThrowEffect();
64+
65+
}
66+
#if (UNITY_EDITOR)
67+
private void Test()
68+
{
69+
if (JCS_Input.GetKeyDown(KeyCode.H))
70+
ActiveEffect();
71+
}
72+
#endif
73+
74+
//========================================
75+
// Self-Define
76+
//------------------------------
77+
//----------------------
78+
// Public Functions
79+
public void ActiveEffect()
80+
{
81+
mStartingPosition = this.transform.localPosition;
82+
83+
mEffect = true;
84+
mReachInflectionPoint = false;
85+
}
86+
87+
//----------------------
88+
// Protected Functions
89+
90+
//----------------------
91+
// Private Functions
92+
private void DoThrowEffect()
93+
{
94+
if (mTargetTransform == null)
95+
return;
96+
97+
Vector3 currentPos = this.transform.localPosition;
98+
mVelocity.x = (this.mTargetTransform.localPosition.x - currentPos.x) / mHorizontalFriction * Time.deltaTime;
99+
mVelocity.z = (this.mTargetTransform.localPosition.z - currentPos.z) / mHorizontalFriction * Time.deltaTime;
100+
101+
// before reach to inflection point
102+
if (!mReachInflectionPoint)
103+
{
104+
// calculate inflection point
105+
{
106+
mInflectionPointX = ((mTargetTransform.localPosition.x - this.mStartingPosition.x) / 2) + this.mStartingPosition.x;
107+
108+
if (mVelocity.x > 0)
109+
{
110+
if (currentPos.x >= mInflectionPointX)
111+
mReachInflectionPoint = true;
112+
}
113+
else
114+
{
115+
if (currentPos.x <= mInflectionPointX)
116+
mReachInflectionPoint = true;
117+
}
118+
}
119+
120+
mVelocity.y = JCS_Mathf.ToPositive((mInflectionPointX - currentPos.x) * mVerticalForce * Time.deltaTime);
121+
}
122+
// after reach to inflection point
123+
else {
124+
125+
//mVelocity.y = JCS_Mathf.ToNegative(mVerticalForce / (this.mTargetTransform.localPosition.x - currentPos.x) * Time.deltaTime);
126+
127+
float forceSpeed = JCS_Mathf.ToPositive(mVerticalForce / (this.mTargetTransform.localPosition.x - currentPos.x));
128+
mVelocity.y = (this.mTargetTransform.localPosition.y - currentPos.y) * forceSpeed * Time.deltaTime;
129+
}
130+
131+
// apply new localPosition
132+
if (!float.IsInfinity(mVelocity.x) &&
133+
!float.IsInfinity(mVelocity.y) &&
134+
!float.IsInfinity(mVelocity.z))
135+
this.transform.localPosition += mVelocity;
136+
}
137+
138+
}
139+
}

Assets/JCSUnity_Framework/Scripts/Actions/JCS_ThrowAction.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity_Framework/Scripts/Effects/Destroy.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* $File: JCS_DestinationDestroy.cs $
3+
* $Date: $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information $
7+
* Copyright (c) 2016 by Shen, Jen-Chieh $
8+
*/
9+
using UnityEngine;
10+
using System.Collections;
11+
12+
namespace JCSUnity
13+
{
14+
/// <summary>
15+
/// While hit the destination destroy it
16+
/// </summary>
17+
[RequireComponent(typeof(JCS_AlphaObject))]
18+
public class JCS_DestinationDestroy
19+
: JCS_UnityObject
20+
{
21+
22+
//----------------------
23+
// Public Variables
24+
public enum FadeType
25+
{
26+
IN,
27+
OUT
28+
}
29+
30+
//----------------------
31+
// Private Variables
32+
33+
[Header("** Runtime Variables **")]
34+
[SerializeField] private Transform mTargetTransform = null;
35+
[Tooltip("Accept range to destroy this object.(circle)")]
36+
[SerializeField] private float mDestroyDistance = 0.5f;
37+
38+
[Header("** Fade Effect **")]
39+
[SerializeField] private bool mFadeEffect = true;
40+
[SerializeField] private FadeType mFadeType = FadeType.IN;
41+
[SerializeField] private float mFadeDistance = 5;
42+
private JCS_AlphaObject mAlphaObject = null;
43+
44+
45+
//----------------------
46+
// Protected Variables
47+
48+
//========================================
49+
// setter / getter
50+
//------------------------------
51+
public void SetTargetTransform(Transform pos) { this.mTargetTransform = pos; }
52+
53+
//========================================
54+
// Unity's function
55+
//------------------------------
56+
private void Awake()
57+
{
58+
this.mAlphaObject = this.GetComponent<JCS_AlphaObject>();
59+
60+
this.mAlphaObject.SetObjectType(this.GetObjectType());
61+
62+
UpdateUnityData();
63+
}
64+
65+
private void Update()
66+
{
67+
float currentDistance = Vector3.Distance(this.transform.localPosition, mTargetTransform.localPosition);
68+
69+
if (mFadeEffect)
70+
{
71+
if (currentDistance <= mFadeDistance)
72+
{
73+
float alphaDeltaDistance = mFadeDistance - mDestroyDistance;
74+
if (mFadeType == FadeType.IN)
75+
mAlphaObject.TargetAlpha = (currentDistance - mDestroyDistance) / alphaDeltaDistance;
76+
else if (mFadeType == FadeType.OUT)
77+
mAlphaObject.TargetAlpha = 1 - (currentDistance - mDestroyDistance) / alphaDeltaDistance;
78+
}
79+
}
80+
81+
82+
if (currentDistance <= mDestroyDistance)
83+
{
84+
Destroy(this.gameObject);
85+
}
86+
}
87+
88+
//========================================
89+
// Self-Define
90+
//------------------------------
91+
//----------------------
92+
// Public Functions
93+
94+
//----------------------
95+
// Protected Functions
96+
97+
//----------------------
98+
// Private Functions
99+
100+
}
101+
}

Assets/JCSUnity_Framework/Scripts/Effects/Destroy/JCS_DestinationDestroy.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity_Framework/Scripts/Effects/Item/JCS_Item.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace JCSUnity
1313
{
1414

1515
[RequireComponent(typeof(BoxCollider))]
16+
[RequireComponent(typeof(JCS_SoundPlayer))]
1617
public class JCS_Item
1718
: JCS_UnityObject
1819
{
@@ -25,12 +26,17 @@ public class JCS_Item
2526
private bool mCanPick = true;
2627
private BoxCollider mBoxCollider = null;
2728

29+
private JCS_SoundPlayer mSoundPlayer = null;
30+
[Tooltip("Audio sound when u pick up this item")]
31+
[SerializeField] private AudioClip mPickSound = null;
32+
2833
//----------------------
2934
// Protected Variables
3035

3136
//========================================
3237
// setter / getter
3338
//------------------------------
39+
public bool CanPick { get { return this.mCanPick; } set { this.mCanPick = value; } }
3440
public BoxCollider GetBoxCollider() { return this.mBoxCollider; }
3541

3642
//========================================
@@ -39,29 +45,55 @@ public class JCS_Item
3945
private void Awake()
4046
{
4147
mBoxCollider = this.GetComponent<BoxCollider>();
48+
mSoundPlayer = this.GetComponent<JCS_SoundPlayer>();
4249

4350
// update the data once
4451
// depends on what game object is.
4552
UpdateUnityData();
4653
}
4754

48-
private void Update()
55+
private void OnTriggerStay(Collider other)
4956
{
50-
57+
if (JCS_Input.GetKeyDown(KeyCode.Z))
58+
{
59+
Pick(other);
60+
}
5161
}
5262

5363
//========================================
5464
// Self-Define
5565
//------------------------------
5666
//----------------------
5767
// Public Functions
58-
public void Drop()
68+
public void Pick(Collider other)
5969
{
70+
if (!mCanPick)
71+
return;
6072

61-
}
62-
public void Pick()
63-
{
73+
JCS_OneJump joj = this.GetComponent<JCS_OneJump>();
74+
if (joj != null)
75+
{
76+
77+
// Only when item is on the ground!
78+
if (joj.GetVelocity().y != 0)
79+
return;
80+
}
81+
82+
// Check the colliding object are is active player.
83+
if (JCS_PlayerManager.instance.IsActivePlayerTransform(other.transform))
84+
{
85+
JCS_ThrowAction ta = this.gameObject.AddComponent<JCS_ThrowAction>();
86+
ta.SetTargetTransform(other.transform);
87+
ta.ActiveEffect();
88+
89+
JCS_DestinationDestroy jcsdd = this.gameObject.AddComponent<JCS_DestinationDestroy>();
90+
jcsdd.SetTargetTransform(other.transform);
91+
92+
if (mPickSound != null)
93+
mSoundPlayer.PlayOneShot(mPickSound);
6494

95+
mCanPick = false;
96+
}
6597
}
6698

6799
//----------------------

0 commit comments

Comments
 (0)