Exemple #1
0
        protected override void DisconnectBoth(AttachObject obj1, AttachObject obj2)
        {
            LineObjectState state = (LineObjectState)obj1.state;

            Destroy(state.lineState.lineRenderer);
            state.lineState.lineRenderer = null;
        }
Exemple #2
0
        public Vector3 GetWorldDirection(Attachment attachment, AttachObject reference = null)
        {
            if (defaultParam.type != ParamType.Vector3)
            {
                throw new System.InvalidOperationException("Param type is not Vector3");
            }
            AttachObject provider = GetProvider(attachment, reference);
            Param        param    = provider.resolvedParams.GetParam(defaultParam);

            if (relativityType == ParamRelativityType.None)
            {
                return(param.vector3Value);
            }
            if (relativityType == ParamRelativityType.Normal)
            {
                if (relativeTo == ParamNormalRelativity.World)
                {
                    return(param.vector3Value);
                }
                AttachObject relativeToObject = provider;
                if (relativeTo == ParamNormalRelativity.Object)
                {
                    relativeToObject = GetRelativeToProvider(attachment, reference);
                }
                return(param.GetWorldDirection(relativeToObject.paramsRelativeTo));
            }
            throw new System.NotImplementedException("Param relativity type not supported for this operation");
        }
        public override void OnObjectWasRemoved(Attachment attachment, AttachObject obj, int oldIndexInCategory)
        {
            if (obj.category != (int)Categories.Links)
            {
                return;
            }
            AttachObject link;

            if (oldIndexInCategory == 0)
            {
                link = GetHead(attachment);
            }
            else
            {
                link = attachment.objects.Get((int)Categories.Links, oldIndexInCategory - 1);
            }
            if (link == null || !link.isConnected)
            {
                return;
            }
            AttachObject nextLink = GetNextLink(link);

            if (nextLink != null && nextLink.isConnected)
            {
                ConnectLinks(link, nextLink);
            }
        }
Exemple #4
0
        public int GetSortingOrder(Attachment attachment, AttachObject reference = null)
        {
            if (defaultParam.type != ParamType.Integer)
            {
                throw new System.InvalidOperationException("Param type is not Integer");
            }
            AttachObject provider = GetProvider(attachment, reference);
            Param        param    = provider.resolvedParams.GetParam(defaultParam);

            if (relativityType == ParamRelativityType.None)
            {
                return(param.intValue);
            }
            if (relativityType == ParamRelativityType.Normal)
            {
                if (relativeTo == ParamNormalRelativity.World)
                {
                    return(param.intValue);
                }
                AttachObject relativeToObject = provider;
                if (relativeTo == ParamNormalRelativity.Object)
                {
                    relativeToObject = GetRelativeToProvider(attachment, reference);
                }
                return(param.GetSortingOrder(relativeToObject.spriteRenderer));
            }
            throw new System.NotImplementedException("Param relativity type not supported for this operation");
        }
        Vector3 GetDesiredPositionForObject(AttachObject obj)
        {
            PositionOptions options = onAttachOptions.positionOptions;

            return(ClingyFollowing.FollowingUtility.GetDesiredPositionForObject(obj, options.behavior,
                                                                                options.anchor1Param, options.anchor2Param));
        }
Exemple #6
0
 public AttachEventInfo(AttachEventType eventType, AttachObject attachObject, MonoBehaviour sender = null)
 {
     this.eventType    = eventType;
     this.attachObject = attachObject;
     this.attachment   = attachObject.attachment;
     this.sender       = null;
 }
 public override void DoLateUpdate(Attachment attachment) {
     if (!IsConnected(attachment))
         return;
     AttachObject target = GetTarget(attachment);
     AttachObject follower = GetFollower(attachment);
     FollowingAttachStrategyUtility.FollowTarget(target, follower, positionOptions, rotationOptions);
 }
        public void Insert(int indexInCategory, AttachObject obj)
        {
            int c         = 0;
            int flattened = -1;

            for (int i = 0; i < objects.Count; i++)
            {
                if (objects[i].category == obj.category)
                {
                    if (c == indexInCategory)
                    {
                        flattened = i;
                        break;
                    }
                    c++;
                }
            }
            if (flattened == -1)
            {
                if (indexInCategory != c)
                {
                    throw new ArgumentOutOfRangeException();
                }
                flattened = objects.Count;
            }
            objects.Insert(flattened, obj);
            SendEvent(AttachObjectListEventType.ObjectAdded, obj);
        }
Exemple #9
0
        protected bool IsConnected(Attachment attachment)
        {
            AttachObject obj1 = GetObject1(attachment);
            AttachObject obj2 = GetObject2(attachment);

            return(obj1 != null && obj1.isConnected && obj2 != null && obj2.isConnected);
        }
        Quaternion GetDesiredRotationForObject(AttachObject obj)
        {
            RotationOptions options = onAttachOptions.rotationOptions;

            return(ClingyFollowing.FollowingUtility.GetDesiredRotationForObject(obj, options.behavior,
                                                                                options.rotationParam, options.lookAtPositionParam, options.upParam, options.forwardParam,
                                                                                options.offsetParam));
        }
Exemple #11
0
 public override ParamSelector GetColorParamSelector(AttachObject obj)
 {
     if (obj.category == (int)Categories.Root)
     {
         return(rootColorParam);
     }
     return(leafColorParam);
 }
Exemple #12
0
 public AttachObject GetRelativeToProvider(Attachment attachment, AttachObject reference = null)
 {
     if (reference == null)
     {
         return(attachment.strategy.ResolveProvider(this.relativeToProvider, attachment));
     }
     return(attachment.strategy.ResolveProvider(this.relativeToProvider, reference));
 }
Exemple #13
0
 public virtual void ApplyParamsForSelf(AttachObject obj)
 {
     if (spriteParams)
     {
         spriteParams.MergeParamsForCurrentSprite(obj.resolvedParams, GetSpriteRenderer());
     }
     obj.resolvedParams.MergeFrom(baseParams);
 }
Exemple #14
0
        public void Remove(AttachObject obj)
        {
            int oldIndexInCategory = GetIndexInCategory(obj);

            SendEvent(AttachObjectListEventType.ObjectWillBeRemoved, obj);
            objects.Remove(obj);
            SendEvent(AttachObjectListEventType.ObjectRemoved, obj, oldIndexInCategory: oldIndexInCategory);
        }
Exemple #15
0
        protected override void ConnectLeaf(AttachObject root, AttachObject leaf)
        {
            LineObjectState state = new LineObjectState();

            state.lineState.lineRenderer = leaf.seedObject.AddComponent <LineRenderer>();
            state.objects = new AttachObject[2];
            leaf.state    = state;
        }
Exemple #16
0
 public override ParamSelector GetPositionParamSelector(AttachObject obj)
 {
     if (obj.category == (int)Categories.Object1)
     {
         return(position1Param);
     }
     return(position2Param);
 }
Exemple #17
0
        protected override void DisconnectLeaf(AttachObject root, AttachObject leaf)
        {
            LineObjectState state = (LineObjectState)leaf.state;

            DestroyImmediate(state.lineState.lineRenderer);
            state.lineState.lineRenderer = null;
            leaf.state = null;
        }
Exemple #18
0
 public override ParamSelector GetWidthParamSelector(AttachObject obj)
 {
     if (obj.category == (int)Categories.Object1)
     {
         return(width1Param);
     }
     return(width2Param);
 }
Exemple #19
0
 public override ParamSelector GetColorParamSelector(AttachObject obj)
 {
     if (obj.category == (int)Categories.Object1)
     {
         return(color1Param);
     }
     return(color2Param);
 }
Exemple #20
0
        public void Replace(AttachObject existingObj, AttachObject newObj)
        {
            int flattened = GetFlattenedIndex(existingObj);

            Remove(existingObj);
            objects.Insert(flattened, newObj);
            SendEvent(AttachObjectListEventType.ObjectAdded, newObj);
        }
Exemple #21
0
 public void ReorderInCategory(AttachObject obj, int newIndexInCategory)
 {
     if (newIndexInCategory == GetIndexInCategory(obj))
     {
         return;
     }
     Remove(obj);
     Insert(newIndexInCategory, obj);
 }
Exemple #22
0
 void HandleObjectWasRemoved(AttachObject obj, int oldIndexInCategory)
 {
     if (!isActive)
     {
         return;
     }
     strategy.OnObjectWasRemoved(this, obj, oldIndexInCategory);
     UpdateIsConnected();
 }
        public override void ApplyParamsForOther(AttachObject other, AttachObject self)
        {
            int     count   = self.attachment.objects.Count(other.category);
            float   degree  = (360 / count) * other.indexInCategory + offset;
            float   radians = degree * Mathf.Deg2Rad;
            Vector3 pos     = new Vector3(Mathf.Cos(radians), Mathf.Sin(radians)) * distance;

            other.resolvedParams.SetParam(new Param(pos, outputPosition));
        }
Exemple #24
0
 void HandleObjectWillBeRemoved(AttachObject obj)
 {
     if (!isActive)
     {
         return;
     }
     orphans.Add(obj);
     obj.Remove();
     UpdateIsConnected();
 }
Exemple #25
0
        public override void ApplyParamsForOther(AttachObject other, AttachObject self)
        {
            defaultInputPosition.name = inputPosition;
            Vector3 worldPos = other.resolvedParams.GetParam(defaultInputPosition)
                               .GetWorldPosition(other.seedObject, other.spriteRenderer);
            Vector3Int cell       = grid.WorldToCell(worldPos);
            Vector3    translated = grid.GetCellCenterWorld(cell);

            other.resolvedParams.SetParam(new Param(translated, outputPosition));
        }
Exemple #26
0
        protected override void ConnectBoth(AttachObject obj1, AttachObject obj2)
        {
            LineObjectState state = new LineObjectState();

            state.lineState.lineRenderer = obj1.seedObject.AddComponent <LineRenderer>();
            state.objects = new AttachObject[2] {
                obj1, obj2
            };
            obj1.state = state;
        }
Exemple #27
0
 // called by Attachment
 public void DeregisterAttachObject(AttachObject obj)
 {
     Debug.Assert(attachObjects.Contains(obj));
     attachObjects.Remove(obj);
     obj.attachment.events.OnObjectWillJoin.RemoveListener(HandleEvent);
     obj.attachment.events.OnObjectWillConnect.RemoveListener(HandleEvent);
     obj.attachment.events.OnObjectConnected.RemoveListener(HandleEvent);
     obj.attachment.events.OnObjectWillDisconnect.RemoveListener(HandleEvent);
     obj.attachment.events.OnObjectWillLeave.RemoveListener(HandleEvent);
     obj.attachment.events.OnObjectLeft.RemoveListener(HandleEvent);
 }
Exemple #28
0
 // called by Attachment
 public void RegisterAttachObject(AttachObject obj)
 {
     Debug.Assert(!attachObjects.Contains(obj));
     attachObjects.Add(obj);
     obj.attachment.events.OnObjectWillJoin.AddListener(HandleEvent);
     obj.attachment.events.OnObjectWillConnect.AddListener(HandleEvent);
     obj.attachment.events.OnObjectConnected.AddListener(HandleEvent);
     obj.attachment.events.OnObjectWillDisconnect.AddListener(HandleEvent);
     obj.attachment.events.OnObjectWillLeave.AddListener(HandleEvent);
     obj.attachment.events.OnObjectLeft.AddListener(HandleEvent);
 }
Exemple #29
0
        void SendEvent(AttachObjectListEventType eventType, AttachObject obj = null, int oldIndexInCategory = -1)
        {
            if (OnChanged == null)
            {
                return;
            }
            AttachObjectListEventInfo eventInfo = new AttachObjectListEventInfo(eventType, this, obj,
                                                                                oldIndexInCategory);

            OnChanged.Invoke(eventInfo);
        }
        FollowingObjectState GetObjectState(AttachObject obj)
        {
            FollowingObjectState state;

            if (obj.state == null)
            {
                state     = new FollowingObjectState();
                obj.state = state;
            }
            state = (FollowingObjectState)obj.state;
            return(state);
        }