public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { var tp = (this.fieldInfo != null) ? this.fieldInfo.FieldType : null; var objProp = property.FindPropertyRelative(PROP_OBJ); if (tp == null || objProp == null || objProp.propertyType != SerializedPropertyType.ObjectReference) { this.DrawMalformed(position); return; } var valueType = com.spacepuppy.Dynamic.DynamicUtil.GetReturnType(DynamicUtil.GetMemberFromType(tp, "_value", true)); if (valueType == null || !(valueType.IsClass || valueType.IsInterface)) { this.DrawMalformed(position); return; } var val = ObjUtil.GetAsFromSource(valueType, EditorGUI.ObjectField(position, label, objProp.objectReferenceValue, typeof(UnityEngine.Object), true)); if (val != null && !valueType.IsInstanceOfType(val)) { val = null; } objProp.objectReferenceValue = val as UnityEngine.Object; }
public bool TryGetAsset <T>(string id, out T asset) where T : class { ResourceEntry entry; if (_source._table.TryGetValue(id, out entry)) { if (entry.Loaded) { asset = ObjUtil.GetAsFromSource <T>(entry.Asset); return(asset != null); } else { entry.Load(); asset = ObjUtil.GetAsFromSource <T>(entry.Asset); if (asset == null) { entry.Unload(); return(false); } else { return(true); } } } asset = null; return(false); }
public static object GetFromTarget(GameObject targ, System.Type restrictionType, EntityRelativity relativity) { switch (relativity) { case EntityRelativity.Entity: { targ = targ.FindRoot(); var obj = ObjUtil.GetAsFromSource(restrictionType, targ); if (object.ReferenceEquals(obj, null) && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } return(obj); } case EntityRelativity.Self: { return(ObjUtil.GetAsFromSource(restrictionType, targ)); } case EntityRelativity.SelfAndChildren: { var obj = ObjUtil.GetAsFromSource(restrictionType, targ); if (object.ReferenceEquals(targ, null) && ComponentUtil.IsAcceptableComponentType(restrictionType)) { obj = targ.GetComponentInChildren(restrictionType); } return(obj); } default: return(null); } }
public object GetTarget(System.Type tp, object triggerArg) { if (tp == null) { throw new System.ArgumentNullException("tp"); } var obj = this.ReduceTarget(triggerArg); if (obj == null) { return(null); } var result = ObjUtil.GetAsFromSource(tp, obj); if (ObjUtil.IsNullOrDestroyed(result) && this.ImplicityReducesEntireEntity && ComponentUtil.IsAcceptableComponentType(tp)) { //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg' var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj)); if (go == null) { return(null); } result = go.FindComponent(tp); } return(result); }
private static void ApplyDefaultAsSingle(SerializedProperty property, System.Type restrictionType, EntityRelativity relativity) { object value = property.GetPropertyValue(false); if (value != null) { return; } var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (object.ReferenceEquals(targ, null)) { value = ObjUtil.GetAsFromSource(restrictionType, property.serializedObject.targetObject); } else { value = GetFromTarget(targ, restrictionType, relativity); } if (value != null) { property.SetPropertyValue(value); } }
public System.Collections.IEnumerable GetTargets(System.Type tp, object triggerArg) { foreach (var obj in this.ReduceTargets(triggerArg)) { if (obj == null) { continue; } var result = ObjUtil.GetAsFromSource(tp, obj); if (ObjUtil.IsNullOrDestroyed(result) && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(tp)) { //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg' var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj)); if (go == null) { continue; } result = go.FindComponent(tp); } if (result != null) { yield return(result); } } }
protected virtual void DoDragAndDrop(SerializedProperty property, Rect listArea) { if (_allowDragAndDrop && this.DragDropElementType != null && Event.current != null) { var ev = Event.current; switch (ev.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (listArea.Contains(ev.mousePosition)) { var refs = (from o in DragAndDrop.objectReferences let obj = ObjUtil.GetAsFromSource(this.DragDropElementType, o, false) where obj != null select obj); DragAndDrop.visualMode = refs.Any() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; if (ev.type == EventType.DragPerform && refs.Any()) { DragAndDrop.AcceptDrag(); AddObjectsToArray(property, refs.ToArray(), _childPropertyAsEntry); GUI.changed = true; } } } break; } } }
public IEnumerable <T> GetTargets <T>(object triggerArg) where T : class { foreach (var obj in this.ReduceTargets(triggerArg)) { if (obj == null) { continue; } var result = ObjUtil.GetAsFromSource <T>(obj); if (result == null && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(typeof(T))) { //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg' var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj)); if (go == null) { continue; } result = go.FindComponent <T>(); } if (result != null) { yield return(result); } } }
protected override void DrawElementValue(Rect area, SerializedProperty element, GUIContent label, int elementIndex) { var modeProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_MODE); switch (modeProp.GetEnumValue <i_PlayAnimation.PlayByMode>()) { case i_PlayAnimation.PlayByMode.PlayAnim: { var clipProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_CLIP); var obj = EditorGUI.ObjectField(area, GUIContent.none, 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; default: { SPEditorGUI.PropertyField(area, element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID), GUIContent.none); } break; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { 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); 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; } SPEditorGUI.PropertyField(r3, property.FindPropertyRelative(PROP_SETTINGS)); } break; case i_PlayAnimation.PlayByMode.PlayAnimByID: { property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null; SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID)); SPEditorGUI.PropertyField(r3, property.FindPropertyRelative(PROP_SETTINGS)); } break; case i_PlayAnimation.PlayByMode.PlayAnimFromResource: { property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null; SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID)); SPEditorGUI.PropertyField(r3, property.FindPropertyRelative(PROP_SETTINGS)); } break; } }
protected override void OnSPInspectorGUI() { this.serializedObject.Update(); this.DrawPropertyField(EditorHelper.PROP_SCRIPT); this.DrawPropertyField(PROP_ORDER); var propMode = this.serializedObject.FindProperty(PROP_MODE); SPEditorGUILayout.PropertyField(propMode); this.DrawTargetAnimatorProperty(); 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; this.DrawPropertyField(PROP_SETTINGS); } break; case i_PlayAnimation.PlayByMode.PlayAnimByID: { this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null; this.DrawPropertyField(PROP_ID); if(this.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue is Animation) { this.DrawPropertyField(PROP_SETTINGS); } } break; case i_PlayAnimation.PlayByMode.PlayAnimFromResource: { this.serializedObject.FindProperty(PROP_CLIP).objectReferenceValue = null; this.DrawPropertyField(PROP_ID); this.DrawPropertyField(PROP_SETTINGS); } break; } this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_ORDER, PROP_MODE, PROP_TARGETANIMATOR, PROP_ID, PROP_CLIP, PROP_SETTINGS); this.serializedObject.ApplyModifiedProperties(); }
public T GetTarget <T>() where T : class { if (_searchBy == SearchBy.Nothing) { return(ObjUtil.GetAsFromSource <T>(_target, true)); } else { return(ObjUtil.Find <T>(_searchBy, _queryString)); } }
private void OnSpawnedObjectHandler_Imp(object sender, TempEventArgs e) { var obj = ObjUtil.GetAsFromSource <SpawnedObjectController>(e.Value); if (obj != null) { obj.OnKilled -= this.OnKilledObjectHandler_Imp; obj.OnKilled += this.OnKilledObjectHandler_Imp; _onSpawnedObject.ActivateTrigger(this, obj); } }
public int IndexOf(IPostProcessingEffect item) { var obj = ObjUtil.GetAsFromSource <UnityEngine.Object>(item); if (obj == null) { return(-1); } return(_owner._globalEffects.IndexOf(obj)); }
private void OnKilledObjectHandler_Imp(object sender, System.EventArgs e) { var obj = ObjUtil.GetAsFromSource <SpawnedObjectController>(sender); if (obj != null) { _objects.Remove(obj); obj.OnKilled -= this.OnKilledObjectHandler; _onKilledObject.ActivateTrigger(this, obj); } }
public T[] GetTargets <T>() where T : class { if (_searchBy == SearchBy.Nothing) { var targ = ObjUtil.GetAsFromSource <T>(_target, true); return(targ != null ? new T[] { targ } : ArrayUtil.Empty <T>()); } else { return(ObjUtil.FindAll <T>(_searchBy, _queryString)); } }
private void UpdateTargetFromSource(SerializedProperty property, TargetSource esrc) { switch (esrc) { case TargetSource.Arg: { property.objectReferenceValue = null; } break; case TargetSource.Self: { UnityEngine.Object obj = property.serializedObject.targetObject; if (this.TargetType != null) { obj = ObjUtil.GetAsFromSource(this.TargetType, obj) as UnityEngine.Object; } property.objectReferenceValue = obj; } break; case TargetSource.Root: { UnityEngine.Object obj = property.serializedObject.targetObject; var go = GameObjectUtil.GetGameObjectFromSource(obj); if (go != null) { obj = go.FindRoot(); } if (this.TargetType != null) { obj = ObjUtil.GetAsFromSource(this.TargetType, obj) as UnityEngine.Object; } property.objectReferenceValue = obj; } break; case TargetSource.Config: { if (this.DefaultFromSelf && property.objectReferenceValue == null) { UnityEngine.Object obj = property.serializedObject.targetObject; if (this.TargetType != null) { obj = ObjUtil.GetAsFromSource(this.TargetType, obj) as UnityEngine.Object; } property.objectReferenceValue = obj; } } break; } }
protected void SetObjectData(object obj) { if (_bundle == null) { return; } var pobj = ObjUtil.GetAsFromSource <IPersistantAsset>(obj); if (pobj != null) { pobj.OnDeserialize(_info, _context, _bundle); } }
public override int SenseAll <T>(ICollection <T> lst, System.Func <T, bool> p = null) { if (lst == null) { throw new System.ArgumentNullException("lst"); } if (lst.IsReadOnly) { throw new System.ArgumentException("List to fill can not be read-only.", "lst"); } if (_intersectingColliders.Count == 0) { return(0); } if (p == null && !_requiresLineOfSight) { int cnt = 0; var e = _intersectingColliders.GetEnumerator(); while (e.MoveNext()) { var a = ColliderAspect.GetAspect(e.Current); var o = ObjUtil.GetAsFromSource <T>(a); if (o != null) { lst.Add(o); cnt++; } } return(cnt); } else { var e = _intersectingColliders.GetEnumerator(); int cnt = 0; while (e.MoveNext()) { var a = ColliderAspect.GetAspect(e.Current); var o = ObjUtil.GetAsFromSource <T>(a); if ((p == null || p(o)) && (!_requiresLineOfSight || this.IsLineOfSight(e.Current))) { lst.Add(e.Current as T); cnt++; } } return(cnt); } }
public void Insert(int index, IPostProcessingEffect item) { if (item == null) { throw new System.ArgumentNullException("item"); } var obj = ObjUtil.GetAsFromSource <UnityEngine.Object>(item); if (obj == null) { throw new System.ArgumentException("item must be a UnityEngine.Object", "value"); } _owner._globalEffects.Insert(index, obj); _owner.EffectsListChanged(); }
protected virtual void DoDragAndDrop(SerializedProperty property, Rect listArea) { if (Event.current == null) { return; } var ev = Event.current; switch (ev.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (listArea.Contains(ev.mousePosition)) { var refs = (from o in DragAndDrop.objectReferences let obj = ObjUtil.GetAsFromSource <AnimationClip>(o) where obj != null select obj); DragAndDrop.visualMode = refs.Any() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; if (ev.type == EventType.DragPerform && refs.Any()) { DragAndDrop.AcceptDrag(); var names = _animList.serializedProperty.EnumerateArray().Select(o => o.FindPropertyRelative("_name").stringValue).ToHashSet(); foreach (var clip in refs) { var stateprop = this.AddNewState(_animList); stateprop.FindPropertyRelative("_clip").objectReferenceValue = clip; string nm = clip.name; string format = nm + "{0:00}"; int cnt = 0; while (names.Contains(nm)) { nm = string.Format(format, ++cnt); } stateprop.FindPropertyRelative("_name").stringValue = nm; } GUI.changed = true; } } } break; } }
private static void ApplyDefaultAsSingle(SerializedProperty property, System.Type fieldType, string name, bool bUseEntity) { if (fieldType == null) { return; } var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject); if (targ == null) { return; } if (bUseEntity) { targ = targ.FindRoot(); } if (TypeUtil.IsType(fieldType, typeof(VariantReference))) { var variant = EditorHelper.GetTargetObjectOfProperty(property) as VariantReference; if (variant != null && variant.Value == null && variant.ValueType == VariantType.GameObject) { var go = targ.FindByName(name); if (go != null) { variant.GameObjectValue = go; property.serializedObject.Update(); return; } } } else if (property.objectReferenceValue == null) { foreach (var obj in targ.transform.FindAllByName(name)) { var o = ObjUtil.GetAsFromSource(fieldType, obj) as UnityEngine.Object; if (o != null) { property.objectReferenceValue = o; property.serializedObject.ApplyModifiedProperties(); return; } } } }
public IPostProcessingEffect this[int index] { get { return(_owner._globalEffects[index] as IPostProcessingEffect); } set { if (value == null) { throw new System.ArgumentNullException("value"); } var obj = ObjUtil.GetAsFromSource <UnityEngine.Object>(value); if (obj == null) { throw new System.ArgumentException("value must be a UnityEngine.Object", "value"); } _owner._globalEffects[index] = obj; } }
public IEnumerable <T> GetAllAssets <T>() where T : class { if (!_clean) { this.SetupTable(); } var e = _table.Values.GetEnumerator(); while (e.MoveNext()) { var obj = ObjUtil.GetAsFromSource <T>(e.Current); if (!object.ReferenceEquals(obj, null)) { yield return(obj); } } }
private object ResolveTargetAnimator(object arg) { var obj = _targetAnimator.GetTarget <UnityEngine.Object>(arg); ISPAnimationSource src = null; ISPAnimator spanim = null; Animation anim = null; if (ObjUtil.GetAsFromSource <ISPAnimationSource>(obj, out src)) { return(src); } if (ObjUtil.GetAsFromSource <ISPAnimator>(obj, out spanim)) { return(spanim); } if (ObjUtil.GetAsFromSource <Animation>(obj, out anim)) { return(anim); } if (_targetAnimator.ImplicityReducesEntireEntity) { var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj)); if (go == null) { return(null); } SPLegacyAnimController spcont; if (go.FindComponent <SPLegacyAnimController>(out spcont)) { return(spcont); } if (go.FindComponent <Animation>(out anim)) { return(anim); } } return(null); }
/// <summary> /// Create just the root object from the asset, will still need to apply all serialized data to the object. /// </summary> /// <returns></returns> protected object CreateRoot() { if (_bundle == null) { return(null); } var resourceId = _info.GetString("sp*id"); var obj = _bundle.LoadAsset(resourceId); if (obj == null) { return(null); } obj = UnityEngine.Object.Instantiate(obj); var pobj = ObjUtil.GetAsFromSource <IPersistantAsset>(obj); return((object)pobj ?? (object)obj); }
public bool Remove(IPostProcessingEffect item) { var obj = ObjUtil.GetAsFromSource <UnityEngine.Object>(item); if (obj == null) { return(false); } if (_owner._globalEffects.Remove(obj)) { if (_owner._globalEffects.Count == 0) { _owner.EffectsListChanged(); } return(true); } return(false); }
public static T Find <T>(SearchBy search, string query) where T : class { switch (search) { case SearchBy.Nothing: return(null); case SearchBy.Tag: return(ObjUtil.GetAsFromSource <T>(GameObjectUtil.FindWithMultiTag(query))); case SearchBy.Name: return(ObjUtil.GetAsFromSource <T>(UnityEngine.GameObject.Find(query))); case SearchBy.Type: return(ObjUtil.GetAsFromSource <T>(UnityEngine.Object.FindObjectOfType(TypeUtil.FindType(query)))); default: return(null); } }
protected override void DrawElementValue(Rect area, SerializedProperty element, GUIContent label, int elementIndex) { var controller = element.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue; if (controller is Animation || controller is SPLegacyAnimController) { var modeProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_MODE); switch (modeProp.GetEnumValue <i_PlayAnimation.PlayByMode>()) { case i_PlayAnimation.PlayByMode.PlayAnim: { var clipProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_CLIP); var obj = EditorGUI.ObjectField(area, GUIContent.none, 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; default: { SPEditorGUI.PropertyField(area, element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID), GUIContent.none); } break; } } else if (controller is ISPAnimator) { var propId = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID); propId.stringValue = i_PlayAnimationInspector.DrawSPAnimatorFunctionPopup(area, GUIContent.none, controller as ISPAnimator, propId.stringValue); } else if (controller is ISPAnimationSource) { SPEditorGUI.PropertyField(area, element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID), GUIContent.none); } }
protected override void DoDragAndDrop(SerializedProperty property, Rect listArea) { if (this.AllowDragAndDrop && this.fieldInfo != null && Event.current != null) { var ev = Event.current; switch (ev.type) { case EventType.DragUpdated: case EventType.DragPerform: { if (listArea.Contains(ev.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; //default var valueMember = com.spacepuppy.Dynamic.DynamicUtil.GetMemberFromType(TypeUtil.GetElementTypeOfListType(this.fieldInfo.FieldType), this.ValuePropertyName, true); if (valueMember == null) { return; } var tp = com.spacepuppy.Dynamic.DynamicUtil.GetReturnType(valueMember); if (tp == null) { return; } var refs = (from o in DragAndDrop.objectReferences let obj = ObjUtil.GetAsFromSource(tp, o, false) where obj != null select obj); DragAndDrop.visualMode = refs.Any() ? DragAndDropVisualMode.Link : DragAndDropVisualMode.Rejected; if (ev.type == EventType.DragPerform && refs.Any()) { DragAndDrop.AcceptDrag(); this.AddObjectsToArray(property, refs.ToArray()); GUI.changed = true; } } } break; } } }