public static Timer InstantiateTimer(Transform _parent, string _name) { return(GameObjectUtil.CreateInstance <Timer>(_parent, _name)); }
private System.Collections.IEnumerable ReduceTargets(object triggerArg) { switch (_find) { case FindCommand.Direct: { object obj = (_configured) ? _target : triggerArg; if (obj == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(obj); break; case ResolveByCommand.WithTag: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.HasTag(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithName: { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go.CompareName(_queryString)) { yield return(obj); } } break; case ResolveByCommand.WithType: { var o = ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj)); if (o != null) { yield return(o); } } break; } } break; case FindCommand.FindParent: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: { var t = trans.parent; if (t != null) { yield return(t); } } break; case ResolveByCommand.WithTag: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.HasTag(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithName: { foreach (var p in GameObjectUtil.GetParents(trans)) { if (p.CompareName(_queryString)) { yield return(p); } } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var p in GameObjectUtil.GetParents(trans)) { var o = ObjUtil.GetAsFromSource(tp, p); if (o != null) { yield return(o); } } } break; } } break; case FindCommand.FindInChildren: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg); if (trans == null) { yield break; } switch (_resolveBy) { case ResolveByCommand.Nothing: if (trans.childCount > 0) { yield return(trans.GetChild(0)); } break; case ResolveByCommand.WithTag: if (trans.childCount > 0) { using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { if (lst[i].HasTag(_queryString)) { yield return(lst[i]); } } } } break; case ResolveByCommand.WithName: if (trans.childCount > 0) { using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { if (lst[i].CompareName(_queryString)) { yield return(lst[i]); } } } } break; case ResolveByCommand.WithType: if (trans.childCount > 0) { var tp = TypeUtil.FindType(_queryString); using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { var o = ObjUtil.GetAsFromSource(tp, lst[i]); if (o != null) { yield return(o); } } } } break; } } break; case FindCommand.FindInEntity: { GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? _target : triggerArg); if (entity == null) { yield break; } ; switch (_resolveBy) { case ResolveByCommand.Nothing: yield return(entity); break; case ResolveByCommand.WithTag: { foreach (var o in entity.FindAllWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(entity.transform, _queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildrenAndSelf(entity.transform, lst); for (int i = 0; i < lst.Count; i++) { var o = ObjUtil.GetAsFromSource(tp, lst[i]); if (o != null) { yield return(o); } } } } break; } } break; case FindCommand.FindInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: { var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg); if (go != null) { yield return(go); } } break; case ResolveByCommand.WithTag: { foreach (var o in GameObjectUtil.FindGameObjectsWithMultiTag(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithName: { foreach (var o in GameObjectUtil.FindAllByName(_queryString)) { yield return(o); } } break; case ResolveByCommand.WithType: { foreach (var o in ObjUtil.FindAll(SearchBy.Type, _queryString)) { yield return(o); } } break; } } break; case FindCommand.FindEntityInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: { var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg); if (go != null) { yield return(go); } } break; case ResolveByCommand.WithTag: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.HasTag(_queryString)) { yield return(e.Current); } } } break; case ResolveByCommand.WithName: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.CompareName(_queryString)) { yield return(e.Current); } } } break; case ResolveByCommand.WithType: { var e = SPEntity.Pool.GetEnumerator(); var tp = TypeUtil.FindType(_queryString); while (e.MoveNext()) { var o = e.Current.GetComponent(tp); if (o != null) { yield return(o); } } } break; } } break; } }
private static bool BuildSpringBoneFromSerializer ( SpringBoneSetupMaps setupMaps, SpringBoneSerializer serializer ) { var baseData = serializer.baseData; Transform childBone = null; if (!setupMaps.allChildren.TryGetValue(baseData.boneName, out childBone)) { Debug.LogError("ボーンが見つかりません: " + baseData.boneName); return(false); } var springBone = childBone.gameObject.AddComponent <SpringBone>(); springBone.stiffnessForce = baseData.stiffness; springBone.dragForce = baseData.drag; springBone.springForce = baseData.springForce; springBone.windInfluence = baseData.windInfluence; springBone.angularStiffness = baseData.angularStiffness; springBone.yAngleLimits = BuildAngleLimitsFromSerializer(baseData.yAngleLimits); springBone.zAngleLimits = BuildAngleLimitsFromSerializer(baseData.zAngleLimits); springBone.radius = baseData.radius; springBone.lodLevel = baseData.lodLevel; springBone.lodMode = (SpringBone.LODMode)baseData.lodMode; springBone.lengthLimitStiffness = baseData.lengthLimitStiffness; springBone.isLengthLimitPercentage = baseData.isLengthLimitPercentage; springBone.lengthLimitMode = (SpringBone.LengthLimitMode)baseData.lengthLimitMode; // Pivot node var pivotNodeName = baseData.pivotName; Transform pivotNode = null; if (pivotNodeName.Length > 0) { if (!setupMaps.allChildren.TryGetValue(pivotNodeName, out pivotNode)) { Debug.LogError("Pivotオブジェクトが見つかりません: " + pivotNodeName); pivotNode = null; } } if (pivotNode == null) { pivotNode = springBone.transform.parent ?? springBone.transform; } else { var skinBones = GameObjectUtil.GetAllBones(springBone.transform.root.gameObject); if (pivotNode.GetComponent <SpringBonePivot>() && SpringBoneSetup.IsPivotProbablySafeToDestroy(pivotNode, skinBones)) { pivotNode.position = springBone.transform.position; } } springBone.pivotNode = pivotNode; springBone.lengthLimitTargets = baseData.lengthLimits .Where(lengthLimit => setupMaps.allChildren.ContainsKey(lengthLimit.objectName)) .Select(lengthLimit => setupMaps.allChildren[lengthLimit.objectName]) .ToArray(); springBone.sphereColliders = serializer.colliderNames .Where(name => setupMaps.sphereColliders.ContainsKey(name)) .Select(name => setupMaps.sphereColliders[name]) .ToArray(); springBone.capsuleColliders = serializer.colliderNames .Where(name => setupMaps.capsuleColliders.ContainsKey(name)) .Select(name => setupMaps.capsuleColliders[name]) .ToArray(); springBone.panelColliders = serializer.colliderNames .Where(name => setupMaps.panelColliders.ContainsKey(name)) .Select(name => setupMaps.panelColliders[name]) .ToArray(); return(true); }
private void DrawGenerically(Rect position, SerializedProperty property, GUIContent label) { if (!this.DrawFlat) { var rh = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); position = new Rect(position.xMin, rh.yMax, position.width, position.height - rh.height); property.isExpanded = EditorGUI.Foldout(rh, property.isExpanded, label); if (!property.isExpanded) { return; } } var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight); var r1 = new Rect(r0.xMin, r0.yMax, r0.width, EditorGUIUtility.singleLineHeight); var r2 = new Rect(r1.xMin, r1.yMax, r1.width, EditorGUIUtility.singleLineHeight); var r3 = new Rect(r2.xMin, r2.yMax, r2.width, position.yMax - r2.yMax - EditorGUIUtility.singleLineHeight * 3f); var r4 = new Rect(r3.xMin, r3.yMax, r3.width, EditorGUIUtility.singleLineHeight); var r5 = new Rect(r4.xMin, r4.yMax, r4.width, EditorGUIUtility.singleLineHeight); var r6 = new Rect(r5.xMin, r5.yMax, r5.width, EditorGUIUtility.singleLineHeight); SPEditorGUI.PropertyField(r0, property.FindPropertyRelative(PROP_WEIGHT)); var propMode = property.FindPropertyRelative(PROP_MODE); SPEditorGUI.PropertyField(r1, propMode); switch (propMode.GetEnumValue <i_PlayAnimation.PlayByMode>()) { case i_PlayAnimation.PlayByMode.PlayAnim: { property.FindPropertyRelative(PROP_ID).stringValue = string.Empty; var clipProp = property.FindPropertyRelative(PROP_CLIP); var obj = EditorGUI.ObjectField(r2, EditorHelper.TempContent(clipProp.displayName), clipProp.objectReferenceValue, typeof(UnityEngine.Object), true); if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip) { clipProp.objectReferenceValue = obj; } else if (GameObjectUtil.IsGameObjectSource(obj)) { clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object; } } break; case i_PlayAnimation.PlayByMode.PlayAnimByID: { property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null; SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID)); } break; case i_PlayAnimation.PlayByMode.PlayAnimFromResource: { property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null; SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID)); } break; } this.DrawSettings(r3, property); SPEditorGUI.PropertyField(r4, property.FindPropertyRelative(PROP_QUEUEMODE)); SPEditorGUI.PropertyField(r5, property.FindPropertyRelative(PROP_PLAYMODE)); SPEditorGUI.PropertyField(r6, property.FindPropertyRelative(PROP_CROSSFADEDUR)); }
public void OnOutOfBounds() { offscren = false; GameObjectUtil.Destroy(gameObject); }
public void LerpToTarget(object targ, float t, float lerpT) { if (_dur == 0f) { t = 1f; } else { t = t / _dur; } if (_updateTranslation > TranslationOptions.None || _updateRotation >= RotationOptions.Heading) { var trans = GameObjectUtil.GetTransformFromSource(targ); if (trans != null) { if (_updateRotation == RotationOptions.Heading) { var wp = _path.Path.GetWaypointAt(t); this.SetPosition(trans, wp.Position, float.NaN); this.SetRotation(trans, Quaternion.LookRotation(wp.Heading), lerpT); } else if (_updateTranslation > TranslationOptions.None) { this.SetPosition(trans, _path.Path.GetPositionAt(t), lerpT); } } } bool useModifiers = (_modifierTable != null && _modifierTable.Count > 0); if (useModifiers || _updateRotation == RotationOptions.Rotation || _updateRotation == RotationOptions.LocalRotation) { var data = _path.Path.GetRelativePositionData(t); var cnt = _path.Path.Count; int i = data.Index; int j = (_path.Path.IsClosed) ? (i + 1) % cnt : i + 1; if (_updateRotation == RotationOptions.Rotation || _updateRotation == RotationOptions.LocalRotation) { var trans = GameObjectUtil.GetTransformFromSource(targ); if (trans != null) { var a = (i >= 0 && i < cnt) ? ComponentUtil.GetComponentFromSource <Transform>(_path.Path.ControlPoint(i)) : null; var b = (j >= 0 && j < cnt) ? ComponentUtil.GetComponentFromSource <Transform>(_path.Path.ControlPoint(j)) : null; if (a != null) { bool useRelative = _path.TransformRelativeTo != null; var r = (useRelative) ? a.GetRelativeRotation(_path.TransformRelativeTo) : a.rotation; if (b != null) { var rb = (useRelative) ? b.GetRelativeRotation(_path.TransformRelativeTo) : b.rotation; r = Quaternion.LerpUnclamped(r, rb, data.TPrime); } this.SetRotation(trans, r, lerpT); } } } if (useModifiers) { var e = _modifierTable.GetEnumerator(); while (e.MoveNext()) { var len = e.Current.Value.Length; var ma = (i >= 0 && i < len) ? e.Current.Value[i] : null; var mb = (j >= 0 && j < len) ? e.Current.Value[j] : null; if (float.IsNaN(lerpT)) { if (ma != null) { if (mb != null) { using (var state = StateToken.GetTempToken()) { ma.CopyTo(state); mb.LerpTo(state, data.TPrime); ma.ModifyWith(targ, state); } } else { ma.Modify(targ); } } else if (mb != null) { mb.Modify(targ); } } else { using (var curState = StateToken.GetTempToken()) using (var state = StateToken.GetTempToken()) { IStateModifier m = null; if (ma != null) { m = ma; if (mb != null) { ma.CopyTo(state); mb.LerpTo(state, data.TPrime); } else { ma.CopyTo(state); } } else if (mb != null) { m = mb; mb.CopyTo(state); } if (m != null) { state.CopyTo(curState); curState.CopyFrom(targ); curState.LerpTo(state, lerpT); m.ModifyWith(state, curState); } } } } } } }
private void DrawObjectRefField(Rect position, SerializedProperty property) { if (ComponentUtil.IsAcceptableComponentType(this.RestrictionType)) { var fieldObjType = (!this.SearchChildren && !this.AllowProxy && TypeUtil.IsType(this.RestrictionType, typeof(UnityEngine.Component))) ? this.RestrictionType : typeof(UnityEngine.GameObject); var obj = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObjects); if (this.ForceOnlySelf) { var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); var ngo = GameObjectUtil.GetGameObjectFromSource(obj); if (targGo == ngo || (this.SearchChildren && targGo.IsParentOf(ngo))) { property.objectReferenceValue = this.GetTargetFromSource(obj); } } else { property.objectReferenceValue = this.GetTargetFromSource(obj); } } else if (this.AllowNonComponents) { var fieldObjType = (!this.AllowProxy && TypeUtil.IsType(this.RestrictionType, typeof(UnityEngine.Object))) ? this.RestrictionType : typeof(UnityEngine.Object); var obj = EditorGUI.ObjectField(position, property.objectReferenceValue, fieldObjType, this.AllowSceneObjects); if (this.ForceOnlySelf) { var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); var ngo = GameObjectUtil.GetGameObjectFromSource(obj); if (targGo == ngo || (this.SearchChildren && targGo.IsParentOf(ngo))) { property.objectReferenceValue = this.GetTargetFromSource(obj); } } else { property.objectReferenceValue = this.GetTargetFromSource(obj); } } else { var ogo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue); var ngo = EditorGUI.ObjectField(position, ogo, typeof(GameObject), this.AllowSceneObjects) as GameObject; if (ogo != ngo) { if (this.ForceOnlySelf) { var targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targGo == ngo || (this.SearchChildren && targGo.IsParentOf(ngo))) { property.objectReferenceValue = this.GetTargetFromSource(ngo); } } else { property.objectReferenceValue = this.GetTargetFromSource(ngo); } } } }
private void DrawAdvanced_TriggerSelected(Rect area, SerializedProperty property) { /* * //Draw Target * var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); * var targProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); * var targLabel = EditorHelper.TempContent("Triggerable Target"); * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); * var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject; * if (newTargGo != targGo) * { * targGo = newTargGo; * targProp.objectReferenceValue = (targGo != null) ? targGo.GetComponent<ITriggerableMechanism>() as Component : null; * } * * var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight); * if (targProp.objectReferenceValue != null) * { * var selectedType = targProp.objectReferenceValue.GetType(); * var availableMechanismTypes = (from c in targGo.GetComponents<ITriggerableMechanism>() select c.GetType()).ToArray(); * var availableMechanismTypeNames = availableMechanismTypes.Select((tp) => tp.Name).ToArray(); * * var index = System.Array.IndexOf(availableMechanismTypes, selectedType); * EditorGUI.BeginChangeCheck(); * index = EditorGUI.Popup(targCompPopupRect, "Target Component", index, availableMechanismTypeNames); * if (EditorGUI.EndChangeCheck()) * { * targProp.objectReferenceValue = (index >= 0) ? targGo.GetComponent(availableMechanismTypes[index]) : null; * } * } * else * { * EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)"); * } * * //Draw Triggerable Arg * var argRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); * var btnRect = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); * var argArrayProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); * if (argArrayProp.arraySize == 0) * { * EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel); * if (GUI.Button(btnRect, _argBtnLabel)) * { * argArrayProp.arraySize = 1; * argArrayProp.serializedObject.ApplyModifiedProperties(); * } * } * else * { * if (argArrayProp.arraySize > 1) argArrayProp.arraySize = 1; * var argProp = argArrayProp.GetArrayElementAtIndex(0); * //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel); * _variantDrawer.RestrictVariantType = false; * _variantDrawer.ForcedObjectType = null; * _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel); * * if (GUI.Button(btnRect, _argBtnLabel)) * { * argArrayProp.arraySize = 0; * argArrayProp.serializedObject.ApplyModifiedProperties(); * } * } */ var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); var targProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); targRect = EditorGUI.PrefixLabel(targRect, EditorHelper.TempContent("Triggerable Target")); //validate if (!GameObjectUtil.IsGameObjectSource(targProp.objectReferenceValue) && !(targProp.objectReferenceValue is ITriggerable)) { targProp.objectReferenceValue = null; } //draw obj field if (targProp.objectReferenceValue != null) { if (SPEditorGUI.XButton(ref targRect, "Clear Selected Object", true)) { targProp.objectReferenceValue = null; goto DrawTriggerableArg; } var targObj = targProp.objectReferenceValue; var availableMechanisms = ObjUtil.GetAllFromSource <ITriggerable>(targObj); var availableMechanismTypeNames = availableMechanisms.Select((o) => EditorHelper.TempContent(o.GetType().Name)).ToArray(); var index = System.Array.IndexOf(availableMechanisms, targObj); EditorGUI.BeginChangeCheck(); index = EditorGUI.Popup(targRect, GUIContent.none, index, availableMechanismTypeNames); if (EditorGUI.EndChangeCheck()) { targObj = (index >= 0) ? availableMechanisms[index] as UnityEngine.Object : null; targProp.objectReferenceValue = targObj; } } else { EditorGUI.BeginChangeCheck(); var targObj = TargetObjectField(targRect, GUIContent.none, targProp.objectReferenceValue); if (EditorGUI.EndChangeCheck()) { targObj = ObjUtil.GetAsFromSource <ITriggerable>(targObj) as UnityEngine.Object; targProp.objectReferenceValue = targObj; } } //Draw Triggerable Arg DrawTriggerableArg: var argRect = new Rect(area.xMin, targRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); var btnRect = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight); var argArrayProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize == 0) { EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel); if (GUI.Button(btnRect, _argBtnLabel)) { argArrayProp.arraySize = 1; argArrayProp.serializedObject.ApplyModifiedProperties(); } } else { if (argArrayProp.arraySize > 1) { argArrayProp.arraySize = 1; } var argProp = argArrayProp.GetArrayElementAtIndex(0); //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel); _variantDrawer.RestrictVariantType = false; _variantDrawer.ForcedObjectType = null; _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel); if (GUI.Button(btnRect, _argBtnLabel)) { argArrayProp.arraySize = 0; argArrayProp.serializedObject.ApplyModifiedProperties(); } } }
private void DrawAdvanced_CallMethodOnSelected(Rect area, SerializedProperty property) { //Draw Target /* * var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); * var targProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); * var targLabel = EditorHelper.TempContent("Triggerable Target"); * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); * var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject; * if (newTargGo != targGo) * { * targGo = newTargGo; * targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null; * } * * var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight); * if (targGo != null) * { * EditorGUI.BeginChangeCheck(); * var selectedComp = SPEditorGUI.SelectComponentFromSourceField(targCompPopupRect, "Target Component", targGo, targProp.objectReferenceValue as Component); * if (EditorGUI.EndChangeCheck()) * { * targProp.objectReferenceValue = selectedComp; * } * } * else * { * EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)"); * } */ var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight); var targProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG); targRect = EditorGUI.PrefixLabel(targRect, EditorHelper.TempContent("Triggerable Target")); var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue); if (targGo != null) { if (SPEditorGUI.XButton(ref targRect, "Clear Selected Object", true)) { targProp.objectReferenceValue = null; goto DrawMethodName; } EditorGUI.BeginChangeCheck(); var selectedComp = SPEditorGUI.SelectComponentFromSourceField(targRect, GUIContent.none, targGo, targProp.objectReferenceValue as Component); if (EditorGUI.EndChangeCheck()) { targProp.objectReferenceValue = selectedComp; } } else { targProp.objectReferenceValue = TargetObjectField(targRect, GUIContent.none, targProp.objectReferenceValue); } //Draw Method Name DrawMethodName: //var methNameRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width, EditorGUIUtility.singleLineHeight); var methNameRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight); System.Reflection.MemberInfo selectedMember = null; if (targProp.objectReferenceValue != null) { var methProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_METHODNAME); //var tp = targProp.objectReferenceValue.GetType(); //var members = GetAvailableMethods(tp).ToArray(); //var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.Method).ToArray(); var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.All, spacepuppy.Dynamic.DynamicMemberAccess.Write).ToArray(); System.Array.Sort(members, (a, b) => string.Compare(a.Name, b.Name, true)); var memberNames = members.Select((m) => m.Name).ToArray(); int index = System.Array.IndexOf(memberNames, methProp.stringValue); index = EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), index, (from n in memberNames select new GUIContent(n)).ToArray()); methProp.stringValue = (index >= 0) ? memberNames[index] : null; selectedMember = (index >= 0) ? members[index] : null; } else { EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), -1, new GUIContent[0]); } property.serializedObject.ApplyModifiedProperties(); //Draw Triggerable Arg var parr = (selectedMember != null) ? com.spacepuppy.Dynamic.DynamicUtil.GetDynamicParameterInfo(selectedMember) : null; if (parr == null || parr.Length == 0) { //NO PARAMETERS _callMethodModeExtraLines = 1; var argRect = new Rect(area.xMin, methNameRect.yMax, area.width, EditorGUIUtility.singleLineHeight); var argArrayProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize > 0) { argArrayProp.arraySize = 0; argArrayProp.serializedObject.ApplyModifiedProperties(); } var cache = SPGUI.Disable(); EditorGUI.LabelField(argRect, GUIContent.none, new GUIContent("*Zero Parameter Count*")); cache.Reset(); } else { //MULTIPLE PARAMETERS - special case, does not support trigger event arg _callMethodModeExtraLines = parr.Length; var argArrayProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS); if (argArrayProp.arraySize != parr.Length) { argArrayProp.arraySize = parr.Length; argArrayProp.serializedObject.ApplyModifiedProperties(); } EditorGUI.indentLevel++; for (int i = 0; i < parr.Length; i++) { var paramType = parr[i].ParameterType; var argRect = new Rect(area.xMin, methNameRect.yMax + i * EditorGUIUtility.singleLineHeight, area.width, EditorGUIUtility.singleLineHeight); var argProp = argArrayProp.GetArrayElementAtIndex(i); if (paramType == typeof(object)) { //draw the default variant as the method accepts anything _variantDrawer.RestrictVariantType = false; _variantDrawer.ForcedObjectType = null; _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed.")); } else { _variantDrawer.RestrictVariantType = true; _variantDrawer.TypeRestrictedTo = paramType; _variantDrawer.ForcedObjectType = (paramType.IsInterface || TypeUtil.IsType(paramType, typeof(Component))) ? paramType : null; _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed.")); } } EditorGUI.indentLevel--; } }
private void NormalizeActionAndWeightArrays() { var go = GameObjectUtil.GetGameObjectFromSource(this.serializedObject.targetObject); if (go == null) { return; } var propActions = this.serializedObject.FindProperty(PROP_ACTIONS); var propWeights = this.serializedObject.FindProperty(PROP_WEIGHTS); var currentActions = go.GetComponents <IAIAction>(); IAIAction[] serializedActions = new IAIAction[propActions.arraySize]; for (int i = 0; i < serializedActions.Length; i++) { serializedActions[i] = propActions.GetArrayElementAtIndex(i).objectReferenceValue as IAIAction; } if (currentActions.Length == serializedActions.Length && currentActions.Compare(serializedActions)) { if (propWeights.arraySize != serializedActions.Length) { propWeights.arraySize = serializedActions.Length; } return; } var serializedWeights = (EditorHelper.GetTargetObjectOfProperty(propWeights) as DiminishingWeightOverDuration[]); if (serializedWeights == null) { serializedWeights = new DiminishingWeightOverDuration[] { } } ; else { serializedWeights = serializedWeights.ToArray(); } propActions.arraySize = currentActions.Length; var weights = new List <DiminishingWeightOverDuration>(); float defaultWeight = this.serializedObject.FindProperty(PROP_DEFAULTWEIGHT).floatValue; for (int i = 0; i < currentActions.Length; i++) { propActions.GetArrayElementAtIndex(i).objectReferenceValue = currentActions[i] as Component; int j = serializedActions.IndexOf(currentActions[i]); if (j >= 0 && j < serializedWeights.Length && serializedWeights[j] != null) { weights.Add(serializedWeights[j]); } else { Debug.Log(currentActions[i].GetType().Name + " had no weight"); weights.Add(new DiminishingWeightOverDuration(defaultWeight)); } } this.serializedObject.ApplyModifiedProperties(); EditorHelper.SetTargetObjectOfProperty(propWeights, weights.ToArray()); this.serializedObject.Update(); }
protected void DrawDefaultMaterialSourceInspector() { var prop = this.serializedObject.FindProperty(PROP_RENDERER); var source = this.target as RendererMaterialSource; var go = GameObjectUtil.GetGameObjectFromSource(source); if (go == null) { EditorGUILayout.HelpBox("MaterialSource can not find target GameObject it's attached to.", MessageType.Error); return; } if (Application.isPlaying) { var cache = SPGUI.Disable(); this.DrawPropertyField(PROP_RENDERER); this.DrawPropertyField(PROP_MAKEUNIQUEONSTART); EditorGUILayout.Toggle("Is Unique", source.IsUnique); cache.Reset(); } else { if (prop.objectReferenceValue != null && prop.objectReferenceValue is Renderer) { var renderer = prop.objectReferenceValue as Renderer; if (renderer.gameObject != go) { prop.objectReferenceValue = null; } } var renderers = go.GetComponents <Renderer>(); if (renderers.Length == 0) { EditorGUILayout.HelpBox("MaterialSource can not find a Renderer on that GameObject it's attached to.", MessageType.Error); return; } else { var sources = go.GetComponents <RendererMaterialSource>(); if (sources.Length > renderers.Length) { Debug.LogWarning("There are too many MaterialSources attached to this GameObject. Removing extra.", go); UnityEngine.Object.DestroyImmediate(this.target); return; } renderers = renderers.Except((from s in sources where s.Renderer != null && s.Renderer != source.Renderer select s.Renderer)).ToArray(); var names = (from r in renderers select EditorHelper.TempContent(r.GetType().Name)).ToArray(); int index = renderers.IndexOf(source.Renderer); index = EditorGUILayout.Popup(EditorHelper.TempContent("Renderer"), index, names); if (index >= 0) { prop.objectReferenceValue = renderers[index]; } else { prop.objectReferenceValue = null; } } this.DrawPropertyField(PROP_MAKEUNIQUEONSTART); } }
public void DoStart() { blocks = GameObjectUtil.CollapseChildrenToList <Block>(blocksParent); }
/// <summary> /// When a click(touch) moved over the GridCell. /// </summary> private void GridCellClickMoved() { if (currentLine == null) { Debug.Log("Current Line is undefined"); return; } if (currentGridCell == null) { Debug.Log("Current GridCell is undefined"); return; } if (previousGridCell == null) { Debug.Log("Previous GridCell is undefined"); return; } if (currentGridCell.index == previousGridCell.index) { return; } ///If the current grid cell is not adjacent of the previous grid cell,then ignore it if (!previousGridCell.OneOfAdjacents(currentGridCell.index)) { Debug.Log("Current grid cell of index " + currentGridCell.index + " is Ignored [Reason : Not Adjacent Of Previous GridCell " + previousGridCell.index); return; } ///If the current grid cell is currently used if (currentGridCell.currentlyUsed) { if (currentGridCell.gridLineIndex == -1) { return; } if (currentGridCell.gridLineIndex == previousGridCell.gridLineIndex) { gridLines [currentGridCell.gridLineIndex].RemoveElements(currentGridCell.index); previousGridCell = currentGridCell; Debug.Log("Remove some Elements from the Line Path of index " + currentGridCell.gridLineIndex); ///Increase the movements counter IncreaseMovements(); return; //skip next } else { Debug.Log("Clear the Line Path of index " + currentGridCell.gridLineIndex); gridLines [currentGridCell.gridLineIndex].ClearPath(); } } ///If the current grid cell is not empty or it's not a partner of the previous grid cell if (!currentGridCell.isEmpty && currentGridCell.index != previousGridCell.tragetIndex) { Debug.Log("Current grid cell of index " + currentGridCell.index + " is Ignored [Reason : Not the wanted Traget]"); return; //skip next } ///Increase the movements counter IncreaseMovements(); ///Setting up the attributes for the current grid cell currentGridCell.currentlyUsed = true; currentGridCell.gridLineIndex = previousGridCell.gridLineIndex; if (currentGridCell.gridLineIndex == -1) { return; } if (currentGridCell.isEmpty) { currentGridCell.tragetIndex = previousGridCell.tragetIndex; } ///Link the color of top background of the current grid cell with the top background color of the previous grid cell currentGridCell.topBackgroundColor = previousGridCell.topBackgroundColor; Debug.Log("New GridCell of Index " + currentGridCell.index + " added to the Line Path of index " + currentLine.index); ///Add the current grid cell index to the current traced grid cells list currentLine.path.Add(currentGridCell.index); ///Determine the New Line Point tempPoint = currentGridCell.transform.position; tempPoint.z = gridLineZPosition; ///Add the position of the New Line Point to the current line gridLines [currentGridCell.gridLineIndex].AddPoint(tempPoint); bool playBubble = true; if (!currentGridCell.isEmpty) { //Two pairs connected if (previousGridCell.tragetIndex == currentGridCell.index) { Debug.Log("Two GridCells connected [GridCell " + (gridLines [currentGridCell.gridLineIndex].GetFirstPathElement()) + " with GridCell " + (gridLines [currentGridCell.gridLineIndex].GetLastPathElement()) + "]"); currentLine.completedLine = true; GridCell gridCell = null; for (int i = 0; i < currentLine.path.Count; i++) { gridCell = gridCells [currentLine.path [i]]; if (i == 0 || i == currentLine.path.Count - 1) { //Setting up the connect pairs GameObjectUtil.FindChildByTag(gridCell.transform, "GridCellContent").GetComponent <SpriteRenderer> ().sprite = currentLevel.dotsPairs [gridCell.elementPairIndex].connectSprite; } ///Setting up the color of the top background of the grid cell tempColor = previousGridCell.topBackgroundColor; tempColor.a = gridCellTopBackgroundAlpha; tempSpriteRendererd = gridCell.transform.Find("background").GetComponent <SpriteRenderer> (); tempSpriteRendererd.color = tempColor; ///Enable the top backgroud of the grid cell tempSpriteRendererd.enabled = true; } ///Play the connected sound effect at the center of the unity world AudioSource.PlayClipAtPoint(connectedSFX, Vector3.zero, effectsAudioSource.volume); playBubble = false; Release(null); //检查是否过关 CheckLevelComplete(); return; } } if (playBubble) { ///Play the water buttle sound effect at the center of the unity world AudioSource.PlayClipAtPoint(waterBubbleSFX, Vector3.zero, effectsAudioSource.volume); } previousGridCell = currentGridCell; }
private double EvalVariable() { _strBuilder.Length = 0; int i = _reader.Read(); if (i < 0) { return(ConvertUtil.ToDouble(_x)); } _current = (char)i; if (_current == '.') { var target = _x; string sprop; //access x for (i = _reader.Read(); i >= 0; i = _reader.Read()) { _current = (char)i; if (char.IsLetterOrDigit(_current) || _current == '_') { _strBuilder.Append(_current); } else if (_current == '.') { sprop = _strBuilder.ToString(); _strBuilder.Length = 0; target = DynamicUtil.GetValue(target, sprop); } else if (char.IsWhiteSpace(_current) || IsArithmeticSymbol(_current) || _current == ')' || _current == ',') { break; } else { throw new System.InvalidOperationException("Failed to parse the command."); } } sprop = _strBuilder.ToString(); _strBuilder.Length = 0; return(ConvertUtil.ToDouble(DynamicUtil.GetValue(target, sprop))); } else if (_current == '(') { for (i = _reader.Read(); i >= 0; i = _reader.Read()) { _current = (char)i; if (char.IsLetterOrDigit(_current) || _current == '_') { _strBuilder.Append(_current); } else if (_current == ')') { break; } else { throw new System.InvalidOperationException("Failed to parse the command."); } } i = _reader.Read(); if (i < 0 || (char)i != '.') { throw new System.InvalidOperationException("Failed to parse the command."); } string stp = _strBuilder.ToString(); _strBuilder.Length = 0; var go = GameObjectUtil.GetGameObjectFromSource(_x); object target = go != null?go.GetComponent(stp) : null; string sprop; //access target for (i = _reader.Read(); i >= 0; i = _reader.Read()) { _current = (char)i; if (char.IsLetterOrDigit(_current) || _current == '_') { _strBuilder.Append(_current); } else if (_current == '.') { sprop = _strBuilder.ToString(); _strBuilder.Length = 0; target = DynamicUtil.GetValue(target, sprop); } else if (char.IsWhiteSpace(_current) || IsArithmeticSymbol(_current) || _current == ')' || _current == ',' || _current == ']') { break; } else { throw new System.InvalidOperationException("Failed to parse the command."); } } sprop = _strBuilder.ToString(); _strBuilder.Length = 0; return(ConvertUtil.ToDouble(DynamicUtil.GetValue(target, sprop))); } else if (char.IsLetterOrDigit(_current) || _current == '_' || _current == '-') { //global _strBuilder.Append(char.ToLower(_current)); for (i = _reader.Read(); i >= 0; i = _reader.Read()) { _current = (char)i; if (char.IsLetterOrDigit(_current) || _current == '_') { _strBuilder.Append(char.ToLower(_current)); } else if (char.IsWhiteSpace(_current) || IsArithmeticSymbol(_current) || _current == ')' || _current == ',') { break; } else { throw new System.InvalidOperationException("Failed to parse the command."); } } var str = _strBuilder.ToString(); _strBuilder.Length = 0; switch (str) { case "pi": return(System.Math.PI); case "2pi": const double TWO_PI = System.Math.PI * 2d; return(TWO_PI); case "pi_2": const double PI_TWO = System.Math.PI / 2d; return(PI_TWO); case "rad2deg": const double RAD2DEG = 180d / System.Math.PI; return(RAD2DEG); case "deg2rad": const double DEG2RAD = System.Math.PI / 180d; return(DEG2RAD); case "secsinmin": return(60d); case "secsinhour": return(3600d); case "secsinday": return(86400d); case "secsinweek": return(604800d); case "secsinyear": return(31536000d); case "infinity": case "inf": return(double.PositiveInfinity); case "-infinity": case "-inf": return(double.NegativeInfinity); case "time": return(UnityEngine.Time.time); case "unscaledtime": return(UnityEngine.Time.unscaledTime); case "fixedtime": return(UnityEngine.Time.fixedTime); case "deltatime": return(UnityEngine.Time.deltaTime); case "fixeddeltatime": return(UnityEngine.Time.fixedDeltaTime); default: return(0d); } } else if (char.IsWhiteSpace(_current) || IsArithmeticSymbol(_current) || _current == ')' || _current == ',') { return(ConvertUtil.ToDouble(_x)); } else { throw new System.InvalidOperationException("Failed to parse the command."); } }
private static void ApplyDefaultAsList(SerializedProperty property, System.Type elementType, System.Type restrictionType, EntityRelativity relativity) { if (property.arraySize != 0) { return; } if (elementType == null || restrictionType == null) { return; } if (TypeUtil.IsType(elementType, typeof(VariantReference))) { var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targ == null) { var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject); if (obj != null) { property.arraySize = 1; var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(0)) as VariantReference; if (variant == null) { return; } variant.Value = obj; property.serializedObject.Update(); GUI.changed = true; } else if (property.arraySize > 0) { property.arraySize = 0; GUI.changed = true; } return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; case EntityRelativity.Self: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, false); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; case EntityRelativity.SelfAndChildren: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference; if (variant != null) { variant.Value = arr[i]; } } property.serializedObject.Update(); GUI.changed = true; } break; } } else if (TypeUtil.IsType(elementType, typeof(UnityEngine.Object))) { var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targ == null) { var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject) as UnityEngine.Object; if (obj != null) { property.arraySize = 1; property.GetArrayElementAtIndex(0).objectReferenceValue = obj; GUI.changed = true; } else if (property.arraySize > 0) { property.arraySize = 0; GUI.changed = true; } return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; case EntityRelativity.Self: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, false); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; case EntityRelativity.SelfAndChildren: { var arr = ObjUtil.GetAllFromSource(restrictionType, targ, true); property.arraySize = arr.Length; for (int i = 0; i < arr.Length; i++) { property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i] as UnityEngine.Object; } } break; } } }
private void Start() { // Must get the ForceProviders in Start and not Awake or Unity will complain that // "the scene is not loaded" forceProviders = GameObjectUtil.FindComponentsOfType <ForceProvider>().ToArray(); }
private static void ApplyDefaultAsSingle(SerializedProperty property, System.Type fieldType, System.Type restrictionType, EntityRelativity relativity) { if (fieldType == null) { return; } if (TypeUtil.IsType(fieldType, typeof(VariantReference))) { var variant = EditorHelper.GetTargetObjectOfProperty(property) as VariantReference; if (variant == null) { return; } if (variant.Value != null) { return; } var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targ == null) { var obj = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject); if (obj != null) { variant.Value = obj; property.serializedObject.Update(); GUI.changed = true; } return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var obj = ObjUtil.GetAsFromSource(restrictionType, targ); if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } if (obj != null) { variant.Value = obj; property.serializedObject.Update(); } } break; case EntityRelativity.Self: { var obj = ObjUtil.GetAsFromSource(restrictionType, targ); if (obj != null) { variant.Value = obj; property.serializedObject.Update(); } } break; case EntityRelativity.SelfAndChildren: { var obj = ObjUtil.GetAsFromSource(restrictionType, targ); if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } if (obj != null) { variant.Value = obj; property.serializedObject.Update(); } } break; } } else if (property.propertyType == SerializedPropertyType.ObjectReference) { if (property.objectReferenceValue != null) { return; } var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targ == null) { property.objectReferenceValue = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject) as UnityEngine.Object; return; } switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object; if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } if (obj != null) { property.objectReferenceValue = obj; GUI.changed = true; } } break; case EntityRelativity.Self: { var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object; if (obj != null) { property.objectReferenceValue = obj; GUI.changed = true; } } break; case EntityRelativity.SelfAndChildren: { var obj = ObjUtil.GetAsFromSource(restrictionType, targ) as UnityEngine.Object; if (obj == null && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } if (obj != null) { property.objectReferenceValue = obj; GUI.changed = true; } } break; } } }
public static Unit CreateNewUnit(Transform _parent, UnitType _unitType, string _name = "") { return(GameObjectUtil.CreateInstance <Unit>( _parent, _name.Length <= 0 ? _unitType.ToString() : _name)); }
public void OnGUI(Rect position, SerializedProperty property) { //if (property.propertyType != SerializedPropertyType.ObjectReference || !TypeUtil.IsType(_restrictionType, typeof(Component), typeof(IComponent))) if (property.propertyType != SerializedPropertyType.ObjectReference || (!this.AllowNonComponents && !ComponentUtil.IsAcceptableComponentType(this.RestrictionType))) { this.DrawAsMismatchedAttribute(position, property); return; } this.Init(); GameObject targGo; if (this.ForceOnlySelf) { targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targGo == null) { this.DrawAsMismatchedAttribute(position, property); return; } if (property.objectReferenceValue == null) { property.objectReferenceValue = this.GetTargetFromSource(targGo); } } targGo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue); if (property.objectReferenceValue == null) { //SPEditorGUI.DefaultPropertyField(position, property, label); if (!this.ForceOnlySelf) { this.DrawObjectRefField(position, property); } else { EditorGUI.LabelField(position, "Malformed serializable field."); } } else if (this.AllowNonComponents) { if (targGo == null) { this.DrawObjectRefField(position, property); } else { this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType, this.AllowProxy); var components = this.ChoiceSelector.GetComponents(); var fullsize = position; if (components.Length == 0 || (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide))) { property.objectReferenceValue = null; fullsize = this.DrawDotDotButton(fullsize, property); this.DrawObjectRefField(fullsize, property); this.ChoiceSelector.GUIComplete(property, -1); } else { position = this.DrawDotDotButton(position, property); var names = this.ChoiceSelector.GetPopupEntries(); System.Array.Resize(ref names, names.Length + 1); names[names.Length - 1] = EditorHelper.TempContent(targGo.name + " (...GameObject)"); int oi = (property.objectReferenceValue is GameObject) ? names.Length - 1 : this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component); int ni = EditorGUI.Popup(position, oi, names); if (oi != ni) { if (ni == names.Length - 1) { property.objectReferenceValue = targGo; } else { property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni); } //if (ni < components.Length) // property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni); //else // property.objectReferenceValue = targGo; } this.ChoiceSelector.GUIComplete(property, ni); } } } else { this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType, this.AllowProxy); var components = this.ChoiceSelector.GetComponents(); var fullsize = position; if (components.Length == 0 || (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide))) { property.objectReferenceValue = null; fullsize = this.DrawDotDotButton(fullsize, property); this.DrawObjectRefField(fullsize, property); this.ChoiceSelector.GUIComplete(property, -1); } else { position = this.DrawDotDotButton(position, property); var names = this.ChoiceSelector.GetPopupEntries(); int oi = this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component); int ni = EditorGUI.Popup(position, oi, names); if (oi != ni) { property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni); } this.ChoiceSelector.GUIComplete(property, ni); } } }
public static T[] FindAll <T>(SearchBy search, string query) where T : class { switch (search) { case SearchBy.Nothing: return(ArrayUtil.Empty <T>()); case SearchBy.Tag: { using (var tmp = com.spacepuppy.Collections.TempCollection.GetList <UnityEngine.GameObject>()) using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { GameObjectUtil.FindGameObjectsWithMultiTag(query, tmp); var e = tmp.GetEnumerator(); while (e.MoveNext()) { var o = ObjUtil.GetAsFromSource <T>(e.Current); if (o != null) { results.Add(o); } } return(results.ToArray()); } } case SearchBy.Name: { using (var tmp = com.spacepuppy.Collections.TempCollection.GetList <UnityEngine.GameObject>()) using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { GameObjectUtil.FindAllByName(query, tmp); var e = tmp.GetEnumerator(); while (e.MoveNext()) { var o = ObjUtil.GetAsFromSource <T>(e.Current); if (o != null) { results.Add(o); } } return(results.ToArray()); } } case SearchBy.Type: { using (var results = com.spacepuppy.Collections.TempCollection.GetList <T>()) { foreach (var o in UnityEngine.Object.FindObjectsOfType(TypeUtil.FindType(query))) { var o2 = ObjUtil.GetAsFromSource <T>(o); if (o2 != null) { results.Add(o2); } } return(results.ToArray()); } } default: return(null); } }
private void OnEnable() { GameObjectUtil.Destroy(gameObject, m_time); }
private void EnsureAllGazeEventHandlersCanBeFound() { GameObjectUtil.EnsureComponentIsPresentForObjectsInSceneWithInterface <IGazeEventHandler, Collider>(missing => missing.AddComponent <SphereCollider>()); }
private void DrawValueFieldInValueMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper) { if (helper.Target == null) { return; } var variant = helper.Target; if (this.RestrictVariantType && helper._type != this.VariantTypeRestrictedTo) { helper.PrepareForValueTypeChange(this.VariantTypeRestrictedTo); GUI.changed = true; //force change } var r0 = new Rect(position.xMin, position.yMin, 90.0f, EditorGUIUtility.singleLineHeight); var r1 = new Rect(r0.xMax, position.yMin, position.xMax - r0.xMax, EditorGUIUtility.singleLineHeight); var cache = SPGUI.DisableIf(this.RestrictVariantType); EditorGUI.BeginChangeCheck(); var valueType = variant.ValueType; valueType = (VariantType)EditorGUI.EnumPopup(r0, GUIContent.none, valueType); if (EditorGUI.EndChangeCheck()) { helper.PrepareForValueTypeChange(valueType); } cache.Reset(); if (_typeRestrictedTo.IsEnum) { variant.IntValue = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(_typeRestrictedTo, variant.IntValue))); } else { switch (valueType) { case VariantType.Null: cache = SPGUI.Disable(); EditorGUI.TextField(r1, "Null"); cache.Reset(); break; case VariantType.String: variant.StringValue = EditorGUI.TextField(r1, variant.StringValue); break; case VariantType.Boolean: variant.BoolValue = EditorGUI.Toggle(r1, variant.BoolValue); break; case VariantType.Integer: variant.IntValue = EditorGUI.IntField(r1, variant.IntValue); break; case VariantType.Float: variant.FloatValue = EditorGUI.FloatField(r1, variant.FloatValue); break; case VariantType.Double: //variant.DoubleValue = ConvertUtil.ToDouble(EditorGUI.TextField(r1, variant.DoubleValue.ToString())); variant.DoubleValue = EditorGUI.DoubleField(r1, variant.DoubleValue); break; case VariantType.Vector2: variant.Vector2Value = EditorGUI.Vector2Field(r1, GUIContent.none, variant.Vector2Value); break; case VariantType.Vector3: variant.Vector3Value = EditorGUI.Vector3Field(r1, GUIContent.none, variant.Vector3Value); break; case VariantType.Vector4: variant.Vector4Value = EditorGUI.Vector4Field(r1, (string)null, variant.Vector4Value); break; case VariantType.Quaternion: variant.QuaternionValue = SPEditorGUI.QuaternionField(r1, GUIContent.none, variant.QuaternionValue); break; case VariantType.Color: variant.ColorValue = EditorGUI.ColorField(r1, variant.ColorValue); break; case VariantType.DateTime: variant.DateValue = ConvertUtil.ToDate(EditorGUI.TextField(r1, variant.DateValue.ToString())); break; case VariantType.GameObject: variant.GameObjectValue = EditorGUI.ObjectField(r1, variant.GameObjectValue, typeof(GameObject), true) as GameObject; break; case VariantType.Component: { _selectComponentDrawer.AllowNonComponents = false; _selectComponentDrawer.RestrictionType = ComponentUtil.IsAcceptableComponentType(_forcedObjectType) ? _forcedObjectType : typeof(Component); _selectComponentDrawer.ShowXButton = true; var targProp = property.FindPropertyRelative(PROP_OBJREF); EditorGUI.BeginChangeCheck(); _selectComponentDrawer.OnGUI(r1, targProp); if (EditorGUI.EndChangeCheck()) { variant.ComponentValue = targProp.objectReferenceValue as Component; } } break; case VariantType.Object: { var obj = variant.ObjectValue; if (ComponentUtil.IsAcceptableComponentType(_forcedObjectType)) { if (obj is GameObject || obj is Component) { _selectComponentDrawer.AllowNonComponents = false; _selectComponentDrawer.RestrictionType = _forcedObjectType; _selectComponentDrawer.ShowXButton = true; var targProp = property.FindPropertyRelative(PROP_OBJREF); EditorGUI.BeginChangeCheck(); _selectComponentDrawer.OnGUI(r1, targProp); if (EditorGUI.EndChangeCheck()) { variant.ObjectValue = targProp.objectReferenceValue as Component; } } else { EditorGUI.BeginChangeCheck(); obj = EditorGUI.ObjectField(r1, obj, typeof(UnityEngine.Object), true); if (EditorGUI.EndChangeCheck()) { if (obj == null) { variant.ObjectValue = null; } else if (_forcedObjectType.IsInstanceOfType(obj)) { variant.ObjectValue = obj; } else { var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go != null) { variant.ObjectValue = go.GetComponent(_forcedObjectType); } else { variant.ObjectValue = null; } } } } } else { variant.ObjectValue = EditorGUI.ObjectField(r1, obj, _forcedObjectType, true); } } break; case VariantType.LayerMask: { variant.LayerMaskValue = SPEditorGUI.LayerMaskField(r1, GUIContent.none, (int)variant.LayerMaskValue); } break; case VariantType.Rect: { variant.RectValue = EditorGUI.RectField(r1, variant.RectValue); } break; case VariantType.Numeric: { //we just treat numeric types as double and let the numeric deal with it var tp = this.TypeRestrictedTo; if (tp != null && typeof(INumeric).IsAssignableFrom(tp)) { var n = variant.NumericValue; double d = n != null?n.ToDouble(null) : 0d; EditorGUI.BeginChangeCheck(); d = EditorGUI.DoubleField(r1, d); if (EditorGUI.EndChangeCheck()) { variant.NumericValue = Numerics.CreateNumeric(tp, d); } } else { variant.DoubleValue = EditorGUI.DoubleField(r1, variant.DoubleValue); } } break; } } }
// Use this for initialization private void Awake() { GameObjectUtil.RegisterSingleton <MessageBox>(this); tweenLayer = GetComponent <TweenLayer>(); }
private object ReduceTarget(object triggerArg) { var targ = _target; if (targ is IProxy) { targ = (targ as IProxy).GetTarget(triggerArg) as UnityEngine.Object; } switch (_find) { case FindCommand.Direct: { object obj = (_configured) ? targ : triggerArg; if (obj == null) { return(null); } switch (_resolveBy) { case ResolveByCommand.Nothing: return(obj); case ResolveByCommand.WithTag: return(GameObjectUtil.GetGameObjectFromSource(obj).HasTag(_queryString) ? obj : null); case ResolveByCommand.WithName: return(GameObjectUtil.GetGameObjectFromSource(obj).CompareName(_queryString) ? obj : null); case ResolveByCommand.WithType: return(ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj)) != null ? obj : null); } } break; case FindCommand.FindParent: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? targ : triggerArg); if (trans == null) { return(null); } switch (_resolveBy) { case ResolveByCommand.Nothing: return(trans.parent); case ResolveByCommand.WithTag: return(trans.FindParentWithTag(_queryString)); case ResolveByCommand.WithName: return(trans.FindParentWithName(_queryString)); case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var p in GameObjectUtil.GetParents(trans)) { var o = ObjUtil.GetAsFromSource(tp, p); if (o != null) { return(o); } } return(null); } } } break; case FindCommand.FindInChildren: { Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? targ : triggerArg); if (trans == null) { return(null); } switch (_resolveBy) { case ResolveByCommand.Nothing: return((trans.childCount > 0) ? trans.GetChild(0) : null); case ResolveByCommand.WithTag: if (trans.childCount > 0) { using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { if (lst[i].HasTag(_queryString)) { return(lst[i]); } } } } break; case ResolveByCommand.WithName: if (trans.childCount > 0) { return(trans.FindByName(_queryString)); } break; case ResolveByCommand.WithType: if (trans.childCount > 0) { var tp = TypeUtil.FindType(_queryString); using (var lst = TempCollection.GetList <Transform>()) { GameObjectUtil.GetAllChildren(trans, lst); for (int i = 0; i < lst.Count; i++) { var o = ObjUtil.GetAsFromSource(tp, lst[i]); if (o != null) { return(o); } } } } break; } } break; case FindCommand.FindInEntity: { GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? targ : triggerArg); if (entity == null) { return(null); } switch (_resolveBy) { case ResolveByCommand.Nothing: return(entity); case ResolveByCommand.WithTag: return(entity.FindWithMultiTag(_queryString)); case ResolveByCommand.WithName: return(entity.FindByName(_queryString)); case ResolveByCommand.WithType: { var tp = TypeUtil.FindType(_queryString); foreach (var t in GameObjectUtil.GetAllChildrenAndSelf(entity)) { var o = ObjUtil.GetAsFromSource(tp, t); if (o != null) { return(o); } } return(null); } } } break; case FindCommand.FindInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: return(GameObjectUtil.GetGameObjectFromSource((_configured) ? targ : triggerArg)); case ResolveByCommand.WithTag: return(GameObjectUtil.FindWithMultiTag(_queryString)); case ResolveByCommand.WithName: return(GameObject.Find(_queryString)); case ResolveByCommand.WithType: return(ObjUtil.Find(SearchBy.Type, _queryString)); } } break; case FindCommand.FindEntityInScene: { switch (_resolveBy) { case ResolveByCommand.Nothing: return(GameObjectUtil.GetGameObjectFromSource((_configured) ? targ : triggerArg)); case ResolveByCommand.WithTag: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.HasTag(_queryString)) { return(e.Current); } } } break; case ResolveByCommand.WithName: { var e = SPEntity.Pool.GetEnumerator(); while (e.MoveNext()) { if (e.Current.CompareName(_queryString)) { return(e.Current); } } } break; case ResolveByCommand.WithType: { var e = SPEntity.Pool.GetEnumerator(); var tp = TypeUtil.FindType(_queryString); while (e.MoveNext()) { var o = e.Current.GetComponentInChildren(tp); if (o != null) { return(o); } } } break; } } break; } return(null); }
private void Trigger_Imp(object sender, object incomingArg, object outgoingArg, BlockingTriggerYieldInstruction instruction) { switch (this._activationType) { case TriggerActivationType.TriggerAllOnTarget: { if (_triggerAllCache == null) { //_triggerAllCache = _triggerable.GetComponentsAlt<ITriggerableMechanism>(); var go = GameObjectUtil.GetGameObjectFromSource(_triggerable); if (go != null) { _triggerAllCache = go.GetComponents <ITriggerableMechanism>(); } else if (_triggerable is ITriggerableMechanism) { _triggerAllCache = new ITriggerableMechanism[] { _triggerable as ITriggerableMechanism } } ; else { _triggerAllCache = ArrayUtil.Empty <ITriggerableMechanism>(); } if (_triggerableArgs.Length > 1) { System.Array.Sort(_triggerableArgs, TriggerableMechanismOrderComparer.Default); } } if (instruction != null) { foreach (var t in _triggerAllCache) { if (t.CanTrigger) { if (t is IBlockingTriggerableMechanism) { (t as IBlockingTriggerableMechanism).Trigger(sender, outgoingArg, instruction); } else { t.Trigger(sender, outgoingArg); } } } } else { foreach (var t in _triggerAllCache) { if (t.CanTrigger) { t.Trigger(sender, outgoingArg); } } } } break; case TriggerActivationType.TriggerSelectedTarget: { //UnityEngine.Object targ = _triggerable; //if (targ is IProxy) targ = (targ as IProxy).GetTarget(incomingArg); //TriggerSelectedTarget(targ, sender, outgoingArg, instruction); TriggerSelectedTarget(_triggerable, sender, outgoingArg, instruction); } break; case TriggerActivationType.SendMessage: { object targ = _triggerable; if (targ is IProxy) { targ = (targ as IProxy).GetTarget(incomingArg); } SendMessageToTarget(targ, _methodName, outgoingArg); } break; case TriggerActivationType.CallMethodOnSelectedTarget: { CallMethodOnSelectedTarget(_triggerable, _methodName, _triggerableArgs); } break; case TriggerActivationType.EnableTarget: { object targ = _triggerable; if (targ is IProxy) { targ = (targ as IProxy).GetTarget(incomingArg); } EnableTarget(_triggerable, ConvertUtil.ToEnum <EnableMode>(_methodName)); } break; case TriggerActivationType.DestroyTarget: { object targ = _triggerable; if (targ is IProxy) { targ = (targ as IProxy).GetTarget(incomingArg); } DestroyTarget(_triggerable); } break; } }
private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused) { var element = _targetList.serializedProperty.GetArrayElementAtIndex(index); var trigProp = element.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG); var actProp = element.FindPropertyRelative(TriggerTargetProps.PROP_ACTIVATIONTYPE); //var act = (TriggerActivationType)actProp.enumValueIndex; var act = actProp.GetEnumValue <TriggerActivationType>(); const float MARGIN = 1.0f; if (act == TriggerActivationType.TriggerAllOnTarget) { //Draw Triggerable - this is the simple case to make a clean designer set up for newbs var trigRect = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight); var trigLabel = new GUIContent("Target"); EditorGUI.BeginProperty(trigRect, trigLabel, trigProp); trigProp.objectReferenceValue = SPEditorGUI.ComponentField(trigRect, trigLabel, TriggerTargetPropertyDrawer.ValidateTriggerableTargAsMechanism(trigProp.objectReferenceValue) as Component, typeof(ITriggerableMechanism), true); EditorGUI.EndProperty(); } else { //Draw Triggerable - this forces the user to use the advanced settings, not for newbs var trigRect = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight); var trigLabel = new GUIContent("Advanced Target", "A target is not set, see advanced settings section to set a target."); if (trigProp.objectReferenceValue != null) { var go = GameObjectUtil.GetGameObjectFromSource(trigProp.objectReferenceValue); var trigType = trigProp.objectReferenceValue.GetType(); GUIContent extraLabel; switch (act) { case TriggerActivationType.SendMessage: extraLabel = new GUIContent("(SendMessage) " + go.name); break; case TriggerActivationType.TriggerSelectedTarget: extraLabel = new GUIContent("(TriggerSelectedTarget) " + go.name + " -> " + trigType.Name); break; case TriggerActivationType.CallMethodOnSelectedTarget: extraLabel = new GUIContent("(CallMethodOnSelectedTarget) " + go.name + " -> " + trigType.Name + "." + element.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME).stringValue); break; default: extraLabel = GUIContent.none; break; } EditorGUI.LabelField(trigRect, trigLabel, extraLabel); } else { EditorGUI.LabelField(trigRect, trigLabel, new GUIContent("No Target"), new GUIStyle("Label") { alignment = TextAnchor.MiddleCenter }); } } ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused); }
public void DrawClip(Rect area, SerializedProperty property, GUIContent label, float labelWidth, GUIStyle labelStyle, bool nameIsReadonly) { //Draw Name var nameProp = property.FindPropertyRelative(PROP_NAME); var labelRect = new Rect(area.xMin, area.yMin, labelWidth, EditorGUIUtility.singleLineHeight); var textRect = new Rect(labelRect.xMax, area.yMin, (area.width - labelWidth) * 0.4f, EditorGUIUtility.singleLineHeight); EditorGUI.BeginProperty(area, label, nameProp); //EditorGUI.LabelField(labelRect, label, labelStyle); GUI.Label(labelRect, label, labelStyle); if (nameIsReadonly || _nameIsReadOnly || Application.isPlaying) { //EditorGUI.LabelField(textRect, nameProp.stringValue, GUI.skin.textField); GUI.Label(textRect, nameProp.stringValue, GUI.skin.textField); } else { //nameProp.stringValue = EditorGUI.TextField(textRect, nameProp.stringValue); nameProp.stringValue = GUI.TextField(textRect, nameProp.stringValue); } //EditorGUI.EndProperty(); var cache = SPGUI.DisableIfPlaying(); //Draw Animation Clip Reference var clipProp = property.FindPropertyRelative(PROP_CLIP); var xmin = textRect.xMax + 2f; var clipRect = new Rect(xmin, area.yMin, area.xMax - xmin, EditorGUIUtility.singleLineHeight); var clipLabel = GUIContent.none; //EditorGUI.BeginProperty(clipRect, clipLabel, clipProp); //clipProp.objectReferenceValue = EditorGUI.ObjectField(clipRect, clipProp.objectReferenceValue, typeof(AnimationClip), false); var obj = clipProp.objectReferenceValue; if (GameObjectUtil.IsGameObjectSource(obj)) { if (_selectComponentDrawer == null) { _selectComponentDrawer = new SelectableComponentPropertyDrawer(); _selectComponentDrawer.RestrictionType = typeof(IScriptableAnimationClip); _selectComponentDrawer.ShowXButton = true; } _selectComponentDrawer.OnGUI(clipRect, clipProp, GUIContent.none); } else { obj = EditorGUI.ObjectField(clipRect, obj, typeof(UnityEngine.Object), true); if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip) { clipProp.objectReferenceValue = obj; } else if (GameObjectUtil.IsGameObjectSource(obj)) { clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object; } } EditorGUI.EndProperty(); cache.Reset(); if (Application.isPlaying && !property.hasMultipleDifferentValues && property.serializedObject.targetObject is SPAnimationController) { if (GUI.Button(new Rect(area.xMin, area.yMin, 20f, EditorGUIUtility.singleLineHeight), ">")) { var targ = property.serializedObject.targetObject as SPAnimationController; targ.Play(nameProp.stringValue); } } }
private void PerformMirror() { var mirrorItems = boneEntries.Where( item => item.sourceBone != null && item.targetBone != null && item.sourceBone != item.targetBone); var undoItems = mirrorItems.Select(item => (Component)item.targetBone).ToList(); var allSkinBones = GameObjectUtil.FindComponentsOfType <SkinnedMeshRenderer>() .SelectMany(renderer => renderer.bones) .Distinct() .ToArray(); var editablePivots = mirrorItems .Select(item => item.targetBone.pivotNode) .Where(pivotNode => pivotNode != null && SpringBoneSetup.IsPivotProbablySafeToDestroy(pivotNode, allSkinBones)) .ToArray(); undoItems.AddRange(editablePivots); Undo.RecordObjects(undoItems.ToArray(), "Mirror SpringBones"); foreach (var mirrorItem in mirrorItems) { var sourceBone = mirrorItem.sourceBone; var targetBone = mirrorItem.targetBone; var rootManager = targetBone.GetComponentInParent <SpringManager>(); if (rootManager == null) { continue; } targetBone.stiffnessForce = sourceBone.stiffnessForce; targetBone.dragForce = sourceBone.dragForce; targetBone.springForce = sourceBone.springForce; targetBone.windInfluence = sourceBone.windInfluence; if (editablePivots.Contains(targetBone.pivotNode)) { MirrorPivot(sourceBone, targetBone); } targetBone.angularStiffness = sourceBone.angularStiffness; sourceBone.yAngleLimits.CopyTo(targetBone.yAngleLimits); sourceBone.zAngleLimits.CopyTo(targetBone.zAngleLimits); targetBone.yAngleLimits.min = -sourceBone.yAngleLimits.max; targetBone.yAngleLimits.max = -sourceBone.yAngleLimits.min; targetBone.lengthLimitTargets = FindMirroredComponents( rootManager.gameObject, sourceBone.lengthLimitTargets, mirrorAxis) .Where(item => item != null) .ToArray(); targetBone.radius = sourceBone.radius; targetBone.sphereColliders = FindMirroredComponents( rootManager.gameObject, sourceBone.sphereColliders, mirrorAxis) .Where(item => item != null) .ToArray(); targetBone.capsuleColliders = FindMirroredComponents( rootManager.gameObject, sourceBone.capsuleColliders, mirrorAxis) .Where(item => item != null) .ToArray(); targetBone.panelColliders = FindMirroredComponents( rootManager.gameObject, sourceBone.panelColliders, mirrorAxis) .Where(item => item != null) .ToArray(); } }
protected override void OnSPInspectorGUI() { this.serializedObject.Update(); this.DrawPropertyField(EditorHelper.PROP_SCRIPT); this.DrawPropertyField(PROP_ORDER); this.DrawPropertyField(PROP_ACTIVATEON); this.DrawTargetAnimatorProperty(); var controller = this.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue; if (controller is Animation || controller is SPLegacyAnimController) { var propMode = this.serializedObject.FindProperty(PROP_MODE); SPEditorGUILayout.PropertyField(propMode); switch (propMode.GetEnumValue <i_PlayAnimation.PlayByMode>()) { case i_PlayAnimation.PlayByMode.PlayAnim: { this.serializedObject.FindProperty(PROP_ID).stringValue = string.Empty; var clipProp = this.serializedObject.FindProperty(PROP_CLIP); var obj = EditorGUILayout.ObjectField(EditorHelper.TempContent(clipProp.displayName), clipProp.objectReferenceValue, typeof(UnityEngine.Object), true); if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip) { clipProp.objectReferenceValue = obj; } else if (GameObjectUtil.IsGameObjectSource(obj)) { clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object; } } break; case i_PlayAnimation.PlayByMode.PlayAnimByID: { this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null; //this.DrawPropertyField(PROP_ID); this.DrawAnimIdSelector(controller); } break; case i_PlayAnimation.PlayByMode.PlayAnimFromResource: { this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null; this.DrawPropertyField(PROP_ID); } break; } this.DrawAnimSettings(); this.DrawPropertyField(PROP_QUEUEMODE); this.DrawPropertyField(PROP_PLAYMODE); this.DrawPropertyField(PROP_CROSSFADEDUR); } else if (controller is ISPAnimator) { var propId = this.serializedObject.FindProperty(PROP_ID); propId.stringValue = DrawSPAnimatorFunctionPopup(EditorGUILayout.GetControlRect(), controller as ISPAnimator, propId.stringValue); } else if (controller is ISPAnimationSource) { this.serializedObject.FindProperty(PROP_MODE).SetEnumValue <i_PlayAnimation.PlayByMode>(i_PlayAnimation.PlayByMode.PlayAnimByID); this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null; this.DrawPropertyField(PROP_ID); this.DrawAnimSettings(); this.DrawPropertyField(PROP_QUEUEMODE); this.DrawPropertyField(PROP_PLAYMODE); this.DrawPropertyField(PROP_CROSSFADEDUR); } this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_ORDER, PROP_ACTIVATEON, PROP_MODE, PROP_TARGETANIMATOR, PROP_ID, PROP_CLIP, PROP_SETTINGSMASK, PROP_SETTINGS, PROP_QUEUEMODE, PROP_PLAYMODE, PROP_CROSSFADEDUR); this.serializedObject.ApplyModifiedProperties(); }