示例#1
0
        public void BuildLink(UnityEngine.Object other)
        {
            Type otherType = other.GetType();

            if (otherType == typeof(IBaseEvent) || !(other is IBaseEvent) || source == null)
            {
                Debug.LogError("Cette node n'accepte pas les liens 'Moment'. Elle n'implémente pas l'interface IEvent.");
            }
            else
            {
                BaseMoment moment     = source.moments[momentIndex].moment;
                Type[]     interfaces = otherType.FindInterfaces(
                    InterfaceFilter,
                    otherType);

                for (int i = 0; i < interfaces.Length; i++)
                {
                    Type[] types = interfaces[i].GetGenericArguments();
                    if (moment.MatchWithGenericTypes(types))
                    {
                        source.moments[momentIndex].moment.AddIEvent(other);
                        break;
                    }
                }
            }
            source = null;
        }
        private void BuildNamedMoments()
        {
            //On cherche a travers tous les membres, lesquels sont de type 'MomentLauncher'
            Type myEventType = myEvent.GetType();

            FieldInfo[] allFields = myEventType.GetFields();
            moments = new List <NamedMoments>();
            for (int i = 0; i < allFields.Length; i++)
            {
                if (allFields[i].FieldType.IsSubclassOf(typeof(BaseMoment)))
                {
                    BaseMoment moment = allFields[i].GetValue(myEvent) as BaseMoment;
                    moments.Add(new NamedMoments(moment, allFields[i].Name));
                }
            }

            BaseMoment[] additionalMoments;
            string[]     additionalNames;
            myEvent.GetAdditionalMoments(out additionalMoments, out additionalNames);

            if (additionalMoments != null && additionalNames != null)
            {
                int count = Mathf.Min(additionalNames.Length, additionalMoments.Length);
                moments.Capacity = moments.Count + count;
                for (int i = 0; i < count; i++)
                {
                    moments.Add(new NamedMoments(additionalMoments[i], additionalNames[i]));
                }
            }

            myEvent.ResetWindowRectSize();
        }
        public void DrawLinks()
        {
            Handles.BeginGUI();

            for (int i = 0; i < moments.Count; i++)
            {
                BaseMoment moment = moments[i].moment;
                for (int u = 0; u < moment.iEvents.Count; u++)
                {
                    UnityEngine.Object otherNode = moment.iEvents[u];
                    if (otherNode is INodedEvent)
                    {
                        INodedEvent otherDisplay = otherNode as INodedEvent;
                        Rect        targetRect   = otherDisplay.WindowRect;
                        DrawBezierRight(WindowRect.position + moments[i].lastDrawnPos,
                                        new Vector2(targetRect.xMin, targetRect.y + 28));
                    }
                    else
                    {
                        Debug.LogWarning("Le moment apparenant a: " + NodeLabel + " a un lien vers un IEvent qui n'est pas IEventDisplay."
                                         + " Destruction du lien.");
                        moment.RemoveNulls();
                        break;
                    }
                }
            }

            Handles.EndGUI();
        }
示例#4
0
        private void RemoveAllLinksTo(IBaseEvent theEvent, Object on)
        {
            FieldInfo[] fields = on.GetType().GetFields();

            for (int i = 0; i < fields.Length; i++)
            {
                if (fields[i].FieldType.IsSubclassOf(typeof(BaseMoment)))
                {
                    BaseMoment moment = fields[i].GetValue(on) as BaseMoment;
                    moment.RemoveIEvent(theEvent.AsObject());
                }
            }


            if (on is INodedEvent)
            {
                INodedEvent onDisplay = on as INodedEvent;

                BaseMoment[] additionalMoments;
                string[]     additionalNames;
                onDisplay.GetAdditionalMoments(out additionalMoments, out additionalNames);

                if (additionalMoments != null)
                {
                    for (int i = 0; i < additionalMoments.Length; i++)
                    {
                        additionalMoments[i].RemoveIEvent(theEvent.AsObject());
                    }
                }
            }
        }
 public NamedMoments(BaseMoment moment, string varName)
 {
     this.moment       = moment;
     this.genericTypes = moment.GetGenericTypes();
     displayName       = varName + "(";
     for (int i = 0; i < genericTypes.Length; i++)
     {
         if (i > 0)
         {
             displayName += ", ";
         }
         displayName += genericTypes[i].Name;
     }
     displayName += ")";
 }