Ejemplo n.º 1
0
        /// <summary>
        /// Returns the index of this SmartObject in the specified SmartMulti.
        /// If not an element in specified SmartMulti, returns -1.
        /// <param name="parent">The SmartMulti. Can leave null if multiElementType is DYNAMIC.</param>
        public int GetMultiIndex(SmartMultiBase parent = null)
        {
            switch (multiElementType)
            {
            case MultiElementType.NONE:
                return(-1);

            case MultiElementType.DYNAMIC:
                if (parent == null || parent == multiParentDynamic)
                {
                    return(_multiParentDynamicIndex);
                }
                return(-1);

            case MultiElementType.PERSISTENT:
                if (parent == null)
                {
                    throw new System.ArgumentException("Must specify SmartMulti parent when getting MultiIndex of a PERSISTENT SmartObject.");
                }
                int result;
                if (!_multiParentsPersistent.TryGetValue(parent, out result))
                {
                    result = -1;
                }
                return(result);
            }
            return(-1);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Internal use only. Registers this SmartObject as an element of a SmartMulti.
 /// </summary>
 public void SetMulti(SmartMultiBase multi, int index, bool isDynamic)
 {
     if (isDynamic)
     {
         if (multiElementType != MultiElementType.NONE)
         {
             throw new System.Exception(string.Format("SmartObject's MultiElementType is already {0} - cannot set DYNAMIC SmartMulti parent", multiElementType));
         }
         multiElementType         = MultiElementType.DYNAMIC;
         multiParentDynamic       = multi;
         _multiParentDynamicIndex = index;
     }
     else
     {
         if (multiElementType == MultiElementType.DYNAMIC)
         {
             throw new System.Exception(string.Format("SmartObject's MultiElementType is already {0} - cannot set PERSISTENT SmartMulti parent", multiElementType));
         }
         if (_multiParentsPersistent.ContainsKey(multi))
         {
             throw new System.ArgumentException(string.Format("Trying to add SmartMulti {0} as a parent of SmartObject {1} when already registered as a parent", multi.name, name));
         }
         multiElementType = MultiElementType.PERSISTENT;
         _multiParentsPersistent.Add(multi, index);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// If this SmartObject is an asset and referenced by one or more SmartMultis, returns those SmartMultis.
        /// Creates and returns a copy of the array.
        /// Check multiElementType is PERSISTENT first.
        /// </summary>
        public SmartMultiBase[] GetMultiParentsPersistent()
        {
            if (multiElementType != MultiElementType.PERSISTENT)
            {
                return(null);
            }
            var result = new SmartMultiBase[_multiParentsPersistent.Count];
            int i      = 0;

            foreach (var a in _multiParentsPersistent)
            {
                result[i] = a.Key;
                ++i;
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Internal use only. Registers a SmartMulti's decorators with its child SmartDatas.
        /// </summary>
        public void SetMultiDecorators(SmartDecoratorBase[] decorators, SmartMultiBase multi)
        {
            if (decorators == null || decorators.Length == 0)
            {
                _multiDecorators.Remove(multi);
                WarnMultiDecorators();
                return;
            }

            SmartDecoratorBase[] d = new SmartDecoratorBase[decorators.Length];
            for (int i = 0; i < decorators.Length; ++i)
            {
                d[i] = decorators[i];
                d[i].SetOwner(this);
            }
            _multiDecorators[multi] = d;

            EvalHasDecorators();
            WarnMultiDecorators();
        }