ads fixed

This commit is contained in:
2023-01-13 23:26:48 +05:30
parent 8ee203e932
commit 8531c5f41a
56 changed files with 67953 additions and 37 deletions

View File

@@ -0,0 +1,125 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class EmojiButton : MonoBehaviour
{
public static EmojiButton instance { get; private set;}
[SerializeField]private EventTrigger trigger;
[SerializeField]private RectTransform radialMenu;
[SerializeField]private RectTransform button;
[SerializeField]private float TriggerDistance = 25;
[SerializeField]private float RadialLayoutSize = 2.7f;
[SerializeField]private float ButtonSize = 1;
[SerializeField]private GameObject[] emojiPrefabs;
[Header("Debug")]
public float angle;
public float distance;
public int curIndex = 0;
void Awake()
{
instance = this;
EventTrigger.Entry pointer_down = new EventTrigger.Entry();
pointer_down.eventID = EventTriggerType.PointerDown;
pointer_down.callback.AddListener( (eventData) => { OnPointerDown((PointerEventData)eventData); } );
trigger.triggers.Add(pointer_down);
EventTrigger.Entry pointer_up = new EventTrigger.Entry();
pointer_up.eventID = EventTriggerType.PointerUp;
pointer_up.callback.AddListener( (eventData) => { OnPointerUp((PointerEventData)eventData); } );
trigger.triggers.Add(pointer_up);
EventTrigger.Entry drag = new EventTrigger.Entry();
drag.eventID = EventTriggerType.Drag;
drag.callback.AddListener( (eventData) => { OnDrag((PointerEventData)eventData); } );
trigger.triggers.Add(drag);
}
void Update(){
if(opened){
for(int i=0; i < radialMenu.childCount-1; i++){
Transform item = radialMenu.GetChild(radialMenu.childCount-1 -i);
if(i == curIndex){
item.localScale = Vector3.Lerp(item.localScale, Vector3.one * 1.2f, 0.1f);
}else{
item.localScale = Vector3.Lerp(item.localScale, Vector3.one * 0.75f, 0.1f);
}
}
}
}
bool isDown = false;
Vector2 startPos;
void OnPointerDown(PointerEventData e){
isDown = true;
startPos = e.position;
}
void OnPointerUp(PointerEventData e){
isDown =false;
if(opened && SceneData.localPlayer != null){
//Trigger send
SceneData.localPlayer.GetComponent<SpaceshipController>().ShowEmoji(curIndex, SceneData.localPlayer.transform.position);
}
ToggleState(false);
}
public void showEmoji(int index, Vector3 position){
EffectPool.Spawn(emojiPrefabs[index], position);
}
void OnDrag(PointerEventData e){
if(!isDown){
return;
}
Vector3 targetDir = e.position - (Vector2)button.position;
angle = Vector3.SignedAngle(targetDir, Vector3.up, Vector3.forward);
if(angle < 0){
angle = 360 + angle;
}
distance= Vector2.Distance(startPos, e.position);
if(distance > TriggerDistance && !opened){
ToggleState(true);
}
if(!opened){return;}
curIndex = (int)(((angle / 360f) * (radialMenu.childCount-1)));
}
bool opened =false;
public void ToggleState(bool val){
if(opened != val){
StartCoroutine(toggleState(val));
}
}
IEnumerator toggleState(bool val){
opened = val;
float t = 0;
float time = 0.25f;
if(opened){
radialMenu.gameObject.SetActive(true);
}else{
button.gameObject.SetActive(true);
}
while(t < time){
t+= Time.deltaTime;
float t2 = t * (1f / time);
radialMenu.localScale = Vector3.one * (opened ? t2 : (1-t2))* RadialLayoutSize;
button.localScale = Vector3.one * (opened ? (1-t2) : t2) * ButtonSize;
yield return new WaitForEndOfFrame();
}
if(opened){
button.gameObject.SetActive(false);
}else{
radialMenu.gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eebdda985924470418244b27721bc5fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,78 @@
using UnityEngine;
using UnityEngine.UI;
/*
Radial Layout Group by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk
Copyright (c) 2015
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.
*/
public class RadialLayout : LayoutGroup {
public float fDistance;
[Range(0f,360f)]
public float MinAngle, MaxAngle, StartAngle;
protected override void OnEnable() { base.OnEnable(); CalculateRadial(); }
public override void SetLayoutHorizontal()
{
}
public override void SetLayoutVertical()
{
}
public override void CalculateLayoutInputVertical()
{
CalculateRadial();
}
public override void CalculateLayoutInputHorizontal()
{
CalculateRadial();
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
CalculateRadial();
}
#endif
void CalculateRadial()
{
m_Tracker.Clear();
if (transform.childCount == 0)
return;
float fOffsetAngle = ((MaxAngle - MinAngle)) / (transform.childCount -1);
float fAngle = StartAngle;
for (int i = 0; i < transform.childCount; i++)
{
RectTransform child = (RectTransform)transform.GetChild(i);
if (child != null)
{
//Adding the elements to the tracker stops the user from modifiying their positions via the editor.
m_Tracker.Add(this, child,
DrivenTransformProperties.Anchors |
DrivenTransformProperties.AnchoredPosition |
DrivenTransformProperties.Pivot);
Vector3 vPos = new Vector3(Mathf.Cos(fAngle * Mathf.Deg2Rad), Mathf.Sin(fAngle * Mathf.Deg2Rad), 0);
child.localPosition = vPos * fDistance;
//Force objects to be center aligned, this can be changed however I'd suggest you keep all of the objects with the same anchor points.
child.anchorMin = child.anchorMax = child.pivot = new Vector2(0.5f, 0.5f);
fAngle += fOffsetAngle;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0df2f2f75c5081f48955713a92a7afc4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -49,6 +49,7 @@ public class SpaceshipController : NetworkBehaviour
public Joystick joystick;
[SyncVar]
public bool boosting;
public bool boosting_local;
[Header("Client Prediction")]
private Vector2 input;
@@ -168,7 +169,7 @@ public class SpaceshipController : NetworkBehaviour
if(!isBoostAvailable){return; }
if (isLocalPlayer)
{
boosting_local = true;
AudioManager.instnace.Boost();
if (isServer)
{
@@ -199,6 +200,7 @@ public class SpaceshipController : NetworkBehaviour
{
if (isLocalPlayer)
{
boosting_local = false;
if (isServer)
{
boosting = false;
@@ -465,15 +467,7 @@ public class SpaceshipController : NetworkBehaviour
}*/
#endregion
CheckForPickups();
if (boosting && scale > 1)
{
speed = movingSpeed * 2 * speedMultiplier;
DecreaseTrail(Time.deltaTime * boostConsumption * 0.5f);
}
else
{
speed = movingSpeed * speedMultiplier;
}
UpdateSpeed();
int bufferIndex = -1;
while(inputQueue.Count > 0){
@@ -489,9 +483,38 @@ public class SpaceshipController : NetworkBehaviour
StartCoroutine(SendToClient(stateBuffer[bufferIndex]));
}
}
void UpdateSpeed(){
if (boosting && trailTime >= minTrailTime)
{
speed = movingSpeed * 2 * speedMultiplier;
DecreaseTrail(Time.deltaTime * boostConsumption * 0.5f);
}
else
{
boosting = false;
speed = movingSpeed * speedMultiplier;
}
}
public float speedLocal = 0;
void UpdateSpeedLocal(){
if (boosting_local && trailTime >= minTrailTime)
{
speedLocal = movingSpeed * 2 * speedMultiplier;
DecreaseTrail(Time.deltaTime * boostConsumption * 0.5f);
}
else
{
boosting_local = false;
OnBoostUp();
speedLocal = movingSpeed * speedMultiplier;
}
}
void ClientHandleTick(){
if(isLocalPlayer){
UpdateSpeedLocal();
}
engineAudio.pitch = Mathf.Lerp(engineAudio.pitch, (boosting) ? boostedPitch : normalPitch, 0.1f);
if (!latestServerState.Equals(default(PlayerState)) &&
@@ -610,7 +633,7 @@ public class SpaceshipController : NetworkBehaviour
PlayerState ProcessMovement(InputState input)
{
// Should always be in sync with same function on Client
body.Translate(new Vector3(0, speed), body);
body.Translate(new Vector3(0, (isLocalPlayer) ? speedLocal: speed), body);
Turn(input.Input);
return new PlayerState()
@@ -1023,4 +1046,31 @@ public class SpaceshipController : NetworkBehaviour
}
}
//Emojis
public void ShowEmoji(int index, Vector3 position){
if(isServer){
RpcShowEmoji(index, position);
}else{
CmdShowEmoji(index, position);
EmojiButton.instance.showEmoji(index,position);
}
}
[Command]
void CmdShowEmoji(int index, Vector3 position){
RpcShowEmoji(index,position);
}
[ClientRpc]
void RpcShowEmoji(int index, Vector3 position){
if(isLocalPlayer){ Debug.Log("ClientRPC for emoji received. I already showed it");return;}
EmojiButton.instance.showEmoji(index, position);
}
}