public void OpenCreditsDialog(Action onCloseCallback = null) { var creditsDialogGo = Object.Instantiate(GlobalParams.CommonAssets.CreditsDialog, _moduleManager.CurrentModule.DialogsContainer); _creditsDialog = creditsDialogGo.GetComponent <CreditsDialog>(); _creditsDialog.Connect(OnCreditsDialogCloseClick, onCloseCallback); }
private IEnumerable <CarSpawner> CarSpawnerGen() { var obj = CarSpawner.Prefab; var carSpawners = new List <CarSpawner>(Constants.RoadEntryCount); while (_graph.Count < Constants.RoadEntryCount)//entry generation { Hex position; Hex unscaledPosition; var objSpawner = Object.Instantiate(obj).GetComponent <CarSpawner>(); do { var edge = Random.Range(0, 4); var pos = Random.Range(0, Constants.WorldSize + 2) / 2; var arr = new[] { pos, Constants.WorldSize / 2 - 1, pos, 0 }; position = new Hex(arr[edge], arr[(edge + 1) % 4]); unscaledPosition = Unscaled(position); }while (objSpawner.BottomDraft.Keys.Any(h => _map.IsOccupied(h + unscaledPosition))); objSpawner.Position = unscaledPosition; objSpawner.MoveTransform(); _graph.Add(position); carSpawners.Add(objSpawner); } return(carSpawners); }
private SceneCardView CreateCardView() { SceneCardView sceneCardView = Object.Instantiate(sceneCardViewPrefab); sceneCardView.gameObject.SetActive(false); return(sceneCardView); }
protected override void Execute(List <GameEntity> entities) { var insideWorkbench = _insideWorkbench.GetEntities(); var recipe = _contexts.game.currentBossEntity.recipe.value; _recipeItems.Clear(); _used.Clear(); var correct = true; foreach (var requiredIngredientDesc in recipe.Ingredients) { _recipeItems[Helper.GetId(requiredIngredientDesc.Type, requiredIngredientDesc.Color)] = requiredIngredientDesc.Amount; } foreach (var insideItem in insideWorkbench) { var id = Helper.GetId(insideItem.ingredient.value, insideItem.color.value); var amount = 0; if (_recipeItems.TryGetValue(id, out amount)) { if (amount > 0) { _recipeItems[id] = amount - 1; _used.Add(insideItem); } } else { correct = false; break; } } if (correct) { if (_recipeItems.All(x => x.Value == 0)) { var newProjectile = _contexts.game.CreateEntity(); var projectileInstance = Object.Instantiate(recipe.ProjectilePrefab); projectileInstance.SetActive(false); newProjectile.AddGameObject(projectileInstance); newProjectile.isInsideInventory = true; newProjectile.AddUsage(UsageType.Weapon); newProjectile.AddRecipe(recipe); newProjectile.AddIcon(recipe.Icon); var link = projectileInstance.AddComponent <GameObjectEntityLink>(); link.Entity = newProjectile; foreach (var gameEntity in _used) { gameEntity.isDestroy = true; } } } }
public void SetCheckpointPosition(int idx, Vec3 pos) { if (idx == checkpoint && !this.didSpawnPlayer) { this.playerInstance = Obj.Instantiate(this.player, pos, Quat.identity); this.didSpawnPlayer = true; } }
private static Road InstantiateRoadObj(Road road, Orientation orientation, Hex position) { var obj = Object.Instantiate(road); obj.Position = RoadController.Unscaled(position); obj.MoveTransform(); obj.SetOrientation(orientation); MapManager.Instance.Map.SetNewOwner(obj); obj.transform.SetParent(RoadPool.Instance.transform); return(obj); }
public T Create <T>() where T : Showable { var type = typeof(T); if (_instantiatedShowables.ContainsKey(type)) { return((T)_instantiatedShowables[type]); } var showable = Object.Instantiate(_showables[type]); _instantiatedShowables.Add(type, showable); return((T)showable); }
// Create an instance of the blueprint and return it private T NewObject(T blueprint) { if (CreateFunction != null) { return(CreateFunction(blueprint)); } if (blueprint == null || !(blueprint is Object)) { return(null); } return(Object.Instantiate(blueprint as Object) as T); }
private IOwnerInfoElement GetElement() { IOwnerInfoElement ret; if (elementsPool.Count > 0) { ret = elementsPool.Dequeue(); } else { ret = Object.Instantiate(ownerElementPrefab); } return(ret); }
public WorldSegment CreateSegment(WorldSegment prefab) { var newSegment = Object.Instantiate(prefab); var lastSegment = segments.LastOrDefault(); if (lastSegment != null) { newSegment.AnchorRight(lastSegment); } segments.Add(newSegment); OnSegmentCreated?.Invoke(newSegment); return(newSegment); }
private void createDetector(RelPos p) { UnityEngine.Transform t = this.transform; Vec3 newPos; GO clone; newPos = this.getRelPos(p); /* XXX: This was the only way I found to instantiate the clone * in local space... */ clone = Obj.Instantiate(this.dummy, t.position, Quat.identity, t); clone.name = p.ToString(); clone.transform.Translate(newPos, UnityEngine.Space.World); RelCol rc = clone.GetComponent <RelCol>(); rc.pos = p; }
private System.Collections.IEnumerator delayedSetPlayer(bool getCheckpointIdx) { Vec3 p; p = this.transform.position; float delay = p.y / 100.0f; yield return(new UnityEngine.WaitForSeconds(delay)); if (getCheckpointIdx) { this.rootEvent <LoaderEvents>( (x, y) => x.GetCheckpointCount(out this.checkPointIdx)); } if (UnityEngine.Application.isEditor && this.dbgCamera != null && UnityEngine.Camera.main == null) { /* XXX: If testing a particular scene, it won't have neither the * camera nor the player (as those are maintained by the loader * scene)... So spawn them here. */ Obj.Instantiate(this.dbgCamera, new Vec3(), Quat.identity); this.dbgPlayerInstance = Obj.Instantiate(this.dbgPlayer, p, Quat.identity); /* XXX: Set this as the root object so the camera may retrieve * the player */ BaseRemoteAction.root = this.gameObject; } if (this.checkPointIdx > 0) { p.y += 2.0f; } this.rootEvent <LoaderEvents>( (x, y) => x.SetCheckpointPosition(this.checkPointIdx, p)); if (UnityEngine.Application.isEditor && this.dbgCamera != null && UnityEngine.Camera.main == null) { this.destroy(); } }
static private GO spawnCopy(GO template, Transform parent, float x, float y, float w, float h) { GO newGo; UiTransform rect; const Axis hor = Axis.Horizontal; const Axis vert = Axis.Vertical; newGo = Obj.Instantiate(template, parent.position, Quat.identity, parent); rect = newGo.AddComponent <UiTransform>(); rect.pivot = new Vec2(0.0f, 1.0f); rect.anchorMin = new Vec2(0.0f, 1.0f); rect.anchorMax = new Vec2(0.0f, 1.0f); rect.anchoredPosition = new Vec2(x, -y); rect.SetSizeWithCurrentAnchors(vert, h); rect.SetSizeWithCurrentAnchors(hor, w); return(newGo); }
void Start() { GO tracker = new GO(); tracker.layer = this.gameObject.layer; RB rb = tracker.AddComponent <RB>(); rb.useGravity = false; rb.isKinematic = true; SC sc = tracker.AddComponent <SC>(); sc.radius = 0.125f; sc.isTrigger = true; tracker.AddComponent <RelCol>(); /* Generate as many detectors as requested */ Tr t = this.transform; for (int i = 1; i <= this.MaxDepth; i++) { /* XXX: (again) This was the only way I found to instantiate * the clone in local space... */ GO obj = Obj.Instantiate(tracker, t.position, Quat.identity, t); obj.name = $"ShadowTracker_{i}"; Vec3 pos = new Vec3(0.0f, i * -1.0f, 0.0f); obj.transform.Translate(pos, UnityEngine.Space.World); } Obj.DestroyImmediate(tracker); for (int i = 0; i < this.MaxDepth * 2; i++) { List node = new List(); node.next = this.emptyList; this.emptyList = node; } this.touchingList = null; this.self = this.transform; }
private void createLevelSelector(int idx) { UnityEngine.Transform t = this.view.content.transform; GO lvl; RectT rect; RawImage img; UiText txt; lvl = Obj.Instantiate(this.template, t.position, Quat.identity, t); rect = lvl.GetComponent <RectT>(); float left = 16.0f / this.viewWidth; float right = 1.0f - 16.0f / this.viewWidth; /* XXX: 1.0f == top, 0.0f == bottom */ float bottom = elementDist; bottom += (idx - 1) * (elementHeight + elementDist); float top = bottom + elementHeight; bottom = 1.0f - bottom / this.viewHeight; top = 1.0f - top / this.viewHeight; rect.anchorMin = new Vec2(left, top); rect.anchorMax = new Vec2(right, bottom); rect.anchoredPosition = new Vec2(0, 0); /* XXX: Unity is terrible at sending events downward... So just... * whatever */ lvl.GetComponentInChildren <LoadLevelOnClick>().idx = idx; img = lvl.GetComponentInChildren <RawImage>(); img.texture = CreateLevelSelectors.cache[this.curIdx].tex; img.material = CreateLevelSelectors.cache[this.curIdx].mat; txt = lvl.GetComponentInChildren <UiText>(); txt.text = CreateLevelSelectors.cache[this.curIdx].name; }
public static T Instantiate <T>(GameObject prefab, Vector3 position, Quaternion rotation) where T : Component { return(Object.Instantiate(prefab, position, rotation).GetComponent <T>()); }
public void ResetModel(ILocalNitroxPlayer localPlayer) { Body = Object.Instantiate(localPlayer.BodyPrototype); PlayerModel = Body.RequireGameObject("player_view"); }
public static T Instantiate <T>(T original, Transform parent, bool worldPositionStays) where T : Object { return((T)((object)Object.Instantiate(original, parent, worldPositionStays))); }
public GameObject CreateDefaultGhostGameObject(Entity ent, CreatedGameObjectDelegate onCreatedGameObject = null, CreatedGameObjectDelegate onCreatedLinkTarget = null) { var ghost = EntityManager.GetComponentData <GhostComponent>(ent); bool isInterpolatedClient = !EntityManager.HasComponent <GhostPredictionComponent>(ent); bool isLocalOwner = false; GameObject view; if (IsServer) { view = this.GetByServer(ghost.GhostType); } else { // 客户端频断是否是LocalOwner if (HasSingleton <NetworkIdComponent>() && EntityManager.HasComponent <GhostOwnerComponent>(ent)) { NetworkIdComponent networkIdComponent = GetSingleton <NetworkIdComponent>(); GhostOwnerComponent ownerComponent = EntityManager.GetComponentData <GhostOwnerComponent>(ent); // [客户端特有] isLocalOwner = ownerComponent.Value == networkIdComponent.Value; } // 预制体集合取 view = isInterpolatedClient ? this.GetByInterpolated(ghost.GhostType) : this.GetByPrediction(ghost.GhostType); } view = Object.Instantiate(view); // Entity标识,以便碰撞检测能找到对应的Entity var entityFlag = view.AddComponent <EntityHold>(); entityFlag.Ent = ent; entityFlag.World = World; SceneManager.MoveGameObjectToScene(view, World.GetLinkedScene()); EntityManager.AddComponentData(ent, new GhostGameObjectSystemState()); this.Add(ent, view); onCreatedGameObject?.Invoke(ghost.GhostType, view, this); var linkedGameObject = CreateLinkedGameObject(isInterpolatedClient, IsServer, view); if (linkedGameObject) { onCreatedLinkTarget?.Invoke(ghost.GhostType, linkedGameObject, this); } // 只能由一个此NetworkBehaviour NetworkBehaviour networkBehaviours = view.GetComponent <NetworkBehaviour>(); if (networkBehaviours) { networkBehaviours.World = World; networkBehaviours.SelfEntity = ent; networkBehaviours.IsServer = IsServer; networkBehaviours.IsOwner = isLocalOwner; EntityManager.AddComponentObject(ent, networkBehaviours); networkBehaviours.NetworkAwake(); } return(view); }
public static T Instantiate <T>(T original, Transform parent) where T : Object { return(Object.Instantiate <T>(original, parent, false)); }
public static T Instantiate <T>(T original, Vector3 position, Quaternion rotation, Transform parent) where T : Object { return((T)((object)Object.Instantiate(original, position, rotation, parent))); }
private void GenerateAugmentSelectors(AugmentRecipe recipe, InventoryGui inventoryGui) { const float spacing = 34; var checkboxPrefab = Menu.instance.m_settingsPrefab.GetComponent <Settings>().m_invertMouse; var magicItem = recipe.FromItem.GetMagicItem(); var rarity = recipe.FromItem.GetRarity(); var startOffset = new Vector2(-330, -165); var augmentableEffects = magicItem.Effects; var effectCount = augmentableEffects.Count; if (EffectSelectors.Count == 0 && EpicLoot.HasAuga) { Auga.API.ComplexTooltip_ClearTextBoxes(AugaTabData.ItemInfoGO); } for (var i = 0; i < Mathf.Max(effectCount, EffectSelectors.Count); ++i) { if (i < effectCount && i >= EffectSelectors.Count) { Toggle selector; if (EpicLoot.HasAuga) { var checkboxTextBox = Auga.API.ComplexTooltip_AddCheckBoxTextBox(AugaTabData.ItemInfoGO); selector = checkboxTextBox.GetComponentInChildren <Toggle>(true); } else { selector = Object.Instantiate(checkboxPrefab, inventoryGui.m_variantButton.transform.parent, false); selector.gameObject.name = $"EffectSelector{i}"; var rt = selector.gameObject.RectTransform(); rt.anchoredPosition = startOffset + new Vector2(0, i * -spacing); var t = selector.GetComponentInChildren <Text>(); t.font = inventoryGui.m_recipeDecription.font; t.resizeTextMaxSize = 18; t.resizeTextMinSize = 10; t.rectTransform.anchoredPosition += new Vector2(300, 0); t.alignment = TextAnchor.MiddleLeft; t.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 300); t.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, spacing); } var index = i; selector.onValueChanged.AddListener((selected) => OnSelectorValueChanged(index, selected)); EffectSelectors.Add(selector); SetSelectorValues(recipe, i, magicItem, rarity); } else if (i >= effectCount && i < EffectSelectors.Count) { if (EpicLoot.HasAuga) { EffectSelectors[i].transform.parent.gameObject.SetActive(false); } else { EffectSelectors[i].gameObject.SetActive(false); } } else { SetSelectorValues(recipe, i, magicItem, rarity); } } }
internal static IEnumerable <Object> DuplicateAssets(IEnumerable <Object> assets) { AssetDatabase.Refresh(); var copiedPaths = new List <string>(); Object firstDuplicatedObjectToFail = null; foreach (var asset in assets) { var assetPath = AssetDatabase.GetAssetPath(asset); // if duplicating a sub-asset, then create a copy next to the main asset file if (!String.IsNullOrEmpty(assetPath) && AssetDatabase.IsSubAsset(asset)) { if (asset is ISubAssetNotDuplicatable) { firstDuplicatedObjectToFail = firstDuplicatedObjectToFail ? firstDuplicatedObjectToFail : asset; continue; } var extension = NativeFormatImporterUtility.GetExtensionForAsset(asset); // We dot sanitize or block unclean the asset filename (asset.name) // since the assertdb will do it for us and has a whole tailored logic for that. // It feels wrong that the asset name (that can apparently contain any char) // is conflated with the orthogonal notion of filename. From the user's POV // it will force an asset dup but with mangled names if the original name contained // "invalid chars" for filenames. // Path.Combine is not used here to avoid blocking asset names that might // contain chars not allowed in filenames. if ((new HashSet <char>(Path.GetInvalidFileNameChars())).Intersect(asset.name).Count() != 0) { Debug.LogWarning(string.Format("Duplicated asset name '{0}' contains invalid characters. Those will be replaced in the duplicated asset name.", asset.name)); } var newPath = AssetDatabase.GenerateUniqueAssetPath( string.Format("{0}{1}{2}.{3}", Path.GetDirectoryName(assetPath), Path.DirectorySeparatorChar, asset.name, extension) ); AssetDatabase.CreateAsset(Object.Instantiate(asset), newPath); copiedPaths.Add(newPath); } // otherwise duplicate the main asset file else if (EditorUtility.IsPersistent(asset)) { var newPath = AssetDatabase.GenerateUniqueAssetPath(assetPath); if (newPath.Length > 0 && AssetDatabase.CopyAsset(assetPath, newPath)) { copiedPaths.Add(newPath); } } } if (firstDuplicatedObjectToFail != null) { var errString = string.Format( "Duplication error: One or more sub assets (with types of {0}) can not be duplicated directly, use the appropriate editor instead", firstDuplicatedObjectToFail.GetType().Name ); Debug.LogError(errString, firstDuplicatedObjectToFail); } AssetDatabase.Refresh(); return(copiedPaths.Select(AssetDatabase.LoadMainAssetAtPath)); }
public static void CopyDefaultSkin() { GUI.skin = null; defaultSkin = Object.Instantiate(GUI.skin); }
public static GameObject Instantiate(GameObject prefab) { return(Object.Instantiate(prefab)); }
public static IEnumerator PopulateSettingsPanel(RectTransform settingsContentRoot) { yield return(null); yield return(null); yield return(null); var categoryPrefab = ourStuffBundle.SettingsCategory; var boolPrefab = ourStuffBundle.SettingsBool; var textPrefab = ourStuffBundle.SettingsText; settingsContentRoot.DestroyChildren(); var pinnedSettings = ExpansionKitSettings.ListPinnedPrefs(false).ToList(); foreach (var keyValuePair in MelonPrefs.GetPreferences()) { var categoryId = keyValuePair.Key; var prefDict = keyValuePair.Value; if (ExpansionKitApi.CustomCategoryUIs.TryGetValue(categoryId, out var specificPrefab)) { Object.Instantiate(specificPrefab, settingsContentRoot, false); continue; } var prefsToPopulate = prefDict.Where(it => !it.Value.Hidden).ToList(); if (prefsToPopulate.Count == 0) { continue; } var categoryUi = Object.Instantiate(categoryPrefab, settingsContentRoot, false); categoryUi.GetComponentInChildren <Text>().text = MelonPrefs.GetCategoryDisplayName(categoryId); var categoryUiContent = categoryUi.transform.Find("CategoryEntries"); var expandButtonTransform = categoryUi.transform.Find("ExpandButton"); var expandButton = expandButtonTransform.GetComponent <Button>(); var expandButtonText = expandButtonTransform.GetComponentInChildren <Text>(); void SetExpanded(bool expanded) { expandButtonText.text = expanded ? "^" : "V"; categoryUiContent.gameObject.SetActive(expanded); } expandButton.onClick.AddListener(new Action(() => { SetExpanded(ourCategoryExpanded[categoryId] = !ourCategoryExpanded[categoryId]); })); if (!ourCategoryExpanded.ContainsKey(categoryId)) { ourCategoryExpanded[categoryId] = !ExpansionKitSettings.IsCategoriesStartCollapsed(); } SetExpanded(ourCategoryExpanded[categoryId]); foreach (var valuePair in prefsToPopulate) { var prefId = valuePair.Key; var prefDesc = valuePair.Value; switch (prefDesc.Type) { case MelonPrefs.MelonPreferenceType.STRING: { var textSetting = Object.Instantiate(textPrefab, categoryUiContent, false); textSetting.GetComponentInChildren <Text>().text = prefDesc.DisplayText ?? prefId; var textField = textSetting.GetComponentInChildren <InputField>(); textField.text = MelonPrefs.GetString(categoryId, prefId); textField.onValueChanged.AddListener(new Action <string>(value => { prefDesc.ValueEdited = value; })); textSetting.GetComponentInChildren <Button>().onClick.AddListener(new Action(() => { BuiltinUiUtils.ShowInputPopup(prefDesc.DisplayText ?? prefId, textField.text, InputField.InputType.Standard, false, "Done", (result, _, __) => prefDesc.ValueEdited = textField.text = result); })); break; } case MelonPrefs.MelonPreferenceType.BOOL: var boolSetting = Object.Instantiate(boolPrefab, categoryUiContent, false); boolSetting.GetComponentInChildren <Text>().text = prefDesc.DisplayText ?? prefId; var mainToggle = boolSetting.transform.Find("Toggle").GetComponent <Toggle>(); mainToggle.isOn = MelonPrefs.GetBool(categoryId, prefId); mainToggle.onValueChanged.AddListener(new Action <bool>( isSet => { prefDesc.ValueEdited = isSet.ToString().ToLowerInvariant(); })); var pinToggle = boolSetting.transform.Find("PinToggle").GetComponent <Toggle>(); pinToggle.isOn = pinnedSettings.Contains((categoryId, prefId)); pinToggle.onValueChanged.AddListener(new Action <bool>(isSet => { if (isSet) { ExpansionKitSettings.PinPref(categoryId, prefId); } else { ExpansionKitSettings.UnpinPref(categoryId, prefId); } })); break; case MelonPrefs.MelonPreferenceType.INT: case MelonPrefs.MelonPreferenceType.FLOAT: { var textSetting = Object.Instantiate(textPrefab, categoryUiContent, false); textSetting.GetComponentInChildren <Text>().text = prefDesc.DisplayText ?? prefId; var textField = textSetting.GetComponentInChildren <InputField>(); textField.text = MelonPrefs.GetString(categoryId, prefId); textField.contentType = prefDesc.Type == MelonPrefs.MelonPreferenceType.INT ? InputField.ContentType.IntegerNumber : InputField.ContentType.DecimalNumber; textField.onValueChanged.AddListener(new Action <string>(value => { prefDesc.ValueEdited = value; })); textSetting.GetComponentInChildren <Button>().onClick.AddListener(new Action(() => { BuiltinUiUtils.ShowInputPopup(prefDesc.DisplayText ?? prefId, textField.text, InputField.InputType.Standard, prefDesc.Type == MelonPrefs.MelonPreferenceType.INT, "Done", (result, _, __) => prefDesc.ValueEdited = textField.text = result); })); break; } default: MelonLogger.LogError($"Unknown mod pref type {prefDesc.Type}"); break; } } } }
public static Object Instantiate(Object original, Transform parent) { return(Object.Instantiate(original, parent, false)); }
public override void TryInitialize(InventoryGui inventoryGui, int tabIndex, Action <TabController> onTabPressed) { base.TryInitialize(inventoryGui, tabIndex, onTabPressed); if (ChoiceDialog == null) { if (EpicLoot.HasAuga) { var resultDialog = Auga.API.Workbench_CreateNewResultsPanel(); resultDialog.SetActive(false); ChoiceDialog = resultDialog.AddComponent <AugmentChoiceDialog>(); var icon = ChoiceDialog.transform.Find("InventoryElement/icon").GetComponent <Image>(); ChoiceDialog.MagicBG = Object.Instantiate(icon, icon.transform.parent); ChoiceDialog.MagicBG.name = "MagicItemBG"; ChoiceDialog.MagicBG.sprite = EpicLoot.GetMagicItemBgSprite(); ChoiceDialog.MagicBG.color = Color.white; ChoiceDialog.MagicBG.rectTransform.anchorMin = new Vector2(0, 0); ChoiceDialog.MagicBG.rectTransform.anchorMax = new Vector2(1, 1); ChoiceDialog.MagicBG.rectTransform.sizeDelta = new Vector2(0, 0); ChoiceDialog.MagicBG.rectTransform.anchoredPosition = new Vector2(0, 0); ChoiceDialog.NameText = ChoiceDialog.transform.Find("Topic").GetComponent <Text>(); var closeButton = ChoiceDialog.gameObject.GetComponentInChildren <Button>(); Object.Destroy(closeButton.gameObject); var tooltip = (RectTransform)ChoiceDialog.transform.Find("TooltipScrollContainer"); tooltip.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 360); var scrollbar = (RectTransform)ChoiceDialog.transform.Find("ScrollBar"); scrollbar.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 360); for (var i = 0; i < 3; i++) { var button = Auga.API.MediumButton_Create(resultDialog.transform, $"AugmentButton{i}", string.Empty); Auga.API.Button_SetTextColors(button, Color.white, Color.white, Color.white, Color.white, Color.white, Color.white); button.navigation = new Navigation { mode = Navigation.Mode.None }; var rt = (RectTransform)button.transform; rt.anchoredPosition = new Vector2(0, -220 - (i * 40)); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 295); ChoiceDialog.EffectChoiceButtons.Add(button); } } else { ChoiceDialog = CreateDialog <AugmentChoiceDialog>(inventoryGui, "AugmentChoiceDialog"); var background = ChoiceDialog.gameObject.transform.Find("Frame").gameObject.RectTransform(); ChoiceDialog.MagicBG = Object.Instantiate(inventoryGui.m_recipeIcon, background); ChoiceDialog.MagicBG.name = "MagicItemBG"; ChoiceDialog.MagicBG.sprite = EpicLoot.GetMagicItemBgSprite(); ChoiceDialog.MagicBG.color = Color.white; ChoiceDialog.NameText = Object.Instantiate(inventoryGui.m_recipeName, background); ChoiceDialog.Description = Object.Instantiate(inventoryGui.m_recipeDecription, background); ChoiceDialog.Description.rectTransform.anchoredPosition += new Vector2(0, -47); ChoiceDialog.Description.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 340); ChoiceDialog.Icon = Object.Instantiate(inventoryGui.m_recipeIcon, background); var closeButton = ChoiceDialog.gameObject.GetComponentInChildren <Button>(); Object.Destroy(closeButton.gameObject); for (var i = 0; i < 3; i++) { var button = Object.Instantiate(inventoryGui.m_craftButton, background); var rt = button.gameObject.RectTransform(); rt.anchoredPosition = new Vector2(0, -155 - (i * 45)); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40); ChoiceDialog.EffectChoiceButtons.Add(button); } } } if (!EpicLoot.HasAuga) { if (AvailableAugmentsDialog == null) { AvailableAugmentsDialog = CreateDialog <AugmentsAvailableDialog>(inventoryGui, "AvailableAugmentsDialog"); var background = AvailableAugmentsDialog.gameObject.transform.Find("Frame").gameObject.RectTransform(); AvailableAugmentsDialog.MagicBG = Object.Instantiate(inventoryGui.m_recipeIcon, background); AvailableAugmentsDialog.MagicBG.name = "MagicItemBG"; AvailableAugmentsDialog.MagicBG.sprite = EpicLoot.GetMagicItemBgSprite(); AvailableAugmentsDialog.MagicBG.color = Color.white; AvailableAugmentsDialog.NameText = Object.Instantiate(inventoryGui.m_recipeName, background); AvailableAugmentsDialog.Description = Object.Instantiate(inventoryGui.m_recipeDecription, background); AvailableAugmentsDialog.Description.rectTransform.anchoredPosition += new Vector2(0, -110); AvailableAugmentsDialog.Description.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 460); AvailableAugmentsDialog.Description.resizeTextForBestFit = true; AvailableAugmentsDialog.Icon = Object.Instantiate(inventoryGui.m_recipeIcon, background); var closeButton = AvailableAugmentsDialog.gameObject.GetComponentInChildren <Button>(); closeButton.onClick = new Button.ButtonClickedEvent(); closeButton.onClick.AddListener(AvailableAugmentsDialog.OnClose); closeButton.transform.SetAsLastSibling(); } if (AvailableAugmentsButton == null) { AvailableAugmentsButton = Object.Instantiate(inventoryGui.m_variantButton, inventoryGui.m_variantButton.transform.parent, true); AvailableAugmentsButton.gameObject.name = "AvailableAugmentsButton"; AvailableAugmentsButton.gameObject.SetActive(false); AvailableAugmentsButton.onClick = new Button.ButtonClickedEvent(); AvailableAugmentsButton.onClick.AddListener(ShowAvailableAugmentsDialog); var text = AvailableAugmentsButton.GetComponentInChildren <Text>(); text.text = Localization.instance.Localize("$mod_epicloot_augment_availableeffects"); var rt = AvailableAugmentsButton.gameObject.RectTransform(); rt.anchoredPosition += new Vector2(50, 0); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 150); } } }
public static T Instantiate <T>(this T selfObj) where T : Object { return(Object.Instantiate(selfObj)); }
private IEnumerator StartDungFluke(GameObject dungFluke, int dungFlukeAudioIndex) { var spriteAnimator = dungFluke.GetComponent <tk2dSpriteAnimator>(); var dungSpazAudioClip = dungFluke.GetComponent <AudioSource>().clip; // Play the animation for the dungFluke movement and the corresponding audio spriteAnimator.Play("Dung Air"); // Create an audio relative to the dung fluke var audioSource = AudioUtil.GetAudioSourceObject(dungFluke).GetComponent <AudioSource>(); audioSource.clip = dungSpazAudioClip; audioSource.Play(); yield return(new WaitForSeconds(1.0f)); // Play the erratic movement animation just before it explodes spriteAnimator.Play("Dung Antic"); dungFluke.FindGameObjectInChildren("Pt Antic").GetComponent <ParticleSystem>().Play(); yield return(new WaitForSeconds(1.0f)); // Now we get the prefab and spawn the actual explosion cloud var dungCloudObject = dungFluke.FindGameObjectInChildren("Knight Dung Cloud"); var dungCloud = Object.Instantiate( dungCloudObject, dungFluke.transform.position, Quaternion.identity ); dungCloud.SetActive(true); dungCloud.layer = 22; Object.Destroy(dungCloud.GetComponent <DamageEffectTicker>()); // Get the control FSM and the audio clip corresponding to the explosion of the dungFluke // We need it later var dungFlukeControl = dungFluke.LocateMyFSM("Control"); var blowClip = (AudioClip)dungFlukeControl.GetAction <AudioPlayerOneShotSingle>("Blow", dungFlukeAudioIndex).audioClip.Value; Object.Destroy(dungFlukeControl); // Set the FSM state to Collider On, so we can actually interact with it dungFlukeControl.SetState("Collider On"); // Play the explosion audio clip audioSource.Stop(); audioSource.PlayOneShot(blowClip); if (GameSettings.IsPvpEnabled && ShouldDoDamage) { dungCloud.AddComponent <DamageHero>(); } // We can already destroy the fluke Object.Destroy(dungFluke); yield return(new WaitForSeconds(3.0f)); // After some time, we can also destroy the cloud Object.Destroy(dungCloud); }