示例#1
0
        public static void FillResources(SchedulerStorage storage, int maxCount)
        {
            ResourceStorage resources = storage.ResourceStorage;

            storage.BeginUpdate();
            try {
                resources.Clear();
                int count = Math.Min(maxCount, ResourceList.Count);
                for (int i = 0; i < count; i++)
                {
                    string caption = string.Empty;
                    if (ResourceList.TryGetValue(i, out caption))
                    {
                        if (string.IsNullOrEmpty(caption))
                        {
                            continue;
                        }

                        Resource resource = storage.CreateResource(i);
                        resource.Caption = caption;
                        resources.Add(resource);
                    }
                }
            }
            finally {
                storage.EndUpdate();
            }
        }
示例#2
0
 private void Start()
 {
     if (ResourceStorage == null)
     {
         ResourceStorage = new ResourceStorage(resourceCapacity);
     }
 }
示例#3
0
    ResourceStorage FindClosestStorage()
    {
        ResourceStorage[] storages         = FindObjectsOfType <ResourceStorage>();
        float             shortestDistance = float.MaxValue;
        ResourceStorage   closestStorage   = null;

        foreach (ResourceStorage rs in storages)
        {
            if (rs.isPersonal)
            {
                continue;
            }
            if (rs.isResource)
            {
                continue;
            }
            if (!rs.CanStore(resourceType))
            {
                continue;
            }

            float dist = Vector3.Distance(transform.position, rs.transform.position);
            if (dist < shortestDistance)
            {
                closestStorage   = rs;
                shortestDistance = dist;
            }
        }
        return(closestStorage);
    }
示例#4
0
    private void Awake()
    {
        GameObject         timeProvidersGo           = new GameObject("-TimeProvider");
        SimpleTimeProvider mainCoroutineTimeProvider = timeProvidersGo.AddComponent <SimpleTimeProvider>();

        coroutineManager = new CoroutineManager();
        coroutineManager.TimeProvider = mainCoroutineTimeProvider;

        resourceStorage = new ResourceStorage(100);

        //Loader for load any file from www
        WebRequestLoader webLoader = new WebRequestLoader(coroutineManager);

        //Creator for cast loaded by www byte[] to string
        webLoader.RegisterResourceCreator(new StringDataCreator());


        //Loader to load bundle from disk
        LocalFolderBundlesLoader bundlesLoader = new LocalFolderBundlesLoader(bundlesFolderPath, coroutineManager);

        //Loader to load bundle from server static folder
        //WebRequestBundlesLoader bundlesLoader = new WebRequestBundlesLoader(bundlesFolderPath, coroutineManager);

        resourceStorage.RegisterResourceLoader(webLoader);
        resourceStorage.RegisterResourceLoader(bundlesLoader);

        coroutineManager.StartCoroutine(this, WorkProcess());
    }
    /*
     * private int CalculateMaxCraftQuantity(ResourceStorage availiable, Characteristics needed)
     * {
     *  characteristics /= quantity;
     *  quantity = 1;
     *  List<int> resourcesNeeded = new List<int>
     *  {
     *      needed.healingPlantsNeeded,
     *      needed.chemistryNeeded,
     *      needed.plasticNeeded
     *  };
     *  List<int> resourcesAvailiable = new List<int>
     *  {
     *      availiable.currentHealingPlants,
     *      availiable.currentChemistry,
     *      availiable.currentPlastic
     *  };
     *  int indexOfMinimalResources = resourcesAvailiable.IndexOf(resourcesAvailiable.Min());
     *  int indexOfMinimalCharacteristics = resourcesNeeded.IndexOf(resourcesNeeded.Min());
     *  int minQuantity1=0, minQuantity2=0, minQuantity3 = 0;
     *  if (resourcesAvailiable[indexOfMinimalResources] < resourcesNeeded[indexOfMinimalResources])
     *  {
     *      return 0;
     *  }
     *  else
     *  {
     *      minQuantity1 = (resourcesNeeded[indexOfMinimalResources]==0)?resourcesAvailiable[indexOfMinimalResources]: (int)(resourcesAvailiable[indexOfMinimalResources] / resourcesNeeded[indexOfMinimalResources]);
     *  }
     *  resourcesAvailiable[indexOfMinimalResources] = 1000000;
     *  indexOfMinimalResources = resourcesAvailiable.IndexOf(resourcesAvailiable.Min());
     *  if (resourcesAvailiable[indexOfMinimalResources] < resourcesNeeded[indexOfMinimalResources])
     *  {
     *      return 0;
     *  }
     *  else
     *  {
     *      minQuantity2 = (resourcesNeeded[indexOfMinimalResources] == 0) ? resourcesAvailiable[indexOfMinimalResources] : (int)(resourcesAvailiable[indexOfMinimalResources] / resourcesNeeded[indexOfMinimalResources]);
     *  }
     *      resourcesAvailiable[indexOfMinimalResources] = 1000000;
     *  indexOfMinimalResources = resourcesAvailiable.IndexOf(resourcesAvailiable.Min());
     *  if (resourcesAvailiable[indexOfMinimalResources] < resourcesNeeded[indexOfMinimalResources])
     *  {
     *      return 0;
     *  }
     *  else
     *  {
     *      minQuantity3 = (resourcesNeeded[indexOfMinimalResources] == 0) ? resourcesAvailiable[indexOfMinimalResources] : (int)(resourcesAvailiable[indexOfMinimalResources] / resourcesNeeded[indexOfMinimalResources]);
     *  }
     *
     *  return new List<int> { minQuantity1, minQuantity2, minQuantity3 }.Min();
     *
     * } */
    private int CalculateMaxCraftQuantity(ResourceStorage availiable, Characteristics needed)
    {
        characteristics /= quantity;
        quantity         = 1;
        List <int> resourcesNeeded = new List <int>
        {
            needed.healingPlantsNeeded,
            needed.chemistryNeeded,
            needed.plasticNeeded
        };
        List <int> resourcesAvailiable = new List <int>
        {
            availiable.currentHealingPlants,
            availiable.currentChemistry,
            availiable.currentPlastic
        };

        if (needed.plasticNeeded == 0)
        {
            resourcesAvailiable.RemoveAt(2); resourcesNeeded.RemoveAt(2);
        }

        int minQuantity1 = 100000, minQuantity2 = 100000, minQuantity3 = 100000;

        CalculateMinimumResources(resourcesAvailiable, resourcesNeeded, out minQuantity1);
        CalculateMinimumResources(resourcesAvailiable, resourcesNeeded, out minQuantity2);
        if (resourcesNeeded.Count > 2)
        {
            CalculateMinimumResources(resourcesAvailiable, resourcesNeeded, out minQuantity3);
        }

        return(new List <int> {
            minQuantity1, minQuantity2, minQuantity3
        }.Min());
    }
示例#6
0
    public void ShowTradeRequest(Player playerToTradeWith, ResourceStorage from, ResourceStorage to)
    {
        var gameController = GetComponent <GameController>();

        tradingViewController.canCancelWithESC = false;
        tradeRequestViewController.Initialize(playerToTradeWith, from, to, gameController.SendTradeRequestAnswer);
    }
示例#7
0
    void PlaceObj(Object obj)
    {
        ResourceController resourceController = GameController.Instance.resourceController;
        ResourceStorage    resourceStorage    = objToPlace.GetComponent <ResourceStorage>();

        if (resourceStorage)
        {
            resourceStorage.AddToStorage();
        }

        GameObject go = Instantiate(objToPlace, ghostObj.transform.position, ghostObj.transform.rotation);

        if (obj.objType == "Wood")
        {
            resourceController.wood -= obj.cost;
        }

        if (obj.objType == "Stone")
        {
            resourceController.stone -= obj.cost;
        }

        audioManager.PlaySound("Build");

        //Debug.Log("Placed " + objToPlace + " at position " + go.transform.position);
    }
    /// <summary>
    /// Gets the available unit to produce for type.
    /// How many unit can produce for type.
    /// This is base on how much resource and available unit space
    /// </summary>
    public int GetAvaliableUnitToProduceForType(CombatUnitType type)
    {
        CombatUnit unit = GetCombatUnitInfoByType(type);

        Dictionary <ResourceType, float> costResource = unit.GetResourceCost;



        if (costResource != null)
        {
            int unitMinProduction = availableUnitToProduce;

            foreach (ResourceType rType in costResource.Keys)
            {
                ResourceStorage rs = Player.Instance.GetResourceStorage(rType);

                unitMinProduction = Mathf.Min(Mathf.FloorToInt(rs.currentResource / costResource[rType]), unitMinProduction);
            }

            return(unitMinProduction);
        }
        else
        {
            Debug.LogError("Combat unit type " + type.ToString() + " has no resource cost setup");

            return(0);
        }
    }
示例#9
0
        private void Shedule_Load(object sender, EventArgs e)
        {
            context = new ClassSRMDataContext(Config.connection);
            DBAppointmentList apts = new DBAppointmentList();

            apts.AddRange(context.DBAppointments.ToArray());

            List <DBResource> resources = new List <DBResource>();

            resources.AddRange(context.DBResources.ToArray());

            AppointmentStorage aptStorage = schedulerStorage1.Appointments;
            ResourceStorage    resStorage = schedulerStorage1.Resources;

            aptStorage.Mappings.AllDay         = "AllDay";
            aptStorage.Mappings.Description    = "Description";
            aptStorage.Mappings.End            = "EndTime";
            aptStorage.Mappings.Label          = "Label";
            aptStorage.Mappings.Location       = "Location";
            aptStorage.Mappings.RecurrenceInfo = "RecurrenceInfo";
            aptStorage.Mappings.ReminderInfo   = "ReminderInfo";
            aptStorage.Mappings.ResourceId     = "CarIdShared";
            aptStorage.Mappings.Start          = "StartTime";
            aptStorage.Mappings.Status         = "Status";
            aptStorage.Mappings.Subject        = "Subject";
            aptStorage.Mappings.Type           = "EventType";

            resStorage.Mappings.Id      = "ID";
            resStorage.Mappings.Caption = "Model";
            resStorage.Mappings.Image   = "Picture";

            resStorage.DataSource = resources;
            aptStorage.DataSource = apts;
            schedulerControl1.GoToToday();
        }
示例#10
0
 public static void PurchaseHouse(ResourceStorage storage)
 {
     storage.wood  = Mathf.Max(0, storage.wood - 1);
     storage.wheat = Mathf.Max(0, storage.wheat - 1);
     storage.wool  = Mathf.Max(0, storage.wool - 1);
     storage.clay  = Mathf.Max(0, storage.clay - 1);
 }
示例#11
0
        public void Init()
        {
            ResourceStorage.DecompressMidiBundle();

            jsonStorage = new JsonStorage();
            jsonStorage.Load();

            uiState          = jsonStorage.Get(JsonStorageKeys.V1.UI_STATE, Storage.Protos.Json.V1.UiStateProto.CreateDefault());
            midiSynthConfigs = jsonStorage.Get(JsonStorageKeys.V1.MIDI_SYNTH_CONFIGS, Storage.Protos.Json.V1.MidiSynthConfigsProto.CreateDefault());
            gameplayConfig   = jsonStorage.Get(JsonStorageKeys.V1.GAMEPLAY_CONFIG, Storage.Protos.Json.V1.GameplayConfigProto.CreateDefault());
            appConfig        = jsonStorage.Get(JsonStorageKeys.V1.APP_CONFIG, Storage.Protos.Json.V1.AppConfigProto.CreateDefault());

            localDb = new LocalDb();
            localDb.Init();

            username = PlayerPrefs.GetString("TEMP_USERNAME", null);
            password = PlayerPrefs.GetString("TEMP_PASSWORD", null);

            netManager = new NetManager();
            netManager.Init(this);

            translationSevice = new TranslationService();
            translationSevice.Init(netManager);
            translationSevice.Load();
            translationSevice.lang = appConfig.displayLang;

            resourceStorage = new ResourceStorage();
            resourceStorage.Init(this);

            InitAudioConfig();
            ApplyAppAudioConfig();
        }
示例#12
0
    public void NewResource(ResourceStorage newRes)
    {
        int       subType      = (int)newRes.res.GetSubType();
        Transform typeCont     = resourcesContainer.transform.GetChild(subType);
        Transform newResParent = typeCont;

        if (typeCont.childCount == 0 || typeCont.GetChild(typeCont.childCount - 1).childCount == 3)
        {
            GameObject newBar = (GameObject)Instantiate(resourceBarPre, transform.position, transform.rotation);
            newResParent = newBar.transform;
            newResParent.SetParent(typeCont, false);
        }
        else
        {
            newResParent = typeCont.GetChild(typeCont.childCount - 1);
        }
        GameObject newResElement = (GameObject)Instantiate(resourceElementPre, transform.position, transform.rotation);

        newResElement.transform.SetParent(newResParent);
        newResElement.transform.GetChild(0).gameObject.GetComponent <Image>().sprite         = newRes.res.GetIcon();
        newResElement.transform.GetChild(1).gameObject.GetComponent <TextMeshProUGUI>().text = newRes.amount + "";
        resElements.Add(newRes.res, newResElement);
        typeCont.GetComponent <LayoutGroup>().SetLayoutVertical();
        LayoutRebuilder.ForceRebuildLayoutImmediate(typeCont.GetComponent <RectTransform>());
        resourcesContainer.GetComponent <LayoutGroup>().SetLayoutVertical();
        LayoutRebuilder.ForceRebuildLayoutImmediate(resourcesContainer.GetComponent <RectTransform>());
        resourcesPanel.GetComponent <LayoutGroup>().SetLayoutVertical();
        LayoutRebuilder.ForceRebuildLayoutImmediate(resourcesPanel.GetComponent <RectTransform>());
    }
示例#13
0
    public void AddResource(ResourceStorage newRes)
    {
        int baseType = (int)newRes.res.GetBaseType();

        if (baseType == 1)
        {
            woodRes.amount += newRes.amount;
            ui.SetWood(woodRes.amount);
        }
        else if (baseType == 2)
        {
            stoneRes.amount += newRes.amount;
            ui.SetStone(stoneRes.amount);
        }
        else
        {
            int resIndex = GetResourceIndex(newRes);
            if (resIndex == -1)
            {
                resources.Add(newRes);
                ui.NewResource(newRes);
            }
            else
            {
                if (baseType == 0)
                {
                    foodTotal += newRes.amount;
                    ui.SetFood(foodTotal);
                }
                resources[resIndex].amount += newRes.amount;
                ui.UpdateResourceValue(resources[resIndex]);
            }
        }
    }
示例#14
0
    public void TryAddRejectsNegativeNextAmount()
    {
        var storage = new ResourceStorage(100);

        Assert.IsFalse(storage.TryAddDelta(new ResourceDelta(ResourceType.Air, -10)));
        Assert.AreEqual(0, storage.NextAmount);
    }
    public void ShowResources(string playerName, ResourceStorage storage)
    {
        Debug.Log("ShowResources called!");

        gameObject.SetActive(true);

        text.text = $"{playerName} gained:";
        text.GetComponent <GraphicFade>().FadeInAndOut(1f, 5f);
        if (storage.IsEmpty())
        {
            text.text = $"{playerName} gained nothing";
            wood.SetActive(false);
            stone.SetActive(false);
            clay.SetActive(false);
            wheat.SetActive(false);
            wool.SetActive(false);
            return;
        }


        ShowResource(storage.wood, this.wood);
        ShowResource(storage.stone, this.stone);
        ShowResource(storage.clay, this.clay);
        ShowResource(storage.wheat, this.wheat);
        ShowResource(storage.wool, this.wool);
    }
示例#16
0
 void Start()
 {
     resources = ResourceStorage._instance;
     woodT     = GameObject.Find("ResourceBar/Wood").GetComponent <Text>();
     stoneT    = GameObject.Find("ResourceBar/Stone").GetComponent <Text>();
     goldT     = GameObject.Find("ResourceBar/Gold").GetComponent <Text>();
 }
示例#17
0
    void Update()
    {
        if (locatedResource == null || !locatedResource.CanStore(resourceType))
        {
            locatedResource = FindClosestResource();
        }
        if (locatedStorage == null)
        {
            locatedStorage = FindClosestStorage();
        }

        if (state == State.IDLE)
        {
            DetermineState();
        }

        switch (state)
        {
        case State.COMMANDED:
            CommandedActions();
            break;

        case State.TRAVELLING:
            MoveTowardsTarget();
            break;

        case State.HARVESTING:
            HarvestResource();
            break;

        case State.DELIVERING:
            DeliverResource();
            break;
        }
    }
示例#18
0
    public void SetPanel(ResourceStorage storage)
    {
        if (!gameObject.activeInHierarchy)
        {
            gameObject.SetActive(true);
        }
        if (herbs != null)
        {
            CheckForChanges(herbs, storage.currentHealingPlants, Color.green);


            herbs.text = storage.currentHealingPlants.ToString() + " / " + storage.MaxHealingPlants.ToString();
        }
        if (chems != null)
        {
            CheckForChanges(chems, storage.currentChemistry, Color.magenta);
            chems.text = storage.currentChemistry.ToString() + " / " + storage.MaxChemistry.ToString();
        }
        if (plastic != null)
        {
            CheckForChanges(plastic, storage.currentPlastic, Color.white);
            plastic.text = storage.currentPlastic.ToString() + " / " + storage.MaxPlastic.ToString();
        }
        if (researchPoints != null)
        {
            CheckForChanges(researchPoints, storage.ResearchPoints, Color.cyan);

            researchPoints.text = storage.ResearchPoints.ToString();
        }
        if (money != null)
        {
            CheckForChanges(money, storage.money, Color.green);
            money.text = storage.money.ToString();
        }
    }
示例#19
0
 public void Dump(ResourceStorage other)
 {
     for (int i = 0; i < (int)ResourceType.Count; i++)
     {
         AddResource(i, other.TakeAll(i));
     }
 }
        void AddFileToProject(ResourceStorage storage)
        {
            FileName resourceFileName = storage.OpenedFile.FileName;
            FileName formFileName     = viewContent.PrimaryFileName;
            IProject project          = SD.ProjectService.FindProjectContainingFile(formFileName);

            // Add this resource file to the project
            if (project != null && !project.IsFileInProject(resourceFileName))
            {
                FileProjectItem newFileProjectItem = new FileProjectItem(project, ItemType.EmbeddedResource);
                newFileProjectItem.DependentUpon = Path.GetFileName(formFileName);
                newFileProjectItem.Include       = FileUtility.GetRelativePath(project.Directory, resourceFileName);
                ProjectService.AddProjectItem(project, newFileProjectItem);
                FileService.FireFileCreated(resourceFileName, false);

                PadDescriptor pd           = SD.Workbench.GetPad(typeof(ProjectBrowserPad));
                FileNode      formFileNode = ((ProjectBrowserPad)pd.PadContent).ProjectBrowserControl.FindFileNode(formFileName);
                if (formFileNode != null)
                {
                    LoggingService.Info("FormFileNode found, adding subitem");
                    FileNode fileNode = new FileNode(resourceFileName, FileNodeStatus.BehindFile);
                    fileNode.AddTo(formFileNode);
                    fileNode.ProjectItem = newFileProjectItem;
                }
                project.Save();
            }
        }
示例#21
0
 public CollectResourceBuildingTile(Vector2 mapLoc, Vector3 worldLoc, char type, GameObject tileObj, CollectResourceBuildingTile tileToCopy, bool isTrees)
     : base(mapLoc, worldLoc, type, tileObj, new Vector2(1, 1))
 {
     CopyTile(tileToCopy);
     this.woodRes  = tileToCopy.woodRes;
     this.stoneRes = tileToCopy.stoneRes;
     this.isTrees  = isTrees;
 }
示例#22
0
        public override void Init(SongSelectLevelScheduler levelScheduler)
        {
            base.Init(levelScheduler);

            titleText.text = "";

            res = game.resourceStorage;
        }
示例#23
0
 public SessionDataPackage()
 {
     Researches      = new Researches();
     ResourceStorage = new ResourceStorage();
     BranchBase      = new BranchBase(new Vector2Int(24, 39));
     Warehouse       = new Warehouse();
     Bureau          = new Bureau();
 }
        public override void Init(SongSelectLevelScheduler levelScheduler)
        {
            base.Init(levelScheduler);

            db  = GameScheduler.instance.localDb;
            res = GameScheduler.instance.resourceStorage;
            web = WebCache.instance;
        }
示例#25
0
 public void AddResources(ResourceStorage storage)
 {
     wood  += storage.wood;
     stone += storage.stone;
     clay  += storage.clay;
     wheat += storage.wheat;
     wool  += storage.wool;
 }
示例#26
0
 public override void Init(SongSelectLevelScheduler level)
 {
     base.Init(level);
     net = game.netManager;
     web = WebCache.instance;
     res = game.resourceStorage;
     db  = game.localDb;
 }
    private IEnumerator WorkProcess()
    {
        string manifestPath = String.Empty;
        string bundlesPath  = String.Empty;

#if UNITY_EDITOR
        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json"))
            {
                manifestPath = AssetDatabase.GUIDToAssetPath(findAsset);
                break;
            }
        }

        foreach (var findAsset in AssetDatabase.FindAssets(bundlesFolderPath))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".u3d"))
            {
                bundlesPath = AssetDatabase.GUIDToAssetPath(findAsset).Replace(bundlesFolderPath + ".u3d", "");

                bundlesPath = Application.dataPath.Replace("/Assets", "/") + bundlesPath;
                break;
            }
        }

        resourceStorage = new ResourceStorage(100);

        UnityResourceFromBundleLoader resFromBundlesLoader = new UnityResourceFromBundleLoader(coroutineManager);
        LocalFolderBundlesLoader      bundlesLoader        = new LocalFolderBundlesLoader(bundlesPath, coroutineManager);

        resourceStorage.RegisterResourceLoader(resFromBundlesLoader);
        resourceStorage.RegisterResourceLoader(bundlesLoader);


        var manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath);

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetBundleManifest>(manifest.text);
        bundlesLoader.Manifest.AddManifestPart(manifestAsJson);
#endif

        var loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName);
        yield return(loadPrefab);

        Instantiate(loadPrefab.Resource);

        //Del me
        resourceStorage.ReleaseFromCache(this, resourceName);

        loadPrefab = resourceStorage.LoadResource <GameObject>(this, resourceName);
        yield return(loadPrefab);

        Instantiate(loadPrefab.Resource);
    }
    public override void OnCycle()
    {
        base.OnCycle();

        if (rules.Length > 0)
        {
            for (int i = 0; i < rules.Length; ++i)
            {
                // OUTPUT
                if (rules[i].isRunning)
                {
                    bool canOutput = true;
                    foreach (ResourceQuantity resource in rules[i].output)
                    {
                        ResourceStorage storage = planet.GetResourceStorage(resource.type);
                        if ((storage.maxStorage - storage.stored) < resource.quantity)
                        {
                            canOutput = false;
                            break;
                        }
                    }

                    if (canOutput)
                    {
                        foreach (ResourceQuantity resource in rules[i].output)
                        {
                            planet.AddResource(resource.type, resource.quantity);
                        }
                        rules[i].isRunning = false;
                    }
                }

                // INPUT
                if (!rules[i].isRunning)
                {
                    bool canInput = true;
                    foreach (ResourceQuantity resource in rules[i].input)
                    {
                        ResourceStorage storage = planet.GetResourceStorage(resource.type);
                        if (storage.stored < resource.quantity)
                        {
                            canInput = false;
                            break;
                        }
                    }

                    if (canInput)
                    {
                        foreach (ResourceQuantity resource in rules[i].input)
                        {
                            planet.RemoveResource(resource.type, resource.quantity);
                        }
                        rules[i].isRunning = true;
                    }
                }
            }
        }
    }
示例#29
0
    private void Awake()
    {
        discCacheFolderPath = Application.dataPath + discCacheFolderPath;
        GameObject         timeProvidersGo           = new GameObject("-TimeProvider");
        SimpleTimeProvider mainCoroutineTimeProvider = timeProvidersGo.AddComponent <SimpleTimeProvider>();

        coroutineManager = new CoroutineManager();
        coroutineManager.TimeProvider = mainCoroutineTimeProvider;

#if UNITY_EDITOR
        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json") && AssetDatabase.GUIDToAssetPath(findAsset).Contains("/Sources/"))
            {
                serverUrl = Application.dataPath.Replace("/Assets", "/") + AssetDatabase.GUIDToAssetPath(findAsset).Replace(manifestName + ".json", "");
                break;
            }
        }

        discCacheFolderPath = serverUrl.Replace("/Sources/", "/FileCacheForExample");


        foreach (var findAsset in AssetDatabase.FindAssets(manifestName))
        {
            if (AssetDatabase.GUIDToAssetPath(findAsset).Contains(".json"))
            {
                manifestPath = AssetDatabase.GUIDToAssetPath(findAsset);
                break;
            }
        }
#endif
        resourceStorage = new ResourceStorage(100);

        var textureCreator = new TextureDataCreator();

        var versionedResourceLoader = new VersionedDiskCachedResourceLoader(discCacheFolderPath, "file://" + serverUrl, coroutineManager);
        versionedResourceLoader.RegisterResourceCreator(textureCreator);
        resourceStorage.RegisterResourceLoader(versionedResourceLoader);

        loaderPrefix = versionedResourceLoader.SupportsMask;
        TextAsset manifest = null;
#if UNITY_EDITOR
        manifest = AssetDatabase.LoadAssetAtPath <TextAsset>(manifestPath);
#endif

        var jsonSerializer =
            new JsonSerializer(new JsonSerializerSettings {
            Formatting = Formatting.Indented
        }, Encoding.UTF8);
        var manifestAsJson = jsonSerializer.DeserializeString <AssetFilesManifest>(manifest.text);

        versionedResourceLoader.Manifest.AddManifestPart(manifestAsJson);

        _loadImageVersion1.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer1Process()); });

        _loadImageVersion2.onClick.AddListener(() => { coroutineManager.StartCoroutine(this, LoadImageVer2Process()); });
    }
示例#30
0
    public void UpdateResourceValue(ResourceStorage updateRes)
    {
        GameObject updateResElement = resElements[updateRes.res];

        if (updateResElement)
        {
            updateResElement.transform.GetChild(1).gameObject.GetComponent <TextMeshProUGUI>().text = updateRes.amount + "";
        }
    }
示例#31
0
		void CreateOpenedFileForStorage(ResourceStorage storage, string fileName, bool isExistingFile)
		{
			storage.OpenedFile = FileService.GetOrCreateOpenedFile(fileName);
			storage.IsNewFile = !isExistingFile;
			if (!isExistingFile && storage.OpenedFile.RegisteredViewContents.Count == 0) {
				storage.OpenedFile.SetData(new byte[0]);
			}
			resourceByFile[storage.OpenedFile] = storage;
			// adding the opened file to the view content will load the file content into ResourceStorage.buffer
			viewContent.AddResourceFile(storage.OpenedFile);
		}
示例#32
0
		void AddFileToProject(ResourceStorage storage)
		{
			string resourceFileName = storage.OpenedFile.FileName;
			string formFileName = viewContent.PrimaryFileName;
			IProject project = GetProject(formFileName);
			
			// Add this resource file to the project
			if (project != null && !project.IsFileInProject(resourceFileName)) {
				FileProjectItem newFileProjectItem = new FileProjectItem(project, ItemType.EmbeddedResource);
				newFileProjectItem.DependentUpon = Path.GetFileName(formFileName);
				newFileProjectItem.Include = FileUtility.GetRelativePath(project.Directory, resourceFileName);
				ProjectService.AddProjectItem(project, newFileProjectItem);
				FileService.FireFileCreated(resourceFileName, false);

				PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(ProjectBrowserPad));
				FileNode formFileNode = ((ProjectBrowserPad)pd.PadContent).ProjectBrowserControl.FindFileNode(formFileName);
				if (formFileNode != null) {
					LoggingService.Info("FormFileNode found, adding subitem");
					FileNode fileNode = new FileNode(resourceFileName, FileNodeStatus.BehindFile);
					fileNode.AddTo(formFileNode);
					fileNode.ProjectItem = newFileProjectItem;
				}
				project.Save();
			}
		}
		public System.Resources.IResourceWriter GetResourceWriter(CultureInfo info)
		{
			try {
				LoggingService.Debug("ResourceWriter requested for culture: " + info.ToString());
				ResourceStorage resourceStorage;
				if (resources.ContainsKey(info.Name)) {
					resourceStorage = resources[info.Name];
				} else {
					resourceStorage = new ResourceStorage();
					resources[info.Name] = resourceStorage;
				}
				return resourceStorage.GetWriter();
			} catch (Exception e) {
				MessageService.ShowError(e.Message);
				return null;
			}
		}
		public System.Resources.IResourceReader GetResourceReader(System.Globalization.CultureInfo info)
		{
			try {
				LoggingService.Debug("ResourceReader requested for culture: "+info.ToString());
				ResourceStorage resourceStorage;
				if (resources != null && resources.ContainsKey(info.Name)) {
					resourceStorage = resources[info.Name];
				} else {
					resourceStorage = new ResourceStorage();
					resources[info.Name] = resourceStorage;
				}
				return resourceStorage.GetReader(CalcResourceFileName(FormFileName, info.Name));
			} catch (Exception e) {
				MessageService.ShowError(e.Message);
				return null;
			}
		}