public ObjectValue targetObject = new ObjectValue(); // used when type = TargetType.Specified //public int linkedIdx = 1; // used with TargetType.Linked public ActionTarget Copy() { ActionTarget t = new ActionTarget(); t.type = this.type; t.targetObject = this.targetObject.Copy(); //t.linkedIdx = this.linkedIdx; return t; }
/// <summary>will determine the target GameObject based on what targetInfo is set to</summary> public static GameObject DetermineTarget(ActionTarget targetInfo, GameObject self, GameObject targeted, GameObject selfTargetedBy, GameObject equipTarget, GameObject helper) { GameObject obj = null; if (targetInfo.type == TargetType.Helper) obj = helper; else if (targetInfo.type == TargetType.Player) obj = UniRPGGlobal.Player.gameObject; else if (targetInfo.type == TargetType.Specified) { if (targetInfo.targetObject.Value == null) return null; obj = (GameObject)targetInfo.targetObject.Value; } else if (targetInfo.type == TargetType.Self) obj = self; else if (targetInfo.type == TargetType.Targeted) obj = targeted; else if (targetInfo.type == TargetType.TargetedBy) obj = selfTargetedBy; else if (targetInfo.type == TargetType.EquipTarget) obj = equipTarget; return obj; }
/// <summary>Show a field where the designer can select the action.targetType</summary> public static void TargetTypeField(EditorWindow ed, string label, ActionTarget actionTarget, string help, int labelWidth = 0) { EditorGUILayout.BeginHorizontal(); { if (label != null) { if (labelWidth == 0) GUILayout.Label(label); else GUILayout.Label(label, GUILayout.Width(labelWidth)); EditorGUILayout.Space(); } EditorGUILayout.BeginVertical(); { actionTarget.type = (Action.TargetType)EditorGUILayout.EnumPopup(actionTarget.type); if (actionTarget.type == Action.TargetType.Specified) { //actionTarget.targetObject = (GameObject)EditorGUILayout.ObjectField(actionTarget.targetObject, typeof(GameObject), true); actionTarget.targetObject = UniRPGEdGui.GlobalObjectVarOrValueField(ed, null, actionTarget.targetObject, typeof(GameObject), true); } else { // make sure it is null so that there is not an unintended link with prefabs or other assets actionTarget.targetObject.SetAsValue = null; } } EditorGUILayout.EndVertical(); if (help != null) { GUILayout.Label(new GUIContent(UniRPGEdGui.Icon_Help, help), GUILayout.Width(20)); EditorGUILayout.Space(); } } EditorGUILayout.EndHorizontal(); }