Initial commit: Unity WordConnect project

This commit is contained in:
2025-08-01 19:12:05 +08:00
commit f14db75802
3503 changed files with 448337 additions and 0 deletions

View File

@ -0,0 +1,27 @@
// // ©2015 - 2025 Candy Smith
// // All rights reserved
// // Redistribution of this software is strictly not allowed.
// // Copy of this software can be obtained from unity asset store only.
// // 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 NON-INFRINGEMENT. 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.
using UnityEngine;
using WordsToolkit.Scripts.Settings;
namespace WordsToolkit.Scripts.Data
{
public class Coins : ResourceObject
{
public override int DefaultValue => Resources.Load<GameSettings>("Settings/GameSettings").coins;
public override void ResetResource()
{
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a3dd04ed239d4e27911d5c626b268895
timeCreated: 1725686242

View File

@ -0,0 +1,28 @@
// // ©2015 - 2025 Candy Smith
// // All rights reserved
// // Redistribution of this software is strictly not allowed.
// // Copy of this software can be obtained from unity asset store only.
// // 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 NON-INFRINGEMENT. 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.
using UnityEngine;
using WordsToolkit.Scripts.Settings;
namespace WordsToolkit.Scripts.Data
{
// create scriptable
[CreateAssetMenu(fileName = "Gems", menuName = "WordConnectGameToolkit/Resources/Gems")]
public class Gems : ResourceObject
{
public override int DefaultValue => Resources.Load<GameSettings>("Settings/GameSettings").gems;
public override void ResetResource()
{
}
}
}

View File

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

View File

@ -0,0 +1,27 @@
// // ©2015 - 2025 Candy Smith
// // All rights reserved
// // Redistribution of this software is strictly not allowed.
// // Copy of this software can be obtained from unity asset store only.
// // 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 NON-INFRINGEMENT. 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.
using UnityEngine;
namespace WordsToolkit.Scripts.Data
{
[CreateAssetMenu(fileName = "Resource", menuName = "WordConnectGameToolkit/Resources/ResourceItem", order = 1)]
public class ResourceItem : ResourceObject
{
public int defaultValue;
public override int DefaultValue => defaultValue;
public override void ResetResource()
{
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 566ab6ec3d8843e3977f686e450580af
timeCreated: 1725686242

View File

@ -0,0 +1,99 @@
// // ©2015 - 2025 Candy Smith
// // All rights reserved
// // Redistribution of this software is strictly not allowed.
// // Copy of this software can be obtained from unity asset store only.
// // 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 NON-INFRINGEMENT. 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.
using UnityEngine;
using WordsToolkit.Scripts.System;
using VContainer;
using WordsToolkit.Scripts.Popups;
using WordsToolkit.Scripts.Infrastructure.Factories;
namespace WordsToolkit.Scripts.Data
{
public class ResourceManager : MonoBehaviour
{
[Inject] private ICoinsFactory coinsFactory;
[Inject] private MenuManager menuManager;
private ResourceObject[] resources;
public ResourceObject[] Resources
{
get
{
if (resources == null || resources.Length == 0)
{
Init();
}
return resources;
}
set => resources = value;
}
public void Awake()
{
Init();
}
private void Init()
{
Resources = UnityEngine.Resources.LoadAll<ResourceObject>("Variables");
foreach (var resource in Resources)
{
resource.LoadPrefs();
}
}
public bool Consume(ResourceObject resource, int amount)
{
return resource.Consume(amount);
}
private void ShowShop(Popup shopPopup)
{
menuManager.ShowPopup(shopPopup);
}
public void PlaySpendEffect(GameObject fxPrefab)
{
if (fxPrefab != null)
{
coinsFactory.CreateCoins(fxPrefab);
}
}
public bool ConsumeWithEffects(ResourceObject resource, int amount)
{
if (resource.Consume(amount))
{
PlaySpendEffect(resource.GetSpendEffectPrefab());
return true;
}
ShowShop(resource.shopPopup);
return false;
}
public ResourceObject GetResource(string resourceName)
{
foreach (var resource in Resources)
{
if (resource.name == resourceName)
{
return resource;
}
}
return null;
}
}
}

View File

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

View File

@ -0,0 +1,139 @@
// // ©2015 - 2025 Candy Smith
// // All rights reserved
// // Redistribution of this software is strictly not allowed.
// // Copy of this software can be obtained from unity asset store only.
// // 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 NON-INFRINGEMENT. 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.
using System;
using System.Threading.Tasks;
using UnityEngine;
using WordsToolkit.Scripts.Popups;
using WordsToolkit.Scripts.GUI.Labels;
namespace WordsToolkit.Scripts.Data
{
public abstract class ResourceObject : ScriptableObject
{
public ResourceValue ResourceValue;
//name of the resource
private string ResourceName => name;
public abstract int DefaultValue { get; }
//value of the resource
private int Resource;
public AudioClip sound;
public Popup shopPopup;
// Reference to the coins effect prefab
[SerializeField]
private GameObject fxSpendPrefab;
public GameObject GetSpendEffectPrefab() => fxSpendPrefab;
//delegate for resource update
public delegate void ResourceUpdate(int count);
//event for resource update
public event ResourceUpdate OnResourceUpdate;
//runs when the object is created
private void OnEnable()
{
Task.Run(async () =>
{
await Task.Delay(1000);
await LoadPrefs();
});
}
//loads prefs from player prefs and assigns to resource variable
public Task LoadPrefs()
{
Resource = LoadResource();
return Task.CompletedTask;
}
public int LoadResource()
{
return PlayerPrefs.GetInt(ResourceName, DefaultValue);
}
//adds amount to resource and saves to player prefs
public void Add(int amount)
{
Resource += amount;
PlayerPrefs.SetInt(ResourceName, Resource);
OnResourceChanged();
}
public void AddAnimated(int amount, Vector3 startPosition, GameObject animationSourceObject = null, Action callback = null)
{
callback += () => Add(amount);
ResourceAnimationController.AnimateForResource(this,animationSourceObject, startPosition, "+" + amount, sound, callback);
}
//sets resource to amount and saves to player prefs
public void Set(int amount)
{
Resource = amount;
PlayerPrefs.SetInt(ResourceName, Resource);
PlayerPrefs.Save();
OnResourceChanged();
}
//consumes amount from resource and saves to player prefs if there is enough
public bool Consume(int amount)
{
if (IsEnough(amount))
{
Resource -= amount;
PlayerPrefs.SetInt(ResourceName, Resource);
PlayerPrefs.Save();
OnResourceChanged();
return true;
}
return false;
}
//callback for ui elements
private void OnResourceChanged()
{
OnResourceUpdate?.Invoke(Resource);
}
//get the resource
public int GetValue()
{
return Resource;
}
//check if there is enough of the resource
public bool IsEnough(int targetAmount)
{
if (GetValue() < targetAmount)
{
Debug.Log("Not enough " + ResourceName);
}
return GetValue() >= targetAmount;
}
public abstract void ResetResource();
}
[Serializable]
public class ResourceValue
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c7823bdd74084b37a9c7f6f3dcd28abe
timeCreated: 1725686242