コード例 #1
0
        public override void Run()
        {
            base.Run();

            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (!Physics.Raycast(ray, out hit))
            {
                return;
            }

            if (MarkFx != null)
            {
                SFX_FxObjectInstancer.InstantiateFx(MarkFx, hit.point, hit.normal);
            }

            if (MarkTargetMode == MarkMode.GameObject)
            {
                if (_markedObjects.Count >= MaxTargets)
                {
                    return;
                }

                var gameObjectId = hit.transform.gameObject.GetInstanceID();
                if (_markedObjects.ContainsKey(gameObjectId))
                {
                    return;
                }

                _markedObjects[gameObjectId] = hit.transform.gameObject;
                var materialAdded = hit.transform.gameObject.AddComponent <SFX_MaterialAdder>();
                materialAdded.Material = MarkMaterial;
                materialAdded.LifeTime = MarkLifeTime;

                SFX_InvokeUtil.RunLater(this, () =>
                {
                    materialAdded.Stop();
                    Destroy(materialAdded);
                    _markedObjects.Remove(gameObjectId);
                }, LifeTime);
            }
            else
            {
                if (_markedPositions.Count >= MaxTargets)
                {
                    return;
                }
                _markedPositions.Add(hit.point);
                SFX_InvokeUtil.RunLater(this, () => { _markedPositions.Remove(hit.point); }, LifeTime);
            }
        }
コード例 #2
0
        private void Awake()
        {
            var collisionProviders = GetComponents <SFX_ICollisionsProvider>();

            foreach (var collisionsProvider in collisionProviders)
            {
                collisionsProvider.OnCollision += delegate(SFX_CollisionPoint collisionPoint)
                {
                    if (_wasCollided)
                    {
                        return;
                    }

                    var targetRotation = Vector3.zero;

                    foreach (var fxObject in FxObjects)
                    {
                        switch (fxObject.FxRotation)
                        {
                        case SFX_FxRotationType.Default:
                            break;

                        case SFX_FxRotationType.Normal:
                            targetRotation = collisionPoint.Normal;
                            break;

                        case SFX_FxRotationType.LookAtEmitter:
                            targetRotation = GetComponent <SFX_IEmitterKeeper>().EmitterTransform.position;
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }

                        SFX_FxObjectInstancer.InstantiateFx(fxObject, collisionPoint.Point, targetRotation);
                    }

                    _wasCollided = true;
                };
            }
        }