public override void Init(UControl self) { base.Init(self); CanvasGroup = Target.GetComponent <CanvasGroup>(); if (CanvasGroup == null) { CanvasGroup = Target.AddComponent <CanvasGroup>(); } }
protected override void OnInitialize() { base.OnInitialize(); _canvasGroup = Target.GetComponent <CanvasGroup>(); if (_canvasGroup == null) { _canvasGroup = Target.AddComponent <CanvasGroup>(); } _canvasGroup.alpha = 0f; }
public void OnPointerExit(PointerEventData e) { var fade = Target.GetComponent <UIFade>(); if (fade != null) { fade.Destroy(); } fade = Target.AddComponent <UIFade>(); fade.TargetValue = UnhoveredOpacity; fade.Duration = Duration; }
public override void Play() { base.Play(); var tweener = Target.AddComponent <UiTweenFloat>(); switch (Fade) { case FadeType.In: tweener.From = 0f; tweener.To = 1f; break; case FadeType.Out: tweener.From = 1f; tweener.To = 0f; break; default: break; } if (Mathf.Approximately(Duration, 0f)) { FixAlpha(); Done(); return; } tweener.Duration = Duration; tweener.OnTweenValue += (value) => { Canvas.alpha = value; }; tweener.Play(() => { FixAlpha(); Done(); }); }
/// <summary> /// 転送コンポーネントへの差し替え。 /// DLLコンポーネントを参照してるオブジェクトがあったら、そっちのcsコンポーネントへの差し替えもする。 /// </summary> /// <param name="objects">全オブジェクト</param> public void Forward(IEnumerable <ForwardingGameObjectInfo> objects) { foreach (var c in DllComponents.Where(x => x.HasForwarder)) { var dllType = c.DllType; var csType = c.ForwarderType; var dllComponent = Target.GetComponent(dllType); var csComponent = Target.AddComponent(csType); if (csComponent == null) { continue; } //DLLコンポーネント中のシリアライズ フィールドの値を、csコンポーネントに移植。 foreach (var f in dllType.GetSerializeFieldInfo()) { var value = f.GetValue(dllComponent); f.SetValue(csComponent, value); } //DLLコンポーネントを参照しているやつをcsコンポーネントに差し替え foreach (var obj in objects) { foreach (var component in obj.Target.GetComponents <Component>()) { foreach (var field in ForwardingFieldInfo.GetFields(component)) { var v = field.Value; if (ReferenceEquals(v, dllComponent)) { field.Value = csComponent; } } } } Object.DestroyImmediate(dllComponent); } }
public override void Play() { base.Play(); var tweener = Target.AddComponent <UiTweenVector>(); tweener.Duration = Duration; tweener.From = From; tweener.To = To; tweener.OnTweenValue += (value) => { Canvas.transform.localScale = value; }; tweener.Play(() => { Canvas.transform.localScale = tweener.To; Done(); }); }
public void Forward() { foreach (var c in DllComponents.Where(x => x.HasForwarder)) { var dllType = c.DllType; var csType = c.ForwarderType; var dllComponent = Target.GetComponent(dllType); var csComponent = Target.AddComponent(csType); foreach (var f in dllType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(f => f.GetCustomAttributes(true).Any(a => a is SerializeField))) { var value = f.GetValue(dllComponent); f.SetValue(csComponent, value); } //todo: public get/set 持ちプロパティ Object.DestroyImmediate(dllComponent); } }
private void SetBoundsControlCollider() { // Make sure that the bounds of all child objects are up to date before we compute bounds UnityPhysics.SyncTransforms(); if (boundsOverride != null) { TargetBounds = boundsOverride; TargetBounds.transform.hasChanged = true; } else { Bounds bounds = GetTargetBounds(); TargetBounds = Target.AddComponent <BoxCollider>(); TargetBounds.center = bounds.center; TargetBounds.size = bounds.size; } CalculateBoxPadding(); TargetBounds.EnsureComponent <NearInteractionGrabbable>(); }
// TODO:インスペクタで回転方向の有効無効を制御できるようにする public void Awake() { Target = transform.parent.gameObject; Target.AddComponent <TransformControllerActivater>(); gameObject.SetActive(false); List <Bounds> boundsList = new List <Bounds>(); foreach (var rendererObj in Target.GetComponentsInChildren <Renderer>()) { boundsList.Add(rendererObj.bounds); } float maxX = boundsList.Max((bounds) => { return(bounds.center.x + bounds.extents.x); }); float minX = boundsList.Min((bounds) => { return(bounds.center.x - bounds.extents.x); }); float maxY = boundsList.Max((bounds) => { return(bounds.center.y + bounds.extents.y); }); float minY = boundsList.Min((bounds) => { return(bounds.center.y - bounds.extents.y); }); float maxZ = boundsList.Max((bounds) => { return(bounds.center.z + bounds.extents.z); }); float minZ = boundsList.Min((bounds) => { return(bounds.center.z - bounds.extents.z); }); // LINQとLambda使ってるので性能出ないとき用 /* * float maxX = boundsList[0].center.x + boundsList[0].extents.x; * float minX = boundsList[0].center.x - boundsList[0].extents.x; * float maxY = boundsList[0].center.y + boundsList[0].extents.y; * float minY = boundsList[0].center.y - boundsList[0].extents.y; * float maxZ = boundsList[0].center.z + boundsList[0].extents.z; * float minZ = boundsList[0].center.z - boundsList[0].extents.z; * * for (int i = 1; i < boundsList.Count; ++i) { * float tempMaxX, tempMinX; * float tempMaxY, tempMinY; * float tempMaxZ, tempMinZ; * * tempMaxX = boundsList[i].center.x + boundsList[i].extents.x; * tempMinX = boundsList[i].center.x - boundsList[i].extents.x; * tempMaxY = boundsList[i].center.y + boundsList[i].extents.y; * tempMinY = boundsList[i].center.y - boundsList[i].extents.y; * tempMaxZ = boundsList[i].center.z + boundsList[i].extents.z; * tempMinZ = boundsList[i].center.z - boundsList[i].extents.z; * * if (tempMaxX > maxX) maxX = tempMaxX; * if (tempMaxY > maxY) maxY = tempMaxY; * if (tempMaxZ > maxZ) maxZ = tempMaxZ; * * if (tempMinX < minX) minX = tempMinX; * if (tempMinY < minY) minY = tempMinY; * if (tempMinZ < minZ) minZ = tempMinZ; * } */ float posX = maxX - (maxX - minX) / 2f; float posY = maxY - (maxY - minY) / 2f; float posZ = maxZ - (maxZ - minZ) / 2f; Vector3 center = new Vector3(posX, posY, posZ); transform.position = center; PositionControlerScale = new Vector3( (maxX - minX) / Target.transform.localScale.x, (maxY - minY) / Target.transform.localScale.y, (maxZ - minZ) / Target.transform.localScale.z ); if (Target.GetComponent <Collider>() == null) { var collider = Target.AddComponent <BoxCollider>(); collider.size = PositionControlerScale; collider.center = Target.transform.InverseTransformPoint(center); } }