Beispiel #1
0
        /// <summary>
        /// 查找角色,武器,配件的关节请使用缓存版本的函数BoneMount.FindChildBoneFromCache
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="target"></param>
        /// <param name="ignoreMissing"></param>
        /// <returns></returns>
        /// <seealso cref="BoneMount.FindChildBoneFromCache"/>
        public static Transform FindChildBone(GameObject obj, string target, bool ignoreMissing = false)
        {
            if (obj != null && target != null)
            {
                var r = BoneTool.FindTransformFromCache(obj, target);

                if (r == null)
                {
                    _logger.InfoFormat("target:{0} is not cached!!!!", target);
                    r = obj.transform.FindTransformRecursive(target);
                }

                if (r == null && !ignoreMissing)
                {
                    _logger.DebugFormat("missing {0} in {1}", target, obj.name);
                }
                return(r);
            }
            else
            {
                _logger.DebugFormat("null object or null target in FindChildBone");
            }

            return(null);
        }
Beispiel #2
0
        public void MountWeaponAttachment(GameObject attachment, GameObject weapon, WeaponPartLocation location)
        {
            if (attachment != null && weapon != null)
            {
                if (weapon.GetComponent <TransformCache>() == null)
                {
                    BoneTool.CacheTransform(weapon);
                }
                if (attachment.GetComponent <TransformCache>() == null)
                {
                    BoneTool.CacheTransform(attachment);
                }

                if (_attachmentLocator.ContainsKey(location))
                {
                    var anchor = FindChildBoneFromCache(attachment, BoneName.AttachmentLocator, false);
                    var target = FindChildBoneFromCache(weapon, _attachmentLocator[location], false);
                    FixedObj2Bones(attachment, anchor, target);
                }
                else
                {
                    _logger.WarnFormat("Wrong Attachment Location: {0}", location);
                }
            }
        }
Beispiel #3
0
        public static void CacheTransform(GameObject obj)
        {
            var cache = obj.GetComponent <TransformCache>();

            if (cache == null)
            {
                cache = obj.AddComponentUncheckRequireAndDisallowMulti <TransformCache>();
                BoneTool.CacheTransform(obj, cache);
            }
        }
Beispiel #4
0
 private static void FindTarget(GameObject obj, string target, ref Transform r, bool containsUnActive = false)
 {
     CacheResults.Clear();
     obj.GetComponentsInChildren <TransformCache>(CacheResults);
     if (CacheResults.Count == 0)
     {
         _logger.DebugFormat("obj:{0} has no cache", obj);
     }
     foreach (TransformCache transformCache in CacheResults)
     {
         r = BoneTool.FindTransformFromCache(transformCache, target, containsUnActive);
         if (r != null)
         {
             break;
         }
     }
 }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="target"></param>
        /// <param name="containsAttach">是否包含子节点缓存</param>
        /// <param name="containsUnActive">是否包含UnActive的节点</param>
        /// <returns></returns>
        public static Transform FindChildBoneFromCache(GameObject obj, string target, bool containsAttach = true, bool containsUnActive = false)
        {
            Transform r = null;

            if (obj != null && target != null)
            {
                if (containsAttach)
                {
                    FindTarget(obj, target, ref r, containsUnActive);
                }
                else if (obj.GetComponent <TransformCache>() == null)
                {
                    FindTarget(obj, target, ref r, containsUnActive);
                }
                else
                {
                    r = BoneTool.FindTransformFromCache(obj, target, containsUnActive);
                }
                return(r);
            }
            _logger.DebugFormat("null object or null target in FindChildBone");

            return(null);
        }