private UiMonoWithMethods GenerateButtonInformation(TargetManagerMonoWithNameAndMethods mono, GameObject incTarget = null, string source = "") { GameObject target = null; if (incTarget != null) { target = incTarget; } else { target = this.target; } if (target == null) { Debug.Log("GenButtons No Target!"); return(null); } var result = new UiMonoWithMethods { MonoName = mono.Name, Object = target, Methods = mono.Methods.Select(y => new UiMethodNameWithParameters { Name = y.Name, Parameters = y.Parameters, }).ToArray(), Source = source, }; return(result); }
private void DestroyIfMonoWithSameNameAttached(TargetManagerMonoWithNameAndMethods preexistingMono, GameObject target, CompMethodsInAssemblyType funcs, List <TargetManagerMonoWithNameAndMethods> existingMonosForTarget) { /// If a mono with the same name is attched, we destroy the old one! if (preexistingMono != null) { Component monoToDestroy = target.GetComponent(preexistingMono.Mono.GetType()); GameObject.Destroy(monoToDestroy); existingMonosForTarget.Remove(existingMonosForTarget.SingleOrDefault(x => x.Name == funcs.TypeName)); Debug.Log("Old Script is overriden"); } }
private bool AreThereChangesInSignature(TargetManagerMonoWithNameAndMethods newMonoData, TargetManagerMonoWithNameAndMethods preexistingMono) { ///If this is the first attach if (preexistingMono == null || preexistingMono.Methods == null) { return(true); } if (!this.TwoMehtodCollHaveSameSignatures(preexistingMono.Methods, newMonoData.Methods)) { return(false); } return(true); }
private TargetManagerMonoWithNameAndMethods GetPreexistingMonoWithSameName(GameObject target, CompMethodsInAssemblyType funcs, List <TargetManagerMonoWithNameAndMethods> existingMonosForTarget) { /// Cheking if there is more than one script with given name already registered which should never happen. TargetManagerMonoWithNameAndMethods[] existingMonos = existingMonosForTarget.Where(x => x.Name == funcs.TypeName).ToArray(); if (existingMonos.Length > 1) { Debug.Log($"There are more that 1 scripts with name {funcs.TypeName} already attached!"); Debug.Break(); return(null); } if (existingMonos.Length == 0) { return(null); } ///We have exactly one TargetManagerMonoWithNameAndMethods previousMono = existingMonos[0]; return(previousMono); }
/// <summary> /// Does two things: /// If attach is true, it attaches the mono to the target and registeres it in attachedMonos /// If attach is false, means that the script is already attached and it only regerteres it in the same collection. /// Also if there is a mono with that name already, it remeves the old one and registeres the new one. /// </summary> /// <param name="funcs"></param> /// <param name="target"></param> /// <param name="attach"></param> /// <param name="alreadyAttachedMono"> If null we need to attach what is passed. If not null - this is the mono that is already attached!</param> /// <returns></returns> private TargetManagerMonoWithNameAndMethods AttachAndAddToDict( CompMethodsInAssemblyType funcs, GameObject target, MonoBehaviour alreadyAttachedMono) { this.CreateMonoDataIfNoneExists(target); /// Getting exsiting monos for target. List <TargetManagerMonoWithNameAndMethods> existingMonosForTarget = this.attachedMonos[target]; TargetManagerMonoWithNameAndMethods preexistingMono = GetPreexistingMonoWithSameName(target, funcs, existingMonosForTarget); this.DestroyIfMonoWithSameNameAttached(preexistingMono, target, funcs, existingMonosForTarget); MonoBehaviour attachedMono = alreadyAttachedMono == null?funcs.Attach(target) : alreadyAttachedMono; TargetManagerMonoWithNameAndMethods newMonoData = new TargetManagerMonoWithNameAndMethods(funcs.TypeName, attachedMono); newMonoData.Methods = funcs.MethodInfos.Select(x => new TargetManagerMethodInfoWithName { MethodInfo = x.Value.MethodInfo, Parameters = x.Value.Parameters, Name = x.Value.MethodInfo.Name, }).ToList(); newMonoData.changesInMethodSignature = this.AreThereChangesInSignature(newMonoData, preexistingMono); /// Adding it to the collection for the given target. existingMonosForTarget.Add(newMonoData); /// Passing the if (alreadyAttachedMono == null) { ReferenceBuffer.Instance.Level.RegisterUpdatedMono(newMonoData); } return(newMonoData); }
public override void RegisterUpdatedMono(TargetManagerMonoWithNameAndMethods data) { if (data.Name == "TurretInt") { var obj = data.Mono; var setup = data.Methods.SingleOrDefault(x => x.Name == "Setup"); if (setup == null) { Debug.LogError("SETUP NULL!!!"); return; } var shootLoop = data.Methods.SingleOrDefault(x => x.Name == "ShootLoop"); if (setup == null) { Debug.LogError("SHOOT LOOP NULL!!!"); return; } setup.MethodInfo.Invoke(obj, new object[] { this }); shootLoop.MethodInfo.Invoke(obj, new object[] { }); } }
public virtual void RegisterUpdatedMono(TargetManagerMonoWithNameAndMethods data) { }