/// <summary> /// Sets or alters this GameObject's <see cref="Duality.Resources.PrefabLink"/> to reference the specified <see cref="Prefab"/>. /// </summary> /// <param name="prefab">The Prefab that will be linked to.</param> /// <seealso cref="Duality.Resources.PrefabLink"/> /// <seealso cref="Duality.Resources.Prefab"/> public void LinkToPrefab(ContentRef <Prefab> prefab) { if (this.prefabLink == null) { // Not affected by another (higher) PrefabLink if (this.AffectedByPrefabLink == null) { this.prefabLink = new PrefabLink(this, prefab); // If a nested object is already PrefabLink'ed, add it to the changelist foreach (GameObject child in this.ChildrenDeep) { if (child.PrefabLink != null && child.PrefabLink.ParentLink == this.prefabLink) { this.prefabLink.PushChange(child, ReflectionInfo.Property_GameObject_PrefabLink, child.PrefabLink.Clone()); } } } // Already affected by another (higher) PrefabLink else { this.prefabLink = new PrefabLink(this, prefab); this.prefabLink.ParentLink.RelocateChanges(this.prefabLink); } } else { this.prefabLink = this.prefabLink.Clone(this, prefab); } }
/// <summary> /// 生成反初始化代码 /// </summary> /// <param name="prefab"></param> private static void CopyElementUnIninitialize(PrefabLink link) { if (link == null) { return; } ElementData[] elementData = GetElementData(link); if (elementData == null) { return; } // 输出 string content = string.Empty; for (int i = 0; i < elementData.Length; i++) { ElementData data = elementData[i]; content += data.VariantName + " = null;\r\n"; } if (!string.IsNullOrEmpty(content)) { TextEditor te = new TextEditor(); te.text = content; te.OnFocus(); te.Copy(); } }
public override void Undo() { if (this.backupPrefab == null) { throw new InvalidOperationException("Can't undo what hasn't been done yet"); } List <Prefab> prefabs = new List <Prefab>(); List <GameObject> linkedObj = new List <GameObject>(); for (int i = this.backupPrefab.Length - 1; i >= 0; i--) { GameObject obj = this.targetObj[i]; Prefab prefab = this.targetPrefab[i].Res; PrefabLink link = obj.PrefabLink; if (prefab == null) { continue; } CloneProvider.DeepCopyTo(this.backupPrefab[i], prefab, BackupCloneContext); if (this.backupLink[i] == null) { this.targetObj[i].BreakPrefabLink(); linkedObj.Add(obj); } prefabs.Add(link.Prefab.Res); } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(prefabs)); DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(linkedObj), ReflectionInfo.Property_GameObject_PrefabLink); }
public override void Undo() { if (this.backupLink == null) { throw new InvalidOperationException("Can't undo what hasn't been done yet"); } for (int i = this.backupLink.Length - 1; i >= 0; i--) { if (this.backupLink[i] == null) { continue; } if (this.backupLink[i].Obj == null) { continue; } this.backupLink[i].Obj.LinkToPrefab(this.backupLink[i].Prefab); PrefabLink link = this.backupLink[i].Obj.PrefabLink; CloneProvider.DeepCopyTo(this.backupLink[i], link, BackupCloneContext); } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetObj), ReflectionInfo.Property_GameObject_PrefabLink); }
/// <summary> /// 生成连接元素声明代码 /// </summary> /// <param name="link"></param> private static void CopyElementDeclare(PrefabLink link) { if (link == null) { return; } ElementData[] elementData = GetElementData(link); if (elementData == null) { return; } // 输出 string content = string.Empty; for (int i = 0; i < elementData.Length; i++) { content += "private const int " + elementData[i].IndexName + " = " + i + ";\r\n"; } content += "\r\n"; for (int i = 0; i < elementData.Length; i++) { content += "private " + elementData[i].TypeName + ' ' + elementData[i].VariantName + ";\r\n"; } if (!string.IsNullOrEmpty(content)) { TextEditor te = new TextEditor(); te.text = content; te.OnFocus(); te.Copy(); } }
/// <summary> /// 生成反初始化代码 /// </summary> /// <param name="prefab"></param> private static void CopyElementUnIninitializeLua(PrefabLink link) { // if (link == null) // { // return; // } // ElementData[] elementData = GetElementData(link); // if (elementData == null) // { // return; // } // // 输出 // string content = string.Empty; // for (int i = 0; i < elementData.Length; i++) // { // content += "self."+ elementData[i].VariantName +" = false" + "\r\n"; // } // if (!string.IsNullOrEmpty(content)) // { // TextEditor te = new TextEditor(); // te.text = content; // te.OnFocus(); // te.Copy(); // } }
static void createTerrefyingHowl() { var dazzling_display = library.Get <BlueprintAbility>("5f3126d4120b2b244a95cb2ec23d69fb"); terrifying_howl_ability = library.CopyAndAdd <BlueprintAbility>("08cb5f4c3b2695e44971bf5c45205df0", "TerrifyingHowlAbility", ""); terrifying_howl_ability.SetName("Terrifying Howl"); terrifying_howl_ability.SetDescription("The barbarian unleashes a terrifying howl as a standard action. All shaken enemies within 30 feet must make a Will save (DC equal to 10 + 1/2 the barbarian’s level + the barbarian’s Strength modifier) or be frightened for 1d4+1 rounds.\n" + "Once an enemy has made a save versus terrifying howl (successful or not), it is immune to this power for 24 hours."); terrifying_howl_ability.Type = AbilityType.Extraordinary; terrifying_howl_ability.RemoveComponents <SpellComponent>(); terrifying_howl_ability.RemoveComponents <SpellListComponent>(); terrifying_howl_ability.Range = AbilityRange.Personal; var frighteneed_buff = library.Get <BlueprintBuff>("f08a7239aa961f34c8301518e71d4cdf"); var shaken_buff = library.Get <BlueprintBuff>("25ec6cb6ab1845c48a95f9c20b034220"); var cooldown_buff = Helpers.CreateBuff("TerrifyingHowlCooldownBuff", "Cooldown: Terrifying Howl", terrifying_howl_ability.Description, "", terrifying_howl_ability.Icon, null); cooldown_buff.SetBuffFlags(BuffFlags.RemoveOnRest); var on_failed_save = Common.createContextSavedApplyBuff(frighteneed_buff, Helpers.CreateContextDuration(Common.createSimpleContextValue(1), Kingmaker.UnitLogic.Mechanics.DurationRate.Rounds, Kingmaker.RuleSystem.DiceType.D4, Common.createSimpleContextValue(1) ), is_dispellable: false ); var apply_cooldown = Common.createContextActionApplyBuff(cooldown_buff, Helpers.CreateContextDuration(Common.createSimpleContextValue(1), Kingmaker.UnitLogic.Mechanics.DurationRate.Days), dispellable: false ); PrefabLink p = new PrefabLink(); p.AssetId = "cbfe312cb8e63e240a859efaad8e467c"; var fx = Common.createContextActionSpawnFx(p); var condition = Helpers.CreateConditional(new Condition[] { Helpers.CreateConditionHasBuffFromCaster(cooldown_buff, true), Helpers.CreateConditionHasFact(shaken_buff), Helpers.Create <ContextConditionIsEnemy>() }, Common.createContextActionSavingThrow(SavingThrowType.Will, Helpers.CreateActionList(on_failed_save, apply_cooldown, fx))); condition.ConditionsChecker.Operation = Operation.And; terrifying_howl_ability.ReplaceComponent <AbilityEffectRunAction>(Helpers.CreateRunActions(condition)); terrifying_howl_ability.AddComponent(Common.createContextCalculateAbilityParamsBasedOnClasses(new BlueprintCharacterClass[] { barbarian_class }, StatType.Strength)); terrifying_howl_ability.AddComponent(dazzling_display.GetComponent <AbilitySpawnFx>()); terrifying_howl_ability.AddComponent(Common.createAbilityCasterHasFacts(rage_marker_caster)); // allow to use only on rage terrifying_howl_feature = Common.AbilityToFeature(terrifying_howl_ability, false); terrifying_howl_feature.Groups = new FeatureGroup[] { FeatureGroup.RagePower }; terrifying_howl_feature.AddComponent(Helpers.PrerequisiteClassLevel(barbarian_class, 8)); addToSelection(terrifying_howl_feature); }
public WildFact() { Main.Accessors.SetBlueprintBuffFlags(this, 2 + 8); // Enum is private... 2 = HiddenInUi, 8 = StayOnDeath Stacking = StackingType.Replace; Frequency = DurationRate.Rounds; FxOnStart = new PrefabLink(); FxOnRemove = new PrefabLink(); Main.Accessors.SetBlueprintUnitFactDisplayName(this) = new L10NString("craftMagicItems-enchantment-wild-name"); Main.Accessors.SetBlueprintUnitFactDescription(this) = new L10NString("craftMagicItems-enchantment-wild-description"); }
/// 初始化 public override void Initialize(UIForm formScript) { if (_isInited) { return; } base.Initialize(formScript); // PLink = gameObject.GetComponent <PrefabLink>(); // m_image = gameObject.GetComponent <Image>(); if (m_image != null) { m_defaultSprite = m_image.sprite; m_defaultColor = m_image.color; } //如果Element不包含 增加一个以便于接收选中事件 if (m_autoAddUIEventScript) { UIEventListener eventScript = gameObject.GetComponent <UIEventListener>(); if (eventScript == null) { eventScript = gameObject.AddComponent <UIEventListener>(); eventScript.Initialize(formScript); } if (ApplyClickSelTween) { eventScript.ApplyClickTween = true; } } //如果Element不包含CanvasGroup,增加一个以便于隐藏/显示 if (!m_useSetActiveForDisplay) { m_canvasGroup = gameObject.GetComponent <CanvasGroup>(); if (m_canvasGroup == null) { m_canvasGroup = gameObject.AddComponent <CanvasGroup>(); } } // m_defaultSize = GetDefaultSize(); //初始化RectTransform InitRectTransform(); // if (m_textObj != null) { m_defaultTextColor = m_textObj.color; } }
public override void OnInspectorGUI() { serializedObject.Update(); //绘制元素列表 OnDrawElements(); serializedObject.ApplyModifiedProperties(); //添加自动生成 _expand = EditorGUIHelper.DrawHead("辅助", _expand); if (_expand) { GUILayout.BeginVertical("box"); { _prefix = EditorGUILayout.TextField("引用前缀", _prefix); if (GUILayout.Button("复制节点定义")) { PrefabLink pl = target as PrefabLink; CopyElementDeclare(pl); } if (GUILayout.Button("复制节点初始化")) { PrefabLink pl = target as PrefabLink; CopyElementInitialize(pl); } if (GUILayout.Button("复制节点反初始化")) { PrefabLink pl = target as PrefabLink; CopyElementUnIninitialize(pl); } // if (GUILayout.Button("复制Lua节点定义")) // { // PrefabLink pl = target as PrefabLink; // CopyElementDeclareLua(pl); // } if (GUILayout.Button("复制Lua节点初始化")) { PrefabLink pl = target as PrefabLink; CopyElementInitializeLua(pl); } // if (GUILayout.Button("复制Lua节点反初始化")) // { // PrefabLink pl = target as PrefabLink; // CopyElementUnIninitializeLua(pl); // } } } }
public bool UpdateLinkState(bool checkFileChanged) { PrefabLinkState lastState = this.linkState; ComponentNode cmpNode = this as ComponentNode; GameObjectNode objNode = (cmpNode != null ? cmpNode.Parent : this) as GameObjectNode; PrefabLink prefabLink = objNode != null ? objNode.Obj.AffectedByPrefabLink : null; bool affectedByPrefabLink = prefabLink != null; if (cmpNode != null) { affectedByPrefabLink = affectedByPrefabLink && prefabLink.AffectsObject(cmpNode.Component); } if (objNode != null) { affectedByPrefabLink = affectedByPrefabLink && prefabLink.AffectsObject(objNode.Obj); } string filePath = affectedByPrefabLink ? prefabLink.Prefab.Path : null; bool fileExists = this.linkLastExisted; if (checkFileChanged || this.linkLastPath != filePath) { fileExists = File.Exists(filePath); } // Prefab-linked entities if (affectedByPrefabLink && fileExists) //prefabLink.Prefab.IsAvailable) // Not sufficient - might be loaded but with a broken path { this.linkState = PrefabLinkState.Active; } else if (cmpNode == null && objNode.Obj.PrefabLink != null) { this.linkState = PrefabLinkState.Broken; } else { this.linkState = PrefabLinkState.None; } this.linkLastExisted = fileExists; this.linkLastPath = filePath; return(this.linkState != lastState); }
/// <summary> /// A <see cref="Cohee.Serialization.Serializer.FieldBlockers">FieldBlocker</see> to prevent /// fields of <see cref="Cohee.Resources.PrefabLink">PrefabLink-ed</see> objects from being serialized unnecessarily. /// </summary> /// <param name="field"></param> /// <param name="obj"></param> /// <returns></returns> public static bool PrefabLinkedFieldBlocker(FieldInfo field, object obj) { Component cmp = obj as Component; if (cmp == null || cmp.GameObj == null) { return(false); } PrefabLink link = cmp.GameObj.AffectedByPrefabLink; if (link == null || !link.AffectsObject(cmp)) { return(false); } return(field.DeclaringType != typeof(Component)); }
/// <summary> /// 生成连接元素初始化代码 /// </summary> /// <param name="link"></param> private static void CopyElementInitialize(PrefabLink link) { if (link == null) { return; } ElementData[] elementData = GetElementData(link); if (elementData == null) { return; } // 输出 string content = string.Empty; for (int i = 0; i < elementData.Length; i++) { ElementData data = elementData[i]; content += data.VariantName + " = "; if (data.TypeName == "GameObject") { content += "$$.GetCacheGameObject("; content += data.IndexName; content += ");\r\n"; } else { content += "$$.GetCacheComponent("; content += data.IndexName; content += ")"; content += "as " + data.TypeName; content += ";\r\n"; } } if (!string.IsNullOrEmpty(content)) { TextEditor te = new TextEditor(); te.text = content; te.OnFocus(); te.Copy(); } }
public override void Do() { if (this.backupLink == null) { this.backupLink = new PrefabLink[this.targetObj.Length]; for (int i = 0; i < this.backupLink.Length; i++) { PrefabLink link = this.targetObj[i].AffectedByPrefabLink; this.backupLink[i] = CloneProvider.DeepClone(link, BackupCloneContext); } } // Destroy all PrefabLinks foreach (GameObject o in this.targetObj) { o.BreakPrefabLink(); } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetObj), ReflectionInfo.Property_GameObject_PrefabLink); }
public override void Do() { if (this.backupPrefab == null) { this.backupPrefab = new Prefab[this.targetObj.Length]; this.backupLink = new PrefabLink[this.targetObj.Length]; for (int i = 0; i < this.backupPrefab.Length; i++) { PrefabLink link = this.targetObj[i].PrefabLink; Prefab prefab = this.targetPrefab[i].Res; this.backupPrefab[i] = CloneProvider.DeepClone(prefab, BackupCloneContext); this.backupLink[i] = CloneProvider.DeepClone(link, BackupCloneContext); } } List <Prefab> prefabs = new List <Prefab>(); List <GameObject> linkedObj = new List <GameObject>(); for (int i = 0; i < this.targetObj.Length; i++) { GameObject obj = this.targetObj[i]; Prefab prefab = this.targetPrefab[i].Res; if (prefab == null) { continue; } prefab.Inject(obj); if (obj.PrefabLink == null) { obj.LinkToPrefab(prefab); linkedObj.Add(obj); } prefabs.Add(prefab); } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(prefabs)); DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(linkedObj), ReflectionInfo.Property_GameObject_PrefabLink); }
public override void Do() { if (this.backupObj == null) { this.backupObj = new Component[this.targetObj.Count]; this.backupLink = new PrefabLink[this.targetObj.Count]; for (int i = 0; i < this.backupObj.Length; i++) { PrefabLink link = this.targetObj[i].GameObj.AffectedByPrefabLink; this.backupObj[i] = this.targetObj[i].DeepClone(BackupCloneContext); this.backupLink[i] = link.DeepClone(BackupCloneContext); } } List <PrefabLink> affectedLinks = new List <PrefabLink>(); foreach (Component component in this.targetObj) { Type cmpType = component.GetType(); TypeInfo cmpTypeInfo = cmpType.GetTypeInfo(); PrefabLink link = component.GameObj.AffectedByPrefabLink; if (link != null) { if (link.Prefab.IsAvailable) { link.Prefab.Res.CopyTo(link.Obj.IndexPathOfChild(component.GameObj), component); } link.ClearChanges(component.GameObj, cmpTypeInfo, null); affectedLinks.Add(link); } else { Component resetBase = cmpTypeInfo.CreateInstanceOf() as Component; resetBase.CopyTo(component); } } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetObj)); }
public override void Undo() { if (this.backupObj == null) { throw new InvalidOperationException("Can't undo what hasn't been done yet"); } List <PrefabLink> affectedLinks = new List <PrefabLink>(); for (int i = this.backupObj.Length - 1; i >= 0; i--) { this.backupObj[i].DeepCopyTo(this.targetObj[i], BackupCloneContext); if (this.backupLink[i] != null && this.backupLink[i].Obj != null && this.backupLink[i].Obj.PrefabLink != null) { PrefabLink link = this.backupLink[i].Obj.PrefabLink; this.backupLink[i].DeepCopyTo(link, BackupCloneContext); affectedLinks.Add(link); } } DualityEditorApp.NotifyObjPropChanged(this, new ObjectSelection(this.targetObj)); }
public override void Do() { if (this.backupObj == null) { this.backupObj = new GameObject[this.targetObj.Length]; this.backupLink = new PrefabLink[this.targetObj.Length]; for (int i = 0; i < this.backupObj.Length; i++) { PrefabLink link = this.targetObj[i].AffectedByPrefabLink; this.backupObj[i] = CloneProvider.DeepClone(this.targetObj[i], BackupCloneContext); this.backupLink[i] = CloneProvider.DeepClone(link, BackupCloneContext); } } // Clear all changes and re-apply Prefabs foreach (GameObject o in this.targetObj) { o.PrefabLink.ClearChanges(); } Duality.Resources.PrefabLink.ApplyAllLinks(this.targetObj); DualityEditorApp.NotifyObjPrefabApplied(this, new ObjectSelection(this.targetObj)); }
/// <summary> /// 生成连接元素初始化代码 /// </summary> /// <param name="link"></param> private static void CopyElementInitializeLua(PrefabLink link) { if (link == null) { return; } ElementData[] elementData = GetElementData(link); if (elementData == null) { return; } // 输出 string content = string.Empty; for (int i = 0; i < elementData.Length; i++) { ElementData data = elementData[i]; content += "local " + elementData[i].VariantName + " = "; if (data.TypeName == "GameObject") { content += string.Format("itemLink:GetCacheGameObject({0})\r\n", i); } else { content += string.Format("itemLink:GetCacheComponent({0})\r\n", i); } } if (!string.IsNullOrEmpty(content)) { TextEditor te = new TextEditor(); te.text = content; te.OnFocus(); te.Copy(); } }
private static ElementData[] GetElementData(PrefabLink prefab) { if (prefab == null || prefab.Elements == null || prefab.Elements.Length == 0) { EditorUtility.DisplayDialog("错误", "没有节点", "确定"); return(null); } ElementData[] elementData = new ElementData[prefab.Elements.Length]; for (int i = 0; i < prefab.Elements.Length; i++) { Component component = prefab.Elements[i].Component; GameObject go = component.gameObject; string goName = go.name; if (string.IsNullOrEmpty(goName)) { EditorUtility.DisplayDialog("错误", "节点名为空", "确定"); return(null); } goName = goName.Trim(); if (string.IsNullOrEmpty(goName)) { EditorUtility.DisplayDialog("错误", "节点名为空", "确定"); return(null); } // 索引 ElementData data; // 类型和变量 data.TypeName = component.GetType().Name; string shortTypeName = data.TypeName; if (data.TypeName.IndexOf("UI") == 0) { shortTypeName = data.TypeName.Substring(2); } // index data.IndexName = _prefix + char.ToUpper(goName[0]) + goName.Substring(1) + shortTypeName + "Index"; // variant name if (string.IsNullOrEmpty(_prefix)) { data.VariantName = "_" + char.ToLower(goName[0]) + goName.Substring(1) + shortTypeName; } else { data.VariantName = _prefix + char.ToUpper(goName[0]) + goName.Substring(1) + shortTypeName; } // 名字重复 for (int j = 0; j < i; j++) { if (elementData[j].IndexName.Equals(data.IndexName, StringComparison.OrdinalIgnoreCase) || elementData[j].VariantName.Equals(data.VariantName, StringComparison.OrdinalIgnoreCase)) { EditorUtility.DisplayDialog( "错误", string.Format("节点名重复,{0},{1}", data.IndexName, data.VariantName), "确定"); return(null); } } // elementData[i] = data; } return(elementData); }
private void Awake() { _plink = GetComponent <PrefabLink>(); Root = transform; }
/// <summary> /// Breaks this GameObject's <see cref="Duality.Resources.PrefabLink"/> /// </summary> public void BreakPrefabLink() { this.prefabLink = null; }