You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
3.6 KiB

2 years ago
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;
public class Card : MonoBehaviour
{
GameObject cntCard;
AssetBundle bundle;
int idx = 0;
int nextChangeTime = 0;
void Start()
{
Config.LoadConfigFromIni();
SetConfig();
Config.LoadCardsInDir();
InitIdx();
LoadCard(Config.cardPath);
}
void SetConfig()
{
if (Config.fullscreen == 1)
{
Screen.SetResolution(7680, 4320, true);
}
else
{
Screen.SetResolution(1280, 720, false);
}
if (Config.cardPath == "" || Config.cardPath == "null")
{
Config.cardPath = FileUtil.OpenFile();
Config.SaveConfigToIni();
}
Camera camera = GetComponent<Camera>();
camera.orthographicSize = Config.cameraSize;
camera.transform.position =
new Vector3(Config.cameraX, Config.cameraY, -10);
}
void LoadCard(string cardPath)
{
if (cntCard) Destroy(cntCard);
if (bundle) bundle.Unload(true);
bundle = AssetBundle.LoadFromFile(cardPath);
foreach (var name in bundle.GetAllAssetNames())
{
Debug.Log(name);
cntCard = (GameObject)Instantiate(bundle.LoadAsset(name));
}
Config.cardPath = cardPath;
Config.SaveConfigToIni();
nextChangeTime = (int)Time.time + Config.changeTime;
}
void InitIdx()
{
for (int i = 0; i < Config.cardsCount; ++i)
{
if (Config.cardsList[i] == Config.cardPath)
{
idx = i;
}
}
}
void Update()
{
if (Config.autoChange == 1 && Time.time >= nextChangeTime && cntCard)
{
LoadNextCard();
}
//SetResolution();
}
public void AdjustYAdd()
{
Config.cameraY += 0.1f;
Config.SaveConfigToIni();
Camera camera = GetComponent<Camera>();
Vector3 vec = camera.transform.position;
vec.y = Config.cameraY;
camera.transform.position = vec;
}
public void AdjustYMinus()
{
Config.cameraY -= 0.1f;
Config.SaveConfigToIni();
Camera camera = GetComponent<Camera>();
Vector3 vec = camera.transform.position;
vec.y = Config.cameraY;
camera.transform.position = vec;
}
public void LoadNextCard()
{
if (Config.randomCard == 1)
{
System.Random ran = new System.Random();
idx = ran.Next(Config.cardsCount);
}
else
{
idx++;
idx %= Config.cardsCount;
}
LoadCard(Config.cardsList[idx]);
}
public void LoadNewCard()
{
LoadCard(FileUtil.OpenFile());
Config.LoadCardsInDir();
InitIdx();
}
public void Quit()
{
Application.Quit();
}
/*
public void SetResolution()
{
if (Screen.fullScreen)
{
return;
}
int curScreenWidth = Screen.width;
int curScreenHeight = Screen.height;
float curScale = (float)curScreenWidth / curScreenHeight;
if (curScale > 16 / 9)
{
int h = (int)((9 * curScreenWidth) / 16);
Screen.SetResolution(curScreenWidth, h, false);
}
else if (curScale < 16 / 9)
{
int w = (int)((16 * curScreenHeight) / 9);
Screen.SetResolution(w, curScreenHeight, false);
}
}
*/
}