Пример #1
0
        /// <inheritdoc />
        public override Rect Draw(Rect rect, object currentValue, Action <object> changeValueCallback, GUIContent label)
        {
            if (RuntimeConfigurator.Exists == false)
            {
                return(rect);
            }

            isUndoOperation = false;
            UniqueNameReference uniqueNameReference = (UniqueNameReference)currentValue;
            PropertyInfo        valueProperty       = currentValue.GetType().GetProperty("Value");
            Type valueType = ReflectionUtils.GetDeclaredTypeOfPropertyOrField(valueProperty);

            if (valueProperty == null)
            {
                throw new ArgumentException("Only ObjectReference<> implementations should inherit from the UniqueNameReference type.");
            }

            Rect       guiLineRect         = rect;
            string     oldUniqueName       = uniqueNameReference.UniqueName;
            GameObject selectedSceneObject = GetGameObjectFromID(oldUniqueName);

            if (selectedSceneObject == null && string.IsNullOrEmpty(oldUniqueName) == false && missingUniqueNames.Contains(oldUniqueName) == false)
            {
                missingUniqueNames.Add(oldUniqueName);
                Debug.LogError($"The Training Scene Object with the unique name '{oldUniqueName}' cannot be found!");
            }

            CheckForMisconfigurationIssues(selectedSceneObject, valueType, ref rect, ref guiLineRect);
            selectedSceneObject = EditorGUI.ObjectField(guiLineRect, label, selectedSceneObject, typeof(GameObject), true) as GameObject;

            string newUniqueName = GetIDFromSelectedObject(selectedSceneObject, valueType, oldUniqueName);

            if (oldUniqueName != newUniqueName)
            {
                RevertableChangesHandler.Do(
                    new CourseCommand(
                        () =>
                {
                    uniqueNameReference.UniqueName = newUniqueName;
                    changeValueCallback(uniqueNameReference);
                },
                        () =>
                {
                    uniqueNameReference.UniqueName = oldUniqueName;
                    changeValueCallback(uniqueNameReference);
                }),
                    isUndoOperation ? undoGroupName : string.Empty);

                if (isUndoOperation)
                {
                    RevertableChangesHandler.CollapseUndoOperations(undoGroupName);
                }
            }

            return(rect);
        }
Пример #2
0
        private static T GetFittingPropertyFromReference <T>(UniqueNameReference reference, Type type) where T : class, ISceneObjectProperty
        {
            ISceneObject sceneObject = RuntimeConfigurator.Configuration.SceneObjectRegistry.GetByName(reference.UniqueName);

            foreach (ISceneObjectProperty prop in sceneObject.Properties)
            {
                if (prop.GetType() == type)
                {
                    return(prop as T);
                }
            }
            Debug.LogWarningFormat("Could not find fitting {0} type in SceneObject {1}", type.Name, reference.UniqueName);
            return(null);
        }
Пример #3
0
        private static IEnumerable <Type> ExtractFittingPropertyTypeFrom <T>(UniqueNameReference reference) where T : ISceneObjectProperty
        {
            IEnumerable <Type> refs = ReflectionUtils.GetConcreteImplementationsOf(reference.GetReferenceType());

            refs = refs.Where(typeof(T).IsAssignableFrom);

            if (UnitTestChecker.IsUnitTesting == false)
            {
                refs = refs.Where(type => type.Assembly.GetReferencedAssemblies().All(name => name.Name != "nunit.framework"));
                if (Application.isEditor == false)
                {
                    refs = refs.Where(type => type.Assembly.GetReferencedAssemblies().All(name => name.Name != "UnityEditor"));
                }
            }

            return(refs);
        }
Пример #4
0
        /// <summary>
        /// Extracts all <see cref="LockableProperties"/> from given condition.
        /// </summary>
        /// <param name="data">Condition to be used for extraction</param>
        /// <param name="checkRequiredComponentsToo">if true the [RequiredComponents] will be checked and added too.</param>
        public static List <LockablePropertyData> ExtractLockablePropertiesFromConditions(IConditionData data, bool checkRequiredComponentsToo = true)
        {
            List <LockablePropertyData> result = new List <LockablePropertyData>();

            List <MemberInfo> memberInfo = GetAllPropertyReferencesFromCondition(data);

            memberInfo.ForEach(info =>
            {
                UniqueNameReference reference = ReflectionUtils.GetValueFromPropertyOrField(data, info) as UniqueNameReference;

                if (reference == null || string.IsNullOrEmpty(reference.UniqueName))
                {
                    return;
                }

                if (RuntimeConfigurator.Configuration.SceneObjectRegistry.ContainsName(reference.UniqueName) == false)
                {
                    return;
                }

                IEnumerable <Type> refs = ExtractFittingPropertyTypeFrom <LockableProperty>(reference);

                Type refType = refs.FirstOrDefault();
                if (refType != null)
                {
                    IEnumerable <Type> types = new[] { refType };
                    if (checkRequiredComponentsToo)
                    {
                        types = GetDependenciesFrom <LockableProperty>(refType);
                    }

                    foreach (Type type in types)
                    {
                        LockableProperty property = GetFittingPropertyFromReference <LockableProperty>(reference, type);
                        if (property != null)
                        {
                            result.Add(new LockablePropertyData(property));
                        }
                    }
                }
            });

            return(result);
        }