Пример #1
0
        private void ReplayRegisterVariable(ReplayVariable variable)
        {
            // Resize the array
            Array.Resize(ref replayVariables, replayVariables.Length + 1);

            // Add to back
            replayVariables[replayVariables.Length - 1] = variable;
        }
Пример #2
0
        /// <summary>
        /// Attempts to find any variables marked with the <see cref="ReplayVarAttribute"/> so that they can be serialized later.
        /// </summary>
        protected virtual void ReplayFindVariables()
        {
            // Clear old array
            replayVariables = new ReplayVariable[0];

            foreach (FieldInfo field in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                // Check if we have the ReplayVarAttribute
                if (field.IsDefined(typeof(ReplayVarAttribute), true) == true)
                {
#if UNITY_WINRT && !UNITY_EDITOR
                    ReplayVarAttribute varAttribute = field.GetCustomAttribute <ReplayVarAttribute>();

                    // Check for unexpected error
                    if (varAttribute == null)
                    {
                        continue;
                    }
#else
                    // Get the attribute
                    object[] attributes = field.GetCustomAttributes(typeof(ReplayVarAttribute), true);

                    // Check for unexpected error
                    if (attributes.Length == 0)
                    {
                        continue;
                    }

                    // Get the first attribute (Only 1 allowed)
                    ReplayVarAttribute varAttribute = attributes[0] as ReplayVarAttribute;
#endif

                    // Create a variable for this field
                    ReplayVariable variable = new ReplayVariable(this, field, varAttribute);

                    // Add to array for serialization
                    ReplayRegisterVariable(variable);
                }
            }
        }