public GameObject CreateOrFindSafe(string instanceId = null, CharacterPosition sourcePosition = null, CharacterPosition targetPosition = null, GameObject parentInstance = null)
        {
            GameObject gameObject = null;

            UnityMainThreadDispatcher.ExecuteOnMainThread(() =>
            {
                gameObject = CreateOrFindUnsafe(instanceId, sourcePosition, targetPosition, parentInstance);
                RefreshIfNecessary(gameObject);
            });

            return(gameObject);
        }
Exemple #2
0
            private static void UpdateTargetDistanceFrom(CharacterPosition position)
            {
                float distanceFeet = GetTargetingCursorDistanceTo(position);

                if (activeTargetRangeText != null)
                {
                    activeTargetRangeText.text = $"{distanceFeet:F}ft";
                }

                bool isInRange = distanceFeet < targetAnchorRange;

                if (TargetingVolume?.activeSelf != isInRange)
                {
                    ToggleTargetIndicatorState(isInRange);
                }
            }
            public static CharacterPositions GetPositions()
            {
                CreatureBoardAsset[] allCreatureAssets = GetAll();
                if (allCreatureAssets == null)
                {
                    return(null);
                }

                CharacterPositions characterPositions = new CharacterPositions();

                foreach (CreatureBoardAsset creatureAsset in allCreatureAssets)
                {
                    CharacterPosition characterPosition = creatureAsset.GetCharacterPosition();
                    characterPositions.Characters.Add(characterPosition);
                }

                return(characterPositions);
            }
Exemple #4
0
            private static void UpdateTarget()
            {
                if (Time.time - lastTargetTetherUpdateTime <= 0.1)                  // Limit updates to ten times a second.
                {
                    return;
                }

                lastTargetTetherUpdateTime = Time.time;

                if (activeTargetRangeIndicator == null)
                {
                    ActivateTargetRangeIndicator();
                }

                KeepTargetTextFacingCamera();

                CharacterPosition position = Minis.GetPosition(targetAnchorId);

                if (position != null)
                {
                    UpdateTargetDistanceFrom(position);
                }
            }
        public GameObject CreateOrFindUnsafe(string instanceId = null, CharacterPosition sourcePosition = null, CharacterPosition targetPosition = null, GameObject parentInstance = null)
        {
            //if (ExistingChildName != null)
            //	Talespire.Log.Debug($"Finding {ExistingChildName}...");
            //else
            //	Talespire.Log.Debug($"Creating {PrefabToCreate}...");

            this.targetPosition = targetPosition;
            this.sourcePosition = sourcePosition;
            GameObject instance = null;

            if (PrefabToCreate != null)
            {
                Talespire.Log.Debug($"instance = Talespire.Prefabs.Clone(\"{PrefabToCreate}\", instanceId);");
                instance = Talespire.Prefabs.Clone(PrefabToCreate, instanceId);
                // TODO: Figure out spell effect motion/positioning...
                if (targetPosition != null && instance.transform != null)
                {
                    instance.transform.position = targetPosition.Position.GetVector3();
                }
                else
                {
                    if (instance.transform == null)
                    {
                        Talespire.Log.Error($"Prefab {PrefabToCreate}'s instance.transform == null!");
                        return(null);
                    }
                }
            }
            else if (ExistingChildName != null)
            {
                if (parentInstance != null && parentInstance.transform != null)
                {
                    Talespire.Log.Debug($"Transform childTransform = parentInstance.transform.Find(\"{ExistingChildName}\");");
                    Transform childTransform = parentInstance.transform.Find(ExistingChildName);
                    instance = childTransform?.gameObject;
                }
                else
                {
                    Talespire.Log.Debug($"parentInstance == null!");
                }
            }
            else if (ItemToClone != null)
            {
                Talespire.Log.Debug($"instance = Talespire.GameObjects.Clone(\"{ItemToClone}\", instanceId);");
                instance = Talespire.GameObjects.Clone(ItemToClone, instanceId);
                // TODO: Figure out spell effect motion/positioning...
                if (targetPosition != null && instance.transform != null)
                {
                    instance.transform.position = targetPosition.Position.GetVector3();
                }
                else
                {
                    if (instance.transform == null)
                    {
                        Talespire.Log.Error($"Clone {ItemToClone}'s instance.transform == null!");
                        return(null);
                    }
                }
            }
            else if (ItemToBorrow != null)
            {
                Talespire.Log.Debug($"instance = Talespire.GameObjects.Get(\"{ItemToBorrow}\");");
                instance = Talespire.GameObjects.Get(ItemToBorrow);
            }
            else if (EffectNameToCreate != null)
            {
                if (KnownEffectsBuilder != null)
                {
                    Talespire.Log.Debug($"instance = KnownEffectsBuilder.Create(\"{EffectNameToCreate}\", instanceId);");
                    instance = KnownEffectsBuilder.Create(EffectNameToCreate, instanceId);
                }
            }

            //Talespire.Log.Debug($"Creation complete!");

            if (instance != null)
            {
                //Talespire.Log.Debug($"ModifyProperties(instance)....");
                ModifyProperties(instance);
            }

            //Talespire.Log.Debug($"Repeat with children...");
            if (Children != null)
            {
                foreach (CompositeEffect nestedEffectDto in Children)
                {
                    if (nestedEffectDto != null)
                    {
                        nestedEffectDto.CreateOrFindUnsafe(instanceId, sourcePosition, targetPosition, instance);
                    }
                    else
                    {
                        Talespire.Log.Error($"nestedEffectDto == null!");
                    }
                }
            }

            if (instance != null)
            {
                //Talespire.Log.Warning($"compositeEffectMap[{instance}] = this ({this});");
                compositeEffectMap[instance] = this;
            }
            else
            {
                Talespire.Log.Error($"Unable to map newly-created composite effect to instance {instance}.");
            }

            // TODO: Worried about a slow memory leak here. If we can hook a unity event for when GOs are destroyed, we could plug the leak by removing those elements from compositeEffectMap.

            return(instance);
        }
Exemple #6
0
 public static float GetTargetingCursorDistanceTo(CharacterPosition position)
 {
     return(GetTargetingCursorDistanceTo(new Vector3(position.Position.x, position.Position.y, position.Position.z)));
 }