private void Start() { inputKeys = new List <InputKey>(keyParent.GetComponentsInChildren <InputKey>()); inputSlots = new List <InputSlot>(fragmentParent.GetComponentsInChildren <InputSlot>()); inputFragments = new List <InputFragment>(fragmentParent.GetComponentsInChildren <InputFragment>()); dropShadow.enabled = false; // Insert each key into the nearest slot foreach (InputKey inputKey in inputKeys) { float shortestDistance = 0; InputSlot nearestSlot = null; foreach (InputSlot inputSlot in inputSlots) { float distance = Vector3.Distance(inputKey.transform.position, inputSlot.transform.position); if (nearestSlot == null || distance < shortestDistance) { nearestSlot = inputSlot; shortestDistance = distance; } } nearestSlot.SetInputKey(inputKey); inputKey.SetInputSlot(nearestSlot); inputKey.transform.position = nearestSlot.transform.position; InputMapper.Instance.AddMapping(nearestSlot.GetAction(), inputKey.GetKeyCode()); } }
private void Start() { S = this; OutputSlot.Initialize(new OutputSlot()); InputSlot.Initialize(new InputSlot()); AddToSingleton(); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequiredMutating <Surface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequiredMutating <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetOptionalMutating <IVertexAttribute <Vector3> >(ref vertexPositionsInputSlot, this); // Fields passCount = 1; frequency = 0.1f; randomness.Initialize(this); minVertexNeighbors = 3; maxVertexNeighbors = 5; minFaceNeighbors = 3; maxFaceNeighbors = 7; lockBoundaryPositions = true; relaxForRegularityWeight = 0.5f; maxRelaxIterations = 20; relaxRelativePrecision = 0.95f; maxRepairIterations = 20; repairRate = 0.5f; }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Surface>(surfaceInputSlot); InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IVertexAttribute <Vector3> >(vertexPositionsInputSlot); randomness.ResetIfBroken(this); }
// Do an animation where they break one by one //private IEnumerator BreakCoroutine() //{ // while (keysToBreak.Count > 0 || fragmentsToBreak.Count > 0) // { // bool itemBroken = false; // if (keysToBreak.Count > 0 && Random.value < 0.5) // { // InputKey inputKey = keysToBreak[Random.Range(0, keysToBreak.Count)]; // keysToBreak.Remove(inputKey); // BreakKey(inputKey); // itemBroken = true; // } // else // { // InputFragment inputFragment = fragmentsToBreak[Random.Range(0, fragmentsToBreak.Count)]; // // Only break a fragment once any keys in it have been broken // bool fragmentContainsKeys = false; // foreach (InputSlot inputSlot in inputFragment.GetComponentsInChildren<InputSlot>()) // { // if (inputSlot.GetInputKey() != null) // { // fragmentContainsKeys = true; // break; // } // } // if (!fragmentContainsKeys) // { // fragmentsToBreak.Remove(inputFragment); // BreakFragment(inputFragment); // itemBroken = true; // } // } // if (itemBroken) { yield return new WaitForSeconds(0.2f); } // } //} private void BreakKey(InputKey inputKey) { if (dragging && draggedKey == inputKey) { StopDragging(); } Vector3 positionVector = inputKey.transform.position - keyParent.transform.position; positionVector = CanvasScale.Instance.WorldToCanvas(positionVector); positionVector.x *= 2; positionVector.y *= 4; inputKey.Break( positionVector + (Vector3)Random.insideUnitCircle * 500f, Random.Range(-360, 360)); InputSlot inputSlot = inputKey.GetInputSlot(); if (inputSlot != null) { inputSlot.SetInputKey(null); InputMapper.Instance.RemoveMapping(inputSlot.GetAction()); } inputKey.SetInputSlot(null); inputKeys.Remove(inputKey); }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IFaceAttribute <Color> >(faceColorsInputSlot); OutputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Color> >(faceEdgeColorsOutputSlot); }
private void grindInput() { ItemStack grindedStack = InputGrindProps.GroundStack.ResolvedItemstack.Clone(); if (OutputSlot.Itemstack == null) { OutputSlot.Itemstack = grindedStack; } else { int mergableQuantity = OutputSlot.Itemstack.Collectible.GetMergableQuantity(OutputSlot.Itemstack, grindedStack, EnumMergePriority.AutoMerge); if (mergableQuantity > 0) { OutputSlot.Itemstack.StackSize += grindedStack.StackSize; } else { BlockFacing face = BlockFacing.HORIZONTALS[nowOutputFace]; nowOutputFace = (nowOutputFace + 1) % 4; Block block = Api.World.BlockAccessor.GetBlock(this.Pos.AddCopy(face)); if (block.Replaceable < 6000) { return; } Api.World.SpawnItemEntity(grindedStack, this.Pos.ToVec3d().Add(0.5 + face.Normalf.X * 0.7, 0.75, 0.5 + face.Normalf.Z * 0.7), new Vec3d(face.Normalf.X * 0.02f, 0, face.Normalf.Z * 0.02f)); } } InputSlot.TakeOut(1); InputSlot.MarkDirty(); OutputSlot.MarkDirty(); }
public static T GetValueOfFieldWithType <T>(EvaluationContext context, InputSlot <StructuredList> dataListInput, InputSlot <int> itemIndex, InputSlot <int> FieldIndex, InputSlot <string> orFieldName, ref FieldInfo fieldRef) { var list = dataListInput.GetValue(context); if (list == null || list.NumElements == 0) { return(default);
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Surface>(surfaceInputSlot); InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IVertexAttribute <Vector3> >(vertexPositionsInputSlot); OutputSlot.ResetAssetTypeIfNull <IFaceAttribute <Vector3> >(faceCentroidsOutputSlot); }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Surface>(surfaceInputSlot); InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IVertexAttribute <Vector3> >(vertexPositionsInputSlot); OutputSlot.ResetAssetTypeIfNull <UniversalFaceSpatialPartitioning>(partitioningOutputSlot); }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Vector3> >(vertexPositionsInputSlot); InputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Vector3> >(offsetsInputSlot); OutputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Vector3> >(offsetVertexPositionsOutputSlot); }
private bool HasIngredient() { if (InputSlot.IsVoid()) { return(false); } SmeltingRecipe recipe = GetSmeltingRecipe(InputSlot); return(recipe != null); }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <FaceGroupCollection>(faceGroupCollectionInputSlot); InputSlot.ResetAssetTypeIfNull <IFaceAttribute <int> >(faceGroupIndicesInputSlot); randomness.ResetIfBroken(this); OutputSlot.ResetAssetTypeIfNull <IFaceGroupAttribute <Color> >(faceGroupColorsOutputSlot); OutputSlot.ResetAssetTypeIfNull <IFaceAttribute <Color> >(faceColorsOutputSlot); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Surface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IVertexAttribute <Vector3> >(ref vertexPositionsInputSlot, this); // Outputs OutputSlot.CreateOrReset <UniversalFaceSpatialPartitioning>(ref partitioningOutputSlot, this, "Face Spatial Partitioning"); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <DynamicMesh>(ref dynamicMeshInputSlot, this); // Fields meshPrefab = null; // Outputs OutputSlot.CreateOrReset <GameObject>(ref prefabOutputSlot, this, "Prefab"); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Surface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IEdgeAttribute <Vector3> >(ref vertexPositionsInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <Vector3> >(ref facePositionsInputSlot, this); // Outputs OutputSlot.CreateOrResetGrouped <IEdgeAttribute <Vector3> >(ref bisectorsOutputSlot, this, "Face Edge Bisectors", "Attributes"); }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); randomness.ResetIfBroken(this); OutputSlot.ResetAssetTypeIfNull <FaceGroupCollection>(faceGroupCollectionOutputSlot); OutputSlot.ResetAssetTypeIfNull <IFaceAttribute <int> >(faceGroupIndicesOutputSlot); foreach (var outputSlot in faceGroupOutputSlots) { OutputSlot.ResetAssetTypeIfNull <FaceGroup>(outputSlot); } }
public void OnAfterDeserialize() { InputSlot.ResetAssetTypeIfNull <Surface>(surfaceInputSlot); InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IFaceAttribute <Vector3> >(facePositionsInputSlot); OutputSlot.ResetAssetTypeIfNull <FaceGroupCollection>(faceGroupCollectionOutputSlot); OutputSlot.ResetAssetTypeIfNull <IFaceAttribute <int> >(faceGroupIndicesOutputSlot); foreach (var outputSlot in faceGroupOutputSlots) { OutputSlot.ResetAssetTypeIfNull <FaceGroup>(outputSlot); } }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Surface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IVertexAttribute <Vector3> >(ref vertexPositionsInputSlot, this); // Fields flatten = false; // Outputs OutputSlot.CreateOrResetGrouped <IFaceAttribute <Vector3> >(ref faceCentroidsOutputSlot, this, "Face Centroids", "Attributes"); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IEdgeAttribute <Vector3> >(ref vertexPositionsInputSlot, this); InputSlot.CreateOrResetRequired <IEdgeAttribute <Vector3> >(ref offsetsInputSlot, this); // Fields scale = 1f; // Outputs OutputSlot.CreateOrResetGrouped <IEdgeAttribute <Vector3> >(ref offsetVertexPositionsOutputSlot, this, "Offset Vertex Positions", "Attributes"); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); // Fields groupCount = 1; randomness.Initialize(this); // Outputs OutputSlot.CreateOrResetGrouped <FaceGroupCollection>(ref faceGroupCollectionOutputSlot, this, "Random Face Groups", "Face Groups"); OutputSlot.CreateOrResetGrouped <IFaceAttribute <int> >(ref faceGroupIndicesOutputSlot, this, "Random Face Group Indices", "Attributes"); faceGroupOutputSlots = new OutputSlot[0]; }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <Color> >(ref faceColorsInputSlot, this); // Fields colorSource = ColorSource.Constant; constantColor = Color.black; blendWeight = 0.5f; // Outputs OutputSlot.CreateOrResetGrouped <IEdgeAttribute <Color> >(ref faceEdgeColorsOutputSlot, this, "Face Edge Colors", "Attributes"); }
public void OnAfterDeserialize() { if (surfaceInputSlot.generator == null) { surfaceInputSlot = InputSlot.CreateRequired <Surface>(this); } InputSlot.ResetAssetTypeIfNull <Surface>(surfaceInputSlot); InputSlot.ResetAssetTypeIfNull <Topology>(topologyInputSlot); InputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Vector3> >(vertexPositionsInputSlot); InputSlot.ResetAssetTypeIfNull <IFaceAttribute <Vector3> >(facePositionsInputSlot); OutputSlot.ResetAssetTypeIfNull <IEdgeAttribute <Vector3> >(bisectorsOutputSlot); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Surface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IVertexAttribute <Vector3> >(ref vertexPositionsInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <Vector3> >(ref facePositionsInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <Vector3> >(ref faceNormalsInputSlot, this); // Fields calculationMethod = CalculationMethod.FromSurfaceNormal; // Outputs OutputSlot.CreateOrResetGrouped <IVertexAttribute <Vector3> >(ref vertexNormalsOutputSlot, this, "Vertex Normals", "Attributes"); }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <QuadrilateralSurface>(ref surfaceInputSlot, this); InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <Vector3> >(ref facePositionsInputSlot, this); // Fields axisDivisions = new IntVector2(1, 1); // Outputs OutputSlot.CreateOrResetGrouped <FaceGroupCollection>(ref faceGroupCollectionOutputSlot, this, "Rectangular Face Groups", "Face Groups"); OutputSlot.CreateOrResetGrouped <IFaceAttribute <int> >(ref faceGroupIndicesOutputSlot, this, "Rectangular Face Group Indices", "Attributes"); faceGroupOutputSlots = new OutputSlot[0]; }
protected override void Initialize() { // Inputs InputSlot.CreateOrResetRequired <Topology>(ref topologyInputSlot, this); InputSlot.CreateOrResetRequired <FaceGroupCollection>(ref faceGroupCollectionInputSlot, this); InputSlot.CreateOrResetRequired <IFaceAttribute <int> >(ref faceGroupIndicesInputSlot, this); // Fields colorSource = ColorSource.Constant; constantColor = Color.white; randomness.Initialize(this); // Outputs OutputSlot.CreateOrResetGrouped <IFaceGroupAttribute <Color> >(ref faceGroupColorsOutputSlot, this, "Face Group Colors", "Attributes"); OutputSlot.CreateOrResetGrouped <IFaceAttribute <Color> >(ref faceColorsOutputSlot, this, "Face Colors", "Attributes"); }
private void UpdateVertexAttributeInputSlots <TAttributeValue>(bool use, ref InputSlot[] ringVertexAttributesInputSlots, ref InputSlot[] centerVertexAttributesInputSlots) { if (use == false) { if (ringVertexAttributesInputSlots.Length > 0) { for (int i = 0; i < ringVertexAttributesInputSlots.Length; ++i) { ringVertexAttributesInputSlots[i].Disconnect(); } ringVertexAttributesInputSlots = new InputSlot[0]; } } else { if (ringVertexAttributesInputSlots.Length != ringDepth) { var newArray = new InputSlot[ringDepth]; System.Array.Copy(ringVertexAttributesInputSlots, newArray, Mathf.Min(ringVertexAttributesInputSlots.Length, ringDepth)); for (int i = ringVertexAttributesInputSlots.Length; i < ringDepth; ++i) { newArray[i] = InputSlot.CreateRequired <IEdgeAttribute <TAttributeValue> >(this); } for (int i = ringDepth; i < ringVertexAttributesInputSlots.Length; ++i) { ringVertexAttributesInputSlots[i].Disconnect(); } ringVertexAttributesInputSlots = newArray; } } if (use == false || triangulation != Triangulation.Umbrella) { if (centerVertexAttributesInputSlots.Length > 0) { centerVertexAttributesInputSlots[0].Disconnect(); centerVertexAttributesInputSlots = new InputSlot[0]; } } else { if (centerVertexAttributesInputSlots.Length == 0) { centerVertexAttributesInputSlots = new InputSlot[] { InputSlot.CreateRequired <IFaceAttribute <TAttributeValue> >(this) }; } } }
private void grindInput() { ItemStack grindedStack = InputGrindProps.GrindedStack.ResolvedItemstack; if (OutputSlot.Itemstack == null) { OutputSlot.Itemstack = grindedStack.Clone(); } else { OutputSlot.Itemstack.StackSize += grindedStack.StackSize; } InputSlot.TakeOut(1); InputSlot.MarkDirty(); OutputSlot.MarkDirty(); }
private void StopDragging() { dragging = false; dropShadow.enabled = false; // Find the nearest valid slot InputSlot nearestSlot = null; float shortestDistance = 0; foreach (InputSlot inputSlot in inputSlots) { float distance = CanvasScale.Instance.WorldToCanvas(Vector3.Distance(draggedKey.transform.position, inputSlot.transform.position)); if (distance < snapDistance && (nearestSlot == null || distance < shortestDistance)) { nearestSlot = inputSlot; shortestDistance = distance; } } if (nearestSlot != null) { AudioManager.Instance.Play("key_insert"); // Remove the key that was occupying the slot InputKey replacedKey = nearestSlot.GetInputKey(); if (replacedKey != null) { replacedKey.SetInputSlot(null); // Fire off in a random direction //float randomAngle = Random.Range(0, 360); //replacedKey.SetVelocity(1000 * new Vector3(Mathf.Cos(randomAngle), Mathf.Sin(randomAngle), 0)); // Fire off away from the dragged key replacedKey.SetVelocity(1000 * (replacedKey.transform.position - draggedKey.transform.position).normalized); replacedKey.transform.SetAsLastSibling(); InputMapper.Instance.RemoveMapping(nearestSlot.GetAction()); } nearestSlot.SetInputKey(draggedKey); draggedKey.SetInputSlot(nearestSlot); draggedKey.transform.SetAsFirstSibling(); InputMapper.Instance.AddMapping(nearestSlot.GetAction(), draggedKey.GetKeyCode()); } }
public void ShowTrade(ITradeable Tradeable) { AudioManager.S.PlaySound("TradeComplete"); if (CurrentTrade != null) { RemoveItemsFromTradeUI(); } CurrentlyBeingTradedWith = Tradeable; CurrentTrade = CurrentlyBeingTradedWith.GetTrade(); TradesLeft = CurrentTrade.MaxNumberOfTrades; OutputSlot.Initialize(new OutputSlot()); InputSlot.Initialize(new InputSlot()); Background.SetActive(true); InputSlot.SetOutputSihlouette(CurrentTrade.WantedItem); InputSlot S = (InputSlot)InputSlot.ReferenceSlot; S.AcceptedItem = CurrentTrade.WantedItem; OutputSlot.SetOutputSihlouette(CurrentTrade.BaseTradedItem); }