示例#1
0
        private CameraTarget SelectTarget(UpdateCameraEventArgs e)
        {
            var cameraBase   = e.Camera;
            var playerCamera = cameraBase.As <PlayerCamera>();

            if (playerCamera == null)
            {
                return(null);
            }

            TESObjectREFR target    = null;
            uint          refHandle = playerCamera.TargetRefHandle;

            using (var objRef = new ObjectRefHolder(refHandle))
            {
                if (objRef.IsValid)
                {
                    target = objRef.Object;
                }
            }

            var t = CameraTarget.Create(target);

            if (t == null)
            {
                return(null);
            }

            var actor = t.Actor;
            var obj   = t.Object;

            this.LastActorWasPlayer = actor != null && actor.IsPlayer;
            this.LastTargetFormId   = obj != null ? obj.FormId : 0;

            return(t);
        }
        internal static CameraTarget Create(TESObjectREFR obj)
        {
            if (obj == null)
            {
                return(null);
            }

            TESObjectREFR originalObj   = obj;
            Actor         originalActor = obj as Actor;

            bool isMountChange = false;
            {
                var horse = obj as Actor;
                if (horse != null && horse.IsBeingRidden)
                {
                    var rider = horse.GetMountedBy();
                    if (rider != null)
                    {
                        obj           = rider;
                        isMountChange = true;
                    }
                }
            }

            var t = new CameraTarget();

            t.Object         = obj;
            t.Actor          = obj as Actor;
            t.OriginalObject = originalObj;
            t.OriginalActor  = originalActor;

            var node = t.Actor != null && t.Actor.IsPlayer ? t.Actor.GetSkeletonNode(false) : obj.Node;

            if (node == null)
            {
                return(null);
            }

            for (int i = 0; i < EyeNodeNames.Length; i++)
            {
                var name = EyeNodeNames[i];
                var n    = node.LookupNodeByName(name);
                if (n != null)
                {
                    t.HeadNode = n;
                    break;
                }
            }

            if (t.HeadNode == null)
            {
                t.HeadNode = node;
            }

            for (int i = 0; i < RootNodeNames.Length; i++)
            {
                var name = RootNodeNames[i];
                var n    = node.LookupNodeByName(name);
                if (n != null)
                {
                    t.RootNode = n;
                    break;
                }
            }

            if (t.RootNode == null)
            {
                t.RootNode = node;
            }

            t.StabilizeRootNode = t.RootNode;
            if (isMountChange && t.Actor != null && t.OriginalActor != null && !t.Actor.Equals(t.OriginalActor))
            {
                var stabilize = t.OriginalActor.IsPlayer ? t.OriginalActor.GetSkeletonNode(false) : t.OriginalActor.Node;
                if (stabilize != null)
                {
                    t.StabilizeRootNode = stabilize;
                }
            }

            return(t);
        }