UIHomeConnectedDieToken CreateConnectedDieToken(Dice.EditDie die) { var ret = GameObject.Instantiate <UIHomeConnectedDieToken>(connectedDiePrefab, Vector3.zero, Quaternion.identity, connectedDieRoot.transform); ret.Setup(die); return(ret); }
void OnBehaviorDownloadedEvent(Dice.EditDie die, Behaviors.EditBehavior behavior) { // Check whether we should stay connected to some of the dice List <EditDie> toDisconnect = new List <EditDie>(connectedDice); if (behavior.CollectAudioClips().Any()) { // This die assignment uses a behavior that has audio clips, so stay connected to the die if (connectedDice.Contains(die)) { toDisconnect.Remove(die); } else if (die != null) { // Connect to the new die connectedDice.Add(die); DiceManager.Instance.ConnectDie(die, (d, res, _) => { if (!res) { connectedDice.Remove(d); } }); } } foreach (var d in toDisconnect) { connectedDice.Remove(d); DiceManager.Instance.DisconnectDie(d, null); } }
UILiveDieEntry CreateEntry(Dice.EditDie die, int roll) { // Create the gameObject var ret = GameObject.Instantiate <UILiveDieEntry>(dieEntryPrefab, Vector3.zero, Quaternion.identity, contentRoot.transform); // Initialize it ret.Setup(die, roll, Time.time); return(ret); }
public bool ShowDiePicker(string title, Dice.EditDie previousDie, System.Func <Dice.EditDie, bool> selector, System.Action <bool, Dice.EditDie> closeAction) { bool ret = !diePicker.isShown; if (ret) { diePicker.Show(title, previousDie, selector, closeAction); } return(ret); }
public void Setup(Dice.EditDie die) { editDie = die; this.dieRenderer = DiceRendererManager.Instance.CreateDiceRenderer(die.designAndColor); if (dieRenderer != null) { dieRenderImage.texture = dieRenderer.renderTexture; } dieNameText.text = die.name; }
public void UploadBehavior(Behaviors.EditBehavior behavior, Dice.EditDie die, System.Action <bool> callback) { UpdateDieDataSet(behavior, die, (res) => { if (res) { // We're done! callback?.Invoke(true); } else { callback?.Invoke(false); } }); }
void OnDieUpdatedEvent(Dice.EditDie die, Behaviors.EditBehavior behavior) { UpdatePresetAndBehaviorStatuses(); }
public void UpdateDieDataSet(Behaviors.EditBehavior behavior, Dice.EditDie die, System.Action <bool> callback) { // Make sure the die is ready! ShowProgrammingBox("Connecting to " + die.name + "..."); DiceManager.Instance.ConnectDie(die, (editDie, res, message) => { if (res) { // The die is ready to be uploaded to // Generate the data to be uploaded EditDataSet editSet = new EditDataSet(); // Grab the behavior editSet.behavior = behavior.Duplicate(); // And add the animations that this behavior uses var animations = editSet.behavior.CollectAnimations(); // Add default rules and animations to behavior / set if (AppDataSet.Instance.defaultBehavior != null) { // Rules that are in fact copied over var copiedRules = new List <EditRule>(); foreach (var rule in AppDataSet.Instance.defaultBehavior.rules) { if (!editSet.behavior.rules.Any(r => r.condition.type == rule.condition.type)) { var ruleCopy = rule.Duplicate(); copiedRules.Add(ruleCopy); editSet.behavior.rules.Add(ruleCopy); } } // Copied animations var copiedAnims = new Dictionary <Animations.EditAnimation, Animations.EditAnimation>(); // Add animations used by default rules foreach (var editAnim in AppDataSet.Instance.defaultBehavior.CollectAnimations()) { foreach (var copiedRule in copiedRules) { if (copiedRule.DependsOnAnimation(editAnim)) { Animations.EditAnimation copiedAnim = null; if (!copiedAnims.TryGetValue(editAnim, out copiedAnim)) { copiedAnim = editAnim.Duplicate(); animations.Add(copiedAnim); copiedAnims.Add(editAnim, copiedAnim); } copiedRule.ReplaceAnimation(editAnim, copiedAnim); } } } } editSet.animations.AddRange(animations); foreach (var pattern in AppDataSet.Instance.patterns) { bool asRGB = false; if (animations.Any(anim => anim.DependsOnPattern(pattern, out asRGB))) { if (asRGB) { editSet.rgbPatterns.Add(pattern); } else { editSet.patterns.Add(pattern); } } } // Set the behavior var dataSet = editSet.ToDataSet(); // Check the dataset against the one stored in the die var hash = dataSet.ComputeHash(); // Get the hash directly from the die editDie.die.GetDieInfo((info_res) => { if (info_res) { if (hash != editDie.die.dataSetHash) { // We need to upload the dataset first Debug.Log("Uploading dataset to die " + editDie.name); var dataSetDataSize = dataSet.ComputeDataSetDataSize(); Debug.Log("Dataset data size " + dataSetDataSize); UpdateProgrammingBox(0.0f, "Uploading data to " + editDie.name + "..."); editDie.die.UploadDataSet(dataSet, (pct) => { UpdateProgrammingBox(pct, "Uploading data to " + editDie.name + "..."); }, (res2, errorMsg) => { if (res2) { editDie.die.GetDieInfo(res3 => { if (res3) { HideProgrammingBox(); if (hash != editDie.die.dataSetHash) { ShowDialogBox("Error verifying data sent to " + editDie.name, message, "Ok", null, null); callback?.Invoke(false); } else { die.currentBehavior = behavior; AppDataSet.Instance.SaveData(); onDieBehaviorUpdatedEvent?.Invoke(die, die.currentBehavior); callback?.Invoke(true); } DiceManager.Instance.DisconnectDie(editDie, null); } else { HideProgrammingBox(); ShowDialogBox("Error fetching profile hash value from " + editDie.name, message, "Ok", null, null); DiceManager.Instance.DisconnectDie(editDie, null); callback?.Invoke(false); } }); } else { HideProgrammingBox(); ShowDialogBox("Error uploading data to " + editDie.name, errorMsg, "Ok", null, null); DiceManager.Instance.DisconnectDie(editDie, null); callback?.Invoke(false); } }); } else { Debug.Log("Die " + editDie.name + " already has preset with hash 0x" + hash.ToString("X8") + " programmed."); HideProgrammingBox(); ShowDialogBox("Profile already Programmed", "Die " + editDie.name + " already has profile \"" + behavior.name + "\" programmed.", "Ok", null, null); DiceManager.Instance.DisconnectDie(editDie, null); callback?.Invoke(true); } } else { HideProgrammingBox(); ShowDialogBox("Error verifying profile hash on " + editDie.name, message, "Ok", null, null); DiceManager.Instance.DisconnectDie(editDie, null); callback?.Invoke(false); } }); } else { HideProgrammingBox(); ShowDialogBox("Error connecting to " + editDie.name, message, "Ok", null, null); callback(false); } }); }
public IEnumerable <Presets.EditPreset> CollectPresetsForDie(Dice.EditDie die) { return(presets.Where(b => b.DependsOnDie(die))); }