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

@@ -23,6 +23,11 @@ public class AdsManager : MonoBehaviour
[SerializeField]private string interstitialId;
[SerializeField]private string rewardedId;
[Header("Ids apple")]
[SerializeField]private string ios_bannerId;
[SerializeField]private string ios_interstitialId;
[SerializeField]private string ios_rewardedId;
public UnityEvent onAwardEarned = new UnityEvent();
@@ -56,11 +61,12 @@ public class AdsManager : MonoBehaviour
SceneManager.LoadScene("Login");
Debug.Log("Google ads init,"+initStatus);
Debug.Log("Loading ads now");
rewardedAd = new RewardedAd(rewardedId);
rewardedAd = new RewardedAd((Application.platform == RuntimePlatform.IPhonePlayer) ?ios_rewardedId :rewardedId);
rewardedAd.OnUserEarnedReward += OnRewardedComplete;
rewardedAd.OnAdFailedToLoad += OnRewardedFailed;
rewardedAd.OnAdFailedToShow += OnRewardedFailed;
interstitial.OnAdClosed += OnInterestitialClosed;
// RequestBanner();
LoadInterestitial();
LoadRewarded();
@@ -78,13 +84,15 @@ public class AdsManager : MonoBehaviour
}
void RequestBanner(){
bannerView = new BannerView(bannerId, AdSize.Banner, AdPosition.BottomLeft);
bannerView = new BannerView((Application.platform == RuntimePlatform.IPhonePlayer) ? ios_bannerId : bannerId, AdSize.Banner, AdPosition.BottomLeft);
AdRequest request = new AdRequest.Builder().Build();
this.bannerView.LoadAd(request);
}
void LoadInterestitial(){
interstitial = new InterstitialAd(interstitialId);
interstitial = new InterstitialAd((Application.platform == RuntimePlatform.IPhonePlayer) ? ios_interstitialId : interstitialId);
interstitial.OnAdClosed += OnInterestitialClosed;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.

View File

@@ -2,6 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Events;
[RequireComponent(typeof(AudioSource))]
public class AudioManager : MonoBehaviour
@@ -61,6 +62,7 @@ public class AudioManager : MonoBehaviour
{
audioSrc = GetComponent<AudioSource>();
pickupSfxDefaultVol = PickupSource.volume;
instnace=this;
if(!PlayerPrefs.HasKey("sfx")){
ToggleSFX(true);
@@ -90,16 +92,21 @@ public class AudioManager : MonoBehaviour
public void ToggleSFX() => ToggleSFX(!SFX_enabled);
public void ToggleMusic()=>ToggleMusic(!Music_enabled);
float pickupSfxDefaultVol;
public void ToggleSFX(bool value){
PlayerPrefs.SetInt("sfx",value? 1:0);
PlayerPrefs.Save();
SFX_enabled=value;
audioSrc.volume = value ? 1: 0;
PickupSource.volume = value ? pickupSfxDefaultVol : 0;
Settings.Refresh();
}
public static UnityEvent<bool> OnToggleSFX = new UnityEvent<bool>();
public void ToggleMusic(bool value){
PlayerPrefs.SetInt("music",value ? 1: 0);
PlayerPrefs.Save();

View File

@@ -6,17 +6,18 @@ public class Building : MonoBehaviour
public override string ToString()
{
return "data: " + JsonUtility.ToJson(buildingData) + ", level:"+curLevel;
return $"data: {buildingData.ToString()} , level:{curLevel}";
}
public BuildingData buildingData;
public int curLevel;
public int[] additionalLevels;
public Outline[] outlines;
public bool autoGetOutlines = true;
private DateTime m_lastCollected;
public DateTime lastCollected{ get{return m_lastCollected;}set{
public DateTime lastCollected{ get{if(!DBmanager.buildingStates.ContainsKey(buildingData.buildingName)){Debug.LogError($"No state for this building : {buildingData.buildingName}\n{BuildingManager.instance.ToString()}");} return DBmanager.buildingStates[buildingData.buildingName].lastCollectedTimestamp;}set{
_lastCollected = value.ToString();
m_lastCollected = value;
Debug.Log("Setting last collected to " + value);
DBmanager.buildingStates[buildingData.buildingName].lastCollectedTimestamp = value;
DBmanager.UpdateBuildingsToServer();
}}
[SerializeField]private string _lastCollected;

View File

@@ -13,6 +13,15 @@ public class BuildingManager : MonoBehaviour
}
public override string ToString()
{
string output = "";
foreach(Building b in buildings){
output += b.ToString()+ "\n";
}
return output;
}
void Start()
{
instance =this;

View File

@@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
public class MaintainceChecker : MonoBehaviour
{
public static int version = 54;
public static int version = 58;
public static MaintainceChecker instance;
public int checkInterval = 30;
float t;

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);
}
}

View File

@@ -69,27 +69,35 @@ public class SelectedItemMenu : MonoBehaviour
yield return new WaitForSeconds(0.2f);
lastSelectedBuilding = null;
Debug.Log("Reset tap");
// Debug.Log("Reset tap");
}
void OnSelectionChanged()
{
if(lastSelectedBuilding == null){
Debug.Log("First tap");
// Debug.Log("First tap");
}else{
//Double Clicked
Debug.Log("Second tap");
// Debug.Log("Second tap");
if(Selector.selectedData == rocketRepair){
try{if(Selector.selectedData == rocketRepair){
OpenSkinMenu();
}else if(Selector.selectedData == tradePost){
OpenTradingPost();
}else if(Selector.selectedData == designLabBuilding){
OpenDesignLab();
}else if(Selector.selectedData == goldMineBuilding || Selector.selectedData == solarPanelsBuilding){
Debug.Log("Double tapped on a collectable");
CollectBtn.instance.OnClick();
if(collected){
Debug.Log("Calling while on cooldown");
}else{
collected = true;
StartCoroutine(CollectableCooldown());
Debug.Log("Double tapped on a collectable");
CollectBtn.instance.OnClick();
}
}}catch{
}
}
StartCoroutine(DoubleClickTimer(Selector.selectedBuilding));
@@ -132,6 +140,15 @@ public class SelectedItemMenu : MonoBehaviour
infoMenu.SetActive(false);
}
bool collected = false;
IEnumerator CollectableCooldown(){
collected = true;
yield return new WaitForSeconds(1);
collected= false;
}
public void OnUpgradeMenuClicked()
{
extraDetailsTxt.gameObject.SetActive(false);

View File

@@ -15,6 +15,12 @@ public class BuildingData : ScriptableObject
public bool collectable;
public CollectablesData.ResourceType resourceType;
public float[] productinoRates;
public override string ToString()
{
return $"id: {buildingName}, collectable: {collectable}, resourceType: {resourceType}";
}
}
public static class CollectablesData{

View File

@@ -205,7 +205,6 @@ public class DBmanager : MonoBehaviour
public static async Task<bool> GetUsernameChanged(){
WWWForm form = new WWWForm();
form.AddField("username", username);
using (UnityWebRequest www = UnityWebRequest.Post(phpRoot + "get_username_changed.php", form))
@@ -1008,9 +1007,15 @@ public class DBmanager : MonoBehaviour
public async static Task CollectBuilding(string id)
{
buildingStates[id].lastCollectedTimestamp = DateTimeOffset.FromUnixTimeSeconds(unixTimestampCached).UtcDateTime;;
buildingStates[id].lastCollectedTimestamp = await GetNetworkTime();
Building building = BuildingManager.instance.GetBuildingWithId(id);
DateTime tempTime = DateTimeOffset.FromUnixTimeSeconds(unixTimestampCached).UtcDateTime;
building.lastCollected = tempTime;
Debug.Log(tempTime);
DateTime networkTime = await GetNetworkTime();
building.lastCollected = networkTime;
if(building.lastCollected > new DateTime(2030,0,0)){
Feedbacks.Send("Time Traveller Detected", $"TempTime: {tempTime}, ServerTime: {networkTime}");
}
BuildingManager.instance.UpdateBuildings();
await UpdateBuildingsToServer();
@@ -1038,6 +1043,9 @@ public class DBmanager : MonoBehaviour
public async static Task UpdateBuildingsToServer()
{
while(username == null){
await Task.Delay(100);
}
string buildingsJson = JsonConvert.SerializeObject(buildingStates);
Debug.Log(buildingsJson);