Exemplo n.º 1
0
        static void UpdateJointDescriptionFromParams(AttachStrategyJointDescription2D jd, AttachObject jointed,
                                                     AttachObject connected, AttachObject reference = null)
        {
            Attachment attachment = jointed.attachment;

            ParamSelector selector;

            selector = jd.GetAnchorParamSelector();
            // anchors must be relative to the associated Rigidbody's transform
            jd.anchor = jointed.rigidbody2D.transform.InverseTransformPoint(
                selector.GetWorldPosition(attachment, reference));

            selector = jd.GetConnectedAnchorParamSelector();
            // anchors must be relative to the associated Rigidbody's transform
            jd.connectedAnchor = connected.rigidbody2D.transform.InverseTransformPoint(
                selector.GetWorldPosition(attachment, reference));

            selector  = jd.GetTargetParamSelector();
            jd.target = selector.GetWorldPosition(attachment, reference);

            // selector = jd.GetLimitsParamSelector();
            // jd.limits = selector.get
            // provider = reference != null ? attachment.attachStrategy.ResolveProvider(selector.provider, reference)
            //         : attachment.attachStrategy.ResolveProvider(selector.provider, attachment);
            // jd.limits = provider.resolvedParams.GetParam(ParamType.AngleLimits, selector.name, selector.defaultParam)
            //         .angleLimitsValue;

            selector    = jd.GetDistanceParamSelector();
            jd.distance = selector.GetParam(attachment, reference).floatValue;
        }
Exemplo n.º 2
0
        // returns a world rotation
        public static Quaternion GetDesiredRotationForObject(AttachObject obj, RotationBehavior behavior,
                                                             ParamSelector rotation, ParamSelector lookAtPosition, ParamSelector up, ParamSelector forward,
                                                             ParamSelector offset)
        {
            Quaternion result;

            switch (behavior)
            {
            case RotationBehavior.DoNothing:
                throw new System.InvalidOperationException("RotationBehavior is to do nothing");

            case RotationBehavior.Snap:
                result = rotation.GetWorldRotation(obj.attachment, obj);
                break;

            case RotationBehavior.LookAt:
                result = GetLookAtRotation(obj.attachable, obj.attachment, lookAtPosition, up, obj);
                break;

            case RotationBehavior.LookAt2D:
                result = GetLookAt2DRotation(obj.attachable, obj.attachment, lookAtPosition, obj,
                                             obj.spriteRenderer ? obj.spriteRenderer.flipX : false);
                break;

            case RotationBehavior.LookDirection:
                result = GetLookDirectionRotation(obj.attachable, obj.attachment, forward, up, obj);
                break;

            default:
                throw new System.NotImplementedException("Rotation behavior not implemented.");
            }
            Quaternion off = offset.GetWorldRotation(obj.attachment, obj);

            return(result * off);
        }
Exemplo n.º 3
0
 public static void FollowTarget(AttachObject target, AttachObject follower,
                                 AttachStrategyFollowPositionOptions positionOptions,
                                 AttachStrategyFollowRotationOptions rotationOptions)
 {
     if (rotationOptions.behavior != RotationBehavior.DoNothing)
     {
         Quaternion desiredRotation = FollowingUtility.GetDesiredRotationForObject(follower,
                                                                                   rotationOptions.behavior, rotationOptions.GetRotationParamSelector(),
                                                                                   rotationOptions.GetLookAtPositionParamSelector(), rotationOptions.GetUpParamSelector(),
                                                                                   rotationOptions.GetForwardParamSelector(), rotationOptions.GetOffsetParamSelector());
         Quaternion nextRotation;
         if (rotationOptions.speed == 0)
         {
             nextRotation = desiredRotation;
         }
         else
         {
             nextRotation = Quaternion.RotateTowards(follower.attachable.transform.rotation, desiredRotation,
                                                     Time.deltaTime * rotationOptions.speed);
         }
         ClingyUtils.MoveRotation(nextRotation, follower.attachable.transform, rotationOptions.rotateMethod,
                                  follower.rigidbody, follower.rigidbody2D);
     }
     // todo - move before rotate, rotate before move...it's situationally dependent
     if (positionOptions.behavior != PositionBehavior.DoNothing)
     {
         FollowingObjectState state = GetObjectState(follower);
         Vector3 desiredPos         = FollowingUtility.GetDesiredPositionForObject(follower, positionOptions.behavior,
                                                                                   positionOptions.GetFollowerAnchorParamSelector(),
                                                                                   positionOptions.GetTargetAnchorParamSelector());
         if (!positionOptions.followX)
         {
             desiredPos.x = follower.attachable.transform.position.x;
         }
         if (!positionOptions.followY)
         {
             desiredPos.y = follower.attachable.transform.position.y;
         }
         if (!positionOptions.followZ)
         {
             desiredPos.z = follower.attachable.transform.position.z;
         }
         Vector3 nextPos;
         if (positionOptions.smoothing == 0)
         {
             nextPos = desiredPos;
         }
         else
         {
             nextPos = Vector3.SmoothDamp(follower.attachable.transform.position, desiredPos,
                                          ref state.velocity, positionOptions.smoothing);
         }
         ClingyUtils.MovePosition(nextPos, follower.attachable.transform, positionOptions.moveMethod,
                                  follower.rigidbody, follower.rigidbody2D);
     }
     // // note this sets localScale to lossyScale, so only works if there's no parent scale on the attacher
     // if (followScale)
     //     context.attacher.transform.localScale = context.receiver.transform.lossyScale;
 }
Exemplo n.º 4
0
 public AttachObjectListEventInfo(AttachObjectListEventType eventType, AttachObjectList sender,
                                  AttachObject obj = null, int oldIndexInCategory = -1)
 {
     this.eventType          = eventType;
     this.sender             = sender;
     this.obj                = obj;
     this.oldIndexInCategory = oldIndexInCategory;
 }
Exemplo n.º 5
0
        // returns a world rotation
        public static Quaternion GetLookAt2DRotation(GameObject gameObjectToRotate, Attachment attachment,
                                                     ParamSelector lookAtPos, AttachObject reference = null, bool flipX = false)
        {
            Vector3 lookAtWorldPos = lookAtPos.GetWorldPosition(attachment, reference);

            if (gameObjectToRotate.transform.position == lookAtWorldPos)
            {
                return(gameObjectToRotate.transform.rotation);
            }
            return(ClingyUtils.LookAt2D(gameObjectToRotate.transform.position, lookAtWorldPos, flipX));
        }
Exemplo n.º 6
0
        static FollowingObjectState GetObjectState(AttachObject obj)
        {
            FollowingObjectState state;

            if (obj.state == null)
            {
                state     = new FollowingObjectState();
                obj.state = state;
            }
            state = (FollowingObjectState)obj.state;
            return(state);
        }
Exemplo n.º 7
0
 void Start()
 {
     head = attacher.attachment.objects.Get(0, 0);
     detachHeadButton.SetActive(true);
     attachHeadButton.SetActive(false);
     tail = attacher.attachment.objects.Get(2, 0);
     detachTailButton.SetActive(true);
     attachTailButton.SetActive(false);
     link = new AttachObject(linkGameObject, 1);
     detachLinkButton.SetActive(false);
     attachLinkButton.SetActive(true);
 }
Exemplo n.º 8
0
        public static PhysicsObjectState GetObjectState(AttachObject obj)
        {
            PhysicsObjectState state;

            if (obj.state == null)
            {
                state     = new PhysicsObjectState();
                obj.state = state;
            }
            state = (PhysicsObjectState)obj.state;
            return(state);
        }
Exemplo n.º 9
0
 void Start()
 {
     attachObject = FindObjectOfType <AttachObject>();
     //Populate list with rows arrays
     //We are only populating one and three to leave gamespace for other events
     balconyRows.Add(rowOne);
     balconyRows.Add(rowThree);
     balconyRowsLower.Add(lowerRowOne);
     balconyRowsLower.Add(lowerRowThree);
     //Starting methods that spawn objects
     RowRange();
     RowRangeLower();
 }
Exemplo n.º 10
0
        public static void DestroyJoints(AttachObject obj)
        {
            PhysicsObjectState state = GetObjectState(obj);

            for (int i = 0; i < state.joints.Length; i++)
            {
                if (state.joints[i])
                {
                    GameObject.Destroy(state.joints[i]);
                    state.joints[i] = null;
                }
            }
        }
Exemplo n.º 11
0
        // returns a world position
        public static Vector3 GetDesiredPositionForObject(AttachObject obj, PositionBehavior behavior,
                                                          ParamSelector anchor1, ParamSelector anchor2)
        {
            switch (behavior)
            {
            case PositionBehavior.DoNothing:
                throw new System.InvalidOperationException("PositionBehavior is to do nothing");

            // return obj.gameObject.transform.position;
            case PositionBehavior.Snap:
                return(GetSnapPosition(obj.attachable, obj.attachment, anchor1, anchor2, obj));
            }
            throw new System.NotImplementedException("Position behavior not implemented.");
        }
Exemplo n.º 12
0
 public void OnEnable()
 {
     objectsRL = new ReorderableList(objects, typeof(AttachObject));
     // objectsRL = new ReorderableList(attachRequest.combinedObjects,
     //         typeof(AttachRequestObject), false, true, true, true);
     objectsRL.drawHeaderCallback = (Rect rect) => {
         EditorGUI.LabelField(rect, "Attach Objects");
     };
     objectsRL.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
         rect.y += EditorGUIUtility.standardVerticalSpacing;
         EditorGUI.LabelField(rect, GetLabelForAttachObject(index), EditorStyles.boldLabel);
         rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
         // SerializedProperty objProp = objectsRL.serializedProperty.GetArrayElementAtIndex(index);
         EditorGUI.BeginChangeCheck();
         AttachObject obj = GetObjectByFlattenedIndex(index);
         rect.height = EditorGUIUtility.singleLineHeight;
         GameObject seedObject = (GameObject)EditorGUI.ObjectField(rect, "Game Object", obj.seedObject,
                                                                   typeof(GameObject), true);
         rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
         string keyPattern = EditorGUI.DelayedTextField(rect, "Key Pattern", obj.keyPattern);
         if (EditorGUI.EndChangeCheck())
         {
             objectList.Replace(obj,
                                new AttachObject(seedObject, obj.category, keyPattern, obj.defaultParams.Clone()));
         }
     };
     objectsRL.onAddCallback = (ReorderableList rl) => {
         ShowAddObjectMenu();
     };
     objectsRL.onRemoveCallback = (ReorderableList rl) => {
         objectList.Remove(GetCategory(rl.index), GetIndexInCategory(rl.index, GetCategory(rl.index)));
         if (rl.index == objectList.Count())
         {
             rl.index--;
         }
         // paramsRL = null;
         // selectedObject = -1;
         // rl.index = -1;
     };
     objectsRL.onReorderCallback = (ReorderableList rl) => {
         objectList.HandleFlattenedReorder(selectedObject, rl.index);
     };
     objectsRL.elementHeightCallback = (int index) => {
         return(EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing * 4);
         // SerializedProperty objProp = objectsRL.serializedProperty.GetArrayElementAtIndex(index);
         // return ClingyEditorUtils.GetPropHeight(objProp, drawProps) + EditorGUIUtility.singleLineHeight
         //         + EditorGUIUtility.standardVerticalSpacing * 3;
     };
 }
Exemplo n.º 13
0
        private static WXPayResult GetWXPayResult(string xmlResult)
        {
            WXPayResult payResult = new WXPayResult();

            try
            {
                byte[]    array     = Encoding.UTF8.GetBytes(xmlResult);
                Stream    stream    = new MemoryStream(array);
                XDocument xDocument = new XDocument();
                xDocument = XDocument.Load(stream);
                XElement     root         = xDocument.Root;
                string       attach       = root.Element("attach").Value;
                AttachObject attachObject = new AttachObject();
                attachObject           = JsonConvert.DeserializeObject <AttachObject>(attach);
                payResult.fee_name     = attachObject.fn;
                payResult.mch_id       = root.Element("mch_id").Value;
                payResult.bank_type    = root.Element("bank_type").Value;
                payResult.cash_fee     = Convert.ToDouble(root.Element("cash_fee").Value) / 100;
                payResult.fee_type     = root.Element("fee_type").Value;
                payResult.openid       = root.Element("openid").Value;
                payResult.out_trade_no = root.Element("out_trade_no").Value;
                string time = root.Element("time_end").Value;
                payResult.time_end       = time.Substring(0, 4) + "-" + time.Substring(4, 2) + "-" + time.Substring(6, 2) + " " + time.Substring(8, 2) + ":" + time.Substring(10, 2) + ":" + time.Substring(12, 2);
                payResult.total_fee      = Convert.ToDouble(root.Element("total_fee").Value) / 100;
                payResult.transaction_id = root.Element("transaction_id").Value;
                if (attachObject.fn == "看园定金")
                {
                    payResult.attach = attachObject.fn + ":" + attachObject.name + "的家长" + attachObject.rn + "交费" + attachObject.tc + "元";
                }
                else
                {
                    SignUp s = SignUpDal.GetSignUpInfo(attachObject.kn, attachObject.id);
                    payResult.attach = attachObject.fn + ":" + s.name + "的家长" + s.relateName + "交费" + attachObject.tc + "元";
                }
            }
            catch (Exception exp)
            {
                using (StreamWriter sw = new StreamWriter("D:\\1_importTemp\\TestFile5.txt"))
                {
                    sw.WriteLine("error:" + exp.Message);
                }
            }
            return(payResult);
        }
Exemplo n.º 14
0
        // public static void UpdateJointDescriptionsFromParams(AttachObject jointed, AttachObject connected,
        //         AttachStrategyJointDescription2D[] jointDescriptions) {
        //     PhysicsObjectState jointedState = GetObjectState(jointed);
        //     PhysicsObjectState connectedState = GetObjectState(connected);
        //     int i = 0;
        //     foreach (AttachStrategyJointDescription2D jd in jointDescriptions) {
        //         UpdateJointDescriptionFromParams(jd, jointed, connected);
        //         // jd.ApplyAnchors(jointedState.joints[i]);
        //         // jd.ApplyLimits(jointedState.joints[i], jointed.gameObject, connectedState.rb);
        //         i ++;
        //     }
        // }

        public static void CreateOrApplyAllJoints(AttachObject jointed, AttachObject connected,
                                                  AttachStrategyJointDescription[] jointDescriptions, AttachObject reference = null,
                                                  bool hideJointsInInspector = true)
        {
            PhysicsObjectState jointedState = GetObjectState(jointed);

            if (jointedState.joints == null || jointedState.joints.Length != jointDescriptions.Length)
            {
                jointedState.joints = new Joint[jointDescriptions.Length];
            }
            int i = 0;

            foreach (AttachStrategyJointDescription jd in jointDescriptions)
            {
                UpdateJointDescriptionFromParams(jd, jointed, connected, reference);
                jointedState.joints[i] = jd.CreateOrApply(jointed.rigidbody.gameObject, connected.rigidbody,
                                                          joint: jointedState.joints[i]);
                jointedState.joints[i].hideFlags = hideJointsInInspector ? HideFlags.HideInInspector : HideFlags.None;
                i++;
            }
        }
Exemplo n.º 15
0
        static void UpdateJointDescriptionFromParams(AttachStrategyJointDescription jd, AttachObject jointed,
                                                     AttachObject connected, AttachObject reference = null)
        {
            Attachment attachment = jointed.attachment;

            ParamSelector selector;

            selector = jd.GetAnchorParamSelector();
            // anchors must be relative to the associated Rigidbody's transform
            jd.anchor = jointed.rigidbody.transform.InverseTransformPoint(
                selector.GetWorldPosition(attachment, reference));

            selector = jd.GetConnectedAnchorParamSelector();
            // anchors must be relative to the associated Rigidbody's transform
            jd.connectedAnchor = connected.rigidbody.transform.InverseTransformPoint(
                selector.GetWorldPosition(attachment, reference));

            selector = jd.GetAxisParamSelector();
            // axes must be relative to the jointed Rigidbody's transform
            jd.axis = jointed.rigidbody.transform.InverseTransformDirection(
                selector.GetWorldDirection(attachment, reference));

            selector = jd.GetSecondaryAxisParamSelector();
            // axes must be relative to the jointed Rigidbody's transform
            jd.secondaryAxis = jointed.rigidbody.transform.InverseTransformDirection(
                selector.GetWorldDirection(attachment, reference));

            selector = jd.GetSwingAxisParamSelector();
            // axes must be relative to the jointed Rigidbody's transform
            jd.swingAxis = jointed.rigidbody.transform.InverseTransformDirection(
                selector.GetWorldDirection(attachment, reference));

            // todo maybe
            // selector = jd.GetLimitsParamSelector();
            // provider = reference != null ? attachment.attachStrategy.ResolveProvider(selector.provider, reference)
            //         : attachment.attachStrategy.ResolveProvider(selector.provider, attachment);
            // jd.limits = provider.resolvedParams.GetParam(ParamType.AngleLimits, selector.name, selector.defaultParam)
            //         .angleLimitsValue;
        }
Exemplo n.º 16
0
    public void AttachToHP(GameObject obj, string szHP, bool initByHP)
    {
        if(null == obj || IsAttach(obj, szHP)) return;

        AttachObject att = new AttachObject(0, szHP, false);
        att.Obj = obj;
        AttachObjectToHP(obj, szHP, initByHP);
    }
Exemplo n.º 17
0
 public void AddAttach(int modelId, string szHP)
 {
     if(IsAttach(modelId, szHP)) return;
     AttachObject att = new AttachObject(modelId, szHP, true);
     ModelMgr.Instance.LoadModel(modelId, OnAttachCallBack, null, att);
 }
Exemplo n.º 18
0
        // returns a world rotation
        public static Quaternion GetLookDirectionRotation(GameObject gameObjectToRotate, Attachment attachment,
                                                          ParamSelector forward, ParamSelector up, AttachObject reference = null)
        {
            Vector3 worldForward = forward.GetWorldDirection(attachment, reference);
            Vector3 worldUp      = up.GetWorldDirection(attachment, reference);

            return(Quaternion.LookRotation(worldForward, worldUp));
        }
Exemplo n.º 19
0
        public static void RefreshLineRenderer(AttachStrategyLineRendererDescription lineRendererDescription,
                                               LineState state, AttachObject[] objects, AttachObject reference = null,
                                               bool hideLineRendererInInspector = true)
        {
            AttachStrategyLineRendererDescription lrd = lineRendererDescription;
            Attachment attachment = objects[0].attachment;

            if (state.points == null || state.points.Length != objects.Length)
            {
                state.points = new Vector3[objects.Length];
            }
            state.widthCurve    = new AnimationCurve();
            state.colorGradient = new Gradient();
            GradientColorKey[] colors = new GradientColorKey[objects.Length];
            GradientAlphaKey[] alphas = new GradientAlphaKey[objects.Length];
            int i = 0;

            foreach (AttachObject obj in objects)
            {
                ParamSelector selector = lrd.GetPositionParamSelector(obj);
                state.points[i] = selector.GetWorldPosition(attachment, reference ?? obj);
                if (lrd.perObjectWidth)
                {
                    selector = lrd.GetWidthParamSelector(obj);
                    state.widthCurve.AddKey(i / (objects.Length - 1),
                                            selector.GetParam(attachment, reference ?? obj).floatValue);
                }
                if (lrd.perObjectColor)
                {
                    selector  = lrd.GetColorParamSelector(obj);
                    colors[i] = new GradientColorKey(selector.GetParam(attachment, reference ?? obj).colorValue,
                                                     i / (objects.Length - 1));
                    alphas[i] = new GradientAlphaKey(selector.GetParam(attachment, reference ?? obj).colorValue.a,
                                                     i / (objects.Length - 1));
                }
                i++;
            }
            if (lrd.perObjectColor)
            {
                state.colorGradient.SetKeys(colors, alphas);
            }
            lrd.UpdateLineRenderer(state.lineRenderer, state.points, lrd.perObjectColor ? state.colorGradient : null,
                                   lrd.perObjectWidth ? state.widthCurve : null);
            state.lineRenderer.hideFlags = hideLineRendererInInspector ? HideFlags.HideInInspector : HideFlags.None;
        }
Exemplo n.º 20
0
 public abstract ParamSelector GetWidthParamSelector(AttachObject obj);
Exemplo n.º 21
0
 public abstract ParamSelector GetPositionParamSelector(AttachObject obj);
Exemplo n.º 22
0
        // returns a world rotation
        public static Quaternion GetLookAtRotation(GameObject gameObjectToRotate, Attachment attachment,
                                                   ParamSelector lookAtPos, ParamSelector up, AttachObject reference = null)
        {
            Vector3 lookAtWorldPos = lookAtPos.GetWorldPosition(attachment, reference);
            Vector3 worldUp        = up.GetWorldDirection(attachment, reference);

            if (gameObjectToRotate.transform.position == lookAtWorldPos)
            {
                return(gameObjectToRotate.transform.rotation);
            }
            return(Quaternion.LookRotation(lookAtWorldPos - gameObjectToRotate.transform.position, worldUp));
        }
Exemplo n.º 23
0
 void DelAttach(AttachObject att)
 {
     if(null == att) return;
     if(null != att.Obj)
     {
         att.Obj.transform.parent = null;
         if(att.MustUnload)
         {
             GameObject.DestroyImmediate(att.Obj);
             ModelMgr.Instance.UnLoadModel(att.ModelId);
         }
     }
     listAttachObject.Remove(att);
 }
Exemplo n.º 24
0
 public abstract ParamSelector GetColorParamSelector(AttachObject obj);
Exemplo n.º 25
0
        // returns a world position
        public static Vector3 GetSnapPosition(GameObject gameObjectToSnap, Attachment attachment,
                                              ParamSelector anchor1, ParamSelector anchor2, AttachObject reference = null)
        {
            Vector3 worldAnchor1 = anchor1.GetWorldPosition(attachment, reference);
            Vector3 worldAnchor2 = anchor2.GetWorldPosition(attachment, reference);

            return(worldAnchor2 - (worldAnchor1 - gameObjectToSnap.transform.position));
        }